-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
108 lines (91 loc) · 2.13 KB
/
api.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package drovedns
import (
"fmt"
"sync"
)
// Host struct
type Host struct {
Host string
Port int32
PortType string
}
type HostGroup struct {
Hosts []Host
Tags map[string]string
}
// App struct
type App struct {
ID string
Vhost string
Hosts []Host
Tags map[string]string
Groups map[string]HostGroup
}
type DroveServiceHost struct {
Host string `json:"host"`
Port int32 `json:"port"`
PortType string `json:"portType"`
}
// DroveAppsResponse struct for our apps nested with tasks.
type DroveAppsResponse struct {
Status string `json:"status"`
Apps []DroveApp `json:"data"`
Message string `json:"message"`
}
type DroveApp struct {
ID string `json:"appId"`
Vhost string `json:"vhost"`
Tags map[string]string `json:"tags"`
Hosts []DroveServiceHost `json:"hosts"`
}
type DroveEventSummary struct {
EventsCount map[string]interface{} `json:"eventsCount"`
LastSyncTime int64 `json:"lastSyncTime"`
}
type DroveEventsApiResponse struct {
Status string `json:"status"`
EventSummary DroveEventSummary `json:"data"`
Message string `json:"message"`
}
type LeaderController struct {
Endpoint string
Host string
Port int32
}
type EndpointStatus struct {
Endpoint string
Healthy bool
Message string
}
type CurrSyncPoint struct {
sync.RWMutex
LastSyncTime int64
}
type DroveAuthConfig struct {
User string
Pass string
AccessToken string
}
func (dc DroveAuthConfig) Validate() error {
if dc.User == "" && dc.Pass == "" && dc.AccessToken == "" {
return fmt.Errorf("User-pass or AccessToken should be set")
}
if (dc.Pass != "" || dc.User != "") && dc.AccessToken != "" {
return fmt.Errorf("Both user-pass and access token should not be set")
}
return nil
}
type DroveConfig struct {
Endpoint string
AuthConfig DroveAuthConfig
SkipSSL bool
}
func (dc DroveConfig) Validate() error {
if dc.Endpoint == "" {
return fmt.Errorf("Endpoint Cant be empty")
}
return dc.AuthConfig.Validate()
}
func NewDroveConfig() DroveConfig {
return DroveConfig{SkipSSL: false, AuthConfig: DroveAuthConfig{}}
}