-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathadmin_setting_twilio.go
105 lines (85 loc) · 3.06 KB
/
admin_setting_twilio.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tfe
import (
"context"
)
// Compile-time proof of interface implementation.
var _ TwilioSettings = (*adminTwilioSettings)(nil)
// TwilioSettings describes all the Twilio admin settings for the Admin Setting API.
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/settings
type TwilioSettings interface {
// Read returns the Twilio settings.
Read(ctx context.Context) (*AdminTwilioSetting, error)
// Update updates Twilio settings.
Update(ctx context.Context, options AdminTwilioSettingsUpdateOptions) (*AdminTwilioSetting, error)
// Verify verifies Twilio settings.
Verify(ctx context.Context, options AdminTwilioSettingsVerifyOptions) error
}
type adminTwilioSettings struct {
client *Client
}
// AdminTwilioSetting represents the Twilio settings in Terraform Enterprise.
type AdminTwilioSetting struct {
ID string `jsonapi:"primary,twilio-settings"`
Enabled bool `jsonapi:"attr,enabled"`
AccountSid string `jsonapi:"attr,account-sid"`
FromNumber string `jsonapi:"attr,from-number"`
}
// Read returns the Twilio settings.
func (a *adminTwilioSettings) Read(ctx context.Context) (*AdminTwilioSetting, error) {
req, err := a.client.NewRequest("GET", "admin/twilio-settings", nil)
if err != nil {
return nil, err
}
twilio := &AdminTwilioSetting{}
err = req.Do(ctx, twilio)
if err != nil {
return nil, err
}
return twilio, nil
}
// AdminTwilioSettingsUpdateOptions represents the admin options for updating
// Twilio settings.
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/settings#request-body-4
type AdminTwilioSettingsUpdateOptions struct {
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
AccountSid *string `jsonapi:"attr,account-sid,omitempty"`
AuthToken *string `jsonapi:"attr,auth-token,omitempty"`
FromNumber *string `jsonapi:"attr,from-number,omitempty"`
}
// AdminTwilioSettingsVerifyOptions represents the test number to verify Twilio.
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/settings#verify-twilio-settings
type AdminTwilioSettingsVerifyOptions struct {
TestNumber *string `jsonapi:"attr,test-number"` // Required
}
// Update updates the Twilio settings.
func (a *adminTwilioSettings) Update(ctx context.Context, options AdminTwilioSettingsUpdateOptions) (*AdminTwilioSetting, error) {
req, err := a.client.NewRequest("PATCH", "admin/twilio-settings", &options)
if err != nil {
return nil, err
}
twilio := &AdminTwilioSetting{}
err = req.Do(ctx, twilio)
if err != nil {
return nil, err
}
return twilio, nil
}
// Verify verifies Twilio settings.
func (a *adminTwilioSettings) Verify(ctx context.Context, options AdminTwilioSettingsVerifyOptions) error {
if err := options.valid(); err != nil {
return err
}
req, err := a.client.NewRequest("PATCH", "admin/twilio-settings/verify", &options)
if err != nil {
return err
}
return req.Do(ctx, nil)
}
func (o AdminTwilioSettingsVerifyOptions) valid() error {
if !validString(o.TestNumber) {
return ErrRequiredTestNumber
}
return nil
}