From 9720d5b4510e224ce666bad4e3b7032463e1c994 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 28 Sep 2022 17:51:25 +0200 Subject: [PATCH] cli/context/store: listContextData(): accept name instead of ID This allows callers to just pass the name, and handle the conversion to ID and path internally. Signed-off-by: Sebastiaan van Stijn --- cli/context/store/store.go | 2 +- cli/context/store/tlsstore.go | 3 ++- cli/context/store/tlsstore_test.go | 7 +++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/context/store/store.go b/cli/context/store/store.go index 97a2d93ea6..299bdb9a74 100644 --- a/cli/context/store/store.go +++ b/cli/context/store/store.go @@ -181,7 +181,7 @@ func (s *store) ResetEndpointTLSMaterial(contextName string, endpointName string } func (s *store) ListTLSFiles(name string) (map[string]EndpointFiles, error) { - res, err := s.tls.listContextData(contextdirOf(name)) + res, err := s.tls.listContextData(name) return res, patchErrContextName(err, name) } diff --git a/cli/context/store/tlsstore.go b/cli/context/store/tlsstore.go index 777c9c04f0..30620b3f97 100644 --- a/cli/context/store/tlsstore.go +++ b/cli/context/store/tlsstore.go @@ -62,7 +62,8 @@ func (s *tlsStore) removeAllContextData(name string) error { return os.RemoveAll(s.contextDir(contextdirOf(name))) } -func (s *tlsStore) listContextData(contextID contextdir) (map[string]EndpointFiles, error) { +func (s *tlsStore) listContextData(name string) (map[string]EndpointFiles, error) { + contextID := contextdirOf(name) epFSs, err := os.ReadDir(s.contextDir(contextID)) if err != nil { if os.IsNotExist(err) { diff --git a/cli/context/store/tlsstore_test.go b/cli/context/store/tlsstore_test.go index 3f6b6c4443..9c4c79ebda 100644 --- a/cli/context/store/tlsstore_test.go +++ b/cli/context/store/tlsstore_test.go @@ -49,7 +49,6 @@ func TestTlsListAndBatchRemove(t *testing.T) { } const contextName = "test-ctx" - contextID := contextdirOf(contextName) for name, files := range all { for _, file := range files { err := testee.createOrUpdate(contextName, name, file, []byte("data")) @@ -57,19 +56,19 @@ func TestTlsListAndBatchRemove(t *testing.T) { } } - resAll, err := testee.listContextData(contextID) + resAll, err := testee.listContextData(contextName) assert.NilError(t, err) assert.DeepEqual(t, resAll, all) err = testee.removeAllEndpointData(contextName, "ep3") assert.NilError(t, err) - resEp1ep2, err := testee.listContextData(contextID) + resEp1ep2, err := testee.listContextData(contextName) assert.NilError(t, err) assert.DeepEqual(t, resEp1ep2, ep1ep2) err = testee.removeAllContextData(contextName) assert.NilError(t, err) - resEmpty, err := testee.listContextData(contextID) + resEmpty, err := testee.listContextData(contextName) assert.NilError(t, err) assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{}) }