Skip to content

Commit d1de774

Browse files
committed
internal: refactor namespaces to be profiles
1 parent 6ce0f32 commit d1de774

File tree

15 files changed

+108
-108
lines changed

15 files changed

+108
-108
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ GLOBALS:
6868
--help/-h boolean - print help message
6969
```
7070
71-
#### set a namespace
71+
#### create/update a profile
7272
7373
```bash
7474
$ envy set example FOO=1 BAR=2 BAZ=3
7575
```
7676
77-
#### update existing variable in a namespace
77+
#### update existing variable in a profile
7878
7979
```bash
8080
$ envy set example FOO=4
8181
```
8282
83-
#### remove variable from namespace
83+
#### remove variable from profile
8484
8585
```bash
8686
$ envy set example -FOO
@@ -112,7 +112,7 @@ BAR=2
112112
BAZ-3
113113
```
114114
115-
#### list namespaces
115+
#### list available profiles
116116
117117
```bash
118118
$ envy list
@@ -122,27 +122,27 @@ nomad/e2e
122122
test
123123
```
124124
125-
#### show namespace
125+
#### show variables in a profile
126126
127127
```bash
128128
$ envy show test
129129
AWS_ACCESS_KEY_ID
130130
AWS_SECRET_ACCESS_KEY
131131
```
132132
133-
#### show namespace w/ values
133+
#### show profile variables w/ values
134134
135135
```bash
136136
$ envy show -decrypt test
137137
AWS_ACCESS_KEY_ID=aaabbbccc
138138
AWS_SECRET_ACCESS_KEY=233kjsdf309jfsd
139139
```
140140
141-
#### remove namespace
141+
#### delete profile
142142
143143
```bash
144144
$ envy purge test
145-
purged namespace "test"
145+
purged profile "test"
146146
```
147147
148148
# Contributing

internal/commands/common.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
)
1919

2020
var (
21-
argRe = regexp.MustCompile(`^(?P<key>\w+)=(?P<secret>.+)$`)
22-
namespaceRe = regexp.MustCompile(`^[-:/\w]+$`)
21+
argRe = regexp.MustCompile(`^(?P<key>\w+)=(?P<secret>.+)$`)
22+
profileRe = regexp.MustCompile(`^[-:/\w]+$`)
2323
)
2424

2525
const (
@@ -53,16 +53,16 @@ func invoke(args []string, tool *setup.Tool) babycli.Code {
5353
return r.Run()
5454
}
5555

56-
func checkName(namespace string) error {
57-
if !namespaceRe.MatchString(namespace) {
58-
return errors.New("namespace uses non-word characters")
56+
func checkName(profile string) error {
57+
if !profileRe.MatchString(profile) {
58+
return errors.New("name uses non-word characters")
5959
}
6060
return nil
6161
}
6262

6363
type Extractor interface {
64-
PreProcess(args []string) (string, *set.Set[string], *set.HashSet[*conceal.Text, int], error)
65-
Namespace(vars *set.HashSet[*conceal.Text, int]) (*safe.Namespace, error)
64+
Process(args []string) (string, *set.Set[string], *set.HashSet[*conceal.Text, int], error)
65+
Profile(vars *set.HashSet[*conceal.Text, int]) (*safe.Profile, error)
6666
}
6767

6868
type extractor struct {
@@ -75,14 +75,14 @@ func newExtractor(ring keyring.Ring) Extractor {
7575
}
7676
}
7777

78-
// PreProcess returns
79-
// - the namespace
78+
// Process returns
79+
// - the profile
8080
// - the set of keys to be removed
8181
// - the set of key/values to be added
8282
// - any error
83-
func (e *extractor) PreProcess(args []string) (string, *set.Set[string], *set.HashSet[*conceal.Text, int], error) {
83+
func (e *extractor) Process(args []string) (string, *set.Set[string], *set.HashSet[*conceal.Text, int], error) {
8484
if len(args) < 2 {
85-
return "", nil, nil, errors.New("requires at least 2 arguments (namespace, <key,...>)")
85+
return "", nil, nil, errors.New("requires at least 2 arguments (profile, <key,...>)")
8686
}
8787
ns := args[0]
8888
rm := set.New[string](4)
@@ -101,12 +101,12 @@ func (e *extractor) PreProcess(args []string) (string, *set.Set[string], *set.Ha
101101
return ns, rm, add, nil
102102
}
103103

104-
func (e *extractor) Namespace(vars *set.HashSet[*conceal.Text, int]) (*safe.Namespace, error) {
104+
func (e *extractor) Profile(vars *set.HashSet[*conceal.Text, int]) (*safe.Profile, error) {
105105
content, err := e.process(vars.Slice())
106106
if err != nil {
107107
return nil, err
108108
}
109-
return &safe.Namespace{
109+
return &safe.Profile{
110110
Name: "",
111111
Content: content,
112112
}, nil

internal/commands/exec.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func newExecCmd(tool *setup.Tool) *babycli.Component {
5757
},
5858
}
5959
}
60-
func env(tool *setup.Tool, ns *safe.Namespace, environment []string) []string {
61-
for key, value := range ns.Content {
60+
func env(tool *setup.Tool, pr *safe.Profile, environment []string) []string {
61+
for key, value := range pr.Content {
6262
secret := tool.Ring.Decrypt(value).Unveil()
6363
environment = append(environment, fmt.Sprintf(
6464
"%s=%s", key, secret,
@@ -74,13 +74,13 @@ func envContext(insulate bool) []string {
7474
return os.Environ()
7575
}
7676

77-
func newCmd(tool *setup.Tool, ns *safe.Namespace, insulate bool, argVars []string, command string, args []string) *exec.Cmd {
77+
func newCmd(tool *setup.Tool, ns *safe.Profile, insulate bool, argVars []string, command string, args []string) *exec.Cmd {
7878
ctx := context.Background()
7979
cmd := exec.CommandContext(ctx, command, args...)
8080

8181
// Environment variables are injected in the following order:
8282
// 1. OS variables if insulate is false
83-
// 2. envy namespace vars
83+
// 2. envy profile vars
8484
// 3. Variables in input args
8585
cmd.Env = append(env(tool, ns, envContext(insulate)), argVars...)
8686
cmd.Stdout = os.Stdout

internal/commands/exec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestExecCmd_ok(t *testing.T) {
4343
Box: box,
4444
}
4545

46-
box.GetMock.Expect("myNS").Return(&safe.Namespace{
46+
box.GetMock.Expect("myNS").Return(&safe.Profile{
4747
Name: "myNS",
4848
Content: map[string]safe.Encrypted{
4949
"a": {0x1},
@@ -100,7 +100,7 @@ func TestExecCmd_bad_command(t *testing.T) {
100100
Box: box,
101101
}
102102

103-
box.GetMock.Expect("myNS").Return(&safe.Namespace{
103+
box.GetMock.Expect("myNS").Return(&safe.Profile{
104104
Name: "myNS",
105105
Content: map[string]safe.Encrypted{
106106
"a": {0x1},

internal/commands/list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ func newListCmd(tool *setup.Tool) *babycli.Component {
1717
tool.Writer.Errorf("list command expects no args")
1818
return babycli.Failure
1919
}
20-
namespaces, err := tool.Box.List()
20+
profiles, err := tool.Box.List()
2121
if err != nil {
22-
tool.Writer.Errorf("unable to list namespaces: %v", err)
22+
tool.Writer.Errorf("unable to list profiles: %v", err)
2323
return babycli.Failure
2424
}
2525

26-
for _, ns := range namespaces {
27-
tool.Writer.Printf("%s", ns)
26+
for _, profile := range profiles {
27+
tool.Writer.Printf("%s", profile)
2828
}
2929
return babycli.Success
3030
},

internal/commands/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestListCmd_list_fails(t *testing.T) {
5353

5454
must.One(t, rc)
5555
must.Eq(t, "", a.String())
56-
must.Eq(t, "envy: unable to list namespaces: io error\n", b.String())
56+
must.Eq(t, "envy: unable to list profiles: io error\n", b.String())
5757
}
5858

5959
func TestListCmd_extra_args(t *testing.T) {

internal/commands/purge_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ func TestPurgeCmd_bad_profile(t *testing.T) {
7979
Box: box,
8080
}
8181

82-
// namespace must be valid
82+
// profile must be valid
8383
rc := invoke([]string{"purge", "foo=bar"}, tool)
8484

8585
must.One(t, rc)
8686
must.Eq(t, "", a.String())
87-
must.Eq(t, "envy: unable to purge profile: namespace uses non-word characters\n", b.String())
87+
must.Eq(t, "envy: unable to purge profile: name uses non-word characters\n", b.String())
8888
}
8989

9090
func TestPurgeCmd_two_arg(t *testing.T) {

internal/commands/set.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ func newSetCmd(tool *setup.Tool) *babycli.Component {
1515
Function: func(c *babycli.Component) babycli.Code {
1616
args := c.Arguments()
1717
extractor := newExtractor(tool.Ring)
18-
namespace, remove, add, err := extractor.PreProcess(args)
18+
profile, remove, add, err := extractor.Process(args)
1919
if err != nil {
2020
tool.Writer.Errorf("unable to parse args: %v", err)
2121
return babycli.Failure
2222
}
2323

24-
if err = checkName(namespace); err != nil {
25-
tool.Writer.Errorf("could not set namespace: %v", err)
24+
if err = checkName(profile); err != nil {
25+
tool.Writer.Errorf("could not set profile: %v", err)
2626
return babycli.Failure
2727
}
2828

2929
if !remove.Empty() {
30-
if err := tool.Box.Delete(namespace, remove); err != nil {
30+
if err := tool.Box.Delete(profile, remove); err != nil {
3131
tool.Writer.Errorf("coult not remove variables: %v", err)
3232
return babycli.Failure
3333
}
3434
}
3535

36-
n, err := extractor.Namespace(add)
36+
n, err := extractor.Profile(add)
3737
if err != nil {
3838
tool.Writer.Errorf("unable to parse args: %v", err)
3939
return babycli.Failure
4040
}
41-
n.Name = namespace
41+
n.Name = profile
4242

4343
if err = tool.Box.Set(n); err != nil {
4444
tool.Writer.Errorf("unable to set variables: %v", err)

internal/commands/set_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestSetCmd_ok(t *testing.T) {
2626
ring.EncryptMock.When(conceal.New("abc123")).Then(safe.Encrypted{8, 8, 8, 8, 8, 8})
2727
ring.EncryptMock.When(conceal.New("1234")).Then(safe.Encrypted{9, 9, 9, 9})
2828

29-
box.SetMock.Expect(&safe.Namespace{
29+
box.SetMock.Expect(&safe.Profile{
3030
Name: "myNS",
3131
Content: map[string]safe.Encrypted{
3232
"foo": {8, 8, 8, 8, 8, 8},
@@ -56,7 +56,7 @@ func TestSetCmd_io_error(t *testing.T) {
5656

5757
a, b, w := newWriter()
5858

59-
box.SetMock.Expect(&safe.Namespace{
59+
box.SetMock.Expect(&safe.Profile{
6060
Name: "myNS",
6161
Content: map[string]safe.Encrypted{
6262
"foo": {8, 8, 8, 8, 8, 8},
@@ -95,12 +95,12 @@ func TestSetCmd_bad_ns(t *testing.T) {
9595
Box: box,
9696
}
9797

98-
// e.g. forgot to specify namespace
98+
// e.g. forgot to specify profile
9999
rc := invoke([]string{"set", "foo=abc123", "bar=1234"}, tool)
100100

101101
must.One(t, rc)
102102
must.Eq(t, "", a.String())
103-
must.Eq(t, "envy: could not set namespace: namespace uses non-word characters\n", b.String())
103+
must.Eq(t, "envy: could not set profile: name uses non-word characters\n", b.String())
104104
}
105105

106106
func TestSetCmd_no_vars(t *testing.T) {
@@ -118,10 +118,10 @@ func TestSetCmd_no_vars(t *testing.T) {
118118
Box: box,
119119
}
120120

121-
// e.g. reminder to use purge to remove namespace
121+
// e.g. reminder to use purge to remove profile
122122
rc := invoke([]string{"set", "ns1"}, tool)
123123

124124
must.One(t, rc)
125125
must.Eq(t, "", a.String())
126-
must.Eq(t, "envy: unable to parse args: requires at least 2 arguments (namespace, <key,...>)\n", b.String())
126+
must.Eq(t, "envy: unable to parse args: requires at least 2 arguments (profile, <key,...>)\n", b.String())
127127
}

internal/commands/show_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestShowCmd_Execute(t *testing.T) {
2828
Box: box,
2929
}
3030

31-
box.GetMock.Expect("myNS").Return(&safe.Namespace{
31+
box.GetMock.Expect("myNS").Return(&safe.Profile{
3232
Name: "myNS",
3333
Content: map[string]safe.Encrypted{
3434
"foo": {1, 1, 1},
@@ -58,7 +58,7 @@ func TestShowCmd_Execute_unveil(t *testing.T) {
5858
Box: box,
5959
}
6060

61-
box.GetMock.Expect("myNS").Return(&safe.Namespace{
61+
box.GetMock.Expect("myNS").Return(&safe.Profile{
6262
Name: "myNS",
6363
Content: map[string]safe.Encrypted{
6464
"foo": {1, 1, 1},

0 commit comments

Comments
 (0)