|
| 1 | +package siteshield |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "net/http" |
| 7 | + |
| 8 | + validation "github.com/go-ozzo/ozzo-validation" |
| 9 | +) |
| 10 | + |
| 11 | +// SiteShieldMap represents a collection of Site Shield |
| 12 | +// |
| 13 | +// See: SiteShieldMap.GetSiteShieldMaps() |
| 14 | +// API Docs: // site_shield v1 |
| 15 | +// |
| 16 | +// https://developer.akamai.com/api/cloud_security/site_shield/v1.html |
| 17 | + |
| 18 | +type ( |
| 19 | + // SiteShieldMap contains operations available on SiteShieldMap resource |
| 20 | + // See: // site_shield v1 |
| 21 | + // |
| 22 | + // https://developer.akamai.com/api/cloud_security/site_shield/v1.html#getamap |
| 23 | + SiteShieldMap interface { |
| 24 | + GetSiteShieldMaps(ctx context.Context) (*GetSiteShieldMapsResponse, error) |
| 25 | + GetSiteShieldMap(ctx context.Context, params SiteShieldMapRequest) (*SiteShieldMapResponse, error) |
| 26 | + AckSiteShieldMap(ctx context.Context, params SiteShieldMapRequest) (*SiteShieldMapResponse, error) |
| 27 | + } |
| 28 | + |
| 29 | + SiteShieldMapRequest struct { |
| 30 | + UniqueID int |
| 31 | + } |
| 32 | + |
| 33 | + GetSiteShieldMapsResponse struct { |
| 34 | + SiteShieldMaps []SiteShieldMapResponse `json:"siteShieldMaps"` |
| 35 | + } |
| 36 | + |
| 37 | + SiteShieldMapResponse struct { |
| 38 | + Acknowledged bool `json:"acknowledged"` |
| 39 | + Contacts []string `json:"contacts"` |
| 40 | + CurrentCidrs []string `json:"currentCidrs"` |
| 41 | + ProposedCidrs []string `json:"proposedCidrs"` |
| 42 | + RuleName string `json:"ruleName"` |
| 43 | + Type string `json:"type"` |
| 44 | + Service string `json:"service"` |
| 45 | + Shared bool `json:"shared"` |
| 46 | + AcknowledgeRequiredBy int64 `json:"acknowledgeRequiredBy"` |
| 47 | + PreviouslyAcknowledgedOn int64 `json:"previouslyAcknowledgedOn"` |
| 48 | + ID int `json:"id,omitempty"` |
| 49 | + LatestTicketID int `json:"latestTicketId,omitempty"` |
| 50 | + MapAlias string `json:"mapAlias,omitempty"` |
| 51 | + McmMapRuleID int `json:"mcmMapRuleId,omitempty"` |
| 52 | + } |
| 53 | +) |
| 54 | + |
| 55 | +// Validate validates SiteShieldMapRequest |
| 56 | +func (v SiteShieldMapRequest) Validate() error { |
| 57 | + return validation.Errors{ |
| 58 | + "UniqueID": validation.Validate(v.UniqueID, validation.Required), |
| 59 | + }.Filter() |
| 60 | +} |
| 61 | + |
| 62 | +// GetSiteShieldMaps will get a list of SiteShieldMap. |
| 63 | +// |
| 64 | +// API Docs: // site_shield v1 |
| 65 | +// |
| 66 | +// https://developer.akamai.com/api/cloud_security/site_shield/v1.html#listmaps |
| 67 | + |
| 68 | +func (s *siteshieldmap) GetSiteShieldMaps(ctx context.Context) (*GetSiteShieldMapsResponse, error) { |
| 69 | + logger := s.Log(ctx) |
| 70 | + logger.Debug("GetSiteShieldMaps") |
| 71 | + |
| 72 | + var rval GetSiteShieldMapsResponse |
| 73 | + |
| 74 | + uri := "/siteshield/v1/maps" |
| 75 | + |
| 76 | + req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) |
| 77 | + if err != nil { |
| 78 | + return nil, fmt.Errorf("failed to create getSiteShieldMaps request: %s", err.Error()) |
| 79 | + } |
| 80 | + |
| 81 | + resp, err := s.Exec(req, &rval) |
| 82 | + if err != nil { |
| 83 | + return nil, fmt.Errorf("getsiteshieldmaps request failed: %s", err.Error()) |
| 84 | + } |
| 85 | + |
| 86 | + if resp.StatusCode != http.StatusOK { |
| 87 | + return nil, s.Error(resp) |
| 88 | + } |
| 89 | + |
| 90 | + return &rval, nil |
| 91 | + |
| 92 | +} |
| 93 | + |
| 94 | +// GetSiteShieldMap will get a SiteShieldMap by unique ID. |
| 95 | +// |
| 96 | +// API Docs: // site_shield v1 |
| 97 | +// |
| 98 | +// https://developer.akamai.com/api/cloud_security/site_shield/v1.html#getamap |
| 99 | + |
| 100 | +func (s *siteshieldmap) GetSiteShieldMap(ctx context.Context, params SiteShieldMapRequest) (*SiteShieldMapResponse, error) { |
| 101 | + if err := params.Validate(); err != nil { |
| 102 | + return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error()) |
| 103 | + } |
| 104 | + |
| 105 | + logger := s.Log(ctx) |
| 106 | + logger.Debug("GetSiteShieldMap") |
| 107 | + |
| 108 | + var rval SiteShieldMapResponse |
| 109 | + |
| 110 | + uri := fmt.Sprintf("/siteshield/v1/maps/%d", params.UniqueID) |
| 111 | + |
| 112 | + req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) |
| 113 | + if err != nil { |
| 114 | + return nil, fmt.Errorf("failed to create getSiteShieldMap request: %s", err.Error()) |
| 115 | + } |
| 116 | + |
| 117 | + resp, err := s.Exec(req, &rval) |
| 118 | + if err != nil { |
| 119 | + return nil, fmt.Errorf("getSiteShieldMap request failed: %s", err.Error()) |
| 120 | + } |
| 121 | + |
| 122 | + if resp.StatusCode != http.StatusOK { |
| 123 | + return nil, s.Error(resp) |
| 124 | + } |
| 125 | + |
| 126 | + return &rval, nil |
| 127 | +} |
| 128 | + |
| 129 | +// AckSiteShieldMap will acknowledge changes to a SiteShieldMap. |
| 130 | +// |
| 131 | +// API Docs: // site_shield v1 |
| 132 | +// |
| 133 | +// https://developer.akamai.com/api/cloud_security/site_shield/v1.html#acknowledgeamap |
| 134 | + |
| 135 | +func (s *siteshieldmap) AckSiteShieldMap(ctx context.Context, params SiteShieldMapRequest) (*SiteShieldMapResponse, error) { |
| 136 | + if err := params.Validate(); err != nil { |
| 137 | + return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error()) |
| 138 | + } |
| 139 | + |
| 140 | + logger := s.Log(ctx) |
| 141 | + logger.Debug("AckSiteShieldMap") |
| 142 | + |
| 143 | + postURL := fmt.Sprintf("/siteshield/v1/maps/%d/acknowledge", params.UniqueID) |
| 144 | + |
| 145 | + req, err := http.NewRequestWithContext(ctx, http.MethodPost, postURL, nil) |
| 146 | + if err != nil { |
| 147 | + return nil, fmt.Errorf("failed to create AckSiteShieldMap: %s", err.Error()) |
| 148 | + } |
| 149 | + |
| 150 | + var rval SiteShieldMapResponse |
| 151 | + resp, err := s.Exec(req, &rval, params) |
| 152 | + if err != nil { |
| 153 | + return nil, fmt.Errorf("AckSiteShieldMap request failed: %s", err.Error()) |
| 154 | + } |
| 155 | + |
| 156 | + if resp.StatusCode != http.StatusOK { |
| 157 | + return nil, s.Error(resp) |
| 158 | + } |
| 159 | + |
| 160 | + return &rval, nil |
| 161 | +} |
0 commit comments