-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvendors.go
119 lines (101 loc) · 4.02 KB
/
vendors.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package cloudability
import (
"fmt"
)
const vendorsEndpoint = "/vendors/"
// VendorsEndpoint - Cloudabiity Vendors Endpoint
type VendorsEndpoint struct {
*v3Endpoint
}
// Vendors - Vendors Endpoint
func (c *Client) Vendors() *VendorsEndpoint {
return &VendorsEndpoint{newV3Endpoint(c, vendorsEndpoint)}
}
// Vendor - Cloudability Vendor
type Vendor struct {
Key string `json:"key"`
Label string `json:"label"`
Description string `json:"description"`
}
// Verification - Cloudability Verification
type Verification struct {
State string `json:"state"`
LastVerificationAttemptedAt string `json:"lastVerificationAttemptedAt"`
Message string `json:"message"`
}
// Authorization - Cloudabiity Authorization
type Authorization struct {
Type string `json:"type"`
RoleName string `json:"roleName"`
ExternalID string `json:"externalId"`
BucketName *string `json:"bucketName,omitempty"`
CostAndUsageReport *CostAndUsageReport `json:"costAndUsageReport,omitempty"`
}
// Account - Cloudability Account
type Account struct {
ID string `json:"id"`
VendorAccountName string `json:"vendorAccountName"`
VendorAccountID string `json:"vendorAccountId"`
VendorKey string `json:"vendorKey"`
Verification *Verification `json:"verification"`
Authorization *Authorization `json:"authorization"`
ParentAccountID string `json:"parentAccountId"`
CreatedAt string `json:"createdAt"`
}
// GetVendors - get all vendors
func (e VendorsEndpoint) GetVendors() ([]Vendor, error) {
var result v3Result[[]Vendor]
err := e.get(e, "", &result)
return result.Result, err
}
// GetAccounts - get all accounts for a given vendor
func (e VendorsEndpoint) GetAccounts(vendor string) ([]Account, error) {
var result v3Result[[]Account]
err := e.get(e, fmt.Sprintf("%s/accounts/", vendor), &result)
return result.Result, err
}
// GetAccount - get a single account for a given vendor
func (e VendorsEndpoint) GetAccount(vendor string, accountID string) (*Account, error) {
var result v3Result[*Account]
err := e.get(e, fmt.Sprintf("%s/accounts/%s?viewId=0", vendor, accountID), &result)
return result.Result, err
}
// VerifyAccount - verify account
func (e VendorsEndpoint) VerifyAccount(vendor string, accountID string) (*Account, error) {
var result v3Result[*Account]
err := e.post(e, fmt.Sprintf("%s/accounts/%s/verification?viewId=0", vendor, accountID), nil, &result)
return result.Result, err
}
// CostAndUsageReport - cost and usage report
type CostAndUsageReport struct {
Name string `json:"name,omitempty"`
Prefix string `json:"prefix,omitempty"`
}
// NewLinkedAccountParams - params required to create a new linked account
type NewLinkedAccountParams struct {
VendorAccountID string `json:"vendorAccountId"`
Type string `json:"type"`
}
// NewMasterAccountParams - params required to create a new master account
type NewMasterAccountParams struct {
*NewLinkedAccountParams
BucketName string `json:"bucketName"`
CostAndUsageReport *CostAndUsageReport `json:"costAndUsageReport"`
}
// NewMasterAccount - Create a new master account
func (e VendorsEndpoint) NewMasterAccount(vendorKey string, newAccountParams *NewMasterAccountParams) (*Account, error) {
var result v3Result[*Account]
err := e.post(e, fmt.Sprintf("%s/accounts", vendorKey), newAccountParams, &result)
return result.Result, err
}
// NewLinkedAccount - Create a new linked account
func (e VendorsEndpoint) NewLinkedAccount(vendorKey string, newAccountParams *NewLinkedAccountParams) (*Account, error) {
var result v3Result[*Account]
err := e.post(e, fmt.Sprintf("%s/accounts", vendorKey), newAccountParams, &result)
return result.Result, err
}
// DeleteAccount - Delete an account
func (e VendorsEndpoint) DeleteAccount(vendor string, accountID string) error {
err := e.delete(e, fmt.Sprintf("%s/accounts/%s?viewId=0", vendor, accountID))
return err
}