mirror of https://github.com/docker/cli.git
cli/context/store: getData(): 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
3b7f13a5e5
commit
0bcdff2571
|
@ -186,7 +186,7 @@ func (s *store) ListTLSFiles(name string) (map[string]EndpointFiles, error) {
|
|||
}
|
||||
|
||||
func (s *store) GetTLSData(contextName, endpointName, fileName string) ([]byte, error) {
|
||||
res, err := s.tls.getData(contextdirOf(contextName), endpointName, fileName)
|
||||
res, err := s.tls.getData(contextName, endpointName, fileName)
|
||||
return res, patchErrContextName(err, contextName)
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ func (s *tlsStore) createOrUpdate(name, endpointName, filename string, data []by
|
|||
return os.WriteFile(s.filePath(contextID, endpointName, filename), data, 0600)
|
||||
}
|
||||
|
||||
func (s *tlsStore) getData(contextID contextdir, endpointName, filename string) ([]byte, error) {
|
||||
data, err := os.ReadFile(s.filePath(contextID, endpointName, filename))
|
||||
func (s *tlsStore) getData(name, endpointName, filename string) ([]byte, error) {
|
||||
data, err := os.ReadFile(s.filePath(contextdirOf(name), endpointName, filename))
|
||||
if err != nil {
|
||||
return nil, convertTLSDataDoesNotExist(endpointName, filename, err)
|
||||
}
|
||||
|
|
|
@ -12,17 +12,17 @@ func TestTlsCreateUpdateGetRemove(t *testing.T) {
|
|||
const contextName = "test-ctx"
|
||||
contextID := contextdirOf(contextName)
|
||||
|
||||
_, err := testee.getData(contextID, "test-ep", "test-data")
|
||||
_, err := testee.getData(contextName, "test-ep", "test-data")
|
||||
assert.Equal(t, true, IsErrTLSDataDoesNotExist(err))
|
||||
|
||||
err = testee.createOrUpdate(contextName, "test-ep", "test-data", []byte("data"))
|
||||
assert.NilError(t, err)
|
||||
data, err := testee.getData(contextID, "test-ep", "test-data")
|
||||
data, err := testee.getData(contextName, "test-ep", "test-data")
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, string(data), "data")
|
||||
err = testee.createOrUpdate(contextName, "test-ep", "test-data", []byte("data2"))
|
||||
assert.NilError(t, err)
|
||||
data, err = testee.getData(contextID, "test-ep", "test-data")
|
||||
data, err = testee.getData(contextName, "test-ep", "test-data")
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, string(data), "data2")
|
||||
|
||||
|
@ -31,7 +31,7 @@ func TestTlsCreateUpdateGetRemove(t *testing.T) {
|
|||
err = testee.remove(contextID, "test-ep", "test-data")
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = testee.getData(contextID, "test-ep", "test-data")
|
||||
_, err = testee.getData(contextName, "test-ep", "test-data")
|
||||
assert.Equal(t, true, IsErrTLSDataDoesNotExist(err))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue