Skip to content

Commit

Permalink
Add safety check before trying to delete an SSH fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTheEvilOne committed Sep 20, 2021
1 parent f5b9ce4 commit 7c40a46
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/controller/infrastructure/ensurer/ssh_public_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ func EnsureSSHPublicKey(ctx context.Context, client *hcloud.Client, publicKey []
// client *hcloud.Client HCloud client
// fingerprint string SSH fingerprint
func EnsureSSHPublicKeyDeleted(ctx context.Context, client *hcloud.Client, fingerprint string) error {
sshKey, _, err := client.SSHKey.GetByFingerprint(ctx, fingerprint)
if nil != err {
return err
} else if sshKey != nil {
_, err := client.SSHKey.Delete(ctx, sshKey)
if "" != fingerprint {
sshKey, _, err := client.SSHKey.GetByFingerprint(ctx, fingerprint)
if nil != err {
return err
} else if sshKey != nil {
_, err := client.SSHKey.Delete(ctx, sshKey)
if nil != err {
return err
}
}
}

Expand Down

0 comments on commit 7c40a46

Please sign in to comment.