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.
type Keypair struct {
Public string `json:"public"`
Private string `json:"-"`
Private string `json:"private"`
}
// 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
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 {

View file

@ -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)
}