-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathazure_oidc_configuration.go
More file actions
147 lines (115 loc) · 4.29 KB
/
azure_oidc_configuration.go
File metadata and controls
147 lines (115 loc) · 4.29 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
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
package tfe
import (
"context"
"fmt"
"net/url"
)
// AzureOIDCConfigurations describes all the Azure OIDC configuration related methods that the HCP Terraform API supports.
// HCP Terraform API docs:
// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/hold-your-own-key/oidc-configurations/azure
type AzureOIDCConfigurations interface {
Create(ctx context.Context, organization string, options AzureOIDCConfigurationCreateOptions) (*AzureOIDCConfiguration, error)
Read(ctx context.Context, oidcID string) (*AzureOIDCConfiguration, error)
Update(ctx context.Context, oidcID string, options AzureOIDCConfigurationUpdateOptions) (*AzureOIDCConfiguration, error)
Delete(ctx context.Context, oidcID string) error
}
type azureOIDCConfigurations struct {
client *Client
}
var _ AzureOIDCConfigurations = &azureOIDCConfigurations{}
type AzureOIDCConfiguration struct {
ID string `jsonapi:"primary,azure-oidc-configurations"`
ClientID string `jsonapi:"attr,client-id"`
SubscriptionID string `jsonapi:"attr,subscription-id"`
TenantID string `jsonapi:"attr,tenant-id"`
Organization *Organization `jsonapi:"relation,organization"`
}
type AzureOIDCConfigurationCreateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,azure-oidc-configurations"`
// Attributes
ClientID string `jsonapi:"attr,client-id"`
SubscriptionID string `jsonapi:"attr,subscription-id"`
TenantID string `jsonapi:"attr,tenant-id"`
}
type AzureOIDCConfigurationUpdateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,azure-oidc-configurations"`
// Attributes
ClientID *string `jsonapi:"attr,client-id,omitempty"`
SubscriptionID *string `jsonapi:"attr,subscription-id,omitempty"`
TenantID *string `jsonapi:"attr,tenant-id,omitempty"`
}
func (o *AzureOIDCConfigurationCreateOptions) valid() error {
if o.ClientID == "" {
return ErrRequiredClientID
}
if o.SubscriptionID == "" {
return ErrRequiredSubscriptionID
}
if o.TenantID == "" {
return ErrRequiredTenantID
}
return nil
}
func (aoc *azureOIDCConfigurations) Create(ctx context.Context, organization string, options AzureOIDCConfigurationCreateOptions) (*AzureOIDCConfiguration, error) {
if !validStringID(&organization) {
return nil, ErrInvalidOrg
}
if err := options.valid(); err != nil {
return nil, err
}
req, err := aoc.client.NewRequest("POST", fmt.Sprintf("organizations/%s/oidc-configurations", url.PathEscape(organization)), &options)
if err != nil {
return nil, err
}
azureOIDCConfiguration := &AzureOIDCConfiguration{}
err = req.Do(ctx, azureOIDCConfiguration)
if err != nil {
return nil, err
}
return azureOIDCConfiguration, nil
}
func (aoc *azureOIDCConfigurations) Read(ctx context.Context, oidcID string) (*AzureOIDCConfiguration, error) {
req, err := aoc.client.NewRequest("GET", fmt.Sprintf(OIDCConfigPathFormat, url.PathEscape(oidcID)), nil)
if err != nil {
return nil, err
}
azureOIDCConfiguration := &AzureOIDCConfiguration{}
err = req.Do(ctx, azureOIDCConfiguration)
if err != nil {
return nil, err
}
return azureOIDCConfiguration, nil
}
func (aoc *azureOIDCConfigurations) Update(ctx context.Context, oidcID string, options AzureOIDCConfigurationUpdateOptions) (*AzureOIDCConfiguration, error) {
if !validStringID(&oidcID) {
return nil, ErrInvalidOIDC
}
req, err := aoc.client.NewRequest("PATCH", fmt.Sprintf(OIDCConfigPathFormat, url.PathEscape(oidcID)), &options)
if err != nil {
return nil, err
}
azureOIDCConfiguration := &AzureOIDCConfiguration{}
err = req.Do(ctx, azureOIDCConfiguration)
if err != nil {
return nil, err
}
return azureOIDCConfiguration, nil
}
func (aoc *azureOIDCConfigurations) Delete(ctx context.Context, oidcID string) error {
if !validStringID(&oidcID) {
return ErrInvalidOIDC
}
req, err := aoc.client.NewRequest("DELETE", fmt.Sprintf(OIDCConfigPathFormat, url.PathEscape(oidcID)), nil)
if err != nil {
return err
}
return req.Do(ctx, nil)
}