-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathworkload_identity_providers.go
165 lines (136 loc) · 5.92 KB
/
workload_identity_providers.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package scalr
import (
"context"
"errors"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ WorkloadIdentityProviders = (*workloadIdentityProviders)(nil)
// WorkloadIdentityProviders describes all the workload identity provider related methods that the Scalr API supports.
type WorkloadIdentityProviders interface {
List(ctx context.Context, options WorkloadIdentityProvidersListOptions) (*WorkloadIdentityProvidersList, error)
Create(ctx context.Context, options WorkloadIdentityProviderCreateOptions) (*WorkloadIdentityProvider, error)
Read(ctx context.Context, providerID string) (*WorkloadIdentityProvider, error)
Update(ctx context.Context, providerID string, options WorkloadIdentityProviderUpdateOptions) (*WorkloadIdentityProvider, error)
Delete(ctx context.Context, providerID string) error
}
// workloadIdentityProviders implements WorkloadIdentityProviders.
type workloadIdentityProviders struct {
client *Client
}
// WorkloadIdentityProvidersList represents a list of workload identity providers.
type WorkloadIdentityProvidersList struct {
*Pagination
Items []*WorkloadIdentityProvider
}
// WorkloadIdentityProvider represents a Scalr workload identity provider.
type WorkloadIdentityProvider struct {
ID string `jsonapi:"primary,workload-identity-providers"`
Name string `jsonapi:"attr,name"`
URL string `jsonapi:"attr,url"`
AllowedAudiences []string `jsonapi:"attr,allowed-audiences"`
CreatedAt string `jsonapi:"attr,created-at"`
CreatedByEmail *string `jsonapi:"attr,created-by-email"`
Status string `jsonapi:"attr,status"`
AssumeServiceAccountPolicies []*AssumeServiceAccountPolicy `jsonapi:"relation,assume-service-account-policies"`
}
// WorkloadIdentityProvidersListOptions represents the options for listing workload identity providers.
type WorkloadIdentityProvidersListOptions struct {
ListOptions
Sort string `url:"sort,omitempty"`
Query *string `url:"query,omitempty"`
Filter *WorkloadIdentityProviderFilter `url:"filter,omitempty"`
}
type WorkloadIdentityProviderFilter struct {
WorkloadIdentityProvider string `url:"workload-identity-provider,omitempty"`
Name string `url:"name,omitempty"`
Url string `url:"url,omitempty"`
}
// List all workload identity providers within a Scalr account.
func (s *workloadIdentityProviders) List(ctx context.Context, options WorkloadIdentityProvidersListOptions) (*WorkloadIdentityProvidersList, error) {
req, err := s.client.newRequest("GET", "workload-identity-providers", &options)
if err != nil {
return nil, err
}
wipList := &WorkloadIdentityProvidersList{}
err = s.client.do(ctx, req, wipList)
if err != nil {
return nil, err
}
return wipList, nil
}
// WorkloadIdentityProviderCreateOptions represents the options for creating a new workload identity provider.
type WorkloadIdentityProviderCreateOptions struct {
ID string `jsonapi:"primary,workload-identity-providers"`
Name *string `jsonapi:"attr,name"`
URL *string `jsonapi:"attr,url"`
AllowedAudiences []string `jsonapi:"attr,allowed-audiences"`
}
// Create a new workload identity provider.
func (s *workloadIdentityProviders) Create(ctx context.Context, options WorkloadIdentityProviderCreateOptions) (*WorkloadIdentityProvider, error) {
options.ID = ""
req, err := s.client.newRequest("POST", "workload-identity-providers", &options)
if err != nil {
return nil, err
}
provider := &WorkloadIdentityProvider{}
err = s.client.do(ctx, req, provider)
if err != nil {
return nil, err
}
return provider, nil
}
// Read a workload identity provider by provider ID.
func (s *workloadIdentityProviders) Read(ctx context.Context, providerID string) (*WorkloadIdentityProvider, error) {
if !validStringID(&providerID) {
return nil, errors.New("invalid value for workload identity provider ID")
}
urlPath := fmt.Sprintf("workload-identity-providers/%s", url.QueryEscape(providerID))
req, err := s.client.newRequest("GET", urlPath, nil)
if err != nil {
return nil, err
}
provider := &WorkloadIdentityProvider{}
err = s.client.do(ctx, req, provider)
if err != nil {
return nil, err
}
return provider, nil
}
// WorkloadIdentityProviderUpdateOptions represents the options for updating a workload identity provider.
type WorkloadIdentityProviderUpdateOptions struct {
ID string `jsonapi:"primary,workload-identity-providers"`
Name *string `jsonapi:"attr,name"`
AllowedAudiences []string `jsonapi:"attr,allowed-audiences"`
}
// Update an existing workload identity provider.
func (s *workloadIdentityProviders) Update(ctx context.Context, providerID string, options WorkloadIdentityProviderUpdateOptions) (*WorkloadIdentityProvider, error) {
if !validStringID(&providerID) {
return nil, errors.New("invalid value for workload identity provider ID")
}
options.ID = ""
urlPath := fmt.Sprintf("workload-identity-providers/%s", url.QueryEscape(providerID))
req, err := s.client.newRequest("PATCH", urlPath, &options)
if err != nil {
return nil, err
}
provider := &WorkloadIdentityProvider{}
err = s.client.do(ctx, req, provider)
if err != nil {
return nil, err
}
return provider, nil
}
// Delete a workload identity provider by its ID.
func (s *workloadIdentityProviders) Delete(ctx context.Context, providerID string) error {
if !validStringID(&providerID) {
return errors.New("invalid value for workload identity provider ID")
}
urlPath := fmt.Sprintf("workload-identity-providers/%s", url.QueryEscape(providerID))
req, err := s.client.newRequest("DELETE", urlPath, nil)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}