From fb2999c35dd3f977804165a79bcb9a317f3463a6 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 9 May 2015 12:54:38 -0700 Subject: [PATCH] include private key in json, manually scrub from rest responses --- common/repo.go | 2 +- runner/builtin/runner.go | 2 ++ server/repos.go | 23 ++++++++++++++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/common/repo.go b/common/repo.go index cc7d96a1c..97579d4bf 100644 --- a/common/repo.go +++ b/common/repo.go @@ -29,7 +29,7 @@ type Repo struct { // private repositories, or as a deployment key. type Keypair struct { Public string `json:"public"` - Private string `json:"-"` + Private string `json:"private"` } // Owner represents the owner of a repository. diff --git a/runner/builtin/runner.go b/runner/builtin/runner.go index dacad0a8a..bcbe7bce1 100644 --- a/runner/builtin/runner.go +++ b/runner/builtin/runner.go @@ -144,8 +144,10 @@ func (r *Runner) Run(w *queue.Work) error { var buf bytes.Buffer rc, err := worker.Logs() if err != nil && builderr != nil { + buf.WriteString("001 Error launching build") buf.WriteString(builderr.Error()) } else if err != nil { + buf.WriteString("002 Error launching build") buf.WriteString(err.Error()) return err } else { diff --git a/server/repos.go b/server/repos.go index 7c89e09da..cf6ea3bf4 100644 --- a/server/repos.go +++ b/server/repos.go @@ -55,9 +55,16 @@ func GetRepo(c *gin.Context) { perm := ToPerm(c) data := repoResp{repo, perm, nil, nil, nil} // if the user is an administrator of the project - // we should display the private parameter data. - if perm.Admin { + // we should display the private parameter data + // and keypair data. + if perm.Push { data.Params, _ = store.RepoParams(repo.FullName) + + // note that we should only display the public key + keypair, err := store.RepoKeypair(repo.FullName) + if err == nil { + data.Keypair = &common.Keypair{Public: keypair.Public} + } } // if the user is authenticated, we should display // if she is watching the current repository. @@ -69,12 +76,11 @@ func GetRepo(c *gin.Context) { // check to see if the user is subscribing to the repo data.Watch = &common.Subscriber{} data.Watch.Subscribed, _ = store.Subscribed(user.Login, repo.FullName) - data.Keypair, _ = store.RepoKeypair(repo.FullName) c.JSON(200, data) } -// PutRepo accapets a request to update the named repository +// PutRepo accepts a request to update the named repository // in the datastore. It expects a JSON input and returns the // updated repository in JSON format if successful. // @@ -122,11 +128,18 @@ func PutRepo(c *gin.Context) { data := repoResp{repo, perm, nil, nil, nil} data.Params, _ = store.RepoParams(repo.FullName) + data.Keypair, _ = store.RepoKeypair(repo.FullName) // check to see if the user is subscribing to the repo data.Watch = &common.Subscriber{} data.Watch.Subscribed, _ = store.Subscribed(user.Login, repo.FullName) - data.Keypair, _ = store.RepoKeypair(repo.FullName) + + // scrub the private key from the keypair + if data.Keypair != nil { + data.Keypair = &common.Keypair{ + Public: data.Keypair.Public, + } + } c.JSON(200, data) }