-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added the possibility the you can list, create, and delete ssh key - Modify the instance create cmd now you can pass the name or the id of the ssh key - Update README.md BREAKING CHANGE: No Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
- Loading branch information
1 parent
410abb5
commit 4f3a644
Showing
8 changed files
with
185 additions
and
11 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
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
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,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/civo/cli/config" | ||
"github.com/civo/cli/utility" | ||
"github.com/logrusorgru/aurora" | ||
"github.com/spf13/cobra" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
var sshKeyCreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Aliases: []string{"new", "add"}, | ||
Short: "Create a new ssh key", | ||
Args: cobra.MinimumNArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
client, err := config.CivoAPIClient() | ||
if err != nil { | ||
fmt.Printf("Unable to create a Civo API Client: %s\n", aurora.Red(err)) | ||
os.Exit(1) | ||
} | ||
|
||
// reading the file | ||
data, err := ioutil.ReadFile(args[1]) | ||
if err != nil { | ||
fmt.Printf("Unable to read the ssh key file: %s\n", aurora.Red(err)) | ||
os.Exit(1) | ||
} | ||
|
||
_, err = client.NewSSHKey(args[0], string(data)) | ||
if err != nil { | ||
fmt.Printf("Unable to create the ssh key: %s\n", aurora.Red(err)) | ||
os.Exit(1) | ||
} | ||
|
||
sshKey, err := client.FindSSHKey(args[0]) | ||
if err != nil { | ||
fmt.Printf("Unable to find the ssh key: %s\n", aurora.Red(err)) | ||
os.Exit(1) | ||
} | ||
|
||
ow := utility.NewOutputWriterWithMap(map[string]string{"ID": sshKey.ID, "Name": sshKey.Name}) | ||
|
||
switch outputFormat { | ||
case "json": | ||
ow.WriteSingleObjectJSON() | ||
case "custom": | ||
ow.WriteCustomOutput(outputFields) | ||
default: | ||
fmt.Printf("Created a ssh key called %s with ID %s\n", aurora.Green(sshKey.Name), aurora.Green(sshKey.ID)) | ||
} | ||
}, | ||
} |
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,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/civo/cli/config" | ||
"github.com/civo/cli/utility" | ||
"github.com/logrusorgru/aurora" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var sshKeyListCmd = &cobra.Command{ | ||
Use: "ls", | ||
Aliases: []string{"list", "all"}, | ||
Short: "List all ssh keys", | ||
Long: `List all current ssh keys. | ||
If you wish to use a custom format, the available fields are: | ||
* ID | ||
* Name | ||
* Fingerprint | ||
Example: civo ssh ls -o custom -f "ID: Name"`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
client, err := config.CivoAPIClient() | ||
if err != nil { | ||
fmt.Printf("Unable to create a Civo API Client: %s\n", aurora.Red(err)) | ||
os.Exit(1) | ||
} | ||
|
||
sshKeys, err := client.ListSSHKeys() | ||
if err != nil { | ||
fmt.Printf("Unable to list ssh keys: %s\n", aurora.Red(err)) | ||
os.Exit(1) | ||
} | ||
|
||
ow := utility.NewOutputWriter() | ||
for _, sshkey := range sshKeys { | ||
ow.StartLine() | ||
|
||
ow.AppendData("ID", sshkey.ID) | ||
ow.AppendData("Name", sshkey.Name) | ||
ow.AppendDataWithLabel("Fingerprint", sshkey.Fingerprint, "Finger Print") | ||
} | ||
|
||
switch outputFormat { | ||
case "json": | ||
ow.WriteMultipleObjectsJSON() | ||
case "custom": | ||
ow.WriteCustomOutput(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,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/civo/cli/config" | ||
"github.com/civo/cli/utility" | ||
"github.com/logrusorgru/aurora" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var sshKeyRemoveCmd = &cobra.Command{ | ||
Use: "remove", | ||
Aliases: []string{"rm", "delete", "destroy"}, | ||
Short: "Remove a ssh key", | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
client, err := config.CivoAPIClient() | ||
if err != nil { | ||
fmt.Printf("Unable to create a Civo API Client: %s\n", aurora.Red(err)) | ||
os.Exit(1) | ||
} | ||
|
||
sshKey, err := client.FindSSHKey(args[0]) | ||
if err != nil { | ||
fmt.Printf("Unable to find ssh key for your search: %s\n", aurora.Red(err)) | ||
os.Exit(1) | ||
} | ||
|
||
_, err = client.DeleteSSHKey(sshKey.ID) | ||
|
||
ow := utility.NewOutputWriterWithMap(map[string]string{"ID": sshKey.ID, "Name": sshKey.Name}) | ||
|
||
switch outputFormat { | ||
case "json": | ||
ow.WriteSingleObjectJSON() | ||
case "custom": | ||
ow.WriteCustomOutput(outputFields) | ||
default: | ||
fmt.Printf("The ssh key called %s with ID %s was delete\n", aurora.Green(sshKey.Name), aurora.Green(sshKey.ID)) | ||
} | ||
}, | ||
} |