Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: clean up SecretStore to not use KeystoreItem #3834

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/kops/delete_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func RunDeleteSecret(f *util.Factory, out io.Writer, options *DeleteSecretOption

switch secrets[0].Type {
case kops.SecretTypeSecret:
err = secretStore.DeleteSecret(secrets[0])
err = secretStore.DeleteSecret(secrets[0].Name)
case SecretTypeSSHPublicKey:
sshCredential := &kops.SSHCredential{}
sshCredential.Name = secrets[0].Name
Expand Down
6 changes: 3 additions & 3 deletions cmd/kops/get_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ func listSecrets(keyStore fi.CAStore, secretStore fi.SecretStore, sshCredentialS
}

if findType == "" || findType == strings.ToLower(string(kops.SecretTypeSecret)) {
l, err := secretStore.ListSecrets()
names, err := secretStore.ListSecrets()
if err != nil {
return nil, fmt.Errorf("error listing secrets %v", err)
}

for _, id := range l {
for _, name := range names {
i := &fi.KeystoreItem{
Name: id,
Name: name,
Type: kops.SecretTypeSecret,
}
if findType != "" && findType != strings.ToLower(string(i.Type)) {
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type SecretStore interface {
// Secret returns a secret. Returns an error if not found
Secret(id string) (*Secret, error)
// DeleteSecret deletes the specified secret
DeleteSecret(item *KeystoreItem) error
DeleteSecret(id string) error
// FindSecret finds a secret, if exists. Returns nil,nil if not found
FindSecret(id string) (*Secret, error)
// GetOrCreateSecret creates a secret
Expand Down
22 changes: 20 additions & 2 deletions upup/pkg/fi/secrets/clientset_secretstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,27 @@ func (c *ClientsetSecretStore) Secret(name string) (*fi.Secret, error) {
}

// DeleteSecret implements fi.SecretStore::DeleteSecret
func (c *ClientsetSecretStore) DeleteSecret(item *fi.KeystoreItem) error {
func (c *ClientsetSecretStore) DeleteSecret(name string) error {
client := c.clientset.Keysets(c.namespace)
return fi.DeleteKeysetItem(client, item.Name, kops.SecretTypeKeypair, item.Id)

keyset, err := client.Get(name, v1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
} else {
return fmt.Errorf("error reading Keyset %q: %v", name, err)
}
}

if keyset.Spec.Type != kops.SecretTypeSecret {
return fmt.Errorf("mismatch on Keyset type on %q", name)
}

if err := client.Delete(name, &v1.DeleteOptions{}); err != nil {
return fmt.Errorf("error deleting Keyset %q: %v", name, err)
}

return nil
}

// GetOrCreateSecret implements fi.SecretStore::GetOrCreateSecret
Expand Down
12 changes: 3 additions & 9 deletions upup/pkg/fi/secrets/vfs_secretstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,9 @@ func (c *VFSSecretStore) FindSecret(id string) (*fi.Secret, error) {
}

// DeleteSecret implements fi.SecretStore DeleteSecret
func (c *VFSSecretStore) DeleteSecret(item *fi.KeystoreItem) error {
switch item.Type {
case kops.SecretTypeSecret:
p := c.buildSecretPath(item.Name)
return p.Remove()

default:
return fmt.Errorf("deletion of secretstore items of type %v not (yet) supported", item.Type)
}
func (c *VFSSecretStore) DeleteSecret(name string) error {
p := c.buildSecretPath(name)
return p.Remove()
}

func (c *VFSSecretStore) ListSecrets() ([]string, error) {
Expand Down