-
Notifications
You must be signed in to change notification settings - Fork 1
/
tfacon.go
74 lines (63 loc) · 1.79 KB
/
tfacon.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
package core
import (
"fmt"
"net/http"
"github.com/JunqiZhang0/tfacon/connectors"
"github.com/JunqiZhang0/tfacon/common"
"github.com/spf13/viper"
)
type TFACon interface {
GetAllTestIds() []string
BuildUpdatedList(ids []string, concurrent bool, add_attributes bool) common.GeneralUpdatedList
UpdateAll(common.GeneralUpdatedList, bool)
String() string
InitConnector()
Validate(verbose bool) (bool, error)
}
func Run(viperRun, viperConfig *viper.Viper) {
var con TFACon = GetCon(viperRun)
// fmt.Printf("%+v\n", con)
// fmt.Println("===========================")
con.InitConnector()
runHelper(viperConfig, con.GetAllTestIds(), con)
}
func runHelper(viperConfig *viper.Viper, ids []string, con TFACon) {
if len(ids) == 0 {
return
}
updated_list_of_issues := con.BuildUpdatedList(ids, viperConfig.GetBool("config.concurrency"), viperConfig.GetBool("config.add_attributes"))
// Doing this because the api can only take 20 items per request
con.UpdateAll(updated_list_of_issues, viperConfig.GetBool("config.verbose"))
runHelper(viperConfig, con.GetAllTestIds(), con)
}
func GetInfo(viper *viper.Viper) TFACon {
var con TFACon = GetCon(viper)
return con
}
func Validate(viper *viper.Viper) (bool, error) {
var con TFACon = GetCon(viper)
success, err := con.Validate(viper.GetBool("verbose"))
return success, err
}
func GetCon(viper *viper.Viper) TFACon {
var con TFACon
switch viper.Get("CONNECTOR_TYPE") {
case "RPCon":
con = &connectors.RPConnector{Client: &http.Client{}}
err := viper.Unmarshal(con)
if err != nil {
fmt.Println(err)
}
// case "POLCon":
// con = RPConnector{}
// case "JiraCon":
// con = RPConnector{}
default:
con = &connectors.RPConnector{Client: &http.Client{}}
err := viper.Unmarshal(con)
if err != nil {
fmt.Println(err)
}
}
return con
}