-
Notifications
You must be signed in to change notification settings - Fork 180
/
get.go
111 lines (101 loc) · 2.11 KB
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package secret
import (
"context"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/drone/drone-go/plugin/secret"
"github.com/urfave/cli"
)
var secretFindCmd = cli.Command{
Name: "get",
Usage: "get the named secret",
ArgsUsage: "secret",
Action: secretFind,
Flags: []cli.Flag{
cli.StringFlag{
Name: "ref",
Usage: "git reference",
Value: "refs/heads/master",
},
cli.StringFlag{
Name: "source",
Usage: "source branch",
},
cli.StringFlag{
Name: "target",
Usage: "target branch",
},
cli.StringFlag{
Name: "before",
Usage: "commit sha before the change",
},
cli.StringFlag{
Name: "after",
Usage: "commit sha after the change",
},
cli.StringFlag{
Name: "event",
Usage: "build event",
},
cli.StringFlag{
Name: "repo",
Usage: "repository name",
},
// TODO(bradrydzewski) these parameters should
// be defined globally for all plugin commands.
cli.StringFlag{
Name: "endpoint",
Usage: "plugin endpoint",
EnvVar: "DRONE_SECRET_ENDPOINT",
},
cli.StringFlag{
Name: "secret",
Usage: "plugin secret",
EnvVar: "DRONE_SECRET_SECRET, DRONE_SECRET_PLUGIN_TOKEN",
},
cli.StringFlag{
Name: "ssl-skip-verify",
Usage: "plugin ssl verification disabled",
EnvVar: "DRONE_SECRET_VERIFY",
},
},
}
func secretFind(c *cli.Context) error {
path := c.Args().First()
key := c.Args().Get(1)
slug := c.String("repo")
owner, name, err := internal.ParseRepo(slug)
if err != nil {
return err
}
repo := drone.Repo{
Namespace: owner,
Name: name,
Slug: slug,
}
build := drone.Build{
Ref: c.String("ref"),
Before: c.String("before"),
After: c.String("after"),
Source: c.String("source"),
Target: c.String("target"),
Event: c.String("event"),
}
req := &secret.Request{
Path: path,
Name: key,
Repo: repo,
Build: build,
}
client := secret.Client(
c.String("endpoint"),
c.String("secret"),
c.Bool("ssl-skip-verify"),
)
res, err := client.Find(context.Background(), req)
if err != nil {
return err
}
println(res.Data)
return nil
}