-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
89 lines (79 loc) · 1.95 KB
/
client.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
81
82
83
84
85
86
87
88
89
package main
import (
"crypto/tls"
"net/http"
"time"
)
// Client represents a connection to Sangfor
type Client struct {
Client *http.Client
BaseAPIURL string
PublicKey string
Token string
Valid bool
}
// GetAPIClient Gets Sangfor API Client
func GetAPIClient(host string) *Client {
// Create custom transport layer configuration
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
MinVersion: getMinTLSVersion(),
},
}
// Create HTTP Client
httpClient := &http.Client{
Transport: tr,
}
// Sangfor API Client
client := &Client{
Client: httpClient,
Valid: true,
}
// Set Base API
client.BaseAPIURL = host + "/janus"
return client
}
// getMinTLSVersion Gets Minimum TLS Version
func getMinTLSVersion() uint16 {
return tls.VersionTLS12
}
// SangforAuthResponse represents the auth response
type SangforAuthResponse struct {
Message string `json:"message"`
Data struct {
Access struct {
Token struct {
IssuedAt time.Time `json:"issued_at"`
Expires time.Time `json:"expires"`
ID string `json:"id"`
Tenant struct {
ID string `json:"id"`
Description string `json:"description"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
} `json:"tenant"`
AuditIds []string `json:"audit_ids"`
} `json:"token"`
User struct {
Username string `json:"username"`
Name string `json:"name"`
ID string `json:"id"`
RolesLinks []interface{} `json:"roles_links"`
Roles []struct {
Name string `json:"name"`
} `json:"roles"`
} `json:"user"`
} `json:"access"`
} `json:"data"`
Code int `json:"code"`
}
// SangforAuthReq represents the auth request
type SangforAuthReq struct {
Auth struct {
PasswordCredentials struct {
Username string `json:"username"`
Password string `json:"password"`
} `json:"passwordCredentials"`
} `json:"auth"`
}