Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from johnmccabe/token-command
Browse files Browse the repository at this point in the history
Add token subcommand
  • Loading branch information
johnmccabe authored Jul 4, 2018
2 parents 1a878eb + 33ff224 commit 4bedb3a
Show file tree
Hide file tree
Showing 34 changed files with 8,143 additions and 6 deletions.
13 changes: 11 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@

[prune]
go-tests = true
unused-packages = true
unused-packages = true
[[constraint]]
branch = "master"
name = "golang.org/x/crypto"
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Too much talk, have a look at it in action.

## Features

- [x] updates every `30s`, see
- [x] updates with a configurable period
- [x] shows all active vms created using your token
- [x] vms with < 1hr before their deletion are highlighted in red
- [x] quick access to some details of each vm
Expand All @@ -31,7 +31,7 @@ Too much talk, have a look at it in action.

### Prerequisites

- You must have a vmpooler token, refer to the vmfloaty documentation/confluence for instructions.
- You must have a vmpooler token, see [generating a token](#generating-a-token) if you don't already have one.
- for the SSH to vmpooler instance action to work you should have the vmpooler ssh key added to the ssh agent, `ssh-add /path/to/priv/key`.

### Install BitBar
Expand All @@ -55,13 +55,29 @@ Install using the provider Homebrew tap.
$ brew tap johnmccabe/vmpooler-bitbar
$ brew install vmpooler-bitbar

### Generating a Token

IF you already have a token you can jump to the next section, if not run the following command:

$ vmpooler-bitbar token

Follow the prompts, you will be asked for the following:

- vmpooler API endpoint (for example, `https://vmpooler.mycompany.net/api/v1`)
- username (your LDAP username, for example `joe.bloggs`)
- password (your LDAP password, for example, `password1`)

Your token will be printed to stdout:

Token generated: pop448v0ztnwta3c964pifngrmk8ea4u

### Configuring

Before vmpooler-bitbar becomes available you must configure the plugin:

$ vmpooler-bitbar config

Follow the prompts, pressing `?` for more details of each field, you will be prompted for the following:
Follow the prompts, pressing `?` for more details of each field, you will be asked for the following:

- vmpooler API endpoint (for example, `https://vmpooler.mycompany.net/api/v1`)
- vmpooler token (for example, `kpy2fn8sgjkcbyn896yilzqxwjlnfake`)
Expand Down
55 changes: 55 additions & 0 deletions commands/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package commands

import (
"bufio"
"fmt"
"log"
"os"
"syscall"

"github.com/johnmccabe/go-vmpooler/token"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)

func init() {
rootCmd.AddCommand(tokenCmd)
}

var tokenCmd = &cobra.Command{
Use: "token",
Run: runTokenCmd,
}

func runTokenCmd(cmd *cobra.Command, args []string) {
endpoint, username, password, err := getCredentials()
if err != nil {
log.Fatal(err.Error())
}

t := token.NewClient(endpoint, username, password)

token, err := t.Generate()
if err != nil {
log.Fatal(err.Error())
}
fmt.Printf("\nToken generated: %s\n", token.Token)
}

func getCredentials() (string, string, string, error) {
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("Enter vmpooler API endpoint: ")
scanner.Scan()
endpoint := scanner.Text()

fmt.Print("Enter Username: ")
scanner.Scan()
username := scanner.Text()

fmt.Print("Enter Password: ")
bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
password := string(bytePassword)
fmt.Println()

return endpoint, username, password, err
}
3 changes: 3 additions & 0 deletions vendor/golang.org/x/crypto/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/golang.org/x/crypto/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/golang.org/x/crypto/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/golang.org/x/crypto/PATENTS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bedb3a

Please sign in to comment.