-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
106 lines (87 loc) · 2.07 KB
/
main.go
File metadata and controls
106 lines (87 loc) · 2.07 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"bufio"
"crypto/tls"
"fmt"
"net/http"
"os"
"github.com/dciangot/sts-wire/pkg/core"
)
func main() {
inputReader := *bufio.NewReader(os.Stdin)
scanner := core.GetInputWrapper{
Scanner: inputReader,
}
instance := ""
if len(os.Args) > 1 {
instance = os.Args[1]
if instance == "-h" {
fmt.Println("dodas-IAMClientRec <client name>")
return
} else if instance == "" {
instance = "automatic"
}
} else {
instance = "automatic"
}
iamServer := ""
iamServer = os.Getenv("IAM_INSTANCE")
if iamServer == "" {
if len(os.Args) > 2 {
iamServer = os.Args[2]
}
}
if iamServer == "" {
fmt.Println("No IAM instance specified, please set env IAM_INSTANCE or use:")
fmt.Println("dodas-IAMClientRec <client name> <IAM instance>")
return
}
callback := os.Getenv("OAUTH_CALLBACK")
if callback == "" {
fmt.Println("No Service redirect callback url specified, please set env OAUTH_CALLBACK")
return
}
confDir := "." + instance
_, err := os.Stat(confDir)
if os.IsNotExist(err) {
os.Mkdir(confDir, os.ModePerm)
}
clientConfig := core.IAMClientConfig{
CallbackURL: callback,
ClientName: instance,
}
// Create a CA certificate pool and add cert.pem to it
//caCert, err := ioutil.ReadFile("MINIO.pem")
//if err != nil {
// log.Fatal(err)
//}
//caCertPool := x509.NewCertPool()
//caCertPool.AppendCertsFromPEM(caCert)
// Create the TLS Config with the CA pool and enable Client certificate validation
cfg := &tls.Config{
//ClientCAs: caCertPool,
InsecureSkipVerify: true,
}
//cfg.BuildNameToCertificate()
tr := &http.Transport{
TLSClientConfig: cfg,
}
httpClient := &http.Client{
Transport: tr,
}
clientIAM := core.InitClientConfig{
ConfDir: confDir,
ClientConfig: clientConfig,
Scanner: scanner,
HTTPClient: *httpClient,
IAMServer: iamServer,
ClientTemplate: ClientTemplate,
NoPWD: true,
}
_, clientResponse, _, err := clientIAM.InitClient(instance)
if err != nil {
panic(err)
}
fmt.Println(clientResponse.ClientID)
fmt.Println(clientResponse.ClientSecret)
}