-
Notifications
You must be signed in to change notification settings - Fork 66
/
config.go
43 lines (35 loc) · 957 Bytes
/
config.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
package octopusdeploy
import (
"net/url"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)
// Config holds Address and the APIKey of the Octopus Deploy server
type Config struct {
Address string
APIKey string
SpaceID string
}
// Client returns a new Octopus Deploy client
func (c *Config) Client() (*client.Client, diag.Diagnostics) {
apiURL, err := url.Parse(c.Address)
if err != nil {
return nil, diag.FromErr(err)
}
octopus, err := client.NewClient(nil, apiURL, c.APIKey, "")
if err != nil {
return nil, diag.FromErr(err)
}
if len(c.SpaceID) > 0 {
space, err := spaces.GetByID(octopus, c.SpaceID)
if err != nil {
return nil, diag.FromErr(err)
}
octopus, err = client.NewClient(nil, apiURL, c.APIKey, space.GetID())
if err != nil {
return nil, diag.FromErr(err)
}
}
return octopus, nil
}