mirror of https://github.com/docker/cli.git
cli/context/store: rename removeAllContextData(), removeAllEndpointData()
The existing `remove()` was unused, and using that as name makes it more consistent with the metadata-store. Also renaming `removeAllEndpointData` to just `removeEndpoint`, as it's part of the TLS-store, which should already make it clear it's about (TLS)data. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
09c94c1c21
commit
cd7c493ea2
|
@ -142,7 +142,7 @@ func (s *ContextStore) Remove(name string) error {
|
|||
if err := s.meta.remove(name); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove context %s", name)
|
||||
}
|
||||
if err := s.tls.removeAllContextData(name); err != nil {
|
||||
if err := s.tls.remove(name); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove context %s", name)
|
||||
}
|
||||
return nil
|
||||
|
@ -157,7 +157,7 @@ func (s *ContextStore) GetMetadata(name string) (Metadata, error) {
|
|||
// ResetTLSMaterial removes TLS data for all endpoints in the context and replaces
|
||||
// it with the new data.
|
||||
func (s *ContextStore) ResetTLSMaterial(name string, data *ContextTLSData) error {
|
||||
if err := s.tls.removeAllContextData(name); err != nil {
|
||||
if err := s.tls.remove(name); err != nil {
|
||||
return err
|
||||
}
|
||||
if data == nil {
|
||||
|
@ -176,7 +176,7 @@ func (s *ContextStore) ResetTLSMaterial(name string, data *ContextTLSData) error
|
|||
// ResetEndpointTLSMaterial removes TLS data for the given context and endpoint,
|
||||
// and replaces it with the new data.
|
||||
func (s *ContextStore) ResetEndpointTLSMaterial(contextName string, endpointName string, data *EndpointTLSData) error {
|
||||
if err := s.tls.removeAllEndpointData(contextName, endpointName); err != nil {
|
||||
if err := s.tls.removeEndpoint(contextName, endpointName); err != nil {
|
||||
return err
|
||||
}
|
||||
if data == nil {
|
||||
|
|
|
@ -45,26 +45,17 @@ func (s *tlsStore) getData(name, endpointName, filename string) ([]byte, error)
|
|||
return data, nil
|
||||
}
|
||||
|
||||
// remove removes a TLS data from an endpoint
|
||||
// TODO(thaJeztah) tlsStore.remove() is not used anywhere outside of tests; should we use removeAllEndpointData() only?
|
||||
func (s *tlsStore) remove(name, endpointName, filename string) error {
|
||||
err := os.Remove(filepath.Join(s.endpointDir(name, endpointName), filename))
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *tlsStore) removeAllEndpointData(name, endpointName string) error {
|
||||
if err := os.RemoveAll(s.endpointDir(name, endpointName)); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove TLS data for endpoint %s", endpointName)
|
||||
// remove deletes all TLS data for the given context.
|
||||
func (s *tlsStore) remove(name string) error {
|
||||
if err := os.RemoveAll(s.contextDir(name)); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove TLS data")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *tlsStore) removeAllContextData(name string) error {
|
||||
if err := os.RemoveAll(s.contextDir(name)); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove TLS data")
|
||||
func (s *tlsStore) removeEndpoint(name, endpointName string) error {
|
||||
if err := os.RemoveAll(s.endpointDir(name, endpointName)); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove TLS data for endpoint %s", endpointName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -26,11 +26,8 @@ func TestTlsCreateUpdateGetRemove(t *testing.T) {
|
|||
assert.NilError(t, err)
|
||||
assert.Equal(t, string(data), "data2")
|
||||
|
||||
err = testee.remove(contextName, "test-ep", "test-data")
|
||||
err = testee.removeEndpoint(contextName, "test-ep")
|
||||
assert.NilError(t, err)
|
||||
err = testee.remove(contextName, "test-ep", "test-data")
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = testee.getData(contextName, "test-ep", "test-data")
|
||||
assert.ErrorType(t, err, errdefs.IsNotFound)
|
||||
}
|
||||
|
@ -61,13 +58,13 @@ func TestTlsListAndBatchRemove(t *testing.T) {
|
|||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, resAll, all)
|
||||
|
||||
err = testee.removeAllEndpointData(contextName, "ep3")
|
||||
err = testee.removeEndpoint(contextName, "ep3")
|
||||
assert.NilError(t, err)
|
||||
resEp1ep2, err := testee.listContextData(contextName)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, resEp1ep2, ep1ep2)
|
||||
|
||||
err = testee.removeAllContextData(contextName)
|
||||
err = testee.remove(contextName)
|
||||
assert.NilError(t, err)
|
||||
resEmpty, err := testee.listContextData(contextName)
|
||||
assert.NilError(t, err)
|
||||
|
|
Loading…
Reference in New Issue