Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for drone 1.x #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
drone-secrets

.idea/
74 changes: 58 additions & 16 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test:
@for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;

$(EXECUTABLE): $(wildcard *.go)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-s -w $(LDFLAGS)'
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-s -w $(LDFLAGS)' -o drone-secrets-linux-amd64
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-s -w $(LDFLAGS)' -o drone-secrets-darwin-amd64

builddev:
go build -ldflags '-s -w $(LDFLAGS)'
Expand Down
20 changes: 5 additions & 15 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ var Command = cli.Command{
},
}

var defaultSecretEvents = []string{
drone.EventPush,
drone.EventTag,
drone.EventDeploy,
}

func run(c *cli.Context) error {
manifest, err := mfst.Load(c.String("manifest"))
if err != nil {
Expand All @@ -44,10 +38,10 @@ func run(c *cli.Context) error {
return err
}

return processManifest(c, client, manifest)
return processManifest(client, manifest)
}

func processManifest(c *cli.Context, client drone.Client, manifest mfst.SecretsManifest) error {
func processManifest(client drone.Client, manifest mfst.SecretsManifest) error {
for _, manifestSecret := range manifest {
if err := ensureSecrets(client, &manifestSecret); err != nil {
return err
Expand Down Expand Up @@ -81,17 +75,13 @@ func ensureSecretsForRepo(client drone.Client, manifestSecret *mfst.SecretDef, r
return err
}

if len(secret.Events) == 0 {
secret.Events = defaultSecretEvents
}

if strings.HasPrefix(secret.Value, "@") {
path := strings.TrimPrefix(secret.Value, "@")
if strings.HasPrefix(secret.Data, "@") {
path := strings.TrimPrefix(secret.Data, "@")
out, err := ioutil.ReadFile(path)
if err != nil {
return err
}
secret.Value = string(out)
secret.Data = string(out)
}

_, serr := client.Secret(owner, name, secret.Name)
Expand Down
10 changes: 0 additions & 10 deletions examples/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,12 @@
# Comma delimited or list accepted (for value images and events keys)
- name: SLACK_WEBHOOK
value: abcde
events: push,tag
images:
- plugins/slack
- plugins/slack:*

# Setting value to a list
# List types are converted to a comma delimited string
- name: PLUGINS_ENVIRONMENT_VARIABLES
events:
- push
- tag
value:
- PORT=1234
- SECRET_TOKEN=abcd1234
# Same as:
# value: PORT=1234,SECRET_TOKEN=abcde1234,...
images:
- plugins/ecs
- plugins/ecs:*
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/urfave/cli"
)

const version string = "0.0.5"
const version string = "0.1.0"

func main() {
app := cli.NewApp()
Expand Down
33 changes: 4 additions & 29 deletions manifest/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package manifest

import (
"fmt"
"strings"

"github.com/drone/drone-go/drone"
Expand All @@ -10,8 +9,7 @@ import (
type Secret struct {
Name string `yaml:name`
Value StringArray `yaml:value`
Images StringArray `yaml:images`
Events StringArray `yaml:events`
EnablePullRequests bool `yaml:enable_pull_requests`
}

type SecretDef struct {
Expand Down Expand Up @@ -42,39 +40,16 @@ func (a *StringArray) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}

func toDroneEvent(event string) (string, error) {
switch event {
case "pr", "pull-request", "pull":
return drone.EventPull, nil
case "push":
return drone.EventPush, nil
case "tag":
return drone.EventTag, nil
case "deployment":
return drone.EventDeploy, nil

default:
return "", fmt.Errorf("manifest: Invalid event type '%s'", event)
}
}

func (inst *Secret) ToDroneSecret() (*drone.Secret, error) {
converted := &drone.Secret{}
converted.Name = inst.Name

if len(inst.Value) != 0 {
converted.Value = strings.Join(inst.Value, ",")
converted.Data = strings.Join(inst.Value, ",")
}
converted.Images = inst.Images

for _, evt := range inst.Events {
convertedEvt, err := toDroneEvent(evt)
if err != nil {
return converted, err
}

converted.Events = append(converted.Events, convertedEvt)
}
converted.PullRequestPush = inst.EnablePullRequests;
converted.PullRequest = inst.EnablePullRequests;

return converted, nil
}
6 changes: 6 additions & 0 deletions vendor/github.com/drone/drone-go/NOTICE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading