From ac6ab3f5ea8f7e5f2e2557147cacf2a299e851c0 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Sun, 25 Aug 2024 12:16:35 -0500 Subject: [PATCH] internal: refactor namespaces to be profiles --- README.md | 16 +++++----- internal/commands/common.go | 26 ++++++++--------- internal/commands/exec.go | 8 ++--- internal/commands/exec_test.go | 4 +-- internal/commands/list.go | 8 ++--- internal/commands/list_test.go | 2 +- internal/commands/purge_test.go | 4 +-- internal/commands/set.go | 12 ++++---- internal/commands/set_test.go | 12 ++++---- internal/commands/show_test.go | 4 +-- internal/safe/box_mock.go | 28 +++++++++--------- internal/safe/namespace.go | 6 ++-- internal/safe/namespace_test.go | 6 ++-- internal/safe/safe.go | 52 ++++++++++++++++----------------- internal/safe/safe_test.go | 28 +++++++++--------- 15 files changed, 108 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index fa5ccdc..b4c922d 100644 --- a/README.md +++ b/README.md @@ -68,19 +68,19 @@ GLOBALS: --help/-h boolean - print help message ``` -#### set a namespace +#### create/update a profile ```bash $ envy set example FOO=1 BAR=2 BAZ=3 ``` -#### update existing variable in a namespace +#### update existing variable in a profile ```bash $ envy set example FOO=4 ``` -#### remove variable from namespace +#### remove variable from profile ```bash $ envy set example -FOO @@ -112,7 +112,7 @@ BAR=2 BAZ-3 ``` -#### list namespaces +#### list available profiles ```bash $ envy list @@ -122,7 +122,7 @@ nomad/e2e test ``` -#### show namespace +#### show variables in a profile ```bash $ envy show test @@ -130,7 +130,7 @@ AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY ``` -#### show namespace w/ values +#### show profile variables w/ values ```bash $ envy show -decrypt test @@ -138,11 +138,11 @@ AWS_ACCESS_KEY_ID=aaabbbccc AWS_SECRET_ACCESS_KEY=233kjsdf309jfsd ``` -#### remove namespace +#### delete profile ```bash $ envy purge test -purged namespace "test" +purged profile "test" ``` # Contributing diff --git a/internal/commands/common.go b/internal/commands/common.go index 0985882..e4df300 100644 --- a/internal/commands/common.go +++ b/internal/commands/common.go @@ -18,8 +18,8 @@ import ( ) var ( - argRe = regexp.MustCompile(`^(?P\w+)=(?P.+)$`) - namespaceRe = regexp.MustCompile(`^[-:/\w]+$`) + argRe = regexp.MustCompile(`^(?P\w+)=(?P.+)$`) + profileRe = regexp.MustCompile(`^[-:/\w]+$`) ) const ( @@ -53,16 +53,16 @@ func invoke(args []string, tool *setup.Tool) babycli.Code { return r.Run() } -func checkName(namespace string) error { - if !namespaceRe.MatchString(namespace) { - return errors.New("namespace uses non-word characters") +func checkName(profile string) error { + if !profileRe.MatchString(profile) { + return errors.New("name uses non-word characters") } return nil } type Extractor interface { - PreProcess(args []string) (string, *set.Set[string], *set.HashSet[*conceal.Text, int], error) - Namespace(vars *set.HashSet[*conceal.Text, int]) (*safe.Namespace, error) + Process(args []string) (string, *set.Set[string], *set.HashSet[*conceal.Text, int], error) + Profile(vars *set.HashSet[*conceal.Text, int]) (*safe.Profile, error) } type extractor struct { @@ -75,14 +75,14 @@ func newExtractor(ring keyring.Ring) Extractor { } } -// PreProcess returns -// - the namespace +// Process returns +// - the profile // - the set of keys to be removed // - the set of key/values to be added // - any error -func (e *extractor) PreProcess(args []string) (string, *set.Set[string], *set.HashSet[*conceal.Text, int], error) { +func (e *extractor) Process(args []string) (string, *set.Set[string], *set.HashSet[*conceal.Text, int], error) { if len(args) < 2 { - return "", nil, nil, errors.New("requires at least 2 arguments (namespace, )") + return "", nil, nil, errors.New("requires at least 2 arguments (profile, )") } ns := args[0] rm := set.New[string](4) @@ -101,12 +101,12 @@ func (e *extractor) PreProcess(args []string) (string, *set.Set[string], *set.Ha return ns, rm, add, nil } -func (e *extractor) Namespace(vars *set.HashSet[*conceal.Text, int]) (*safe.Namespace, error) { +func (e *extractor) Profile(vars *set.HashSet[*conceal.Text, int]) (*safe.Profile, error) { content, err := e.process(vars.Slice()) if err != nil { return nil, err } - return &safe.Namespace{ + return &safe.Profile{ Name: "", Content: content, }, nil diff --git a/internal/commands/exec.go b/internal/commands/exec.go index 14002c7..3ca035a 100644 --- a/internal/commands/exec.go +++ b/internal/commands/exec.go @@ -57,8 +57,8 @@ func newExecCmd(tool *setup.Tool) *babycli.Component { }, } } -func env(tool *setup.Tool, ns *safe.Namespace, environment []string) []string { - for key, value := range ns.Content { +func env(tool *setup.Tool, pr *safe.Profile, environment []string) []string { + for key, value := range pr.Content { secret := tool.Ring.Decrypt(value).Unveil() environment = append(environment, fmt.Sprintf( "%s=%s", key, secret, @@ -74,13 +74,13 @@ func envContext(insulate bool) []string { return os.Environ() } -func newCmd(tool *setup.Tool, ns *safe.Namespace, insulate bool, argVars []string, command string, args []string) *exec.Cmd { +func newCmd(tool *setup.Tool, ns *safe.Profile, insulate bool, argVars []string, command string, args []string) *exec.Cmd { ctx := context.Background() cmd := exec.CommandContext(ctx, command, args...) // Environment variables are injected in the following order: // 1. OS variables if insulate is false - // 2. envy namespace vars + // 2. envy profile vars // 3. Variables in input args cmd.Env = append(env(tool, ns, envContext(insulate)), argVars...) cmd.Stdout = os.Stdout diff --git a/internal/commands/exec_test.go b/internal/commands/exec_test.go index 90f143a..88f3192 100644 --- a/internal/commands/exec_test.go +++ b/internal/commands/exec_test.go @@ -43,7 +43,7 @@ func TestExecCmd_ok(t *testing.T) { Box: box, } - box.GetMock.Expect("myNS").Return(&safe.Namespace{ + box.GetMock.Expect("myNS").Return(&safe.Profile{ Name: "myNS", Content: map[string]safe.Encrypted{ "a": {0x1}, @@ -100,7 +100,7 @@ func TestExecCmd_bad_command(t *testing.T) { Box: box, } - box.GetMock.Expect("myNS").Return(&safe.Namespace{ + box.GetMock.Expect("myNS").Return(&safe.Profile{ Name: "myNS", Content: map[string]safe.Encrypted{ "a": {0x1}, diff --git a/internal/commands/list.go b/internal/commands/list.go index 9183007..d1e232a 100644 --- a/internal/commands/list.go +++ b/internal/commands/list.go @@ -17,14 +17,14 @@ func newListCmd(tool *setup.Tool) *babycli.Component { tool.Writer.Errorf("list command expects no args") return babycli.Failure } - namespaces, err := tool.Box.List() + profiles, err := tool.Box.List() if err != nil { - tool.Writer.Errorf("unable to list namespaces: %v", err) + tool.Writer.Errorf("unable to list profiles: %v", err) return babycli.Failure } - for _, ns := range namespaces { - tool.Writer.Printf("%s", ns) + for _, profile := range profiles { + tool.Writer.Printf("%s", profile) } return babycli.Success }, diff --git a/internal/commands/list_test.go b/internal/commands/list_test.go index a3bfc60..1b80e79 100644 --- a/internal/commands/list_test.go +++ b/internal/commands/list_test.go @@ -53,7 +53,7 @@ func TestListCmd_list_fails(t *testing.T) { must.One(t, rc) must.Eq(t, "", a.String()) - must.Eq(t, "envy: unable to list namespaces: io error\n", b.String()) + must.Eq(t, "envy: unable to list profiles: io error\n", b.String()) } func TestListCmd_extra_args(t *testing.T) { diff --git a/internal/commands/purge_test.go b/internal/commands/purge_test.go index 37d742c..0b70fe5 100644 --- a/internal/commands/purge_test.go +++ b/internal/commands/purge_test.go @@ -79,12 +79,12 @@ func TestPurgeCmd_bad_profile(t *testing.T) { Box: box, } - // namespace must be valid + // profile must be valid rc := invoke([]string{"purge", "foo=bar"}, tool) must.One(t, rc) must.Eq(t, "", a.String()) - must.Eq(t, "envy: unable to purge profile: namespace uses non-word characters\n", b.String()) + must.Eq(t, "envy: unable to purge profile: name uses non-word characters\n", b.String()) } func TestPurgeCmd_two_arg(t *testing.T) { diff --git a/internal/commands/set.go b/internal/commands/set.go index 1e38ebe..b646163 100644 --- a/internal/commands/set.go +++ b/internal/commands/set.go @@ -15,30 +15,30 @@ func newSetCmd(tool *setup.Tool) *babycli.Component { Function: func(c *babycli.Component) babycli.Code { args := c.Arguments() extractor := newExtractor(tool.Ring) - namespace, remove, add, err := extractor.PreProcess(args) + profile, remove, add, err := extractor.Process(args) if err != nil { tool.Writer.Errorf("unable to parse args: %v", err) return babycli.Failure } - if err = checkName(namespace); err != nil { - tool.Writer.Errorf("could not set namespace: %v", err) + if err = checkName(profile); err != nil { + tool.Writer.Errorf("could not set profile: %v", err) return babycli.Failure } if !remove.Empty() { - if err := tool.Box.Delete(namespace, remove); err != nil { + if err := tool.Box.Delete(profile, remove); err != nil { tool.Writer.Errorf("coult not remove variables: %v", err) return babycli.Failure } } - n, err := extractor.Namespace(add) + n, err := extractor.Profile(add) if err != nil { tool.Writer.Errorf("unable to parse args: %v", err) return babycli.Failure } - n.Name = namespace + n.Name = profile if err = tool.Box.Set(n); err != nil { tool.Writer.Errorf("unable to set variables: %v", err) diff --git a/internal/commands/set_test.go b/internal/commands/set_test.go index a787592..6749cd9 100644 --- a/internal/commands/set_test.go +++ b/internal/commands/set_test.go @@ -26,7 +26,7 @@ func TestSetCmd_ok(t *testing.T) { ring.EncryptMock.When(conceal.New("abc123")).Then(safe.Encrypted{8, 8, 8, 8, 8, 8}) ring.EncryptMock.When(conceal.New("1234")).Then(safe.Encrypted{9, 9, 9, 9}) - box.SetMock.Expect(&safe.Namespace{ + box.SetMock.Expect(&safe.Profile{ Name: "myNS", Content: map[string]safe.Encrypted{ "foo": {8, 8, 8, 8, 8, 8}, @@ -56,7 +56,7 @@ func TestSetCmd_io_error(t *testing.T) { a, b, w := newWriter() - box.SetMock.Expect(&safe.Namespace{ + box.SetMock.Expect(&safe.Profile{ Name: "myNS", Content: map[string]safe.Encrypted{ "foo": {8, 8, 8, 8, 8, 8}, @@ -95,12 +95,12 @@ func TestSetCmd_bad_ns(t *testing.T) { Box: box, } - // e.g. forgot to specify namespace + // e.g. forgot to specify profile rc := invoke([]string{"set", "foo=abc123", "bar=1234"}, tool) must.One(t, rc) must.Eq(t, "", a.String()) - must.Eq(t, "envy: could not set namespace: namespace uses non-word characters\n", b.String()) + must.Eq(t, "envy: could not set profile: name uses non-word characters\n", b.String()) } func TestSetCmd_no_vars(t *testing.T) { @@ -118,10 +118,10 @@ func TestSetCmd_no_vars(t *testing.T) { Box: box, } - // e.g. reminder to use purge to remove namespace + // e.g. reminder to use purge to remove profile rc := invoke([]string{"set", "ns1"}, tool) must.One(t, rc) must.Eq(t, "", a.String()) - must.Eq(t, "envy: unable to parse args: requires at least 2 arguments (namespace, )\n", b.String()) + must.Eq(t, "envy: unable to parse args: requires at least 2 arguments (profile, )\n", b.String()) } diff --git a/internal/commands/show_test.go b/internal/commands/show_test.go index aec04a5..a3273f5 100644 --- a/internal/commands/show_test.go +++ b/internal/commands/show_test.go @@ -28,7 +28,7 @@ func TestShowCmd_Execute(t *testing.T) { Box: box, } - box.GetMock.Expect("myNS").Return(&safe.Namespace{ + box.GetMock.Expect("myNS").Return(&safe.Profile{ Name: "myNS", Content: map[string]safe.Encrypted{ "foo": {1, 1, 1}, @@ -58,7 +58,7 @@ func TestShowCmd_Execute_unveil(t *testing.T) { Box: box, } - box.GetMock.Expect("myNS").Return(&safe.Namespace{ + box.GetMock.Expect("myNS").Return(&safe.Profile{ Name: "myNS", Content: map[string]safe.Encrypted{ "foo": {1, 1, 1}, diff --git a/internal/safe/box_mock.go b/internal/safe/box_mock.go index 964d304..19e5c7f 100644 --- a/internal/safe/box_mock.go +++ b/internal/safe/box_mock.go @@ -21,7 +21,7 @@ type BoxMock struct { beforeDeleteCounter uint64 DeleteMock mBoxMockDelete - funcGet func(s1 string) (np1 *Namespace, err error) + funcGet func(s1 string) (np1 *Profile, err error) inspectFuncGet func(s1 string) afterGetCounter uint64 beforeGetCounter uint64 @@ -39,8 +39,8 @@ type BoxMock struct { beforePurgeCounter uint64 PurgeMock mBoxMockPurge - funcSet func(np1 *Namespace) (err error) - inspectFuncSet func(np1 *Namespace) + funcSet func(np1 *Profile) (err error) + inspectFuncSet func(np1 *Profile) afterSetCounter uint64 beforeSetCounter uint64 SetMock mBoxMockSet @@ -310,7 +310,7 @@ type BoxMockGetParams struct { // BoxMockGetResults contains results of the Box.Get type BoxMockGetResults struct { - np1 *Namespace + np1 *Profile err error } @@ -346,7 +346,7 @@ func (mmGet *mBoxMockGet) Inspect(f func(s1 string)) *mBoxMockGet { } // Return sets up results that will be returned by Box.Get -func (mmGet *mBoxMockGet) Return(np1 *Namespace, err error) *BoxMock { +func (mmGet *mBoxMockGet) Return(np1 *Profile, err error) *BoxMock { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("BoxMock.Get mock is already set by Set") } @@ -359,7 +359,7 @@ func (mmGet *mBoxMockGet) Return(np1 *Namespace, err error) *BoxMock { } // Set uses given function f to mock the Box.Get method -func (mmGet *mBoxMockGet) Set(f func(s1 string) (np1 *Namespace, err error)) *BoxMock { +func (mmGet *mBoxMockGet) Set(f func(s1 string) (np1 *Profile, err error)) *BoxMock { if mmGet.defaultExpectation != nil { mmGet.mock.t.Fatalf("Default expectation is already set for the Box.Get method") } @@ -388,13 +388,13 @@ func (mmGet *mBoxMockGet) When(s1 string) *BoxMockGetExpectation { } // Then sets up Box.Get return parameters for the expectation previously defined by the When method -func (e *BoxMockGetExpectation) Then(np1 *Namespace, err error) *BoxMock { +func (e *BoxMockGetExpectation) Then(np1 *Profile, err error) *BoxMock { e.results = &BoxMockGetResults{np1, err} return e.mock } // Get implements Box -func (mmGet *BoxMock) Get(s1 string) (np1 *Namespace, err error) { +func (mmGet *BoxMock) Get(s1 string) (np1 *Profile, err error) { mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1) defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1) @@ -880,7 +880,7 @@ type BoxMockSetExpectation struct { // BoxMockSetParams contains parameters of the Box.Set type BoxMockSetParams struct { - np1 *Namespace + np1 *Profile } // BoxMockSetResults contains results of the Box.Set @@ -889,7 +889,7 @@ type BoxMockSetResults struct { } // Expect sets up expected params for Box.Set -func (mmSet *mBoxMockSet) Expect(np1 *Namespace) *mBoxMockSet { +func (mmSet *mBoxMockSet) Expect(np1 *Profile) *mBoxMockSet { if mmSet.mock.funcSet != nil { mmSet.mock.t.Fatalf("BoxMock.Set mock is already set by Set") } @@ -909,7 +909,7 @@ func (mmSet *mBoxMockSet) Expect(np1 *Namespace) *mBoxMockSet { } // Inspect accepts an inspector function that has same arguments as the Box.Set -func (mmSet *mBoxMockSet) Inspect(f func(np1 *Namespace)) *mBoxMockSet { +func (mmSet *mBoxMockSet) Inspect(f func(np1 *Profile)) *mBoxMockSet { if mmSet.mock.inspectFuncSet != nil { mmSet.mock.t.Fatalf("Inspect function is already set for BoxMock.Set") } @@ -933,7 +933,7 @@ func (mmSet *mBoxMockSet) Return(err error) *BoxMock { } // Set uses given function f to mock the Box.Set method -func (mmSet *mBoxMockSet) Set(f func(np1 *Namespace) (err error)) *BoxMock { +func (mmSet *mBoxMockSet) Set(f func(np1 *Profile) (err error)) *BoxMock { if mmSet.defaultExpectation != nil { mmSet.mock.t.Fatalf("Default expectation is already set for the Box.Set method") } @@ -948,7 +948,7 @@ func (mmSet *mBoxMockSet) Set(f func(np1 *Namespace) (err error)) *BoxMock { // When sets expectation for the Box.Set which will trigger the result defined by the following // Then helper -func (mmSet *mBoxMockSet) When(np1 *Namespace) *BoxMockSetExpectation { +func (mmSet *mBoxMockSet) When(np1 *Profile) *BoxMockSetExpectation { if mmSet.mock.funcSet != nil { mmSet.mock.t.Fatalf("BoxMock.Set mock is already set by Set") } @@ -968,7 +968,7 @@ func (e *BoxMockSetExpectation) Then(err error) *BoxMock { } // Set implements Box -func (mmSet *BoxMock) Set(np1 *Namespace) (err error) { +func (mmSet *BoxMock) Set(np1 *Profile) (err error) { mm_atomic.AddUint64(&mmSet.beforeSetCounter, 1) defer mm_atomic.AddUint64(&mmSet.afterSetCounter, 1) diff --git a/internal/safe/namespace.go b/internal/safe/namespace.go index b2c1ef8..ae0ba4f 100644 --- a/internal/safe/namespace.go +++ b/internal/safe/namespace.go @@ -11,17 +11,17 @@ import ( type Encrypted []byte -type Namespace struct { +type Profile struct { Name string Content map[string]Encrypted } -func (ns *Namespace) String() string { +func (ns *Profile) String() string { keys := ns.Keys() return fmt.Sprintf("(%s [%s])", ns.Name, strings.Join(keys, " ")) } -func (ns *Namespace) Keys() []string { +func (ns *Profile) Keys() []string { keys := make([]string, 0, len(ns.Content)) for key := range ns.Content { keys = append(keys, key) diff --git a/internal/safe/namespace_test.go b/internal/safe/namespace_test.go index 2d8af80..a5cbc3e 100644 --- a/internal/safe/namespace_test.go +++ b/internal/safe/namespace_test.go @@ -9,15 +9,15 @@ import ( "github.com/shoenig/test/must" ) -func TestNamespace_String(t *testing.T) { - ns := &Namespace{ +func TestProfile_String(t *testing.T) { + pr := &Profile{ Name: "ns1", Content: map[string]Encrypted{ "foo": []byte{1, 1, 1, 1, 1}, "bar": []byte{2, 2, 2, 2, 2}, }, } - s := ns.String() + s := pr.String() exp := "(ns1 [bar foo])" must.Eq(t, exp, s) } diff --git a/internal/safe/safe.go b/internal/safe/safe.go index a326b4d..a094996 100644 --- a/internal/safe/safe.go +++ b/internal/safe/safe.go @@ -42,10 +42,10 @@ func Path(dbFile string) (string, error) { // //go:generate go run github.com/gojuno/minimock/v3/cmd/minimock@v3.0.10 -g -i Box -s _mock.go type Box interface { - Set(*Namespace) error + Set(*Profile) error Delete(string, *set.Set[string]) error Purge(string) error - Get(string) (*Namespace, error) + Get(string) (*Profile, error) List() ([]string, error) } @@ -100,18 +100,18 @@ func (b *box) close(openErr error) { b.database = nil } -func bucket(create bool, tx *bbolt.Tx, namespace string) (*bbolt.Bucket, error) { +func bucket(create bool, tx *bbolt.Tx, profile string) (*bbolt.Bucket, error) { if create { - return tx.CreateBucketIfNotExists([]byte(namespace)) + return tx.CreateBucketIfNotExists([]byte(profile)) } - if bkt := tx.Bucket([]byte(namespace)); bkt != nil { + if bkt := tx.Bucket([]byte(profile)); bkt != nil { return bkt, nil } - return nil, errors.Errorf("namespace %q does not exist", namespace) + return nil, errors.Errorf("profile %q does not exist", profile) } -func put(bkt *bbolt.Bucket, ns *Namespace) error { - for k, v := range ns.Content { +func put(bkt *bbolt.Bucket, pr *Profile) error { + for k, v := range pr.Content { if err := bkt.Put([]byte(k), []byte(v)); err != nil { return err } @@ -119,35 +119,35 @@ func put(bkt *bbolt.Bucket, ns *Namespace) error { return nil } -// Purge will delete the namespace, including any existing content. -func (b *box) Purge(namespace string) error { +// Purge will delete the profile, including any existing content. +func (b *box) Purge(profile string) error { defer b.close(b.open()) return b.database.Update(func(tx *bbolt.Tx) error { - return tx.DeleteBucket([]byte(namespace)) + return tx.DeleteBucket([]byte(profile)) }) } // Set will amend the content of ns. Any overlapping pre-existing values will be // overwritten. -func (b *box) Set(ns *Namespace) error { +func (b *box) Set(pr *Profile) error { defer b.close(b.open()) return b.database.Update(func(tx *bbolt.Tx) error { - bkt, err := bucket(true, tx, ns.Name) + bkt, err := bucket(true, tx, pr.Name) if err != nil { return err } - return put(bkt, ns) + return put(bkt, pr) }) } -// Delete will remove keys from namespace. -func (b *box) Delete(namespace string, keys *set.Set[string]) error { +// Delete will remove keys from profile. +func (b *box) Delete(profile string, keys *set.Set[string]) error { defer b.close(b.open()) return b.database.Update(func(tx *bbolt.Tx) error { - bkt, err := bucket(true, tx, namespace) + bkt, err := bucket(true, tx, profile) if err != nil { return err } @@ -161,13 +161,13 @@ func (b *box) Delete(namespace string, keys *set.Set[string]) error { }) } -// Get will return the contents of namespace. -func (b *box) Get(namespace string) (*Namespace, error) { +// Get will return the contents of profile. +func (b *box) Get(profile string) (*Profile, error) { defer b.close(b.open()) content := make(map[string]Encrypted) if err := b.database.View(func(tx *bbolt.Tx) error { - bkt, err := bucket(false, tx, namespace) + bkt, err := bucket(false, tx, profile) if err != nil { return err } @@ -184,24 +184,24 @@ func (b *box) Get(namespace string) (*Namespace, error) { return nil, err } - return &Namespace{ - Name: namespace, + return &Profile{ + Name: profile, Content: content, }, nil } -// List will return a list of namespaces that have been created. +// List will return a list of profile that have been created. func (b *box) List() ([]string, error) { defer b.close(b.open()) - var namespaces []string + var profiles []string if err := b.database.View(func(tx *bbolt.Tx) error { return tx.ForEach(func(ns []byte, _ *bbolt.Bucket) error { - namespaces = append(namespaces, string(ns)) + profiles = append(profiles, string(ns)) return nil }) }); err != nil { return nil, err } - return namespaces, nil + return profiles, nil } diff --git a/internal/safe/safe_test.go b/internal/safe/safe_test.go index 6b786df..4bb3da9 100644 --- a/internal/safe/safe_test.go +++ b/internal/safe/safe_test.go @@ -45,10 +45,10 @@ func TestSafe_Set(t *testing.T) { b := New(newFile(t)) _, err := b.Get("does-not-exist") - must.EqError(t, err, "namespace \"does-not-exist\" does not exist") + must.EqError(t, err, "profile \"does-not-exist\" does not exist") // set ns1 first time - err = b.Set(&Namespace{ + err = b.Set(&Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"), @@ -58,7 +58,7 @@ func TestSafe_Set(t *testing.T) { must.NoError(t, err) // set ns2 first time - err = b.Set(&Namespace{ + err = b.Set(&Profile{ Name: "ns2", Content: map[string]Encrypted{ "keyA": []byte("foo"), @@ -69,7 +69,7 @@ func TestSafe_Set(t *testing.T) { ns1, err := b.Get("ns1") must.NoError(t, err) - must.Eq(t, &Namespace{ + must.Eq(t, &Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"), @@ -79,7 +79,7 @@ func TestSafe_Set(t *testing.T) { ns2, err := b.Get("ns2") must.NoError(t, err) - must.Eq(t, &Namespace{ + must.Eq(t, &Profile{ Name: "ns2", Content: map[string]Encrypted{ "keyA": []byte("foo"), @@ -88,7 +88,7 @@ func TestSafe_Set(t *testing.T) { }, ns2) // set ns2 second time - err = b.Set(&Namespace{ + err = b.Set(&Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"), @@ -100,7 +100,7 @@ func TestSafe_Set(t *testing.T) { ns1, err = b.Get("ns1") must.NoError(t, err) - must.Eq(t, &Namespace{ + must.Eq(t, &Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"), @@ -114,7 +114,7 @@ func TestSafe_Purge(t *testing.T) { b := New(newFile(t)) // set ns1 - err := b.Set(&Namespace{ + err := b.Set(&Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"), @@ -126,7 +126,7 @@ func TestSafe_Purge(t *testing.T) { // ensure ns1 is set ns1, err := b.Get("ns1") must.NoError(t, err) - must.Eq(t, &Namespace{ + must.Eq(t, &Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"), @@ -140,14 +140,14 @@ func TestSafe_Purge(t *testing.T) { // ensure ns1 is not set anymore _, err = b.Get("ns1") - must.EqError(t, err, `namespace "ns1" does not exist`) + must.EqError(t, err, `profile "ns1" does not exist`) } func TestSafe_Update(t *testing.T) { b := New(newFile(t)) // set ns1 - err := b.Set(&Namespace{ + err := b.Set(&Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"), @@ -159,7 +159,7 @@ func TestSafe_Update(t *testing.T) { // ensure ns1 is set ns1, err := b.Get("ns1") must.NoError(t, err) - must.Eq(t, &Namespace{ + must.Eq(t, &Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"), @@ -168,7 +168,7 @@ func TestSafe_Update(t *testing.T) { }, ns1) // update ns1 - err = b.Set(&Namespace{ + err = b.Set(&Profile{ Name: "ns1", Content: map[string]Encrypted{ "key2": []byte("value2"), @@ -180,7 +180,7 @@ func TestSafe_Update(t *testing.T) { // ensure ns1 is joined union ns1, err = b.Get("ns1") must.NoError(t, err) - must.Eq(t, &Namespace{ + must.Eq(t, &Profile{ Name: "ns1", Content: map[string]Encrypted{ "key1": []byte("value1"),