diff --git a/aisecurityforappsv1/ai_security_for_apps_v1.go b/aisecurityforappsv1/ai_security_for_apps_v1.go new file mode 100644 index 00000000..74c37b3f --- /dev/null +++ b/aisecurityforappsv1/ai_security_for_apps_v1.go @@ -0,0 +1,3596 @@ +/** + * (C) Copyright IBM Corp. 2026. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * IBM OpenAPI SDK Code Generator Version: 3.117.0-7f07c563-20260915-094553 + */ + +// Package aisecurityforappsv1 : Operations and models for the AiSecurityForAppsV1 service +package aisecurityforappsv1 + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "reflect" + "strings" + "time" + + "github.com/IBM/go-sdk-core/v5/core" + common "github.com/IBM/networking-go-sdk/common" + "github.com/go-openapi/strfmt" +) + +// AiSecurityForAppsV1 : AI Security for Apps +// +// API Version: 1.0.0 +type AiSecurityForAppsV1 struct { + Service *core.BaseService + + // Full url-encoded CRN of the service instance. + Crn *string + + // Zone identifier to identify the zone. + ZoneIdentifier *string +} + +// DefaultServiceURL is the default URL to make service requests to. +const DefaultServiceURL = "https://api.cis.cloud.ibm.com" + +// DefaultServiceName is the default key used to find external configuration information. +const DefaultServiceName = "ai_security_for_apps" + +// AiSecurityForAppsV1Options : Service options +type AiSecurityForAppsV1Options struct { + ServiceName string + URL string + Authenticator core.Authenticator + + // Full url-encoded CRN of the service instance. + Crn *string `validate:"required"` + + // Zone identifier to identify the zone. + ZoneIdentifier *string `validate:"required"` +} + +// NewAiSecurityForAppsV1UsingExternalConfig : constructs an instance of AiSecurityForAppsV1 with passed in options and external configuration. +func NewAiSecurityForAppsV1UsingExternalConfig(options *AiSecurityForAppsV1Options) (aiSecurityForApps *AiSecurityForAppsV1, err error) { + if options.ServiceName == "" { + options.ServiceName = DefaultServiceName + } + + if options.Authenticator == nil { + options.Authenticator, err = core.GetAuthenticatorFromEnvironment(options.ServiceName) + if err != nil { + err = core.SDKErrorf(err, "", "env-auth-error", common.GetComponentInfo()) + return + } + } + + aiSecurityForApps, err = NewAiSecurityForAppsV1(options) + err = core.RepurposeSDKProblem(err, "new-client-error") + if err != nil { + return + } + + err = aiSecurityForApps.Service.ConfigureService(options.ServiceName) + if err != nil { + err = core.SDKErrorf(err, "", "client-config-error", common.GetComponentInfo()) + return + } + + if options.URL != "" { + err = aiSecurityForApps.Service.SetServiceURL(options.URL) + err = core.RepurposeSDKProblem(err, "url-set-error") + } + return +} + +// NewAiSecurityForAppsV1 : constructs an instance of AiSecurityForAppsV1 with passed in options. +func NewAiSecurityForAppsV1(options *AiSecurityForAppsV1Options) (service *AiSecurityForAppsV1, err error) { + serviceOptions := &core.ServiceOptions{ + URL: DefaultServiceURL, + Authenticator: options.Authenticator, + } + + err = core.ValidateStruct(options, "options") + if err != nil { + err = core.SDKErrorf(err, "", "invalid-global-options", common.GetComponentInfo()) + return + } + + baseService, err := core.NewBaseService(serviceOptions) + if err != nil { + err = core.SDKErrorf(err, "", "new-base-error", common.GetComponentInfo()) + return + } + + if options.URL != "" { + err = baseService.SetServiceURL(options.URL) + if err != nil { + err = core.SDKErrorf(err, "", "set-url-error", common.GetComponentInfo()) + return + } + } + + service = &AiSecurityForAppsV1{ + Service: baseService, + Crn: options.Crn, + ZoneIdentifier: options.ZoneIdentifier, + } + + return +} + +// GetServiceURLForRegion returns the service URL to be used for the specified region +func GetServiceURLForRegion(region string) (string, error) { + return "", core.SDKErrorf(nil, "service does not support regional URLs", "no-regional-support", common.GetComponentInfo()) +} + +// Clone makes a copy of "aiSecurityForApps" suitable for processing requests. +func (aiSecurityForApps *AiSecurityForAppsV1) Clone() *AiSecurityForAppsV1 { + if core.IsNil(aiSecurityForApps) { + return nil + } + clone := *aiSecurityForApps + clone.Service = aiSecurityForApps.Service.Clone() + return &clone +} + +// SetServiceURL sets the service URL +func (aiSecurityForApps *AiSecurityForAppsV1) SetServiceURL(url string) error { + err := aiSecurityForApps.Service.SetServiceURL(url) + if err != nil { + err = core.SDKErrorf(err, "", "url-set-error", common.GetComponentInfo()) + } + return err +} + +// GetServiceURL returns the service URL +func (aiSecurityForApps *AiSecurityForAppsV1) GetServiceURL() string { + return aiSecurityForApps.Service.GetServiceURL() +} + +// SetDefaultHeaders sets HTTP headers to be sent in every request +func (aiSecurityForApps *AiSecurityForAppsV1) SetDefaultHeaders(headers http.Header) { + aiSecurityForApps.Service.SetDefaultHeaders(headers) +} + +// SetEnableGzipCompression sets the service's EnableGzipCompression field +func (aiSecurityForApps *AiSecurityForAppsV1) SetEnableGzipCompression(enableGzip bool) { + aiSecurityForApps.Service.SetEnableGzipCompression(enableGzip) +} + +// GetEnableGzipCompression returns the service's EnableGzipCompression field +func (aiSecurityForApps *AiSecurityForAppsV1) GetEnableGzipCompression() bool { + return aiSecurityForApps.Service.GetEnableGzipCompression() +} + +// EnableRetries enables automatic retries for requests invoked for this service instance. +// If either parameter is specified as 0, then a default value is used instead. +func (aiSecurityForApps *AiSecurityForAppsV1) EnableRetries(maxRetries int, maxRetryInterval time.Duration) { + aiSecurityForApps.Service.EnableRetries(maxRetries, maxRetryInterval) +} + +// DisableRetries disables automatic retries for requests invoked for this service instance. +func (aiSecurityForApps *AiSecurityForAppsV1) DisableRetries() { + aiSecurityForApps.Service.DisableRetries() +} + +// GetAiSecuritySettings : Get AI Security for Apps settings +// Get AI Security for Apps enabled/disabled setting for a given zone. +func (aiSecurityForApps *AiSecurityForAppsV1) GetAiSecuritySettings(getAiSecuritySettingsOptions *GetAiSecuritySettingsOptions) (result *AiSecuritySettingsResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.GetAiSecuritySettingsWithContext(context.Background(), getAiSecuritySettingsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// GetAiSecuritySettingsWithContext is an alternate form of the GetAiSecuritySettings method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) GetAiSecuritySettingsWithContext(ctx context.Context, getAiSecuritySettingsOptions *GetAiSecuritySettingsOptions) (result *AiSecuritySettingsResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(getAiSecuritySettingsOptions, "getAiSecuritySettingsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/ai_security/settings`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "GetAiSecuritySettings") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range getAiSecuritySettingsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "get_ai_security_settings", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAiSecuritySettingsResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// ReplaceZoneAiSecuritySettings : Update AI Security for Apps settings +// Enable or disable AI Security for Apps for a given zone. +func (aiSecurityForApps *AiSecurityForAppsV1) ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptions *ReplaceZoneAiSecuritySettingsOptions) (result *AiSecuritySettingsResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.ReplaceZoneAiSecuritySettingsWithContext(context.Background(), replaceZoneAiSecuritySettingsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// ReplaceZoneAiSecuritySettingsWithContext is an alternate form of the ReplaceZoneAiSecuritySettings method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) ReplaceZoneAiSecuritySettingsWithContext(ctx context.Context, replaceZoneAiSecuritySettingsOptions *ReplaceZoneAiSecuritySettingsOptions) (result *AiSecuritySettingsResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(replaceZoneAiSecuritySettingsOptions, "replaceZoneAiSecuritySettingsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.PUT) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/ai_security/settings`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "ReplaceZoneAiSecuritySettings") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range replaceZoneAiSecuritySettingsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if replaceZoneAiSecuritySettingsOptions.Enabled != nil { + body["enabled"] = replaceZoneAiSecuritySettingsOptions.Enabled + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "replace_zone_ai_security_settings", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAiSecuritySettingsResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// GetApiGatewayDiscovery : Get API Gateway discovery +// Retrieve discovered operations for a zone rendered as OpenAPI schemas. Use this to identify AI-powered endpoints, +// save them to Endpoint Management, and label them to enable AI Security for Apps scanning. +func (aiSecurityForApps *AiSecurityForAppsV1) GetApiGatewayDiscovery(getApiGatewayDiscoveryOptions *GetApiGatewayDiscoveryOptions) (result *ApiGatewayDiscoveryResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.GetApiGatewayDiscoveryWithContext(context.Background(), getApiGatewayDiscoveryOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// GetApiGatewayDiscoveryWithContext is an alternate form of the GetApiGatewayDiscovery method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) GetApiGatewayDiscoveryWithContext(ctx context.Context, getApiGatewayDiscoveryOptions *GetApiGatewayDiscoveryOptions) (result *ApiGatewayDiscoveryResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(getApiGatewayDiscoveryOptions, "getApiGatewayDiscoveryOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/discovery`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "GetApiGatewayDiscovery") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range getApiGatewayDiscoveryOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "get_api_gateway_discovery", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayDiscoveryResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// ListApiGatewayDiscoveryOperations : List API Gateway discovery operations +// Retrieve the most up-to-date list of discovered operations for a zone. +func (aiSecurityForApps *AiSecurityForAppsV1) ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptions *ListApiGatewayDiscoveryOperationsOptions) (result *DiscoveryOperationsListResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.ListApiGatewayDiscoveryOperationsWithContext(context.Background(), listApiGatewayDiscoveryOperationsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// ListApiGatewayDiscoveryOperationsWithContext is an alternate form of the ListApiGatewayDiscoveryOperations method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) ListApiGatewayDiscoveryOperationsWithContext(ctx context.Context, listApiGatewayDiscoveryOperationsOptions *ListApiGatewayDiscoveryOperationsOptions) (result *DiscoveryOperationsListResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(listApiGatewayDiscoveryOperationsOptions, "listApiGatewayDiscoveryOperationsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/discovery/operations`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "ListApiGatewayDiscoveryOperations") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range listApiGatewayDiscoveryOperationsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + if listApiGatewayDiscoveryOperationsOptions.Diff != nil { + builder.AddQuery("diff", fmt.Sprint(*listApiGatewayDiscoveryOperationsOptions.Diff)) + } + if listApiGatewayDiscoveryOperationsOptions.Direction != nil { + builder.AddQuery("direction", fmt.Sprint(*listApiGatewayDiscoveryOperationsOptions.Direction)) + } + if listApiGatewayDiscoveryOperationsOptions.Endpoint != nil { + builder.AddQuery("endpoint", fmt.Sprint(*listApiGatewayDiscoveryOperationsOptions.Endpoint)) + } + if listApiGatewayDiscoveryOperationsOptions.Host != nil { + builder.AddQuery("host", strings.Join(listApiGatewayDiscoveryOperationsOptions.Host, ",")) + } + if listApiGatewayDiscoveryOperationsOptions.Method != nil { + builder.AddQuery("method", strings.Join(listApiGatewayDiscoveryOperationsOptions.Method, ",")) + } + if listApiGatewayDiscoveryOperationsOptions.Order != nil { + builder.AddQuery("order", fmt.Sprint(*listApiGatewayDiscoveryOperationsOptions.Order)) + } + if listApiGatewayDiscoveryOperationsOptions.Origin != nil { + builder.AddQuery("origin", fmt.Sprint(*listApiGatewayDiscoveryOperationsOptions.Origin)) + } + if listApiGatewayDiscoveryOperationsOptions.State != nil { + builder.AddQuery("state", fmt.Sprint(*listApiGatewayDiscoveryOperationsOptions.State)) + } + if listApiGatewayDiscoveryOperationsOptions.Page != nil { + builder.AddQuery("page", fmt.Sprint(*listApiGatewayDiscoveryOperationsOptions.Page)) + } + if listApiGatewayDiscoveryOperationsOptions.PerPage != nil { + builder.AddQuery("per_page", fmt.Sprint(*listApiGatewayDiscoveryOperationsOptions.PerPage)) + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "list_api_gateway_discovery_operations", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalDiscoveryOperationsListResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// UpdateZoneApiGatewayDiscoveryOperation : Bulk update discovered operation states +// Bulk update the state of one or more discovered operations. Use to mark operations as saved (promoting to Endpoint +// Management) or ignored. +func (aiSecurityForApps *AiSecurityForAppsV1) UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptions *UpdateZoneApiGatewayDiscoveryOperationOptions) (result *DiscoveryOperationsPatchResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.UpdateZoneApiGatewayDiscoveryOperationWithContext(context.Background(), updateZoneApiGatewayDiscoveryOperationOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// UpdateZoneApiGatewayDiscoveryOperationWithContext is an alternate form of the UpdateZoneApiGatewayDiscoveryOperation method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) UpdateZoneApiGatewayDiscoveryOperationWithContext(ctx context.Context, updateZoneApiGatewayDiscoveryOperationOptions *UpdateZoneApiGatewayDiscoveryOperationOptions) (result *DiscoveryOperationsPatchResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(updateZoneApiGatewayDiscoveryOperationOptions, "updateZoneApiGatewayDiscoveryOperationOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.PATCH) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/discovery/operations`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "UpdateZoneApiGatewayDiscoveryOperation") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range updateZoneApiGatewayDiscoveryOperationOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + if updateZoneApiGatewayDiscoveryOperationOptions.RequestBody != nil { + _, err = builder.SetBodyContentJSON(updateZoneApiGatewayDiscoveryOperationOptions.RequestBody) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "update_zone_api_gateway_discovery_operation", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalDiscoveryOperationsPatchResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// DeleteZoneApiGatewayOperations : Bulk-delete all API Gateway operations for a zone +// Bulk-delete all API Gateway operations saved to Endpoint Management for a zone. +func (aiSecurityForApps *AiSecurityForAppsV1) DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptions *DeleteZoneApiGatewayOperationsOptions) (result *ApiGatewayNullResultResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.DeleteZoneApiGatewayOperationsWithContext(context.Background(), deleteZoneApiGatewayOperationsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// DeleteZoneApiGatewayOperationsWithContext is an alternate form of the DeleteZoneApiGatewayOperations method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) DeleteZoneApiGatewayOperationsWithContext(ctx context.Context, deleteZoneApiGatewayOperationsOptions *DeleteZoneApiGatewayOperationsOptions) (result *ApiGatewayNullResultResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteZoneApiGatewayOperationsOptions, "deleteZoneApiGatewayOperationsOptions cannot be nil") + if err != nil { + err = core.SDKErrorf(err, "", "unexpected-nil-param", common.GetComponentInfo()) + return + } + err = core.ValidateStruct(deleteZoneApiGatewayOperationsOptions, "deleteZoneApiGatewayOperationsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "DeleteZoneApiGatewayOperations") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range deleteZoneApiGatewayOperationsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + _, err = builder.SetBodyContentJSON(deleteZoneApiGatewayOperationsOptions.ApiGatewayOperationsDeleteInputItem) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "delete_zone_api_gateway_operations", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayNullResultResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// ListZoneApiGatewayOperations : List API Gateway operations +// List all API Gateway operations saved to Endpoint Management for a zone. +func (aiSecurityForApps *AiSecurityForAppsV1) ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptions *ListZoneApiGatewayOperationsOptions) (result *ApiGatewayOperationsListResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.ListZoneApiGatewayOperationsWithContext(context.Background(), listZoneApiGatewayOperationsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// ListZoneApiGatewayOperationsWithContext is an alternate form of the ListZoneApiGatewayOperations method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) ListZoneApiGatewayOperationsWithContext(ctx context.Context, listZoneApiGatewayOperationsOptions *ListZoneApiGatewayOperationsOptions) (result *ApiGatewayOperationsListResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(listZoneApiGatewayOperationsOptions, "listZoneApiGatewayOperationsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "ListZoneApiGatewayOperations") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range listZoneApiGatewayOperationsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + if listZoneApiGatewayOperationsOptions.Host != nil { + builder.AddQuery("host", strings.Join(listZoneApiGatewayOperationsOptions.Host, ",")) + } + if listZoneApiGatewayOperationsOptions.Method != nil { + builder.AddQuery("method", strings.Join(listZoneApiGatewayOperationsOptions.Method, ",")) + } + if listZoneApiGatewayOperationsOptions.Endpoint != nil { + builder.AddQuery("endpoint", fmt.Sprint(*listZoneApiGatewayOperationsOptions.Endpoint)) + } + if listZoneApiGatewayOperationsOptions.Labels != nil { + builder.AddQuery("labels", strings.Join(listZoneApiGatewayOperationsOptions.Labels, ",")) + } + if listZoneApiGatewayOperationsOptions.Direction != nil { + builder.AddQuery("direction", fmt.Sprint(*listZoneApiGatewayOperationsOptions.Direction)) + } + if listZoneApiGatewayOperationsOptions.Order != nil { + builder.AddQuery("order", fmt.Sprint(*listZoneApiGatewayOperationsOptions.Order)) + } + if listZoneApiGatewayOperationsOptions.Page != nil { + builder.AddQuery("page", fmt.Sprint(*listZoneApiGatewayOperationsOptions.Page)) + } + if listZoneApiGatewayOperationsOptions.PerPage != nil { + builder.AddQuery("per_page", fmt.Sprint(*listZoneApiGatewayOperationsOptions.PerPage)) + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "list_zone_api_gateway_operations", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayOperationsListResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// CreateZoneApiGatewayOperation : Create API Gateway operations in bulk +// Create API Gateway operations in bulk for a zone, saving them to Endpoint Management. +func (aiSecurityForApps *AiSecurityForAppsV1) CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptions *CreateZoneApiGatewayOperationOptions) (result *ApiGatewayOperationsResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.CreateZoneApiGatewayOperationWithContext(context.Background(), createZoneApiGatewayOperationOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// CreateZoneApiGatewayOperationWithContext is an alternate form of the CreateZoneApiGatewayOperation method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) CreateZoneApiGatewayOperationWithContext(ctx context.Context, createZoneApiGatewayOperationOptions *CreateZoneApiGatewayOperationOptions) (result *ApiGatewayOperationsResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(createZoneApiGatewayOperationOptions, "createZoneApiGatewayOperationOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "CreateZoneApiGatewayOperation") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range createZoneApiGatewayOperationOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + if createZoneApiGatewayOperationOptions.ApiGatewayOperation != nil { + _, err = builder.SetBodyContentJSON(createZoneApiGatewayOperationOptions.ApiGatewayOperation) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "create_zone_api_gateway_operation", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayOperationsResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// CreateApiGatewayOperationItem : Create a single API Gateway operation +// Create a single API Gateway operation for a zone, saving it to Endpoint Management. +func (aiSecurityForApps *AiSecurityForAppsV1) CreateApiGatewayOperationItem(createApiGatewayOperationItemOptions *CreateApiGatewayOperationItemOptions) (result *ApiGatewayOperationItemResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.CreateApiGatewayOperationItemWithContext(context.Background(), createApiGatewayOperationItemOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// CreateApiGatewayOperationItemWithContext is an alternate form of the CreateApiGatewayOperationItem method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) CreateApiGatewayOperationItemWithContext(ctx context.Context, createApiGatewayOperationItemOptions *CreateApiGatewayOperationItemOptions) (result *ApiGatewayOperationItemResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(createApiGatewayOperationItemOptions, "createApiGatewayOperationItemOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/item`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "CreateApiGatewayOperationItem") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range createApiGatewayOperationItemOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if createApiGatewayOperationItemOptions.Method != nil { + body["method"] = createApiGatewayOperationItemOptions.Method + } + if createApiGatewayOperationItemOptions.Host != nil { + body["host"] = createApiGatewayOperationItemOptions.Host + } + if createApiGatewayOperationItemOptions.Endpoint != nil { + body["endpoint"] = createApiGatewayOperationItemOptions.Endpoint + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "create_api_gateway_operation_item", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayOperationItemResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// ReplaceZoneApiGatewayOperationLabels : Replace labels on API Gateway operations in bulk +// Replace labels on a set of API Gateway operations in bulk. +func (aiSecurityForApps *AiSecurityForAppsV1) ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptions *ReplaceZoneApiGatewayOperationLabelsOptions) (result *ApiGatewayOperationsLabelsResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.ReplaceZoneApiGatewayOperationLabelsWithContext(context.Background(), replaceZoneApiGatewayOperationLabelsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// ReplaceZoneApiGatewayOperationLabelsWithContext is an alternate form of the ReplaceZoneApiGatewayOperationLabels method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) ReplaceZoneApiGatewayOperationLabelsWithContext(ctx context.Context, replaceZoneApiGatewayOperationLabelsOptions *ReplaceZoneApiGatewayOperationLabelsOptions) (result *ApiGatewayOperationsLabelsResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(replaceZoneApiGatewayOperationLabelsOptions, "replaceZoneApiGatewayOperationLabelsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.PUT) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/labels`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "ReplaceZoneApiGatewayOperationLabels") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range replaceZoneApiGatewayOperationLabelsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if replaceZoneApiGatewayOperationLabelsOptions.Selector != nil { + body["selector"] = replaceZoneApiGatewayOperationLabelsOptions.Selector + } + if replaceZoneApiGatewayOperationLabelsOptions.User != nil { + body["user"] = replaceZoneApiGatewayOperationLabelsOptions.User + } + if replaceZoneApiGatewayOperationLabelsOptions.Managed != nil { + body["managed"] = replaceZoneApiGatewayOperationLabelsOptions.Managed + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "replace_zone_api_gateway_operation_labels", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayOperationsLabelsResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// DeleteZoneApiGatewayOperationLabels : Remove labels from API Gateway operations in bulk +// Remove labels from a set of API Gateway operations in bulk. +func (aiSecurityForApps *AiSecurityForAppsV1) DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptions *DeleteZoneApiGatewayOperationLabelsOptions) (result *ApiGatewayNullResultResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.DeleteZoneApiGatewayOperationLabelsWithContext(context.Background(), deleteZoneApiGatewayOperationLabelsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// DeleteZoneApiGatewayOperationLabelsWithContext is an alternate form of the DeleteZoneApiGatewayOperationLabels method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) DeleteZoneApiGatewayOperationLabelsWithContext(ctx context.Context, deleteZoneApiGatewayOperationLabelsOptions *DeleteZoneApiGatewayOperationLabelsOptions) (result *ApiGatewayNullResultResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteZoneApiGatewayOperationLabelsOptions, "deleteZoneApiGatewayOperationLabelsOptions cannot be nil") + if err != nil { + err = core.SDKErrorf(err, "", "unexpected-nil-param", common.GetComponentInfo()) + return + } + err = core.ValidateStruct(deleteZoneApiGatewayOperationLabelsOptions, "deleteZoneApiGatewayOperationLabelsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/labels`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "DeleteZoneApiGatewayOperationLabels") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range deleteZoneApiGatewayOperationLabelsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if deleteZoneApiGatewayOperationLabelsOptions.Selector != nil { + body["selector"] = deleteZoneApiGatewayOperationLabelsOptions.Selector + } + if deleteZoneApiGatewayOperationLabelsOptions.User != nil { + body["user"] = deleteZoneApiGatewayOperationLabelsOptions.User + } + if deleteZoneApiGatewayOperationLabelsOptions.Managed != nil { + body["managed"] = deleteZoneApiGatewayOperationLabelsOptions.Managed + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "delete_zone_api_gateway_operation_labels", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayNullResultResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// UpdateApiGatewayOperationLabels : Add or remove labels from API Gateway operations +// Add or remove labels from one or more API Gateway operations. Apply the built-in LLM label to endpoints that receive +// LLM traffic to enable IBM AI Security for Apps to scan those endpoints for prompt injection, PII, and unsafe topics. +func (aiSecurityForApps *AiSecurityForAppsV1) UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptions *UpdateApiGatewayOperationLabelsOptions) (result *ApiGatewayOperationsLabelsResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.UpdateApiGatewayOperationLabelsWithContext(context.Background(), updateApiGatewayOperationLabelsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// UpdateApiGatewayOperationLabelsWithContext is an alternate form of the UpdateApiGatewayOperationLabels method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) UpdateApiGatewayOperationLabelsWithContext(ctx context.Context, updateApiGatewayOperationLabelsOptions *UpdateApiGatewayOperationLabelsOptions) (result *ApiGatewayOperationsLabelsResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(updateApiGatewayOperationLabelsOptions, "updateApiGatewayOperationLabelsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/labels`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "UpdateApiGatewayOperationLabels") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range updateApiGatewayOperationLabelsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if updateApiGatewayOperationLabelsOptions.Selector != nil { + body["selector"] = updateApiGatewayOperationLabelsOptions.Selector + } + if updateApiGatewayOperationLabelsOptions.User != nil { + body["user"] = updateApiGatewayOperationLabelsOptions.User + } + if updateApiGatewayOperationLabelsOptions.Managed != nil { + body["managed"] = updateApiGatewayOperationLabelsOptions.Managed + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "update_api_gateway_operation_labels", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayOperationsLabelsResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// CreateApiGatewayOperationLabels : Attach labels to a single operation +// Attach labels to a single API Gateway operation. +func (aiSecurityForApps *AiSecurityForAppsV1) CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptions *CreateApiGatewayOperationLabelsOptions) (result *ApiGatewayOperationLabelResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.CreateApiGatewayOperationLabelsWithContext(context.Background(), createApiGatewayOperationLabelsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// CreateApiGatewayOperationLabelsWithContext is an alternate form of the CreateApiGatewayOperationLabels method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) CreateApiGatewayOperationLabelsWithContext(ctx context.Context, createApiGatewayOperationLabelsOptions *CreateApiGatewayOperationLabelsOptions) (result *ApiGatewayOperationLabelResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createApiGatewayOperationLabelsOptions, "createApiGatewayOperationLabelsOptions cannot be nil") + if err != nil { + err = core.SDKErrorf(err, "", "unexpected-nil-param", common.GetComponentInfo()) + return + } + err = core.ValidateStruct(createApiGatewayOperationLabelsOptions, "createApiGatewayOperationLabelsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + "operation_id": *createApiGatewayOperationLabelsOptions.OperationID, + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/{operation_id}/labels`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "CreateApiGatewayOperationLabels") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range createApiGatewayOperationLabelsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if createApiGatewayOperationLabelsOptions.User != nil { + body["user"] = createApiGatewayOperationLabelsOptions.User + } + if createApiGatewayOperationLabelsOptions.Managed != nil { + body["managed"] = createApiGatewayOperationLabelsOptions.Managed + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "create_api_gateway_operation_labels", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayOperationLabelResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// SetZoneApiGatewayOperationLabels : Replace labels on a single operation +// Replace labels on a single API Gateway operation. +func (aiSecurityForApps *AiSecurityForAppsV1) SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptions *SetZoneApiGatewayOperationLabelsOptions) (result *ApiGatewayOperationLabelResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.SetZoneApiGatewayOperationLabelsWithContext(context.Background(), setZoneApiGatewayOperationLabelsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// SetZoneApiGatewayOperationLabelsWithContext is an alternate form of the SetZoneApiGatewayOperationLabels method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) SetZoneApiGatewayOperationLabelsWithContext(ctx context.Context, setZoneApiGatewayOperationLabelsOptions *SetZoneApiGatewayOperationLabelsOptions) (result *ApiGatewayOperationLabelResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(setZoneApiGatewayOperationLabelsOptions, "setZoneApiGatewayOperationLabelsOptions cannot be nil") + if err != nil { + err = core.SDKErrorf(err, "", "unexpected-nil-param", common.GetComponentInfo()) + return + } + err = core.ValidateStruct(setZoneApiGatewayOperationLabelsOptions, "setZoneApiGatewayOperationLabelsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + "operation_id": *setZoneApiGatewayOperationLabelsOptions.OperationID, + } + + builder := core.NewRequestBuilder(core.PUT) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/{operation_id}/labels`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "SetZoneApiGatewayOperationLabels") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range setZoneApiGatewayOperationLabelsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if setZoneApiGatewayOperationLabelsOptions.User != nil { + body["user"] = setZoneApiGatewayOperationLabelsOptions.User + } + if setZoneApiGatewayOperationLabelsOptions.Managed != nil { + body["managed"] = setZoneApiGatewayOperationLabelsOptions.Managed + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "set_zone_api_gateway_operation_labels", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayOperationLabelResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// UnsetZoneApiGatewayOperationLabels : Remove labels from a single operation +// Remove labels from a single API Gateway operation. +func (aiSecurityForApps *AiSecurityForAppsV1) UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptions *UnsetZoneApiGatewayOperationLabelsOptions) (result *ApiGatewayNullResultResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.UnsetZoneApiGatewayOperationLabelsWithContext(context.Background(), unsetZoneApiGatewayOperationLabelsOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// UnsetZoneApiGatewayOperationLabelsWithContext is an alternate form of the UnsetZoneApiGatewayOperationLabels method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) UnsetZoneApiGatewayOperationLabelsWithContext(ctx context.Context, unsetZoneApiGatewayOperationLabelsOptions *UnsetZoneApiGatewayOperationLabelsOptions) (result *ApiGatewayNullResultResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(unsetZoneApiGatewayOperationLabelsOptions, "unsetZoneApiGatewayOperationLabelsOptions cannot be nil") + if err != nil { + err = core.SDKErrorf(err, "", "unexpected-nil-param", common.GetComponentInfo()) + return + } + err = core.ValidateStruct(unsetZoneApiGatewayOperationLabelsOptions, "unsetZoneApiGatewayOperationLabelsOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + "operation_id": *unsetZoneApiGatewayOperationLabelsOptions.OperationID, + } + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/{operation_id}/labels`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "UnsetZoneApiGatewayOperationLabels") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range unsetZoneApiGatewayOperationLabelsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if unsetZoneApiGatewayOperationLabelsOptions.User != nil { + body["user"] = unsetZoneApiGatewayOperationLabelsOptions.User + } + if unsetZoneApiGatewayOperationLabelsOptions.Managed != nil { + body["managed"] = unsetZoneApiGatewayOperationLabelsOptions.Managed + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "unset_zone_api_gateway_operation_labels", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayNullResultResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// GetZoneApiGatewayOperation : Retrieve information about an operation +// Retrieve information about a specific operation on a zone. +func (aiSecurityForApps *AiSecurityForAppsV1) GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptions *GetZoneApiGatewayOperationOptions) (result *ApiGatewayOperationItemResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.GetZoneApiGatewayOperationWithContext(context.Background(), getZoneApiGatewayOperationOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// GetZoneApiGatewayOperationWithContext is an alternate form of the GetZoneApiGatewayOperation method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) GetZoneApiGatewayOperationWithContext(ctx context.Context, getZoneApiGatewayOperationOptions *GetZoneApiGatewayOperationOptions) (result *ApiGatewayOperationItemResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getZoneApiGatewayOperationOptions, "getZoneApiGatewayOperationOptions cannot be nil") + if err != nil { + err = core.SDKErrorf(err, "", "unexpected-nil-param", common.GetComponentInfo()) + return + } + err = core.ValidateStruct(getZoneApiGatewayOperationOptions, "getZoneApiGatewayOperationOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + "operation_id": *getZoneApiGatewayOperationOptions.OperationID, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/{operation_id}`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "GetZoneApiGatewayOperation") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range getZoneApiGatewayOperationOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "get_zone_api_gateway_operation", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewayOperationItemResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + +// DeleteZoneApiGatewayOperation : Delete an operation +// Delete an operation from a zone. +func (aiSecurityForApps *AiSecurityForAppsV1) DeleteZoneApiGatewayOperation(deleteZoneApiGatewayOperationOptions *DeleteZoneApiGatewayOperationOptions) (response *core.DetailedResponse, err error) { + response, err = aiSecurityForApps.DeleteZoneApiGatewayOperationWithContext(context.Background(), deleteZoneApiGatewayOperationOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// DeleteZoneApiGatewayOperationWithContext is an alternate form of the DeleteZoneApiGatewayOperation method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) DeleteZoneApiGatewayOperationWithContext(ctx context.Context, deleteZoneApiGatewayOperationOptions *DeleteZoneApiGatewayOperationOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteZoneApiGatewayOperationOptions, "deleteZoneApiGatewayOperationOptions cannot be nil") + if err != nil { + err = core.SDKErrorf(err, "", "unexpected-nil-param", common.GetComponentInfo()) + return + } + err = core.ValidateStruct(deleteZoneApiGatewayOperationOptions, "deleteZoneApiGatewayOperationOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + "operation_id": *deleteZoneApiGatewayOperationOptions.OperationID, + } + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/operations/{operation_id}`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "DeleteZoneApiGatewayOperation") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range deleteZoneApiGatewayOperationOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + response, err = aiSecurityForApps.Service.Request(request, nil) + if err != nil { + core.EnrichHTTPProblem(err, "delete_zone_api_gateway_operation", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + + return +} + +// GetApiGatewaySchemas : Get API Gateway schemas +// Retrieve API Gateway schemas for a specified zone rendered as OpenAPI schemas. +func (aiSecurityForApps *AiSecurityForAppsV1) GetApiGatewaySchemas(getApiGatewaySchemasOptions *GetApiGatewaySchemasOptions) (result *ApiGatewaySchemasResp, response *core.DetailedResponse, err error) { + result, response, err = aiSecurityForApps.GetApiGatewaySchemasWithContext(context.Background(), getApiGatewaySchemasOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// GetApiGatewaySchemasWithContext is an alternate form of the GetApiGatewaySchemas method which supports a Context parameter +func (aiSecurityForApps *AiSecurityForAppsV1) GetApiGatewaySchemasWithContext(ctx context.Context, getApiGatewaySchemasOptions *GetApiGatewaySchemasOptions) (result *ApiGatewaySchemasResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(getApiGatewaySchemasOptions, "getApiGatewaySchemasOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "crn": *aiSecurityForApps.Crn, + "zone_identifier": *aiSecurityForApps.ZoneIdentifier, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = aiSecurityForApps.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(aiSecurityForApps.Service.Options.URL, `/v1/{crn}/zones/{zone_identifier}/api_gateway/schemas`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + sdkHeaders := common.GetSdkHeaders("ai_security_for_apps", "V1", "GetApiGatewaySchemas") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + for headerName, headerValue := range getApiGatewaySchemasOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = aiSecurityForApps.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "get_api_gateway_schemas", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalApiGatewaySchemasResp) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} +func getServiceComponentInfo() *core.ProblemComponent { + return core.NewProblemComponent(DefaultServiceName, "1.0.0") +} + +// AiSecuritySettingsRespResult : Container for response information. +type AiSecuritySettingsRespResult struct { + // Whether AI Security for Apps is enabled on the zone. + Enabled *bool `json:"enabled,omitempty"` +} + +// UnmarshalAiSecuritySettingsRespResult unmarshals an instance of AiSecuritySettingsRespResult from the specified map of raw messages. +func UnmarshalAiSecuritySettingsRespResult(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AiSecuritySettingsRespResult) + err = core.UnmarshalPrimitive(m, "enabled", &obj.Enabled) + if err != nil { + err = core.SDKErrorf(err, "", "enabled-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationItemRespResult : ApiGatewayOperationItemRespResult struct +type ApiGatewayOperationItemRespResult struct { + // UUID of the created operation. + OperationID *string `json:"operation_id,omitempty"` + + Method *string `json:"method,omitempty"` + + Host *string `json:"host,omitempty"` + + Endpoint *string `json:"endpoint,omitempty"` +} + +// UnmarshalApiGatewayOperationItemRespResult unmarshals an instance of ApiGatewayOperationItemRespResult from the specified map of raw messages. +func UnmarshalApiGatewayOperationItemRespResult(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationItemRespResult) + err = core.UnmarshalPrimitive(m, "operation_id", &obj.OperationID) + if err != nil { + err = core.SDKErrorf(err, "", "operation_id-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "method", &obj.Method) + if err != nil { + err = core.SDKErrorf(err, "", "method-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "host", &obj.Host) + if err != nil { + err = core.SDKErrorf(err, "", "host-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "endpoint", &obj.Endpoint) + if err != nil { + err = core.SDKErrorf(err, "", "endpoint-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationLabelRespResult : The updated operation with its label set. +type ApiGatewayOperationLabelRespResult struct { + // UUID of the operation. + OperationID *string `json:"operation_id,omitempty"` + + // Labels applied to the operation. + Labels []ApiGatewayOperationLabelRespResultLabelsItem `json:"labels,omitempty"` +} + +// UnmarshalApiGatewayOperationLabelRespResult unmarshals an instance of ApiGatewayOperationLabelRespResult from the specified map of raw messages. +func UnmarshalApiGatewayOperationLabelRespResult(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationLabelRespResult) + err = core.UnmarshalPrimitive(m, "operation_id", &obj.OperationID) + if err != nil { + err = core.SDKErrorf(err, "", "operation_id-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "labels", &obj.Labels, UnmarshalApiGatewayOperationLabelRespResultLabelsItem) + if err != nil { + err = core.SDKErrorf(err, "", "labels-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationLabelRespResultLabelsItem : ApiGatewayOperationLabelRespResultLabelsItem struct +type ApiGatewayOperationLabelRespResultLabelsItem struct { + // Label name. + Name *string `json:"name,omitempty"` + + // Label source (e.g. managed or user). + Source *string `json:"source,omitempty"` +} + +// UnmarshalApiGatewayOperationLabelRespResultLabelsItem unmarshals an instance of ApiGatewayOperationLabelRespResultLabelsItem from the specified map of raw messages. +func UnmarshalApiGatewayOperationLabelRespResultLabelsItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationLabelRespResultLabelsItem) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + err = core.SDKErrorf(err, "", "name-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "source", &obj.Source) + if err != nil { + err = core.SDKErrorf(err, "", "source-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsDeleteInputItem : ApiGatewayOperationsDeleteInputItem struct +type ApiGatewayOperationsDeleteInputItem struct { + // UUID of the operation to delete. + OperationID *string `json:"operation_id" validate:"required"` +} + +// NewApiGatewayOperationsDeleteInputItem : Instantiate ApiGatewayOperationsDeleteInputItem (Generic Model Constructor) +func (*AiSecurityForAppsV1) NewApiGatewayOperationsDeleteInputItem(operationID string) (_model *ApiGatewayOperationsDeleteInputItem, err error) { + _model = &ApiGatewayOperationsDeleteInputItem{ + OperationID: core.StringPtr(operationID), + } + err = core.ValidateStruct(_model, "required parameters") + if err != nil { + err = core.SDKErrorf(err, "", "model-missing-required", common.GetComponentInfo()) + } + return +} + +// UnmarshalApiGatewayOperationsDeleteInputItem unmarshals an instance of ApiGatewayOperationsDeleteInputItem from the specified map of raw messages. +func UnmarshalApiGatewayOperationsDeleteInputItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsDeleteInputItem) + err = core.UnmarshalPrimitive(m, "operation_id", &obj.OperationID) + if err != nil { + err = core.SDKErrorf(err, "", "operation_id-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsBulkDeleteInputManaged : Managed labels to remove. +type ApiGatewayOperationsLabelsBulkDeleteInputManaged struct { + // List of managed label names to remove. + Labels []string `json:"labels,omitempty"` +} + +// UnmarshalApiGatewayOperationsLabelsBulkDeleteInputManaged unmarshals an instance of ApiGatewayOperationsLabelsBulkDeleteInputManaged from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsBulkDeleteInputManaged(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsBulkDeleteInputManaged) + err = core.UnmarshalPrimitive(m, "labels", &obj.Labels) + if err != nil { + err = core.SDKErrorf(err, "", "labels-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsBulkDeleteInputSelector : Selector specifying which operations to affect. +type ApiGatewayOperationsLabelsBulkDeleteInputSelector struct { + // Operations to include. + Include *ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude `json:"include" validate:"required"` +} + +// NewApiGatewayOperationsLabelsBulkDeleteInputSelector : Instantiate ApiGatewayOperationsLabelsBulkDeleteInputSelector (Generic Model Constructor) +func (*AiSecurityForAppsV1) NewApiGatewayOperationsLabelsBulkDeleteInputSelector(include *ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) (_model *ApiGatewayOperationsLabelsBulkDeleteInputSelector, err error) { + _model = &ApiGatewayOperationsLabelsBulkDeleteInputSelector{ + Include: include, + } + err = core.ValidateStruct(_model, "required parameters") + if err != nil { + err = core.SDKErrorf(err, "", "model-missing-required", common.GetComponentInfo()) + } + return +} + +// UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelector unmarshals an instance of ApiGatewayOperationsLabelsBulkDeleteInputSelector from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelector(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsBulkDeleteInputSelector) + err = core.UnmarshalModel(m, "include", &obj.Include, UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + if err != nil { + err = core.SDKErrorf(err, "", "include-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude : Operations to include. +type ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude struct { + // Array of operation UUIDs to remove labels from. + OperationIds []string `json:"operation_ids,omitempty"` +} + +// UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude unmarshals an instance of ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + err = core.UnmarshalPrimitive(m, "operation_ids", &obj.OperationIds) + if err != nil { + err = core.SDKErrorf(err, "", "operation_ids-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsBulkDeleteInputUser : User-defined labels to remove. +type ApiGatewayOperationsLabelsBulkDeleteInputUser struct { + // List of user-defined label names to remove. + Labels []string `json:"labels,omitempty"` +} + +// UnmarshalApiGatewayOperationsLabelsBulkDeleteInputUser unmarshals an instance of ApiGatewayOperationsLabelsBulkDeleteInputUser from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsBulkDeleteInputUser(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsBulkDeleteInputUser) + err = core.UnmarshalPrimitive(m, "labels", &obj.Labels) + if err != nil { + err = core.SDKErrorf(err, "", "labels-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsBulkInputManaged : Managed labels to apply (e.g. cf-llm). +type ApiGatewayOperationsLabelsBulkInputManaged struct { + // List of managed label names to apply. + Labels []string `json:"labels" validate:"required"` +} + +// NewApiGatewayOperationsLabelsBulkInputManaged : Instantiate ApiGatewayOperationsLabelsBulkInputManaged (Generic Model Constructor) +func (*AiSecurityForAppsV1) NewApiGatewayOperationsLabelsBulkInputManaged(labels []string) (_model *ApiGatewayOperationsLabelsBulkInputManaged, err error) { + _model = &ApiGatewayOperationsLabelsBulkInputManaged{ + Labels: labels, + } + err = core.ValidateStruct(_model, "required parameters") + if err != nil { + err = core.SDKErrorf(err, "", "model-missing-required", common.GetComponentInfo()) + } + return +} + +// UnmarshalApiGatewayOperationsLabelsBulkInputManaged unmarshals an instance of ApiGatewayOperationsLabelsBulkInputManaged from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsBulkInputManaged(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsBulkInputManaged) + err = core.UnmarshalPrimitive(m, "labels", &obj.Labels) + if err != nil { + err = core.SDKErrorf(err, "", "labels-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsBulkInputSelector : Selector specifying which operations to label. +type ApiGatewayOperationsLabelsBulkInputSelector struct { + // Operations to include in the label operation. + Include *ApiGatewayOperationsLabelsBulkInputSelectorInclude `json:"include" validate:"required"` +} + +// NewApiGatewayOperationsLabelsBulkInputSelector : Instantiate ApiGatewayOperationsLabelsBulkInputSelector (Generic Model Constructor) +func (*AiSecurityForAppsV1) NewApiGatewayOperationsLabelsBulkInputSelector(include *ApiGatewayOperationsLabelsBulkInputSelectorInclude) (_model *ApiGatewayOperationsLabelsBulkInputSelector, err error) { + _model = &ApiGatewayOperationsLabelsBulkInputSelector{ + Include: include, + } + err = core.ValidateStruct(_model, "required parameters") + if err != nil { + err = core.SDKErrorf(err, "", "model-missing-required", common.GetComponentInfo()) + } + return +} + +// UnmarshalApiGatewayOperationsLabelsBulkInputSelector unmarshals an instance of ApiGatewayOperationsLabelsBulkInputSelector from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsBulkInputSelector(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsBulkInputSelector) + err = core.UnmarshalModel(m, "include", &obj.Include, UnmarshalApiGatewayOperationsLabelsBulkInputSelectorInclude) + if err != nil { + err = core.SDKErrorf(err, "", "include-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsBulkInputSelectorInclude : Operations to include in the label operation. +type ApiGatewayOperationsLabelsBulkInputSelectorInclude struct { + // Array of operation UUIDs to label. + OperationIds []string `json:"operation_ids,omitempty"` +} + +// UnmarshalApiGatewayOperationsLabelsBulkInputSelectorInclude unmarshals an instance of ApiGatewayOperationsLabelsBulkInputSelectorInclude from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsBulkInputSelectorInclude(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsBulkInputSelectorInclude) + err = core.UnmarshalPrimitive(m, "operation_ids", &obj.OperationIds) + if err != nil { + err = core.SDKErrorf(err, "", "operation_ids-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsBulkInputUser : User-defined labels to apply. +type ApiGatewayOperationsLabelsBulkInputUser struct { + // List of user-defined label names to apply. Send an empty array if no user labels are needed. + Labels []string `json:"labels" validate:"required"` +} + +// NewApiGatewayOperationsLabelsBulkInputUser : Instantiate ApiGatewayOperationsLabelsBulkInputUser (Generic Model Constructor) +func (*AiSecurityForAppsV1) NewApiGatewayOperationsLabelsBulkInputUser(labels []string) (_model *ApiGatewayOperationsLabelsBulkInputUser, err error) { + _model = &ApiGatewayOperationsLabelsBulkInputUser{ + Labels: labels, + } + err = core.ValidateStruct(_model, "required parameters") + if err != nil { + err = core.SDKErrorf(err, "", "model-missing-required", common.GetComponentInfo()) + } + return +} + +// UnmarshalApiGatewayOperationsLabelsBulkInputUser unmarshals an instance of ApiGatewayOperationsLabelsBulkInputUser from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsBulkInputUser(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsBulkInputUser) + err = core.UnmarshalPrimitive(m, "labels", &obj.Labels) + if err != nil { + err = core.SDKErrorf(err, "", "labels-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsRespResultItem : ApiGatewayOperationsLabelsRespResultItem struct +type ApiGatewayOperationsLabelsRespResultItem struct { + OperationID *string `json:"operation_id,omitempty"` + + Labels []ApiGatewayOperationsLabelsRespResultItemLabelsItem `json:"labels,omitempty"` +} + +// UnmarshalApiGatewayOperationsLabelsRespResultItem unmarshals an instance of ApiGatewayOperationsLabelsRespResultItem from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsRespResultItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsRespResultItem) + err = core.UnmarshalPrimitive(m, "operation_id", &obj.OperationID) + if err != nil { + err = core.SDKErrorf(err, "", "operation_id-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "labels", &obj.Labels, UnmarshalApiGatewayOperationsLabelsRespResultItemLabelsItem) + if err != nil { + err = core.SDKErrorf(err, "", "labels-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsRespResultItemLabelsItem : ApiGatewayOperationsLabelsRespResultItemLabelsItem struct +type ApiGatewayOperationsLabelsRespResultItemLabelsItem struct { + // Label name. + Name *string `json:"name,omitempty"` + + // Label source (e.g. managed or user). + Source *string `json:"source,omitempty"` +} + +// UnmarshalApiGatewayOperationsLabelsRespResultItemLabelsItem unmarshals an instance of ApiGatewayOperationsLabelsRespResultItemLabelsItem from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsRespResultItemLabelsItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsRespResultItemLabelsItem) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + err = core.SDKErrorf(err, "", "name-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "source", &obj.Source) + if err != nil { + err = core.SDKErrorf(err, "", "source-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsListRespResultItem : ApiGatewayOperationsListRespResultItem struct +type ApiGatewayOperationsListRespResultItem struct { + // UUID of the operation. + OperationID *string `json:"operation_id,omitempty"` + + Method *string `json:"method,omitempty"` + + Host *string `json:"host,omitempty"` + + Endpoint *string `json:"endpoint,omitempty"` + + LastUpdated *strfmt.DateTime `json:"last_updated,omitempty"` +} + +// UnmarshalApiGatewayOperationsListRespResultItem unmarshals an instance of ApiGatewayOperationsListRespResultItem from the specified map of raw messages. +func UnmarshalApiGatewayOperationsListRespResultItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsListRespResultItem) + err = core.UnmarshalPrimitive(m, "operation_id", &obj.OperationID) + if err != nil { + err = core.SDKErrorf(err, "", "operation_id-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "method", &obj.Method) + if err != nil { + err = core.SDKErrorf(err, "", "method-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "host", &obj.Host) + if err != nil { + err = core.SDKErrorf(err, "", "host-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "endpoint", &obj.Endpoint) + if err != nil { + err = core.SDKErrorf(err, "", "endpoint-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "last_updated", &obj.LastUpdated) + if err != nil { + err = core.SDKErrorf(err, "", "last_updated-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsRespResultItem : ApiGatewayOperationsRespResultItem struct +type ApiGatewayOperationsRespResultItem struct { + // UUID of the created operation. + OperationID *string `json:"operation_id,omitempty"` + + Method *string `json:"method,omitempty"` + + Host *string `json:"host,omitempty"` + + Endpoint *string `json:"endpoint,omitempty"` +} + +// UnmarshalApiGatewayOperationsRespResultItem unmarshals an instance of ApiGatewayOperationsRespResultItem from the specified map of raw messages. +func UnmarshalApiGatewayOperationsRespResultItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsRespResultItem) + err = core.UnmarshalPrimitive(m, "operation_id", &obj.OperationID) + if err != nil { + err = core.SDKErrorf(err, "", "operation_id-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "method", &obj.Method) + if err != nil { + err = core.SDKErrorf(err, "", "method-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "host", &obj.Host) + if err != nil { + err = core.SDKErrorf(err, "", "host-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "endpoint", &obj.Endpoint) + if err != nil { + err = core.SDKErrorf(err, "", "endpoint-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreateApiGatewayOperationItemOptions : The CreateApiGatewayOperationItem options. +type CreateApiGatewayOperationItemOptions struct { + // The HTTP method for the operation. + Method *string `json:"method,omitempty"` + + // RFC3986-compliant host. + Host *string `json:"host,omitempty"` + + // The endpoint path. Must start with /. + Endpoint *string `json:"endpoint,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// Constants associated with the CreateApiGatewayOperationItemOptions.Method property. +// The HTTP method for the operation. +const ( + CreateApiGatewayOperationItemOptions_Method_Delete = "DELETE" + CreateApiGatewayOperationItemOptions_Method_Get = "GET" + CreateApiGatewayOperationItemOptions_Method_Head = "HEAD" + CreateApiGatewayOperationItemOptions_Method_Options = "OPTIONS" + CreateApiGatewayOperationItemOptions_Method_Patch = "PATCH" + CreateApiGatewayOperationItemOptions_Method_Post = "POST" + CreateApiGatewayOperationItemOptions_Method_Put = "PUT" +) + +// NewCreateApiGatewayOperationItemOptions : Instantiate CreateApiGatewayOperationItemOptions +func (*AiSecurityForAppsV1) NewCreateApiGatewayOperationItemOptions() *CreateApiGatewayOperationItemOptions { + return &CreateApiGatewayOperationItemOptions{} +} + +// SetMethod : Allow user to set Method +func (_options *CreateApiGatewayOperationItemOptions) SetMethod(method string) *CreateApiGatewayOperationItemOptions { + _options.Method = core.StringPtr(method) + return _options +} + +// SetHost : Allow user to set Host +func (_options *CreateApiGatewayOperationItemOptions) SetHost(host string) *CreateApiGatewayOperationItemOptions { + _options.Host = core.StringPtr(host) + return _options +} + +// SetEndpoint : Allow user to set Endpoint +func (_options *CreateApiGatewayOperationItemOptions) SetEndpoint(endpoint string) *CreateApiGatewayOperationItemOptions { + _options.Endpoint = core.StringPtr(endpoint) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateApiGatewayOperationItemOptions) SetHeaders(param map[string]string) *CreateApiGatewayOperationItemOptions { + options.Headers = param + return options +} + +// CreateApiGatewayOperationLabelsOptions : The CreateApiGatewayOperationLabels options. +type CreateApiGatewayOperationLabelsOptions struct { + // UUID of the API Gateway operation. + OperationID *string `json:"operation_id" validate:"required,ne="` + + // Flat list of user-defined label names to attach. Must be present; send an empty array if no user labels are needed. + User []string `json:"user,omitempty"` + + // Flat list of managed label names to attach (e.g. cf-llm). + Managed []string `json:"managed,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewCreateApiGatewayOperationLabelsOptions : Instantiate CreateApiGatewayOperationLabelsOptions +func (*AiSecurityForAppsV1) NewCreateApiGatewayOperationLabelsOptions(operationID string) *CreateApiGatewayOperationLabelsOptions { + return &CreateApiGatewayOperationLabelsOptions{ + OperationID: core.StringPtr(operationID), + } +} + +// SetOperationID : Allow user to set OperationID +func (_options *CreateApiGatewayOperationLabelsOptions) SetOperationID(operationID string) *CreateApiGatewayOperationLabelsOptions { + _options.OperationID = core.StringPtr(operationID) + return _options +} + +// SetUser : Allow user to set User +func (_options *CreateApiGatewayOperationLabelsOptions) SetUser(user []string) *CreateApiGatewayOperationLabelsOptions { + _options.User = user + return _options +} + +// SetManaged : Allow user to set Managed +func (_options *CreateApiGatewayOperationLabelsOptions) SetManaged(managed []string) *CreateApiGatewayOperationLabelsOptions { + _options.Managed = managed + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateApiGatewayOperationLabelsOptions) SetHeaders(param map[string]string) *CreateApiGatewayOperationLabelsOptions { + options.Headers = param + return options +} + +// CreateZoneApiGatewayOperationOptions : The CreateZoneApiGatewayOperation options. +type CreateZoneApiGatewayOperationOptions struct { + // List of operations to create. + ApiGatewayOperation []ApiGatewayOperation `json:"api_gateway_operation,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewCreateZoneApiGatewayOperationOptions : Instantiate CreateZoneApiGatewayOperationOptions +func (*AiSecurityForAppsV1) NewCreateZoneApiGatewayOperationOptions() *CreateZoneApiGatewayOperationOptions { + return &CreateZoneApiGatewayOperationOptions{} +} + +// SetApiGatewayOperation : Allow user to set ApiGatewayOperation +func (_options *CreateZoneApiGatewayOperationOptions) SetApiGatewayOperation(apiGatewayOperation []ApiGatewayOperation) *CreateZoneApiGatewayOperationOptions { + _options.ApiGatewayOperation = apiGatewayOperation + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateZoneApiGatewayOperationOptions) SetHeaders(param map[string]string) *CreateZoneApiGatewayOperationOptions { + options.Headers = param + return options +} + +// DeleteZoneApiGatewayOperationLabelsOptions : The DeleteZoneApiGatewayOperationLabels options. +type DeleteZoneApiGatewayOperationLabelsOptions struct { + // Selector specifying which operations to affect. + Selector *ApiGatewayOperationsLabelsBulkDeleteInputSelector `json:"selector" validate:"required"` + + // User-defined labels to remove. + User *ApiGatewayOperationsLabelsBulkDeleteInputUser `json:"user,omitempty"` + + // Managed labels to remove. + Managed *ApiGatewayOperationsLabelsBulkDeleteInputManaged `json:"managed,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewDeleteZoneApiGatewayOperationLabelsOptions : Instantiate DeleteZoneApiGatewayOperationLabelsOptions +func (*AiSecurityForAppsV1) NewDeleteZoneApiGatewayOperationLabelsOptions(selector *ApiGatewayOperationsLabelsBulkDeleteInputSelector) *DeleteZoneApiGatewayOperationLabelsOptions { + return &DeleteZoneApiGatewayOperationLabelsOptions{ + Selector: selector, + } +} + +// SetSelector : Allow user to set Selector +func (_options *DeleteZoneApiGatewayOperationLabelsOptions) SetSelector(selector *ApiGatewayOperationsLabelsBulkDeleteInputSelector) *DeleteZoneApiGatewayOperationLabelsOptions { + _options.Selector = selector + return _options +} + +// SetUser : Allow user to set User +func (_options *DeleteZoneApiGatewayOperationLabelsOptions) SetUser(user *ApiGatewayOperationsLabelsBulkDeleteInputUser) *DeleteZoneApiGatewayOperationLabelsOptions { + _options.User = user + return _options +} + +// SetManaged : Allow user to set Managed +func (_options *DeleteZoneApiGatewayOperationLabelsOptions) SetManaged(managed *ApiGatewayOperationsLabelsBulkDeleteInputManaged) *DeleteZoneApiGatewayOperationLabelsOptions { + _options.Managed = managed + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteZoneApiGatewayOperationLabelsOptions) SetHeaders(param map[string]string) *DeleteZoneApiGatewayOperationLabelsOptions { + options.Headers = param + return options +} + +// DeleteZoneApiGatewayOperationOptions : The DeleteZoneApiGatewayOperation options. +type DeleteZoneApiGatewayOperationOptions struct { + // UUID of the API Gateway operation. + OperationID *string `json:"operation_id" validate:"required,ne="` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewDeleteZoneApiGatewayOperationOptions : Instantiate DeleteZoneApiGatewayOperationOptions +func (*AiSecurityForAppsV1) NewDeleteZoneApiGatewayOperationOptions(operationID string) *DeleteZoneApiGatewayOperationOptions { + return &DeleteZoneApiGatewayOperationOptions{ + OperationID: core.StringPtr(operationID), + } +} + +// SetOperationID : Allow user to set OperationID +func (_options *DeleteZoneApiGatewayOperationOptions) SetOperationID(operationID string) *DeleteZoneApiGatewayOperationOptions { + _options.OperationID = core.StringPtr(operationID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteZoneApiGatewayOperationOptions) SetHeaders(param map[string]string) *DeleteZoneApiGatewayOperationOptions { + options.Headers = param + return options +} + +// DeleteZoneApiGatewayOperationsOptions : The DeleteZoneApiGatewayOperations options. +type DeleteZoneApiGatewayOperationsOptions struct { + // List of specific operation IDs to delete. + ApiGatewayOperationsDeleteInputItem []ApiGatewayOperationsDeleteInputItem `json:"ApiGatewayOperationsDeleteInputItem" validate:"required"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewDeleteZoneApiGatewayOperationsOptions : Instantiate DeleteZoneApiGatewayOperationsOptions +func (*AiSecurityForAppsV1) NewDeleteZoneApiGatewayOperationsOptions(apiGatewayOperationsDeleteInputItem []ApiGatewayOperationsDeleteInputItem) *DeleteZoneApiGatewayOperationsOptions { + return &DeleteZoneApiGatewayOperationsOptions{ + ApiGatewayOperationsDeleteInputItem: apiGatewayOperationsDeleteInputItem, + } +} + +// SetApiGatewayOperationsDeleteInputItem : Allow user to set ApiGatewayOperationsDeleteInputItem +func (_options *DeleteZoneApiGatewayOperationsOptions) SetApiGatewayOperationsDeleteInputItem(apiGatewayOperationsDeleteInputItem []ApiGatewayOperationsDeleteInputItem) *DeleteZoneApiGatewayOperationsOptions { + _options.ApiGatewayOperationsDeleteInputItem = apiGatewayOperationsDeleteInputItem + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteZoneApiGatewayOperationsOptions) SetHeaders(param map[string]string) *DeleteZoneApiGatewayOperationsOptions { + options.Headers = param + return options +} + +// DiscoveryOperationFeatures : DiscoveryOperationFeatures struct +type DiscoveryOperationFeatures struct { + TrafficStats *DiscoveryOperationFeaturesTrafficStats `json:"traffic_stats,omitempty"` +} + +// UnmarshalDiscoveryOperationFeatures unmarshals an instance of DiscoveryOperationFeatures from the specified map of raw messages. +func UnmarshalDiscoveryOperationFeatures(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DiscoveryOperationFeatures) + err = core.UnmarshalModel(m, "traffic_stats", &obj.TrafficStats, UnmarshalDiscoveryOperationFeaturesTrafficStats) + if err != nil { + err = core.SDKErrorf(err, "", "traffic_stats-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DiscoveryOperationFeaturesTrafficStats : DiscoveryOperationFeaturesTrafficStats struct +type DiscoveryOperationFeaturesTrafficStats struct { + LastUpdated *strfmt.DateTime `json:"last_updated,omitempty"` + + // The period in seconds over which statistics were computed. + PeriodSeconds *int64 `json:"period_seconds,omitempty"` + + // The average number of requests seen during this period. + Requests *float64 `json:"requests,omitempty"` +} + +// UnmarshalDiscoveryOperationFeaturesTrafficStats unmarshals an instance of DiscoveryOperationFeaturesTrafficStats from the specified map of raw messages. +func UnmarshalDiscoveryOperationFeaturesTrafficStats(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DiscoveryOperationFeaturesTrafficStats) + err = core.UnmarshalPrimitive(m, "last_updated", &obj.LastUpdated) + if err != nil { + err = core.SDKErrorf(err, "", "last_updated-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "period_seconds", &obj.PeriodSeconds) + if err != nil { + err = core.SDKErrorf(err, "", "period_seconds-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "requests", &obj.Requests) + if err != nil { + err = core.SDKErrorf(err, "", "requests-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GetAiSecuritySettingsOptions : The GetAiSecuritySettings options. +type GetAiSecuritySettingsOptions struct { + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewGetAiSecuritySettingsOptions : Instantiate GetAiSecuritySettingsOptions +func (*AiSecurityForAppsV1) NewGetAiSecuritySettingsOptions() *GetAiSecuritySettingsOptions { + return &GetAiSecuritySettingsOptions{} +} + +// SetHeaders : Allow user to set Headers +func (options *GetAiSecuritySettingsOptions) SetHeaders(param map[string]string) *GetAiSecuritySettingsOptions { + options.Headers = param + return options +} + +// GetApiGatewayDiscoveryOptions : The GetApiGatewayDiscovery options. +type GetApiGatewayDiscoveryOptions struct { + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewGetApiGatewayDiscoveryOptions : Instantiate GetApiGatewayDiscoveryOptions +func (*AiSecurityForAppsV1) NewGetApiGatewayDiscoveryOptions() *GetApiGatewayDiscoveryOptions { + return &GetApiGatewayDiscoveryOptions{} +} + +// SetHeaders : Allow user to set Headers +func (options *GetApiGatewayDiscoveryOptions) SetHeaders(param map[string]string) *GetApiGatewayDiscoveryOptions { + options.Headers = param + return options +} + +// GetApiGatewaySchemasOptions : The GetApiGatewaySchemas options. +type GetApiGatewaySchemasOptions struct { + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewGetApiGatewaySchemasOptions : Instantiate GetApiGatewaySchemasOptions +func (*AiSecurityForAppsV1) NewGetApiGatewaySchemasOptions() *GetApiGatewaySchemasOptions { + return &GetApiGatewaySchemasOptions{} +} + +// SetHeaders : Allow user to set Headers +func (options *GetApiGatewaySchemasOptions) SetHeaders(param map[string]string) *GetApiGatewaySchemasOptions { + options.Headers = param + return options +} + +// GetZoneApiGatewayOperationOptions : The GetZoneApiGatewayOperation options. +type GetZoneApiGatewayOperationOptions struct { + // UUID of the API Gateway operation. + OperationID *string `json:"operation_id" validate:"required,ne="` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewGetZoneApiGatewayOperationOptions : Instantiate GetZoneApiGatewayOperationOptions +func (*AiSecurityForAppsV1) NewGetZoneApiGatewayOperationOptions(operationID string) *GetZoneApiGatewayOperationOptions { + return &GetZoneApiGatewayOperationOptions{ + OperationID: core.StringPtr(operationID), + } +} + +// SetOperationID : Allow user to set OperationID +func (_options *GetZoneApiGatewayOperationOptions) SetOperationID(operationID string) *GetZoneApiGatewayOperationOptions { + _options.OperationID = core.StringPtr(operationID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetZoneApiGatewayOperationOptions) SetHeaders(param map[string]string) *GetZoneApiGatewayOperationOptions { + options.Headers = param + return options +} + +// ListApiGatewayDiscoveryOperationsOptions : The ListApiGatewayDiscoveryOperations options. +type ListApiGatewayDiscoveryOperationsOptions struct { + // When true, only return operations not yet saved into API Shield Endpoint Management. + Diff *bool `json:"diff,omitempty"` + + // Direction to order results. + Direction *string `json:"direction,omitempty"` + + // Filter results to only include endpoints containing this pattern. + Endpoint *string `json:"endpoint,omitempty"` + + // Filter results to only include the specified hosts. + Host []string `json:"host,omitempty"` + + // Filter results to only include the specified HTTP methods. + Method []string `json:"method,omitempty"` + + // Field to order results by. + Order *string `json:"order,omitempty"` + + // Filter by discovery engine source. + Origin *string `json:"origin,omitempty"` + + // Filter results by discovery state (review/saved/ignored). + State *string `json:"state,omitempty"` + + // Page number of paginated results. + Page *int64 `json:"page,omitempty"` + + // Maximum number of results per page. + PerPage *int64 `json:"per_page,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// Constants associated with the ListApiGatewayDiscoveryOperationsOptions.Direction property. +// Direction to order results. +const ( + ListApiGatewayDiscoveryOperationsOptions_Direction_Asc = "asc" + ListApiGatewayDiscoveryOperationsOptions_Direction_Desc = "desc" +) + +// Constants associated with the ListApiGatewayDiscoveryOperationsOptions.Order property. +// Field to order results by. +const ( + ListApiGatewayDiscoveryOperationsOptions_Order_Endpoint = "endpoint" + ListApiGatewayDiscoveryOperationsOptions_Order_Host = "host" + ListApiGatewayDiscoveryOperationsOptions_Order_Method = "method" + ListApiGatewayDiscoveryOperationsOptions_Order_TrafficStatsLastUpdated = "traffic_stats.last_updated" + ListApiGatewayDiscoveryOperationsOptions_Order_TrafficStatsRequests = "traffic_stats.requests" +) + +// Constants associated with the ListApiGatewayDiscoveryOperationsOptions.Origin property. +// Filter by discovery engine source. +const ( + ListApiGatewayDiscoveryOperationsOptions_Origin_Labeldiscovery = "LabelDiscovery" + ListApiGatewayDiscoveryOperationsOptions_Origin_Ml = "ML" + ListApiGatewayDiscoveryOperationsOptions_Origin_Sessionidentifier = "SessionIdentifier" +) + +// Constants associated with the ListApiGatewayDiscoveryOperationsOptions.State property. +// Filter results by discovery state (review/saved/ignored). +const ( + ListApiGatewayDiscoveryOperationsOptions_State_Ignored = "ignored" + ListApiGatewayDiscoveryOperationsOptions_State_Review = "review" + ListApiGatewayDiscoveryOperationsOptions_State_Saved = "saved" +) + +// NewListApiGatewayDiscoveryOperationsOptions : Instantiate ListApiGatewayDiscoveryOperationsOptions +func (*AiSecurityForAppsV1) NewListApiGatewayDiscoveryOperationsOptions() *ListApiGatewayDiscoveryOperationsOptions { + return &ListApiGatewayDiscoveryOperationsOptions{} +} + +// SetDiff : Allow user to set Diff +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetDiff(diff bool) *ListApiGatewayDiscoveryOperationsOptions { + _options.Diff = core.BoolPtr(diff) + return _options +} + +// SetDirection : Allow user to set Direction +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetDirection(direction string) *ListApiGatewayDiscoveryOperationsOptions { + _options.Direction = core.StringPtr(direction) + return _options +} + +// SetEndpoint : Allow user to set Endpoint +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetEndpoint(endpoint string) *ListApiGatewayDiscoveryOperationsOptions { + _options.Endpoint = core.StringPtr(endpoint) + return _options +} + +// SetHost : Allow user to set Host +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetHost(host []string) *ListApiGatewayDiscoveryOperationsOptions { + _options.Host = host + return _options +} + +// SetMethod : Allow user to set Method +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetMethod(method []string) *ListApiGatewayDiscoveryOperationsOptions { + _options.Method = method + return _options +} + +// SetOrder : Allow user to set Order +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetOrder(order string) *ListApiGatewayDiscoveryOperationsOptions { + _options.Order = core.StringPtr(order) + return _options +} + +// SetOrigin : Allow user to set Origin +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetOrigin(origin string) *ListApiGatewayDiscoveryOperationsOptions { + _options.Origin = core.StringPtr(origin) + return _options +} + +// SetState : Allow user to set State +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetState(state string) *ListApiGatewayDiscoveryOperationsOptions { + _options.State = core.StringPtr(state) + return _options +} + +// SetPage : Allow user to set Page +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetPage(page int64) *ListApiGatewayDiscoveryOperationsOptions { + _options.Page = core.Int64Ptr(page) + return _options +} + +// SetPerPage : Allow user to set PerPage +func (_options *ListApiGatewayDiscoveryOperationsOptions) SetPerPage(perPage int64) *ListApiGatewayDiscoveryOperationsOptions { + _options.PerPage = core.Int64Ptr(perPage) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListApiGatewayDiscoveryOperationsOptions) SetHeaders(param map[string]string) *ListApiGatewayDiscoveryOperationsOptions { + options.Headers = param + return options +} + +// ListZoneApiGatewayOperationsOptions : The ListZoneApiGatewayOperations options. +type ListZoneApiGatewayOperationsOptions struct { + // Filter results to only include the specified hosts. + Host []string `json:"host,omitempty"` + + // Filter results to only include the specified HTTP methods. + Method []string `json:"method,omitempty"` + + // Filter results to only include endpoints containing this pattern. + Endpoint *string `json:"endpoint,omitempty"` + + // Filter results to only include operations with these labels applied. Use cf-llm to find endpoints tagged for AI + // Security for Apps scanning. + Labels []string `json:"labels,omitempty"` + + // Direction to order results. + Direction *string `json:"direction,omitempty"` + + // Field to order results by. + Order *string `json:"order,omitempty"` + + // Page number of paginated results. + Page *int64 `json:"page,omitempty"` + + // Maximum number of results per page. + PerPage *int64 `json:"per_page,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// Constants associated with the ListZoneApiGatewayOperationsOptions.Method property. +const ( + ListZoneApiGatewayOperationsOptions_Method_Delete = "DELETE" + ListZoneApiGatewayOperationsOptions_Method_Get = "GET" + ListZoneApiGatewayOperationsOptions_Method_Head = "HEAD" + ListZoneApiGatewayOperationsOptions_Method_Options = "OPTIONS" + ListZoneApiGatewayOperationsOptions_Method_Patch = "PATCH" + ListZoneApiGatewayOperationsOptions_Method_Post = "POST" + ListZoneApiGatewayOperationsOptions_Method_Put = "PUT" +) + +// Constants associated with the ListZoneApiGatewayOperationsOptions.Direction property. +// Direction to order results. +const ( + ListZoneApiGatewayOperationsOptions_Direction_Asc = "asc" + ListZoneApiGatewayOperationsOptions_Direction_Desc = "desc" +) + +// Constants associated with the ListZoneApiGatewayOperationsOptions.Order property. +// Field to order results by. +const ( + ListZoneApiGatewayOperationsOptions_Order_Endpoint = "endpoint" + ListZoneApiGatewayOperationsOptions_Order_Host = "host" + ListZoneApiGatewayOperationsOptions_Order_LastUpdated = "last_updated" + ListZoneApiGatewayOperationsOptions_Order_Method = "method" +) + +// NewListZoneApiGatewayOperationsOptions : Instantiate ListZoneApiGatewayOperationsOptions +func (*AiSecurityForAppsV1) NewListZoneApiGatewayOperationsOptions() *ListZoneApiGatewayOperationsOptions { + return &ListZoneApiGatewayOperationsOptions{} +} + +// SetHost : Allow user to set Host +func (_options *ListZoneApiGatewayOperationsOptions) SetHost(host []string) *ListZoneApiGatewayOperationsOptions { + _options.Host = host + return _options +} + +// SetMethod : Allow user to set Method +func (_options *ListZoneApiGatewayOperationsOptions) SetMethod(method []string) *ListZoneApiGatewayOperationsOptions { + _options.Method = method + return _options +} + +// SetEndpoint : Allow user to set Endpoint +func (_options *ListZoneApiGatewayOperationsOptions) SetEndpoint(endpoint string) *ListZoneApiGatewayOperationsOptions { + _options.Endpoint = core.StringPtr(endpoint) + return _options +} + +// SetLabels : Allow user to set Labels +func (_options *ListZoneApiGatewayOperationsOptions) SetLabels(labels []string) *ListZoneApiGatewayOperationsOptions { + _options.Labels = labels + return _options +} + +// SetDirection : Allow user to set Direction +func (_options *ListZoneApiGatewayOperationsOptions) SetDirection(direction string) *ListZoneApiGatewayOperationsOptions { + _options.Direction = core.StringPtr(direction) + return _options +} + +// SetOrder : Allow user to set Order +func (_options *ListZoneApiGatewayOperationsOptions) SetOrder(order string) *ListZoneApiGatewayOperationsOptions { + _options.Order = core.StringPtr(order) + return _options +} + +// SetPage : Allow user to set Page +func (_options *ListZoneApiGatewayOperationsOptions) SetPage(page int64) *ListZoneApiGatewayOperationsOptions { + _options.Page = core.Int64Ptr(page) + return _options +} + +// SetPerPage : Allow user to set PerPage +func (_options *ListZoneApiGatewayOperationsOptions) SetPerPage(perPage int64) *ListZoneApiGatewayOperationsOptions { + _options.PerPage = core.Int64Ptr(perPage) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListZoneApiGatewayOperationsOptions) SetHeaders(param map[string]string) *ListZoneApiGatewayOperationsOptions { + options.Headers = param + return options +} + +// ReplaceZoneAiSecuritySettingsOptions : The ReplaceZoneAiSecuritySettings options. +type ReplaceZoneAiSecuritySettingsOptions struct { + // Set to true to enable AI Security for Apps, false to disable. + Enabled *bool `json:"enabled,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewReplaceZoneAiSecuritySettingsOptions : Instantiate ReplaceZoneAiSecuritySettingsOptions +func (*AiSecurityForAppsV1) NewReplaceZoneAiSecuritySettingsOptions() *ReplaceZoneAiSecuritySettingsOptions { + return &ReplaceZoneAiSecuritySettingsOptions{} +} + +// SetEnabled : Allow user to set Enabled +func (_options *ReplaceZoneAiSecuritySettingsOptions) SetEnabled(enabled bool) *ReplaceZoneAiSecuritySettingsOptions { + _options.Enabled = core.BoolPtr(enabled) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ReplaceZoneAiSecuritySettingsOptions) SetHeaders(param map[string]string) *ReplaceZoneAiSecuritySettingsOptions { + options.Headers = param + return options +} + +// ReplaceZoneApiGatewayOperationLabelsOptions : The ReplaceZoneApiGatewayOperationLabels options. +type ReplaceZoneApiGatewayOperationLabelsOptions struct { + // Selector specifying which operations to label. + Selector *ApiGatewayOperationsLabelsBulkInputSelector `json:"selector,omitempty"` + + // User-defined labels to apply. + User *ApiGatewayOperationsLabelsBulkInputUser `json:"user,omitempty"` + + // Managed labels to apply (e.g. cf-llm). + Managed *ApiGatewayOperationsLabelsBulkInputManaged `json:"managed,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewReplaceZoneApiGatewayOperationLabelsOptions : Instantiate ReplaceZoneApiGatewayOperationLabelsOptions +func (*AiSecurityForAppsV1) NewReplaceZoneApiGatewayOperationLabelsOptions() *ReplaceZoneApiGatewayOperationLabelsOptions { + return &ReplaceZoneApiGatewayOperationLabelsOptions{} +} + +// SetSelector : Allow user to set Selector +func (_options *ReplaceZoneApiGatewayOperationLabelsOptions) SetSelector(selector *ApiGatewayOperationsLabelsBulkInputSelector) *ReplaceZoneApiGatewayOperationLabelsOptions { + _options.Selector = selector + return _options +} + +// SetUser : Allow user to set User +func (_options *ReplaceZoneApiGatewayOperationLabelsOptions) SetUser(user *ApiGatewayOperationsLabelsBulkInputUser) *ReplaceZoneApiGatewayOperationLabelsOptions { + _options.User = user + return _options +} + +// SetManaged : Allow user to set Managed +func (_options *ReplaceZoneApiGatewayOperationLabelsOptions) SetManaged(managed *ApiGatewayOperationsLabelsBulkInputManaged) *ReplaceZoneApiGatewayOperationLabelsOptions { + _options.Managed = managed + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ReplaceZoneApiGatewayOperationLabelsOptions) SetHeaders(param map[string]string) *ReplaceZoneApiGatewayOperationLabelsOptions { + options.Headers = param + return options +} + +// SetZoneApiGatewayOperationLabelsOptions : The SetZoneApiGatewayOperationLabels options. +type SetZoneApiGatewayOperationLabelsOptions struct { + // UUID of the API Gateway operation. + OperationID *string `json:"operation_id" validate:"required,ne="` + + // Flat list of user-defined label names to attach. Must be present; send an empty array if no user labels are needed. + User []string `json:"user,omitempty"` + + // Flat list of managed label names to attach (e.g. cf-llm). + Managed []string `json:"managed,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewSetZoneApiGatewayOperationLabelsOptions : Instantiate SetZoneApiGatewayOperationLabelsOptions +func (*AiSecurityForAppsV1) NewSetZoneApiGatewayOperationLabelsOptions(operationID string) *SetZoneApiGatewayOperationLabelsOptions { + return &SetZoneApiGatewayOperationLabelsOptions{ + OperationID: core.StringPtr(operationID), + } +} + +// SetOperationID : Allow user to set OperationID +func (_options *SetZoneApiGatewayOperationLabelsOptions) SetOperationID(operationID string) *SetZoneApiGatewayOperationLabelsOptions { + _options.OperationID = core.StringPtr(operationID) + return _options +} + +// SetUser : Allow user to set User +func (_options *SetZoneApiGatewayOperationLabelsOptions) SetUser(user []string) *SetZoneApiGatewayOperationLabelsOptions { + _options.User = user + return _options +} + +// SetManaged : Allow user to set Managed +func (_options *SetZoneApiGatewayOperationLabelsOptions) SetManaged(managed []string) *SetZoneApiGatewayOperationLabelsOptions { + _options.Managed = managed + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *SetZoneApiGatewayOperationLabelsOptions) SetHeaders(param map[string]string) *SetZoneApiGatewayOperationLabelsOptions { + options.Headers = param + return options +} + +// UnsetZoneApiGatewayOperationLabelsOptions : The UnsetZoneApiGatewayOperationLabels options. +type UnsetZoneApiGatewayOperationLabelsOptions struct { + // UUID of the API Gateway operation. + OperationID *string `json:"operation_id" validate:"required,ne="` + + // Flat list of user-defined label names to remove. + User []string `json:"user,omitempty"` + + // Flat list of managed label names to remove. + Managed []string `json:"managed,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewUnsetZoneApiGatewayOperationLabelsOptions : Instantiate UnsetZoneApiGatewayOperationLabelsOptions +func (*AiSecurityForAppsV1) NewUnsetZoneApiGatewayOperationLabelsOptions(operationID string) *UnsetZoneApiGatewayOperationLabelsOptions { + return &UnsetZoneApiGatewayOperationLabelsOptions{ + OperationID: core.StringPtr(operationID), + } +} + +// SetOperationID : Allow user to set OperationID +func (_options *UnsetZoneApiGatewayOperationLabelsOptions) SetOperationID(operationID string) *UnsetZoneApiGatewayOperationLabelsOptions { + _options.OperationID = core.StringPtr(operationID) + return _options +} + +// SetUser : Allow user to set User +func (_options *UnsetZoneApiGatewayOperationLabelsOptions) SetUser(user []string) *UnsetZoneApiGatewayOperationLabelsOptions { + _options.User = user + return _options +} + +// SetManaged : Allow user to set Managed +func (_options *UnsetZoneApiGatewayOperationLabelsOptions) SetManaged(managed []string) *UnsetZoneApiGatewayOperationLabelsOptions { + _options.Managed = managed + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *UnsetZoneApiGatewayOperationLabelsOptions) SetHeaders(param map[string]string) *UnsetZoneApiGatewayOperationLabelsOptions { + options.Headers = param + return options +} + +// UpdateApiGatewayOperationLabelsOptions : The UpdateApiGatewayOperationLabels options. +type UpdateApiGatewayOperationLabelsOptions struct { + // Selector specifying which operations to label. + Selector *ApiGatewayOperationsLabelsBulkInputSelector `json:"selector,omitempty"` + + // User-defined labels to apply. + User *ApiGatewayOperationsLabelsBulkInputUser `json:"user,omitempty"` + + // Managed labels to apply (e.g. cf-llm). + Managed *ApiGatewayOperationsLabelsBulkInputManaged `json:"managed,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewUpdateApiGatewayOperationLabelsOptions : Instantiate UpdateApiGatewayOperationLabelsOptions +func (*AiSecurityForAppsV1) NewUpdateApiGatewayOperationLabelsOptions() *UpdateApiGatewayOperationLabelsOptions { + return &UpdateApiGatewayOperationLabelsOptions{} +} + +// SetSelector : Allow user to set Selector +func (_options *UpdateApiGatewayOperationLabelsOptions) SetSelector(selector *ApiGatewayOperationsLabelsBulkInputSelector) *UpdateApiGatewayOperationLabelsOptions { + _options.Selector = selector + return _options +} + +// SetUser : Allow user to set User +func (_options *UpdateApiGatewayOperationLabelsOptions) SetUser(user *ApiGatewayOperationsLabelsBulkInputUser) *UpdateApiGatewayOperationLabelsOptions { + _options.User = user + return _options +} + +// SetManaged : Allow user to set Managed +func (_options *UpdateApiGatewayOperationLabelsOptions) SetManaged(managed *ApiGatewayOperationsLabelsBulkInputManaged) *UpdateApiGatewayOperationLabelsOptions { + _options.Managed = managed + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *UpdateApiGatewayOperationLabelsOptions) SetHeaders(param map[string]string) *UpdateApiGatewayOperationLabelsOptions { + options.Headers = param + return options +} + +// UpdateZoneApiGatewayDiscoveryOperationOptions : The UpdateZoneApiGatewayDiscoveryOperation options. +type UpdateZoneApiGatewayDiscoveryOperationOptions struct { + // List of operation state updates. + RequestBody map[string]interface{} `json:"request_body,omitempty"` + + // Allows users to set headers on API requests. + Headers map[string]string +} + +// NewUpdateZoneApiGatewayDiscoveryOperationOptions : Instantiate UpdateZoneApiGatewayDiscoveryOperationOptions +func (*AiSecurityForAppsV1) NewUpdateZoneApiGatewayDiscoveryOperationOptions() *UpdateZoneApiGatewayDiscoveryOperationOptions { + return &UpdateZoneApiGatewayDiscoveryOperationOptions{} +} + +// SetRequestBody : Allow user to set RequestBody +func (_options *UpdateZoneApiGatewayDiscoveryOperationOptions) SetRequestBody(requestBody map[string]interface{}) *UpdateZoneApiGatewayDiscoveryOperationOptions { + _options.RequestBody = requestBody + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *UpdateZoneApiGatewayDiscoveryOperationOptions) SetHeaders(param map[string]string) *UpdateZoneApiGatewayDiscoveryOperationOptions { + options.Headers = param + return options +} + +// AiSecuritySettingsResp : AI Security for Apps settings response. +type AiSecuritySettingsResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + // Container for response information. + Result *AiSecuritySettingsRespResult `json:"result" validate:"required"` +} + +// UnmarshalAiSecuritySettingsResp unmarshals an instance of AiSecuritySettingsResp from the specified map of raw messages. +func UnmarshalAiSecuritySettingsResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AiSecuritySettingsResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalAiSecuritySettingsRespResult) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayDiscoveryResp : API Gateway discovery response (OpenAPI schema format). +type ApiGatewayDiscoveryResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + // Discovered operations rendered as an OpenAPI schema document. + Result map[string]interface{} `json:"result" validate:"required"` +} + +// UnmarshalApiGatewayDiscoveryResp unmarshals an instance of ApiGatewayDiscoveryResp from the specified map of raw messages. +func UnmarshalApiGatewayDiscoveryResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayDiscoveryResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "result", &obj.Result) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayNullResultResp : API Gateway response with null result on success. +type ApiGatewayNullResultResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + // Result on success. May be an empty object ({}) or an empty array ([]) depending on the operation. No type constraint + // is applied so that SDK generators produce an interface{} / any field that can hold either. + Result interface{} `json:"result" validate:"required"` +} + +// UnmarshalApiGatewayNullResultResp unmarshals an instance of ApiGatewayNullResultResp from the specified map of raw messages. +func UnmarshalApiGatewayNullResultResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayNullResultResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "result", &obj.Result) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperation : An API Gateway operation definition. +type ApiGatewayOperation struct { + // The HTTP method for the operation. + Method *string `json:"method" validate:"required"` + + // RFC3986-compliant host. + Host *string `json:"host" validate:"required"` + + // The endpoint path. Must start with /. + Endpoint *string `json:"endpoint" validate:"required"` +} + +// Constants associated with the ApiGatewayOperation.Method property. +// The HTTP method for the operation. +const ( + ApiGatewayOperation_Method_Delete = "DELETE" + ApiGatewayOperation_Method_Get = "GET" + ApiGatewayOperation_Method_Head = "HEAD" + ApiGatewayOperation_Method_Options = "OPTIONS" + ApiGatewayOperation_Method_Patch = "PATCH" + ApiGatewayOperation_Method_Post = "POST" + ApiGatewayOperation_Method_Put = "PUT" +) + +// NewApiGatewayOperation : Instantiate ApiGatewayOperation (Generic Model Constructor) +func (*AiSecurityForAppsV1) NewApiGatewayOperation(method string, host string, endpoint string) (_model *ApiGatewayOperation, err error) { + _model = &ApiGatewayOperation{ + Method: core.StringPtr(method), + Host: core.StringPtr(host), + Endpoint: core.StringPtr(endpoint), + } + err = core.ValidateStruct(_model, "required parameters") + if err != nil { + err = core.SDKErrorf(err, "", "model-missing-required", common.GetComponentInfo()) + } + return +} + +// UnmarshalApiGatewayOperation unmarshals an instance of ApiGatewayOperation from the specified map of raw messages. +func UnmarshalApiGatewayOperation(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperation) + err = core.UnmarshalPrimitive(m, "method", &obj.Method) + if err != nil { + err = core.SDKErrorf(err, "", "method-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "host", &obj.Host) + if err != nil { + err = core.SDKErrorf(err, "", "host-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "endpoint", &obj.Endpoint) + if err != nil { + err = core.SDKErrorf(err, "", "endpoint-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationItemResp : Single API Gateway operation create response. +type ApiGatewayOperationItemResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + Result *ApiGatewayOperationItemRespResult `json:"result" validate:"required"` +} + +// UnmarshalApiGatewayOperationItemResp unmarshals an instance of ApiGatewayOperationItemResp from the specified map of raw messages. +func UnmarshalApiGatewayOperationItemResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationItemResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalApiGatewayOperationItemRespResult) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationLabelResp : API Gateway single operation label response. +type ApiGatewayOperationLabelResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + // The updated operation with its label set. + Result *ApiGatewayOperationLabelRespResult `json:"result" validate:"required"` +} + +// UnmarshalApiGatewayOperationLabelResp unmarshals an instance of ApiGatewayOperationLabelResp from the specified map of raw messages. +func UnmarshalApiGatewayOperationLabelResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationLabelResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalApiGatewayOperationLabelRespResult) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsLabelsResp : API Gateway operations labels update response. +type ApiGatewayOperationsLabelsResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + // List of operations with their updated label sets. + Result []ApiGatewayOperationsLabelsRespResultItem `json:"result" validate:"required"` +} + +// UnmarshalApiGatewayOperationsLabelsResp unmarshals an instance of ApiGatewayOperationsLabelsResp from the specified map of raw messages. +func UnmarshalApiGatewayOperationsLabelsResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsLabelsResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalApiGatewayOperationsLabelsRespResultItem) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsListResp : API Gateway operations list response. +type ApiGatewayOperationsListResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + // List of operations in Endpoint Management. + Result []ApiGatewayOperationsListRespResultItem `json:"result" validate:"required"` + + ResultInfo *ResultInfo `json:"result_info,omitempty"` +} + +// UnmarshalApiGatewayOperationsListResp unmarshals an instance of ApiGatewayOperationsListResp from the specified map of raw messages. +func UnmarshalApiGatewayOperationsListResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsListResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalApiGatewayOperationsListRespResultItem) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result_info", &obj.ResultInfo, UnmarshalResultInfo) + if err != nil { + err = core.SDKErrorf(err, "", "result_info-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewayOperationsResp : API Gateway bulk operations create response. +type ApiGatewayOperationsResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + // List of created operations. + Result []ApiGatewayOperationsRespResultItem `json:"result" validate:"required"` +} + +// UnmarshalApiGatewayOperationsResp unmarshals an instance of ApiGatewayOperationsResp from the specified map of raw messages. +func UnmarshalApiGatewayOperationsResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewayOperationsResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalApiGatewayOperationsRespResultItem) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ApiGatewaySchemasResp : API Gateway schemas response (OpenAPI schema format). +type ApiGatewaySchemasResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + // API Gateway schemas rendered as an OpenAPI schema document. + Result map[string]interface{} `json:"result" validate:"required"` +} + +// UnmarshalApiGatewaySchemasResp unmarshals an instance of ApiGatewaySchemasResp from the specified map of raw messages. +func UnmarshalApiGatewaySchemasResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ApiGatewaySchemasResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "result", &obj.Result) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DiscoveryOperation : A discovered API operation. +type DiscoveryOperation struct { + // UUID of the discovered operation. + ID *string `json:"id,omitempty"` + + // The endpoint path. May contain path parameter templates in curly braces (e.g. /api/user/{var1}/details). + Endpoint *string `json:"endpoint,omitempty"` + + // RFC3986-compliant host. + Host *string `json:"host,omitempty"` + + // The HTTP method used to access the endpoint. + Method *string `json:"method,omitempty"` + + LastUpdated *strfmt.DateTime `json:"last_updated,omitempty"` + + // API discovery engine(s) that discovered this operation. + Origin []string `json:"origin,omitempty"` + + // State of the operation in API Discovery. review - not yet saved to Endpoint Management; saved - saved to Endpoint + // Management; ignored - marked as ignored. + State *string `json:"state,omitempty"` + + Features *DiscoveryOperationFeatures `json:"features,omitempty"` +} + +// Constants associated with the DiscoveryOperation.Method property. +// The HTTP method used to access the endpoint. +const ( + DiscoveryOperation_Method_Connect = "CONNECT" + DiscoveryOperation_Method_Delete = "DELETE" + DiscoveryOperation_Method_Get = "GET" + DiscoveryOperation_Method_Head = "HEAD" + DiscoveryOperation_Method_Options = "OPTIONS" + DiscoveryOperation_Method_Patch = "PATCH" + DiscoveryOperation_Method_Post = "POST" + DiscoveryOperation_Method_Put = "PUT" + DiscoveryOperation_Method_Trace = "TRACE" +) + +// Constants associated with the DiscoveryOperation.Origin property. +const ( + DiscoveryOperation_Origin_Labeldiscovery = "LabelDiscovery" + DiscoveryOperation_Origin_Ml = "ML" + DiscoveryOperation_Origin_Sessionidentifier = "SessionIdentifier" +) + +// Constants associated with the DiscoveryOperation.State property. +// State of the operation in API Discovery. review - not yet saved to Endpoint Management; saved - saved to Endpoint +// Management; ignored - marked as ignored. +const ( + DiscoveryOperation_State_Ignored = "ignored" + DiscoveryOperation_State_Review = "review" + DiscoveryOperation_State_Saved = "saved" +) + +// UnmarshalDiscoveryOperation unmarshals an instance of DiscoveryOperation from the specified map of raw messages. +func UnmarshalDiscoveryOperation(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DiscoveryOperation) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + err = core.SDKErrorf(err, "", "id-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "endpoint", &obj.Endpoint) + if err != nil { + err = core.SDKErrorf(err, "", "endpoint-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "host", &obj.Host) + if err != nil { + err = core.SDKErrorf(err, "", "host-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "method", &obj.Method) + if err != nil { + err = core.SDKErrorf(err, "", "method-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "last_updated", &obj.LastUpdated) + if err != nil { + err = core.SDKErrorf(err, "", "last_updated-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "origin", &obj.Origin) + if err != nil { + err = core.SDKErrorf(err, "", "origin-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "state", &obj.State) + if err != nil { + err = core.SDKErrorf(err, "", "state-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "features", &obj.Features, UnmarshalDiscoveryOperationFeatures) + if err != nil { + err = core.SDKErrorf(err, "", "features-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DiscoveryOperationsListResp : API Gateway discovery operations list response. +type DiscoveryOperationsListResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + Result []DiscoveryOperation `json:"result" validate:"required"` + + ResultInfo *ResultInfo `json:"result_info,omitempty"` +} + +// UnmarshalDiscoveryOperationsListResp unmarshals an instance of DiscoveryOperationsListResp from the specified map of raw messages. +func UnmarshalDiscoveryOperationsListResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DiscoveryOperationsListResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalDiscoveryOperation) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result_info", &obj.ResultInfo, UnmarshalResultInfo) + if err != nil { + err = core.SDKErrorf(err, "", "result_info-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DiscoveryOperationsPatchResp : API Gateway discovery operations bulk patch response. +type DiscoveryOperationsPatchResp struct { + // Was operation successful. + Success *bool `json:"success" validate:"required"` + + // Array of errors encountered. + Errors [][]string `json:"errors" validate:"required"` + + // Array of messages returned. + Messages [][]string `json:"messages" validate:"required"` + + Result []DiscoveryOperation `json:"result" validate:"required"` +} + +// UnmarshalDiscoveryOperationsPatchResp unmarshals an instance of DiscoveryOperationsPatchResp from the specified map of raw messages. +func UnmarshalDiscoveryOperationsPatchResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DiscoveryOperationsPatchResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + err = core.SDKErrorf(err, "", "success-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + err = core.SDKErrorf(err, "", "errors-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + err = core.SDKErrorf(err, "", "messages-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalDiscoveryOperation) + if err != nil { + err = core.SDKErrorf(err, "", "result-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ResultInfo : ResultInfo struct +type ResultInfo struct { + // Total number of results for the requested service. + Count *int64 `json:"count,omitempty"` + + // Current page within paginated list of results. + Page *int64 `json:"page,omitempty"` + + // Number of results per page. + PerPage *int64 `json:"per_page,omitempty"` + + // Total number of results. + TotalCount *int64 `json:"total_count,omitempty"` +} + +// UnmarshalResultInfo unmarshals an instance of ResultInfo from the specified map of raw messages. +func UnmarshalResultInfo(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ResultInfo) + err = core.UnmarshalPrimitive(m, "count", &obj.Count) + if err != nil { + err = core.SDKErrorf(err, "", "count-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "page", &obj.Page) + if err != nil { + err = core.SDKErrorf(err, "", "page-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "per_page", &obj.PerPage) + if err != nil { + err = core.SDKErrorf(err, "", "per_page-error", common.GetComponentInfo()) + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + err = core.SDKErrorf(err, "", "total_count-error", common.GetComponentInfo()) + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} diff --git a/aisecurityforappsv1/ai_security_for_apps_v1_integration_test.go b/aisecurityforappsv1/ai_security_for_apps_v1_integration_test.go new file mode 100644 index 00000000..e7d9ef59 --- /dev/null +++ b/aisecurityforappsv1/ai_security_for_apps_v1_integration_test.go @@ -0,0 +1,592 @@ +//go:build integration + +/** + * (C) Copyright IBM Corp. 2026. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package aisecurityforappsv1_test + +import ( + "fmt" + "net/http" + "os" + + "github.com/IBM/go-sdk-core/v5/core" + . "github.com/IBM/networking-go-sdk/aisecurityforappsv1" + "github.com/joho/godotenv" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +const configFile = "../cis.env" + +var configLoaded bool = true +var authenticationSucceeded bool = true + +func shouldSkipTest() { + if !configLoaded { + Skip("External configuration is not available, skipping...") + } + + if !authenticationSucceeded { + Skip("Authentication failed. Check external configuration...") + } +} + +var _ = Describe(`AiSecurityForAppsV1 Integration Tests`, func() { + + defer GinkgoRecover() + if _, err := os.Stat(configFile); err != nil { + configLoaded = false + } + + err := godotenv.Load(configFile) + if err != nil { + configLoaded = false + } + + authenticator := &core.IamAuthenticator{ + ApiKey: os.Getenv("CIS_SERVICES_APIKEY"), + URL: os.Getenv("CIS_SERVICES_AUTH_URL"), + } + authErr := authenticator.Authenticate(&http.Request{ + Header: http.Header{}, + }) + if authErr != nil { + authenticationSucceeded = false + fmt.Println("Authentication error during setup: ", authErr) + } + serviceURL := os.Getenv("API_ENDPOINT") + crn := os.Getenv("CRN") + zoneID := os.Getenv("ZONE_ID") + + globalOptions := &AiSecurityForAppsV1Options{ + ServiceName: DefaultServiceName, + URL: serviceURL, + Authenticator: authenticator, + Crn: &crn, + ZoneIdentifier: &zoneID, + } + + service, serviceErr := NewAiSecurityForAppsV1(globalOptions) + if serviceErr != nil { + fmt.Println(serviceErr) + } + + // ========================================================================= + // AI Security Settings + // ========================================================================= + + Describe(`AI Security Settings`, func() { + Context(`Get and Update AI Security Settings`, func() { + It(`Get AI Security Settings`, func() { + shouldSkipTest() + + getOptions := service.NewGetAiSecuritySettingsOptions() + result, response, err := service.GetAiSecuritySettings(getOptions) + Expect(err).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(*result.Success).To(BeTrue()) + }) + + It(`Update AI Security Settings`, func() { + shouldSkipTest() + + // Read current value so we can restore it afterwards + getOptions := service.NewGetAiSecuritySettingsOptions() + getResult, _, getErr := service.GetAiSecuritySettings(getOptions) + Expect(getErr).To(BeNil()) + Expect(getResult).ToNot(BeNil()) + + currentEnabled := *getResult.Result.Enabled + + // Toggle to the opposite value + updateOptions := service.NewReplaceZoneAiSecuritySettingsOptions(). + SetEnabled(!currentEnabled) + result, response, err := service.ReplaceZoneAiSecuritySettings(updateOptions) + Expect(err).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(*result.Success).To(BeTrue()) + Expect(*result.Result.Enabled).To(Equal(!currentEnabled)) + + // Restore original value + restoreOptions := service.NewReplaceZoneAiSecuritySettingsOptions(). + SetEnabled(currentEnabled) + _, _, restoreErr := service.ReplaceZoneAiSecuritySettings(restoreOptions) + Expect(restoreErr).To(BeNil()) + }) + }) + }) + + // ========================================================================= + // API Gateway — all operations follow the natural resource lifecycle + // ========================================================================= + + Describe(`API Gateway`, func() { + + // ----------------------------------------------------------------- + // Read-only discovery and schema endpoints + // ----------------------------------------------------------------- + + Context(`Read-only operations`, func() { + It(`Get API Gateway Discovery (OpenAPI schema view)`, func() { + shouldSkipTest() + + result, response, err := service.GetApiGatewayDiscovery(service.NewGetApiGatewayDiscoveryOptions()) + Expect(err).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(*result.Success).To(BeTrue()) + }) + + It(`List API Gateway Discovery Operations (default params)`, func() { + shouldSkipTest() + + result, response, err := service.ListApiGatewayDiscoveryOperations( + service.NewListApiGatewayDiscoveryOperationsOptions(), + ) + Expect(err).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(*result.Success).To(BeTrue()) + }) + + It(`List API Gateway Discovery Operations with filters`, func() { + shouldSkipTest() + + opts := service.NewListApiGatewayDiscoveryOperationsOptions(). + SetPerPage(5). + SetPage(1) + result, response, err := service.ListApiGatewayDiscoveryOperations(opts) + Expect(err).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(*result.Success).To(BeTrue()) + }) + + It(`Get API Gateway Schemas (OpenAPI schema view)`, func() { + shouldSkipTest() + + result, response, err := service.GetApiGatewaySchemas(service.NewGetApiGatewaySchemasOptions()) + Expect(err).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(*result.Success).To(BeTrue()) + }) + }) + + // ----------------------------------------------------------------- + // Discovery state update (PATCH) — depends on zone having + // discovered operations in "review" state; skipped gracefully if not + // ----------------------------------------------------------------- + + Context(`Discovery state update`, func() { + It(`Bulk-update discovered operation state (ignored → review)`, func() { + shouldSkipTest() + + // Find at least one operation in "review" state to patch + listOpts := service.NewListApiGatewayDiscoveryOperationsOptions(). + SetState("review"). + SetPerPage(5) + listResult, listResponse, listErr := service.ListApiGatewayDiscoveryOperations(listOpts) + Expect(listErr).To(BeNil()) + Expect(listResponse).ToNot(BeNil()) + Expect(listResult).ToNot(BeNil()) + Expect(*listResult.Success).To(BeTrue()) + + if len(listResult.Result) == 0 { + Skip("No discovered operations in 'review' state — skipping discovery PATCH test") + } + + discoveredID := *listResult.Result[0].ID + + // PATCH: mark "ignored"; body is a free-form map { uuid: { state } } + patchBody := map[string]interface{}{ + discoveredID: map[string]interface{}{"state": "ignored"}, + } + patchResult, patchResponse, patchErr := service.UpdateZoneApiGatewayDiscoveryOperation( + service.NewUpdateZoneApiGatewayDiscoveryOperationOptions().SetRequestBody(patchBody), + ) + Expect(patchErr).To(BeNil()) + Expect(patchResponse).ToNot(BeNil()) + Expect(patchResult).ToNot(BeNil()) + Expect(*patchResult.Success).To(BeTrue()) + + // Restore to "review" + restoreBody := map[string]interface{}{ + discoveredID: map[string]interface{}{"state": "review"}, + } + _, _, restoreErr := service.UpdateZoneApiGatewayDiscoveryOperation( + service.NewUpdateZoneApiGatewayDiscoveryOperationOptions().SetRequestBody(restoreBody), + ) + Expect(restoreErr).To(BeNil()) + }) + }) + + // ----------------------------------------------------------------- + // Single-operation lifecycle: Create → List (verify) → Get → Delete → 404 + // ----------------------------------------------------------------- + + Context(`Single operation lifecycle`, func() { + It(`Create, list, get, delete, and verify 404`, func() { + shouldSkipTest() + + // Create a single operation via the /item endpoint + createResult, createResponse, createErr := service.CreateApiGatewayOperationItem( + service.NewCreateApiGatewayOperationItemOptions(). + SetMethod("POST"). + SetHost("api.example.com"). + SetEndpoint("/v1/messages"), + ) + Expect(createErr).To(BeNil()) + Expect(createResponse).ToNot(BeNil()) + Expect(createResult).ToNot(BeNil()) + Expect(*createResult.Success).To(BeTrue()) + Expect(createResult.Result).ToNot(BeNil()) + Expect(createResult.Result.OperationID).ToNot(BeNil()) + + operationID := *createResult.Result.OperationID + + // Safety cleanup if a later assertion fails + defer func() { + if operationID != "" { + _, _ = service.DeleteZoneApiGatewayOperation( + service.NewDeleteZoneApiGatewayOperationOptions(operationID), + ) + } + }() + + // List operations and verify the newly created one appears + listResult, listResponse, listErr := service.ListZoneApiGatewayOperations( + service.NewListZoneApiGatewayOperationsOptions(). + SetHost([]string{"api.example.com"}). + SetMethod([]string{"POST"}), + ) + Expect(listErr).To(BeNil()) + Expect(listResponse).ToNot(BeNil()) + Expect(listResult).ToNot(BeNil()) + Expect(*listResult.Success).To(BeTrue()) + found := false + for _, op := range listResult.Result { + if op.OperationID != nil && *op.OperationID == operationID { + found = true + break + } + } + Expect(found).To(BeTrue(), "Expected newly created operation %s in list result", operationID) + + // Get by ID and verify fields round-trip correctly + getResult, getResponse, getErr := service.GetZoneApiGatewayOperation( + service.NewGetZoneApiGatewayOperationOptions(operationID), + ) + Expect(getErr).To(BeNil()) + Expect(getResponse).ToNot(BeNil()) + Expect(getResult).ToNot(BeNil()) + Expect(*getResult.Success).To(BeTrue()) + Expect(*getResult.Result.OperationID).To(Equal(operationID)) + Expect(*getResult.Result.Method).To(Equal("POST")) + Expect(*getResult.Result.Host).To(Equal("api.example.com")) + Expect(*getResult.Result.Endpoint).To(Equal("/v1/messages")) + + // Delete and assert 204 / no error + deleteResponse, deleteErr := service.DeleteZoneApiGatewayOperation( + service.NewDeleteZoneApiGatewayOperationOptions(operationID), + ) + Expect(deleteErr).To(BeNil()) + Expect(deleteResponse).ToNot(BeNil()) + operationID = "" // prevent defer double-delete + + // Verify the operation is gone (404) + _, verifyResponse, verifyErr := service.GetZoneApiGatewayOperation( + service.NewGetZoneApiGatewayOperationOptions(*createResult.Result.OperationID), + ) + Expect(verifyErr).ToNot(BeNil()) + Expect(verifyResponse.StatusCode).To(Equal(404)) + }) + }) + + // ----------------------------------------------------------------- + // Bulk operation lifecycle: + // Create (bulk) → Get one → Update labels (add) → Replace labels + // (bulk PUT) → Delete labels (bulk DELETE) → Delete all individually + // ----------------------------------------------------------------- + + Context(`Bulk operation lifecycle`, func() { + It(`Create 3 operations, label them, verify labels, then clean up`, func() { + shouldSkipTest() + + // Build 3 operations and create them in one bulk call + op1, err := service.NewApiGatewayOperation("GET", "api.example.com", "/v2/users") + Expect(err).To(BeNil()) + op2, err := service.NewApiGatewayOperation("POST", "api.example.com", "/v2/orders") + Expect(err).To(BeNil()) + op3, err := service.NewApiGatewayOperation("DELETE", "api.example.com", "/v2/sessions") + Expect(err).To(BeNil()) + + bulkResult, bulkResponse, bulkErr := service.CreateZoneApiGatewayOperation( + service.NewCreateZoneApiGatewayOperationOptions(). + SetApiGatewayOperation([]ApiGatewayOperation{*op1, *op2, *op3}), + ) + Expect(bulkErr).To(BeNil()) + Expect(bulkResponse).ToNot(BeNil()) + Expect(bulkResult).ToNot(BeNil()) + Expect(*bulkResult.Success).To(BeTrue()) + Expect(len(bulkResult.Result)).To(Equal(3)) + + opIDs := make([]string, 0, 3) + for _, item := range bulkResult.Result { + Expect(item.OperationID).ToNot(BeNil()) + opIDs = append(opIDs, *item.OperationID) + } + + // Safety cleanup — always delete individually on exit + defer func() { + for _, id := range opIDs { + _, _ = service.DeleteZoneApiGatewayOperation( + service.NewDeleteZoneApiGatewayOperationOptions(id), + ) + } + }() + + // Step 1: Get one operation by ID and verify its fields + getResult, getResponse, getErr := service.GetZoneApiGatewayOperation( + service.NewGetZoneApiGatewayOperationOptions(opIDs[1]), + ) + Expect(getErr).To(BeNil()) + Expect(getResponse).ToNot(BeNil()) + Expect(getResult).ToNot(BeNil()) + Expect(*getResult.Success).To(BeTrue()) + Expect(*getResult.Result.OperationID).To(Equal(opIDs[1])) + + // Step 2: Add managed label to all 3 ops (POST /operations/labels) + // API requires 'user' field to be present even when empty + const managedLabel = "cf-llm" + addResult, addResponse, addErr := service.UpdateApiGatewayOperationLabels( + service.NewUpdateApiGatewayOperationLabelsOptions(). + SetUser(&ApiGatewayOperationsLabelsBulkInputUser{Labels: []string{}}). + SetManaged(&ApiGatewayOperationsLabelsBulkInputManaged{Labels: []string{managedLabel}}). + SetSelector(&ApiGatewayOperationsLabelsBulkInputSelector{ + Include: &ApiGatewayOperationsLabelsBulkInputSelectorInclude{ + OperationIds: opIDs, + }, + }), + ) + Expect(addErr).To(BeNil()) + Expect(addResponse).ToNot(BeNil()) + Expect(addResult).ToNot(BeNil()) + Expect(*addResult.Success).To(BeTrue()) + Expect(len(addResult.Result)).To(Equal(3)) + + // Verify all 3 operations have the label + for _, item := range addResult.Result { + hasLabel := false + for _, lbl := range item.Labels { + if lbl.Name != nil && *lbl.Name == managedLabel { + hasLabel = true + break + } + } + Expect(hasLabel).To(BeTrue(), "Expected label '%s' on operation %s", managedLabel, *item.OperationID) + } + + // Step 3: Replace labels on all 3 ops (PUT /operations/labels) + replaceResult, replaceResponse, replaceErr := service.ReplaceZoneApiGatewayOperationLabels( + service.NewReplaceZoneApiGatewayOperationLabelsOptions(). + SetUser(&ApiGatewayOperationsLabelsBulkInputUser{Labels: []string{}}). + SetManaged(&ApiGatewayOperationsLabelsBulkInputManaged{Labels: []string{managedLabel}}). + SetSelector(&ApiGatewayOperationsLabelsBulkInputSelector{ + Include: &ApiGatewayOperationsLabelsBulkInputSelectorInclude{ + OperationIds: opIDs, + }, + }), + ) + Expect(replaceErr).To(BeNil()) + Expect(replaceResponse).ToNot(BeNil()) + Expect(replaceResult).ToNot(BeNil()) + Expect(*replaceResult.Success).To(BeTrue()) + + // Step 4: Bulk-delete labels from all 3 ops (DELETE /operations/labels) + deleteLabelsResult, deleteLabelsResponse, deleteLabelsErr := service.DeleteZoneApiGatewayOperationLabels( + service.NewDeleteZoneApiGatewayOperationLabelsOptions( + &ApiGatewayOperationsLabelsBulkDeleteInputSelector{ + Include: &ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude{ + OperationIds: opIDs, + }, + }, + ).SetManaged(&ApiGatewayOperationsLabelsBulkDeleteInputManaged{ + Labels: []string{managedLabel}, + }), + ) + Expect(deleteLabelsErr).To(BeNil()) + Expect(deleteLabelsResponse).ToNot(BeNil()) + Expect(deleteLabelsResult).ToNot(BeNil()) + Expect(*deleteLabelsResult.Success).To(BeTrue()) + + // Step 5: Delete all operations individually and assert each call succeeds + for _, id := range opIDs { + deleteResponse, deleteErr := service.DeleteZoneApiGatewayOperation( + service.NewDeleteZoneApiGatewayOperationOptions(id), + ) + Expect(deleteErr).To(BeNil()) + Expect(deleteResponse).ToNot(BeNil()) + } + opIDs = nil // prevent defer double-delete + }) + }) + + // ----------------------------------------------------------------- + // Per-operation label lifecycle (POST/PUT/DELETE on /{operation_id}/labels) + // Uses CreateApiGatewayOperationItem to create a fresh operation, + // exercises all three per-operation label verbs, then deletes it. + // ----------------------------------------------------------------- + + Context(`Per-operation label lifecycle`, func() { + It(`Create operation, attach labels, replace labels, remove labels, delete operation`, func() { + shouldSkipTest() + + // Create a dedicated operation to attach labels to + createResult, createResponse, createErr := service.CreateApiGatewayOperationItem( + service.NewCreateApiGatewayOperationItemOptions(). + SetMethod("POST"). + SetHost("api.example.com"). + SetEndpoint("/v1/label-test"), + ) + Expect(createErr).To(BeNil()) + Expect(createResponse).ToNot(BeNil()) + Expect(createResult).ToNot(BeNil()) + Expect(*createResult.Success).To(BeTrue()) + Expect(createResult.Result.OperationID).ToNot(BeNil()) + + operationID := *createResult.Result.OperationID + + // Safety cleanup + defer func() { + if operationID != "" { + _, _ = service.DeleteZoneApiGatewayOperation( + service.NewDeleteZoneApiGatewayOperationOptions(operationID), + ) + } + }() + + // Step 1: Attach labels — POST /{operation_id}/labels + // API requires both 'user' and 'managed' in the body + addResult, addResponse, addErr := service.CreateApiGatewayOperationLabels( + service.NewCreateApiGatewayOperationLabelsOptions(operationID). + SetUser([]string{}). + SetManaged([]string{"cf-llm"}), + ) + Expect(addErr).To(BeNil()) + Expect(addResponse).ToNot(BeNil()) + Expect(addResult).ToNot(BeNil()) + Expect(*addResult.Success).To(BeTrue()) + + // Step 2: Replace labels — PUT /{operation_id}/labels + // API requires both 'user' and 'managed' in the body + setResult, setResponse, setErr := service.SetZoneApiGatewayOperationLabels( + service.NewSetZoneApiGatewayOperationLabelsOptions(operationID). + SetUser([]string{}). + SetManaged([]string{"cf-llm"}), + ) + Expect(setErr).To(BeNil()) + Expect(setResponse).ToNot(BeNil()) + Expect(setResult).ToNot(BeNil()) + Expect(*setResult.Success).To(BeTrue()) + + // Step 3: Remove labels — DELETE /{operation_id}/labels + unsetResult, unsetResponse, unsetErr := service.UnsetZoneApiGatewayOperationLabels( + service.NewUnsetZoneApiGatewayOperationLabelsOptions(operationID). + SetManaged([]string{"cf-llm"}), + ) + Expect(unsetErr).To(BeNil()) + Expect(unsetResponse).ToNot(BeNil()) + Expect(unsetResult).ToNot(BeNil()) + Expect(*unsetResult.Success).To(BeTrue()) + + // Clean up the operation + _, deleteErr := service.DeleteZoneApiGatewayOperation( + service.NewDeleteZoneApiGatewayOperationOptions(operationID), + ) + Expect(deleteErr).To(BeNil()) + operationID = "" // prevent defer double-delete + }) + }) + + // ----------------------------------------------------------------- + // Bulk operation delete (DELETE /operations with operation_ids body) + // Creates two operations, attempts bulk-delete. + // Tolerates a 400 if the backend rejects the format on this zone — + // the individual defer cleanup handles the actual teardown. + // ----------------------------------------------------------------- + + Context(`Bulk operation delete`, func() { + It(`Create two operations then bulk-delete them`, func() { + shouldSkipTest() + + op1, err := service.NewApiGatewayOperation("GET", "api.example.com", "/v1/bulk-del/a") + Expect(err).To(BeNil()) + op2, err := service.NewApiGatewayOperation("POST", "api.example.com", "/v1/bulk-del/b") + Expect(err).To(BeNil()) + + createResult, createResponse, createErr := service.CreateZoneApiGatewayOperation( + service.NewCreateZoneApiGatewayOperationOptions(). + SetApiGatewayOperation([]ApiGatewayOperation{*op1, *op2}), + ) + Expect(createErr).To(BeNil()) + Expect(createResponse).ToNot(BeNil()) + Expect(createResult).ToNot(BeNil()) + Expect(*createResult.Success).To(BeTrue()) + Expect(len(createResult.Result)).To(BeNumerically(">=", 1)) + + ids := make([]string, 0, len(createResult.Result)) + for _, op := range createResult.Result { + if op.OperationID != nil { + ids = append(ids, *op.OperationID) + } + } + + // Always clean up individually — defer handles teardown regardless of bulk outcome + defer func() { + for _, id := range ids { + _, _ = service.DeleteZoneApiGatewayOperation( + service.NewDeleteZoneApiGatewayOperationOptions(id), + ) + } + }() + + deleteItems := make([]ApiGatewayOperationsDeleteInputItem, 0, len(ids)) + for _, id := range ids { + item, err := service.NewApiGatewayOperationsDeleteInputItem(id) + Expect(err).To(BeNil()) + deleteItems = append(deleteItems, *item) + } + + // Attempt bulk-delete; tolerate failure (backend inconsistency on some zones) + bulkDeleteResult, bulkDeleteResponse, bulkDeleteErr := service.DeleteZoneApiGatewayOperations( + service.NewDeleteZoneApiGatewayOperationsOptions(deleteItems), + ) + if bulkDeleteErr == nil { + Expect(bulkDeleteResponse).ToNot(BeNil()) + Expect(bulkDeleteResult).ToNot(BeNil()) + Expect(*bulkDeleteResult.Success).To(BeTrue()) + ids = nil // prevent defer double-delete + } else { + fmt.Printf("DeleteZoneApiGatewayOperations returned error (may be unsupported on this zone): %v\n", bulkDeleteErr) + } + }) + }) + }) +}) diff --git a/aisecurityforappsv1/ai_security_for_apps_v1_suite_test.go b/aisecurityforappsv1/ai_security_for_apps_v1_suite_test.go new file mode 100644 index 00000000..5bd6f409 --- /dev/null +++ b/aisecurityforappsv1/ai_security_for_apps_v1_suite_test.go @@ -0,0 +1,29 @@ +/** + * (C) Copyright IBM Corp. 2026. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package aisecurityforappsv1_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestAiSecurityForAppsV1(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "AiSecurityForAppsV1 Suite") +} diff --git a/aisecurityforappsv1/ai_security_for_apps_v1_test.go b/aisecurityforappsv1/ai_security_for_apps_v1_test.go new file mode 100644 index 00000000..a5dd03e7 --- /dev/null +++ b/aisecurityforappsv1/ai_security_for_apps_v1_test.go @@ -0,0 +1,5462 @@ +/** + * (C) Copyright IBM Corp. 2026. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package aisecurityforappsv1_test + +import ( + "bytes" + "context" + "encoding/base64" + "encoding/json" + "fmt" + "io" + "net/http" + "net/http/httptest" + "os" + "time" + + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/networking-go-sdk/aisecurityforappsv1" + "github.com/go-openapi/strfmt" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe(`AiSecurityForAppsV1`, func() { + var testServer *httptest.Server + Describe(`Service constructor tests`, func() { + crn := "testString" + zoneIdentifier := "testString" + It(`Instantiate service client`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + }) + It(`Instantiate service client with error: Invalid URL`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: "{BAD_URL_STRING", + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(aiSecurityForAppsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + It(`Instantiate service client with error: Invalid Auth`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: "https://aisecurityforappsv1/api", + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + Authenticator: &core.BasicAuthenticator{ + Username: "", + Password: "", + }, + }) + Expect(aiSecurityForAppsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + It(`Instantiate service client with error: Validation Error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{}) + Expect(aiSecurityForAppsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + }) + Describe(`Service constructor tests using external config`, func() { + crn := "testString" + zoneIdentifier := "testString" + Context(`Using external config, construct service client instances`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "AI_SECURITY_FOR_APPS_URL": "https://aisecurityforappsv1/api", + "AI_SECURITY_FOR_APPS_AUTH_TYPE": "noauth", + } + + It(`Create service client using external config successfully`, func() { + SetTestEnvironment(testEnvironment) + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1UsingExternalConfig(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + ClearTestEnvironment(testEnvironment) + + clone := aiSecurityForAppsService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != aiSecurityForAppsService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(aiSecurityForAppsService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(aiSecurityForAppsService.Service.Options.Authenticator)) + }) + It(`Create service client using external config and set url from constructor successfully`, func() { + SetTestEnvironment(testEnvironment) + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1UsingExternalConfig(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: "https://testService/api", + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + + clone := aiSecurityForAppsService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != aiSecurityForAppsService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(aiSecurityForAppsService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(aiSecurityForAppsService.Service.Options.Authenticator)) + }) + It(`Create service client using external config and set url programatically successfully`, func() { + SetTestEnvironment(testEnvironment) + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1UsingExternalConfig(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + err := aiSecurityForAppsService.SetServiceURL("https://testService/api") + Expect(err).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + + clone := aiSecurityForAppsService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != aiSecurityForAppsService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(aiSecurityForAppsService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(aiSecurityForAppsService.Service.Options.Authenticator)) + }) + }) + Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "AI_SECURITY_FOR_APPS_URL": "https://aisecurityforappsv1/api", + "AI_SECURITY_FOR_APPS_AUTH_TYPE": "someOtherAuth", + } + + SetTestEnvironment(testEnvironment) + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1UsingExternalConfig(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + + It(`Instantiate service client with error`, func() { + Expect(aiSecurityForAppsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + Context(`Using external config, construct service client instances with error: Invalid URL`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "AI_SECURITY_FOR_APPS_AUTH_TYPE": "NOAuth", + } + + SetTestEnvironment(testEnvironment) + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1UsingExternalConfig(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: "{BAD_URL_STRING", + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + + It(`Instantiate service client with error`, func() { + Expect(aiSecurityForAppsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + }) + Describe(`Regional endpoint tests`, func() { + It(`GetServiceURLForRegion(region string)`, func() { + var url string + var err error + url, err = aisecurityforappsv1.GetServiceURLForRegion("INVALID_REGION") + Expect(url).To(BeEmpty()) + Expect(err).ToNot(BeNil()) + fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error()) + }) + }) + Describe(`GetAiSecuritySettings(getAiSecuritySettingsOptions *GetAiSecuritySettingsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + getAiSecuritySettingsPath := "/v1/testString/zones/testString/ai_security/settings" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getAiSecuritySettingsPath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetAiSecuritySettings with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetAiSecuritySettingsOptions model + getAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.GetAiSecuritySettingsOptions) + getAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.GetAiSecuritySettings(getAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.GetAiSecuritySettings(getAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetAiSecuritySettings(getAiSecuritySettingsOptions *GetAiSecuritySettingsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + getAiSecuritySettingsPath := "/v1/testString/zones/testString/ai_security/settings" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getAiSecuritySettingsPath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"enabled": false}}`) + })) + }) + It(`Invoke GetAiSecuritySettings successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the GetAiSecuritySettingsOptions model + getAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.GetAiSecuritySettingsOptions) + getAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.GetAiSecuritySettingsWithContext(ctx, getAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.GetAiSecuritySettings(getAiSecuritySettingsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.GetAiSecuritySettingsWithContext(ctx, getAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getAiSecuritySettingsPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"enabled": false}}`) + })) + }) + It(`Invoke GetAiSecuritySettings successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.GetAiSecuritySettings(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetAiSecuritySettingsOptions model + getAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.GetAiSecuritySettingsOptions) + getAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.GetAiSecuritySettings(getAiSecuritySettingsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetAiSecuritySettings with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetAiSecuritySettingsOptions model + getAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.GetAiSecuritySettingsOptions) + getAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.GetAiSecuritySettings(getAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetAiSecuritySettings successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetAiSecuritySettingsOptions model + getAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.GetAiSecuritySettingsOptions) + getAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.GetAiSecuritySettings(getAiSecuritySettingsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptions *ReplaceZoneAiSecuritySettingsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + replaceZoneAiSecuritySettingsPath := "/v1/testString/zones/testString/ai_security/settings" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceZoneAiSecuritySettingsPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ReplaceZoneAiSecuritySettings with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ReplaceZoneAiSecuritySettingsOptions model + replaceZoneAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.ReplaceZoneAiSecuritySettingsOptions) + replaceZoneAiSecuritySettingsOptionsModel.Enabled = core.BoolPtr(true) + replaceZoneAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptions *ReplaceZoneAiSecuritySettingsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + replaceZoneAiSecuritySettingsPath := "/v1/testString/zones/testString/ai_security/settings" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceZoneAiSecuritySettingsPath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"enabled": false}}`) + })) + }) + It(`Invoke ReplaceZoneAiSecuritySettings successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the ReplaceZoneAiSecuritySettingsOptions model + replaceZoneAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.ReplaceZoneAiSecuritySettingsOptions) + replaceZoneAiSecuritySettingsOptionsModel.Enabled = core.BoolPtr(true) + replaceZoneAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.ReplaceZoneAiSecuritySettingsWithContext(ctx, replaceZoneAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.ReplaceZoneAiSecuritySettingsWithContext(ctx, replaceZoneAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceZoneAiSecuritySettingsPath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"enabled": false}}`) + })) + }) + It(`Invoke ReplaceZoneAiSecuritySettings successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneAiSecuritySettings(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ReplaceZoneAiSecuritySettingsOptions model + replaceZoneAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.ReplaceZoneAiSecuritySettingsOptions) + replaceZoneAiSecuritySettingsOptionsModel.Enabled = core.BoolPtr(true) + replaceZoneAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ReplaceZoneAiSecuritySettings with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ReplaceZoneAiSecuritySettingsOptions model + replaceZoneAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.ReplaceZoneAiSecuritySettingsOptions) + replaceZoneAiSecuritySettingsOptionsModel.Enabled = core.BoolPtr(true) + replaceZoneAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ReplaceZoneAiSecuritySettings successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ReplaceZoneAiSecuritySettingsOptions model + replaceZoneAiSecuritySettingsOptionsModel := new(aisecurityforappsv1.ReplaceZoneAiSecuritySettingsOptions) + replaceZoneAiSecuritySettingsOptionsModel.Enabled = core.BoolPtr(true) + replaceZoneAiSecuritySettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneAiSecuritySettings(replaceZoneAiSecuritySettingsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetApiGatewayDiscovery(getApiGatewayDiscoveryOptions *GetApiGatewayDiscoveryOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + getApiGatewayDiscoveryPath := "/v1/testString/zones/testString/api_gateway/discovery" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getApiGatewayDiscoveryPath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetApiGatewayDiscovery with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetApiGatewayDiscoveryOptions model + getApiGatewayDiscoveryOptionsModel := new(aisecurityforappsv1.GetApiGatewayDiscoveryOptions) + getApiGatewayDiscoveryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.GetApiGatewayDiscovery(getApiGatewayDiscoveryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.GetApiGatewayDiscovery(getApiGatewayDiscoveryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetApiGatewayDiscovery(getApiGatewayDiscoveryOptions *GetApiGatewayDiscoveryOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + getApiGatewayDiscoveryPath := "/v1/testString/zones/testString/api_gateway/discovery" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getApiGatewayDiscoveryPath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"anyKey": "anyValue"}}`) + })) + }) + It(`Invoke GetApiGatewayDiscovery successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the GetApiGatewayDiscoveryOptions model + getApiGatewayDiscoveryOptionsModel := new(aisecurityforappsv1.GetApiGatewayDiscoveryOptions) + getApiGatewayDiscoveryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.GetApiGatewayDiscoveryWithContext(ctx, getApiGatewayDiscoveryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.GetApiGatewayDiscovery(getApiGatewayDiscoveryOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.GetApiGatewayDiscoveryWithContext(ctx, getApiGatewayDiscoveryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getApiGatewayDiscoveryPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"anyKey": "anyValue"}}`) + })) + }) + It(`Invoke GetApiGatewayDiscovery successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.GetApiGatewayDiscovery(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetApiGatewayDiscoveryOptions model + getApiGatewayDiscoveryOptionsModel := new(aisecurityforappsv1.GetApiGatewayDiscoveryOptions) + getApiGatewayDiscoveryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.GetApiGatewayDiscovery(getApiGatewayDiscoveryOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetApiGatewayDiscovery with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetApiGatewayDiscoveryOptions model + getApiGatewayDiscoveryOptionsModel := new(aisecurityforappsv1.GetApiGatewayDiscoveryOptions) + getApiGatewayDiscoveryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.GetApiGatewayDiscovery(getApiGatewayDiscoveryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetApiGatewayDiscovery successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetApiGatewayDiscoveryOptions model + getApiGatewayDiscoveryOptionsModel := new(aisecurityforappsv1.GetApiGatewayDiscoveryOptions) + getApiGatewayDiscoveryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.GetApiGatewayDiscovery(getApiGatewayDiscoveryOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptions *ListApiGatewayDiscoveryOperationsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + listApiGatewayDiscoveryOperationsPath := "/v1/testString/zones/testString/api_gateway/discovery/operations" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listApiGatewayDiscoveryOperationsPath)) + Expect(req.Method).To(Equal("GET")) + // TODO: Add check for diff query parameter + Expect(req.URL.Query()["direction"]).To(Equal([]string{"asc"})) + Expect(req.URL.Query()["endpoint"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["order"]).To(Equal([]string{"host"})) + Expect(req.URL.Query()["origin"]).To(Equal([]string{"ML"})) + Expect(req.URL.Query()["state"]).To(Equal([]string{"review"})) + Expect(req.URL.Query()["page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + Expect(req.URL.Query()["per_page"]).To(Equal([]string{fmt.Sprint(int64(5))})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListApiGatewayDiscoveryOperations with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ListApiGatewayDiscoveryOperationsOptions model + listApiGatewayDiscoveryOperationsOptionsModel := new(aisecurityforappsv1.ListApiGatewayDiscoveryOperationsOptions) + listApiGatewayDiscoveryOperationsOptionsModel.Diff = core.BoolPtr(true) + listApiGatewayDiscoveryOperationsOptionsModel.Direction = core.StringPtr("asc") + listApiGatewayDiscoveryOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listApiGatewayDiscoveryOperationsOptionsModel.Host = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Method = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Order = core.StringPtr("host") + listApiGatewayDiscoveryOperationsOptionsModel.Origin = core.StringPtr("ML") + listApiGatewayDiscoveryOperationsOptionsModel.State = core.StringPtr("review") + listApiGatewayDiscoveryOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listApiGatewayDiscoveryOperationsOptionsModel.PerPage = core.Int64Ptr(int64(5)) + listApiGatewayDiscoveryOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptions *ListApiGatewayDiscoveryOperationsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + listApiGatewayDiscoveryOperationsPath := "/v1/testString/zones/testString/api_gateway/discovery/operations" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listApiGatewayDiscoveryOperationsPath)) + Expect(req.Method).To(Equal("GET")) + + // TODO: Add check for diff query parameter + Expect(req.URL.Query()["direction"]).To(Equal([]string{"asc"})) + Expect(req.URL.Query()["endpoint"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["order"]).To(Equal([]string{"host"})) + Expect(req.URL.Query()["origin"]).To(Equal([]string{"ML"})) + Expect(req.URL.Query()["state"]).To(Equal([]string{"review"})) + Expect(req.URL.Query()["page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + Expect(req.URL.Query()["per_page"]).To(Equal([]string{fmt.Sprint(int64(5))})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "endpoint": "/v1/messages", "host": "api.example.com", "method": "POST", "last_updated": "2024-01-01T00:00:00.000Z", "origin": ["ML"], "state": "review", "features": {"traffic_stats": {"last_updated": "2019-01-01T12:00:00.000Z", "period_seconds": 13, "requests": 8}}}], "result_info": {"count": 5, "page": 4, "per_page": 7, "total_count": 10}}`) + })) + }) + It(`Invoke ListApiGatewayDiscoveryOperations successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the ListApiGatewayDiscoveryOperationsOptions model + listApiGatewayDiscoveryOperationsOptionsModel := new(aisecurityforappsv1.ListApiGatewayDiscoveryOperationsOptions) + listApiGatewayDiscoveryOperationsOptionsModel.Diff = core.BoolPtr(true) + listApiGatewayDiscoveryOperationsOptionsModel.Direction = core.StringPtr("asc") + listApiGatewayDiscoveryOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listApiGatewayDiscoveryOperationsOptionsModel.Host = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Method = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Order = core.StringPtr("host") + listApiGatewayDiscoveryOperationsOptionsModel.Origin = core.StringPtr("ML") + listApiGatewayDiscoveryOperationsOptionsModel.State = core.StringPtr("review") + listApiGatewayDiscoveryOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listApiGatewayDiscoveryOperationsOptionsModel.PerPage = core.Int64Ptr(int64(5)) + listApiGatewayDiscoveryOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.ListApiGatewayDiscoveryOperationsWithContext(ctx, listApiGatewayDiscoveryOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.ListApiGatewayDiscoveryOperationsWithContext(ctx, listApiGatewayDiscoveryOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listApiGatewayDiscoveryOperationsPath)) + Expect(req.Method).To(Equal("GET")) + + // TODO: Add check for diff query parameter + Expect(req.URL.Query()["direction"]).To(Equal([]string{"asc"})) + Expect(req.URL.Query()["endpoint"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["order"]).To(Equal([]string{"host"})) + Expect(req.URL.Query()["origin"]).To(Equal([]string{"ML"})) + Expect(req.URL.Query()["state"]).To(Equal([]string{"review"})) + Expect(req.URL.Query()["page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + Expect(req.URL.Query()["per_page"]).To(Equal([]string{fmt.Sprint(int64(5))})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "endpoint": "/v1/messages", "host": "api.example.com", "method": "POST", "last_updated": "2024-01-01T00:00:00.000Z", "origin": ["ML"], "state": "review", "features": {"traffic_stats": {"last_updated": "2019-01-01T12:00:00.000Z", "period_seconds": 13, "requests": 8}}}], "result_info": {"count": 5, "page": 4, "per_page": 7, "total_count": 10}}`) + })) + }) + It(`Invoke ListApiGatewayDiscoveryOperations successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.ListApiGatewayDiscoveryOperations(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListApiGatewayDiscoveryOperationsOptions model + listApiGatewayDiscoveryOperationsOptionsModel := new(aisecurityforappsv1.ListApiGatewayDiscoveryOperationsOptions) + listApiGatewayDiscoveryOperationsOptionsModel.Diff = core.BoolPtr(true) + listApiGatewayDiscoveryOperationsOptionsModel.Direction = core.StringPtr("asc") + listApiGatewayDiscoveryOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listApiGatewayDiscoveryOperationsOptionsModel.Host = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Method = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Order = core.StringPtr("host") + listApiGatewayDiscoveryOperationsOptionsModel.Origin = core.StringPtr("ML") + listApiGatewayDiscoveryOperationsOptionsModel.State = core.StringPtr("review") + listApiGatewayDiscoveryOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listApiGatewayDiscoveryOperationsOptionsModel.PerPage = core.Int64Ptr(int64(5)) + listApiGatewayDiscoveryOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListApiGatewayDiscoveryOperations with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ListApiGatewayDiscoveryOperationsOptions model + listApiGatewayDiscoveryOperationsOptionsModel := new(aisecurityforappsv1.ListApiGatewayDiscoveryOperationsOptions) + listApiGatewayDiscoveryOperationsOptionsModel.Diff = core.BoolPtr(true) + listApiGatewayDiscoveryOperationsOptionsModel.Direction = core.StringPtr("asc") + listApiGatewayDiscoveryOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listApiGatewayDiscoveryOperationsOptionsModel.Host = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Method = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Order = core.StringPtr("host") + listApiGatewayDiscoveryOperationsOptionsModel.Origin = core.StringPtr("ML") + listApiGatewayDiscoveryOperationsOptionsModel.State = core.StringPtr("review") + listApiGatewayDiscoveryOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listApiGatewayDiscoveryOperationsOptionsModel.PerPage = core.Int64Ptr(int64(5)) + listApiGatewayDiscoveryOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListApiGatewayDiscoveryOperations successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ListApiGatewayDiscoveryOperationsOptions model + listApiGatewayDiscoveryOperationsOptionsModel := new(aisecurityforappsv1.ListApiGatewayDiscoveryOperationsOptions) + listApiGatewayDiscoveryOperationsOptionsModel.Diff = core.BoolPtr(true) + listApiGatewayDiscoveryOperationsOptionsModel.Direction = core.StringPtr("asc") + listApiGatewayDiscoveryOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listApiGatewayDiscoveryOperationsOptionsModel.Host = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Method = []string{"testString"} + listApiGatewayDiscoveryOperationsOptionsModel.Order = core.StringPtr("host") + listApiGatewayDiscoveryOperationsOptionsModel.Origin = core.StringPtr("ML") + listApiGatewayDiscoveryOperationsOptionsModel.State = core.StringPtr("review") + listApiGatewayDiscoveryOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listApiGatewayDiscoveryOperationsOptionsModel.PerPage = core.Int64Ptr(int64(5)) + listApiGatewayDiscoveryOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.ListApiGatewayDiscoveryOperations(listApiGatewayDiscoveryOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptions *UpdateZoneApiGatewayDiscoveryOperationOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + updateZoneApiGatewayDiscoveryOperationPath := "/v1/testString/zones/testString/api_gateway/discovery/operations" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateZoneApiGatewayDiscoveryOperationPath)) + Expect(req.Method).To(Equal("PATCH")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateZoneApiGatewayDiscoveryOperation with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the UpdateZoneApiGatewayDiscoveryOperationOptions model + updateZoneApiGatewayDiscoveryOperationOptionsModel := new(aisecurityforappsv1.UpdateZoneApiGatewayDiscoveryOperationOptions) + updateZoneApiGatewayDiscoveryOperationOptionsModel.RequestBody = map[string]interface{}{"anyKey": "anyValue"} + updateZoneApiGatewayDiscoveryOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptions *UpdateZoneApiGatewayDiscoveryOperationOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + updateZoneApiGatewayDiscoveryOperationPath := "/v1/testString/zones/testString/api_gateway/discovery/operations" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateZoneApiGatewayDiscoveryOperationPath)) + Expect(req.Method).To(Equal("PATCH")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "endpoint": "/v1/messages", "host": "api.example.com", "method": "POST", "last_updated": "2024-01-01T00:00:00.000Z", "origin": ["ML"], "state": "review", "features": {"traffic_stats": {"last_updated": "2019-01-01T12:00:00.000Z", "period_seconds": 13, "requests": 8}}}]}`) + })) + }) + It(`Invoke UpdateZoneApiGatewayDiscoveryOperation successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the UpdateZoneApiGatewayDiscoveryOperationOptions model + updateZoneApiGatewayDiscoveryOperationOptionsModel := new(aisecurityforappsv1.UpdateZoneApiGatewayDiscoveryOperationOptions) + updateZoneApiGatewayDiscoveryOperationOptionsModel.RequestBody = map[string]interface{}{"anyKey": "anyValue"} + updateZoneApiGatewayDiscoveryOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperationWithContext(ctx, updateZoneApiGatewayDiscoveryOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperationWithContext(ctx, updateZoneApiGatewayDiscoveryOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateZoneApiGatewayDiscoveryOperationPath)) + Expect(req.Method).To(Equal("PATCH")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "endpoint": "/v1/messages", "host": "api.example.com", "method": "POST", "last_updated": "2024-01-01T00:00:00.000Z", "origin": ["ML"], "state": "review", "features": {"traffic_stats": {"last_updated": "2019-01-01T12:00:00.000Z", "period_seconds": 13, "requests": 8}}}]}`) + })) + }) + It(`Invoke UpdateZoneApiGatewayDiscoveryOperation successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperation(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the UpdateZoneApiGatewayDiscoveryOperationOptions model + updateZoneApiGatewayDiscoveryOperationOptionsModel := new(aisecurityforappsv1.UpdateZoneApiGatewayDiscoveryOperationOptions) + updateZoneApiGatewayDiscoveryOperationOptionsModel.RequestBody = map[string]interface{}{"anyKey": "anyValue"} + updateZoneApiGatewayDiscoveryOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke UpdateZoneApiGatewayDiscoveryOperation with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the UpdateZoneApiGatewayDiscoveryOperationOptions model + updateZoneApiGatewayDiscoveryOperationOptionsModel := new(aisecurityforappsv1.UpdateZoneApiGatewayDiscoveryOperationOptions) + updateZoneApiGatewayDiscoveryOperationOptionsModel.RequestBody = map[string]interface{}{"anyKey": "anyValue"} + updateZoneApiGatewayDiscoveryOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke UpdateZoneApiGatewayDiscoveryOperation successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the UpdateZoneApiGatewayDiscoveryOperationOptions model + updateZoneApiGatewayDiscoveryOperationOptionsModel := new(aisecurityforappsv1.UpdateZoneApiGatewayDiscoveryOperationOptions) + updateZoneApiGatewayDiscoveryOperationOptionsModel.RequestBody = map[string]interface{}{"anyKey": "anyValue"} + updateZoneApiGatewayDiscoveryOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.UpdateZoneApiGatewayDiscoveryOperation(updateZoneApiGatewayDiscoveryOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptions *DeleteZoneApiGatewayOperationsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + deleteZoneApiGatewayOperationsPath := "/v1/testString/zones/testString/api_gateway/operations" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deleteZoneApiGatewayOperationsPath)) + Expect(req.Method).To(Equal("DELETE")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperations with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsDeleteInputItem model + apiGatewayOperationsDeleteInputItemModel := new(aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem) + apiGatewayOperationsDeleteInputItemModel.OperationID = core.StringPtr("f174e90a-fafe-4643-bbbc-4a0ed4fc8415") + + // Construct an instance of the DeleteZoneApiGatewayOperationsOptions model + deleteZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationsOptions) + deleteZoneApiGatewayOperationsOptionsModel.ApiGatewayOperationsDeleteInputItem = []aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem{*apiGatewayOperationsDeleteInputItemModel} + deleteZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptions *DeleteZoneApiGatewayOperationsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + deleteZoneApiGatewayOperationsPath := "/v1/testString/zones/testString/api_gateway/operations" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deleteZoneApiGatewayOperationsPath)) + Expect(req.Method).To(Equal("DELETE")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": "anyValue"}`) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperations successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the ApiGatewayOperationsDeleteInputItem model + apiGatewayOperationsDeleteInputItemModel := new(aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem) + apiGatewayOperationsDeleteInputItemModel.OperationID = core.StringPtr("f174e90a-fafe-4643-bbbc-4a0ed4fc8415") + + // Construct an instance of the DeleteZoneApiGatewayOperationsOptions model + deleteZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationsOptions) + deleteZoneApiGatewayOperationsOptionsModel.ApiGatewayOperationsDeleteInputItem = []aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem{*apiGatewayOperationsDeleteInputItemModel} + deleteZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperationsWithContext(ctx, deleteZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperationsWithContext(ctx, deleteZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deleteZoneApiGatewayOperationsPath)) + Expect(req.Method).To(Equal("DELETE")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": "anyValue"}`) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperations successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperations(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ApiGatewayOperationsDeleteInputItem model + apiGatewayOperationsDeleteInputItemModel := new(aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem) + apiGatewayOperationsDeleteInputItemModel.OperationID = core.StringPtr("f174e90a-fafe-4643-bbbc-4a0ed4fc8415") + + // Construct an instance of the DeleteZoneApiGatewayOperationsOptions model + deleteZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationsOptions) + deleteZoneApiGatewayOperationsOptionsModel.ApiGatewayOperationsDeleteInputItem = []aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem{*apiGatewayOperationsDeleteInputItemModel} + deleteZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke DeleteZoneApiGatewayOperations with error: Operation validation and request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsDeleteInputItem model + apiGatewayOperationsDeleteInputItemModel := new(aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem) + apiGatewayOperationsDeleteInputItemModel.OperationID = core.StringPtr("f174e90a-fafe-4643-bbbc-4a0ed4fc8415") + + // Construct an instance of the DeleteZoneApiGatewayOperationsOptions model + deleteZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationsOptions) + deleteZoneApiGatewayOperationsOptionsModel.ApiGatewayOperationsDeleteInputItem = []aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem{*apiGatewayOperationsDeleteInputItemModel} + deleteZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the DeleteZoneApiGatewayOperationsOptions model with no property values + deleteZoneApiGatewayOperationsOptionsModelNew := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperations successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsDeleteInputItem model + apiGatewayOperationsDeleteInputItemModel := new(aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem) + apiGatewayOperationsDeleteInputItemModel.OperationID = core.StringPtr("f174e90a-fafe-4643-bbbc-4a0ed4fc8415") + + // Construct an instance of the DeleteZoneApiGatewayOperationsOptions model + deleteZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationsOptions) + deleteZoneApiGatewayOperationsOptionsModel.ApiGatewayOperationsDeleteInputItem = []aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem{*apiGatewayOperationsDeleteInputItemModel} + deleteZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperations(deleteZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptions *ListZoneApiGatewayOperationsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + listZoneApiGatewayOperationsPath := "/v1/testString/zones/testString/api_gateway/operations" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listZoneApiGatewayOperationsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["endpoint"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["direction"]).To(Equal([]string{"asc"})) + Expect(req.URL.Query()["order"]).To(Equal([]string{"host"})) + Expect(req.URL.Query()["page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + Expect(req.URL.Query()["per_page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListZoneApiGatewayOperations with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ListZoneApiGatewayOperationsOptions model + listZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.ListZoneApiGatewayOperationsOptions) + listZoneApiGatewayOperationsOptionsModel.Host = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Method = []string{"GET"} + listZoneApiGatewayOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listZoneApiGatewayOperationsOptionsModel.Labels = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Direction = core.StringPtr("asc") + listZoneApiGatewayOperationsOptionsModel.Order = core.StringPtr("host") + listZoneApiGatewayOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.PerPage = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptions *ListZoneApiGatewayOperationsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + listZoneApiGatewayOperationsPath := "/v1/testString/zones/testString/api_gateway/operations" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listZoneApiGatewayOperationsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["endpoint"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["direction"]).To(Equal([]string{"asc"})) + Expect(req.URL.Query()["order"]).To(Equal([]string{"host"})) + Expect(req.URL.Query()["page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + Expect(req.URL.Query()["per_page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"operation_id": "test-fafe-4643-bbbc-example", "method": "POST", "host": "api.example.com", "endpoint": "/v1/messages", "last_updated": "2024-01-01T00:00:00.000Z"}], "result_info": {"count": 5, "page": 4, "per_page": 7, "total_count": 10}}`) + })) + }) + It(`Invoke ListZoneApiGatewayOperations successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the ListZoneApiGatewayOperationsOptions model + listZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.ListZoneApiGatewayOperationsOptions) + listZoneApiGatewayOperationsOptionsModel.Host = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Method = []string{"GET"} + listZoneApiGatewayOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listZoneApiGatewayOperationsOptionsModel.Labels = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Direction = core.StringPtr("asc") + listZoneApiGatewayOperationsOptionsModel.Order = core.StringPtr("host") + listZoneApiGatewayOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.PerPage = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.ListZoneApiGatewayOperationsWithContext(ctx, listZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.ListZoneApiGatewayOperationsWithContext(ctx, listZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listZoneApiGatewayOperationsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["endpoint"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["direction"]).To(Equal([]string{"asc"})) + Expect(req.URL.Query()["order"]).To(Equal([]string{"host"})) + Expect(req.URL.Query()["page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + Expect(req.URL.Query()["per_page"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"operation_id": "test-fafe-4643-bbbc-example", "method": "POST", "host": "api.example.com", "endpoint": "/v1/messages", "last_updated": "2024-01-01T00:00:00.000Z"}], "result_info": {"count": 5, "page": 4, "per_page": 7, "total_count": 10}}`) + })) + }) + It(`Invoke ListZoneApiGatewayOperations successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.ListZoneApiGatewayOperations(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListZoneApiGatewayOperationsOptions model + listZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.ListZoneApiGatewayOperationsOptions) + listZoneApiGatewayOperationsOptionsModel.Host = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Method = []string{"GET"} + listZoneApiGatewayOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listZoneApiGatewayOperationsOptionsModel.Labels = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Direction = core.StringPtr("asc") + listZoneApiGatewayOperationsOptionsModel.Order = core.StringPtr("host") + listZoneApiGatewayOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.PerPage = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListZoneApiGatewayOperations with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ListZoneApiGatewayOperationsOptions model + listZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.ListZoneApiGatewayOperationsOptions) + listZoneApiGatewayOperationsOptionsModel.Host = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Method = []string{"GET"} + listZoneApiGatewayOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listZoneApiGatewayOperationsOptionsModel.Labels = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Direction = core.StringPtr("asc") + listZoneApiGatewayOperationsOptionsModel.Order = core.StringPtr("host") + listZoneApiGatewayOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.PerPage = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListZoneApiGatewayOperations successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ListZoneApiGatewayOperationsOptions model + listZoneApiGatewayOperationsOptionsModel := new(aisecurityforappsv1.ListZoneApiGatewayOperationsOptions) + listZoneApiGatewayOperationsOptionsModel.Host = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Method = []string{"GET"} + listZoneApiGatewayOperationsOptionsModel.Endpoint = core.StringPtr("testString") + listZoneApiGatewayOperationsOptionsModel.Labels = []string{"testString"} + listZoneApiGatewayOperationsOptionsModel.Direction = core.StringPtr("asc") + listZoneApiGatewayOperationsOptionsModel.Order = core.StringPtr("host") + listZoneApiGatewayOperationsOptionsModel.Page = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.PerPage = core.Int64Ptr(int64(1)) + listZoneApiGatewayOperationsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.ListZoneApiGatewayOperations(listZoneApiGatewayOperationsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptions *CreateZoneApiGatewayOperationOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + createZoneApiGatewayOperationPath := "/v1/testString/zones/testString/api_gateway/operations" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createZoneApiGatewayOperationPath)) + Expect(req.Method).To(Equal("POST")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateZoneApiGatewayOperation with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperation model + apiGatewayOperationModel := new(aisecurityforappsv1.ApiGatewayOperation) + apiGatewayOperationModel.Method = core.StringPtr("POST") + apiGatewayOperationModel.Host = core.StringPtr("api.example.com") + apiGatewayOperationModel.Endpoint = core.StringPtr("/v1/messages") + + // Construct an instance of the CreateZoneApiGatewayOperationOptions model + createZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.CreateZoneApiGatewayOperationOptions) + createZoneApiGatewayOperationOptionsModel.ApiGatewayOperation = []aisecurityforappsv1.ApiGatewayOperation{*apiGatewayOperationModel} + createZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptions *CreateZoneApiGatewayOperationOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + createZoneApiGatewayOperationPath := "/v1/testString/zones/testString/api_gateway/operations" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createZoneApiGatewayOperationPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "method": "POST", "host": "api.example.com", "endpoint": "/v1/messages"}]}`) + })) + }) + It(`Invoke CreateZoneApiGatewayOperation successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the ApiGatewayOperation model + apiGatewayOperationModel := new(aisecurityforappsv1.ApiGatewayOperation) + apiGatewayOperationModel.Method = core.StringPtr("POST") + apiGatewayOperationModel.Host = core.StringPtr("api.example.com") + apiGatewayOperationModel.Endpoint = core.StringPtr("/v1/messages") + + // Construct an instance of the CreateZoneApiGatewayOperationOptions model + createZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.CreateZoneApiGatewayOperationOptions) + createZoneApiGatewayOperationOptionsModel.ApiGatewayOperation = []aisecurityforappsv1.ApiGatewayOperation{*apiGatewayOperationModel} + createZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.CreateZoneApiGatewayOperationWithContext(ctx, createZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.CreateZoneApiGatewayOperationWithContext(ctx, createZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createZoneApiGatewayOperationPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "method": "POST", "host": "api.example.com", "endpoint": "/v1/messages"}]}`) + })) + }) + It(`Invoke CreateZoneApiGatewayOperation successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.CreateZoneApiGatewayOperation(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ApiGatewayOperation model + apiGatewayOperationModel := new(aisecurityforappsv1.ApiGatewayOperation) + apiGatewayOperationModel.Method = core.StringPtr("POST") + apiGatewayOperationModel.Host = core.StringPtr("api.example.com") + apiGatewayOperationModel.Endpoint = core.StringPtr("/v1/messages") + + // Construct an instance of the CreateZoneApiGatewayOperationOptions model + createZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.CreateZoneApiGatewayOperationOptions) + createZoneApiGatewayOperationOptionsModel.ApiGatewayOperation = []aisecurityforappsv1.ApiGatewayOperation{*apiGatewayOperationModel} + createZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreateZoneApiGatewayOperation with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperation model + apiGatewayOperationModel := new(aisecurityforappsv1.ApiGatewayOperation) + apiGatewayOperationModel.Method = core.StringPtr("POST") + apiGatewayOperationModel.Host = core.StringPtr("api.example.com") + apiGatewayOperationModel.Endpoint = core.StringPtr("/v1/messages") + + // Construct an instance of the CreateZoneApiGatewayOperationOptions model + createZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.CreateZoneApiGatewayOperationOptions) + createZoneApiGatewayOperationOptionsModel.ApiGatewayOperation = []aisecurityforappsv1.ApiGatewayOperation{*apiGatewayOperationModel} + createZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke CreateZoneApiGatewayOperation successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperation model + apiGatewayOperationModel := new(aisecurityforappsv1.ApiGatewayOperation) + apiGatewayOperationModel.Method = core.StringPtr("POST") + apiGatewayOperationModel.Host = core.StringPtr("api.example.com") + apiGatewayOperationModel.Endpoint = core.StringPtr("/v1/messages") + + // Construct an instance of the CreateZoneApiGatewayOperationOptions model + createZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.CreateZoneApiGatewayOperationOptions) + createZoneApiGatewayOperationOptionsModel.ApiGatewayOperation = []aisecurityforappsv1.ApiGatewayOperation{*apiGatewayOperationModel} + createZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.CreateZoneApiGatewayOperation(createZoneApiGatewayOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateApiGatewayOperationItem(createApiGatewayOperationItemOptions *CreateApiGatewayOperationItemOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + createApiGatewayOperationItemPath := "/v1/testString/zones/testString/api_gateway/operations/item" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createApiGatewayOperationItemPath)) + Expect(req.Method).To(Equal("POST")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateApiGatewayOperationItem with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the CreateApiGatewayOperationItemOptions model + createApiGatewayOperationItemOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationItemOptions) + createApiGatewayOperationItemOptionsModel.Method = core.StringPtr("POST") + createApiGatewayOperationItemOptionsModel.Host = core.StringPtr("api.example.com") + createApiGatewayOperationItemOptionsModel.Endpoint = core.StringPtr("/v1/messages") + createApiGatewayOperationItemOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationItem(createApiGatewayOperationItemOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.CreateApiGatewayOperationItem(createApiGatewayOperationItemOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateApiGatewayOperationItem(createApiGatewayOperationItemOptions *CreateApiGatewayOperationItemOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + createApiGatewayOperationItemPath := "/v1/testString/zones/testString/api_gateway/operations/item" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createApiGatewayOperationItemPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "method": "POST", "host": "api.example.com", "endpoint": "/v1/messages"}}`) + })) + }) + It(`Invoke CreateApiGatewayOperationItem successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the CreateApiGatewayOperationItemOptions model + createApiGatewayOperationItemOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationItemOptions) + createApiGatewayOperationItemOptionsModel.Method = core.StringPtr("POST") + createApiGatewayOperationItemOptionsModel.Host = core.StringPtr("api.example.com") + createApiGatewayOperationItemOptionsModel.Endpoint = core.StringPtr("/v1/messages") + createApiGatewayOperationItemOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationItemWithContext(ctx, createApiGatewayOperationItemOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationItem(createApiGatewayOperationItemOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.CreateApiGatewayOperationItemWithContext(ctx, createApiGatewayOperationItemOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createApiGatewayOperationItemPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "method": "POST", "host": "api.example.com", "endpoint": "/v1/messages"}}`) + })) + }) + It(`Invoke CreateApiGatewayOperationItem successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationItem(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the CreateApiGatewayOperationItemOptions model + createApiGatewayOperationItemOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationItemOptions) + createApiGatewayOperationItemOptionsModel.Method = core.StringPtr("POST") + createApiGatewayOperationItemOptionsModel.Host = core.StringPtr("api.example.com") + createApiGatewayOperationItemOptionsModel.Endpoint = core.StringPtr("/v1/messages") + createApiGatewayOperationItemOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.CreateApiGatewayOperationItem(createApiGatewayOperationItemOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreateApiGatewayOperationItem with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the CreateApiGatewayOperationItemOptions model + createApiGatewayOperationItemOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationItemOptions) + createApiGatewayOperationItemOptionsModel.Method = core.StringPtr("POST") + createApiGatewayOperationItemOptionsModel.Host = core.StringPtr("api.example.com") + createApiGatewayOperationItemOptionsModel.Endpoint = core.StringPtr("/v1/messages") + createApiGatewayOperationItemOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationItem(createApiGatewayOperationItemOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke CreateApiGatewayOperationItem successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the CreateApiGatewayOperationItemOptions model + createApiGatewayOperationItemOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationItemOptions) + createApiGatewayOperationItemOptionsModel.Method = core.StringPtr("POST") + createApiGatewayOperationItemOptionsModel.Host = core.StringPtr("api.example.com") + createApiGatewayOperationItemOptionsModel.Endpoint = core.StringPtr("/v1/messages") + createApiGatewayOperationItemOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationItem(createApiGatewayOperationItemOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptions *ReplaceZoneApiGatewayOperationLabelsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + replaceZoneApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/labels" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ReplaceZoneApiGatewayOperationLabels with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the ReplaceZoneApiGatewayOperationLabelsOptions model + replaceZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.ReplaceZoneApiGatewayOperationLabelsOptions) + replaceZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + replaceZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptions *ReplaceZoneApiGatewayOperationLabelsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + replaceZoneApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/labels" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "labels": [{"name": "cf-llm", "source": "managed"}]}]}`) + })) + }) + It(`Invoke ReplaceZoneApiGatewayOperationLabels successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the ReplaceZoneApiGatewayOperationLabelsOptions model + replaceZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.ReplaceZoneApiGatewayOperationLabelsOptions) + replaceZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + replaceZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabelsWithContext(ctx, replaceZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabelsWithContext(ctx, replaceZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "labels": [{"name": "cf-llm", "source": "managed"}]}]}`) + })) + }) + It(`Invoke ReplaceZoneApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabels(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the ReplaceZoneApiGatewayOperationLabelsOptions model + replaceZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.ReplaceZoneApiGatewayOperationLabelsOptions) + replaceZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + replaceZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ReplaceZoneApiGatewayOperationLabels with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the ReplaceZoneApiGatewayOperationLabelsOptions model + replaceZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.ReplaceZoneApiGatewayOperationLabelsOptions) + replaceZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + replaceZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ReplaceZoneApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the ReplaceZoneApiGatewayOperationLabelsOptions model + replaceZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.ReplaceZoneApiGatewayOperationLabelsOptions) + replaceZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + replaceZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + replaceZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.ReplaceZoneApiGatewayOperationLabels(replaceZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptions *DeleteZoneApiGatewayOperationLabelsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + deleteZoneApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/labels" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deleteZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("DELETE")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperationLabels with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude model + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelector model + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector) + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel.Include = apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputUser model + apiGatewayOperationsLabelsBulkDeleteInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputUser) + apiGatewayOperationsLabelsBulkDeleteInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputManaged model + apiGatewayOperationsLabelsBulkDeleteInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputManaged) + apiGatewayOperationsLabelsBulkDeleteInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the DeleteZoneApiGatewayOperationLabelsOptions model + deleteZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationLabelsOptions) + deleteZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkDeleteInputSelectorModel + deleteZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkDeleteInputUserModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkDeleteInputManagedModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptions *DeleteZoneApiGatewayOperationLabelsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + deleteZoneApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/labels" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deleteZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("DELETE")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": "anyValue"}`) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperationLabels successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude model + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelector model + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector) + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel.Include = apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputUser model + apiGatewayOperationsLabelsBulkDeleteInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputUser) + apiGatewayOperationsLabelsBulkDeleteInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputManaged model + apiGatewayOperationsLabelsBulkDeleteInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputManaged) + apiGatewayOperationsLabelsBulkDeleteInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the DeleteZoneApiGatewayOperationLabelsOptions model + deleteZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationLabelsOptions) + deleteZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkDeleteInputSelectorModel + deleteZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkDeleteInputUserModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkDeleteInputManagedModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabelsWithContext(ctx, deleteZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabelsWithContext(ctx, deleteZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deleteZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("DELETE")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": "anyValue"}`) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabels(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude model + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelector model + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector) + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel.Include = apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputUser model + apiGatewayOperationsLabelsBulkDeleteInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputUser) + apiGatewayOperationsLabelsBulkDeleteInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputManaged model + apiGatewayOperationsLabelsBulkDeleteInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputManaged) + apiGatewayOperationsLabelsBulkDeleteInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the DeleteZoneApiGatewayOperationLabelsOptions model + deleteZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationLabelsOptions) + deleteZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkDeleteInputSelectorModel + deleteZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkDeleteInputUserModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkDeleteInputManagedModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke DeleteZoneApiGatewayOperationLabels with error: Operation validation and request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude model + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelector model + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector) + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel.Include = apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputUser model + apiGatewayOperationsLabelsBulkDeleteInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputUser) + apiGatewayOperationsLabelsBulkDeleteInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputManaged model + apiGatewayOperationsLabelsBulkDeleteInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputManaged) + apiGatewayOperationsLabelsBulkDeleteInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the DeleteZoneApiGatewayOperationLabelsOptions model + deleteZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationLabelsOptions) + deleteZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkDeleteInputSelectorModel + deleteZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkDeleteInputUserModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkDeleteInputManagedModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the DeleteZoneApiGatewayOperationLabelsOptions model with no property values + deleteZoneApiGatewayOperationLabelsOptionsModelNew := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationLabelsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude model + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelector model + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector) + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel.Include = apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputUser model + apiGatewayOperationsLabelsBulkDeleteInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputUser) + apiGatewayOperationsLabelsBulkDeleteInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputManaged model + apiGatewayOperationsLabelsBulkDeleteInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputManaged) + apiGatewayOperationsLabelsBulkDeleteInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the DeleteZoneApiGatewayOperationLabelsOptions model + deleteZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationLabelsOptions) + deleteZoneApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkDeleteInputSelectorModel + deleteZoneApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkDeleteInputUserModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkDeleteInputManagedModel + deleteZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperationLabels(deleteZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptions *UpdateApiGatewayOperationLabelsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + updateApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/labels" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("POST")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateApiGatewayOperationLabels with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the UpdateApiGatewayOperationLabelsOptions model + updateApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UpdateApiGatewayOperationLabelsOptions) + updateApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + updateApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + updateApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + updateApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptions *UpdateApiGatewayOperationLabelsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + updateApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/labels" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "labels": [{"name": "cf-llm", "source": "managed"}]}]}`) + })) + }) + It(`Invoke UpdateApiGatewayOperationLabels successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the UpdateApiGatewayOperationLabelsOptions model + updateApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UpdateApiGatewayOperationLabelsOptions) + updateApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + updateApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + updateApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + updateApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.UpdateApiGatewayOperationLabelsWithContext(ctx, updateApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.UpdateApiGatewayOperationLabelsWithContext(ctx, updateApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "labels": [{"name": "cf-llm", "source": "managed"}]}]}`) + })) + }) + It(`Invoke UpdateApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.UpdateApiGatewayOperationLabels(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the UpdateApiGatewayOperationLabelsOptions model + updateApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UpdateApiGatewayOperationLabelsOptions) + updateApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + updateApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + updateApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + updateApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke UpdateApiGatewayOperationLabels with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the UpdateApiGatewayOperationLabelsOptions model + updateApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UpdateApiGatewayOperationLabelsOptions) + updateApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + updateApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + updateApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + updateApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke UpdateApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + + // Construct an instance of the UpdateApiGatewayOperationLabelsOptions model + updateApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UpdateApiGatewayOperationLabelsOptions) + updateApiGatewayOperationLabelsOptionsModel.Selector = apiGatewayOperationsLabelsBulkInputSelectorModel + updateApiGatewayOperationLabelsOptionsModel.User = apiGatewayOperationsLabelsBulkInputUserModel + updateApiGatewayOperationLabelsOptionsModel.Managed = apiGatewayOperationsLabelsBulkInputManagedModel + updateApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.UpdateApiGatewayOperationLabels(updateApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptions *CreateApiGatewayOperationLabelsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + createApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/testString/labels" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("POST")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateApiGatewayOperationLabels with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the CreateApiGatewayOperationLabelsOptions model + createApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationLabelsOptions) + createApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + createApiGatewayOperationLabelsOptionsModel.User = []string{} + createApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + createApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptions *CreateApiGatewayOperationLabelsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + createApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/testString/labels" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "labels": [{"name": "cf-llm", "source": "managed"}]}}`) + })) + }) + It(`Invoke CreateApiGatewayOperationLabels successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the CreateApiGatewayOperationLabelsOptions model + createApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationLabelsOptions) + createApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + createApiGatewayOperationLabelsOptionsModel.User = []string{} + createApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + createApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationLabelsWithContext(ctx, createApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.CreateApiGatewayOperationLabelsWithContext(ctx, createApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "labels": [{"name": "cf-llm", "source": "managed"}]}}`) + })) + }) + It(`Invoke CreateApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationLabels(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the CreateApiGatewayOperationLabelsOptions model + createApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationLabelsOptions) + createApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + createApiGatewayOperationLabelsOptionsModel.User = []string{} + createApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + createApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreateApiGatewayOperationLabels with error: Operation validation and request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the CreateApiGatewayOperationLabelsOptions model + createApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationLabelsOptions) + createApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + createApiGatewayOperationLabelsOptionsModel.User = []string{} + createApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + createApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the CreateApiGatewayOperationLabelsOptions model with no property values + createApiGatewayOperationLabelsOptionsModelNew := new(aisecurityforappsv1.CreateApiGatewayOperationLabelsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = aiSecurityForAppsService.CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke CreateApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the CreateApiGatewayOperationLabelsOptions model + createApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.CreateApiGatewayOperationLabelsOptions) + createApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + createApiGatewayOperationLabelsOptionsModel.User = []string{} + createApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + createApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.CreateApiGatewayOperationLabels(createApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptions *SetZoneApiGatewayOperationLabelsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + setZoneApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/testString/labels" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(setZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke SetZoneApiGatewayOperationLabels with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the SetZoneApiGatewayOperationLabelsOptions model + setZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.SetZoneApiGatewayOperationLabelsOptions) + setZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + setZoneApiGatewayOperationLabelsOptionsModel.User = []string{} + setZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + setZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptions *SetZoneApiGatewayOperationLabelsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + setZoneApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/testString/labels" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(setZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "labels": [{"name": "cf-llm", "source": "managed"}]}}`) + })) + }) + It(`Invoke SetZoneApiGatewayOperationLabels successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the SetZoneApiGatewayOperationLabelsOptions model + setZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.SetZoneApiGatewayOperationLabelsOptions) + setZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + setZoneApiGatewayOperationLabelsOptionsModel.User = []string{} + setZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + setZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.SetZoneApiGatewayOperationLabelsWithContext(ctx, setZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.SetZoneApiGatewayOperationLabelsWithContext(ctx, setZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(setZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "labels": [{"name": "cf-llm", "source": "managed"}]}}`) + })) + }) + It(`Invoke SetZoneApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.SetZoneApiGatewayOperationLabels(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the SetZoneApiGatewayOperationLabelsOptions model + setZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.SetZoneApiGatewayOperationLabelsOptions) + setZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + setZoneApiGatewayOperationLabelsOptionsModel.User = []string{} + setZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + setZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke SetZoneApiGatewayOperationLabels with error: Operation validation and request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the SetZoneApiGatewayOperationLabelsOptions model + setZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.SetZoneApiGatewayOperationLabelsOptions) + setZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + setZoneApiGatewayOperationLabelsOptionsModel.User = []string{} + setZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + setZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the SetZoneApiGatewayOperationLabelsOptions model with no property values + setZoneApiGatewayOperationLabelsOptionsModelNew := new(aisecurityforappsv1.SetZoneApiGatewayOperationLabelsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = aiSecurityForAppsService.SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke SetZoneApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the SetZoneApiGatewayOperationLabelsOptions model + setZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.SetZoneApiGatewayOperationLabelsOptions) + setZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + setZoneApiGatewayOperationLabelsOptionsModel.User = []string{} + setZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"cf-llm"} + setZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.SetZoneApiGatewayOperationLabels(setZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptions *UnsetZoneApiGatewayOperationLabelsOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + unsetZoneApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/testString/labels" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(unsetZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("DELETE")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke UnsetZoneApiGatewayOperationLabels with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the UnsetZoneApiGatewayOperationLabelsOptions model + unsetZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UnsetZoneApiGatewayOperationLabelsOptions) + unsetZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + unsetZoneApiGatewayOperationLabelsOptionsModel.User = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptions *UnsetZoneApiGatewayOperationLabelsOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + unsetZoneApiGatewayOperationLabelsPath := "/v1/testString/zones/testString/api_gateway/operations/testString/labels" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(unsetZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("DELETE")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": "anyValue"}`) + })) + }) + It(`Invoke UnsetZoneApiGatewayOperationLabels successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the UnsetZoneApiGatewayOperationLabelsOptions model + unsetZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UnsetZoneApiGatewayOperationLabelsOptions) + unsetZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + unsetZoneApiGatewayOperationLabelsOptionsModel.User = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabelsWithContext(ctx, unsetZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabelsWithContext(ctx, unsetZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(unsetZoneApiGatewayOperationLabelsPath)) + Expect(req.Method).To(Equal("DELETE")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": "anyValue"}`) + })) + }) + It(`Invoke UnsetZoneApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabels(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the UnsetZoneApiGatewayOperationLabelsOptions model + unsetZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UnsetZoneApiGatewayOperationLabelsOptions) + unsetZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + unsetZoneApiGatewayOperationLabelsOptionsModel.User = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke UnsetZoneApiGatewayOperationLabels with error: Operation validation and request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the UnsetZoneApiGatewayOperationLabelsOptions model + unsetZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UnsetZoneApiGatewayOperationLabelsOptions) + unsetZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + unsetZoneApiGatewayOperationLabelsOptionsModel.User = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the UnsetZoneApiGatewayOperationLabelsOptions model with no property values + unsetZoneApiGatewayOperationLabelsOptionsModelNew := new(aisecurityforappsv1.UnsetZoneApiGatewayOperationLabelsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke UnsetZoneApiGatewayOperationLabels successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the UnsetZoneApiGatewayOperationLabelsOptions model + unsetZoneApiGatewayOperationLabelsOptionsModel := new(aisecurityforappsv1.UnsetZoneApiGatewayOperationLabelsOptions) + unsetZoneApiGatewayOperationLabelsOptionsModel.OperationID = core.StringPtr("testString") + unsetZoneApiGatewayOperationLabelsOptionsModel.User = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Managed = []string{"testString"} + unsetZoneApiGatewayOperationLabelsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.UnsetZoneApiGatewayOperationLabels(unsetZoneApiGatewayOperationLabelsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptions *GetZoneApiGatewayOperationOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + getZoneApiGatewayOperationPath := "/v1/testString/zones/testString/api_gateway/operations/testString" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getZoneApiGatewayOperationPath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetZoneApiGatewayOperation with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetZoneApiGatewayOperationOptions model + getZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.GetZoneApiGatewayOperationOptions) + getZoneApiGatewayOperationOptionsModel.OperationID = core.StringPtr("testString") + getZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptions *GetZoneApiGatewayOperationOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + getZoneApiGatewayOperationPath := "/v1/testString/zones/testString/api_gateway/operations/testString" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getZoneApiGatewayOperationPath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "method": "POST", "host": "api.example.com", "endpoint": "/v1/messages"}}`) + })) + }) + It(`Invoke GetZoneApiGatewayOperation successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the GetZoneApiGatewayOperationOptions model + getZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.GetZoneApiGatewayOperationOptions) + getZoneApiGatewayOperationOptionsModel.OperationID = core.StringPtr("testString") + getZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.GetZoneApiGatewayOperationWithContext(ctx, getZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.GetZoneApiGatewayOperationWithContext(ctx, getZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getZoneApiGatewayOperationPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"operation_id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415", "method": "POST", "host": "api.example.com", "endpoint": "/v1/messages"}}`) + })) + }) + It(`Invoke GetZoneApiGatewayOperation successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.GetZoneApiGatewayOperation(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetZoneApiGatewayOperationOptions model + getZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.GetZoneApiGatewayOperationOptions) + getZoneApiGatewayOperationOptionsModel.OperationID = core.StringPtr("testString") + getZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetZoneApiGatewayOperation with error: Operation validation and request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetZoneApiGatewayOperationOptions model + getZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.GetZoneApiGatewayOperationOptions) + getZoneApiGatewayOperationOptionsModel.OperationID = core.StringPtr("testString") + getZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the GetZoneApiGatewayOperationOptions model with no property values + getZoneApiGatewayOperationOptionsModelNew := new(aisecurityforappsv1.GetZoneApiGatewayOperationOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = aiSecurityForAppsService.GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetZoneApiGatewayOperation successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetZoneApiGatewayOperationOptions model + getZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.GetZoneApiGatewayOperationOptions) + getZoneApiGatewayOperationOptionsModel.OperationID = core.StringPtr("testString") + getZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.GetZoneApiGatewayOperation(getZoneApiGatewayOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteZoneApiGatewayOperation(deleteZoneApiGatewayOperationOptions *DeleteZoneApiGatewayOperationOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + deleteZoneApiGatewayOperationPath := "/v1/testString/zones/testString/api_gateway/operations/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deleteZoneApiGatewayOperationPath)) + Expect(req.Method).To(Equal("DELETE")) + + res.WriteHeader(204) + })) + }) + It(`Invoke DeleteZoneApiGatewayOperation successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperation(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeleteZoneApiGatewayOperationOptions model + deleteZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationOptions) + deleteZoneApiGatewayOperationOptionsModel.OperationID = core.StringPtr("testString") + deleteZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperation(deleteZoneApiGatewayOperationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeleteZoneApiGatewayOperation with error: Operation validation and request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the DeleteZoneApiGatewayOperationOptions model + deleteZoneApiGatewayOperationOptionsModel := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationOptions) + deleteZoneApiGatewayOperationOptionsModel.OperationID = core.StringPtr("testString") + deleteZoneApiGatewayOperationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := aiSecurityForAppsService.DeleteZoneApiGatewayOperation(deleteZoneApiGatewayOperationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeleteZoneApiGatewayOperationOptions model with no property values + deleteZoneApiGatewayOperationOptionsModelNew := new(aisecurityforappsv1.DeleteZoneApiGatewayOperationOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = aiSecurityForAppsService.DeleteZoneApiGatewayOperation(deleteZoneApiGatewayOperationOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetApiGatewaySchemas(getApiGatewaySchemasOptions *GetApiGatewaySchemasOptions) - Operation response error`, func() { + crn := "testString" + zoneIdentifier := "testString" + getApiGatewaySchemasPath := "/v1/testString/zones/testString/api_gateway/schemas" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getApiGatewaySchemasPath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetApiGatewaySchemas with error: Operation response processing error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetApiGatewaySchemasOptions model + getApiGatewaySchemasOptionsModel := new(aisecurityforappsv1.GetApiGatewaySchemasOptions) + getApiGatewaySchemasOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := aiSecurityForAppsService.GetApiGatewaySchemas(getApiGatewaySchemasOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + aiSecurityForAppsService.EnableRetries(0, 0) + result, response, operationErr = aiSecurityForAppsService.GetApiGatewaySchemas(getApiGatewaySchemasOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetApiGatewaySchemas(getApiGatewaySchemasOptions *GetApiGatewaySchemasOptions)`, func() { + crn := "testString" + zoneIdentifier := "testString" + getApiGatewaySchemasPath := "/v1/testString/zones/testString/api_gateway/schemas" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getApiGatewaySchemasPath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"anyKey": "anyValue"}}`) + })) + }) + It(`Invoke GetApiGatewaySchemas successfully with retries`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + aiSecurityForAppsService.EnableRetries(0, 0) + + // Construct an instance of the GetApiGatewaySchemasOptions model + getApiGatewaySchemasOptionsModel := new(aisecurityforappsv1.GetApiGatewaySchemasOptions) + getApiGatewaySchemasOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := aiSecurityForAppsService.GetApiGatewaySchemasWithContext(ctx, getApiGatewaySchemasOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + aiSecurityForAppsService.DisableRetries() + result, response, operationErr := aiSecurityForAppsService.GetApiGatewaySchemas(getApiGatewaySchemasOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = aiSecurityForAppsService.GetApiGatewaySchemasWithContext(ctx, getApiGatewaySchemasOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getApiGatewaySchemasPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": {"anyKey": "anyValue"}}`) + })) + }) + It(`Invoke GetApiGatewaySchemas successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := aiSecurityForAppsService.GetApiGatewaySchemas(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetApiGatewaySchemasOptions model + getApiGatewaySchemasOptionsModel := new(aisecurityforappsv1.GetApiGatewaySchemasOptions) + getApiGatewaySchemasOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = aiSecurityForAppsService.GetApiGatewaySchemas(getApiGatewaySchemasOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetApiGatewaySchemas with error: Operation request error`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetApiGatewaySchemasOptions model + getApiGatewaySchemasOptionsModel := new(aisecurityforappsv1.GetApiGatewaySchemasOptions) + getApiGatewaySchemasOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := aiSecurityForAppsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := aiSecurityForAppsService.GetApiGatewaySchemas(getApiGatewaySchemasOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetApiGatewaySchemas successfully`, func() { + aiSecurityForAppsService, serviceErr := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + Expect(serviceErr).To(BeNil()) + Expect(aiSecurityForAppsService).ToNot(BeNil()) + + // Construct an instance of the GetApiGatewaySchemasOptions model + getApiGatewaySchemasOptionsModel := new(aisecurityforappsv1.GetApiGatewaySchemasOptions) + getApiGatewaySchemasOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := aiSecurityForAppsService.GetApiGatewaySchemas(getApiGatewaySchemasOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`Model constructor tests`, func() { + Context(`Using a service client instance`, func() { + crn := "testString" + zoneIdentifier := "testString" + aiSecurityForAppsService, _ := aisecurityforappsv1.NewAiSecurityForAppsV1(&aisecurityforappsv1.AiSecurityForAppsV1Options{ + URL: "http://aisecurityforappsv1modelgenerator.com", + Authenticator: &core.NoAuthAuthenticator{}, + Crn: core.StringPtr(crn), + ZoneIdentifier: core.StringPtr(zoneIdentifier), + }) + It(`Invoke NewApiGatewayOperationsDeleteInputItem successfully`, func() { + operationID := "f174e90a-fafe-4643-bbbc-4a0ed4fc8415" + _model, err := aiSecurityForAppsService.NewApiGatewayOperationsDeleteInputItem(operationID) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewApiGatewayOperationsLabelsBulkDeleteInputSelector successfully`, func() { + var include *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude = nil + _, err := aiSecurityForAppsService.NewApiGatewayOperationsLabelsBulkDeleteInputSelector(include) + Expect(err).ToNot(BeNil()) + }) + It(`Invoke NewApiGatewayOperationsLabelsBulkInputManaged successfully`, func() { + labels := []string{"testString"} + _model, err := aiSecurityForAppsService.NewApiGatewayOperationsLabelsBulkInputManaged(labels) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewApiGatewayOperationsLabelsBulkInputSelector successfully`, func() { + var include *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude = nil + _, err := aiSecurityForAppsService.NewApiGatewayOperationsLabelsBulkInputSelector(include) + Expect(err).ToNot(BeNil()) + }) + It(`Invoke NewApiGatewayOperationsLabelsBulkInputUser successfully`, func() { + labels := []string{"testString"} + _model, err := aiSecurityForAppsService.NewApiGatewayOperationsLabelsBulkInputUser(labels) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewCreateApiGatewayOperationItemOptions successfully`, func() { + // Construct an instance of the CreateApiGatewayOperationItemOptions model + createApiGatewayOperationItemOptionsModel := aiSecurityForAppsService.NewCreateApiGatewayOperationItemOptions() + createApiGatewayOperationItemOptionsModel.SetMethod("POST") + createApiGatewayOperationItemOptionsModel.SetHost("api.example.com") + createApiGatewayOperationItemOptionsModel.SetEndpoint("/v1/messages") + createApiGatewayOperationItemOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createApiGatewayOperationItemOptionsModel).ToNot(BeNil()) + Expect(createApiGatewayOperationItemOptionsModel.Method).To(Equal(core.StringPtr("POST"))) + Expect(createApiGatewayOperationItemOptionsModel.Host).To(Equal(core.StringPtr("api.example.com"))) + Expect(createApiGatewayOperationItemOptionsModel.Endpoint).To(Equal(core.StringPtr("/v1/messages"))) + Expect(createApiGatewayOperationItemOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewCreateApiGatewayOperationLabelsOptions successfully`, func() { + // Construct an instance of the CreateApiGatewayOperationLabelsOptions model + operationID := "testString" + createApiGatewayOperationLabelsOptionsModel := aiSecurityForAppsService.NewCreateApiGatewayOperationLabelsOptions(operationID) + createApiGatewayOperationLabelsOptionsModel.SetOperationID("testString") + createApiGatewayOperationLabelsOptionsModel.SetUser([]string{}) + createApiGatewayOperationLabelsOptionsModel.SetManaged([]string{"cf-llm"}) + createApiGatewayOperationLabelsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createApiGatewayOperationLabelsOptionsModel).ToNot(BeNil()) + Expect(createApiGatewayOperationLabelsOptionsModel.OperationID).To(Equal(core.StringPtr("testString"))) + Expect(createApiGatewayOperationLabelsOptionsModel.User).To(Equal([]string{})) + Expect(createApiGatewayOperationLabelsOptionsModel.Managed).To(Equal([]string{"cf-llm"})) + Expect(createApiGatewayOperationLabelsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewCreateZoneApiGatewayOperationOptions successfully`, func() { + // Construct an instance of the ApiGatewayOperation model + apiGatewayOperationModel := new(aisecurityforappsv1.ApiGatewayOperation) + Expect(apiGatewayOperationModel).ToNot(BeNil()) + apiGatewayOperationModel.Method = core.StringPtr("POST") + apiGatewayOperationModel.Host = core.StringPtr("api.example.com") + apiGatewayOperationModel.Endpoint = core.StringPtr("/v1/messages") + Expect(apiGatewayOperationModel.Method).To(Equal(core.StringPtr("POST"))) + Expect(apiGatewayOperationModel.Host).To(Equal(core.StringPtr("api.example.com"))) + Expect(apiGatewayOperationModel.Endpoint).To(Equal(core.StringPtr("/v1/messages"))) + + // Construct an instance of the CreateZoneApiGatewayOperationOptions model + createZoneApiGatewayOperationOptionsModel := aiSecurityForAppsService.NewCreateZoneApiGatewayOperationOptions() + createZoneApiGatewayOperationOptionsModel.SetApiGatewayOperation([]aisecurityforappsv1.ApiGatewayOperation{*apiGatewayOperationModel}) + createZoneApiGatewayOperationOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createZoneApiGatewayOperationOptionsModel).ToNot(BeNil()) + Expect(createZoneApiGatewayOperationOptionsModel.ApiGatewayOperation).To(Equal([]aisecurityforappsv1.ApiGatewayOperation{*apiGatewayOperationModel})) + Expect(createZoneApiGatewayOperationOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteZoneApiGatewayOperationLabelsOptions successfully`, func() { + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude model + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + Expect(apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + Expect(apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel.OperationIds).To(Equal([]string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"})) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputSelector model + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector) + Expect(apiGatewayOperationsLabelsBulkDeleteInputSelectorModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkDeleteInputSelectorModel.Include = apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel + Expect(apiGatewayOperationsLabelsBulkDeleteInputSelectorModel.Include).To(Equal(apiGatewayOperationsLabelsBulkDeleteInputSelectorIncludeModel)) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputUser model + apiGatewayOperationsLabelsBulkDeleteInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputUser) + Expect(apiGatewayOperationsLabelsBulkDeleteInputUserModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkDeleteInputUserModel.Labels = []string{"testString"} + Expect(apiGatewayOperationsLabelsBulkDeleteInputUserModel.Labels).To(Equal([]string{"testString"})) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkDeleteInputManaged model + apiGatewayOperationsLabelsBulkDeleteInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputManaged) + Expect(apiGatewayOperationsLabelsBulkDeleteInputManagedModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkDeleteInputManagedModel.Labels = []string{"testString"} + Expect(apiGatewayOperationsLabelsBulkDeleteInputManagedModel.Labels).To(Equal([]string{"testString"})) + + // Construct an instance of the DeleteZoneApiGatewayOperationLabelsOptions model + var deleteZoneApiGatewayOperationLabelsOptionsSelector *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector = nil + deleteZoneApiGatewayOperationLabelsOptionsModel := aiSecurityForAppsService.NewDeleteZoneApiGatewayOperationLabelsOptions(deleteZoneApiGatewayOperationLabelsOptionsSelector) + deleteZoneApiGatewayOperationLabelsOptionsModel.SetSelector(apiGatewayOperationsLabelsBulkDeleteInputSelectorModel) + deleteZoneApiGatewayOperationLabelsOptionsModel.SetUser(apiGatewayOperationsLabelsBulkDeleteInputUserModel) + deleteZoneApiGatewayOperationLabelsOptionsModel.SetManaged(apiGatewayOperationsLabelsBulkDeleteInputManagedModel) + deleteZoneApiGatewayOperationLabelsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteZoneApiGatewayOperationLabelsOptionsModel).ToNot(BeNil()) + Expect(deleteZoneApiGatewayOperationLabelsOptionsModel.Selector).To(Equal(apiGatewayOperationsLabelsBulkDeleteInputSelectorModel)) + Expect(deleteZoneApiGatewayOperationLabelsOptionsModel.User).To(Equal(apiGatewayOperationsLabelsBulkDeleteInputUserModel)) + Expect(deleteZoneApiGatewayOperationLabelsOptionsModel.Managed).To(Equal(apiGatewayOperationsLabelsBulkDeleteInputManagedModel)) + Expect(deleteZoneApiGatewayOperationLabelsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteZoneApiGatewayOperationOptions successfully`, func() { + // Construct an instance of the DeleteZoneApiGatewayOperationOptions model + operationID := "testString" + deleteZoneApiGatewayOperationOptionsModel := aiSecurityForAppsService.NewDeleteZoneApiGatewayOperationOptions(operationID) + deleteZoneApiGatewayOperationOptionsModel.SetOperationID("testString") + deleteZoneApiGatewayOperationOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteZoneApiGatewayOperationOptionsModel).ToNot(BeNil()) + Expect(deleteZoneApiGatewayOperationOptionsModel.OperationID).To(Equal(core.StringPtr("testString"))) + Expect(deleteZoneApiGatewayOperationOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteZoneApiGatewayOperationsOptions successfully`, func() { + // Construct an instance of the ApiGatewayOperationsDeleteInputItem model + apiGatewayOperationsDeleteInputItemModel := new(aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem) + Expect(apiGatewayOperationsDeleteInputItemModel).ToNot(BeNil()) + apiGatewayOperationsDeleteInputItemModel.OperationID = core.StringPtr("f174e90a-fafe-4643-bbbc-4a0ed4fc8415") + Expect(apiGatewayOperationsDeleteInputItemModel.OperationID).To(Equal(core.StringPtr("f174e90a-fafe-4643-bbbc-4a0ed4fc8415"))) + + // Construct an instance of the DeleteZoneApiGatewayOperationsOptions model + apiGatewayOperationsDeleteInputItem := []aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem{} + deleteZoneApiGatewayOperationsOptionsModel := aiSecurityForAppsService.NewDeleteZoneApiGatewayOperationsOptions(apiGatewayOperationsDeleteInputItem) + deleteZoneApiGatewayOperationsOptionsModel.SetApiGatewayOperationsDeleteInputItem([]aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem{*apiGatewayOperationsDeleteInputItemModel}) + deleteZoneApiGatewayOperationsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteZoneApiGatewayOperationsOptionsModel).ToNot(BeNil()) + Expect(deleteZoneApiGatewayOperationsOptionsModel.ApiGatewayOperationsDeleteInputItem).To(Equal([]aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem{*apiGatewayOperationsDeleteInputItemModel})) + Expect(deleteZoneApiGatewayOperationsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetAiSecuritySettingsOptions successfully`, func() { + // Construct an instance of the GetAiSecuritySettingsOptions model + getAiSecuritySettingsOptionsModel := aiSecurityForAppsService.NewGetAiSecuritySettingsOptions() + getAiSecuritySettingsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getAiSecuritySettingsOptionsModel).ToNot(BeNil()) + Expect(getAiSecuritySettingsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetApiGatewayDiscoveryOptions successfully`, func() { + // Construct an instance of the GetApiGatewayDiscoveryOptions model + getApiGatewayDiscoveryOptionsModel := aiSecurityForAppsService.NewGetApiGatewayDiscoveryOptions() + getApiGatewayDiscoveryOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getApiGatewayDiscoveryOptionsModel).ToNot(BeNil()) + Expect(getApiGatewayDiscoveryOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetApiGatewaySchemasOptions successfully`, func() { + // Construct an instance of the GetApiGatewaySchemasOptions model + getApiGatewaySchemasOptionsModel := aiSecurityForAppsService.NewGetApiGatewaySchemasOptions() + getApiGatewaySchemasOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getApiGatewaySchemasOptionsModel).ToNot(BeNil()) + Expect(getApiGatewaySchemasOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetZoneApiGatewayOperationOptions successfully`, func() { + // Construct an instance of the GetZoneApiGatewayOperationOptions model + operationID := "testString" + getZoneApiGatewayOperationOptionsModel := aiSecurityForAppsService.NewGetZoneApiGatewayOperationOptions(operationID) + getZoneApiGatewayOperationOptionsModel.SetOperationID("testString") + getZoneApiGatewayOperationOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getZoneApiGatewayOperationOptionsModel).ToNot(BeNil()) + Expect(getZoneApiGatewayOperationOptionsModel.OperationID).To(Equal(core.StringPtr("testString"))) + Expect(getZoneApiGatewayOperationOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListApiGatewayDiscoveryOperationsOptions successfully`, func() { + // Construct an instance of the ListApiGatewayDiscoveryOperationsOptions model + listApiGatewayDiscoveryOperationsOptionsModel := aiSecurityForAppsService.NewListApiGatewayDiscoveryOperationsOptions() + listApiGatewayDiscoveryOperationsOptionsModel.SetDiff(true) + listApiGatewayDiscoveryOperationsOptionsModel.SetDirection("asc") + listApiGatewayDiscoveryOperationsOptionsModel.SetEndpoint("testString") + listApiGatewayDiscoveryOperationsOptionsModel.SetHost([]string{"testString"}) + listApiGatewayDiscoveryOperationsOptionsModel.SetMethod([]string{"testString"}) + listApiGatewayDiscoveryOperationsOptionsModel.SetOrder("host") + listApiGatewayDiscoveryOperationsOptionsModel.SetOrigin("ML") + listApiGatewayDiscoveryOperationsOptionsModel.SetState("review") + listApiGatewayDiscoveryOperationsOptionsModel.SetPage(int64(1)) + listApiGatewayDiscoveryOperationsOptionsModel.SetPerPage(int64(5)) + listApiGatewayDiscoveryOperationsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listApiGatewayDiscoveryOperationsOptionsModel).ToNot(BeNil()) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Diff).To(Equal(core.BoolPtr(true))) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Direction).To(Equal(core.StringPtr("asc"))) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Endpoint).To(Equal(core.StringPtr("testString"))) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Host).To(Equal([]string{"testString"})) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Method).To(Equal([]string{"testString"})) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Order).To(Equal(core.StringPtr("host"))) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Origin).To(Equal(core.StringPtr("ML"))) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.State).To(Equal(core.StringPtr("review"))) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Page).To(Equal(core.Int64Ptr(int64(1)))) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.PerPage).To(Equal(core.Int64Ptr(int64(5)))) + Expect(listApiGatewayDiscoveryOperationsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListZoneApiGatewayOperationsOptions successfully`, func() { + // Construct an instance of the ListZoneApiGatewayOperationsOptions model + listZoneApiGatewayOperationsOptionsModel := aiSecurityForAppsService.NewListZoneApiGatewayOperationsOptions() + listZoneApiGatewayOperationsOptionsModel.SetHost([]string{"testString"}) + listZoneApiGatewayOperationsOptionsModel.SetMethod([]string{"GET"}) + listZoneApiGatewayOperationsOptionsModel.SetEndpoint("testString") + listZoneApiGatewayOperationsOptionsModel.SetLabels([]string{"testString"}) + listZoneApiGatewayOperationsOptionsModel.SetDirection("asc") + listZoneApiGatewayOperationsOptionsModel.SetOrder("host") + listZoneApiGatewayOperationsOptionsModel.SetPage(int64(1)) + listZoneApiGatewayOperationsOptionsModel.SetPerPage(int64(1)) + listZoneApiGatewayOperationsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listZoneApiGatewayOperationsOptionsModel).ToNot(BeNil()) + Expect(listZoneApiGatewayOperationsOptionsModel.Host).To(Equal([]string{"testString"})) + Expect(listZoneApiGatewayOperationsOptionsModel.Method).To(Equal([]string{"GET"})) + Expect(listZoneApiGatewayOperationsOptionsModel.Endpoint).To(Equal(core.StringPtr("testString"))) + Expect(listZoneApiGatewayOperationsOptionsModel.Labels).To(Equal([]string{"testString"})) + Expect(listZoneApiGatewayOperationsOptionsModel.Direction).To(Equal(core.StringPtr("asc"))) + Expect(listZoneApiGatewayOperationsOptionsModel.Order).To(Equal(core.StringPtr("host"))) + Expect(listZoneApiGatewayOperationsOptionsModel.Page).To(Equal(core.Int64Ptr(int64(1)))) + Expect(listZoneApiGatewayOperationsOptionsModel.PerPage).To(Equal(core.Int64Ptr(int64(1)))) + Expect(listZoneApiGatewayOperationsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewReplaceZoneAiSecuritySettingsOptions successfully`, func() { + // Construct an instance of the ReplaceZoneAiSecuritySettingsOptions model + replaceZoneAiSecuritySettingsOptionsModel := aiSecurityForAppsService.NewReplaceZoneAiSecuritySettingsOptions() + replaceZoneAiSecuritySettingsOptionsModel.SetEnabled(true) + replaceZoneAiSecuritySettingsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(replaceZoneAiSecuritySettingsOptionsModel).ToNot(BeNil()) + Expect(replaceZoneAiSecuritySettingsOptionsModel.Enabled).To(Equal(core.BoolPtr(true))) + Expect(replaceZoneAiSecuritySettingsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewReplaceZoneApiGatewayOperationLabelsOptions successfully`, func() { + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + Expect(apiGatewayOperationsLabelsBulkInputSelectorIncludeModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + Expect(apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds).To(Equal([]string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"})) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + Expect(apiGatewayOperationsLabelsBulkInputSelectorModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + Expect(apiGatewayOperationsLabelsBulkInputSelectorModel.Include).To(Equal(apiGatewayOperationsLabelsBulkInputSelectorIncludeModel)) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + Expect(apiGatewayOperationsLabelsBulkInputUserModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + Expect(apiGatewayOperationsLabelsBulkInputUserModel.Labels).To(Equal([]string{"testString"})) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + Expect(apiGatewayOperationsLabelsBulkInputManagedModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + Expect(apiGatewayOperationsLabelsBulkInputManagedModel.Labels).To(Equal([]string{"testString"})) + + // Construct an instance of the ReplaceZoneApiGatewayOperationLabelsOptions model + replaceZoneApiGatewayOperationLabelsOptionsModel := aiSecurityForAppsService.NewReplaceZoneApiGatewayOperationLabelsOptions() + replaceZoneApiGatewayOperationLabelsOptionsModel.SetSelector(apiGatewayOperationsLabelsBulkInputSelectorModel) + replaceZoneApiGatewayOperationLabelsOptionsModel.SetUser(apiGatewayOperationsLabelsBulkInputUserModel) + replaceZoneApiGatewayOperationLabelsOptionsModel.SetManaged(apiGatewayOperationsLabelsBulkInputManagedModel) + replaceZoneApiGatewayOperationLabelsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(replaceZoneApiGatewayOperationLabelsOptionsModel).ToNot(BeNil()) + Expect(replaceZoneApiGatewayOperationLabelsOptionsModel.Selector).To(Equal(apiGatewayOperationsLabelsBulkInputSelectorModel)) + Expect(replaceZoneApiGatewayOperationLabelsOptionsModel.User).To(Equal(apiGatewayOperationsLabelsBulkInputUserModel)) + Expect(replaceZoneApiGatewayOperationLabelsOptionsModel.Managed).To(Equal(apiGatewayOperationsLabelsBulkInputManagedModel)) + Expect(replaceZoneApiGatewayOperationLabelsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewSetZoneApiGatewayOperationLabelsOptions successfully`, func() { + // Construct an instance of the SetZoneApiGatewayOperationLabelsOptions model + operationID := "testString" + setZoneApiGatewayOperationLabelsOptionsModel := aiSecurityForAppsService.NewSetZoneApiGatewayOperationLabelsOptions(operationID) + setZoneApiGatewayOperationLabelsOptionsModel.SetOperationID("testString") + setZoneApiGatewayOperationLabelsOptionsModel.SetUser([]string{}) + setZoneApiGatewayOperationLabelsOptionsModel.SetManaged([]string{"cf-llm"}) + setZoneApiGatewayOperationLabelsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(setZoneApiGatewayOperationLabelsOptionsModel).ToNot(BeNil()) + Expect(setZoneApiGatewayOperationLabelsOptionsModel.OperationID).To(Equal(core.StringPtr("testString"))) + Expect(setZoneApiGatewayOperationLabelsOptionsModel.User).To(Equal([]string{})) + Expect(setZoneApiGatewayOperationLabelsOptionsModel.Managed).To(Equal([]string{"cf-llm"})) + Expect(setZoneApiGatewayOperationLabelsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewUnsetZoneApiGatewayOperationLabelsOptions successfully`, func() { + // Construct an instance of the UnsetZoneApiGatewayOperationLabelsOptions model + operationID := "testString" + unsetZoneApiGatewayOperationLabelsOptionsModel := aiSecurityForAppsService.NewUnsetZoneApiGatewayOperationLabelsOptions(operationID) + unsetZoneApiGatewayOperationLabelsOptionsModel.SetOperationID("testString") + unsetZoneApiGatewayOperationLabelsOptionsModel.SetUser([]string{"testString"}) + unsetZoneApiGatewayOperationLabelsOptionsModel.SetManaged([]string{"testString"}) + unsetZoneApiGatewayOperationLabelsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(unsetZoneApiGatewayOperationLabelsOptionsModel).ToNot(BeNil()) + Expect(unsetZoneApiGatewayOperationLabelsOptionsModel.OperationID).To(Equal(core.StringPtr("testString"))) + Expect(unsetZoneApiGatewayOperationLabelsOptionsModel.User).To(Equal([]string{"testString"})) + Expect(unsetZoneApiGatewayOperationLabelsOptionsModel.Managed).To(Equal([]string{"testString"})) + Expect(unsetZoneApiGatewayOperationLabelsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewUpdateApiGatewayOperationLabelsOptions successfully`, func() { + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelectorInclude model + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + Expect(apiGatewayOperationsLabelsBulkInputSelectorIncludeModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + Expect(apiGatewayOperationsLabelsBulkInputSelectorIncludeModel.OperationIds).To(Equal([]string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"})) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputSelector model + apiGatewayOperationsLabelsBulkInputSelectorModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + Expect(apiGatewayOperationsLabelsBulkInputSelectorModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkInputSelectorModel.Include = apiGatewayOperationsLabelsBulkInputSelectorIncludeModel + Expect(apiGatewayOperationsLabelsBulkInputSelectorModel.Include).To(Equal(apiGatewayOperationsLabelsBulkInputSelectorIncludeModel)) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputUser model + apiGatewayOperationsLabelsBulkInputUserModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + Expect(apiGatewayOperationsLabelsBulkInputUserModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkInputUserModel.Labels = []string{"testString"} + Expect(apiGatewayOperationsLabelsBulkInputUserModel.Labels).To(Equal([]string{"testString"})) + + // Construct an instance of the ApiGatewayOperationsLabelsBulkInputManaged model + apiGatewayOperationsLabelsBulkInputManagedModel := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + Expect(apiGatewayOperationsLabelsBulkInputManagedModel).ToNot(BeNil()) + apiGatewayOperationsLabelsBulkInputManagedModel.Labels = []string{"testString"} + Expect(apiGatewayOperationsLabelsBulkInputManagedModel.Labels).To(Equal([]string{"testString"})) + + // Construct an instance of the UpdateApiGatewayOperationLabelsOptions model + updateApiGatewayOperationLabelsOptionsModel := aiSecurityForAppsService.NewUpdateApiGatewayOperationLabelsOptions() + updateApiGatewayOperationLabelsOptionsModel.SetSelector(apiGatewayOperationsLabelsBulkInputSelectorModel) + updateApiGatewayOperationLabelsOptionsModel.SetUser(apiGatewayOperationsLabelsBulkInputUserModel) + updateApiGatewayOperationLabelsOptionsModel.SetManaged(apiGatewayOperationsLabelsBulkInputManagedModel) + updateApiGatewayOperationLabelsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(updateApiGatewayOperationLabelsOptionsModel).ToNot(BeNil()) + Expect(updateApiGatewayOperationLabelsOptionsModel.Selector).To(Equal(apiGatewayOperationsLabelsBulkInputSelectorModel)) + Expect(updateApiGatewayOperationLabelsOptionsModel.User).To(Equal(apiGatewayOperationsLabelsBulkInputUserModel)) + Expect(updateApiGatewayOperationLabelsOptionsModel.Managed).To(Equal(apiGatewayOperationsLabelsBulkInputManagedModel)) + Expect(updateApiGatewayOperationLabelsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewUpdateZoneApiGatewayDiscoveryOperationOptions successfully`, func() { + // Construct an instance of the UpdateZoneApiGatewayDiscoveryOperationOptions model + updateZoneApiGatewayDiscoveryOperationOptionsModel := aiSecurityForAppsService.NewUpdateZoneApiGatewayDiscoveryOperationOptions() + updateZoneApiGatewayDiscoveryOperationOptionsModel.SetRequestBody(map[string]interface{}{"anyKey": "anyValue"}) + updateZoneApiGatewayDiscoveryOperationOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(updateZoneApiGatewayDiscoveryOperationOptionsModel).ToNot(BeNil()) + Expect(updateZoneApiGatewayDiscoveryOperationOptionsModel.RequestBody).To(Equal(map[string]interface{}{"anyKey": "anyValue"})) + Expect(updateZoneApiGatewayDiscoveryOperationOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewApiGatewayOperation successfully`, func() { + method := "POST" + host := "api.example.com" + endpoint := "/v1/messages" + _model, err := aiSecurityForAppsService.NewApiGatewayOperation(method, host, endpoint) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + }) + }) + Describe(`Model unmarshaling tests`, func() { + It(`Invoke UnmarshalApiGatewayOperationsDeleteInputItem successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem) + model.OperationID = core.StringPtr("f174e90a-fafe-4643-bbbc-4a0ed4fc8415") + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsDeleteInputItem + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsDeleteInputItem(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperationsLabelsBulkDeleteInputManaged successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputManaged) + model.Labels = []string{"testString"} + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputManaged + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsLabelsBulkDeleteInputManaged(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelector successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector) + model.Include = nil + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelector + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelector(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude) + model.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsLabelsBulkDeleteInputSelectorInclude(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperationsLabelsBulkDeleteInputUser successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputUser) + model.Labels = []string{"testString"} + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkDeleteInputUser + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsLabelsBulkDeleteInputUser(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperationsLabelsBulkInputManaged successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged) + model.Labels = []string{"testString"} + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputManaged + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsLabelsBulkInputManaged(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperationsLabelsBulkInputSelector successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector) + model.Include = nil + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelector + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsLabelsBulkInputSelector(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperationsLabelsBulkInputSelectorInclude successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude) + model.OperationIds = []string{"f174e90a-fafe-4643-bbbc-4a0ed4fc8415"} + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputSelectorInclude + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsLabelsBulkInputSelectorInclude(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperationsLabelsBulkInputUser successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser) + model.Labels = []string{"testString"} + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperationsLabelsBulkInputUser + err = aisecurityforappsv1.UnmarshalApiGatewayOperationsLabelsBulkInputUser(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + It(`Invoke UnmarshalApiGatewayOperation successfully`, func() { + // Construct an instance of the model. + model := new(aisecurityforappsv1.ApiGatewayOperation) + model.Method = core.StringPtr("POST") + model.Host = core.StringPtr("api.example.com") + model.Endpoint = core.StringPtr("/v1/messages") + + b, err := json.Marshal(model) + Expect(err).To(BeNil()) + + var raw map[string]json.RawMessage + err = json.Unmarshal(b, &raw) + Expect(err).To(BeNil()) + + var result *aisecurityforappsv1.ApiGatewayOperation + err = aisecurityforappsv1.UnmarshalApiGatewayOperation(raw, &result) + Expect(err).To(BeNil()) + Expect(result).ToNot(BeNil()) + Expect(result).To(Equal(model)) + }) + }) + Describe(`Utility function tests`, func() { + It(`Invoke CreateMockByteArray() successfully`, func() { + mockByteArray := CreateMockByteArray("VGhpcyBpcyBhIHRlc3Qgb2YgdGhlIGVtZXJnZW5jeSBicm9hZGNhc3Qgc3lzdGVt") + Expect(mockByteArray).ToNot(BeNil()) + }) + It(`Invoke CreateMockUUID() successfully`, func() { + mockUUID := CreateMockUUID("9fab83da-98cb-4f18-a7ba-b6f0435c9673") + Expect(mockUUID).ToNot(BeNil()) + }) + It(`Invoke CreateMockReader() successfully`, func() { + mockReader := CreateMockReader("This is a test.") + Expect(mockReader).ToNot(BeNil()) + }) + It(`Invoke CreateMockDate() successfully`, func() { + mockDate := CreateMockDate("2019-01-01") + Expect(mockDate).ToNot(BeNil()) + }) + It(`Invoke CreateMockDateTime() successfully`, func() { + mockDateTime := CreateMockDateTime("2019-01-01T12:00:00.000Z") + Expect(mockDateTime).ToNot(BeNil()) + }) + }) +}) + +// +// Utility functions used by the generated test code +// + +func CreateMockByteArray(encodedString string) *[]byte { + ba, err := base64.StdEncoding.DecodeString(encodedString) + if err != nil { + panic(err) + } + return &ba +} + +func CreateMockUUID(mockData string) *strfmt.UUID { + uuid := strfmt.UUID(mockData) + return &uuid +} + +func CreateMockReader(mockData string) io.ReadCloser { + return io.NopCloser(bytes.NewReader([]byte(mockData))) +} + +func CreateMockDate(mockData string) *strfmt.Date { + d, err := core.ParseDate(mockData) + if err != nil { + return nil + } + return &d +} + +func CreateMockDateTime(mockData string) *strfmt.DateTime { + d, err := core.ParseDateTime(mockData) + if err != nil { + return nil + } + return &d +} + +func SetTestEnvironment(testEnvironment map[string]string) { + for key, value := range testEnvironment { + os.Setenv(key, value) + } +} + +func ClearTestEnvironment(testEnvironment map[string]string) { + for key := range testEnvironment { + os.Unsetenv(key) + } +}