-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from uzaxirr/db-versions
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package sshkey | ||
|
||
import ( | ||
"github.com/civo/cli/common" | ||
"github.com/civo/cli/config" | ||
"github.com/civo/cli/utility" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var sshKeyFindCmd = &cobra.Command{ | ||
Use: "find", | ||
Aliases: []string{"get"}, | ||
Example: `civo ssh find`, | ||
Short: "Finds an SSH key by either part of the ID or part of the name", | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
client, err := config.CivoAPIClient() | ||
if err != nil { | ||
utility.Error("Creating the connection to Civo's API failed with %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
sshKey, err := client.FindSSHKey(args[0]) | ||
if err != nil { | ||
utility.Error("SSHKey %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
ow := utility.NewOutputWriterWithMap(map[string]string{"id": sshKey.ID, "name": sshKey.Name}) | ||
|
||
switch common.OutputFormat { | ||
case "json": | ||
ow.WriteSingleObjectJSON(common.PrettySet) | ||
case "custom": | ||
ow.WriteCustomOutput(common.OutputFields) | ||
default: | ||
ow.WriteTable() | ||
} | ||
}, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package sshkey | ||
|
||
import ( | ||
"errors" | ||
"github.com/civo/civogo" | ||
"github.com/civo/cli/common" | ||
"github.com/civo/cli/config" | ||
"github.com/civo/cli/utility" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var sshKeyUpdateCmd = &cobra.Command{ | ||
Use: "update", | ||
Aliases: []string{"modify", "rename"}, | ||
Example: `civo ssh rename my-mac-keys my-dell-keys | ||
civo ip rename "1234-68gyd-8knw9" new-keys`, | ||
Short: "Updates a SSH key record", | ||
Args: cobra.MinimumNArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
utility.EnsureCurrentRegion() | ||
|
||
client, err := config.CivoAPIClient() | ||
if common.RegionSet != "" { | ||
client.Region = common.RegionSet | ||
} | ||
if err != nil { | ||
utility.Error("Creating the connection to Civo's API failed with %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
sshKey, err := client.FindSSHKey(args[0]) | ||
if err != nil { | ||
if errors.Is(err, civogo.ZeroMatchesError) { | ||
utility.Error("sorry there is no %s SSH key in your account", utility.Red(args[0])) | ||
os.Exit(1) | ||
} else if errors.Is(err, civogo.MultipleMatchesError) { | ||
utility.Error("sorry we found more than one SSH keys with that value in your account") | ||
os.Exit(1) | ||
} else { | ||
utility.Error("%s", err) | ||
} | ||
} | ||
|
||
newName := args[1] | ||
renamedKey, err := client.UpdateSSHKey(newName, sshKey.ID) | ||
if err != nil { | ||
utility.Error("%s", err) | ||
os.Exit(1) | ||
} | ||
|
||
ow := utility.NewOutputWriterWithMap(map[string]string{"id": renamedKey.ID, "name": renamedKey.Name}) | ||
|
||
switch common.OutputFormat { | ||
case "json": | ||
ow.WriteSingleObjectJSON(common.PrettySet) | ||
case "custom": | ||
ow.WriteCustomOutput(common.OutputFields) | ||
default: | ||
ow.WriteTable() | ||
} | ||
}, | ||
} |