mirror of https://github.com/docker/cli.git
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:
parent
712cc9a1c7
commit
9720d5b451
|
@ -181,7 +181,7 @@ func (s *store) ResetEndpointTLSMaterial(contextName string, endpointName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) ListTLSFiles(name string) (map[string]EndpointFiles, error) {
|
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)
|
return res, patchErrContextName(err, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,8 @@ func (s *tlsStore) removeAllContextData(name string) error {
|
||||||
return os.RemoveAll(s.contextDir(contextdirOf(name)))
|
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))
|
epFSs, err := os.ReadDir(s.contextDir(contextID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
|
|
@ -49,7 +49,6 @@ func TestTlsListAndBatchRemove(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextName = "test-ctx"
|
const contextName = "test-ctx"
|
||||||
contextID := contextdirOf(contextName)
|
|
||||||
for name, files := range all {
|
for name, files := range all {
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
err := testee.createOrUpdate(contextName, name, file, []byte("data"))
|
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.NilError(t, err)
|
||||||
assert.DeepEqual(t, resAll, all)
|
assert.DeepEqual(t, resAll, all)
|
||||||
|
|
||||||
err = testee.removeAllEndpointData(contextName, "ep3")
|
err = testee.removeAllEndpointData(contextName, "ep3")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
resEp1ep2, err := testee.listContextData(contextID)
|
resEp1ep2, err := testee.listContextData(contextName)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.DeepEqual(t, resEp1ep2, ep1ep2)
|
assert.DeepEqual(t, resEp1ep2, ep1ep2)
|
||||||
|
|
||||||
err = testee.removeAllContextData(contextName)
|
err = testee.removeAllContextData(contextName)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
resEmpty, err := testee.listContextData(contextID)
|
resEmpty, err := testee.listContextData(contextName)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{})
|
assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue