-
Notifications
You must be signed in to change notification settings - Fork 7
/
connector.go
53 lines (47 loc) · 1.12 KB
/
connector.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
package builder
import (
"fmt"
"github.com/go-resty/resty/v2"
"gopkg.in/yaml.v2"
"strings"
)
type ConnectorConfig struct {
Kind string `json:"kind"`
ApiVersion string `json:"apiVersion"`
Metadata struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
} `json:"metadata"`
Spec struct {
Type string `json:"type"`
Config string `json:"config"`
} `json:"spec"`
}
func GetBuildManifest(url string) (*ConnectorConfig, error) {
resp, err := resty.New().NewRequest().Get(url)
if err != nil {
return nil, err
}
manifests := string(resp.Body())
for _, manifest := range strings.Split(manifests, "\n---\n") {
c, err := parseConnectorConfig(manifest)
if err != nil {
continue
}
return c, nil
}
return nil, fmt.Errorf("no valid connector configuration found ")
}
func parseConnectorConfig(manifest string) (*ConnectorConfig, error) {
c := &ConnectorConfig{}
err := yaml.Unmarshal([]byte(manifest), c)
if err != nil {
return nil, err
}
switch c.Spec.Type {
case "bridges", "targets", "sources":
return c, nil
default:
return nil, fmt.Errorf("config is not a connector")
}
}