-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathclient_list_activation.go
218 lines (176 loc) · 6.95 KB
/
client_list_activation.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package clientlists
import (
"context"
"fmt"
"net/http"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session"
validation "github.com/go-ozzo/ozzo-validation/v4"
)
type (
// ActivationParams contains activation general parameters
ActivationParams struct {
Action ActivationAction `json:"action"`
Comments string `json:"comments"`
Network ActivationNetwork `json:"network"`
NotificationRecipients []string `json:"notificationRecipients"`
SiebelTicketID string `json:"siebelTicketId"`
}
// GetActivationRequest contains activation request param
GetActivationRequest struct {
ActivationID int64
}
// GetActivationResponse contains activation details
GetActivationResponse struct {
ActivationID int64 `json:"activationId"`
CreateDate string `json:"createDate"`
CreatedBy string `json:"createdBy"`
Fast bool `json:"fast"`
InitialActivation bool `json:"initialActivation"`
ActivationStatus ActivationStatus `json:"activationStatus"`
ListID string `json:"listId"`
Version int64 `json:"version"`
ActivationParams
}
// CreateActivationRequest contains activation request parameters for CreateActivation method
CreateActivationRequest struct {
ListID string
ActivationParams
}
// CreateActivationResponse contains activation response
CreateActivationResponse GetActivationStatusResponse
// GetActivationStatusRequest contains request params for GetActivationStatus
GetActivationStatusRequest struct {
ListID string
Network ActivationNetwork
}
// GetActivationStatusResponse contains activation status response
GetActivationStatusResponse struct {
Action ActivationAction `json:"action"`
ActivationID int64 `json:"activationId"`
ActivationStatus ActivationStatus `json:"activationStatus"`
Comments string `json:"comments"`
CreateDate string `json:"createDate"`
CreatedBy string `json:"createdBy"`
ListID string `json:"listId"`
Network ActivationNetwork `json:"network"`
NotificationRecipients []string `json:"notificationRecipients"`
SiebelTicketID string `json:"siebelTicketId"`
Version int64 `json:"version"`
}
// ActivationNetwork is a type for network field
ActivationNetwork string
// ActivationStatus is a type for activationStatus field
ActivationStatus string
// ActivationAction is a type for action field
ActivationAction string
)
const (
// Staging activation network value STAGING
Staging ActivationNetwork = "STAGING"
// Production activation network value PRODUCTION
Production ActivationNetwork = "PRODUCTION"
// Inactive activation status value INACTIVE
Inactive ActivationStatus = "INACTIVE"
// PendingActivation activation status value PENDING_ACTIVATION
PendingActivation ActivationStatus = "PENDING_ACTIVATION"
// Active activation status value ACTIVE
Active ActivationStatus = "ACTIVE"
// Modified activation status value MODIFIED
Modified ActivationStatus = "MODIFIED"
// PendingDeactivation activation status value PENDING_DEACTIVATION
PendingDeactivation ActivationStatus = "PENDING_DEACTIVATION"
// Failed activation status value FAILED
Failed ActivationStatus = "FAILED"
// Activate action value ACTIVATE
Activate ActivationAction = "ACTIVATE"
)
func (v GetActivationRequest) validate() error {
return edgegriderr.ParseValidationErrors(validation.Errors{
"ActivationID": validation.Validate(v.ActivationID, validation.Required),
})
}
func (v GetActivationStatusRequest) validate() error {
return edgegriderr.ParseValidationErrors(validation.Errors{
"ListID": validation.Validate(v.ListID, validation.Required),
"Network": validation.Validate(v.Network,
validation.Required,
validation.In(Staging, Production),
),
})
}
func (v CreateActivationRequest) validate() error {
return edgegriderr.ParseValidationErrors(validation.Errors{
"ListID": validation.Validate(v.ListID, validation.Required),
"Network": validation.Validate(v.Network,
validation.Required,
validation.In(Staging, Production),
),
})
}
func (p *clientlists) CreateActivation(ctx context.Context, params CreateActivationRequest) (*CreateActivationResponse, error) {
logger := p.Log(ctx)
logger.Debug("Create Activation")
if err := params.validate(); err != nil {
return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
}
uri := fmt.Sprintf("/client-list/v1/lists/%s/activations", params.ListID)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, nil)
if err != nil {
return nil, fmt.Errorf("create 'create activation' request failed: %s", err.Error())
}
var rval CreateActivationResponse
resp, err := p.Exec(req, &rval, params.ActivationParams)
if err != nil {
return nil, fmt.Errorf("create activation request failed: %s", err.Error())
}
defer session.CloseResponseBody(resp)
if resp.StatusCode != http.StatusOK {
return nil, p.Error(resp)
}
return &rval, nil
}
func (p *clientlists) GetActivationStatus(ctx context.Context, params GetActivationStatusRequest) (*GetActivationStatusResponse, error) {
logger := p.Log(ctx)
logger.Debug("Get Activation Status")
if err := params.validate(); err != nil {
return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
}
uri := fmt.Sprintf("/client-list/v1/lists/%s/environments/%s/status", params.ListID, params.Network)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("create get activation status request failed: %s", err.Error())
}
var rval GetActivationStatusResponse
resp, err := p.Exec(req, &rval, params)
if err != nil {
return nil, fmt.Errorf("get activation status request failed: %s", err.Error())
}
defer session.CloseResponseBody(resp)
if resp.StatusCode != http.StatusOK {
return nil, p.Error(resp)
}
return &rval, nil
}
func (p *clientlists) GetActivation(ctx context.Context, params GetActivationRequest) (*GetActivationResponse, error) {
logger := p.Log(ctx)
logger.Debug("Get Activation")
if err := params.validate(); err != nil {
return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
}
uri := fmt.Sprintf("/client-list/v1/activations/%d", params.ActivationID)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("create get activation request failed: %s", err.Error())
}
var rval GetActivationResponse
resp, err := p.Exec(req, &rval, params)
if err != nil {
return nil, fmt.Errorf("get activation request failed: %s", err.Error())
}
defer session.CloseResponseBody(resp)
if resp.StatusCode != http.StatusOK {
return nil, p.Error(resp)
}
return &rval, nil
}