Integrated org secrets into client

This commit is contained in:
Thomas Boerger 2016-07-25 17:03:54 +02:00 committed by Thomas Boerger
parent 606ca93881
commit 86e4e53e77
No known key found for this signature in database
GPG key ID: 5A388F55283960B6
2 changed files with 55 additions and 24 deletions

View file

@ -61,6 +61,15 @@ type Client interface {
// SecretDel deletes a named repository secret. // SecretDel deletes a named repository secret.
SecretDel(string, string, string) error SecretDel(string, string, string) error
// TeamSecretList returns a list of all team secrets.
TeamSecretList(string) ([]*model.Secret, error)
// TeamSecretPost create or updates a team secret.
TeamSecretPost(string, *model.Secret) error
// TeamSecretDel deletes a named team secret.
TeamSecretDel(string, string) error
// Build returns a repository build by number. // Build returns a repository build by number.
Build(string, string, int) (*model.Build, error) Build(string, string, int) (*model.Build, error)

View file

@ -28,26 +28,28 @@ const (
pathLogs = "%s/api/queue/logs/%d" pathLogs = "%s/api/queue/logs/%d"
pathLogsAuth = "%s/api/queue/logs/%d?access_token=%s" pathLogsAuth = "%s/api/queue/logs/%d?access_token=%s"
pathSelf = "%s/api/user" pathSelf = "%s/api/user"
pathFeed = "%s/api/user/feed" pathFeed = "%s/api/user/feed"
pathRepos = "%s/api/user/repos" pathRepos = "%s/api/user/repos"
pathRepo = "%s/api/repos/%s/%s" pathRepo = "%s/api/repos/%s/%s"
pathChown = "%s/api/repos/%s/%s/chown" pathChown = "%s/api/repos/%s/%s/chown"
pathEncrypt = "%s/api/repos/%s/%s/encrypt" pathEncrypt = "%s/api/repos/%s/%s/encrypt"
pathBuilds = "%s/api/repos/%s/%s/builds" pathBuilds = "%s/api/repos/%s/%s/builds"
pathBuild = "%s/api/repos/%s/%s/builds/%v" pathBuild = "%s/api/repos/%s/%s/builds/%v"
pathJob = "%s/api/repos/%s/%s/builds/%d/%d" pathJob = "%s/api/repos/%s/%s/builds/%d/%d"
pathLog = "%s/api/repos/%s/%s/logs/%d/%d" pathLog = "%s/api/repos/%s/%s/logs/%d/%d"
pathKey = "%s/api/repos/%s/%s/key" pathKey = "%s/api/repos/%s/%s/key"
pathSign = "%s/api/repos/%s/%s/sign" pathSign = "%s/api/repos/%s/%s/sign"
pathSecrets = "%s/api/repos/%s/%s/secrets" pathRepoSecrets = "%s/api/repos/%s/%s/secrets"
pathSecret = "%s/api/repos/%s/%s/secrets/%s" pathRepoSecret = "%s/api/repos/%s/%s/secrets/%s"
pathNodes = "%s/api/nodes" pathTeamSecrets = "%s/api/teams/%s/secrets"
pathNode = "%s/api/nodes/%d" pathTeamSecret = "%s/api/teams/%s/secrets/%s"
pathUsers = "%s/api/users" pathNodes = "%s/api/nodes"
pathUser = "%s/api/users/%s" pathNode = "%s/api/nodes/%d"
pathBuildQueue = "%s/api/builds" pathUsers = "%s/api/users"
pathAgent = "%s/api/agents" pathUser = "%s/api/users/%s"
pathBuildQueue = "%s/api/builds"
pathAgent = "%s/api/agents"
) )
type client struct { type client struct {
@ -78,7 +80,7 @@ func NewClientTokenTLS(uri, token string, c *tls.Config) Client {
if trans, ok := auther.Transport.(*oauth2.Transport); ok { if trans, ok := auther.Transport.(*oauth2.Transport); ok {
trans.Base = &http.Transport{ trans.Base = &http.Transport{
TLSClientConfig: c, TLSClientConfig: c,
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
} }
} }
} }
@ -265,20 +267,40 @@ func (c *client) Deploy(owner, name string, num int, env string, params map[stri
// SecretList returns a list of a repository secrets. // SecretList returns a list of a repository secrets.
func (c *client) SecretList(owner, name string) ([]*model.Secret, error) { func (c *client) SecretList(owner, name string) ([]*model.Secret, error) {
var out []*model.Secret var out []*model.Secret
uri := fmt.Sprintf(pathSecrets, c.base, owner, name) uri := fmt.Sprintf(pathRepoSecrets, c.base, owner, name)
err := c.get(uri, &out) err := c.get(uri, &out)
return out, err return out, err
} }
// SecretPost create or updates a repository secret. // SecretPost create or updates a repository secret.
func (c *client) SecretPost(owner, name string, secret *model.Secret) error { func (c *client) SecretPost(owner, name string, secret *model.Secret) error {
uri := fmt.Sprintf(pathSecrets, c.base, owner, name) uri := fmt.Sprintf(pathRepoSecrets, c.base, owner, name)
return c.post(uri, secret, nil) return c.post(uri, secret, nil)
} }
// SecretDel deletes a named repository secret. // SecretDel deletes a named repository secret.
func (c *client) SecretDel(owner, name, secret string) error { func (c *client) SecretDel(owner, name, secret string) error {
uri := fmt.Sprintf(pathSecret, c.base, owner, name, secret) uri := fmt.Sprintf(pathRepoSecret, c.base, owner, name, secret)
return c.delete(uri)
}
// TeamSecretList returns a list of a repository secrets.
func (c *client) TeamSecretList(team string) ([]*model.Secret, error) {
var out []*model.Secret
uri := fmt.Sprintf(pathTeamSecrets, c.base, team)
err := c.get(uri, &out)
return out, err
}
// TeamSecretPost create or updates a repository secret.
func (c *client) TeamSecretPost(team string, secret *model.Secret) error {
uri := fmt.Sprintf(pathTeamSecrets, c.base, team)
return c.post(uri, secret, nil)
}
// TeamSecretDel deletes a named repository secret.
func (c *client) TeamSecretDel(team, secret string) error {
uri := fmt.Sprintf(pathTeamSecret, c.base, team, secret)
return c.delete(uri) return c.delete(uri)
} }