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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-09-28 17:51:25 +02:00
parent 712cc9a1c7
commit 9720d5b451
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 6 additions and 6 deletions

View File

@ -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)
}

View File

@ -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) {

View File

@ -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{})
}