-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
executable file
·115 lines (98 loc) · 4.22 KB
/
client.go
File metadata and controls
executable file
·115 lines (98 loc) · 4.22 KB
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
109
110
111
112
113
114
115
// Copyright © 2019 cloud.ca Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package gocca contains the implementation of cloud.ca API
package gocca
import (
"github.com/cloud-ca/gocca/api"
"github.com/cloud-ca/gocca/configuration"
"github.com/cloud-ca/gocca/services"
"github.com/cloud-ca/gocca/services/cloudca"
)
// DefaultAPIURL default API URL to use
const DefaultAPIURL = "https://api.cloud.ca/v1/"
// Client for interacting with cloud.ca API
type Client struct {
apiClient api.Client
Tasks services.TaskService
Environments configuration.EnvironmentService
Users configuration.UserService
ServiceConnections configuration.ServiceConnectionService
Organizations configuration.OrganizationService
}
// GetAPIClient Get the API Client used by all the services
func (c *Client) GetAPIClient() api.Client {
return c.apiClient
}
// GetAPIURL Get the API url used to do he calls
func (c *Client) GetAPIURL() string {
return c.GetAPIClient().GetAPIURL()
}
// GetAPIKey Get the API key used in the calls
func (c *Client) GetAPIKey() string {
return c.GetAPIClient().GetAPIKey()
}
// GetResources get the Resources for a specific serviceCode and environmentName
// For now it assumes that the serviceCode belongs to a cloud.ca service type
func (c *Client) GetResources(serviceCode string, environmentName string) (services.ServiceResources, error) {
//TODO: change to check service type of service code
return cloudca.NewResources(c.apiClient, serviceCode, environmentName), nil
}
// NewClient Create a Client with the default URL
func NewClient(apiKey string) *Client {
return NewClientWithURL(DefaultAPIURL, apiKey)
}
// NewClientWithURL Create a Client with a custom URL
func NewClientWithURL(apiURL string, apiKey string) *Client {
apiClient := api.NewClient(apiURL, apiKey)
return NewClientWithAPIClient(apiClient)
}
// NewInsecureClientWithURL Create a Client with a custom URL that accepts insecure connections
func NewInsecureClientWithURL(apiURL string, apiKey string) *Client {
apiClient := api.NewInsecureClient(apiURL, apiKey)
return NewClientWithAPIClient(apiClient)
}
// NewClientWithAPIClient Create a Client with a provided API client
func NewClientWithAPIClient(apiClient api.Client) *Client {
return &Client{
apiClient: apiClient,
Tasks: services.NewTaskService(apiClient),
Environments: configuration.NewEnvironmentService(apiClient),
Users: configuration.NewUserService(apiClient),
ServiceConnections: configuration.NewServiceConnectionService(apiClient),
Organizations: configuration.NewOrganizationService(apiClient),
}
}
///////////////////////////////////////////////////
// Deperacated functions
///////////////////////////////////////////////////
// NewCcaClient Create a Client with the default URL
// **Deprecated, Use NewClient(apiKey string) instead**
func NewCcaClient(apiKey string) *Client {
return NewClient(apiKey)
}
// NewCcaClientWithURL Create a Client with a custom URL
// **Deprecated, NewClientWithURL(apiKey string, apiKey string) instead**
func NewCcaClientWithURL(apiURL string, apiKey string) *Client {
return NewClientWithURL(apiURL, apiKey)
}
// NewInsecureCcaClientWithURL Create a Client with a custom URL that accepts insecure connections
// **Deprecated, Use NewInsecureClientWithURL(apiURL string, apiKey string) instead**
func NewInsecureCcaClientWithURL(apiURL string, apiKey string) *Client {
return NewInsecureClientWithURL(apiURL, apiKey)
}
// NewCcaClientWithAPIClient Create a Client with a provided API client
// **Deprecated, Use NewCcaClientWithApiClient(apiClient api.Client) instead**
func NewCcaClientWithAPIClient(apiClient api.Client) *Client {
return NewClientWithAPIClient(apiClient)
}