diff --git a/services/albwaf/oas_commit b/services/albwaf/oas_commit index 1538b64bb..0b29150ff 100644 --- a/services/albwaf/oas_commit +++ b/services/albwaf/oas_commit @@ -1 +1 @@ -d5bd75f47f4b364fa6f71663efb4ba41ec703ac8 +eb0ad5628a25f969e274fc7ed90e412ee7a5b69f diff --git a/services/albwaf/v1betaapi/api_default.go b/services/albwaf/v1betaapi/api_default.go index 7f0eecbe4..bea43c5d5 100644 --- a/services/albwaf/v1betaapi/api_default.go +++ b/services/albwaf/v1betaapi/api_default.go @@ -254,6 +254,23 @@ type DefaultAPI interface { // @return GetManagedRuleSetResponse PatchManagedRuleSetExecute(r ApiPatchManagedRuleSetRequest) (*GetManagedRuleSetResponse, error) + /* + UpdateCustomRuleGroup Update a CRG configuration + + Replaces the rules array of an existing CRG. The CRG name is immutable and used as the resource key. Send the complete desired rule set; per-rule partial merge is not supported. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId + @param region + @param name + @return ApiUpdateCustomRuleGroupRequest + */ + UpdateCustomRuleGroup(ctx context.Context, projectId string, region string, name string) ApiUpdateCustomRuleGroupRequest + + // UpdateCustomRuleGroupExecute executes the request + // @return GetCustomRuleGroupResponse + UpdateCustomRuleGroupExecute(r ApiUpdateCustomRuleGroupRequest) (*GetCustomRuleGroupResponse, error) + /* UpdateWAF Update a WAF configuration @@ -2339,6 +2356,159 @@ func (a *DefaultAPIService) PatchManagedRuleSetExecute(r ApiPatchManagedRuleSetR return localVarReturnValue, nil } +type ApiUpdateCustomRuleGroupRequest struct { + ctx context.Context + ApiService DefaultAPI + projectId string + region string + name string + updateCustomRuleGroupPayload *UpdateCustomRuleGroupPayload +} + +func (r ApiUpdateCustomRuleGroupRequest) UpdateCustomRuleGroupPayload(updateCustomRuleGroupPayload UpdateCustomRuleGroupPayload) ApiUpdateCustomRuleGroupRequest { + r.updateCustomRuleGroupPayload = &updateCustomRuleGroupPayload + return r +} + +func (r ApiUpdateCustomRuleGroupRequest) Execute() (*GetCustomRuleGroupResponse, error) { + return r.ApiService.UpdateCustomRuleGroupExecute(r) +} + +/* +UpdateCustomRuleGroup Update a CRG configuration + +Replaces the rules array of an existing CRG. The CRG name is immutable and used as the resource key. Send the complete desired rule set; per-rule partial merge is not supported. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId + @param region + @param name + @return ApiUpdateCustomRuleGroupRequest +*/ +func (a *DefaultAPIService) UpdateCustomRuleGroup(ctx context.Context, projectId string, region string, name string) ApiUpdateCustomRuleGroupRequest { + return ApiUpdateCustomRuleGroupRequest{ + ApiService: a, + ctx: ctx, + projectId: projectId, + region: region, + name: name, + } +} + +// Execute executes the request +// +// @return GetCustomRuleGroupResponse +func (a *DefaultAPIService) UpdateCustomRuleGroupExecute(r ApiUpdateCustomRuleGroupRequest) (*GetCustomRuleGroupResponse, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetCustomRuleGroupResponse + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.UpdateCustomRuleGroup") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{region}/custom-rule-groups/{name}" + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(parameterValueToString(r.projectId, "projectId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"region"+"}", url.PathEscape(parameterValueToString(r.region, "region")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"name"+"}", url.PathEscape(parameterValueToString(r.name, "name")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.updateCustomRuleGroupPayload == nil { + return localVarReturnValue, reportError("updateCustomRuleGroupPayload is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json", "*/*"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateCustomRuleGroupPayload + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, err + } + + contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) + if ok { + *contextHTTPRequest = req + } + + localVarHTTPResponse, err := a.client.callAPI(req) + contextHTTPResponse, ok := r.ctx.Value(config.ContextHTTPResponse).(**http.Response) + if ok { + *contextHTTPResponse = localVarHTTPResponse + } + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &oapierror.GenericOpenAPIError{ + Body: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + StatusCode: localVarHTTPResponse.StatusCode, + } + if localVarHTTPResponse.StatusCode == 401 { + var v Status + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + var v Status + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &oapierror.GenericOpenAPIError{ + StatusCode: localVarHTTPResponse.StatusCode, + Body: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + type ApiUpdateWAFRequest struct { ctx context.Context ApiService DefaultAPI diff --git a/services/albwaf/v1betaapi/api_default_mock.go b/services/albwaf/v1betaapi/api_default_mock.go index c4188cd25..d0d57159a 100644 --- a/services/albwaf/v1betaapi/api_default_mock.go +++ b/services/albwaf/v1betaapi/api_default_mock.go @@ -48,6 +48,8 @@ type DefaultAPIServiceMock struct { ListWAFExecuteMock *func(r ApiListWAFRequest) (*ListWAFResponse, error) // PatchManagedRuleSetExecuteMock can be populated to implement the behavior of the PatchManagedRuleSetExecute function of this mock PatchManagedRuleSetExecuteMock *func(r ApiPatchManagedRuleSetRequest) (*GetManagedRuleSetResponse, error) + // UpdateCustomRuleGroupExecuteMock can be populated to implement the behavior of the UpdateCustomRuleGroupExecute function of this mock + UpdateCustomRuleGroupExecuteMock *func(r ApiUpdateCustomRuleGroupRequest) (*GetCustomRuleGroupResponse, error) // UpdateWAFExecuteMock can be populated to implement the behavior of the UpdateWAFExecute function of this mock UpdateWAFExecuteMock *func(r ApiUpdateWAFRequest) (*GetWAFResponse, error) } @@ -325,6 +327,26 @@ func (a DefaultAPIServiceMock) PatchManagedRuleSetExecute(r ApiPatchManagedRuleS return (*a.PatchManagedRuleSetExecuteMock)(r) } +func (a DefaultAPIServiceMock) UpdateCustomRuleGroup(ctx context.Context, projectId string, region string, name string) ApiUpdateCustomRuleGroupRequest { + return ApiUpdateCustomRuleGroupRequest{ + ApiService: a, + ctx: ctx, + projectId: projectId, + region: region, + name: name, + } +} + +// UpdateCustomRuleGroupExecute is a no-op by default and will return only return nil values. Behavior can be controlled by populating the UpdateCustomRuleGroupExecuteMock field in the DefaultAPIServiceMock struct. +func (a DefaultAPIServiceMock) UpdateCustomRuleGroupExecute(r ApiUpdateCustomRuleGroupRequest) (*GetCustomRuleGroupResponse, error) { + if a.UpdateCustomRuleGroupExecuteMock == nil { + var localVarReturnValue *GetCustomRuleGroupResponse + return localVarReturnValue, nil + } + + return (*a.UpdateCustomRuleGroupExecuteMock)(r) +} + func (a DefaultAPIServiceMock) UpdateWAF(ctx context.Context, projectId string, region string, name string) ApiUpdateWAFRequest { return ApiUpdateWAFRequest{ ApiService: a, diff --git a/services/albwaf/v1betaapi/model_update_custom_rule_group_payload.go b/services/albwaf/v1betaapi/model_update_custom_rule_group_payload.go new file mode 100644 index 000000000..059a33ad0 --- /dev/null +++ b/services/albwaf/v1betaapi/model_update_custom_rule_group_payload.go @@ -0,0 +1,273 @@ +/* +STACKIT Application Load Balancer Web Application Firewall API + +Generate a Web Application Firewall (WAF) to use with Application Load Balancers (ALB). The name of the WAF configuration is used in the listener of the ALB. This will activate the WAF for that ALB. An ALB with a WAF can have Managed Rule Set (MRS) and in addition can have Custom Rule Group (CRG). To create a WAF one first needs to create all the configurations that are referenced in the WAF configuration. Currently this only consists of a rule configuration, which is written in Seclang. Once all configurations are created and referenced in the WAF configuration it can be used with an ALB. Currently updating a WAF configuration will not update an existing ALB until the Load Balancer VMs are restarted. + +API version: 1beta.0.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1betaapi + +import ( + "encoding/json" + "fmt" +) + +// checks if the UpdateCustomRuleGroupPayload type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateCustomRuleGroupPayload{} + +// UpdateCustomRuleGroupPayload Request payload for updating an existing CRG. Replaces the rules array atomically. +type UpdateCustomRuleGroupPayload struct { + // Custom rule group name. Immutable resource key. Provided via URL path. + Name string `json:"name" validate:"regexp=^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$"` + // Project identifier + ProjectId *string `json:"projectId,omitempty" validate:"regexp=^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"` + // Region + Region *string `json:"region,omitempty" validate:"regexp=^[a-z]{2,4}[0-9]{2}$"` + // The collection of custom rule group SecLang parameters forming this execution group. Replaces the existing rules atomically. + Rules []CreateCustomRule `json:"rules"` + AdditionalProperties map[string]interface{} +} + +type _UpdateCustomRuleGroupPayload UpdateCustomRuleGroupPayload + +// NewUpdateCustomRuleGroupPayload instantiates a new UpdateCustomRuleGroupPayload object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateCustomRuleGroupPayload(name string, rules []CreateCustomRule) *UpdateCustomRuleGroupPayload { + this := UpdateCustomRuleGroupPayload{} + this.Name = name + this.Rules = rules + return &this +} + +// NewUpdateCustomRuleGroupPayloadWithDefaults instantiates a new UpdateCustomRuleGroupPayload object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateCustomRuleGroupPayloadWithDefaults() *UpdateCustomRuleGroupPayload { + this := UpdateCustomRuleGroupPayload{} + return &this +} + +// GetName returns the Name field value +func (o *UpdateCustomRuleGroupPayload) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *UpdateCustomRuleGroupPayload) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *UpdateCustomRuleGroupPayload) SetName(v string) { + o.Name = v +} + +// GetProjectId returns the ProjectId field value if set, zero value otherwise. +func (o *UpdateCustomRuleGroupPayload) GetProjectId() string { + if o == nil || IsNil(o.ProjectId) { + var ret string + return ret + } + return *o.ProjectId +} + +// GetProjectIdOk returns a tuple with the ProjectId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateCustomRuleGroupPayload) GetProjectIdOk() (*string, bool) { + if o == nil || IsNil(o.ProjectId) { + return nil, false + } + return o.ProjectId, true +} + +// HasProjectId returns a boolean if a field has been set. +func (o *UpdateCustomRuleGroupPayload) HasProjectId() bool { + if o != nil && !IsNil(o.ProjectId) { + return true + } + + return false +} + +// SetProjectId gets a reference to the given string and assigns it to the ProjectId field. +func (o *UpdateCustomRuleGroupPayload) SetProjectId(v string) { + o.ProjectId = &v +} + +// GetRegion returns the Region field value if set, zero value otherwise. +func (o *UpdateCustomRuleGroupPayload) GetRegion() string { + if o == nil || IsNil(o.Region) { + var ret string + return ret + } + return *o.Region +} + +// GetRegionOk returns a tuple with the Region field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateCustomRuleGroupPayload) GetRegionOk() (*string, bool) { + if o == nil || IsNil(o.Region) { + return nil, false + } + return o.Region, true +} + +// HasRegion returns a boolean if a field has been set. +func (o *UpdateCustomRuleGroupPayload) HasRegion() bool { + if o != nil && !IsNil(o.Region) { + return true + } + + return false +} + +// SetRegion gets a reference to the given string and assigns it to the Region field. +func (o *UpdateCustomRuleGroupPayload) SetRegion(v string) { + o.Region = &v +} + +// GetRules returns the Rules field value +func (o *UpdateCustomRuleGroupPayload) GetRules() []CreateCustomRule { + if o == nil { + var ret []CreateCustomRule + return ret + } + + return o.Rules +} + +// GetRulesOk returns a tuple with the Rules field value +// and a boolean to check if the value has been set. +func (o *UpdateCustomRuleGroupPayload) GetRulesOk() ([]CreateCustomRule, bool) { + if o == nil { + return nil, false + } + return o.Rules, true +} + +// SetRules sets field value +func (o *UpdateCustomRuleGroupPayload) SetRules(v []CreateCustomRule) { + o.Rules = v +} + +func (o UpdateCustomRuleGroupPayload) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateCustomRuleGroupPayload) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["name"] = o.Name + if !IsNil(o.ProjectId) { + toSerialize["projectId"] = o.ProjectId + } + if !IsNil(o.Region) { + toSerialize["region"] = o.Region + } + toSerialize["rules"] = o.Rules + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *UpdateCustomRuleGroupPayload) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "name", + "rules", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varUpdateCustomRuleGroupPayload := _UpdateCustomRuleGroupPayload{} + + err = json.Unmarshal(data, &varUpdateCustomRuleGroupPayload) + + if err != nil { + return err + } + + *o = UpdateCustomRuleGroupPayload(varUpdateCustomRuleGroupPayload) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "projectId") + delete(additionalProperties, "region") + delete(additionalProperties, "rules") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableUpdateCustomRuleGroupPayload struct { + value *UpdateCustomRuleGroupPayload + isSet bool +} + +func (v NullableUpdateCustomRuleGroupPayload) Get() *UpdateCustomRuleGroupPayload { + return v.value +} + +func (v *NullableUpdateCustomRuleGroupPayload) Set(val *UpdateCustomRuleGroupPayload) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateCustomRuleGroupPayload) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateCustomRuleGroupPayload) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateCustomRuleGroupPayload(val *UpdateCustomRuleGroupPayload) *NullableUpdateCustomRuleGroupPayload { + return &NullableUpdateCustomRuleGroupPayload{value: val, isSet: true} +} + +func (v NullableUpdateCustomRuleGroupPayload) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateCustomRuleGroupPayload) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +}