github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/appsec/advanced_settings_evasive_path_match.go (about) 1 package appsec 2 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 8 validation "github.com/go-ozzo/ozzo-validation/v4" 9 ) 10 11 type ( 12 // The AdvancedSettingsEvasivePathMatch interface supports retrieving or modifying the Evasive Path Match setting. 13 AdvancedSettingsEvasivePathMatch interface { 14 // GetAdvancedSettingsEvasivePathMatch retrieves the Evasive Path Match setting. 15 // 16 // See: https://techdocs.akamai.com/application-security/reference/get-evasive-path-match-per-config 17 GetAdvancedSettingsEvasivePathMatch(ctx context.Context, params GetAdvancedSettingsEvasivePathMatchRequest) (*GetAdvancedSettingsEvasivePathMatchResponse, error) 18 19 // UpdateAdvancedSettingsEvasivePathMatch modifies the Evasive Path Match setting. 20 // 21 // See: https://techdocs.akamai.com/application-security/reference/put-evasive-path-match-per-config 22 UpdateAdvancedSettingsEvasivePathMatch(ctx context.Context, params UpdateAdvancedSettingsEvasivePathMatchRequest) (*UpdateAdvancedSettingsEvasivePathMatchResponse, error) 23 24 // RemoveAdvancedSettingsEvasivePathMatch removes the Evasive Path Match setting. 25 // 26 // Deprecated: this method will be removed in a future release. Use UpdateAdvancedSettingsEvasivePathMatch instead. 27 RemoveAdvancedSettingsEvasivePathMatch(ctx context.Context, params RemoveAdvancedSettingsEvasivePathMatchRequest) (*RemoveAdvancedSettingsEvasivePathMatchResponse, error) 28 } 29 30 // GetAdvancedSettingsEvasivePathMatchRequest is used to retrieve the EvasivePathMatch setting 31 GetAdvancedSettingsEvasivePathMatchRequest struct { 32 ConfigID int `json:"-"` 33 Version int `json:"-"` 34 PolicyID string `json:"-"` 35 } 36 37 // GetAdvancedSettingsEvasivePathMatchResponse returns the EvasivePathMatch setting 38 GetAdvancedSettingsEvasivePathMatchResponse struct { 39 EnablePathMatch bool `json:"enablePathMatch"` 40 } 41 42 // UpdateAdvancedSettingsEvasivePathMatchRequest is used to update the EvasivePathMatch setting 43 UpdateAdvancedSettingsEvasivePathMatchRequest struct { 44 ConfigID int `json:"-"` 45 Version int `json:"-"` 46 PolicyID string `json:"-"` 47 EnablePathMatch bool `json:"enablePathMatch"` 48 } 49 50 // UpdateAdvancedSettingsEvasivePathMatchResponse returns the result of updating the EvasivePathMatch setting 51 UpdateAdvancedSettingsEvasivePathMatchResponse struct { 52 EnablePathMatch bool `json:"enablePathMatch"` 53 } 54 55 // RemoveAdvancedSettingsEvasivePathMatchRequest is used to clear the EvasivePathMatch setting 56 RemoveAdvancedSettingsEvasivePathMatchRequest struct { 57 ConfigID int `json:"-"` 58 Version int `json:"-"` 59 PolicyID string `json:"-"` 60 EnablePathMatch bool `json:"enablePathMatch"` 61 } 62 63 // RemoveAdvancedSettingsEvasivePathMatchResponse returns the result of clearing the EvasivePathMatch setting 64 RemoveAdvancedSettingsEvasivePathMatchResponse struct { 65 ConfigID int `json:"-"` 66 Version int `json:"-"` 67 PolicyID string `json:"-"` 68 EnablePathMatch bool `json:"enablePathMatch"` 69 } 70 ) 71 72 // Validate validates GetAdvancedSettingssEvasivePathMatchRequest 73 func (v GetAdvancedSettingsEvasivePathMatchRequest) Validate() error { 74 return validation.Errors{ 75 "ConfigID": validation.Validate(v.ConfigID, validation.Required), 76 "Version": validation.Validate(v.Version, validation.Required), 77 }.Filter() 78 } 79 80 // Validate validates UpdateAdvancedSettingsEvasivePathMatchRequest 81 func (v UpdateAdvancedSettingsEvasivePathMatchRequest) Validate() error { 82 return validation.Errors{ 83 "ConfigID": validation.Validate(v.ConfigID, validation.Required), 84 "Version": validation.Validate(v.Version, validation.Required), 85 }.Filter() 86 } 87 88 // Validate validates UpdateAdvancedSettingsEvasivePathMatchRequest 89 func (v RemoveAdvancedSettingsEvasivePathMatchRequest) Validate() error { 90 return validation.Errors{ 91 "ConfigID": validation.Validate(v.ConfigID, validation.Required), 92 "Version": validation.Validate(v.Version, validation.Required), 93 }.Filter() 94 } 95 96 func (p *appsec) GetAdvancedSettingsEvasivePathMatch(ctx context.Context, params GetAdvancedSettingsEvasivePathMatchRequest) (*GetAdvancedSettingsEvasivePathMatchResponse, error) { 97 logger := p.Log(ctx) 98 logger.Debug("GetAdvancedSettingsEvasivePathMatch") 99 100 if err := params.Validate(); err != nil { 101 return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error()) 102 } 103 104 var uri string 105 if params.PolicyID != "" { 106 uri = fmt.Sprintf( 107 "/appsec/v1/configs/%d/versions/%d/security-policies/%s/advanced-settings/evasive-path-match", 108 params.ConfigID, 109 params.Version, 110 params.PolicyID) 111 } else { 112 uri = fmt.Sprintf( 113 "/appsec/v1/configs/%d/versions/%d/advanced-settings/evasive-path-match", 114 params.ConfigID, 115 params.Version) 116 } 117 118 req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) 119 if err != nil { 120 return nil, fmt.Errorf("failed to create GetAdvancedSettingsEvasivePathMatch request: %w", err) 121 } 122 123 var result GetAdvancedSettingsEvasivePathMatchResponse 124 resp, err := p.Exec(req, &result) 125 if err != nil { 126 return nil, fmt.Errorf("get advanced settings evasive path match request failed: %w", err) 127 } 128 129 if resp.StatusCode != http.StatusOK { 130 return nil, p.Error(resp) 131 } 132 133 return &result, nil 134 } 135 136 func (p *appsec) UpdateAdvancedSettingsEvasivePathMatch(ctx context.Context, params UpdateAdvancedSettingsEvasivePathMatchRequest) (*UpdateAdvancedSettingsEvasivePathMatchResponse, error) { 137 logger := p.Log(ctx) 138 logger.Debug("UpdateAdvancedSettingsEvasivePathMatch") 139 140 if err := params.Validate(); err != nil { 141 return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error()) 142 } 143 144 var uri string 145 if params.PolicyID != "" { 146 uri = fmt.Sprintf( 147 "/appsec/v1/configs/%d/versions/%d/security-policies/%s/advanced-settings/evasive-path-match", 148 params.ConfigID, 149 params.Version, 150 params.PolicyID) 151 } else { 152 uri = fmt.Sprintf( 153 "/appsec/v1/configs/%d/versions/%d/advanced-settings/evasive-path-match", 154 params.ConfigID, 155 params.Version) 156 } 157 158 req, err := http.NewRequestWithContext(ctx, http.MethodPut, uri, nil) 159 if err != nil { 160 return nil, fmt.Errorf("failed to create UpdateAdvancedSettingsEvasivePathMatch request: %w", err) 161 } 162 req.Header.Set("Content-Type", "application/json") 163 164 var result UpdateAdvancedSettingsEvasivePathMatchResponse 165 resp, err := p.Exec(req, &result, params) 166 if err != nil { 167 return nil, fmt.Errorf("update advanced settings evasive path match request failed: %w", err) 168 } 169 170 if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { 171 return nil, p.Error(resp) 172 } 173 174 return &result, nil 175 } 176 177 func (p *appsec) RemoveAdvancedSettingsEvasivePathMatch(ctx context.Context, params RemoveAdvancedSettingsEvasivePathMatchRequest) (*RemoveAdvancedSettingsEvasivePathMatchResponse, error) { 178 logger := p.Log(ctx) 179 logger.Debug("RemoveAdvancedSettingsEvasivePathMatch") 180 181 request := UpdateAdvancedSettingsEvasivePathMatchRequest{ 182 ConfigID: params.ConfigID, 183 Version: params.Version, 184 PolicyID: params.PolicyID, 185 EnablePathMatch: false, 186 } 187 _, err := p.UpdateAdvancedSettingsEvasivePathMatch(ctx, request) 188 if err != nil { 189 return nil, fmt.Errorf("remove advanced settings evasive path match request failed: %w", err) 190 } 191 response := RemoveAdvancedSettingsEvasivePathMatchResponse{ 192 ConfigID: params.ConfigID, 193 Version: params.Version, 194 PolicyID: params.PolicyID, 195 EnablePathMatch: false, 196 } 197 return &response, nil 198 }