diff --git a/README.md b/README.md index 7189a216..9da7656d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Service Name | Package name --- | --- [Case Management](https://cloud.ibm.com/apidocs/case-management) | casemanagementv1 [Catalog Management](https://cloud.ibm.com/apidocs/resource-catalog/private-catalog) | catalogmanagementv1 +[Configuration Governance](https://cloud.ibm.com/apidocs/security-compliance/config) | configurationgovernancev1 [Enterprise Management](https://cloud.ibm.com/apidocs/enterprise-apis/enterprise) | enterprisemanagementv1 [Global Catalog](https://cloud.ibm.com/apidocs/resource-catalog/global-catalog) | globalcatalogv1 [Global Search](https://cloud.ibm.com/apidocs/search) | globalsearchv2 diff --git a/configurationgovernancev1/configuration_governance_v1.go b/configurationgovernancev1/configuration_governance_v1.go new file mode 100644 index 00000000..b0be6c30 --- /dev/null +++ b/configurationgovernancev1/configuration_governance_v1.go @@ -0,0 +1,2809 @@ +/** + * (C) Copyright IBM Corp. 2020. + * + * 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: 99-SNAPSHOT-68ee7c8f-20200829-062726 + */ + + +// Package configurationgovernancev1 : Operations and models for the ConfigurationGovernanceV1 service +package configurationgovernancev1 + +import ( + "encoding/json" + "fmt" + "github.com/IBM/go-sdk-core/v4/core" + common "github.com/IBM/platform-services-go-sdk/common" + "reflect" +) + +// ConfigurationGovernanceV1 : API specification for the Configuration Governance service. +// +// Version: 1.0.0 +type ConfigurationGovernanceV1 struct { + Service *core.BaseService +} + +// DefaultServiceURL is the default URL to make service requests to. +const DefaultServiceURL = "https://compliance.cloud.ibm.com" + +// DefaultServiceName is the default key used to find external configuration information. +const DefaultServiceName = "configuration_governance" + +// ConfigurationGovernanceV1Options : Service options +type ConfigurationGovernanceV1Options struct { + ServiceName string + URL string + Authenticator core.Authenticator +} + +// NewConfigurationGovernanceV1UsingExternalConfig : constructs an instance of ConfigurationGovernanceV1 with passed in options and external configuration. +func NewConfigurationGovernanceV1UsingExternalConfig(options *ConfigurationGovernanceV1Options) (configurationGovernance *ConfigurationGovernanceV1, err error) { + if options.ServiceName == "" { + options.ServiceName = DefaultServiceName + } + + if options.Authenticator == nil { + options.Authenticator, err = core.GetAuthenticatorFromEnvironment(options.ServiceName) + if err != nil { + return + } + } + + configurationGovernance, err = NewConfigurationGovernanceV1(options) + if err != nil { + return + } + + err = configurationGovernance.Service.ConfigureService(options.ServiceName) + if err != nil { + return + } + + if options.URL != "" { + err = configurationGovernance.Service.SetServiceURL(options.URL) + } + return +} + +// NewConfigurationGovernanceV1 : constructs an instance of ConfigurationGovernanceV1 with passed in options. +func NewConfigurationGovernanceV1(options *ConfigurationGovernanceV1Options) (service *ConfigurationGovernanceV1, err error) { + serviceOptions := &core.ServiceOptions{ + URL: DefaultServiceURL, + Authenticator: options.Authenticator, + } + + baseService, err := core.NewBaseService(serviceOptions) + if err != nil { + return + } + + if options.URL != "" { + err = baseService.SetServiceURL(options.URL) + if err != nil { + return + } + } + + service = &ConfigurationGovernanceV1{ + Service: baseService, + } + + return +} + +// SetServiceURL sets the service URL +func (configurationGovernance *ConfigurationGovernanceV1) SetServiceURL(url string) error { + return configurationGovernance.Service.SetServiceURL(url) +} + +// CreateRules : Create rules +// Creates one or more rules that you can use to govern the way that IBM Cloud resources can be provisioned and +// configured. +// +// A successful `POST /config/rules` request defines a rule based on the target, conditions, and enforcement actions +// that you specify. The response returns the ID value for your rule, along with other metadata. +func (configurationGovernance *ConfigurationGovernanceV1) CreateRules(createRulesOptions *CreateRulesOptions) (result *CreateRulesResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createRulesOptions, "createRulesOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(createRulesOptions, "createRulesOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules"} + pathParameters := []string{} + + builder := core.NewRequestBuilder(core.POST) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range createRulesOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "CreateRules") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if createRulesOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*createRulesOptions.TransactionID)) + } + + body := make(map[string]interface{}) + if createRulesOptions.Rules != nil { + body["rules"] = createRulesOptions.Rules + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = configurationGovernance.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateRulesResponse) + if err != nil { + return + } + response.Result = result + + return +} + +// ListRules : List rules +// Retrieves a list of the rules that are available in your account. +func (configurationGovernance *ConfigurationGovernanceV1) ListRules(listRulesOptions *ListRulesOptions) (result *RuleList, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listRulesOptions, "listRulesOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(listRulesOptions, "listRulesOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules"} + pathParameters := []string{} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range listRulesOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "ListRules") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if listRulesOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*listRulesOptions.TransactionID)) + } + + builder.AddQuery("account_id", fmt.Sprint(*listRulesOptions.AccountID)) + if listRulesOptions.Attached != nil { + builder.AddQuery("attached", fmt.Sprint(*listRulesOptions.Attached)) + } + if listRulesOptions.Labels != nil { + builder.AddQuery("labels", fmt.Sprint(*listRulesOptions.Labels)) + } + if listRulesOptions.Scopes != nil { + builder.AddQuery("scopes", fmt.Sprint(*listRulesOptions.Scopes)) + } + if listRulesOptions.Limit != nil { + builder.AddQuery("limit", fmt.Sprint(*listRulesOptions.Limit)) + } + if listRulesOptions.Offset != nil { + builder.AddQuery("offset", fmt.Sprint(*listRulesOptions.Offset)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = configurationGovernance.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRuleList) + if err != nil { + return + } + response.Result = result + + return +} + +// GetRule : Get a rule +// Retrieves an existing rule and its details. +func (configurationGovernance *ConfigurationGovernanceV1) GetRule(getRuleOptions *GetRuleOptions) (result *Rule, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getRuleOptions, "getRuleOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getRuleOptions, "getRuleOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules"} + pathParameters := []string{*getRuleOptions.RuleID} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range getRuleOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "GetRule") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if getRuleOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*getRuleOptions.TransactionID)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = configurationGovernance.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRule) + if err != nil { + return + } + response.Result = result + + return +} + +// UpdateRule : Update a rule +// Updates an existing rule based on the properties that you specify. +func (configurationGovernance *ConfigurationGovernanceV1) UpdateRule(updateRuleOptions *UpdateRuleOptions) (result *Rule, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(updateRuleOptions, "updateRuleOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(updateRuleOptions, "updateRuleOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules"} + pathParameters := []string{*updateRuleOptions.RuleID} + + builder := core.NewRequestBuilder(core.PUT) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range updateRuleOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "UpdateRule") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if updateRuleOptions.IfMatch != nil { + builder.AddHeader("If-Match", fmt.Sprint(*updateRuleOptions.IfMatch)) + } + if updateRuleOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*updateRuleOptions.TransactionID)) + } + + body := make(map[string]interface{}) + if updateRuleOptions.Name != nil { + body["name"] = updateRuleOptions.Name + } + if updateRuleOptions.Description != nil { + body["description"] = updateRuleOptions.Description + } + if updateRuleOptions.Target != nil { + body["target"] = updateRuleOptions.Target + } + if updateRuleOptions.RequiredConfig != nil { + body["required_config"] = updateRuleOptions.RequiredConfig + } + if updateRuleOptions.EnforcementActions != nil { + body["enforcement_actions"] = updateRuleOptions.EnforcementActions + } + if updateRuleOptions.AccountID != nil { + body["account_id"] = updateRuleOptions.AccountID + } + if updateRuleOptions.RuleType != nil { + body["rule_type"] = updateRuleOptions.RuleType + } + if updateRuleOptions.Labels != nil { + body["labels"] = updateRuleOptions.Labels + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = configurationGovernance.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRule) + if err != nil { + return + } + response.Result = result + + return +} + +// DeleteRule : Delete a rule +// Deletes an existing rule. +func (configurationGovernance *ConfigurationGovernanceV1) DeleteRule(deleteRuleOptions *DeleteRuleOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteRuleOptions, "deleteRuleOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(deleteRuleOptions, "deleteRuleOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules"} + pathParameters := []string{*deleteRuleOptions.RuleID} + + builder := core.NewRequestBuilder(core.DELETE) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range deleteRuleOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "DeleteRule") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + if deleteRuleOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*deleteRuleOptions.TransactionID)) + } + + request, err := builder.Build() + if err != nil { + return + } + + response, err = configurationGovernance.Service.Request(request, nil) + + return +} + +// CreateAttachments : Create attachments +// Creates one or more scope attachments for an existing rule. +// +// You can attach an existing rule to a scope, such as a specific IBM Cloud account, to start evaluating the rule for +// compliance. A successful +// `POST /config/v1/rules/{rule_id}/attachments` returns the ID value for the attachment, along with other metadata. +func (configurationGovernance *ConfigurationGovernanceV1) CreateAttachments(createAttachmentsOptions *CreateAttachmentsOptions) (result *CreateAttachmentsResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createAttachmentsOptions, "createAttachmentsOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(createAttachmentsOptions, "createAttachmentsOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules", "attachments"} + pathParameters := []string{*createAttachmentsOptions.RuleID} + + builder := core.NewRequestBuilder(core.POST) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range createAttachmentsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "CreateAttachments") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if createAttachmentsOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*createAttachmentsOptions.TransactionID)) + } + + body := make(map[string]interface{}) + if createAttachmentsOptions.Attachments != nil { + body["attachments"] = createAttachmentsOptions.Attachments + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = configurationGovernance.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateAttachmentsResponse) + if err != nil { + return + } + response.Result = result + + return +} + +// ListAttachments : List attachments +// Retrieves a list of scope attachments that are associated with the specified rule. +func (configurationGovernance *ConfigurationGovernanceV1) ListAttachments(listAttachmentsOptions *ListAttachmentsOptions) (result *AttachmentList, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listAttachmentsOptions, "listAttachmentsOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(listAttachmentsOptions, "listAttachmentsOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules", "attachments"} + pathParameters := []string{*listAttachmentsOptions.RuleID} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range listAttachmentsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "ListAttachments") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if listAttachmentsOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*listAttachmentsOptions.TransactionID)) + } + + if listAttachmentsOptions.Limit != nil { + builder.AddQuery("limit", fmt.Sprint(*listAttachmentsOptions.Limit)) + } + if listAttachmentsOptions.Offset != nil { + builder.AddQuery("offset", fmt.Sprint(*listAttachmentsOptions.Offset)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = configurationGovernance.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAttachmentList) + if err != nil { + return + } + response.Result = result + + return +} + +// GetAttachment : Get an attachment +// Retrieves an existing scope attachment for a rule. +func (configurationGovernance *ConfigurationGovernanceV1) GetAttachment(getAttachmentOptions *GetAttachmentOptions) (result *Attachment, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getAttachmentOptions, "getAttachmentOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getAttachmentOptions, "getAttachmentOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules", "attachments"} + pathParameters := []string{*getAttachmentOptions.RuleID, *getAttachmentOptions.AttachmentID} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range getAttachmentOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "GetAttachment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if getAttachmentOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*getAttachmentOptions.TransactionID)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = configurationGovernance.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAttachment) + if err != nil { + return + } + response.Result = result + + return +} + +// UpdateAttachment : Update an attachment +// Updates an existing scope attachment based on the properties that you specify. +func (configurationGovernance *ConfigurationGovernanceV1) UpdateAttachment(updateAttachmentOptions *UpdateAttachmentOptions) (result *Attachment, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(updateAttachmentOptions, "updateAttachmentOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(updateAttachmentOptions, "updateAttachmentOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules", "attachments"} + pathParameters := []string{*updateAttachmentOptions.RuleID, *updateAttachmentOptions.AttachmentID} + + builder := core.NewRequestBuilder(core.PUT) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range updateAttachmentOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "UpdateAttachment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if updateAttachmentOptions.IfMatch != nil { + builder.AddHeader("If-Match", fmt.Sprint(*updateAttachmentOptions.IfMatch)) + } + if updateAttachmentOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*updateAttachmentOptions.TransactionID)) + } + + body := make(map[string]interface{}) + if updateAttachmentOptions.AccountID != nil { + body["account_id"] = updateAttachmentOptions.AccountID + } + if updateAttachmentOptions.IncludedScope != nil { + body["included_scope"] = updateAttachmentOptions.IncludedScope + } + if updateAttachmentOptions.ExcludedScopes != nil { + body["excluded_scopes"] = updateAttachmentOptions.ExcludedScopes + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = configurationGovernance.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAttachment) + if err != nil { + return + } + response.Result = result + + return +} + +// DeleteAttachment : Delete an attachment +// Deletes an existing scope attachment. +func (configurationGovernance *ConfigurationGovernanceV1) DeleteAttachment(deleteAttachmentOptions *DeleteAttachmentOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteAttachmentOptions, "deleteAttachmentOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(deleteAttachmentOptions, "deleteAttachmentOptions") + if err != nil { + return + } + + pathSegments := []string{"config/v1/rules", "attachments"} + pathParameters := []string{*deleteAttachmentOptions.RuleID, *deleteAttachmentOptions.AttachmentID} + + builder := core.NewRequestBuilder(core.DELETE) + _, err = builder.ConstructHTTPURL(configurationGovernance.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range deleteAttachmentOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("configuration_governance", "V1", "DeleteAttachment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + if deleteAttachmentOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*deleteAttachmentOptions.TransactionID)) + } + + request, err := builder.Build() + if err != nil { + return + } + + response, err = configurationGovernance.Service.Request(request, nil) + + return +} + +// Attachment : The scopes to attach to the rule. +type Attachment struct { + // The UUID that uniquely identifies the attachment. + AttachmentID *string `json:"attachment_id" validate:"required"` + + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + // Your IBM Cloud account ID. + AccountID *string `json:"account_id" validate:"required"` + + // The extent at which the rule can be attached across your accounts. + IncludedScope *RuleScope `json:"included_scope" validate:"required"` + + // The extent at which the rule can be excluded from the included scope. + ExcludedScopes []RuleScope `json:"excluded_scopes,omitempty"` +} + + +// UnmarshalAttachment unmarshals an instance of Attachment from the specified map of raw messages. +func UnmarshalAttachment(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Attachment) + err = core.UnmarshalPrimitive(m, "attachment_id", &obj.AttachmentID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "rule_id", &obj.RuleID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "included_scope", &obj.IncludedScope, UnmarshalRuleScope) + if err != nil { + return + } + err = core.UnmarshalModel(m, "excluded_scopes", &obj.ExcludedScopes, UnmarshalRuleScope) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AttachmentList : A list of attachments. +type AttachmentList struct { + // The requested offset for the returned items. + Offset *int64 `json:"offset" validate:"required"` + + // The requested limit for the returned items. + Limit *int64 `json:"limit" validate:"required"` + + // The total number of available items. + TotalCount *int64 `json:"total_count" validate:"required"` + + // The first page of available items. + First *Link `json:"first" validate:"required"` + + // The last page of available items. + Last *Link `json:"last" validate:"required"` + + Attachments []Attachment `json:"attachments" validate:"required"` +} + + +// UnmarshalAttachmentList unmarshals an instance of AttachmentList from the specified map of raw messages. +func UnmarshalAttachmentList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AttachmentList) + err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalLink) + if err != nil { + return + } + err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalLink) + if err != nil { + return + } + err = core.UnmarshalModel(m, "attachments", &obj.Attachments, UnmarshalAttachment) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AttachmentRequest : The scopes to attach to the rule. +type AttachmentRequest struct { + // Your IBM Cloud account ID. + AccountID *string `json:"account_id" validate:"required"` + + // The extent at which the rule can be attached across your accounts. + IncludedScope *RuleScope `json:"included_scope" validate:"required"` + + // The extent at which the rule can be excluded from the included scope. + ExcludedScopes []RuleScope `json:"excluded_scopes,omitempty"` +} + + +// NewAttachmentRequest : Instantiate AttachmentRequest (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewAttachmentRequest(accountID string, includedScope *RuleScope) (model *AttachmentRequest, err error) { + model = &AttachmentRequest{ + AccountID: core.StringPtr(accountID), + IncludedScope: includedScope, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalAttachmentRequest unmarshals an instance of AttachmentRequest from the specified map of raw messages. +func UnmarshalAttachmentRequest(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AttachmentRequest) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "included_scope", &obj.IncludedScope, UnmarshalRuleScope) + if err != nil { + return + } + err = core.UnmarshalModel(m, "excluded_scopes", &obj.ExcludedScopes, UnmarshalRuleScope) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreateAttachmentsOptions : The CreateAttachments options. +type CreateAttachmentsOptions struct { + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + Attachments []AttachmentRequest `json:"attachments" validate:"required"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCreateAttachmentsOptions : Instantiate CreateAttachmentsOptions +func (*ConfigurationGovernanceV1) NewCreateAttachmentsOptions(ruleID string, attachments []AttachmentRequest) *CreateAttachmentsOptions { + return &CreateAttachmentsOptions{ + RuleID: core.StringPtr(ruleID), + Attachments: attachments, + } +} + +// SetRuleID : Allow user to set RuleID +func (options *CreateAttachmentsOptions) SetRuleID(ruleID string) *CreateAttachmentsOptions { + options.RuleID = core.StringPtr(ruleID) + return options +} + +// SetAttachments : Allow user to set Attachments +func (options *CreateAttachmentsOptions) SetAttachments(attachments []AttachmentRequest) *CreateAttachmentsOptions { + options.Attachments = attachments + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *CreateAttachmentsOptions) SetTransactionID(transactionID string) *CreateAttachmentsOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateAttachmentsOptions) SetHeaders(param map[string]string) *CreateAttachmentsOptions { + options.Headers = param + return options +} + +// CreateAttachmentsResponse : CreateAttachmentsResponse struct +type CreateAttachmentsResponse struct { + Attachments []Attachment `json:"attachments" validate:"required"` +} + + +// UnmarshalCreateAttachmentsResponse unmarshals an instance of CreateAttachmentsResponse from the specified map of raw messages. +func UnmarshalCreateAttachmentsResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreateAttachmentsResponse) + err = core.UnmarshalModel(m, "attachments", &obj.Attachments, UnmarshalAttachment) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreateRuleRequest : A rule to be created. +type CreateRuleRequest struct { + // A field that you can use in bulk operations to store a custom identifier for an individual request. If you omit this + // field, the service generates and sends a `request_id` string for each new rule. The generated string corresponds + // with the numerical order of the rules request array. For example, `"request_id": "1"`, `"request_id": "2"`. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `request_id` with + // each request. + RequestID *string `json:"request_id,omitempty"` + + // User-settable properties associated with a rule to be created or updated. + Rule *RuleRequest `json:"rule" validate:"required"` +} + + +// NewCreateRuleRequest : Instantiate CreateRuleRequest (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewCreateRuleRequest(rule *RuleRequest) (model *CreateRuleRequest, err error) { + model = &CreateRuleRequest{ + Rule: rule, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalCreateRuleRequest unmarshals an instance of CreateRuleRequest from the specified map of raw messages. +func UnmarshalCreateRuleRequest(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreateRuleRequest) + err = core.UnmarshalPrimitive(m, "request_id", &obj.RequestID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "rule", &obj.Rule, UnmarshalRuleRequest) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreateRuleResponse : Response information for a rule request. +// +// If the 'status_code' property indicates success, the 'request_id' and 'rule' properties will be present. If the +// 'status_code' property indicates an error, the 'request_id', 'errors', and 'trace' fields will be present. +type CreateRuleResponse struct { + // The identifier that is used to correlate an individual request. + // + // To assist with debugging, you can use this ID to identify and inspect only one request that was made as part of a + // bulk operation. + RequestID *string `json:"request_id,omitempty"` + + // The HTTP response status code. + StatusCode *int64 `json:"status_code,omitempty"` + + // Information about a newly-created rule. + // + // This field will be present for a successful request. + Rule *Rule `json:"rule,omitempty"` + + // The error contents of the multi-status response. + // + // This field will be present for a failed rule request. + Errors []RuleResponseError `json:"errors,omitempty"` + + // The UUID that uniquely identifies the request. + // + // This field will be present for a failed rule request. + Trace *string `json:"trace,omitempty"` +} + + +// UnmarshalCreateRuleResponse unmarshals an instance of CreateRuleResponse from the specified map of raw messages. +func UnmarshalCreateRuleResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreateRuleResponse) + err = core.UnmarshalPrimitive(m, "request_id", &obj.RequestID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + if err != nil { + return + } + err = core.UnmarshalModel(m, "rule", &obj.Rule, UnmarshalRule) + if err != nil { + return + } + err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalRuleResponseError) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreateRulesOptions : The CreateRules options. +type CreateRulesOptions struct { + // A list of rules to be created. + Rules []CreateRuleRequest `json:"rules" validate:"required"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCreateRulesOptions : Instantiate CreateRulesOptions +func (*ConfigurationGovernanceV1) NewCreateRulesOptions(rules []CreateRuleRequest) *CreateRulesOptions { + return &CreateRulesOptions{ + Rules: rules, + } +} + +// SetRules : Allow user to set Rules +func (options *CreateRulesOptions) SetRules(rules []CreateRuleRequest) *CreateRulesOptions { + options.Rules = rules + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *CreateRulesOptions) SetTransactionID(transactionID string) *CreateRulesOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateRulesOptions) SetHeaders(param map[string]string) *CreateRulesOptions { + options.Headers = param + return options +} + +// CreateRulesResponse : The response associated with a request to create one or more rules. +type CreateRulesResponse struct { + // An array of rule responses. + Rules []CreateRuleResponse `json:"rules" validate:"required"` +} + + +// UnmarshalCreateRulesResponse unmarshals an instance of CreateRulesResponse from the specified map of raw messages. +func UnmarshalCreateRulesResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreateRulesResponse) + err = core.UnmarshalModel(m, "rules", &obj.Rules, UnmarshalCreateRuleResponse) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DeleteAttachmentOptions : The DeleteAttachment options. +type DeleteAttachmentOptions struct { + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + // The UUID that uniquely identifies the attachment. + AttachmentID *string `json:"attachment_id" validate:"required"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteAttachmentOptions : Instantiate DeleteAttachmentOptions +func (*ConfigurationGovernanceV1) NewDeleteAttachmentOptions(ruleID string, attachmentID string) *DeleteAttachmentOptions { + return &DeleteAttachmentOptions{ + RuleID: core.StringPtr(ruleID), + AttachmentID: core.StringPtr(attachmentID), + } +} + +// SetRuleID : Allow user to set RuleID +func (options *DeleteAttachmentOptions) SetRuleID(ruleID string) *DeleteAttachmentOptions { + options.RuleID = core.StringPtr(ruleID) + return options +} + +// SetAttachmentID : Allow user to set AttachmentID +func (options *DeleteAttachmentOptions) SetAttachmentID(attachmentID string) *DeleteAttachmentOptions { + options.AttachmentID = core.StringPtr(attachmentID) + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *DeleteAttachmentOptions) SetTransactionID(transactionID string) *DeleteAttachmentOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteAttachmentOptions) SetHeaders(param map[string]string) *DeleteAttachmentOptions { + options.Headers = param + return options +} + +// DeleteRuleOptions : The DeleteRule options. +type DeleteRuleOptions struct { + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteRuleOptions : Instantiate DeleteRuleOptions +func (*ConfigurationGovernanceV1) NewDeleteRuleOptions(ruleID string) *DeleteRuleOptions { + return &DeleteRuleOptions{ + RuleID: core.StringPtr(ruleID), + } +} + +// SetRuleID : Allow user to set RuleID +func (options *DeleteRuleOptions) SetRuleID(ruleID string) *DeleteRuleOptions { + options.RuleID = core.StringPtr(ruleID) + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *DeleteRuleOptions) SetTransactionID(transactionID string) *DeleteRuleOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteRuleOptions) SetHeaders(param map[string]string) *DeleteRuleOptions { + options.Headers = param + return options +} + +// EnforcementAction : EnforcementAction struct +type EnforcementAction struct { + // To block a request from completing, use `disallow`. To log the request to Activity Tracker with LogDNA, use + // `audit_log`. + Action *string `json:"action" validate:"required"` +} + +// Constants associated with the EnforcementAction.Action property. +// To block a request from completing, use `disallow`. To log the request to Activity Tracker with LogDNA, use +// `audit_log`. +const ( + EnforcementActionActionAuditLogConst = "audit_log" + EnforcementActionActionDisallowConst = "disallow" +) + + +// NewEnforcementAction : Instantiate EnforcementAction (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewEnforcementAction(action string) (model *EnforcementAction, err error) { + model = &EnforcementAction{ + Action: core.StringPtr(action), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalEnforcementAction unmarshals an instance of EnforcementAction from the specified map of raw messages. +func UnmarshalEnforcementAction(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(EnforcementAction) + err = core.UnmarshalPrimitive(m, "action", &obj.Action) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GetAttachmentOptions : The GetAttachment options. +type GetAttachmentOptions struct { + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + // The UUID that uniquely identifies the attachment. + AttachmentID *string `json:"attachment_id" validate:"required"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetAttachmentOptions : Instantiate GetAttachmentOptions +func (*ConfigurationGovernanceV1) NewGetAttachmentOptions(ruleID string, attachmentID string) *GetAttachmentOptions { + return &GetAttachmentOptions{ + RuleID: core.StringPtr(ruleID), + AttachmentID: core.StringPtr(attachmentID), + } +} + +// SetRuleID : Allow user to set RuleID +func (options *GetAttachmentOptions) SetRuleID(ruleID string) *GetAttachmentOptions { + options.RuleID = core.StringPtr(ruleID) + return options +} + +// SetAttachmentID : Allow user to set AttachmentID +func (options *GetAttachmentOptions) SetAttachmentID(attachmentID string) *GetAttachmentOptions { + options.AttachmentID = core.StringPtr(attachmentID) + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *GetAttachmentOptions) SetTransactionID(transactionID string) *GetAttachmentOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *GetAttachmentOptions) SetHeaders(param map[string]string) *GetAttachmentOptions { + options.Headers = param + return options +} + +// GetRuleOptions : The GetRule options. +type GetRuleOptions struct { + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetRuleOptions : Instantiate GetRuleOptions +func (*ConfigurationGovernanceV1) NewGetRuleOptions(ruleID string) *GetRuleOptions { + return &GetRuleOptions{ + RuleID: core.StringPtr(ruleID), + } +} + +// SetRuleID : Allow user to set RuleID +func (options *GetRuleOptions) SetRuleID(ruleID string) *GetRuleOptions { + options.RuleID = core.StringPtr(ruleID) + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *GetRuleOptions) SetTransactionID(transactionID string) *GetRuleOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *GetRuleOptions) SetHeaders(param map[string]string) *GetRuleOptions { + options.Headers = param + return options +} + +// Link : A link that is used to paginate through available resources. +type Link struct { + // The URL for the first, previous, next, or last page of resources. + Href *string `json:"href" validate:"required"` +} + + +// UnmarshalLink unmarshals an instance of Link from the specified map of raw messages. +func UnmarshalLink(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Link) + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ListAttachmentsOptions : The ListAttachments options. +type ListAttachmentsOptions struct { + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // The number of resources to retrieve. By default, list operations return the first 100 items. To retrieve a different + // set of items, use `limit` with `offset` to page through your available resources. + // + // **Usage:** If you have 20 rules, and you want to retrieve only the first 5 rules, use + // `../rules?account_id={account_id}&limit=5`. + Limit *int64 `json:"limit,omitempty"` + + // The number of resources to skip. By specifying `offset`, you retrieve a subset of resources that starts with the + // `offset` value. Use `offset` with `limit` to page through your available resources. + // + // **Usage:** If you have 100 rules, and you want to retrieve rules 26 through 50, use + // `../rules?account_id={account_id}&offset=25&limit=5`. + Offset *int64 `json:"offset,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListAttachmentsOptions : Instantiate ListAttachmentsOptions +func (*ConfigurationGovernanceV1) NewListAttachmentsOptions(ruleID string) *ListAttachmentsOptions { + return &ListAttachmentsOptions{ + RuleID: core.StringPtr(ruleID), + } +} + +// SetRuleID : Allow user to set RuleID +func (options *ListAttachmentsOptions) SetRuleID(ruleID string) *ListAttachmentsOptions { + options.RuleID = core.StringPtr(ruleID) + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *ListAttachmentsOptions) SetTransactionID(transactionID string) *ListAttachmentsOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetLimit : Allow user to set Limit +func (options *ListAttachmentsOptions) SetLimit(limit int64) *ListAttachmentsOptions { + options.Limit = core.Int64Ptr(limit) + return options +} + +// SetOffset : Allow user to set Offset +func (options *ListAttachmentsOptions) SetOffset(offset int64) *ListAttachmentsOptions { + options.Offset = core.Int64Ptr(offset) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *ListAttachmentsOptions) SetHeaders(param map[string]string) *ListAttachmentsOptions { + options.Headers = param + return options +} + +// ListRulesOptions : The ListRules options. +type ListRulesOptions struct { + // Your IBM Cloud account ID. + AccountID *string `json:"account_id" validate:"required"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Retrieves a list of rules that have scope attachments. + Attached *bool `json:"attached,omitempty"` + + // Retrieves a list of rules that match the labels that you specify. + Labels *string `json:"labels,omitempty"` + + // Retrieves a list of rules that match the scope ID that you specify. + Scopes *string `json:"scopes,omitempty"` + + // The number of resources to retrieve. By default, list operations return the first 100 items. To retrieve a different + // set of items, use `limit` with `offset` to page through your available resources. + // + // **Usage:** If you have 20 rules, and you want to retrieve only the first 5 rules, use + // `../rules?account_id={account_id}&limit=5`. + Limit *int64 `json:"limit,omitempty"` + + // The number of resources to skip. By specifying `offset`, you retrieve a subset of resources that starts with the + // `offset` value. Use `offset` with `limit` to page through your available resources. + // + // **Usage:** If you have 100 rules, and you want to retrieve rules 26 through 50, use + // `../rules?account_id={account_id}&offset=25&limit=5`. + Offset *int64 `json:"offset,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListRulesOptions : Instantiate ListRulesOptions +func (*ConfigurationGovernanceV1) NewListRulesOptions(accountID string) *ListRulesOptions { + return &ListRulesOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (options *ListRulesOptions) SetAccountID(accountID string) *ListRulesOptions { + options.AccountID = core.StringPtr(accountID) + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *ListRulesOptions) SetTransactionID(transactionID string) *ListRulesOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetAttached : Allow user to set Attached +func (options *ListRulesOptions) SetAttached(attached bool) *ListRulesOptions { + options.Attached = core.BoolPtr(attached) + return options +} + +// SetLabels : Allow user to set Labels +func (options *ListRulesOptions) SetLabels(labels string) *ListRulesOptions { + options.Labels = core.StringPtr(labels) + return options +} + +// SetScopes : Allow user to set Scopes +func (options *ListRulesOptions) SetScopes(scopes string) *ListRulesOptions { + options.Scopes = core.StringPtr(scopes) + return options +} + +// SetLimit : Allow user to set Limit +func (options *ListRulesOptions) SetLimit(limit int64) *ListRulesOptions { + options.Limit = core.Int64Ptr(limit) + return options +} + +// SetOffset : Allow user to set Offset +func (options *ListRulesOptions) SetOffset(offset int64) *ListRulesOptions { + options.Offset = core.Int64Ptr(offset) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *ListRulesOptions) SetHeaders(param map[string]string) *ListRulesOptions { + options.Headers = param + return options +} + +// Rule : Properties associated with a rule, including both user-settable and server-populated properties. +type Rule struct { + // Your IBM Cloud account ID. + AccountID *string `json:"account_id,omitempty"` + + // A human-readable alias to assign to your rule. + Name *string `json:"name" validate:"required"` + + // An extended description of your rule. + Description *string `json:"description" validate:"required"` + + // The type of rule. Rules that you create are `user_defined`. + RuleType *string `json:"rule_type,omitempty"` + + // The properties that describe the resource that you want to target + // with the rule. + Target *TargetResource `json:"target" validate:"required"` + + RequiredConfig RuleRequiredConfigIntf `json:"required_config" validate:"required"` + + // The actions that the service must run on your behalf when a request to create or modify the target resource does not + // comply with your conditions. + EnforcementActions []EnforcementAction `json:"enforcement_actions" validate:"required"` + + // Labels that you can use to group and search for similar rules, such as those that help you to meet a specific + // organization guideline. + Labels []string `json:"labels,omitempty"` + + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id,omitempty"` + + // The date the resource was created. + CreationDate *string `json:"creation_date,omitempty"` + + // The unique identifier for the user or application that created the resource. + CreatedBy *string `json:"created_by,omitempty"` + + // The date the resource was last modified. + ModificationDate *string `json:"modification_date,omitempty"` + + // The unique identifier for the user or application that last modified the resource. + ModifiedBy *string `json:"modified_by,omitempty"` + + // The number of scope attachments that are associated with the rule. + NumberOfAttachments *int64 `json:"number_of_attachments,omitempty"` +} + +// Constants associated with the Rule.RuleType property. +// The type of rule. Rules that you create are `user_defined`. +const ( + RuleRuleTypeUserDefinedConst = "user_defined" +) + + +// UnmarshalRule unmarshals an instance of Rule from the specified map of raw messages. +func UnmarshalRule(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Rule) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "rule_type", &obj.RuleType) + if err != nil { + return + } + err = core.UnmarshalModel(m, "target", &obj.Target, UnmarshalTargetResource) + if err != nil { + return + } + err = core.UnmarshalModel(m, "required_config", &obj.RequiredConfig, UnmarshalRuleRequiredConfig) + if err != nil { + return + } + err = core.UnmarshalModel(m, "enforcement_actions", &obj.EnforcementActions, UnmarshalEnforcementAction) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "labels", &obj.Labels) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "rule_id", &obj.RuleID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "creation_date", &obj.CreationDate) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_by", &obj.CreatedBy) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "modification_date", &obj.ModificationDate) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "modified_by", &obj.ModifiedBy) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "number_of_attachments", &obj.NumberOfAttachments) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleCondition : RuleCondition struct +// Models which "extend" this model: +// - RuleConditionSingleProperty +// - RuleConditionOrLvl2 +// - RuleConditionAndLvl2 +type RuleCondition struct { + Description *string `json:"description,omitempty"` + + // A resource configuration variable that describes the property that you want to apply to the target resource. + // + // Available options depend on the target service and resource. Currently, + // `public_access_enabled` is supported. + Property *string `json:"property,omitempty"` + + // The way in which the `property` field is compared to its value. + // + // There are three types of operators: string, numeric, and boolean. + Operator *string `json:"operator,omitempty"` + + // The way in which you want your property to be applied. + // + // Value options differ depending on the rule that you configure. If you use a boolean operator, you do not need to + // input a value. + Value *string `json:"value,omitempty"` + + Or []RuleSingleProperty `json:"or,omitempty"` + + And []RuleSingleProperty `json:"and,omitempty"` +} + +// Constants associated with the RuleCondition.Operator property. +// The way in which the `property` field is compared to its value. +// +// There are three types of operators: string, numeric, and boolean. +const ( + RuleConditionOperatorIsEmptyConst = "is_empty" + RuleConditionOperatorIsFalseConst = "is_false" + RuleConditionOperatorIsNotEmptyConst = "is_not_empty" + RuleConditionOperatorIsTrueConst = "is_true" + RuleConditionOperatorNumEqualsConst = "num_equals" + RuleConditionOperatorNumGreaterThanConst = "num_greater_than" + RuleConditionOperatorNumGreaterThanEqualsConst = "num_greater_than_equals" + RuleConditionOperatorNumLessThanConst = "num_less_than" + RuleConditionOperatorNumLessThanEqualsConst = "num_less_than_equals" + RuleConditionOperatorNumNotEqualsConst = "num_not_equals" + RuleConditionOperatorStringEqualsConst = "string_equals" + RuleConditionOperatorStringMatchConst = "string_match" + RuleConditionOperatorStringNotEqualsConst = "string_not_equals" + RuleConditionOperatorStringNotMatchConst = "string_not_match" +) + +func (*RuleCondition) isaRuleCondition() bool { + return true +} + +type RuleConditionIntf interface { + isaRuleCondition() bool +} + +// UnmarshalRuleCondition unmarshals an instance of RuleCondition from the specified map of raw messages. +func UnmarshalRuleCondition(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleCondition) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "property", &obj.Property) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + err = core.UnmarshalModel(m, "or", &obj.Or, UnmarshalRuleSingleProperty) + if err != nil { + return + } + err = core.UnmarshalModel(m, "and", &obj.And, UnmarshalRuleSingleProperty) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleList : A list of rules. +type RuleList struct { + // The requested offset for the returned items. + Offset *int64 `json:"offset" validate:"required"` + + // The requested limit for the returned items. + Limit *int64 `json:"limit" validate:"required"` + + // The total number of available items. + TotalCount *int64 `json:"total_count" validate:"required"` + + // The first page of available items. + First *Link `json:"first" validate:"required"` + + // The last page of available items. + Last *Link `json:"last" validate:"required"` + + // An array of rules. + Rules []Rule `json:"rules" validate:"required"` +} + + +// UnmarshalRuleList unmarshals an instance of RuleList from the specified map of raw messages. +func UnmarshalRuleList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleList) + err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalLink) + if err != nil { + return + } + err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalLink) + if err != nil { + return + } + err = core.UnmarshalModel(m, "rules", &obj.Rules, UnmarshalRule) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleRequest : User-settable properties associated with a rule to be created or updated. +type RuleRequest struct { + // Your IBM Cloud account ID. + AccountID *string `json:"account_id,omitempty"` + + // A human-readable alias to assign to your rule. + Name *string `json:"name" validate:"required"` + + // An extended description of your rule. + Description *string `json:"description" validate:"required"` + + // The type of rule. Rules that you create are `user_defined`. + RuleType *string `json:"rule_type,omitempty"` + + // The properties that describe the resource that you want to target + // with the rule. + Target *TargetResource `json:"target" validate:"required"` + + RequiredConfig RuleRequiredConfigIntf `json:"required_config" validate:"required"` + + // The actions that the service must run on your behalf when a request to create or modify the target resource does not + // comply with your conditions. + EnforcementActions []EnforcementAction `json:"enforcement_actions" validate:"required"` + + // Labels that you can use to group and search for similar rules, such as those that help you to meet a specific + // organization guideline. + Labels []string `json:"labels,omitempty"` +} + +// Constants associated with the RuleRequest.RuleType property. +// The type of rule. Rules that you create are `user_defined`. +const ( + RuleRequestRuleTypeUserDefinedConst = "user_defined" +) + + +// NewRuleRequest : Instantiate RuleRequest (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleRequest(name string, description string, target *TargetResource, requiredConfig RuleRequiredConfigIntf, enforcementActions []EnforcementAction) (model *RuleRequest, err error) { + model = &RuleRequest{ + Name: core.StringPtr(name), + Description: core.StringPtr(description), + Target: target, + RequiredConfig: requiredConfig, + EnforcementActions: enforcementActions, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalRuleRequest unmarshals an instance of RuleRequest from the specified map of raw messages. +func UnmarshalRuleRequest(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleRequest) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "rule_type", &obj.RuleType) + if err != nil { + return + } + err = core.UnmarshalModel(m, "target", &obj.Target, UnmarshalTargetResource) + if err != nil { + return + } + err = core.UnmarshalModel(m, "required_config", &obj.RequiredConfig, UnmarshalRuleRequiredConfig) + if err != nil { + return + } + err = core.UnmarshalModel(m, "enforcement_actions", &obj.EnforcementActions, UnmarshalEnforcementAction) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "labels", &obj.Labels) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleRequiredConfig : RuleRequiredConfig struct +// Models which "extend" this model: +// - RuleRequiredConfigSingleProperty +// - RuleRequiredConfigMultipleProperties +type RuleRequiredConfig struct { + Description *string `json:"description,omitempty"` + + // A resource configuration variable that describes the property that you want to apply to the target resource. + // + // Available options depend on the target service and resource. Currently, + // `public_access_enabled` is supported. + Property *string `json:"property,omitempty"` + + // The way in which the `property` field is compared to its value. + // + // There are three types of operators: string, numeric, and boolean. + Operator *string `json:"operator,omitempty"` + + // The way in which you want your property to be applied. + // + // Value options differ depending on the rule that you configure. If you use a boolean operator, you do not need to + // input a value. + Value *string `json:"value,omitempty"` + + Or []RuleConditionIntf `json:"or,omitempty"` + + And []RuleConditionIntf `json:"and,omitempty"` +} + +// Constants associated with the RuleRequiredConfig.Operator property. +// The way in which the `property` field is compared to its value. +// +// There are three types of operators: string, numeric, and boolean. +const ( + RuleRequiredConfigOperatorIsEmptyConst = "is_empty" + RuleRequiredConfigOperatorIsFalseConst = "is_false" + RuleRequiredConfigOperatorIsNotEmptyConst = "is_not_empty" + RuleRequiredConfigOperatorIsTrueConst = "is_true" + RuleRequiredConfigOperatorNumEqualsConst = "num_equals" + RuleRequiredConfigOperatorNumGreaterThanConst = "num_greater_than" + RuleRequiredConfigOperatorNumGreaterThanEqualsConst = "num_greater_than_equals" + RuleRequiredConfigOperatorNumLessThanConst = "num_less_than" + RuleRequiredConfigOperatorNumLessThanEqualsConst = "num_less_than_equals" + RuleRequiredConfigOperatorNumNotEqualsConst = "num_not_equals" + RuleRequiredConfigOperatorStringEqualsConst = "string_equals" + RuleRequiredConfigOperatorStringMatchConst = "string_match" + RuleRequiredConfigOperatorStringNotEqualsConst = "string_not_equals" + RuleRequiredConfigOperatorStringNotMatchConst = "string_not_match" +) + +func (*RuleRequiredConfig) isaRuleRequiredConfig() bool { + return true +} + +type RuleRequiredConfigIntf interface { + isaRuleRequiredConfig() bool +} + +// UnmarshalRuleRequiredConfig unmarshals an instance of RuleRequiredConfig from the specified map of raw messages. +func UnmarshalRuleRequiredConfig(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleRequiredConfig) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "property", &obj.Property) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + err = core.UnmarshalModel(m, "or", &obj.Or, UnmarshalRuleCondition) + if err != nil { + return + } + err = core.UnmarshalModel(m, "and", &obj.And, UnmarshalRuleCondition) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleResponseError : RuleResponseError struct +type RuleResponseError struct { + // Specifies the problem that caused the error. + Code *string `json:"code" validate:"required"` + + // Describes the problem. + Message *string `json:"message" validate:"required"` +} + + +// UnmarshalRuleResponseError unmarshals an instance of RuleResponseError from the specified map of raw messages. +func UnmarshalRuleResponseError(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleResponseError) + err = core.UnmarshalPrimitive(m, "code", &obj.Code) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "message", &obj.Message) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleScope : The extent at which the rule can be attached across your accounts. +type RuleScope struct { + // A short description or alias to assign to the scope. + Note *string `json:"note,omitempty"` + + // The ID of the scope, such as an enterprise, account, or account group, that you want to evaluate. + ScopeID *string `json:"scope_id" validate:"required"` + + // The type of scope that you want to evaluate. + ScopeType *string `json:"scope_type" validate:"required"` +} + +// Constants associated with the RuleScope.ScopeType property. +// The type of scope that you want to evaluate. +const ( + RuleScopeScopeTypeAccountConst = "account" + RuleScopeScopeTypeAccountResourceGroupConst = "account.resource_group" + RuleScopeScopeTypeEnterpriseConst = "enterprise" + RuleScopeScopeTypeEnterpriseAccountConst = "enterprise.account" + RuleScopeScopeTypeEnterpriseAccountGroupConst = "enterprise.account_group" +) + + +// NewRuleScope : Instantiate RuleScope (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleScope(scopeID string, scopeType string) (model *RuleScope, err error) { + model = &RuleScope{ + ScopeID: core.StringPtr(scopeID), + ScopeType: core.StringPtr(scopeType), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalRuleScope unmarshals an instance of RuleScope from the specified map of raw messages. +func UnmarshalRuleScope(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleScope) + err = core.UnmarshalPrimitive(m, "note", &obj.Note) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "scope_id", &obj.ScopeID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "scope_type", &obj.ScopeType) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleSingleProperty : The requirement that must be met to determine the resource's level of compliance in accordance with the rule. +// +// To apply a single property check, define a configuration property and the desired value that you want to check +// against. +type RuleSingleProperty struct { + Description *string `json:"description,omitempty"` + + // A resource configuration variable that describes the property that you want to apply to the target resource. + // + // Available options depend on the target service and resource. Currently, + // `public_access_enabled` is supported. + Property *string `json:"property" validate:"required"` + + // The way in which the `property` field is compared to its value. + // + // There are three types of operators: string, numeric, and boolean. + Operator *string `json:"operator" validate:"required"` + + // The way in which you want your property to be applied. + // + // Value options differ depending on the rule that you configure. If you use a boolean operator, you do not need to + // input a value. + Value *string `json:"value,omitempty"` +} + +// Constants associated with the RuleSingleProperty.Operator property. +// The way in which the `property` field is compared to its value. +// +// There are three types of operators: string, numeric, and boolean. +const ( + RuleSinglePropertyOperatorIsEmptyConst = "is_empty" + RuleSinglePropertyOperatorIsFalseConst = "is_false" + RuleSinglePropertyOperatorIsNotEmptyConst = "is_not_empty" + RuleSinglePropertyOperatorIsTrueConst = "is_true" + RuleSinglePropertyOperatorNumEqualsConst = "num_equals" + RuleSinglePropertyOperatorNumGreaterThanConst = "num_greater_than" + RuleSinglePropertyOperatorNumGreaterThanEqualsConst = "num_greater_than_equals" + RuleSinglePropertyOperatorNumLessThanConst = "num_less_than" + RuleSinglePropertyOperatorNumLessThanEqualsConst = "num_less_than_equals" + RuleSinglePropertyOperatorNumNotEqualsConst = "num_not_equals" + RuleSinglePropertyOperatorStringEqualsConst = "string_equals" + RuleSinglePropertyOperatorStringMatchConst = "string_match" + RuleSinglePropertyOperatorStringNotEqualsConst = "string_not_equals" + RuleSinglePropertyOperatorStringNotMatchConst = "string_not_match" +) + + +// NewRuleSingleProperty : Instantiate RuleSingleProperty (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleSingleProperty(property string, operator string) (model *RuleSingleProperty, err error) { + model = &RuleSingleProperty{ + Property: core.StringPtr(property), + Operator: core.StringPtr(operator), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalRuleSingleProperty unmarshals an instance of RuleSingleProperty from the specified map of raw messages. +func UnmarshalRuleSingleProperty(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleSingleProperty) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "property", &obj.Property) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleTargetAttribute : The attributes that are associated with a rule target. +type RuleTargetAttribute struct { + Name *string `json:"name" validate:"required"` + + // The way in which the `name` field is compared to its value. + // + // There are three types of operators: string, numeric, and boolean. + Operator *string `json:"operator" validate:"required"` + + // The way in which you want your property to be applied. + // + // Value options differ depending on the rule that you configure. If you use a boolean operator, you do not need to + // input a value. + Value *string `json:"value,omitempty"` +} + +// Constants associated with the RuleTargetAttribute.Operator property. +// The way in which the `name` field is compared to its value. +// +// There are three types of operators: string, numeric, and boolean. +const ( + RuleTargetAttributeOperatorIsEmptyConst = "is_empty" + RuleTargetAttributeOperatorIsFalseConst = "is_false" + RuleTargetAttributeOperatorIsNotEmptyConst = "is_not_empty" + RuleTargetAttributeOperatorIsTrueConst = "is_true" + RuleTargetAttributeOperatorNumEqualsConst = "num_equals" + RuleTargetAttributeOperatorNumGreaterThanConst = "num_greater_than" + RuleTargetAttributeOperatorNumGreaterThanEqualsConst = "num_greater_than_equals" + RuleTargetAttributeOperatorNumLessThanConst = "num_less_than" + RuleTargetAttributeOperatorNumLessThanEqualsConst = "num_less_than_equals" + RuleTargetAttributeOperatorNumNotEqualsConst = "num_not_equals" + RuleTargetAttributeOperatorStringEqualsConst = "string_equals" + RuleTargetAttributeOperatorStringMatchConst = "string_match" + RuleTargetAttributeOperatorStringNotEqualsConst = "string_not_equals" + RuleTargetAttributeOperatorStringNotMatchConst = "string_not_match" +) + + +// NewRuleTargetAttribute : Instantiate RuleTargetAttribute (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleTargetAttribute(name string, operator string) (model *RuleTargetAttribute, err error) { + model = &RuleTargetAttribute{ + Name: core.StringPtr(name), + Operator: core.StringPtr(operator), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalRuleTargetAttribute unmarshals an instance of RuleTargetAttribute from the specified map of raw messages. +func UnmarshalRuleTargetAttribute(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleTargetAttribute) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// TargetResource : The properties that describe the resource that you want to target with the rule. +type TargetResource struct { + // The programmatic name of the IBM Cloud service that you want to target with the rule. Currently, `iam-groups` is + // supported. + ServiceName *string `json:"service_name" validate:"required"` + + // The type of resource that you want to target. + ResourceKind *string `json:"resource_kind" validate:"required"` + + // An extra qualifier for the resource kind. When you include additional attributes, only the resources that match the + // definition are included in the rule. + AdditionalTargetAttributes []RuleTargetAttribute `json:"additional_target_attributes,omitempty"` +} + + +// NewTargetResource : Instantiate TargetResource (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewTargetResource(serviceName string, resourceKind string) (model *TargetResource, err error) { + model = &TargetResource{ + ServiceName: core.StringPtr(serviceName), + ResourceKind: core.StringPtr(resourceKind), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalTargetResource unmarshals an instance of TargetResource from the specified map of raw messages. +func UnmarshalTargetResource(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(TargetResource) + err = core.UnmarshalPrimitive(m, "service_name", &obj.ServiceName) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "resource_kind", &obj.ResourceKind) + if err != nil { + return + } + err = core.UnmarshalModel(m, "additional_target_attributes", &obj.AdditionalTargetAttributes, UnmarshalRuleTargetAttribute) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// UpdateAttachmentOptions : The UpdateAttachment options. +type UpdateAttachmentOptions struct { + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + // The UUID that uniquely identifies the attachment. + AttachmentID *string `json:"attachment_id" validate:"required"` + + // Compares a supplied `Etag` value with the version that is stored for the requested resource. If the values match, + // the server allows the request method to continue. + // + // To find the `Etag` value, run a GET request on the resource that you want to modify, and check the response headers. + IfMatch *string `json:"If-Match" validate:"required"` + + // Your IBM Cloud account ID. + AccountID *string `json:"account_id" validate:"required"` + + // The extent at which the rule can be attached across your accounts. + IncludedScope *RuleScope `json:"included_scope" validate:"required"` + + // The extent at which the rule can be excluded from the included scope. + ExcludedScopes []RuleScope `json:"excluded_scopes,omitempty"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewUpdateAttachmentOptions : Instantiate UpdateAttachmentOptions +func (*ConfigurationGovernanceV1) NewUpdateAttachmentOptions(ruleID string, attachmentID string, ifMatch string, accountID string, includedScope *RuleScope) *UpdateAttachmentOptions { + return &UpdateAttachmentOptions{ + RuleID: core.StringPtr(ruleID), + AttachmentID: core.StringPtr(attachmentID), + IfMatch: core.StringPtr(ifMatch), + AccountID: core.StringPtr(accountID), + IncludedScope: includedScope, + } +} + +// SetRuleID : Allow user to set RuleID +func (options *UpdateAttachmentOptions) SetRuleID(ruleID string) *UpdateAttachmentOptions { + options.RuleID = core.StringPtr(ruleID) + return options +} + +// SetAttachmentID : Allow user to set AttachmentID +func (options *UpdateAttachmentOptions) SetAttachmentID(attachmentID string) *UpdateAttachmentOptions { + options.AttachmentID = core.StringPtr(attachmentID) + return options +} + +// SetIfMatch : Allow user to set IfMatch +func (options *UpdateAttachmentOptions) SetIfMatch(ifMatch string) *UpdateAttachmentOptions { + options.IfMatch = core.StringPtr(ifMatch) + return options +} + +// SetAccountID : Allow user to set AccountID +func (options *UpdateAttachmentOptions) SetAccountID(accountID string) *UpdateAttachmentOptions { + options.AccountID = core.StringPtr(accountID) + return options +} + +// SetIncludedScope : Allow user to set IncludedScope +func (options *UpdateAttachmentOptions) SetIncludedScope(includedScope *RuleScope) *UpdateAttachmentOptions { + options.IncludedScope = includedScope + return options +} + +// SetExcludedScopes : Allow user to set ExcludedScopes +func (options *UpdateAttachmentOptions) SetExcludedScopes(excludedScopes []RuleScope) *UpdateAttachmentOptions { + options.ExcludedScopes = excludedScopes + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *UpdateAttachmentOptions) SetTransactionID(transactionID string) *UpdateAttachmentOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *UpdateAttachmentOptions) SetHeaders(param map[string]string) *UpdateAttachmentOptions { + options.Headers = param + return options +} + +// UpdateRuleOptions : The UpdateRule options. +type UpdateRuleOptions struct { + // The UUID that uniquely identifies the rule. + RuleID *string `json:"rule_id" validate:"required"` + + // Compares a supplied `Etag` value with the version that is stored for the requested resource. If the values match, + // the server allows the request method to continue. + // + // To find the `Etag` value, run a GET request on the resource that you want to modify, and check the response headers. + IfMatch *string `json:"If-Match" validate:"required"` + + // A human-readable alias to assign to your rule. + Name *string `json:"name" validate:"required"` + + // An extended description of your rule. + Description *string `json:"description" validate:"required"` + + // The properties that describe the resource that you want to target + // with the rule. + Target *TargetResource `json:"target" validate:"required"` + + RequiredConfig RuleRequiredConfigIntf `json:"required_config" validate:"required"` + + // The actions that the service must run on your behalf when a request to create or modify the target resource does not + // comply with your conditions. + EnforcementActions []EnforcementAction `json:"enforcement_actions" validate:"required"` + + // Your IBM Cloud account ID. + AccountID *string `json:"account_id,omitempty"` + + // The type of rule. Rules that you create are `user_defined`. + RuleType *string `json:"rule_type,omitempty"` + + // Labels that you can use to group and search for similar rules, such as those that help you to meet a specific + // organization guideline. + Labels []string `json:"labels,omitempty"` + + // The unique identifier that is used to trace an entire request. If you omit this field, the service generates and + // sends a transaction ID in the + // `trace` field of the response body. + // + // **Note:** To help with debugging logs, it is strongly recommended that you generate and supply a `Transaction-Id` + // with each request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// Constants associated with the UpdateRuleOptions.RuleType property. +// The type of rule. Rules that you create are `user_defined`. +const ( + UpdateRuleOptionsRuleTypeUserDefinedConst = "user_defined" +) + +// NewUpdateRuleOptions : Instantiate UpdateRuleOptions +func (*ConfigurationGovernanceV1) NewUpdateRuleOptions(ruleID string, ifMatch string, name string, description string, target *TargetResource, requiredConfig RuleRequiredConfigIntf, enforcementActions []EnforcementAction) *UpdateRuleOptions { + return &UpdateRuleOptions{ + RuleID: core.StringPtr(ruleID), + IfMatch: core.StringPtr(ifMatch), + Name: core.StringPtr(name), + Description: core.StringPtr(description), + Target: target, + RequiredConfig: requiredConfig, + EnforcementActions: enforcementActions, + } +} + +// SetRuleID : Allow user to set RuleID +func (options *UpdateRuleOptions) SetRuleID(ruleID string) *UpdateRuleOptions { + options.RuleID = core.StringPtr(ruleID) + return options +} + +// SetIfMatch : Allow user to set IfMatch +func (options *UpdateRuleOptions) SetIfMatch(ifMatch string) *UpdateRuleOptions { + options.IfMatch = core.StringPtr(ifMatch) + return options +} + +// SetName : Allow user to set Name +func (options *UpdateRuleOptions) SetName(name string) *UpdateRuleOptions { + options.Name = core.StringPtr(name) + return options +} + +// SetDescription : Allow user to set Description +func (options *UpdateRuleOptions) SetDescription(description string) *UpdateRuleOptions { + options.Description = core.StringPtr(description) + return options +} + +// SetTarget : Allow user to set Target +func (options *UpdateRuleOptions) SetTarget(target *TargetResource) *UpdateRuleOptions { + options.Target = target + return options +} + +// SetRequiredConfig : Allow user to set RequiredConfig +func (options *UpdateRuleOptions) SetRequiredConfig(requiredConfig RuleRequiredConfigIntf) *UpdateRuleOptions { + options.RequiredConfig = requiredConfig + return options +} + +// SetEnforcementActions : Allow user to set EnforcementActions +func (options *UpdateRuleOptions) SetEnforcementActions(enforcementActions []EnforcementAction) *UpdateRuleOptions { + options.EnforcementActions = enforcementActions + return options +} + +// SetAccountID : Allow user to set AccountID +func (options *UpdateRuleOptions) SetAccountID(accountID string) *UpdateRuleOptions { + options.AccountID = core.StringPtr(accountID) + return options +} + +// SetRuleType : Allow user to set RuleType +func (options *UpdateRuleOptions) SetRuleType(ruleType string) *UpdateRuleOptions { + options.RuleType = core.StringPtr(ruleType) + return options +} + +// SetLabels : Allow user to set Labels +func (options *UpdateRuleOptions) SetLabels(labels []string) *UpdateRuleOptions { + options.Labels = labels + return options +} + +// SetTransactionID : Allow user to set TransactionID +func (options *UpdateRuleOptions) SetTransactionID(transactionID string) *UpdateRuleOptions { + options.TransactionID = core.StringPtr(transactionID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *UpdateRuleOptions) SetHeaders(param map[string]string) *UpdateRuleOptions { + options.Headers = param + return options +} + +// RuleConditionAndLvl2 : A condition with the `and` logical operator. +// This model "extends" RuleCondition +type RuleConditionAndLvl2 struct { + Description *string `json:"description,omitempty"` + + And []RuleSingleProperty `json:"and" validate:"required"` +} + + +// NewRuleConditionAndLvl2 : Instantiate RuleConditionAndLvl2 (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleConditionAndLvl2(and []RuleSingleProperty) (model *RuleConditionAndLvl2, err error) { + model = &RuleConditionAndLvl2{ + And: and, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*RuleConditionAndLvl2) isaRuleCondition() bool { + return true +} + +// UnmarshalRuleConditionAndLvl2 unmarshals an instance of RuleConditionAndLvl2 from the specified map of raw messages. +func UnmarshalRuleConditionAndLvl2(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleConditionAndLvl2) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalModel(m, "and", &obj.And, UnmarshalRuleSingleProperty) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleConditionOrLvl2 : A condition with the `or` logical operator. +// This model "extends" RuleCondition +type RuleConditionOrLvl2 struct { + Description *string `json:"description,omitempty"` + + Or []RuleSingleProperty `json:"or" validate:"required"` +} + + +// NewRuleConditionOrLvl2 : Instantiate RuleConditionOrLvl2 (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleConditionOrLvl2(or []RuleSingleProperty) (model *RuleConditionOrLvl2, err error) { + model = &RuleConditionOrLvl2{ + Or: or, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*RuleConditionOrLvl2) isaRuleCondition() bool { + return true +} + +// UnmarshalRuleConditionOrLvl2 unmarshals an instance of RuleConditionOrLvl2 from the specified map of raw messages. +func UnmarshalRuleConditionOrLvl2(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleConditionOrLvl2) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalModel(m, "or", &obj.Or, UnmarshalRuleSingleProperty) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleConditionSingleProperty : The requirement that must be met to determine the resource's level of compliance in accordance with the rule. +// +// To apply a single property check, define a configuration property and the desired value that you want to check +// against. +// This model "extends" RuleCondition +type RuleConditionSingleProperty struct { + Description *string `json:"description,omitempty"` + + // A resource configuration variable that describes the property that you want to apply to the target resource. + // + // Available options depend on the target service and resource. Currently, + // `public_access_enabled` is supported. + Property *string `json:"property" validate:"required"` + + // The way in which the `property` field is compared to its value. + // + // There are three types of operators: string, numeric, and boolean. + Operator *string `json:"operator" validate:"required"` + + // The way in which you want your property to be applied. + // + // Value options differ depending on the rule that you configure. If you use a boolean operator, you do not need to + // input a value. + Value *string `json:"value,omitempty"` +} + +// Constants associated with the RuleConditionSingleProperty.Operator property. +// The way in which the `property` field is compared to its value. +// +// There are three types of operators: string, numeric, and boolean. +const ( + RuleConditionSinglePropertyOperatorIsEmptyConst = "is_empty" + RuleConditionSinglePropertyOperatorIsFalseConst = "is_false" + RuleConditionSinglePropertyOperatorIsNotEmptyConst = "is_not_empty" + RuleConditionSinglePropertyOperatorIsTrueConst = "is_true" + RuleConditionSinglePropertyOperatorNumEqualsConst = "num_equals" + RuleConditionSinglePropertyOperatorNumGreaterThanConst = "num_greater_than" + RuleConditionSinglePropertyOperatorNumGreaterThanEqualsConst = "num_greater_than_equals" + RuleConditionSinglePropertyOperatorNumLessThanConst = "num_less_than" + RuleConditionSinglePropertyOperatorNumLessThanEqualsConst = "num_less_than_equals" + RuleConditionSinglePropertyOperatorNumNotEqualsConst = "num_not_equals" + RuleConditionSinglePropertyOperatorStringEqualsConst = "string_equals" + RuleConditionSinglePropertyOperatorStringMatchConst = "string_match" + RuleConditionSinglePropertyOperatorStringNotEqualsConst = "string_not_equals" + RuleConditionSinglePropertyOperatorStringNotMatchConst = "string_not_match" +) + + +// NewRuleConditionSingleProperty : Instantiate RuleConditionSingleProperty (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleConditionSingleProperty(property string, operator string) (model *RuleConditionSingleProperty, err error) { + model = &RuleConditionSingleProperty{ + Property: core.StringPtr(property), + Operator: core.StringPtr(operator), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*RuleConditionSingleProperty) isaRuleCondition() bool { + return true +} + +// UnmarshalRuleConditionSingleProperty unmarshals an instance of RuleConditionSingleProperty from the specified map of raw messages. +func UnmarshalRuleConditionSingleProperty(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleConditionSingleProperty) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "property", &obj.Property) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleRequiredConfigMultipleProperties : The requirements that must be met to determine the resource's level of compliance in accordance with the rule. +// +// Use logical operators (`and`/`or`) to define multiple property checks and conditions. To define requirements for a +// rule, list one or more property check objects in the `and` array. To add conditions to a property check, use `or`. +// Models which "extend" this model: +// - RuleRequiredConfigMultiplePropertiesConditionOr +// - RuleRequiredConfigMultiplePropertiesConditionAnd +// This model "extends" RuleRequiredConfig +type RuleRequiredConfigMultipleProperties struct { + Description *string `json:"description,omitempty"` + + Or []RuleConditionIntf `json:"or,omitempty"` + + And []RuleConditionIntf `json:"and,omitempty"` +} + +func (*RuleRequiredConfigMultipleProperties) isaRuleRequiredConfigMultipleProperties() bool { + return true +} + +type RuleRequiredConfigMultiplePropertiesIntf interface { + RuleRequiredConfigIntf + isaRuleRequiredConfigMultipleProperties() bool +} + +func (*RuleRequiredConfigMultipleProperties) isaRuleRequiredConfig() bool { + return true +} + +// UnmarshalRuleRequiredConfigMultipleProperties unmarshals an instance of RuleRequiredConfigMultipleProperties from the specified map of raw messages. +func UnmarshalRuleRequiredConfigMultipleProperties(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleRequiredConfigMultipleProperties) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalModel(m, "or", &obj.Or, UnmarshalRuleCondition) + if err != nil { + return + } + err = core.UnmarshalModel(m, "and", &obj.And, UnmarshalRuleCondition) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleRequiredConfigSingleProperty : The requirement that must be met to determine the resource's level of compliance in accordance with the rule. +// +// To apply a single property check, define a configuration property and the desired value that you want to check +// against. +// This model "extends" RuleRequiredConfig +type RuleRequiredConfigSingleProperty struct { + Description *string `json:"description,omitempty"` + + // A resource configuration variable that describes the property that you want to apply to the target resource. + // + // Available options depend on the target service and resource. Currently, + // `public_access_enabled` is supported. + Property *string `json:"property" validate:"required"` + + // The way in which the `property` field is compared to its value. + // + // There are three types of operators: string, numeric, and boolean. + Operator *string `json:"operator" validate:"required"` + + // The way in which you want your property to be applied. + // + // Value options differ depending on the rule that you configure. If you use a boolean operator, you do not need to + // input a value. + Value *string `json:"value,omitempty"` +} + +// Constants associated with the RuleRequiredConfigSingleProperty.Operator property. +// The way in which the `property` field is compared to its value. +// +// There are three types of operators: string, numeric, and boolean. +const ( + RuleRequiredConfigSinglePropertyOperatorIsEmptyConst = "is_empty" + RuleRequiredConfigSinglePropertyOperatorIsFalseConst = "is_false" + RuleRequiredConfigSinglePropertyOperatorIsNotEmptyConst = "is_not_empty" + RuleRequiredConfigSinglePropertyOperatorIsTrueConst = "is_true" + RuleRequiredConfigSinglePropertyOperatorNumEqualsConst = "num_equals" + RuleRequiredConfigSinglePropertyOperatorNumGreaterThanConst = "num_greater_than" + RuleRequiredConfigSinglePropertyOperatorNumGreaterThanEqualsConst = "num_greater_than_equals" + RuleRequiredConfigSinglePropertyOperatorNumLessThanConst = "num_less_than" + RuleRequiredConfigSinglePropertyOperatorNumLessThanEqualsConst = "num_less_than_equals" + RuleRequiredConfigSinglePropertyOperatorNumNotEqualsConst = "num_not_equals" + RuleRequiredConfigSinglePropertyOperatorStringEqualsConst = "string_equals" + RuleRequiredConfigSinglePropertyOperatorStringMatchConst = "string_match" + RuleRequiredConfigSinglePropertyOperatorStringNotEqualsConst = "string_not_equals" + RuleRequiredConfigSinglePropertyOperatorStringNotMatchConst = "string_not_match" +) + + +// NewRuleRequiredConfigSingleProperty : Instantiate RuleRequiredConfigSingleProperty (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleRequiredConfigSingleProperty(property string, operator string) (model *RuleRequiredConfigSingleProperty, err error) { + model = &RuleRequiredConfigSingleProperty{ + Property: core.StringPtr(property), + Operator: core.StringPtr(operator), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*RuleRequiredConfigSingleProperty) isaRuleRequiredConfig() bool { + return true +} + +// UnmarshalRuleRequiredConfigSingleProperty unmarshals an instance of RuleRequiredConfigSingleProperty from the specified map of raw messages. +func UnmarshalRuleRequiredConfigSingleProperty(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleRequiredConfigSingleProperty) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "property", &obj.Property) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleRequiredConfigMultiplePropertiesConditionAnd : A condition with the `and` logical operator. +// This model "extends" RuleRequiredConfigMultipleProperties +type RuleRequiredConfigMultiplePropertiesConditionAnd struct { + Description *string `json:"description,omitempty"` + + And []RuleConditionIntf `json:"and" validate:"required"` +} + + +// NewRuleRequiredConfigMultiplePropertiesConditionAnd : Instantiate RuleRequiredConfigMultiplePropertiesConditionAnd (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleRequiredConfigMultiplePropertiesConditionAnd(and []RuleConditionIntf) (model *RuleRequiredConfigMultiplePropertiesConditionAnd, err error) { + model = &RuleRequiredConfigMultiplePropertiesConditionAnd{ + And: and, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*RuleRequiredConfigMultiplePropertiesConditionAnd) isaRuleRequiredConfigMultipleProperties() bool { + return true +} + +func (*RuleRequiredConfigMultiplePropertiesConditionAnd) isaRuleRequiredConfig() bool { + return true +} + +// UnmarshalRuleRequiredConfigMultiplePropertiesConditionAnd unmarshals an instance of RuleRequiredConfigMultiplePropertiesConditionAnd from the specified map of raw messages. +func UnmarshalRuleRequiredConfigMultiplePropertiesConditionAnd(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleRequiredConfigMultiplePropertiesConditionAnd) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalModel(m, "and", &obj.And, UnmarshalRuleCondition) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RuleRequiredConfigMultiplePropertiesConditionOr : A condition with the `or` logical operator. +// This model "extends" RuleRequiredConfigMultipleProperties +type RuleRequiredConfigMultiplePropertiesConditionOr struct { + Description *string `json:"description,omitempty"` + + Or []RuleConditionIntf `json:"or" validate:"required"` +} + + +// NewRuleRequiredConfigMultiplePropertiesConditionOr : Instantiate RuleRequiredConfigMultiplePropertiesConditionOr (Generic Model Constructor) +func (*ConfigurationGovernanceV1) NewRuleRequiredConfigMultiplePropertiesConditionOr(or []RuleConditionIntf) (model *RuleRequiredConfigMultiplePropertiesConditionOr, err error) { + model = &RuleRequiredConfigMultiplePropertiesConditionOr{ + Or: or, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*RuleRequiredConfigMultiplePropertiesConditionOr) isaRuleRequiredConfigMultipleProperties() bool { + return true +} + +func (*RuleRequiredConfigMultiplePropertiesConditionOr) isaRuleRequiredConfig() bool { + return true +} + +// UnmarshalRuleRequiredConfigMultiplePropertiesConditionOr unmarshals an instance of RuleRequiredConfigMultiplePropertiesConditionOr from the specified map of raw messages. +func UnmarshalRuleRequiredConfigMultiplePropertiesConditionOr(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleRequiredConfigMultiplePropertiesConditionOr) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalModel(m, "or", &obj.Or, UnmarshalRuleCondition) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} diff --git a/configurationgovernancev1/configuration_governance_v1_examples_test.go b/configurationgovernancev1/configuration_governance_v1_examples_test.go new file mode 100644 index 00000000..f3d133c7 --- /dev/null +++ b/configurationgovernancev1/configuration_governance_v1_examples_test.go @@ -0,0 +1,472 @@ +// +build examples + +/** + * (C) Copyright IBM Corp. 2020. + * + * 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 configurationgovernancev1_test + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/IBM/go-sdk-core/v4/core" + "github.com/IBM/platform-services-go-sdk/configurationgovernancev1" + "github.com/google/uuid" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +// This file provides an example of how to use the Configuration Governance service. +// +// The following configuration properties are assumed to be defined in the external configuration file: +// CONFIGURATION_GOVERNANCE_URL= +// CONFIGURATION_GOVERNANCE_AUTHTYPE=iam +// CONFIGURATION_GOVERNANCE_APIKEY= +// CONFIGURATION_GOVERNANCE_AUTH_URL= +// CONFIGURATION_GOVERNANCE_ACCOUNT_ID= +// CONFIGURATION_GOVERNANCE_EXAMPLE_SERVICE_NAME= +// CONFIGURATION_GOVERNANCE_ENTERPRISE_SCOPE_ID= +// CONFIGURATION_GOVERNANCE_SUBACCT_SCOPE_ID= +// + +const externalConfigFile = "../configuration_governance.env" + +var ( + configurationGovernanceService *configurationgovernancev1.ConfigurationGovernanceV1 + config map[string]string + configLoaded bool = false + + // Test-related configuration properties. + accountID string + serviceName string + enterpriseScopeID string + subacctScopeID string +) + +// Global variables to hold various values shared between operations +var ( + ruleIDLink string + ruleToUpdateLink *configurationgovernancev1.Rule + ruleToUpdateEtagLink string + + attachmentIDLink string + attachmentToUpdateLink *configurationgovernancev1.Attachment + attachmentToUpdateEtagLink string +) + +func shouldSkipTest() { + if !configLoaded { + Skip("External configuration is not available, skipping tests...") + } +} + +var _ = Describe(`ConfigurationGovernanceV1 Examples Tests`, func() { + Describe(`External configuration`, func() { + It("Successfully load the configuration", func() { + var err error + _, err = os.Stat(externalConfigFile) + if err != nil { + Skip("External configuration file not found, skipping tests: " + err.Error()) + } + + os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile) + config, err = core.GetServiceProperties(configurationgovernancev1.DefaultServiceName) + if err != nil { + Skip("Error loading service properties, skipping tests: " + err.Error()) + } + + configLoaded = len(config) > 0 + + if configLoaded { + // Retrieve test-related properties from the external configuration. + accountID = config["ACCOUNT_ID"] + serviceName = config["EXAMPLE_SERVICE_NAME"] + enterpriseScopeID = config["ENTERPRISE_SCOPE_ID"] + subacctScopeID = config["SUBACCT_SCOPE_ID"] + } + }) + }) + + Describe(`Client initialization`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It("Successfully construct the service client instance", func() { + var err error + + // begin-common + + configurationGovernanceServiceOptions := &configurationgovernancev1.ConfigurationGovernanceV1Options{} + + configurationGovernanceService, err = + configurationgovernancev1.NewConfigurationGovernanceV1UsingExternalConfig( + configurationGovernanceServiceOptions, + ) + if err != nil { + panic(err) + } + + // end-common + + Expect(configurationGovernanceService).ToNot(BeNil()) + }) + }) + + Describe(`ConfigurationGovernanceV1 request examples`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CreateRules request example`, func() { + // begin-create_rules + + ruleRequestModel := &configurationgovernancev1.RuleRequest{ + AccountID: &accountID, + Name: core.StringPtr("Disable public access"), + Description: core.StringPtr("Ensure that public access to account resources is disabled."), + Target: &configurationgovernancev1.TargetResource{ + ServiceName: &serviceName, + ResourceKind: core.StringPtr("service"), + }, + RequiredConfig: &configurationgovernancev1.RuleRequiredConfigSingleProperty{ + Description: core.StringPtr("Ensure public access is disabled."), + Property: core.StringPtr("public_access_enabled"), + Operator: core.StringPtr("is_false"), + }, + EnforcementActions: []configurationgovernancev1.EnforcementAction{ + configurationgovernancev1.EnforcementAction{ + Action: core.StringPtr("audit_log"), + }, + configurationgovernancev1.EnforcementAction{ + Action: core.StringPtr("disallow"), + }, + }, + Labels: []string{"test_label"}, + } + + createRulesOptions := configurationGovernanceService.NewCreateRulesOptions( + []configurationgovernancev1.CreateRuleRequest{ + configurationgovernancev1.CreateRuleRequest{ + Rule: ruleRequestModel, + }, + }, + ) + createRulesOptions.SetTransactionID(uuid.New().String()) + + createRulesResponse, response, err := configurationGovernanceService.CreateRules(createRulesOptions) + // For a 207 status code, check the response entry for an error + if response.StatusCode == 207 { + for _, responseEntry := range createRulesResponse.Rules { + if *responseEntry.StatusCode > int64(299) { + err = fmt.Errorf("%s: %s", *responseEntry.Errors[0].Code, *responseEntry.Errors[0].Message) + } + } + } + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(createRulesResponse, "", " ") + fmt.Printf("\nCreateRules() result:\n%s\n", string(b)) + + // end-create_rules + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createRulesResponse).ToNot(BeNil()) + Expect(createRulesResponse.Rules).ToNot(BeEmpty()) + Expect(createRulesResponse.Rules[0]).ToNot(BeNil()) + Expect(createRulesResponse.Rules[0].Rule).ToNot(BeNil()) + Expect(createRulesResponse.Rules[0].Rule.RuleID).ToNot(BeNil()) + + ruleIDLink = *createRulesResponse.Rules[0].Rule.RuleID + Expect(ruleIDLink).ToNot(BeEmpty()) + }) + It(`ListRules request example`, func() { + // begin-list_rules + + listRulesOptions := configurationGovernanceService.NewListRulesOptions( + accountID, + ) + listRulesOptions.SetLabels("test_label") + listRulesOptions.SetTransactionID(uuid.New().String()) + + ruleList, response, err := configurationGovernanceService.ListRules(listRulesOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(ruleList, "", " ") + fmt.Printf("\nListRules() result:\n%s\n", string(b)) + + // end-list_rules + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(ruleList).ToNot(BeNil()) + + }) + It(`GetRule request example`, func() { + Expect(ruleIDLink).ToNot(BeEmpty()) + + // begin-get_rule + + getRuleOptions := configurationGovernanceService.NewGetRuleOptions( + ruleIDLink, + ) + getRuleOptions.SetTransactionID(uuid.New().String()) + + rule, response, err := configurationGovernanceService.GetRule(getRuleOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(rule, "", " ") + fmt.Printf("\nGetRule() result:\n%s\n", string(b)) + + // end-get_rule + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(rule).ToNot(BeNil()) + + ruleToUpdateLink = rule + + // Retrieve the Etag header from the response for use in the UpdateRule() operation. + ruleToUpdateEtagLink = response.GetHeaders().Get("Etag") + Expect(ruleToUpdateEtagLink).ToNot(BeEmpty()) + + }) + It(`UpdateRule request example`, func() { + Expect(ruleIDLink).ToNot(BeEmpty()) + Expect(ruleToUpdateLink).ToNot(BeNil()) + Expect(ruleToUpdateEtagLink).ToNot(BeEmpty()) + + // begin-update_rule + + // Update the existing rule's description. + updateRuleOptions := configurationGovernanceService.NewUpdateRuleOptions( + ruleIDLink, + ruleToUpdateEtagLink, + *ruleToUpdateLink.Name, + "This is an updated description.", + ruleToUpdateLink.Target, + ruleToUpdateLink.RequiredConfig, + ruleToUpdateLink.EnforcementActions, + ) + updateRuleOptions.SetAccountID(*ruleToUpdateLink.AccountID) + updateRuleOptions.SetRuleType(*ruleToUpdateLink.RuleType) + updateRuleOptions.SetLabels(ruleToUpdateLink.Labels) + updateRuleOptions.SetTransactionID(uuid.New().String()) + + rule, response, err := configurationGovernanceService.UpdateRule(updateRuleOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(rule, "", " ") + fmt.Printf("\nUpdateRule() result:\n%s\n", string(b)) + + // end-update_rule + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(rule).ToNot(BeNil()) + + }) + It(`CreateAttachments request example`, func() { + Expect(ruleIDLink).ToNot(BeEmpty()) + + // begin-create_attachments + + createAttachmentRequest := configurationgovernancev1.AttachmentRequest{ + AccountID: &accountID, + IncludedScope: &configurationgovernancev1.RuleScope{ + Note: core.StringPtr("My enterprise"), + ScopeID: &enterpriseScopeID, + ScopeType: core.StringPtr("enterprise"), + }, + ExcludedScopes: []configurationgovernancev1.RuleScope{ + configurationgovernancev1.RuleScope{ + Note: core.StringPtr("leaf account"), + ScopeID: &subacctScopeID, + ScopeType: core.StringPtr("enterprise.account"), + }, + }, + } + + createAttachmentsOptions := configurationGovernanceService.NewCreateAttachmentsOptions( + ruleIDLink, + []configurationgovernancev1.AttachmentRequest{ + createAttachmentRequest, + }, + ) + createAttachmentsOptions.SetTransactionID(uuid.New().String()) + + createAttachmentsResponse, response, err := configurationGovernanceService.CreateAttachments(createAttachmentsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(createAttachmentsResponse, "", " ") + fmt.Printf("\nCreateAttachments() result:\n%s\n", string(b)) + + // end-create_attachments + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createAttachmentsResponse).ToNot(BeNil()) + Expect(createAttachmentsResponse.Attachments).ToNot(BeEmpty()) + Expect(createAttachmentsResponse.Attachments[0]).ToNot(BeNil()) + Expect(createAttachmentsResponse.Attachments[0].AttachmentID).ToNot(BeNil()) + + attachmentIDLink = *createAttachmentsResponse.Attachments[0].AttachmentID + Expect(attachmentIDLink).ToNot(BeEmpty()) + + }) + It(`ListAttachments request example`, func() { + Expect(ruleIDLink).ToNot(BeEmpty()) + + // begin-list_attachments + + listAttachmentsOptions := configurationGovernanceService.NewListAttachmentsOptions( + ruleIDLink, + ) + listAttachmentsOptions.SetTransactionID(uuid.New().String()) + + attachmentList, response, err := configurationGovernanceService.ListAttachments(listAttachmentsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(attachmentList, "", " ") + fmt.Printf("\nListAttachments() result:\n%s\n", string(b)) + + // end-list_attachments + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(attachmentList).ToNot(BeNil()) + }) + It(`GetAttachment request example`, func() { + Expect(ruleIDLink).ToNot(BeEmpty()) + Expect(attachmentIDLink).ToNot(BeEmpty()) + + // begin-get_attachment + + getAttachmentOptions := configurationGovernanceService.NewGetAttachmentOptions( + ruleIDLink, + attachmentIDLink, + ) + getAttachmentOptions.SetTransactionID(uuid.New().String()) + + attachment, response, err := configurationGovernanceService.GetAttachment(getAttachmentOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(attachment, "", " ") + fmt.Printf("\nGetAttachment() result:\n%s\n", string(b)) + + // end-get_attachment + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(attachment).ToNot(BeNil()) + + attachmentToUpdateLink = attachment + + // Retrieve the Etag header from the response for use in the update operation. + attachmentToUpdateEtagLink = response.GetHeaders().Get("Etag") + Expect(attachmentToUpdateEtagLink).ToNot(BeEmpty()) + }) + It(`UpdateAttachment request example`, func() { + Expect(ruleIDLink).ToNot(BeEmpty()) + Expect(attachmentIDLink).ToNot(BeEmpty()) + Expect(attachmentToUpdateLink).ToNot(BeNil()) + Expect(attachmentToUpdateEtagLink).ToNot(BeEmpty()) + + // begin-update_attachment + + // Update the Note field within the existing attachment's IncludedScope. + updatedIncludedScope := &configurationgovernancev1.RuleScope{ + Note: core.StringPtr("This is a new note."), + ScopeID: attachmentToUpdateLink.IncludedScope.ScopeID, + ScopeType: attachmentToUpdateLink.IncludedScope.ScopeType, + } + + updateAttachmentOptions := configurationGovernanceService.NewUpdateAttachmentOptions( + ruleIDLink, + attachmentIDLink, + attachmentToUpdateEtagLink, + *attachmentToUpdateLink.AccountID, + updatedIncludedScope, + ) + updateAttachmentOptions.SetExcludedScopes(attachmentToUpdateLink.ExcludedScopes) + updateAttachmentOptions.SetTransactionID(uuid.New().String()) + + attachment, response, err := configurationGovernanceService.UpdateAttachment(updateAttachmentOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(attachment, "", " ") + fmt.Printf("UpdateAttachment() result:\n%s\n", string(b)) + + // end-update_attachment + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(attachment).ToNot(BeNil()) + }) + It(`DeleteAttachment request example`, func() { + Expect(ruleIDLink).ToNot(BeEmpty()) + Expect(attachmentIDLink).ToNot(BeEmpty()) + + // begin-delete_attachment + + deleteAttachmentOptions := configurationGovernanceService.NewDeleteAttachmentOptions( + ruleIDLink, + attachmentIDLink, + ) + + response, err := configurationGovernanceService.DeleteAttachment(deleteAttachmentOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(response, "", " ") + fmt.Printf("DeleteAttachment() response body:\n%s\n", string(b)) + + // end-delete_attachment + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + It(`DeleteRule request example`, func() { + Expect(ruleIDLink).ToNot(BeEmpty()) + + // begin-delete_rule + + deleteRuleOptions := configurationGovernanceService.NewDeleteRuleOptions( + ruleIDLink, + ) + + response, err := configurationGovernanceService.DeleteRule(deleteRuleOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(response, "", " ") + fmt.Printf("DeleteRule() response body:\n%s\n", string(b)) + + // end-delete_rule + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) +}) diff --git a/configurationgovernancev1/configuration_governance_v1_integration_test.go b/configurationgovernancev1/configuration_governance_v1_integration_test.go new file mode 100644 index 00000000..ba2b78f8 --- /dev/null +++ b/configurationgovernancev1/configuration_governance_v1_integration_test.go @@ -0,0 +1,924 @@ +// +build integration + +/** + * (C) Copyright IBM Corp. 2020. + * + * 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 configurationgovernancev1_test + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/IBM/go-sdk-core/v4/core" + . "github.com/IBM/platform-services-go-sdk/configurationgovernancev1" + "github.com/google/uuid" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +/** + * This file contains an integration test for the configurationgovernancev1 package. + * + * Notes: + * + * The integration test will automatically skip tests if the required config file is not available. + */ + +const verbose bool = true + +var _ = Describe(`ConfigurationGovernanceV1 Integration Tests`, func() { + + const externalConfigFile = "../configuration_governance.env" + const TestLabel = "GoSDKIntegrationTest" + + var ( + err error + service *ConfigurationGovernanceV1 + serviceNoAccess *ConfigurationGovernanceV1 + serviceURL string + config map[string]string + + // Test-related config properties. + accountID string + testServiceName string + enterpriseScopeID string + subacctScopeID string + + transactionID string + + // Sample rules and attachments. + sampleRule1 *RuleRequest + sampleRule2 *RuleRequest + badSampleRule *RuleRequest + + enterpriseScope *RuleScope + accountScope *RuleScope + badScope *RuleScope + + // Variables to hold various id's and object instances (these could perhaps be configured via links). + ruleID1 string + rule1 *Rule + ruleEtag1 string + ruleID2 string + + attachmentID1 string + attachment1 *Attachment + attachmentEtag1 string + attachmentID2 string + ) + + var shouldSkipTest = func() { + Skip("External configuration is not available, skipping tests...") + } + + Describe(`External configuration`, func() { + It("Successfully load the configuration", func() { + _, err = os.Stat(externalConfigFile) + if err != nil { + Skip("External configuration file not found, skipping tests: " + err.Error()) + } + + os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile) + config, err = core.GetServiceProperties(DefaultServiceName) + if err != nil { + Skip("Error loading service properties, skipping tests: " + err.Error()) + } + serviceURL = config["URL"] + if serviceURL == "" { + Skip("Unable to load service URL configuration property, skipping tests") + } + + // Retrieve test-related config properties. + accountID = config["ACCOUNT_ID"] + Expect(accountID).ToNot(BeEmpty()) + + testServiceName = config["TEST_SERVICE_NAME"] + Expect(testServiceName).ToNot(BeEmpty()) + + enterpriseScopeID = config["ENTERPRISE_SCOPE_ID"] + Expect(enterpriseScopeID).ToNot(BeEmpty()) + + subacctScopeID = config["SUBACCT_SCOPE_ID"] + Expect(subacctScopeID).ToNot(BeEmpty()) + + transactionID = uuid.New().String() + + log(fmt.Sprintf("\nService URL: %s", serviceURL)) + log(fmt.Sprintf("TransactionID: %s", transactionID)) + + shouldSkipTest = func() {} + + }) + }) + + Describe(`Initialize sample data`, func() { + It("Successfully construct model instances", func() { + // Initialize some structs to serve as sample rules and attachments. + + ruleTargetAttributeModel := &RuleTargetAttribute{ + Name: core.StringPtr("resource_id"), + Operator: core.StringPtr("is_not_empty"), + } + targetResourceModel := &TargetResource{ + ServiceName: &testServiceName, + ResourceKind: core.StringPtr("bucket"), + AdditionalTargetAttributes: []RuleTargetAttribute{*ruleTargetAttributeModel}, + } + allowedGBCondition := &RuleConditionSingleProperty{ + Property: core.StringPtr("allowed_gb"), + Operator: core.StringPtr("num_less_than_equals"), + Value: core.StringPtr("20"), + } + locationCondition := &RuleConditionSingleProperty{ + Property: core.StringPtr("location"), + Operator: core.StringPtr("string_equals"), + Value: core.StringPtr("us-east"), + } + ruleRequiredConfigModel1 := &RuleRequiredConfigMultiplePropertiesConditionAnd{ + Description: core.StringPtr("allowed_gb<=20 && location=='us-east'"), + And: []RuleConditionIntf{allowedGBCondition, locationCondition}, + } + ruleRequiredConfigModel2 := &RuleRequiredConfigSingleProperty{ + Description: core.StringPtr("allowed_gb <= 30"), + Property: core.StringPtr("allowed_gb"), + Operator: core.StringPtr("num_less_than_equals"), + Value: core.StringPtr("30"), + } + enforcementActionModel := &EnforcementAction{ + Action: core.StringPtr("disallow"), + } + + // Sample rules. + sampleRule1 = &RuleRequest{ + AccountID: &accountID, + Name: core.StringPtr("Go Test Rule #1"), + Description: core.StringPtr("This is the description for Go Test Rule #1."), + RuleType: core.StringPtr("user_defined"), + Target: targetResourceModel, + RequiredConfig: ruleRequiredConfigModel1, + EnforcementActions: []EnforcementAction{*enforcementActionModel}, + Labels: []string{TestLabel}, + } + sampleRule2 = &RuleRequest{ + AccountID: &accountID, + Name: core.StringPtr("Go Test Rule #2"), + Description: core.StringPtr("This is the description for Go Test Rule #2."), + RuleType: core.StringPtr("user_defined"), + Target: targetResourceModel, + RequiredConfig: ruleRequiredConfigModel2, + EnforcementActions: []EnforcementAction{*enforcementActionModel}, + Labels: []string{TestLabel}, + } + badSampleRule = &RuleRequest{ + AccountID: &accountID, + Name: core.StringPtr("Go Test Rule #3"), + Description: core.StringPtr("This is the description for Go Test Rule #3."), + RuleType: core.StringPtr("service_defined"), + Target: targetResourceModel, + RequiredConfig: ruleRequiredConfigModel2, + EnforcementActions: []EnforcementAction{*enforcementActionModel}, + Labels: []string{TestLabel}, + } + + // Sample rule scopes. + enterpriseScope = &RuleScope{ + Note: core.StringPtr("enterprise"), + ScopeID: core.StringPtr(enterpriseScopeID), + ScopeType: core.StringPtr("enterprise"), + } + accountScope = &RuleScope{ + Note: core.StringPtr("leaf account"), + ScopeID: core.StringPtr(subacctScopeID), + ScopeType: core.StringPtr("enterprise.account"), + } + badScope = &RuleScope{ + Note: core.StringPtr("leaf account"), + ScopeID: core.StringPtr(subacctScopeID), + ScopeType: core.StringPtr("enterprise.BOGUS"), + } + }) + }) + + Describe(`Client initialization`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It("Successfully construct the service client instance", func() { + + configurationGovernanceServiceOptions := &ConfigurationGovernanceV1Options{} + + service, err = NewConfigurationGovernanceV1UsingExternalConfig(configurationGovernanceServiceOptions) + + Expect(err).To(BeNil()) + Expect(service).ToNot(BeNil()) + Expect(service.Service.Options.URL).To(Equal(serviceURL)) + }) + It("Successfully construct addition 'no-access' service client instance", func() { + + configurationGovernanceServiceOptions := &ConfigurationGovernanceV1Options{ + ServiceName: "NO_ACCESS", + } + + serviceNoAccess, err = NewConfigurationGovernanceV1UsingExternalConfig(configurationGovernanceServiceOptions) + + Expect(err).To(BeNil()) + Expect(serviceNoAccess).ToNot(BeNil()) + Expect(serviceNoAccess.Service.Options.URL).To(Equal(serviceURL)) + }) + + It("Successfully setup the environment for tests", func() { + log("\nSetup...") + cleanRules(service, accountID, TestLabel) + log("Finished setup.") + }) + }) + + Describe(`CreateRules - Create rules`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully create rule #1`, func() { + + createRuleRequestModel := &CreateRuleRequest{ + RequestID: core.StringPtr("request-0"), + Rule: sampleRule1, + } + + createRulesOptions := &CreateRulesOptions{ + Rules: []CreateRuleRequest{*createRuleRequestModel}, + TransactionID: &transactionID, + } + + createRulesResponse, response, err := service.CreateRules(createRulesOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createRulesResponse).ToNot(BeNil()) + + // log(fmt.Sprintf("\nReceived response:\n%s", toJson(createRulesResponse))) + Expect(len(createRulesResponse.Rules)).To(Equal(1)) + ruleResponse1 := createRulesResponse.Rules[0] + Expect(ruleResponse1).ToNot(BeNil()) + Expect(*ruleResponse1.RequestID).To(Equal("request-0")) + Expect(*ruleResponse1.StatusCode).To(Equal(int64(201))) + Expect(ruleResponse1.Rule).ToNot(BeNil()) + + ruleID1 = *ruleResponse1.Rule.RuleID + Expect(ruleID1).ToNot(BeEmpty()) + + }) + It(`Successfully create rule #2`, func() { + + createRuleRequestModel := &CreateRuleRequest{ + Rule: sampleRule2, + } + + createRulesOptions := &CreateRulesOptions{ + Rules: []CreateRuleRequest{*createRuleRequestModel}, + TransactionID: &transactionID, + } + + createRulesResponse, response, err := service.CreateRules(createRulesOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createRulesResponse).ToNot(BeNil()) + // log(fmt.Sprintf("\nReceived response:\n%s", toJson(createRulesResponse))) + + Expect(len(createRulesResponse.Rules)).To(Equal(1)) + ruleResponse1 := createRulesResponse.Rules[0] + Expect(ruleResponse1).ToNot(BeNil()) + Expect(*ruleResponse1.RequestID).ToNot(BeEmpty()) + Expect(*ruleResponse1.StatusCode).To(Equal(int64(201))) + Expect(ruleResponse1.Rule).ToNot(BeNil()) + + ruleID2 = *ruleResponse1.Rule.RuleID + Expect(ruleID2).ToNot(BeEmpty()) + }) + It(`Fail to create invalid rule`, func() { + + createRuleRequestModel := &CreateRuleRequest{ + Rule: badSampleRule, + } + + createRulesOptions := &CreateRulesOptions{ + Rules: []CreateRuleRequest{*createRuleRequestModel}, + TransactionID: &transactionID, + } + + // An error will be reported within the CreateRuleResponse entry, but the operation itself will + // return a 207 status code. + createRulesResponse, response, err := service.CreateRules(createRulesOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(207)) + Expect(createRulesResponse).ToNot(BeNil()) + + // log(fmt.Sprintf("\nReceived response:\n%s", toJson(createRulesResponse))) + Expect(len(createRulesResponse.Rules)).To(Equal(1)) + ruleResponse1 := createRulesResponse.Rules[0] + Expect(ruleResponse1).ToNot(BeNil()) + Expect(*ruleResponse1.RequestID).ToNot(BeEmpty()) + Expect(*ruleResponse1.StatusCode).To(Equal(int64(400))) + Expect(ruleResponse1.Rule).To(BeNil()) + Expect(len(ruleResponse1.Errors)).To(Equal(1)) + error1 := ruleResponse1.Errors[0] + Expect(*error1.Code).To(Equal("rule_error")) + }) + It(`Fail to create rule with unauthorized user`, func() { + + createRuleRequestModel := &CreateRuleRequest{ + Rule: sampleRule1, + } + + createRulesOptions := &CreateRulesOptions{ + Rules: []CreateRuleRequest{*createRuleRequestModel}, + TransactionID: &transactionID, + } + + _, response, err := serviceNoAccess.CreateRules(createRulesOptions) + + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(403)) + // log(fmt.Sprintf("\nExpected error: %s", err.Error())) + }) + }) + + Describe(`ListRules - List rules`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully list rules`, func() { + + listRulesOptions := &ListRulesOptions{ + AccountID: &accountID, + Labels: core.StringPtr(TestLabel), + Offset: core.Int64Ptr(int64(0)), + Limit: core.Int64Ptr(int64(1000)), + TransactionID: &transactionID, + } + + ruleList, response, err := service.ListRules(listRulesOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(ruleList).ToNot(BeNil()) + // log(fmt.Sprintf("\nReceived response:\n%s", toJson(ruleList))) + + Expect(*ruleList.TotalCount).To(Equal(int64(2))) + Expect(*ruleList.Offset).To(Equal(int64(0))) + Expect(*ruleList.Limit).To(Equal(int64(1000))) + Expect(*ruleList.First).ToNot(BeNil()) + Expect(*ruleList.Last).ToNot(BeNil()) + }) + It(`Fail to list rules with unauthorized user`, func() { + + listRulesOptions := &ListRulesOptions{ + AccountID: &accountID, + Labels: core.StringPtr(TestLabel), + Offset: core.Int64Ptr(int64(0)), + Limit: core.Int64Ptr(int64(1000)), + TransactionID: &transactionID, + } + + _, response, err := serviceNoAccess.ListRules(listRulesOptions) + + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(403)) + // log(fmt.Sprintf("\nExpected error: %s", err.Error())) + }) + }) + + Describe(`GetRule - Get a rule`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully get rule #1`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + + getRuleOptions := &GetRuleOptions{ + RuleID: &ruleID1, + TransactionID: &transactionID, + } + + rule, response, err := service.GetRule(getRuleOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(rule).ToNot(BeNil()) + rule1 = rule + + // Grab the Etag value from the response for use in the update operation. + ruleEtag1 = response.GetHeaders().Get("Etag") + Expect(ruleEtag1).ToNot(BeEmpty()) + }) + It(`Fail to get rule with invalid rule id`, func() { + + getRuleOptions := &GetRuleOptions{ + RuleID: core.StringPtr("BOGUS_ID"), + TransactionID: &transactionID, + } + + rule, response, err := service.GetRule(getRuleOptions) + + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(404)) + Expect(response.Result).ToNot(BeNil()) + Expect(rule).To(BeNil()) + + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + errorResponse, ok := response.Result.(map[string]interface{}) + Expect(ok).To(BeTrue()) + Expect(errorResponse["trace"]).To(Equal(transactionID)) + Expect(err.Error()).To(ContainSubstring("not found")) + }) + }) + + Describe(`UpdateRule - Update a rule`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully update rule #1`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + Expect(rule1).ToNot(BeNil()) + Expect(ruleEtag1).ToNot(BeEmpty()) + + newDescription := fmt.Sprintf("Updated: %s", *rule1.Description) + updateRuleOptions := &UpdateRuleOptions{ + RuleID: &ruleID1, + IfMatch: &ruleEtag1, + Name: rule1.Name, + Description: &newDescription, + Target: rule1.Target, + RequiredConfig: rule1.RequiredConfig, + EnforcementActions: rule1.EnforcementActions, + AccountID: rule1.AccountID, + RuleType: rule1.RuleType, + Labels: rule1.Labels, + TransactionID: &transactionID, + } + + rule, response, err := service.UpdateRule(updateRuleOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(rule).ToNot(BeNil()) + Expect(*rule.Description).To(ContainSubstring("Updated:")) + }) + It(`Fail to update rule using invalid Etag`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + Expect(rule1).ToNot(BeNil()) + + newDescription := fmt.Sprintf("Updated: %s", *rule1.Description) + updateRuleOptions := &UpdateRuleOptions{ + RuleID: &ruleID1, + IfMatch: core.StringPtr("BOGUS_ETAG"), + Name: rule1.Name, + Description: &newDescription, + Target: rule1.Target, + RequiredConfig: rule1.RequiredConfig, + EnforcementActions: rule1.EnforcementActions, + AccountID: rule1.AccountID, + RuleType: rule1.RuleType, + Labels: rule1.Labels, + TransactionID: &transactionID, + } + + rule, response, err := service.UpdateRule(updateRuleOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(400)) + Expect(rule).To(BeNil()) + Expect(err.Error()).To(ContainSubstring("If-Match")) + }) + }) + + Describe(`DeleteRule - Delete a rule`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully delete rule #2`, func() { + Expect(ruleID2).ToNot(BeEmpty()) + + deleteRuleOptions := &DeleteRuleOptions{ + RuleID: &ruleID2, + TransactionID: &transactionID, + } + + response, err := service.DeleteRule(deleteRuleOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + + // Next, check to make sure ListRules() returns only 1 rule. + listRulesOptions := &ListRulesOptions{ + AccountID: &accountID, + Labels: core.StringPtr(TestLabel), + Offset: core.Int64Ptr(int64(0)), + Limit: core.Int64Ptr(int64(1000)), + TransactionID: &transactionID, + } + + ruleList, response, err := service.ListRules(listRulesOptions) + Expect(err).To(BeNil()) + Expect(ruleList).ToNot(BeNil()) + Expect(*ruleList.TotalCount).To(Equal(int64(1))) + + // Next, make sure we can't do a get on the deleted rule. + rule := getRule(service, ruleID2) + Expect(rule).To(BeNil()) + }) + It(`Fail to delete rule with invalid rule id`, func() { + + deleteRuleOptions := &DeleteRuleOptions{ + RuleID: core.StringPtr("BOGUS_ID"), + TransactionID: &transactionID, + } + + response, err := service.DeleteRule(deleteRuleOptions) + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(404)) + Expect(err.Error()).To(ContainSubstring("not found")) + }) + }) + + Describe(`CreateAttachments - Create attachments`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully create attachment #1`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + + attachmentRequestModel := &AttachmentRequest{ + AccountID: &accountID, + IncludedScope: enterpriseScope, + ExcludedScopes: []RuleScope{*accountScope}, + } + + createAttachmentsOptions := &CreateAttachmentsOptions{ + RuleID: &ruleID1, + Attachments: []AttachmentRequest{*attachmentRequestModel}, + TransactionID: &transactionID, + } + + createAttachmentsResponse, response, err := service.CreateAttachments(createAttachmentsOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createAttachmentsResponse).ToNot(BeNil()) + // log(fmt.Sprintf("\nReceived response:\n%s", toJson(createAttachmentsResponse))) + + Expect(len(createAttachmentsResponse.Attachments)).To(Equal(1)) + attachment := createAttachmentsResponse.Attachments[0] + Expect(attachment).ToNot(BeNil()) + Expect(attachment.AttachmentID).ToNot(BeNil()) + attachmentID1 = *attachment.AttachmentID + Expect(attachmentID1).ToNot(BeNil()) + + // Now retrieve the rule and make sure the number_of_attachments is 1. + rule := getRule(service, ruleID1) + Expect(rule).ToNot(BeNil()) + Expect(rule.NumberOfAttachments).ToNot(BeNil()) + Expect(*rule.NumberOfAttachments).To(Equal(int64(1))) + }) + It(`Successfully create attachment #2`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + + attachmentRequestModel := &AttachmentRequest{ + AccountID: &accountID, + IncludedScope: accountScope, + } + + createAttachmentsOptions := &CreateAttachmentsOptions{ + RuleID: &ruleID1, + Attachments: []AttachmentRequest{*attachmentRequestModel}, + TransactionID: &transactionID, + } + + createAttachmentsResponse, response, err := service.CreateAttachments(createAttachmentsOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createAttachmentsResponse).ToNot(BeNil()) + // log(fmt.Sprintf("\nReceived response:\n%s", toJson(createAttachmentsResponse))) + + Expect(len(createAttachmentsResponse.Attachments)).To(Equal(1)) + attachment := createAttachmentsResponse.Attachments[0] + Expect(attachment).ToNot(BeNil()) + Expect(attachment.AttachmentID).ToNot(BeNil()) + attachmentID2 = *attachment.AttachmentID + Expect(attachmentID2).ToNot(BeEmpty()) + + // Now retrieve the rule and make sure the number_of_attachments is 1. + rule := getRule(service, ruleID1) + Expect(rule).ToNot(BeNil()) + Expect(rule.NumberOfAttachments).ToNot(BeNil()) + Expect(*rule.NumberOfAttachments).To(Equal(int64(2))) + }) + It(`Fail to create attachment with an invalid scope type`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + Expect(badScope).ToNot(BeNil()) + + attachmentRequestModel := &AttachmentRequest{ + AccountID: &accountID, + IncludedScope: enterpriseScope, + ExcludedScopes: []RuleScope{*badScope}, + } + + createAttachmentsOptions := &CreateAttachmentsOptions{ + RuleID: &ruleID1, + Attachments: []AttachmentRequest{*attachmentRequestModel}, + TransactionID: &transactionID, + } + + createAttachmentsResponse, response, err := service.CreateAttachments(createAttachmentsOptions) + + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(400)) + Expect(createAttachmentsResponse).To(BeNil()) + }) + }) + + Describe(`GetAttachment - Get an attachment`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully get attachment #1`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + Expect(attachmentID1).ToNot(BeEmpty()) + + getAttachmentOptions := &GetAttachmentOptions{ + RuleID: &ruleID1, + AttachmentID: &attachmentID1, + TransactionID: &transactionID, + } + + attachment, response, err := service.GetAttachment(getAttachmentOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(attachment).ToNot(BeNil()) + attachment1 = attachment + + Expect(*attachment.AccountID).To(Equal(accountID)) + Expect(*attachment.RuleID).To(Equal(ruleID1)) + Expect(*attachment.AttachmentID).To(Equal(attachmentID1)) + Expect(*attachment.IncludedScope.Note).To(Equal("enterprise")) + Expect(len(attachment.ExcludedScopes)).To(Equal(1)) + + // Grab the Etag value from the response for use in the update operation. + attachmentEtag1 = response.GetHeaders().Get("Etag") + Expect(attachmentEtag1).ToNot(BeEmpty()) + }) + It(`Fail to get attachment with invalid attachment id`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + + getAttachmentOptions := &GetAttachmentOptions{ + RuleID: &ruleID1, + AttachmentID: core.StringPtr("BOGUS_ID"), + TransactionID: &transactionID, + } + + attachment, response, err := service.GetAttachment(getAttachmentOptions) + //log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(404)) + Expect(attachment).To(BeNil()) + Expect(err.Error()).To(ContainSubstring("not found")) + }) + }) + + Describe(`ListAttachments - List attachments`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully list attachments for rule #1`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + + listAttachmentsOptions := &ListAttachmentsOptions{ + RuleID: &ruleID1, + TransactionID: &transactionID, + Offset: core.Int64Ptr(int64(0)), + Limit: core.Int64Ptr(int64(1000)), + } + + attachmentsList, response, err := service.ListAttachments(listAttachmentsOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(attachmentsList).ToNot(BeNil()) + Expect(*attachmentsList.TotalCount).To(Equal(int64(2))) + Expect(*attachmentsList.Offset).To(Equal(int64(0))) + Expect(*attachmentsList.Limit).To(Equal(int64(1000))) + Expect(attachmentsList.First).ToNot(BeNil()) + Expect(attachmentsList.Last).ToNot(BeNil()) + for _, att := range attachmentsList.Attachments { + if attachmentID1 == *att.AttachmentID { + Expect(*att.IncludedScope.Note).To(Equal("enterprise")) + Expect(len(att.ExcludedScopes)).To(Equal(1)) + } else if attachmentID2 == *att.AttachmentID { + Expect(*att.IncludedScope.Note).To(Equal("leaf account")) + Expect(att.ExcludedScopes).To(BeEmpty()) + } else { + Fail(fmt.Sprintf("Unrecognized attachmentID: %s", *att.AttachmentID)) + } + } + }) + }) + + Describe(`UpdateAttachment - Update an attachment`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully update attachment #1`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + Expect(attachment1).ToNot(BeNil()) + Expect(attachmentID1).ToNot(BeEmpty()) + Expect(attachmentEtag1).ToNot(BeEmpty()) + + // Update the note field of attachment1's IncludedScope field. + updatedNote := fmt.Sprintf("Updated: %s", *attachment1.IncludedScope.Note) + updatedScope := &RuleScope{ + Note: &updatedNote, + ScopeID: attachment1.IncludedScope.ScopeID, + ScopeType: attachment1.IncludedScope.ScopeType, + } + + updateAttachmentOptions := &UpdateAttachmentOptions{ + RuleID: &ruleID1, + AttachmentID: &attachmentID1, + IfMatch: &attachmentEtag1, + AccountID: &accountID, + IncludedScope: updatedScope, + ExcludedScopes: attachment1.ExcludedScopes, + TransactionID: &transactionID, + } + + attachment, response, err := service.UpdateAttachment(updateAttachmentOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(attachment).ToNot(BeNil()) + Expect(*attachment.IncludedScope.Note).To(ContainSubstring("Updated:")) + }) + It(`Fail to update attachment with invalid etag`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + Expect(attachment1).ToNot(BeNil()) + + // Update the note field of attachment1's IncludedScope field. + updatedNote := fmt.Sprintf("Updated: %s", *attachment1.IncludedScope.Note) + updatedScope := &RuleScope{ + Note: &updatedNote, + ScopeID: attachment1.IncludedScope.ScopeID, + ScopeType: attachment1.IncludedScope.ScopeType, + } + + updateAttachmentOptions := &UpdateAttachmentOptions{ + RuleID: &ruleID1, + AttachmentID: &attachmentID1, + IfMatch: core.StringPtr("BOGUS_ETAG"), + AccountID: &accountID, + IncludedScope: updatedScope, + ExcludedScopes: attachment1.ExcludedScopes, + TransactionID: &transactionID, + } + + attachment, response, err := service.UpdateAttachment(updateAttachmentOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(400)) + Expect(attachment).To(BeNil()) + Expect(err.Error()).To(ContainSubstring("If-Match")) + }) + }) + + Describe(`DeleteAttachment - Delete an attachment`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Successfully delete attachment #2`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + Expect(attachmentID2).ToNot(BeEmpty()) + + deleteAttachmentOptions := &DeleteAttachmentOptions{ + RuleID: &ruleID1, + AttachmentID: &attachmentID2, + TransactionID: &transactionID, + } + + response, err := service.DeleteAttachment(deleteAttachmentOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + + }) + It(`Fail to delete attachment with invalid attachment id`, func() { + Expect(ruleID1).ToNot(BeEmpty()) + + deleteAttachmentOptions := &DeleteAttachmentOptions{ + RuleID: &ruleID1, + AttachmentID: core.StringPtr("BOGUS_ID"), + TransactionID: &transactionID, + } + + response, err := service.DeleteAttachment(deleteAttachmentOptions) + // log(fmt.Sprintf("\nReceived detailed response:\n%s", toJson(response))) + + Expect(err).ToNot(BeNil()) + Expect(response.StatusCode).To(Equal(404)) + Expect(err.Error()).To(ContainSubstring("not found")) + }) + }) + + Describe(`Teardown - clean up test data`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`Clean rules`, func() { + log("\nTeardown...") + cleanRules(service, accountID, TestLabel) + log("Finished teardown.") + }) + }) +}) + +func cleanRules(service *ConfigurationGovernanceV1, accountID string, label string) { + log("Cleaning rules...") + + listRulesOptions := &ListRulesOptions{ + AccountID: &accountID, + Labels: core.StringPtr(label), + Offset: core.Int64Ptr(int64(0)), + Limit: core.Int64Ptr(int64(1000)), + } + + ruleList, response, err := service.ListRules(listRulesOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(ruleList).ToNot(BeNil()) + Expect(ruleList.TotalCount).ToNot(BeNil()) + + log(fmt.Sprintf("Found %d rule(s) to be cleaned", *ruleList.TotalCount)) + + if *ruleList.TotalCount > 0 { + for _, rule := range ruleList.Rules { + + log(fmt.Sprintf("Deleting rule: name='%s' id='%s'", *rule.Name, *rule.RuleID)) + + response, err := service.DeleteRule( + &DeleteRuleOptions{ + RuleID: rule.RuleID, + }) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + } + } + + log("Finished cleaning rules...") +} + +func getRule(service *ConfigurationGovernanceV1, ruleID string) (rule *Rule) { + rule, _, _ = service.GetRule(&GetRuleOptions{ + RuleID: core.StringPtr(ruleID), + }) + return +} + +func log(msg string) { + if verbose { + fmt.Printf("%s\n", msg) + } +} + +func toJson(obj interface{}) string { + b, err := json.MarshalIndent(obj, "", " ") + if err != nil { + panic(err) + } + return string(b) + +} diff --git a/configurationgovernancev1/configuration_governance_v1_suite_test.go b/configurationgovernancev1/configuration_governance_v1_suite_test.go new file mode 100644 index 00000000..533cb771 --- /dev/null +++ b/configurationgovernancev1/configuration_governance_v1_suite_test.go @@ -0,0 +1,28 @@ +/** + * (C) Copyright IBM Corp. 2020. + * + * 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 configurationgovernancev1_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "testing" +) + +func TestConfigurationGovernanceV1(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "ConfigurationGovernanceV1 Suite") +} diff --git a/configurationgovernancev1/configuration_governance_v1_test.go b/configurationgovernancev1/configuration_governance_v1_test.go new file mode 100644 index 00000000..d6407d35 --- /dev/null +++ b/configurationgovernancev1/configuration_governance_v1_test.go @@ -0,0 +1,2064 @@ +/** + * (C) Copyright IBM Corp. 2020. + * + * 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 configurationgovernancev1_test + +import ( + "bytes" + "fmt" + "github.com/IBM/go-sdk-core/v4/core" + "github.com/IBM/platform-services-go-sdk/configurationgovernancev1" + "github.com/go-openapi/strfmt" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "io" + "io/ioutil" + "net/http" + "net/http/httptest" + "os" + "time" +) + +var _ = Describe(`ConfigurationGovernanceV1`, func() { + var testServer *httptest.Server + Describe(`Service constructor tests`, func() { + It(`Instantiate service client`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(configurationGovernanceService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + }) + It(`Instantiate service client with error: Invalid URL`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: "{BAD_URL_STRING", + }) + Expect(configurationGovernanceService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + It(`Instantiate service client with error: Invalid Auth`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: "https://configurationgovernancev1/api", + Authenticator: &core.BasicAuthenticator{ + Username: "", + Password: "", + }, + }) + Expect(configurationGovernanceService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + }) + Describe(`Service constructor tests using external config`, func() { + Context(`Using external config, construct service client instances`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "CONFIGURATION_GOVERNANCE_URL": "https://configurationgovernancev1/api", + "CONFIGURATION_GOVERNANCE_AUTH_TYPE": "noauth", + } + + It(`Create service client using external config successfully`, func() { + SetTestEnvironment(testEnvironment) + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1UsingExternalConfig(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + }) + Expect(configurationGovernanceService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url from constructor successfully`, func() { + SetTestEnvironment(testEnvironment) + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1UsingExternalConfig(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: "https://testService/api", + }) + Expect(configurationGovernanceService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url programatically successfully`, func() { + SetTestEnvironment(testEnvironment) + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1UsingExternalConfig(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + }) + err := configurationGovernanceService.SetServiceURL("https://testService/api") + Expect(err).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + }) + 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{ + "CONFIGURATION_GOVERNANCE_URL": "https://configurationgovernancev1/api", + "CONFIGURATION_GOVERNANCE_AUTH_TYPE": "someOtherAuth", + } + + SetTestEnvironment(testEnvironment) + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1UsingExternalConfig(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + }) + + It(`Instantiate service client with error`, func() { + Expect(configurationGovernanceService).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{ + "CONFIGURATION_GOVERNANCE_AUTH_TYPE": "NOAuth", + } + + SetTestEnvironment(testEnvironment) + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1UsingExternalConfig(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: "{BAD_URL_STRING", + }) + + It(`Instantiate service client with error`, func() { + Expect(configurationGovernanceService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + }) + Describe(`CreateRules(createRulesOptions *CreateRulesOptions) - Operation response error`, func() { + createRulesPath := "/config/v1/rules" + 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.Path).To(Equal(createRulesPath)) + Expect(req.Method).To(Equal("POST")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateRules with error: Operation response processing error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the RuleTargetAttribute model + ruleTargetAttributeModel := new(configurationgovernancev1.RuleTargetAttribute) + ruleTargetAttributeModel.Name = core.StringPtr("testString") + ruleTargetAttributeModel.Operator = core.StringPtr("string_equals") + ruleTargetAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the TargetResource model + targetResourceModel := new(configurationgovernancev1.TargetResource) + targetResourceModel.ServiceName = core.StringPtr("iam-groups") + targetResourceModel.ResourceKind = core.StringPtr("service") + targetResourceModel.AdditionalTargetAttributes = []configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel} + + // Construct an instance of the RuleRequiredConfigSingleProperty model + ruleRequiredConfigModel := new(configurationgovernancev1.RuleRequiredConfigSingleProperty) + ruleRequiredConfigModel.Description = core.StringPtr("Public access check") + ruleRequiredConfigModel.Property = core.StringPtr("public_access_enabled") + ruleRequiredConfigModel.Operator = core.StringPtr("is_true") + ruleRequiredConfigModel.Value = core.StringPtr("testString") + + // Construct an instance of the EnforcementAction model + enforcementActionModel := new(configurationgovernancev1.EnforcementAction) + enforcementActionModel.Action = core.StringPtr("audit_log") + + // Construct an instance of the RuleRequest model + ruleRequestModel := new(configurationgovernancev1.RuleRequest) + ruleRequestModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + ruleRequestModel.Name = core.StringPtr("Disable public access") + ruleRequestModel.Description = core.StringPtr("Ensure that public access to account resources is disabled.") + ruleRequestModel.RuleType = core.StringPtr("user_defined") + ruleRequestModel.Target = targetResourceModel + ruleRequestModel.RequiredConfig = ruleRequiredConfigModel + ruleRequestModel.EnforcementActions = []configurationgovernancev1.EnforcementAction{*enforcementActionModel} + ruleRequestModel.Labels = []string{"testString"} + + // Construct an instance of the CreateRuleRequest model + createRuleRequestModel := new(configurationgovernancev1.CreateRuleRequest) + createRuleRequestModel.RequestID = core.StringPtr("3cebc877-58e7-44a5-a292-32114fa73558") + createRuleRequestModel.Rule = ruleRequestModel + + // Construct an instance of the CreateRulesOptions model + createRulesOptionsModel := new(configurationgovernancev1.CreateRulesOptions) + createRulesOptionsModel.Rules = []configurationgovernancev1.CreateRuleRequest{*createRuleRequestModel} + createRulesOptionsModel.TransactionID = core.StringPtr("testString") + createRulesOptionsModel.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 := configurationGovernanceService.CreateRules(createRulesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`CreateRules(createRulesOptions *CreateRulesOptions)`, func() { + createRulesPath := "/config/v1/rules" + 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.Path).To(Equal(createRulesPath)) + Expect(req.Method).To(Equal("POST")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"rules": [{"request_id": "3cebc877-58e7-44a5-a292-32114fa73558", "status_code": 201, "rule": {"account_id": "AccountID", "name": "Name", "description": "Description", "rule_type": "user_defined", "target": {"service_name": "iam-groups", "resource_kind": "zone", "additional_target_attributes": [{"name": "Name", "operator": "string_equals", "value": "Value"}]}, "required_config": {"description": "Description", "property": "public_access_enabled", "operator": "is_true", "value": "Value"}, "enforcement_actions": [{"action": "audit_log"}], "labels": ["Label"], "rule_id": "rule-81f3db5e-f9db-4c46-9de3-a4a76e66adbf", "creation_date": "2020-01-10T05:23:19+0000", "created_by": "CreatedBy", "modification_date": "ModificationDate", "modified_by": "ModifiedBy", "number_of_attachments": 3}, "errors": [{"code": "bad_request", "message": "The rule is missing an account ID"}], "trace": "861263b4-cee3-4514-8d8c-05d17308e6eb"}]}`) + })) + }) + It(`Invoke CreateRules successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := configurationGovernanceService.CreateRules(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the RuleTargetAttribute model + ruleTargetAttributeModel := new(configurationgovernancev1.RuleTargetAttribute) + ruleTargetAttributeModel.Name = core.StringPtr("testString") + ruleTargetAttributeModel.Operator = core.StringPtr("string_equals") + ruleTargetAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the TargetResource model + targetResourceModel := new(configurationgovernancev1.TargetResource) + targetResourceModel.ServiceName = core.StringPtr("iam-groups") + targetResourceModel.ResourceKind = core.StringPtr("service") + targetResourceModel.AdditionalTargetAttributes = []configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel} + + // Construct an instance of the RuleRequiredConfigSingleProperty model + ruleRequiredConfigModel := new(configurationgovernancev1.RuleRequiredConfigSingleProperty) + ruleRequiredConfigModel.Description = core.StringPtr("Public access check") + ruleRequiredConfigModel.Property = core.StringPtr("public_access_enabled") + ruleRequiredConfigModel.Operator = core.StringPtr("is_true") + ruleRequiredConfigModel.Value = core.StringPtr("testString") + + // Construct an instance of the EnforcementAction model + enforcementActionModel := new(configurationgovernancev1.EnforcementAction) + enforcementActionModel.Action = core.StringPtr("audit_log") + + // Construct an instance of the RuleRequest model + ruleRequestModel := new(configurationgovernancev1.RuleRequest) + ruleRequestModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + ruleRequestModel.Name = core.StringPtr("Disable public access") + ruleRequestModel.Description = core.StringPtr("Ensure that public access to account resources is disabled.") + ruleRequestModel.RuleType = core.StringPtr("user_defined") + ruleRequestModel.Target = targetResourceModel + ruleRequestModel.RequiredConfig = ruleRequiredConfigModel + ruleRequestModel.EnforcementActions = []configurationgovernancev1.EnforcementAction{*enforcementActionModel} + ruleRequestModel.Labels = []string{"testString"} + + // Construct an instance of the CreateRuleRequest model + createRuleRequestModel := new(configurationgovernancev1.CreateRuleRequest) + createRuleRequestModel.RequestID = core.StringPtr("3cebc877-58e7-44a5-a292-32114fa73558") + createRuleRequestModel.Rule = ruleRequestModel + + // Construct an instance of the CreateRulesOptions model + createRulesOptionsModel := new(configurationgovernancev1.CreateRulesOptions) + createRulesOptionsModel.Rules = []configurationgovernancev1.CreateRuleRequest{*createRuleRequestModel} + createRulesOptionsModel.TransactionID = core.StringPtr("testString") + createRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = configurationGovernanceService.CreateRules(createRulesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke CreateRules with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the RuleTargetAttribute model + ruleTargetAttributeModel := new(configurationgovernancev1.RuleTargetAttribute) + ruleTargetAttributeModel.Name = core.StringPtr("testString") + ruleTargetAttributeModel.Operator = core.StringPtr("string_equals") + ruleTargetAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the TargetResource model + targetResourceModel := new(configurationgovernancev1.TargetResource) + targetResourceModel.ServiceName = core.StringPtr("iam-groups") + targetResourceModel.ResourceKind = core.StringPtr("service") + targetResourceModel.AdditionalTargetAttributes = []configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel} + + // Construct an instance of the RuleRequiredConfigSingleProperty model + ruleRequiredConfigModel := new(configurationgovernancev1.RuleRequiredConfigSingleProperty) + ruleRequiredConfigModel.Description = core.StringPtr("Public access check") + ruleRequiredConfigModel.Property = core.StringPtr("public_access_enabled") + ruleRequiredConfigModel.Operator = core.StringPtr("is_true") + ruleRequiredConfigModel.Value = core.StringPtr("testString") + + // Construct an instance of the EnforcementAction model + enforcementActionModel := new(configurationgovernancev1.EnforcementAction) + enforcementActionModel.Action = core.StringPtr("audit_log") + + // Construct an instance of the RuleRequest model + ruleRequestModel := new(configurationgovernancev1.RuleRequest) + ruleRequestModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + ruleRequestModel.Name = core.StringPtr("Disable public access") + ruleRequestModel.Description = core.StringPtr("Ensure that public access to account resources is disabled.") + ruleRequestModel.RuleType = core.StringPtr("user_defined") + ruleRequestModel.Target = targetResourceModel + ruleRequestModel.RequiredConfig = ruleRequiredConfigModel + ruleRequestModel.EnforcementActions = []configurationgovernancev1.EnforcementAction{*enforcementActionModel} + ruleRequestModel.Labels = []string{"testString"} + + // Construct an instance of the CreateRuleRequest model + createRuleRequestModel := new(configurationgovernancev1.CreateRuleRequest) + createRuleRequestModel.RequestID = core.StringPtr("3cebc877-58e7-44a5-a292-32114fa73558") + createRuleRequestModel.Rule = ruleRequestModel + + // Construct an instance of the CreateRulesOptions model + createRulesOptionsModel := new(configurationgovernancev1.CreateRulesOptions) + createRulesOptionsModel.Rules = []configurationgovernancev1.CreateRuleRequest{*createRuleRequestModel} + createRulesOptionsModel.TransactionID = core.StringPtr("testString") + createRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := configurationGovernanceService.CreateRules(createRulesOptionsModel) + 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 CreateRulesOptions model with no property values + createRulesOptionsModelNew := new(configurationgovernancev1.CreateRulesOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = configurationGovernanceService.CreateRules(createRulesOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListRules(listRulesOptions *ListRulesOptions) - Operation response error`, func() { + listRulesPath := "/config/v1/rules" + 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.Path).To(Equal(listRulesPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"531fc3e28bfc43c5a2cea07786d93f5c"})) + + + // TODO: Add check for attached query parameter + + Expect(req.URL.Query()["labels"]).To(Equal([]string{"SOC2,ITCS300"})) + + Expect(req.URL.Query()["scopes"]).To(Equal([]string{"scope_id"})) + + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(1000))})) + + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListRules with error: Operation response processing error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the ListRulesOptions model + listRulesOptionsModel := new(configurationgovernancev1.ListRulesOptions) + listRulesOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + listRulesOptionsModel.TransactionID = core.StringPtr("testString") + listRulesOptionsModel.Attached = core.BoolPtr(true) + listRulesOptionsModel.Labels = core.StringPtr("SOC2,ITCS300") + listRulesOptionsModel.Scopes = core.StringPtr("scope_id") + listRulesOptionsModel.Limit = core.Int64Ptr(int64(1000)) + listRulesOptionsModel.Offset = core.Int64Ptr(int64(38)) + listRulesOptionsModel.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 := configurationGovernanceService.ListRules(listRulesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`ListRules(listRulesOptions *ListRulesOptions)`, func() { + listRulesPath := "/config/v1/rules" + 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.Path).To(Equal(listRulesPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"531fc3e28bfc43c5a2cea07786d93f5c"})) + + + // TODO: Add check for attached query parameter + + Expect(req.URL.Query()["labels"]).To(Equal([]string{"SOC2,ITCS300"})) + + Expect(req.URL.Query()["scopes"]).To(Equal([]string{"scope_id"})) + + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(1000))})) + + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 1000, "total_count": 10, "first": {"href": "Href"}, "last": {"href": "Href"}, "rules": [{"account_id": "AccountID", "name": "Name", "description": "Description", "rule_type": "user_defined", "target": {"service_name": "iam-groups", "resource_kind": "zone", "additional_target_attributes": [{"name": "Name", "operator": "string_equals", "value": "Value"}]}, "required_config": {"description": "Description", "property": "public_access_enabled", "operator": "is_true", "value": "Value"}, "enforcement_actions": [{"action": "audit_log"}], "labels": ["Label"], "rule_id": "rule-81f3db5e-f9db-4c46-9de3-a4a76e66adbf", "creation_date": "2020-01-10T05:23:19+0000", "created_by": "CreatedBy", "modification_date": "ModificationDate", "modified_by": "ModifiedBy", "number_of_attachments": 3}]}`) + })) + }) + It(`Invoke ListRules successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := configurationGovernanceService.ListRules(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListRulesOptions model + listRulesOptionsModel := new(configurationgovernancev1.ListRulesOptions) + listRulesOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + listRulesOptionsModel.TransactionID = core.StringPtr("testString") + listRulesOptionsModel.Attached = core.BoolPtr(true) + listRulesOptionsModel.Labels = core.StringPtr("SOC2,ITCS300") + listRulesOptionsModel.Scopes = core.StringPtr("scope_id") + listRulesOptionsModel.Limit = core.Int64Ptr(int64(1000)) + listRulesOptionsModel.Offset = core.Int64Ptr(int64(38)) + listRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = configurationGovernanceService.ListRules(listRulesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke ListRules with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the ListRulesOptions model + listRulesOptionsModel := new(configurationgovernancev1.ListRulesOptions) + listRulesOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + listRulesOptionsModel.TransactionID = core.StringPtr("testString") + listRulesOptionsModel.Attached = core.BoolPtr(true) + listRulesOptionsModel.Labels = core.StringPtr("SOC2,ITCS300") + listRulesOptionsModel.Scopes = core.StringPtr("scope_id") + listRulesOptionsModel.Limit = core.Int64Ptr(int64(1000)) + listRulesOptionsModel.Offset = core.Int64Ptr(int64(38)) + listRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := configurationGovernanceService.ListRules(listRulesOptionsModel) + 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 ListRulesOptions model with no property values + listRulesOptionsModelNew := new(configurationgovernancev1.ListRulesOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = configurationGovernanceService.ListRules(listRulesOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetRule(getRuleOptions *GetRuleOptions) - Operation response error`, func() { + getRulePath := "/config/v1/rules/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.Path).To(Equal(getRulePath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetRule with error: Operation response processing error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the GetRuleOptions model + getRuleOptionsModel := new(configurationgovernancev1.GetRuleOptions) + getRuleOptionsModel.RuleID = core.StringPtr("testString") + getRuleOptionsModel.TransactionID = core.StringPtr("testString") + getRuleOptionsModel.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 := configurationGovernanceService.GetRule(getRuleOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`GetRule(getRuleOptions *GetRuleOptions)`, func() { + getRulePath := "/config/v1/rules/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.Path).To(Equal(getRulePath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"account_id": "AccountID", "name": "Name", "description": "Description", "rule_type": "user_defined", "target": {"service_name": "iam-groups", "resource_kind": "zone", "additional_target_attributes": [{"name": "Name", "operator": "string_equals", "value": "Value"}]}, "required_config": {"description": "Description", "property": "public_access_enabled", "operator": "is_true", "value": "Value"}, "enforcement_actions": [{"action": "audit_log"}], "labels": ["Label"], "rule_id": "rule-81f3db5e-f9db-4c46-9de3-a4a76e66adbf", "creation_date": "2020-01-10T05:23:19+0000", "created_by": "CreatedBy", "modification_date": "ModificationDate", "modified_by": "ModifiedBy", "number_of_attachments": 3}`) + })) + }) + It(`Invoke GetRule successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := configurationGovernanceService.GetRule(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetRuleOptions model + getRuleOptionsModel := new(configurationgovernancev1.GetRuleOptions) + getRuleOptionsModel.RuleID = core.StringPtr("testString") + getRuleOptionsModel.TransactionID = core.StringPtr("testString") + getRuleOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = configurationGovernanceService.GetRule(getRuleOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke GetRule with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the GetRuleOptions model + getRuleOptionsModel := new(configurationgovernancev1.GetRuleOptions) + getRuleOptionsModel.RuleID = core.StringPtr("testString") + getRuleOptionsModel.TransactionID = core.StringPtr("testString") + getRuleOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := configurationGovernanceService.GetRule(getRuleOptionsModel) + 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 GetRuleOptions model with no property values + getRuleOptionsModelNew := new(configurationgovernancev1.GetRuleOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = configurationGovernanceService.GetRule(getRuleOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateRule(updateRuleOptions *UpdateRuleOptions) - Operation response error`, func() { + updateRulePath := "/config/v1/rules/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.Path).To(Equal(updateRulePath)) + Expect(req.Method).To(Equal("PUT")) + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateRule with error: Operation response processing error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the RuleTargetAttribute model + ruleTargetAttributeModel := new(configurationgovernancev1.RuleTargetAttribute) + ruleTargetAttributeModel.Name = core.StringPtr("testString") + ruleTargetAttributeModel.Operator = core.StringPtr("string_equals") + ruleTargetAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the TargetResource model + targetResourceModel := new(configurationgovernancev1.TargetResource) + targetResourceModel.ServiceName = core.StringPtr("iam-groups") + targetResourceModel.ResourceKind = core.StringPtr("service") + targetResourceModel.AdditionalTargetAttributes = []configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel} + + // Construct an instance of the RuleRequiredConfigSingleProperty model + ruleRequiredConfigModel := new(configurationgovernancev1.RuleRequiredConfigSingleProperty) + ruleRequiredConfigModel.Description = core.StringPtr("testString") + ruleRequiredConfigModel.Property = core.StringPtr("public_access_enabled") + ruleRequiredConfigModel.Operator = core.StringPtr("is_false") + ruleRequiredConfigModel.Value = core.StringPtr("testString") + + // Construct an instance of the EnforcementAction model + enforcementActionModel := new(configurationgovernancev1.EnforcementAction) + enforcementActionModel.Action = core.StringPtr("audit_log") + + // Construct an instance of the UpdateRuleOptions model + updateRuleOptionsModel := new(configurationgovernancev1.UpdateRuleOptions) + updateRuleOptionsModel.RuleID = core.StringPtr("testString") + updateRuleOptionsModel.IfMatch = core.StringPtr("testString") + updateRuleOptionsModel.Name = core.StringPtr("Disable public access") + updateRuleOptionsModel.Description = core.StringPtr("Ensure that public access to account resources is disabled.") + updateRuleOptionsModel.Target = targetResourceModel + updateRuleOptionsModel.RequiredConfig = ruleRequiredConfigModel + updateRuleOptionsModel.EnforcementActions = []configurationgovernancev1.EnforcementAction{*enforcementActionModel} + updateRuleOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + updateRuleOptionsModel.RuleType = core.StringPtr("user_defined") + updateRuleOptionsModel.Labels = []string{"testString"} + updateRuleOptionsModel.TransactionID = core.StringPtr("testString") + updateRuleOptionsModel.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 := configurationGovernanceService.UpdateRule(updateRuleOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`UpdateRule(updateRuleOptions *UpdateRuleOptions)`, func() { + updateRulePath := "/config/v1/rules/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.Path).To(Equal(updateRulePath)) + Expect(req.Method).To(Equal("PUT")) + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"account_id": "AccountID", "name": "Name", "description": "Description", "rule_type": "user_defined", "target": {"service_name": "iam-groups", "resource_kind": "zone", "additional_target_attributes": [{"name": "Name", "operator": "string_equals", "value": "Value"}]}, "required_config": {"description": "Description", "property": "public_access_enabled", "operator": "is_true", "value": "Value"}, "enforcement_actions": [{"action": "audit_log"}], "labels": ["Label"], "rule_id": "rule-81f3db5e-f9db-4c46-9de3-a4a76e66adbf", "creation_date": "2020-01-10T05:23:19+0000", "created_by": "CreatedBy", "modification_date": "ModificationDate", "modified_by": "ModifiedBy", "number_of_attachments": 3}`) + })) + }) + It(`Invoke UpdateRule successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := configurationGovernanceService.UpdateRule(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the RuleTargetAttribute model + ruleTargetAttributeModel := new(configurationgovernancev1.RuleTargetAttribute) + ruleTargetAttributeModel.Name = core.StringPtr("testString") + ruleTargetAttributeModel.Operator = core.StringPtr("string_equals") + ruleTargetAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the TargetResource model + targetResourceModel := new(configurationgovernancev1.TargetResource) + targetResourceModel.ServiceName = core.StringPtr("iam-groups") + targetResourceModel.ResourceKind = core.StringPtr("service") + targetResourceModel.AdditionalTargetAttributes = []configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel} + + // Construct an instance of the RuleRequiredConfigSingleProperty model + ruleRequiredConfigModel := new(configurationgovernancev1.RuleRequiredConfigSingleProperty) + ruleRequiredConfigModel.Description = core.StringPtr("testString") + ruleRequiredConfigModel.Property = core.StringPtr("public_access_enabled") + ruleRequiredConfigModel.Operator = core.StringPtr("is_false") + ruleRequiredConfigModel.Value = core.StringPtr("testString") + + // Construct an instance of the EnforcementAction model + enforcementActionModel := new(configurationgovernancev1.EnforcementAction) + enforcementActionModel.Action = core.StringPtr("audit_log") + + // Construct an instance of the UpdateRuleOptions model + updateRuleOptionsModel := new(configurationgovernancev1.UpdateRuleOptions) + updateRuleOptionsModel.RuleID = core.StringPtr("testString") + updateRuleOptionsModel.IfMatch = core.StringPtr("testString") + updateRuleOptionsModel.Name = core.StringPtr("Disable public access") + updateRuleOptionsModel.Description = core.StringPtr("Ensure that public access to account resources is disabled.") + updateRuleOptionsModel.Target = targetResourceModel + updateRuleOptionsModel.RequiredConfig = ruleRequiredConfigModel + updateRuleOptionsModel.EnforcementActions = []configurationgovernancev1.EnforcementAction{*enforcementActionModel} + updateRuleOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + updateRuleOptionsModel.RuleType = core.StringPtr("user_defined") + updateRuleOptionsModel.Labels = []string{"testString"} + updateRuleOptionsModel.TransactionID = core.StringPtr("testString") + updateRuleOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = configurationGovernanceService.UpdateRule(updateRuleOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke UpdateRule with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the RuleTargetAttribute model + ruleTargetAttributeModel := new(configurationgovernancev1.RuleTargetAttribute) + ruleTargetAttributeModel.Name = core.StringPtr("testString") + ruleTargetAttributeModel.Operator = core.StringPtr("string_equals") + ruleTargetAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the TargetResource model + targetResourceModel := new(configurationgovernancev1.TargetResource) + targetResourceModel.ServiceName = core.StringPtr("iam-groups") + targetResourceModel.ResourceKind = core.StringPtr("service") + targetResourceModel.AdditionalTargetAttributes = []configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel} + + // Construct an instance of the RuleRequiredConfigSingleProperty model + ruleRequiredConfigModel := new(configurationgovernancev1.RuleRequiredConfigSingleProperty) + ruleRequiredConfigModel.Description = core.StringPtr("testString") + ruleRequiredConfigModel.Property = core.StringPtr("public_access_enabled") + ruleRequiredConfigModel.Operator = core.StringPtr("is_false") + ruleRequiredConfigModel.Value = core.StringPtr("testString") + + // Construct an instance of the EnforcementAction model + enforcementActionModel := new(configurationgovernancev1.EnforcementAction) + enforcementActionModel.Action = core.StringPtr("audit_log") + + // Construct an instance of the UpdateRuleOptions model + updateRuleOptionsModel := new(configurationgovernancev1.UpdateRuleOptions) + updateRuleOptionsModel.RuleID = core.StringPtr("testString") + updateRuleOptionsModel.IfMatch = core.StringPtr("testString") + updateRuleOptionsModel.Name = core.StringPtr("Disable public access") + updateRuleOptionsModel.Description = core.StringPtr("Ensure that public access to account resources is disabled.") + updateRuleOptionsModel.Target = targetResourceModel + updateRuleOptionsModel.RequiredConfig = ruleRequiredConfigModel + updateRuleOptionsModel.EnforcementActions = []configurationgovernancev1.EnforcementAction{*enforcementActionModel} + updateRuleOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + updateRuleOptionsModel.RuleType = core.StringPtr("user_defined") + updateRuleOptionsModel.Labels = []string{"testString"} + updateRuleOptionsModel.TransactionID = core.StringPtr("testString") + updateRuleOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := configurationGovernanceService.UpdateRule(updateRuleOptionsModel) + 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 UpdateRuleOptions model with no property values + updateRuleOptionsModelNew := new(configurationgovernancev1.UpdateRuleOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = configurationGovernanceService.UpdateRule(updateRuleOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`DeleteRule(deleteRuleOptions *DeleteRuleOptions)`, func() { + deleteRulePath := "/config/v1/rules/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.Path).To(Equal(deleteRulePath)) + Expect(req.Method).To(Equal("DELETE")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.WriteHeader(204) + })) + }) + It(`Invoke DeleteRule successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := configurationGovernanceService.DeleteRule(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeleteRuleOptions model + deleteRuleOptionsModel := new(configurationgovernancev1.DeleteRuleOptions) + deleteRuleOptionsModel.RuleID = core.StringPtr("testString") + deleteRuleOptionsModel.TransactionID = core.StringPtr("testString") + deleteRuleOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = configurationGovernanceService.DeleteRule(deleteRuleOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeleteRule with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the DeleteRuleOptions model + deleteRuleOptionsModel := new(configurationgovernancev1.DeleteRuleOptions) + deleteRuleOptionsModel.RuleID = core.StringPtr("testString") + deleteRuleOptionsModel.TransactionID = core.StringPtr("testString") + deleteRuleOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := configurationGovernanceService.DeleteRule(deleteRuleOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeleteRuleOptions model with no property values + deleteRuleOptionsModelNew := new(configurationgovernancev1.DeleteRuleOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = configurationGovernanceService.DeleteRule(deleteRuleOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateAttachments(createAttachmentsOptions *CreateAttachmentsOptions) - Operation response error`, func() { + createAttachmentsPath := "/config/v1/rules/testString/attachments" + 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.Path).To(Equal(createAttachmentsPath)) + Expect(req.Method).To(Equal("POST")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateAttachments with error: Operation response processing error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the RuleScope model + ruleScopeModel := new(configurationgovernancev1.RuleScope) + ruleScopeModel.Note = core.StringPtr("My enterprise") + ruleScopeModel.ScopeID = core.StringPtr("282cf433ac91493ba860480d92519990") + ruleScopeModel.ScopeType = core.StringPtr("enterprise") + + // Construct an instance of the AttachmentRequest model + attachmentRequestModel := new(configurationgovernancev1.AttachmentRequest) + attachmentRequestModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + attachmentRequestModel.IncludedScope = ruleScopeModel + attachmentRequestModel.ExcludedScopes = []configurationgovernancev1.RuleScope{*ruleScopeModel} + + // Construct an instance of the CreateAttachmentsOptions model + createAttachmentsOptionsModel := new(configurationgovernancev1.CreateAttachmentsOptions) + createAttachmentsOptionsModel.RuleID = core.StringPtr("testString") + createAttachmentsOptionsModel.Attachments = []configurationgovernancev1.AttachmentRequest{*attachmentRequestModel} + createAttachmentsOptionsModel.TransactionID = core.StringPtr("testString") + createAttachmentsOptionsModel.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 := configurationGovernanceService.CreateAttachments(createAttachmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`CreateAttachments(createAttachmentsOptions *CreateAttachmentsOptions)`, func() { + createAttachmentsPath := "/config/v1/rules/testString/attachments" + 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.Path).To(Equal(createAttachmentsPath)) + Expect(req.Method).To(Equal("POST")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"attachments": [{"attachment_id": "attachment-fc7b9a77-1c85-406c-b346-f3f5bb9aa7e2", "rule_id": "rule-81f3db5e-f9db-4c46-9de3-a4a76e66adbf", "account_id": "AccountID", "included_scope": {"note": "Note", "scope_id": "ScopeID", "scope_type": "enterprise"}, "excluded_scopes": [{"note": "Note", "scope_id": "ScopeID", "scope_type": "enterprise"}]}]}`) + })) + }) + It(`Invoke CreateAttachments successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := configurationGovernanceService.CreateAttachments(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the RuleScope model + ruleScopeModel := new(configurationgovernancev1.RuleScope) + ruleScopeModel.Note = core.StringPtr("My enterprise") + ruleScopeModel.ScopeID = core.StringPtr("282cf433ac91493ba860480d92519990") + ruleScopeModel.ScopeType = core.StringPtr("enterprise") + + // Construct an instance of the AttachmentRequest model + attachmentRequestModel := new(configurationgovernancev1.AttachmentRequest) + attachmentRequestModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + attachmentRequestModel.IncludedScope = ruleScopeModel + attachmentRequestModel.ExcludedScopes = []configurationgovernancev1.RuleScope{*ruleScopeModel} + + // Construct an instance of the CreateAttachmentsOptions model + createAttachmentsOptionsModel := new(configurationgovernancev1.CreateAttachmentsOptions) + createAttachmentsOptionsModel.RuleID = core.StringPtr("testString") + createAttachmentsOptionsModel.Attachments = []configurationgovernancev1.AttachmentRequest{*attachmentRequestModel} + createAttachmentsOptionsModel.TransactionID = core.StringPtr("testString") + createAttachmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = configurationGovernanceService.CreateAttachments(createAttachmentsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke CreateAttachments with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the RuleScope model + ruleScopeModel := new(configurationgovernancev1.RuleScope) + ruleScopeModel.Note = core.StringPtr("My enterprise") + ruleScopeModel.ScopeID = core.StringPtr("282cf433ac91493ba860480d92519990") + ruleScopeModel.ScopeType = core.StringPtr("enterprise") + + // Construct an instance of the AttachmentRequest model + attachmentRequestModel := new(configurationgovernancev1.AttachmentRequest) + attachmentRequestModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + attachmentRequestModel.IncludedScope = ruleScopeModel + attachmentRequestModel.ExcludedScopes = []configurationgovernancev1.RuleScope{*ruleScopeModel} + + // Construct an instance of the CreateAttachmentsOptions model + createAttachmentsOptionsModel := new(configurationgovernancev1.CreateAttachmentsOptions) + createAttachmentsOptionsModel.RuleID = core.StringPtr("testString") + createAttachmentsOptionsModel.Attachments = []configurationgovernancev1.AttachmentRequest{*attachmentRequestModel} + createAttachmentsOptionsModel.TransactionID = core.StringPtr("testString") + createAttachmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := configurationGovernanceService.CreateAttachments(createAttachmentsOptionsModel) + 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 CreateAttachmentsOptions model with no property values + createAttachmentsOptionsModelNew := new(configurationgovernancev1.CreateAttachmentsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = configurationGovernanceService.CreateAttachments(createAttachmentsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListAttachments(listAttachmentsOptions *ListAttachmentsOptions) - Operation response error`, func() { + listAttachmentsPath := "/config/v1/rules/testString/attachments" + 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.Path).To(Equal(listAttachmentsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(1000))})) + + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListAttachments with error: Operation response processing error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the ListAttachmentsOptions model + listAttachmentsOptionsModel := new(configurationgovernancev1.ListAttachmentsOptions) + listAttachmentsOptionsModel.RuleID = core.StringPtr("testString") + listAttachmentsOptionsModel.TransactionID = core.StringPtr("testString") + listAttachmentsOptionsModel.Limit = core.Int64Ptr(int64(1000)) + listAttachmentsOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAttachmentsOptionsModel.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 := configurationGovernanceService.ListAttachments(listAttachmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`ListAttachments(listAttachmentsOptions *ListAttachmentsOptions)`, func() { + listAttachmentsPath := "/config/v1/rules/testString/attachments" + 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.Path).To(Equal(listAttachmentsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(1000))})) + + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 1000, "total_count": 10, "first": {"href": "Href"}, "last": {"href": "Href"}, "attachments": [{"attachment_id": "attachment-fc7b9a77-1c85-406c-b346-f3f5bb9aa7e2", "rule_id": "rule-81f3db5e-f9db-4c46-9de3-a4a76e66adbf", "account_id": "AccountID", "included_scope": {"note": "Note", "scope_id": "ScopeID", "scope_type": "enterprise"}, "excluded_scopes": [{"note": "Note", "scope_id": "ScopeID", "scope_type": "enterprise"}]}]}`) + })) + }) + It(`Invoke ListAttachments successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := configurationGovernanceService.ListAttachments(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListAttachmentsOptions model + listAttachmentsOptionsModel := new(configurationgovernancev1.ListAttachmentsOptions) + listAttachmentsOptionsModel.RuleID = core.StringPtr("testString") + listAttachmentsOptionsModel.TransactionID = core.StringPtr("testString") + listAttachmentsOptionsModel.Limit = core.Int64Ptr(int64(1000)) + listAttachmentsOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAttachmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = configurationGovernanceService.ListAttachments(listAttachmentsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke ListAttachments with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the ListAttachmentsOptions model + listAttachmentsOptionsModel := new(configurationgovernancev1.ListAttachmentsOptions) + listAttachmentsOptionsModel.RuleID = core.StringPtr("testString") + listAttachmentsOptionsModel.TransactionID = core.StringPtr("testString") + listAttachmentsOptionsModel.Limit = core.Int64Ptr(int64(1000)) + listAttachmentsOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAttachmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := configurationGovernanceService.ListAttachments(listAttachmentsOptionsModel) + 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 ListAttachmentsOptions model with no property values + listAttachmentsOptionsModelNew := new(configurationgovernancev1.ListAttachmentsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = configurationGovernanceService.ListAttachments(listAttachmentsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetAttachment(getAttachmentOptions *GetAttachmentOptions) - Operation response error`, func() { + getAttachmentPath := "/config/v1/rules/testString/attachments/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.Path).To(Equal(getAttachmentPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetAttachment with error: Operation response processing error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the GetAttachmentOptions model + getAttachmentOptionsModel := new(configurationgovernancev1.GetAttachmentOptions) + getAttachmentOptionsModel.RuleID = core.StringPtr("testString") + getAttachmentOptionsModel.AttachmentID = core.StringPtr("testString") + getAttachmentOptionsModel.TransactionID = core.StringPtr("testString") + getAttachmentOptionsModel.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 := configurationGovernanceService.GetAttachment(getAttachmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`GetAttachment(getAttachmentOptions *GetAttachmentOptions)`, func() { + getAttachmentPath := "/config/v1/rules/testString/attachments/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.Path).To(Equal(getAttachmentPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"attachment_id": "attachment-fc7b9a77-1c85-406c-b346-f3f5bb9aa7e2", "rule_id": "rule-81f3db5e-f9db-4c46-9de3-a4a76e66adbf", "account_id": "AccountID", "included_scope": {"note": "Note", "scope_id": "ScopeID", "scope_type": "enterprise"}, "excluded_scopes": [{"note": "Note", "scope_id": "ScopeID", "scope_type": "enterprise"}]}`) + })) + }) + It(`Invoke GetAttachment successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := configurationGovernanceService.GetAttachment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetAttachmentOptions model + getAttachmentOptionsModel := new(configurationgovernancev1.GetAttachmentOptions) + getAttachmentOptionsModel.RuleID = core.StringPtr("testString") + getAttachmentOptionsModel.AttachmentID = core.StringPtr("testString") + getAttachmentOptionsModel.TransactionID = core.StringPtr("testString") + getAttachmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = configurationGovernanceService.GetAttachment(getAttachmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke GetAttachment with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the GetAttachmentOptions model + getAttachmentOptionsModel := new(configurationgovernancev1.GetAttachmentOptions) + getAttachmentOptionsModel.RuleID = core.StringPtr("testString") + getAttachmentOptionsModel.AttachmentID = core.StringPtr("testString") + getAttachmentOptionsModel.TransactionID = core.StringPtr("testString") + getAttachmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := configurationGovernanceService.GetAttachment(getAttachmentOptionsModel) + 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 GetAttachmentOptions model with no property values + getAttachmentOptionsModelNew := new(configurationgovernancev1.GetAttachmentOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = configurationGovernanceService.GetAttachment(getAttachmentOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateAttachment(updateAttachmentOptions *UpdateAttachmentOptions) - Operation response error`, func() { + updateAttachmentPath := "/config/v1/rules/testString/attachments/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.Path).To(Equal(updateAttachmentPath)) + Expect(req.Method).To(Equal("PUT")) + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateAttachment with error: Operation response processing error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the RuleScope model + ruleScopeModel := new(configurationgovernancev1.RuleScope) + ruleScopeModel.Note = core.StringPtr("My enterprise") + ruleScopeModel.ScopeID = core.StringPtr("282cf433ac91493ba860480d92519990") + ruleScopeModel.ScopeType = core.StringPtr("enterprise") + + // Construct an instance of the UpdateAttachmentOptions model + updateAttachmentOptionsModel := new(configurationgovernancev1.UpdateAttachmentOptions) + updateAttachmentOptionsModel.RuleID = core.StringPtr("testString") + updateAttachmentOptionsModel.AttachmentID = core.StringPtr("testString") + updateAttachmentOptionsModel.IfMatch = core.StringPtr("testString") + updateAttachmentOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + updateAttachmentOptionsModel.IncludedScope = ruleScopeModel + updateAttachmentOptionsModel.ExcludedScopes = []configurationgovernancev1.RuleScope{*ruleScopeModel} + updateAttachmentOptionsModel.TransactionID = core.StringPtr("testString") + updateAttachmentOptionsModel.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 := configurationGovernanceService.UpdateAttachment(updateAttachmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`UpdateAttachment(updateAttachmentOptions *UpdateAttachmentOptions)`, func() { + updateAttachmentPath := "/config/v1/rules/testString/attachments/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.Path).To(Equal(updateAttachmentPath)) + Expect(req.Method).To(Equal("PUT")) + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"attachment_id": "attachment-fc7b9a77-1c85-406c-b346-f3f5bb9aa7e2", "rule_id": "rule-81f3db5e-f9db-4c46-9de3-a4a76e66adbf", "account_id": "AccountID", "included_scope": {"note": "Note", "scope_id": "ScopeID", "scope_type": "enterprise"}, "excluded_scopes": [{"note": "Note", "scope_id": "ScopeID", "scope_type": "enterprise"}]}`) + })) + }) + It(`Invoke UpdateAttachment successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := configurationGovernanceService.UpdateAttachment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the RuleScope model + ruleScopeModel := new(configurationgovernancev1.RuleScope) + ruleScopeModel.Note = core.StringPtr("My enterprise") + ruleScopeModel.ScopeID = core.StringPtr("282cf433ac91493ba860480d92519990") + ruleScopeModel.ScopeType = core.StringPtr("enterprise") + + // Construct an instance of the UpdateAttachmentOptions model + updateAttachmentOptionsModel := new(configurationgovernancev1.UpdateAttachmentOptions) + updateAttachmentOptionsModel.RuleID = core.StringPtr("testString") + updateAttachmentOptionsModel.AttachmentID = core.StringPtr("testString") + updateAttachmentOptionsModel.IfMatch = core.StringPtr("testString") + updateAttachmentOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + updateAttachmentOptionsModel.IncludedScope = ruleScopeModel + updateAttachmentOptionsModel.ExcludedScopes = []configurationgovernancev1.RuleScope{*ruleScopeModel} + updateAttachmentOptionsModel.TransactionID = core.StringPtr("testString") + updateAttachmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = configurationGovernanceService.UpdateAttachment(updateAttachmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke UpdateAttachment with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the RuleScope model + ruleScopeModel := new(configurationgovernancev1.RuleScope) + ruleScopeModel.Note = core.StringPtr("My enterprise") + ruleScopeModel.ScopeID = core.StringPtr("282cf433ac91493ba860480d92519990") + ruleScopeModel.ScopeType = core.StringPtr("enterprise") + + // Construct an instance of the UpdateAttachmentOptions model + updateAttachmentOptionsModel := new(configurationgovernancev1.UpdateAttachmentOptions) + updateAttachmentOptionsModel.RuleID = core.StringPtr("testString") + updateAttachmentOptionsModel.AttachmentID = core.StringPtr("testString") + updateAttachmentOptionsModel.IfMatch = core.StringPtr("testString") + updateAttachmentOptionsModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + updateAttachmentOptionsModel.IncludedScope = ruleScopeModel + updateAttachmentOptionsModel.ExcludedScopes = []configurationgovernancev1.RuleScope{*ruleScopeModel} + updateAttachmentOptionsModel.TransactionID = core.StringPtr("testString") + updateAttachmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := configurationGovernanceService.UpdateAttachment(updateAttachmentOptionsModel) + 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 UpdateAttachmentOptions model with no property values + updateAttachmentOptionsModelNew := new(configurationgovernancev1.UpdateAttachmentOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = configurationGovernanceService.UpdateAttachment(updateAttachmentOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`DeleteAttachment(deleteAttachmentOptions *DeleteAttachmentOptions)`, func() { + deleteAttachmentPath := "/config/v1/rules/testString/attachments/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.Path).To(Equal(deleteAttachmentPath)) + Expect(req.Method).To(Equal("DELETE")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.WriteHeader(204) + })) + }) + It(`Invoke DeleteAttachment successfully`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := configurationGovernanceService.DeleteAttachment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeleteAttachmentOptions model + deleteAttachmentOptionsModel := new(configurationgovernancev1.DeleteAttachmentOptions) + deleteAttachmentOptionsModel.RuleID = core.StringPtr("testString") + deleteAttachmentOptionsModel.AttachmentID = core.StringPtr("testString") + deleteAttachmentOptionsModel.TransactionID = core.StringPtr("testString") + deleteAttachmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = configurationGovernanceService.DeleteAttachment(deleteAttachmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeleteAttachment with error: Operation validation and request error`, func() { + configurationGovernanceService, serviceErr := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(configurationGovernanceService).ToNot(BeNil()) + + // Construct an instance of the DeleteAttachmentOptions model + deleteAttachmentOptionsModel := new(configurationgovernancev1.DeleteAttachmentOptions) + deleteAttachmentOptionsModel.RuleID = core.StringPtr("testString") + deleteAttachmentOptionsModel.AttachmentID = core.StringPtr("testString") + deleteAttachmentOptionsModel.TransactionID = core.StringPtr("testString") + deleteAttachmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := configurationGovernanceService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := configurationGovernanceService.DeleteAttachment(deleteAttachmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeleteAttachmentOptions model with no property values + deleteAttachmentOptionsModelNew := new(configurationgovernancev1.DeleteAttachmentOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = configurationGovernanceService.DeleteAttachment(deleteAttachmentOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`Model constructor tests`, func() { + Context(`Using a service client instance`, func() { + configurationGovernanceService, _ := configurationgovernancev1.NewConfigurationGovernanceV1(&configurationgovernancev1.ConfigurationGovernanceV1Options{ + URL: "http://configurationgovernancev1modelgenerator.com", + Authenticator: &core.NoAuthAuthenticator{}, + }) + It(`Invoke NewAttachmentRequest successfully`, func() { + accountID := "testString" + var includedScope *configurationgovernancev1.RuleScope = nil + _, err := configurationGovernanceService.NewAttachmentRequest(accountID, includedScope) + Expect(err).ToNot(BeNil()) + }) + It(`Invoke NewCreateAttachmentsOptions successfully`, func() { + // Construct an instance of the RuleScope model + ruleScopeModel := new(configurationgovernancev1.RuleScope) + Expect(ruleScopeModel).ToNot(BeNil()) + ruleScopeModel.Note = core.StringPtr("My enterprise") + ruleScopeModel.ScopeID = core.StringPtr("282cf433ac91493ba860480d92519990") + ruleScopeModel.ScopeType = core.StringPtr("enterprise") + Expect(ruleScopeModel.Note).To(Equal(core.StringPtr("My enterprise"))) + Expect(ruleScopeModel.ScopeID).To(Equal(core.StringPtr("282cf433ac91493ba860480d92519990"))) + Expect(ruleScopeModel.ScopeType).To(Equal(core.StringPtr("enterprise"))) + + // Construct an instance of the AttachmentRequest model + attachmentRequestModel := new(configurationgovernancev1.AttachmentRequest) + Expect(attachmentRequestModel).ToNot(BeNil()) + attachmentRequestModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + attachmentRequestModel.IncludedScope = ruleScopeModel + attachmentRequestModel.ExcludedScopes = []configurationgovernancev1.RuleScope{*ruleScopeModel} + Expect(attachmentRequestModel.AccountID).To(Equal(core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c"))) + Expect(attachmentRequestModel.IncludedScope).To(Equal(ruleScopeModel)) + Expect(attachmentRequestModel.ExcludedScopes).To(Equal([]configurationgovernancev1.RuleScope{*ruleScopeModel})) + + // Construct an instance of the CreateAttachmentsOptions model + ruleID := "testString" + createAttachmentsOptionsAttachments := []configurationgovernancev1.AttachmentRequest{} + createAttachmentsOptionsModel := configurationGovernanceService.NewCreateAttachmentsOptions(ruleID, createAttachmentsOptionsAttachments) + createAttachmentsOptionsModel.SetRuleID("testString") + createAttachmentsOptionsModel.SetAttachments([]configurationgovernancev1.AttachmentRequest{*attachmentRequestModel}) + createAttachmentsOptionsModel.SetTransactionID("testString") + createAttachmentsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createAttachmentsOptionsModel).ToNot(BeNil()) + Expect(createAttachmentsOptionsModel.RuleID).To(Equal(core.StringPtr("testString"))) + Expect(createAttachmentsOptionsModel.Attachments).To(Equal([]configurationgovernancev1.AttachmentRequest{*attachmentRequestModel})) + Expect(createAttachmentsOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(createAttachmentsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewCreateRuleRequest successfully`, func() { + var rule *configurationgovernancev1.RuleRequest = nil + _, err := configurationGovernanceService.NewCreateRuleRequest(rule) + Expect(err).ToNot(BeNil()) + }) + It(`Invoke NewCreateRulesOptions successfully`, func() { + // Construct an instance of the RuleTargetAttribute model + ruleTargetAttributeModel := new(configurationgovernancev1.RuleTargetAttribute) + Expect(ruleTargetAttributeModel).ToNot(BeNil()) + ruleTargetAttributeModel.Name = core.StringPtr("testString") + ruleTargetAttributeModel.Operator = core.StringPtr("string_equals") + ruleTargetAttributeModel.Value = core.StringPtr("testString") + Expect(ruleTargetAttributeModel.Name).To(Equal(core.StringPtr("testString"))) + Expect(ruleTargetAttributeModel.Operator).To(Equal(core.StringPtr("string_equals"))) + Expect(ruleTargetAttributeModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the TargetResource model + targetResourceModel := new(configurationgovernancev1.TargetResource) + Expect(targetResourceModel).ToNot(BeNil()) + targetResourceModel.ServiceName = core.StringPtr("iam-groups") + targetResourceModel.ResourceKind = core.StringPtr("service") + targetResourceModel.AdditionalTargetAttributes = []configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel} + Expect(targetResourceModel.ServiceName).To(Equal(core.StringPtr("iam-groups"))) + Expect(targetResourceModel.ResourceKind).To(Equal(core.StringPtr("service"))) + Expect(targetResourceModel.AdditionalTargetAttributes).To(Equal([]configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel})) + + // Construct an instance of the RuleRequiredConfigSingleProperty model + ruleRequiredConfigModel := new(configurationgovernancev1.RuleRequiredConfigSingleProperty) + Expect(ruleRequiredConfigModel).ToNot(BeNil()) + ruleRequiredConfigModel.Description = core.StringPtr("Public access check") + ruleRequiredConfigModel.Property = core.StringPtr("public_access_enabled") + ruleRequiredConfigModel.Operator = core.StringPtr("is_true") + ruleRequiredConfigModel.Value = core.StringPtr("testString") + Expect(ruleRequiredConfigModel.Description).To(Equal(core.StringPtr("Public access check"))) + Expect(ruleRequiredConfigModel.Property).To(Equal(core.StringPtr("public_access_enabled"))) + Expect(ruleRequiredConfigModel.Operator).To(Equal(core.StringPtr("is_true"))) + Expect(ruleRequiredConfigModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the EnforcementAction model + enforcementActionModel := new(configurationgovernancev1.EnforcementAction) + Expect(enforcementActionModel).ToNot(BeNil()) + enforcementActionModel.Action = core.StringPtr("audit_log") + Expect(enforcementActionModel.Action).To(Equal(core.StringPtr("audit_log"))) + + // Construct an instance of the RuleRequest model + ruleRequestModel := new(configurationgovernancev1.RuleRequest) + Expect(ruleRequestModel).ToNot(BeNil()) + ruleRequestModel.AccountID = core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c") + ruleRequestModel.Name = core.StringPtr("Disable public access") + ruleRequestModel.Description = core.StringPtr("Ensure that public access to account resources is disabled.") + ruleRequestModel.RuleType = core.StringPtr("user_defined") + ruleRequestModel.Target = targetResourceModel + ruleRequestModel.RequiredConfig = ruleRequiredConfigModel + ruleRequestModel.EnforcementActions = []configurationgovernancev1.EnforcementAction{*enforcementActionModel} + ruleRequestModel.Labels = []string{"testString"} + Expect(ruleRequestModel.AccountID).To(Equal(core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c"))) + Expect(ruleRequestModel.Name).To(Equal(core.StringPtr("Disable public access"))) + Expect(ruleRequestModel.Description).To(Equal(core.StringPtr("Ensure that public access to account resources is disabled."))) + Expect(ruleRequestModel.RuleType).To(Equal(core.StringPtr("user_defined"))) + Expect(ruleRequestModel.Target).To(Equal(targetResourceModel)) + Expect(ruleRequestModel.RequiredConfig).To(Equal(ruleRequiredConfigModel)) + Expect(ruleRequestModel.EnforcementActions).To(Equal([]configurationgovernancev1.EnforcementAction{*enforcementActionModel})) + Expect(ruleRequestModel.Labels).To(Equal([]string{"testString"})) + + // Construct an instance of the CreateRuleRequest model + createRuleRequestModel := new(configurationgovernancev1.CreateRuleRequest) + Expect(createRuleRequestModel).ToNot(BeNil()) + createRuleRequestModel.RequestID = core.StringPtr("3cebc877-58e7-44a5-a292-32114fa73558") + createRuleRequestModel.Rule = ruleRequestModel + Expect(createRuleRequestModel.RequestID).To(Equal(core.StringPtr("3cebc877-58e7-44a5-a292-32114fa73558"))) + Expect(createRuleRequestModel.Rule).To(Equal(ruleRequestModel)) + + // Construct an instance of the CreateRulesOptions model + createRulesOptionsRules := []configurationgovernancev1.CreateRuleRequest{} + createRulesOptionsModel := configurationGovernanceService.NewCreateRulesOptions(createRulesOptionsRules) + createRulesOptionsModel.SetRules([]configurationgovernancev1.CreateRuleRequest{*createRuleRequestModel}) + createRulesOptionsModel.SetTransactionID("testString") + createRulesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createRulesOptionsModel).ToNot(BeNil()) + Expect(createRulesOptionsModel.Rules).To(Equal([]configurationgovernancev1.CreateRuleRequest{*createRuleRequestModel})) + Expect(createRulesOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(createRulesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteAttachmentOptions successfully`, func() { + // Construct an instance of the DeleteAttachmentOptions model + ruleID := "testString" + attachmentID := "testString" + deleteAttachmentOptionsModel := configurationGovernanceService.NewDeleteAttachmentOptions(ruleID, attachmentID) + deleteAttachmentOptionsModel.SetRuleID("testString") + deleteAttachmentOptionsModel.SetAttachmentID("testString") + deleteAttachmentOptionsModel.SetTransactionID("testString") + deleteAttachmentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteAttachmentOptionsModel).ToNot(BeNil()) + Expect(deleteAttachmentOptionsModel.RuleID).To(Equal(core.StringPtr("testString"))) + Expect(deleteAttachmentOptionsModel.AttachmentID).To(Equal(core.StringPtr("testString"))) + Expect(deleteAttachmentOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(deleteAttachmentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteRuleOptions successfully`, func() { + // Construct an instance of the DeleteRuleOptions model + ruleID := "testString" + deleteRuleOptionsModel := configurationGovernanceService.NewDeleteRuleOptions(ruleID) + deleteRuleOptionsModel.SetRuleID("testString") + deleteRuleOptionsModel.SetTransactionID("testString") + deleteRuleOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteRuleOptionsModel).ToNot(BeNil()) + Expect(deleteRuleOptionsModel.RuleID).To(Equal(core.StringPtr("testString"))) + Expect(deleteRuleOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(deleteRuleOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewEnforcementAction successfully`, func() { + action := "audit_log" + model, err := configurationGovernanceService.NewEnforcementAction(action) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewGetAttachmentOptions successfully`, func() { + // Construct an instance of the GetAttachmentOptions model + ruleID := "testString" + attachmentID := "testString" + getAttachmentOptionsModel := configurationGovernanceService.NewGetAttachmentOptions(ruleID, attachmentID) + getAttachmentOptionsModel.SetRuleID("testString") + getAttachmentOptionsModel.SetAttachmentID("testString") + getAttachmentOptionsModel.SetTransactionID("testString") + getAttachmentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getAttachmentOptionsModel).ToNot(BeNil()) + Expect(getAttachmentOptionsModel.RuleID).To(Equal(core.StringPtr("testString"))) + Expect(getAttachmentOptionsModel.AttachmentID).To(Equal(core.StringPtr("testString"))) + Expect(getAttachmentOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(getAttachmentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetRuleOptions successfully`, func() { + // Construct an instance of the GetRuleOptions model + ruleID := "testString" + getRuleOptionsModel := configurationGovernanceService.NewGetRuleOptions(ruleID) + getRuleOptionsModel.SetRuleID("testString") + getRuleOptionsModel.SetTransactionID("testString") + getRuleOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getRuleOptionsModel).ToNot(BeNil()) + Expect(getRuleOptionsModel.RuleID).To(Equal(core.StringPtr("testString"))) + Expect(getRuleOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(getRuleOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListAttachmentsOptions successfully`, func() { + // Construct an instance of the ListAttachmentsOptions model + ruleID := "testString" + listAttachmentsOptionsModel := configurationGovernanceService.NewListAttachmentsOptions(ruleID) + listAttachmentsOptionsModel.SetRuleID("testString") + listAttachmentsOptionsModel.SetTransactionID("testString") + listAttachmentsOptionsModel.SetLimit(int64(1000)) + listAttachmentsOptionsModel.SetOffset(int64(38)) + listAttachmentsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listAttachmentsOptionsModel).ToNot(BeNil()) + Expect(listAttachmentsOptionsModel.RuleID).To(Equal(core.StringPtr("testString"))) + Expect(listAttachmentsOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(listAttachmentsOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(1000)))) + Expect(listAttachmentsOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(38)))) + Expect(listAttachmentsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListRulesOptions successfully`, func() { + // Construct an instance of the ListRulesOptions model + accountID := "531fc3e28bfc43c5a2cea07786d93f5c" + listRulesOptionsModel := configurationGovernanceService.NewListRulesOptions(accountID) + listRulesOptionsModel.SetAccountID("531fc3e28bfc43c5a2cea07786d93f5c") + listRulesOptionsModel.SetTransactionID("testString") + listRulesOptionsModel.SetAttached(true) + listRulesOptionsModel.SetLabels("SOC2,ITCS300") + listRulesOptionsModel.SetScopes("scope_id") + listRulesOptionsModel.SetLimit(int64(1000)) + listRulesOptionsModel.SetOffset(int64(38)) + listRulesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listRulesOptionsModel).ToNot(BeNil()) + Expect(listRulesOptionsModel.AccountID).To(Equal(core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c"))) + Expect(listRulesOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(listRulesOptionsModel.Attached).To(Equal(core.BoolPtr(true))) + Expect(listRulesOptionsModel.Labels).To(Equal(core.StringPtr("SOC2,ITCS300"))) + Expect(listRulesOptionsModel.Scopes).To(Equal(core.StringPtr("scope_id"))) + Expect(listRulesOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(1000)))) + Expect(listRulesOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(38)))) + Expect(listRulesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewRuleRequest successfully`, func() { + name := "testString" + description := "testString" + var target *configurationgovernancev1.TargetResource = nil + var requiredConfig configurationgovernancev1.RuleRequiredConfigIntf = nil + enforcementActions := []configurationgovernancev1.EnforcementAction{} + _, err := configurationGovernanceService.NewRuleRequest(name, description, target, requiredConfig, enforcementActions) + Expect(err).ToNot(BeNil()) + }) + It(`Invoke NewRuleScope successfully`, func() { + scopeID := "testString" + scopeType := "enterprise" + model, err := configurationGovernanceService.NewRuleScope(scopeID, scopeType) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRuleSingleProperty successfully`, func() { + property := "public_access_enabled" + operator := "is_true" + model, err := configurationGovernanceService.NewRuleSingleProperty(property, operator) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRuleTargetAttribute successfully`, func() { + name := "testString" + operator := "string_equals" + model, err := configurationGovernanceService.NewRuleTargetAttribute(name, operator) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewTargetResource successfully`, func() { + serviceName := "iam-groups" + resourceKind := "zone" + model, err := configurationGovernanceService.NewTargetResource(serviceName, resourceKind) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewUpdateAttachmentOptions successfully`, func() { + // Construct an instance of the RuleScope model + ruleScopeModel := new(configurationgovernancev1.RuleScope) + Expect(ruleScopeModel).ToNot(BeNil()) + ruleScopeModel.Note = core.StringPtr("My enterprise") + ruleScopeModel.ScopeID = core.StringPtr("282cf433ac91493ba860480d92519990") + ruleScopeModel.ScopeType = core.StringPtr("enterprise") + Expect(ruleScopeModel.Note).To(Equal(core.StringPtr("My enterprise"))) + Expect(ruleScopeModel.ScopeID).To(Equal(core.StringPtr("282cf433ac91493ba860480d92519990"))) + Expect(ruleScopeModel.ScopeType).To(Equal(core.StringPtr("enterprise"))) + + // Construct an instance of the UpdateAttachmentOptions model + ruleID := "testString" + attachmentID := "testString" + ifMatch := "testString" + updateAttachmentOptionsAccountID := "531fc3e28bfc43c5a2cea07786d93f5c" + var updateAttachmentOptionsIncludedScope *configurationgovernancev1.RuleScope = nil + updateAttachmentOptionsModel := configurationGovernanceService.NewUpdateAttachmentOptions(ruleID, attachmentID, ifMatch, updateAttachmentOptionsAccountID, updateAttachmentOptionsIncludedScope) + updateAttachmentOptionsModel.SetRuleID("testString") + updateAttachmentOptionsModel.SetAttachmentID("testString") + updateAttachmentOptionsModel.SetIfMatch("testString") + updateAttachmentOptionsModel.SetAccountID("531fc3e28bfc43c5a2cea07786d93f5c") + updateAttachmentOptionsModel.SetIncludedScope(ruleScopeModel) + updateAttachmentOptionsModel.SetExcludedScopes([]configurationgovernancev1.RuleScope{*ruleScopeModel}) + updateAttachmentOptionsModel.SetTransactionID("testString") + updateAttachmentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(updateAttachmentOptionsModel).ToNot(BeNil()) + Expect(updateAttachmentOptionsModel.RuleID).To(Equal(core.StringPtr("testString"))) + Expect(updateAttachmentOptionsModel.AttachmentID).To(Equal(core.StringPtr("testString"))) + Expect(updateAttachmentOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) + Expect(updateAttachmentOptionsModel.AccountID).To(Equal(core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c"))) + Expect(updateAttachmentOptionsModel.IncludedScope).To(Equal(ruleScopeModel)) + Expect(updateAttachmentOptionsModel.ExcludedScopes).To(Equal([]configurationgovernancev1.RuleScope{*ruleScopeModel})) + Expect(updateAttachmentOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(updateAttachmentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewUpdateRuleOptions successfully`, func() { + // Construct an instance of the RuleTargetAttribute model + ruleTargetAttributeModel := new(configurationgovernancev1.RuleTargetAttribute) + Expect(ruleTargetAttributeModel).ToNot(BeNil()) + ruleTargetAttributeModel.Name = core.StringPtr("testString") + ruleTargetAttributeModel.Operator = core.StringPtr("string_equals") + ruleTargetAttributeModel.Value = core.StringPtr("testString") + Expect(ruleTargetAttributeModel.Name).To(Equal(core.StringPtr("testString"))) + Expect(ruleTargetAttributeModel.Operator).To(Equal(core.StringPtr("string_equals"))) + Expect(ruleTargetAttributeModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the TargetResource model + targetResourceModel := new(configurationgovernancev1.TargetResource) + Expect(targetResourceModel).ToNot(BeNil()) + targetResourceModel.ServiceName = core.StringPtr("iam-groups") + targetResourceModel.ResourceKind = core.StringPtr("service") + targetResourceModel.AdditionalTargetAttributes = []configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel} + Expect(targetResourceModel.ServiceName).To(Equal(core.StringPtr("iam-groups"))) + Expect(targetResourceModel.ResourceKind).To(Equal(core.StringPtr("service"))) + Expect(targetResourceModel.AdditionalTargetAttributes).To(Equal([]configurationgovernancev1.RuleTargetAttribute{*ruleTargetAttributeModel})) + + // Construct an instance of the RuleRequiredConfigSingleProperty model + ruleRequiredConfigModel := new(configurationgovernancev1.RuleRequiredConfigSingleProperty) + Expect(ruleRequiredConfigModel).ToNot(BeNil()) + ruleRequiredConfigModel.Description = core.StringPtr("testString") + ruleRequiredConfigModel.Property = core.StringPtr("public_access_enabled") + ruleRequiredConfigModel.Operator = core.StringPtr("is_false") + ruleRequiredConfigModel.Value = core.StringPtr("testString") + Expect(ruleRequiredConfigModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(ruleRequiredConfigModel.Property).To(Equal(core.StringPtr("public_access_enabled"))) + Expect(ruleRequiredConfigModel.Operator).To(Equal(core.StringPtr("is_false"))) + Expect(ruleRequiredConfigModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the EnforcementAction model + enforcementActionModel := new(configurationgovernancev1.EnforcementAction) + Expect(enforcementActionModel).ToNot(BeNil()) + enforcementActionModel.Action = core.StringPtr("audit_log") + Expect(enforcementActionModel.Action).To(Equal(core.StringPtr("audit_log"))) + + // Construct an instance of the UpdateRuleOptions model + ruleID := "testString" + ifMatch := "testString" + updateRuleOptionsName := "Disable public access" + updateRuleOptionsDescription := "Ensure that public access to account resources is disabled." + var updateRuleOptionsTarget *configurationgovernancev1.TargetResource = nil + var updateRuleOptionsRequiredConfig configurationgovernancev1.RuleRequiredConfigIntf = nil + updateRuleOptionsEnforcementActions := []configurationgovernancev1.EnforcementAction{} + updateRuleOptionsModel := configurationGovernanceService.NewUpdateRuleOptions(ruleID, ifMatch, updateRuleOptionsName, updateRuleOptionsDescription, updateRuleOptionsTarget, updateRuleOptionsRequiredConfig, updateRuleOptionsEnforcementActions) + updateRuleOptionsModel.SetRuleID("testString") + updateRuleOptionsModel.SetIfMatch("testString") + updateRuleOptionsModel.SetName("Disable public access") + updateRuleOptionsModel.SetDescription("Ensure that public access to account resources is disabled.") + updateRuleOptionsModel.SetTarget(targetResourceModel) + updateRuleOptionsModel.SetRequiredConfig(ruleRequiredConfigModel) + updateRuleOptionsModel.SetEnforcementActions([]configurationgovernancev1.EnforcementAction{*enforcementActionModel}) + updateRuleOptionsModel.SetAccountID("531fc3e28bfc43c5a2cea07786d93f5c") + updateRuleOptionsModel.SetRuleType("user_defined") + updateRuleOptionsModel.SetLabels([]string{"testString"}) + updateRuleOptionsModel.SetTransactionID("testString") + updateRuleOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(updateRuleOptionsModel).ToNot(BeNil()) + Expect(updateRuleOptionsModel.RuleID).To(Equal(core.StringPtr("testString"))) + Expect(updateRuleOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) + Expect(updateRuleOptionsModel.Name).To(Equal(core.StringPtr("Disable public access"))) + Expect(updateRuleOptionsModel.Description).To(Equal(core.StringPtr("Ensure that public access to account resources is disabled."))) + Expect(updateRuleOptionsModel.Target).To(Equal(targetResourceModel)) + Expect(updateRuleOptionsModel.RequiredConfig).To(Equal(ruleRequiredConfigModel)) + Expect(updateRuleOptionsModel.EnforcementActions).To(Equal([]configurationgovernancev1.EnforcementAction{*enforcementActionModel})) + Expect(updateRuleOptionsModel.AccountID).To(Equal(core.StringPtr("531fc3e28bfc43c5a2cea07786d93f5c"))) + Expect(updateRuleOptionsModel.RuleType).To(Equal(core.StringPtr("user_defined"))) + Expect(updateRuleOptionsModel.Labels).To(Equal([]string{"testString"})) + Expect(updateRuleOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(updateRuleOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewRuleConditionAndLvl2 successfully`, func() { + and := []configurationgovernancev1.RuleSingleProperty{} + model, err := configurationGovernanceService.NewRuleConditionAndLvl2(and) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRuleConditionOrLvl2 successfully`, func() { + or := []configurationgovernancev1.RuleSingleProperty{} + model, err := configurationGovernanceService.NewRuleConditionOrLvl2(or) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRuleConditionSingleProperty successfully`, func() { + property := "public_access_enabled" + operator := "is_true" + model, err := configurationGovernanceService.NewRuleConditionSingleProperty(property, operator) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRuleRequiredConfigSingleProperty successfully`, func() { + property := "public_access_enabled" + operator := "is_true" + model, err := configurationGovernanceService.NewRuleRequiredConfigSingleProperty(property, operator) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRuleRequiredConfigMultiplePropertiesConditionAnd successfully`, func() { + and := []configurationgovernancev1.RuleConditionIntf{} + model, err := configurationGovernanceService.NewRuleRequiredConfigMultiplePropertiesConditionAnd(and) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRuleRequiredConfigMultiplePropertiesConditionOr successfully`, func() { + or := []configurationgovernancev1.RuleConditionIntf{} + model, err := configurationGovernanceService.NewRuleRequiredConfigMultiplePropertiesConditionOr(or) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + }) + }) + Describe(`Utility function tests`, func() { + It(`Invoke CreateMockByteArray() successfully`, func() { + mockByteArray := CreateMockByteArray("This is a test") + 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() + Expect(mockDate).ToNot(BeNil()) + }) + It(`Invoke CreateMockDateTime() successfully`, func() { + mockDateTime := CreateMockDateTime() + Expect(mockDateTime).ToNot(BeNil()) + }) + }) +}) + +// +// Utility functions used by the generated test code +// + +func CreateMockByteArray(mockData string) *[]byte { + ba := make([]byte, 0) + ba = append(ba, mockData...) + return &ba +} + +func CreateMockUUID(mockData string) *strfmt.UUID { + uuid := strfmt.UUID(mockData) + return &uuid +} + +func CreateMockReader(mockData string) io.ReadCloser { + return ioutil.NopCloser(bytes.NewReader([]byte(mockData))) +} + +func CreateMockDate() *strfmt.Date { + d := strfmt.Date(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) + return &d +} + +func CreateMockDateTime() *strfmt.DateTime { + d := strfmt.DateTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) + 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) + } +} diff --git a/go.mod b/go.mod index 56a9e0c0..284ed756 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,9 @@ module github.com/IBM/platform-services-go-sdk go 1.12 require ( - github.com/IBM/go-sdk-core/v4 v4.1.0 + github.com/IBM/go-sdk-core/v4 v4.3.0 github.com/go-openapi/strfmt v0.19.5 + github.com/google/uuid v1.1.1 github.com/joho/godotenv v1.3.0 github.com/onsi/ginkgo v1.12.0 github.com/onsi/gomega v1.9.0 diff --git a/go.sum b/go.sum index 31d6651d..9fa0e95a 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/IBM/go-sdk-core/v4 v4.1.0 h1:KHOZj/P4MFyj9hdNx8OvlsKJ96kBDs84fw8UAOAet5k= -github.com/IBM/go-sdk-core/v4 v4.1.0/go.mod h1:lTUXbqIX6/aAbSCkP6q59+dyFsTwZAc0ewRS2vJWVbg= +github.com/IBM/go-sdk-core/v4 v4.3.0 h1:gWfy8HpptwpgKqXaDPwgomcRTED7wJLkd+nDoz3undo= +github.com/IBM/go-sdk-core/v4 v4.3.0/go.mod h1:lTUXbqIX6/aAbSCkP6q59+dyFsTwZAc0ewRS2vJWVbg= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=