Skip to content

Commit a63407a

Browse files
committed
added environment command
1 parent bed84a3 commit a63407a

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

drone/plugins/environ/environ.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package environ
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/drone/drone-cli/drone/internal"
8+
"github.com/drone/drone-go/drone"
9+
"github.com/drone/drone-go/plugin/environ"
10+
"github.com/urfave/cli"
11+
)
12+
13+
// Command exports the admission command set.
14+
var Command = cli.Command{
15+
Name: "env",
16+
Usage: "test env extensions",
17+
Action: environAction,
18+
Flags: []cli.Flag{
19+
20+
//
21+
// build and repository details
22+
//
23+
24+
cli.StringFlag{
25+
Name: "ref",
26+
Usage: "git reference",
27+
Value: "refs/heads/master",
28+
},
29+
cli.StringFlag{
30+
Name: "source",
31+
Usage: "source branch",
32+
Value: "master",
33+
},
34+
cli.StringFlag{
35+
Name: "target",
36+
Usage: "target branch",
37+
Value: "master",
38+
},
39+
cli.StringFlag{
40+
Name: "before",
41+
Usage: "commit sha before the change",
42+
},
43+
cli.StringFlag{
44+
Name: "after",
45+
Usage: "commit sha after the change",
46+
},
47+
cli.StringFlag{
48+
Name: "repository",
49+
Usage: "repository name",
50+
},
51+
52+
cli.StringFlag{
53+
Name: "endpoint",
54+
Usage: "plugin endpoint",
55+
EnvVar: "DRONE_ENVIRON_ENDPOINT",
56+
},
57+
cli.StringFlag{
58+
Name: "secret",
59+
Usage: "plugin secret",
60+
EnvVar: "DRONE_ENVIRON_SECRET",
61+
},
62+
cli.StringFlag{
63+
Name: "ssl-skip-verify",
64+
Usage: "plugin ssl verification disabled",
65+
EnvVar: "DRONE_ENVIRON_SKIP_VERIFY",
66+
},
67+
},
68+
}
69+
70+
func environAction(c *cli.Context) error {
71+
slug := c.String("repository")
72+
owner, name, _ := internal.ParseRepo(slug)
73+
74+
req := &environ.Request{
75+
Repo: drone.Repo{
76+
Namespace: owner,
77+
Name: name,
78+
Slug: slug,
79+
},
80+
Build: drone.Build{
81+
Ref: c.String("ref"),
82+
Before: c.String("before"),
83+
After: c.String("after"),
84+
Source: c.String("source"),
85+
Target: c.String("target"),
86+
},
87+
}
88+
89+
client := environ.Client(
90+
c.String("endpoint"),
91+
c.String("secret"),
92+
c.Bool("ssl-skip-verify"),
93+
)
94+
list, err := client.List(context.Background(), req)
95+
if err != nil {
96+
return err
97+
}
98+
99+
for k, v := range list {
100+
fmt.Printf("%s=%s\n", k, v)
101+
}
102+
return nil
103+
}

drone/plugins/plugins.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/drone/drone-cli/drone/plugins/admit"
55
"github.com/drone/drone-cli/drone/plugins/config"
66
"github.com/drone/drone-cli/drone/plugins/convert"
7+
"github.com/drone/drone-cli/drone/plugins/environ"
78
"github.com/drone/drone-cli/drone/plugins/registry"
89
"github.com/drone/drone-cli/drone/plugins/secret"
910

@@ -18,7 +19,8 @@ var Command = cli.Command{
1819
admit.Command,
1920
config.Command,
2021
convert.Command,
21-
secret.Command,
22+
environ.Command,
2223
registry.Command,
24+
secret.Command,
2325
},
2426
}

0 commit comments

Comments
 (0)