/
iron_client.go
66 lines (56 loc) · 1.31 KB
/
iron_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
package hsdp
import (
"fmt"
"github.com/cloudfoundry-community/gautocloud"
"github.com/cloudfoundry-community/gautocloud/connectors"
"github.com/philips-software/go-hsdp-api/iron"
)
func init() {
gautocloud.RegisterConnector(NewIronClientConnector())
}
type IronClient struct {
iron.Config
*iron.Client
}
type IronClientConnector struct {
wrapRawConn connectors.Connector
}
func (i IronClientConnector) Id() string {
return "hsdp:iron-client"
}
func (i IronClientConnector) Name() string {
return i.wrapRawConn.Name()
}
func (i IronClientConnector) Tags() []string {
return i.wrapRawConn.Tags()
}
func (i IronClientConnector) Load(schema interface{}) (interface{}, error) {
schema, err := i.wrapRawConn.Load(schema)
if err != nil {
return nil, err
}
fSchema := schema.(IronPlan)
if fSchema.ProjectID == "" {
return nil, fmt.Errorf("invalid ProjectID")
}
if fSchema.Token == "" {
return nil, fmt.Errorf("missing token")
}
config := iron.Config(fSchema)
client, err := iron.NewClient(&config)
if err != nil {
return nil, err
}
return &IronClient{
Client: client,
Config: config,
}, nil
}
func (i IronClientConnector) Schema() interface{} {
return i.wrapRawConn.Schema()
}
func NewIronClientConnector() connectors.Connector {
return &IronClientConnector{
wrapRawConn: NewIronRawConnector(),
}
}