-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
73 lines (60 loc) · 1.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"errors"
"flag"
"fmt"
"os"
)
func main() {
// Define Flags
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
hostFlag := flag.String("host", "", "SCP Cloud Platform Address")
usernameFlag := flag.String("username", "", "SCP Cloud Platform Username")
passwordFlag := flag.String("password", "", "SCP Cloud Platform Password")
// Parse Flags
flag.Parse()
// Check Host
if *hostFlag == "" {
fmt.Println(errors.New("host parameter is missing"))
return
}
// Check Username
if *usernameFlag == "" {
fmt.Println(errors.New("username parameter is missing"))
return
}
// Check Password
if *passwordFlag == "" {
fmt.Println(errors.New("password parameter is missing"))
return
}
// Get Client
client := GetAPIClient(*hostFlag)
// Get Authentication Token
err := run(client, *usernameFlag, *passwordFlag)
if err != nil {
fmt.Println(err.Error())
}
}
func run(client *Client, username, password string) error {
// Get Public Key for Authentication
publicKey, err := GetPublicKey(client)
if err != nil {
return err
}
// Encrypt Password
encryptedPassword, err := GetEncryptedPassword(password, publicKey)
if err != nil {
return err
}
// Authenticate
err = client.Authenticate(username, encryptedPassword)
if err != nil {
return err
}
// Output
fmt.Println("Encrypted Password: ", encryptedPassword)
fmt.Println("---------------------------------------")
fmt.Println("Token: ", client.Token)
return nil
}