include private key in json, manually scrub from rest responses

This commit is contained in:
Brad Rydzewski 2015-05-09 12:54:38 -07:00
parent 062a31de08
commit fb2999c35d
3 changed files with 21 additions and 6 deletions

View file

@ -29,7 +29,7 @@ type Repo struct {
// private repositories, or as a deployment key. // private repositories, or as a deployment key.
type Keypair struct { type Keypair struct {
Public string `json:"public"` Public string `json:"public"`
Private string `json:"-"` Private string `json:"private"`
} }
// Owner represents the owner of a repository. // Owner represents the owner of a repository.

View file

@ -144,8 +144,10 @@ func (r *Runner) Run(w *queue.Work) error {
var buf bytes.Buffer var buf bytes.Buffer
rc, err := worker.Logs() rc, err := worker.Logs()
if err != nil && builderr != nil { if err != nil && builderr != nil {
buf.WriteString("001 Error launching build")
buf.WriteString(builderr.Error()) buf.WriteString(builderr.Error())
} else if err != nil { } else if err != nil {
buf.WriteString("002 Error launching build")
buf.WriteString(err.Error()) buf.WriteString(err.Error())
return err return err
} else { } else {

View file

@ -55,9 +55,16 @@ func GetRepo(c *gin.Context) {
perm := ToPerm(c) perm := ToPerm(c)
data := repoResp{repo, perm, nil, nil, nil} data := repoResp{repo, perm, nil, nil, nil}
// if the user is an administrator of the project // if the user is an administrator of the project
// we should display the private parameter data. // we should display the private parameter data
if perm.Admin { // and keypair data.
if perm.Push {
data.Params, _ = store.RepoParams(repo.FullName) 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 the user is authenticated, we should display
// if she is watching the current repository. // 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 // check to see if the user is subscribing to the repo
data.Watch = &common.Subscriber{} data.Watch = &common.Subscriber{}
data.Watch.Subscribed, _ = store.Subscribed(user.Login, repo.FullName) data.Watch.Subscribed, _ = store.Subscribed(user.Login, repo.FullName)
data.Keypair, _ = store.RepoKeypair(repo.FullName)
c.JSON(200, data) 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 // in the datastore. It expects a JSON input and returns the
// updated repository in JSON format if successful. // updated repository in JSON format if successful.
// //
@ -122,11 +128,18 @@ func PutRepo(c *gin.Context) {
data := repoResp{repo, perm, nil, nil, nil} data := repoResp{repo, perm, nil, nil, nil}
data.Params, _ = store.RepoParams(repo.FullName) data.Params, _ = store.RepoParams(repo.FullName)
data.Keypair, _ = store.RepoKeypair(repo.FullName)
// check to see if the user is subscribing to the repo // check to see if the user is subscribing to the repo
data.Watch = &common.Subscriber{} data.Watch = &common.Subscriber{}
data.Watch.Subscribed, _ = store.Subscribed(user.Login, repo.FullName) 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) c.JSON(200, data)
} }