GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add secrets · PastureStack/cli@9c34bf4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cmd
    • inspect.go
    • rm.go
    • secret.go
  • main.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/inspect.go‎

Copy file name to clipboardExpand all lines: cmd/inspect.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
var (
11-
inspectTypes = []string{"service", "container", "host", "project", "stack", "volume"}
11+
inspectTypes = []string{"service", "container", "host", "project", "stack", "volume", "secret"}
1212
)
1313

1414
func InspectCommand() cli.Command {
Collapse file

‎cmd/rm.go‎

Copy file name to clipboardExpand all lines: cmd/rm.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
var (
12-
rmTypes = []string{"service", "container", "stack", "host", "volume"}
12+
rmTypes = []string{"service", "container", "stack", "host", "volume", "secret"}
1313
)
1414

1515
func RmCommand() cli.Command {
Collapse file

‎cmd/secret.go‎

Copy file name to clipboard
+130Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package cmd
2+
3+
import (
4+
"encoding/base64"
5+
"fmt"
6+
"io"
7+
"io/ioutil"
8+
"os"
9+
10+
"github.com/Sirupsen/logrus"
11+
"github.com/rancher/go-rancher/v2"
12+
"github.com/urfave/cli"
13+
)
14+
15+
func SecretCommand() cli.Command {
16+
secretLsFlags := []cli.Flag{
17+
cli.BoolFlag{
18+
Name: "quiet,q",
19+
Usage: "Only display IDs",
20+
},
21+
cli.StringFlag{
22+
Name: "format",
23+
Usage: "'json' or Custom format: {{.Id}} {{.Name}}",
24+
},
25+
}
26+
27+
return cli.Command{
28+
Name: "secrets",
29+
ShortName: "secret",
30+
Usage: "Operations on secrets",
31+
Action: defaultAction(secretLs),
32+
Flags: secretLsFlags,
33+
Subcommands: []cli.Command{
34+
cli.Command{
35+
Name: "ls",
36+
Usage: "List secrets",
37+
Description: "\nLists all secrets in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher secrets ls\n\t$ rancher --env 1a5 secrets ls\n",
38+
ArgsUsage: "None",
39+
Action: secretLs,
40+
Flags: secretLsFlags,
41+
},
42+
cli.Command{
43+
Name: "create",
44+
Usage: "Create a secret",
45+
Description: "\nCreate all secret in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher secret create my-name file-with-secret\n",
46+
ArgsUsage: "NAME [FILE|-]",
47+
Action: secretCreate,
48+
Flags: []cli.Flag{},
49+
},
50+
},
51+
}
52+
}
53+
54+
type SecretData struct {
55+
ID string
56+
Secret client.Secret
57+
}
58+
59+
func secretLs(ctx *cli.Context) error {
60+
c, err := GetClient(ctx)
61+
if err != nil {
62+
return err
63+
}
64+
65+
collection, err := c.Secret.List(defaultListOpts(ctx))
66+
if err != nil {
67+
return err
68+
}
69+
70+
writer := NewTableWriter([][]string{
71+
{"ID", "ID"},
72+
{"NAME", "Secret.Name"},
73+
{"CREATED", "Secret.Created"},
74+
}, ctx)
75+
76+
defer writer.Close()
77+
78+
for _, item := range collection.Data {
79+
writer.Write(&SecretData{
80+
ID: item.Id,
81+
Secret: item,
82+
})
83+
}
84+
85+
return writer.Err()
86+
}
87+
88+
func secretCreate(ctx *cli.Context) error {
89+
c, err := GetClient(ctx)
90+
if err != nil {
91+
return err
92+
}
93+
94+
w, err := NewWaiter(ctx)
95+
if err != nil {
96+
return err
97+
}
98+
99+
if ctx.NArg() != 2 {
100+
return fmt.Errorf("both NAME and FILE|- are required")
101+
}
102+
103+
name, file := ctx.Args()[0], ctx.Args()[1]
104+
var input io.Reader
105+
106+
if file == "-" {
107+
input = os.Stdin
108+
} else {
109+
input, err = os.Open(file)
110+
if os.IsNotExist(err) {
111+
logrus.Errorf("Failed to find %s, argument must be a file or -", file)
112+
}
113+
}
114+
115+
content, err := ioutil.ReadAll(input)
116+
if err != nil {
117+
return err
118+
}
119+
120+
secret, err := c.Secret.Create(&client.Secret{
121+
Name: name,
122+
Value: base64.StdEncoding.EncodeToString(content),
123+
})
124+
if err != nil {
125+
return err
126+
}
127+
128+
w.Add(secret.Id)
129+
return w.Wait()
130+
}
Collapse file

‎main.go‎

Copy file name to clipboardExpand all lines: main.go
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func mainErr() error {
136136
cmd.RmCommand(),
137137
cmd.RunCommand(),
138138
cmd.ScaleCommand(),
139+
cmd.SecretCommand(),
139140
cmd.SSHCommand(),
140141
cmd.StackCommand(),
141142
cmd.StartCommand(),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.