Skip to content

Commit

Permalink
wip enable pluggable secret and registry backends
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Apr 11, 2017
1 parent 6e244be commit 8348c85
Show file tree
Hide file tree
Showing 78 changed files with 1,748 additions and 1,589 deletions.
48 changes: 15 additions & 33 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ type Client interface {
// UserDel deletes a user account.
UserDel(string) error

// // UserFeed returns the user's activity feed.
// UserFeed() ([]*Activity, error)

// Repo returns a repository by name.
Repo(string, string) (*model.Repo, error)

Expand All @@ -48,36 +45,6 @@ type Client interface {
// RepoDel deletes a repository.
RepoDel(string, string) error

// Sign returns a cryptographic signature for the input string.
Sign(string, string, []byte) ([]byte, error)

// SecretList returns a list of all repository secrets.
SecretList(string, string) ([]*model.Secret, error)

// SecretPost create or updates a repository secret.
SecretPost(string, string, *model.Secret) error

// SecretDel deletes a named repository secret.
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

// GlobalSecretList returns a list of global secrets.
GlobalSecretList() ([]*model.Secret, error)

// GlobalSecretPost create or updates a global secret.
GlobalSecretPost(secret *model.Secret) error

// GlobalSecretDel deletes a named global secret.
GlobalSecretDel(secret string) error

// Build returns a repository build by number.
Build(string, string, int) (*model.Build, error)

Expand Down Expand Up @@ -129,4 +96,19 @@ type Client interface {

// RegistryDelete deletes a registry.
RegistryDelete(owner, name, hostname string) error

// Secret returns a secret by name.
Secret(owner, name, secret string) (*model.Secret, error)

// SecretList returns a list of all repository secrets.
SecretList(owner, name string) ([]*model.Secret, error)

// SecretCreate creates a registry.
SecretCreate(owner, name string, secret *model.Secret) (*model.Secret, error)

// SecretUpdate updates a registry.
SecretUpdate(owner, name string, secret *model.Secret) (*model.Secret, error)

// SecretDelete deletes a secret.
SecretDelete(owner, name, secret string) error
}
118 changes: 38 additions & 80 deletions client/client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,16 @@ const (
pathRepos = "%s/api/user/repos"
pathRepo = "%s/api/repos/%s/%s"
pathChown = "%s/api/repos/%s/%s/chown"
pathEncrypt = "%s/api/repos/%s/%s/encrypt"
pathBuilds = "%s/api/repos/%s/%s/builds"
pathBuild = "%s/api/repos/%s/%s/builds/%v"
pathApprove = "%s/api/repos/%s/%s/builds/%d/approve"
pathDecline = "%s/api/repos/%s/%s/builds/%d/decline"
pathJob = "%s/api/repos/%s/%s/builds/%d/%d"
pathLog = "%s/api/repos/%s/%s/logs/%d/%d"
pathKey = "%s/api/repos/%s/%s/key"
pathSign = "%s/api/repos/%s/%s/sign"
pathRepoSecrets = "%s/api/repos/%s/%s/secrets"
pathRepoSecret = "%s/api/repos/%s/%s/secrets/%s"
pathRepoRegistries = "%s/api/repos/%s/%s/registry"
pathRepoRegistry = "%s/api/repos/%s/%s/registry/%s"
pathTeamSecrets = "%s/api/teams/%s/secrets"
pathTeamSecret = "%s/api/teams/%s/secrets/%s"
pathGlobalSecrets = "%s/api/global/secrets"
pathGlobalSecret = "%s/api/global/secrets/%s"
pathNodes = "%s/api/nodes"
pathNode = "%s/api/nodes/%d"
pathUsers = "%s/api/users"
pathUser = "%s/api/users/%s"
pathBuildQueue = "%s/api/builds"
Expand Down Expand Up @@ -295,77 +286,6 @@ func (c *client) Deploy(owner, name string, num int, env string, params map[stri
return out, err
}

// SecretList returns a list of a repository secrets.
func (c *client) SecretList(owner, name string) ([]*model.Secret, error) {
var out []*model.Secret
uri := fmt.Sprintf(pathRepoSecrets, c.base, owner, name)
err := c.get(uri, &out)
return out, err
}

// SecretPost create or updates a repository secret.
func (c *client) SecretPost(owner, name string, secret *model.Secret) error {
uri := fmt.Sprintf(pathRepoSecrets, c.base, owner, name)
return c.post(uri, secret, nil)
}

// SecretDel deletes a named repository secret.
func (c *client) SecretDel(owner, name, secret string) error {
uri := fmt.Sprintf(pathRepoSecret, c.base, owner, name, secret)
return c.delete(uri)
}

// TeamSecretList returns a list of organizational 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 organizational 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 orgainization secret.
func (c *client) TeamSecretDel(team, secret string) error {
uri := fmt.Sprintf(pathTeamSecret, c.base, team, secret)
return c.delete(uri)
}

// GlobalSecretList returns a list of global secrets.
func (c *client) GlobalSecretList() ([]*model.Secret, error) {
var out []*model.Secret
uri := fmt.Sprintf(pathGlobalSecrets, c.base)
err := c.get(uri, &out)
return out, err
}

// GlobalSecretPost create or updates a global secret.
func (c *client) GlobalSecretPost(secret *model.Secret) error {
uri := fmt.Sprintf(pathGlobalSecrets, c.base)
return c.post(uri, secret, nil)
}

// GlobalSecretDel deletes a named global secret.
func (c *client) GlobalSecretDel(secret string) error {
uri := fmt.Sprintf(pathGlobalSecret, c.base, secret)
return c.delete(uri)
}

// Sign returns a cryptographic signature for the input string.
func (c *client) Sign(owner, name string, in []byte) ([]byte, error) {
uri := fmt.Sprintf(pathSign, c.base, owner, name)
rc, err := stream(c.client, uri, "POST", in, nil)
if err != nil {
return nil, err
}
defer rc.Close()
return ioutil.ReadAll(rc)
}

// Registry returns a registry by hostname.
func (c *client) Registry(owner, name, hostname string) (*model.Registry, error) {
out := new(model.Registry)
Expand Down Expand Up @@ -404,6 +324,44 @@ func (c *client) RegistryDelete(owner, name, hostname string) error {
return c.delete(uri)
}

// Secret returns a secret by name.
func (c *client) Secret(owner, name, secret string) (*model.Secret, error) {
out := new(model.Secret)
uri := fmt.Sprintf(pathRepoSecret, c.base, owner, name, secret)
err := c.get(uri, out)
return out, err
}

// SecretList returns a list of all repository secrets.
func (c *client) SecretList(owner string, name string) ([]*model.Secret, error) {
var out []*model.Secret
uri := fmt.Sprintf(pathRepoSecrets, c.base, owner, name)
err := c.get(uri, &out)
return out, err
}

// SecretCreate creates a secret.
func (c *client) SecretCreate(owner, name string, in *model.Secret) (*model.Secret, error) {
out := new(model.Secret)
uri := fmt.Sprintf(pathRepoSecrets, c.base, owner, name)
err := c.post(uri, in, out)
return out, err
}

// SecretUpdate updates a secret.
func (c *client) SecretUpdate(owner, name string, in *model.Secret) (*model.Secret, error) {
out := new(model.Secret)
uri := fmt.Sprintf(pathRepoSecret, c.base, owner, name, in.Name)
err := c.patch(uri, in, out)
return out, err
}

// SecretDelete deletes a secret.
func (c *client) SecretDelete(owner, name, secret string) error {
uri := fmt.Sprintf(pathRepoSecret, c.base, owner, name, secret)
return c.delete(uri)
}

//
// http request helper functions
//
Expand Down
11 changes: 0 additions & 11 deletions drone/global.go

This file was deleted.

13 changes: 0 additions & 13 deletions drone/global_secret.go

This file was deleted.

33 changes: 0 additions & 33 deletions drone/global_secret_add.go

This file was deleted.

1 change: 0 additions & 1 deletion drone/global_secret_info.go

This file was deleted.

25 changes: 0 additions & 25 deletions drone/global_secret_list.go

This file was deleted.

25 changes: 0 additions & 25 deletions drone/global_secret_rm.go

This file was deleted.

3 changes: 0 additions & 3 deletions drone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ func main() {
registryCmd,
secretCmd,
serverCmd,
signCmd,
repoCmd,
userCmd,
orgCmd,
globalCmd,
}

if err := app.Run(os.Args); err != nil {
Expand Down
11 changes: 0 additions & 11 deletions drone/org.go

This file was deleted.

13 changes: 0 additions & 13 deletions drone/org_secret.go

This file was deleted.

Loading

0 comments on commit 8348c85

Please sign in to comment.