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

Commit 4bedb3a

Browse files
authored
Merge pull request #14 from johnmccabe/token-command
Add token subcommand
2 parents 1a878eb + 33ff224 commit 4bedb3a

34 files changed

+8143
-6
lines changed

Gopkg.lock

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88

99
[prune]
1010
go-tests = true
11-
unused-packages = true
11+
unused-packages = true
12+
[[constraint]]
13+
branch = "master"
14+
name = "golang.org/x/crypto"

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Too much talk, have a look at it in action.
1010

1111
## Features
1212

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

3232
### Prerequisites
3333

34-
- You must have a vmpooler token, refer to the vmfloaty documentation/confluence for instructions.
34+
- You must have a vmpooler token, see [generating a token](#generating-a-token) if you don't already have one.
3535
- 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`.
3636

3737
### Install BitBar
@@ -55,13 +55,29 @@ Install using the provider Homebrew tap.
5555
$ brew tap johnmccabe/vmpooler-bitbar
5656
$ brew install vmpooler-bitbar
5757

58+
### Generating a Token
59+
60+
IF you already have a token you can jump to the next section, if not run the following command:
61+
62+
$ vmpooler-bitbar token
63+
64+
Follow the prompts, you will be asked for the following:
65+
66+
- vmpooler API endpoint (for example, `https://vmpooler.mycompany.net/api/v1`)
67+
- username (your LDAP username, for example `joe.bloggs`)
68+
- password (your LDAP password, for example, `password1`)
69+
70+
Your token will be printed to stdout:
71+
72+
Token generated: pop448v0ztnwta3c964pifngrmk8ea4u
73+
5874
### Configuring
5975

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

6278
$ vmpooler-bitbar config
6379

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

6682
- vmpooler API endpoint (for example, `https://vmpooler.mycompany.net/api/v1`)
6783
- vmpooler token (for example, `kpy2fn8sgjkcbyn896yilzqxwjlnfake`)

commands/token.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package commands
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"log"
7+
"os"
8+
"syscall"
9+
10+
"github.com/johnmccabe/go-vmpooler/token"
11+
"github.com/spf13/cobra"
12+
"golang.org/x/crypto/ssh/terminal"
13+
)
14+
15+
func init() {
16+
rootCmd.AddCommand(tokenCmd)
17+
}
18+
19+
var tokenCmd = &cobra.Command{
20+
Use: "token",
21+
Run: runTokenCmd,
22+
}
23+
24+
func runTokenCmd(cmd *cobra.Command, args []string) {
25+
endpoint, username, password, err := getCredentials()
26+
if err != nil {
27+
log.Fatal(err.Error())
28+
}
29+
30+
t := token.NewClient(endpoint, username, password)
31+
32+
token, err := t.Generate()
33+
if err != nil {
34+
log.Fatal(err.Error())
35+
}
36+
fmt.Printf("\nToken generated: %s\n", token.Token)
37+
}
38+
39+
func getCredentials() (string, string, string, error) {
40+
scanner := bufio.NewScanner(os.Stdin)
41+
fmt.Print("Enter vmpooler API endpoint: ")
42+
scanner.Scan()
43+
endpoint := scanner.Text()
44+
45+
fmt.Print("Enter Username: ")
46+
scanner.Scan()
47+
username := scanner.Text()
48+
49+
fmt.Print("Enter Password: ")
50+
bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
51+
password := string(bytePassword)
52+
fmt.Println()
53+
54+
return endpoint, username, password, err
55+
}

vendor/golang.org/x/crypto/AUTHORS

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/CONTRIBUTORS

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/LICENSE

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/PATENTS

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)