-
Notifications
You must be signed in to change notification settings - Fork 3
/
list_connectors.go
99 lines (85 loc) · 2.67 KB
/
list_connectors.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
package connect
import (
"context"
"fmt"
"net/url"
)
func (c *Client) ListConnectors(ctx context.Context) ([]string, error) {
var connectorNames []string
response, err := c.client.NewRequest().
SetContext(ctx).
SetResult(&connectorNames).
SetError(ApiError{}).
Get("/connectors")
if err != nil {
return nil, err
}
err = getErrorFromResponse(response)
if err != nil {
return nil, err
}
return connectorNames, nil
}
// ListConnectorsOptions describe the available options to list connectors. Either Status or Info must be set to true.
type ListConnectorsOptions struct {
ExpandStatus bool
ExpandInfo bool
}
func (l *ListConnectorsOptions) Validate() error {
if !l.ExpandStatus && !l.ExpandInfo {
return fmt.Errorf("either info or status must be set to true")
}
return nil
}
// ListConnectorsResponseExpanded is the response to /connectors if the expand query parameters are set.
type ListConnectorsResponseExpanded struct {
Info ConnectorInfo `json:"info"`
Status ConnectorStateInfo `json:"status"`
}
// ListConnectorsResponseExpandedInfo represents the Info object for described connectors.
// Deprecated: Use ConnectorInfo instead, the same information is available there
type ListConnectorsResponseExpandedInfo struct {
Name string `json:"name"`
Config map[string]string `json:"config"`
Tasks []struct {
Connector string `json:"connector"`
Task int `json:"task"`
} `json:"tasks"`
Type string `json:"type"`
}
// ListConnectorsResponseExpandedStatus represents the Status object for described connectors.
// Deprecated: Use ConnectorStateInfo instead, the same information is available there
type ListConnectorsResponseExpandedStatus struct {
Name string `json:"name"`
Connector struct {
State string `json:"state"`
WorkerID string `json:"worker_id"`
Trace string `json:"trace,omitempty"`
}
Tasks []struct {
ID int `json:"id"`
State string `json:"state"`
WorkerID string `json:"worker_id"`
Trace string `json:"trace,omitempty"`
} `json:"tasks"`
Type string `json:"type"`
}
func (c *Client) ListConnectorsExpanded(ctx context.Context) (map[string]ListConnectorsResponseExpanded, error) {
// Adds additional options that show us more information about the connectors list
expands := []string{"info", "status"}
connectors := map[string]ListConnectorsResponseExpanded{}
response, err := c.client.NewRequest().
SetContext(ctx).
SetResult(&connectors).
SetError(ApiError{}).
SetQueryParamsFromValues(url.Values{"expand": expands}).
Get("/connectors")
if err != nil {
return nil, err
}
err = getErrorFromResponse(response)
if err != nil {
return nil, err
}
return connectors, nil
}