Skip to content

Commit

Permalink
Add delete command
Browse files Browse the repository at this point in the history
Closes: #1

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Oct 29, 2019
1 parent 32ad8bc commit 227bd6a
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 5 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ Pre-reqs:

* You will need [inlets](https://inlets.dev/) on your client

Workflow:

* After running `inletsctl create`, the IP address of your exit-node will be returned along with a sample `inlets client` command, for instance:

```sh
Inlets OSS exit-node summary:
IP: 209.97.131.180
Auth-token: qFyFzKYQvFSgtl7TM76p5SwWpmHaQGMT405HajiMzIYmwYVgJt1lvAMXfV4S3KlS

Command:
export UPSTREAM=http://127.0.0.1:8000
inlets client --remote "ws://209.97.131.180:8080" \
--token "qFyFzKYQvFSgtl7TM76p5SwWpmHaQGMT405HajiMzIYmwYVgJt1lvAMXfV4S3KlS" \
--upstream $UPSTREAM
```

* You can delete your exit node using the `id` given by your cloud provider

```sh
inletsctl delete --access-token-file ~/Downloads/do-access-token --id 164857028
```

### Example usage with DigitalOcean

```sh
Expand Down
11 changes: 6 additions & 5 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ Command:
--upstream $UPSTREAM
`,
hostStatus.IP, inletsToken, hostStatus.IP, inletsControlPort, inletsToken)
} else {
proPort := 8123
fmt.Printf(`inlets-pro exit-node summary:
return nil
}

proPort := 8123
fmt.Printf(`inlets-pro exit-node summary:
IP: %s
Auth-token: %s
Expand All @@ -167,8 +169,7 @@ Command:
--license "$LICENSE" \
--tcp-ports 8000
`,
hostStatus.IP, inletsToken, hostStatus.IP, proPort, inletsToken)
}
hostStatus.IP, inletsToken, hostStatus.IP, proPort, inletsToken)

return nil
}
Expand Down
100 changes: 100 additions & 0 deletions cmd/delete.go
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
}

0 comments on commit 227bd6a

Please sign in to comment.