-
Notifications
You must be signed in to change notification settings - Fork 20
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(ssh-keys): Update ssh-keys register, show and delete to egos… #639
Merged
pierre-emmanuelJ
merged 5 commits into
exoscale:master
from
mlec1:update-ssh-keys-register-delete-v3
Nov 4, 2024
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5c0d6cc
refactor(ssh-keys): Update ssh-keys register, show and delete to egos…
mlec1 c95e972
refactor(ssh-keys): Add formating
mlec1 8203e03
refactor(ssh-keys): Check for errors in decorateAsyncOperations
mlec1 401a0f8
refactor(ssh-keys): Simplify code
mlec1 7248acf
refactor(iam-key): add proper error message
mlec1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,16 @@ package cmd | |
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/exoscale/cli/pkg/account" | ||
"github.com/exoscale/cli/pkg/globalstate" | ||
"github.com/exoscale/cli/pkg/output" | ||
egoscale "github.com/exoscale/egoscale/v2" | ||
exoapi "github.com/exoscale/egoscale/v2/api" | ||
v3 "github.com/exoscale/egoscale/v3" | ||
) | ||
|
||
type computeSSHKeyRegisterCmd struct { | ||
|
@@ -43,35 +42,53 @@ func (c *computeSSHKeyRegisterCmd) cmdPreRun(cmd *cobra.Command, args []string) | |
|
||
func (c *computeSSHKeyRegisterCmd) cmdRun(cmd *cobra.Command, _ []string) error { | ||
var ( | ||
sshKey *egoscale.SSHKey | ||
sshKey *v3.SSHKey | ||
err error | ||
) | ||
|
||
// Template registration can take a _long time_, raising | ||
// the Exoscale API client timeout as a precaution. | ||
globalstate.EgoscaleClient.SetTimeout(30 * time.Minute) | ||
client := globalstate.EgoscaleV3Client.WithHttpClient(&http.Client{Timeout: 30 * time.Minute}) | ||
|
||
ctx := exoapi.WithEndpoint( | ||
gContext, | ||
exoapi.NewReqEndpoint(account.CurrentAccount.Environment, account.CurrentAccount.DefaultZone), | ||
) | ||
ctx := gContext | ||
|
||
publicKey, err := os.ReadFile(c.PublicKeyFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
decorateAsyncOperation(fmt.Sprintf("Registering SSH key %q...", c.Name), func() { | ||
sshKey, err = globalstate.EgoscaleClient.RegisterSSHKey(ctx, account.CurrentAccount.DefaultZone, c.Name, string(publicKey)) | ||
registerKeyRequest := v3.RegisterSSHKeyRequest{ | ||
Name: c.Name, | ||
PublicKey: string(publicKey), | ||
} | ||
|
||
err = decorateAsyncOperations(fmt.Sprintf("Registering SSH key %q...", c.Name), func() error { | ||
op, err := client.RegisterSSHKey(ctx, registerKeyRequest) | ||
|
||
mlec1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the function, we usually add more error wrapping the same way you did in this file |
||
} | ||
|
||
_, err = client.Wait(ctx, op, v3.OperationStateSuccess) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
mlec1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !globalstate.Quiet { | ||
sshKey, err = client.GetSSHKey(ctx, c.Name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mlec1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return c.outputFunc(&computeSSHKeyShowOutput{ | ||
Fingerprint: *sshKey.Fingerprint, | ||
Name: *sshKey.Name, | ||
Fingerprint: sshKey.Fingerprint, | ||
Name: sshKey.Name, | ||
}, nil) | ||
mlec1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here.