/
post_verification_warnings.go
92 lines (74 loc) · 3.51 KB
/
post_verification_warnings.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
package cps
import (
"context"
"errors"
"fmt"
"net/http"
)
type (
// PostVerification is a CPS API enabling management of post-verification-warnings
PostVerification interface {
// GetChangePostVerificationWarnings gets information about post verification warnings
//
// See: https://techdocs.akamai.com/cps/reference/get-change-allowed-input-param
GetChangePostVerificationWarnings(ctx context.Context, params GetChangeRequest) (*PostVerificationWarnings, error)
// AcknowledgePostVerificationWarnings sends acknowledgement request to CPS informing that the warnings should be ignored
//
// See: https://techdocs.akamai.com/cps/reference/post-change-allowed-input-param
AcknowledgePostVerificationWarnings(context.Context, AcknowledgementRequest) error
}
// PostVerificationWarnings is a response object containing all warnings encountered during enrollment post-verification
PostVerificationWarnings struct {
Warnings string `json:"warnings"`
}
)
var (
// ErrGetChangePostVerificationWarnings is returned when GetChangePostVerificationWarnings fails
ErrGetChangePostVerificationWarnings = errors.New("get post-verification-warnings")
// ErrAcknowledgePostVerificationWarnings is returned when AcknowledgePostVerificationWarnings fails
ErrAcknowledgePostVerificationWarnings = errors.New("acknowledging post-verification-warnings")
)
func (c *cps) GetChangePostVerificationWarnings(ctx context.Context, params GetChangeRequest) (*PostVerificationWarnings, error) {
c.Log(ctx).Debug("GetChangePostVerificationWarnings")
if err := params.Validate(); err != nil {
return nil, fmt.Errorf("%s: %w: %s", ErrGetChangePostVerificationWarnings, ErrStructValidation, err)
}
uri := fmt.Sprintf("/cps/v2/enrollments/%d/changes/%d/input/info/post-verification-warnings",
params.EnrollmentID, params.ChangeID)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("%w: failed to create request: %s", ErrGetChangePostVerificationWarnings, err)
}
req.Header.Set("Accept", "application/vnd.akamai.cps.warnings.v1+json")
var result PostVerificationWarnings
resp, err := c.Exec(req, &result)
if err != nil {
return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangePostVerificationWarnings, err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%s: %w", ErrGetChangePostVerificationWarnings, c.Error(resp))
}
return &result, nil
}
func (c *cps) AcknowledgePostVerificationWarnings(ctx context.Context, params AcknowledgementRequest) error {
c.Log(ctx).Debug("AcknowledgePostVerificationWarnings")
if err := params.Validate(); err != nil {
return fmt.Errorf("%s: %w: %s", ErrAcknowledgePostVerificationWarnings, ErrStructValidation, err)
}
uri := fmt.Sprintf("/cps/v2/enrollments/%d/changes/%d/input/update/post-verification-warnings-ack",
params.EnrollmentID, params.ChangeID)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, nil)
if err != nil {
return fmt.Errorf("%w: failed to create request: %s", ErrAcknowledgePostVerificationWarnings, err)
}
req.Header.Set("Accept", "application/vnd.akamai.cps.change-id.v1+json")
req.Header.Set("Content-Type", "application/vnd.akamai.cps.acknowledgement.v1+json; charset=utf-8")
resp, err := c.Exec(req, nil, params.Acknowledgement)
if err != nil {
return fmt.Errorf("%w: request failed: %s", ErrAcknowledgePostVerificationWarnings, err)
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("%s: %w", ErrAcknowledgePostVerificationWarnings, c.Error(resp))
}
return nil
}