-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #1 Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
- Loading branch information
Showing
3 changed files
with
128 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
inletsCmd.AddCommand(deleteCmd) | ||
deleteCmd.Flags().StringP("provider", "p", "digitalocean", "The cloud provider") | ||
|
||
deleteCmd.Flags().StringP("inlets-token", "t", "", "The inlets auth token for your exit node") | ||
deleteCmd.Flags().StringP("access-token", "a", "", "The access token for your cloud") | ||
deleteCmd.Flags().StringP("access-token-file", "f", "", "Read this file for the access token for your cloud") | ||
|
||
deleteCmd.Flags().StringP("id", "i", "", "Host ID") | ||
|
||
deleteCmd.Flags().String("secret-key", "", "The access token for your cloud (Scaleway)") | ||
deleteCmd.Flags().String("secret-key-file", "", "Read this file for the access token for your cloud (Scaleway)") | ||
deleteCmd.Flags().String("organisation-id", "", "Organisation ID (Scaleway)") | ||
|
||
} | ||
|
||
// clientCmd represents the client sub command. | ||
var deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete an exit node", | ||
Long: `Delete an exit node | ||
Example: inletsctl delete --provider digitalocean --id abczsef`, | ||
RunE: runDelete, | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
} | ||
|
||
func runDelete(cmd *cobra.Command, _ []string) error { | ||
|
||
provider, err := cmd.Flags().GetString("provider") | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get 'provider' value.") | ||
} | ||
|
||
fmt.Printf("Using provider: %s\n", provider) | ||
|
||
inletsToken, err := cmd.Flags().GetString("inlets-token") | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get 'inlets-token' value.") | ||
} | ||
if len(inletsToken) == 0 { | ||
var passwordErr error | ||
inletsToken, passwordErr = generateAuth() | ||
|
||
if passwordErr != nil { | ||
return passwordErr | ||
} | ||
} | ||
|
||
accessToken, err := getFileOrString(cmd.Flags(), "access-token-file", "access-token", true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var secretKey string | ||
var organisationID string | ||
if provider == "scaleway" { | ||
var secretKeyErr error | ||
secretKey, secretKeyErr = getFileOrString(cmd.Flags(), "secret-key-file", "secret-key", true) | ||
if secretKeyErr != nil { | ||
return secretKeyErr | ||
} | ||
|
||
organisationID, _ = cmd.Flags().GetString("organisation-id") | ||
if len(organisationID) == 0 { | ||
return fmt.Errorf("--organisation-id cannot be empty") | ||
} | ||
} | ||
|
||
provisioner, err := getProvisioner(provider, accessToken, secretKey, organisationID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
hostID, _ := cmd.Flags().GetString("id") | ||
|
||
if len(hostID) == 0 { | ||
return fmt.Errorf("give a valid --id for your host") | ||
} | ||
|
||
fmt.Printf("Deleting host: %s from %s\n", hostID, provider) | ||
|
||
err = provisioner.Delete(hostID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |