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:
Sebastiaan van Stijn 2022-09-28 17:40:33 +02:00
parent 3b7f13a5e5
commit 0bcdff2571
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 7 additions and 7 deletions

View File

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

View File

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

View File

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