-
Notifications
You must be signed in to change notification settings - Fork 2
/
logfingjira.go
80 lines (70 loc) · 1.95 KB
/
logfingjira.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
74
75
76
77
78
79
80
package main
import (
"bufio"
"code.google.com/p/go.crypto/ssh/terminal"
"encoding/base64"
"flag"
"fmt"
"os"
"strings"
)
func main() {
username := flag.String("u", "", "Jira username")
pass := flag.String("p", "", "Jira password")
companyName := flag.String("c", "", "Jira company name")
message := flag.String("m", "", "log message")
issue := flag.String("i", "", "log issue key/id")
duration := flag.String("d", "", "log duration")
flag.Parse()
envUsername := os.Getenv("JUNAME")
envCompanyName := os.Getenv("JCOMPNAME")
if len(*message) == 0 || len(*issue) == 0 || len(*duration) == 0 {
fmt.Println("-m -i and -d flags must be set")
return
}
if len(*username) == 0 {
if len(envUsername) == 0 {
username = fetchUsername()
} else {
*username = envUsername
}
}
if len(*pass) == 0 {
pass = fetchPass()
}
if len(*companyName) == 0 {
if len(envCompanyName) != 0 {
companyName = &envCompanyName
} else {
companyName = fetchCompanyName()
}
}
jiraClientObj := jiraClient{UserName: *username, Pass: *pass, Url: "https://" + *companyName + ".atlassian.net/"}
jiraClientObj.logHours(*issue, *message, *duration)
}
func authorizationCode(username, pass string) string {
unamePassByte := []byte(username + ":" + pass)
unamePass := base64.StdEncoding.EncodeToString(unamePassByte)
return unamePass
}
func fetchPass() *string {
fmt.Print("Enter Password: ")
passwordByte, _ := terminal.ReadPassword(0)
password := string(passwordByte)
password = strings.TrimSpace(password)
return &password
}
func fetchCompanyName() *string {
reader := bufio.NewReader(os.Stdin)
fmt.Print("\nEnter Company name (as needed for the API): ")
companyName, _ := reader.ReadString('\n')
companyName = strings.TrimSpace(companyName)
return &companyName
}
func fetchUsername() *string {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter Username: ")
username, _ := reader.ReadString('\n')
username = strings.TrimSpace(username)
return &username
}