From e1fe0be05c63c8832ce43410f8714afc46f35c4f Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Thu, 18 May 2023 19:32:21 +0530 Subject: [PATCH 1/9] feat(IAM Policy Management): re-gen service after recent API changes, Tests added for Policy Template Signed-off-by: Vivek.Jain3 --- .../iam_policy_management_v1.go | 2061 +++++++++- .../iam_policy_management_v1_examples_test.go | 359 +- ...m_policy_management_v1_integration_test.go | 325 +- .../iam_policy_management_v1_test.go | 3419 ++++++++++++++++- 4 files changed, 6045 insertions(+), 119 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1.go b/iampolicymanagementv1/iam_policy_management_v1.go index 0d2d9778..b5ec4351 100644 --- a/iampolicymanagementv1/iam_policy_management_v1.go +++ b/iampolicymanagementv1/iam_policy_management_v1.go @@ -15,7 +15,7 @@ */ /* - * IBM OpenAPI SDK Code Generator Version: 3.68.2-ac7def68-20230310-195410 + * IBM OpenAPI SDK Code Generator Version: 3.71.0-316eb5da-20230504-195406 */ // Package iampolicymanagementv1 : Operations and models for the IamPolicyManagementV1 service @@ -1524,6 +1524,830 @@ func (iamPolicyManagement *IamPolicyManagementV1) DeleteV2PolicyWithContext(ctx return } +// ListPolicyTemplates : Get policy templates by attributes +// Get policy templates and filter by attributes through query parameters. The following attributes are supported: +// account_id account_id is a required query parameter. Only policy templates that have the specified attributes and +// that the caller has read access to are returned. If the caller does not have read access to any policy templates an +// empty array is returned. +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyTemplates(listPolicyTemplatesOptions *ListPolicyTemplatesOptions) (result *PolicyTemplateCollection, response *core.DetailedResponse, err error) { + return iamPolicyManagement.ListPolicyTemplatesWithContext(context.Background(), listPolicyTemplatesOptions) +} + +// ListPolicyTemplatesWithContext is an alternate form of the ListPolicyTemplates method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyTemplatesWithContext(ctx context.Context, listPolicyTemplatesOptions *ListPolicyTemplatesOptions) (result *PolicyTemplateCollection, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listPolicyTemplatesOptions, "listPolicyTemplatesOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(listPolicyTemplatesOptions, "listPolicyTemplatesOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates`, nil) + if err != nil { + return + } + + for headerName, headerValue := range listPolicyTemplatesOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "ListPolicyTemplates") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if listPolicyTemplatesOptions.AcceptLanguage != nil { + builder.AddHeader("Accept-Language", fmt.Sprint(*listPolicyTemplatesOptions.AcceptLanguage)) + } + + builder.AddQuery("account_id", fmt.Sprint(*listPolicyTemplatesOptions.AccountID)) + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyTemplateCollection) + if err != nil { + return + } + response.Result = result + } + + return +} + +// CreatePolicyTemplate : Create a policy template +// Creates a policy template. +func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyTemplate(createPolicyTemplateOptions *CreatePolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + return iamPolicyManagement.CreatePolicyTemplateWithContext(context.Background(), createPolicyTemplateOptions) +} + +// CreatePolicyTemplateWithContext is an alternate form of the CreatePolicyTemplate method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyTemplateWithContext(ctx context.Context, createPolicyTemplateOptions *CreatePolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createPolicyTemplateOptions, "createPolicyTemplateOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(createPolicyTemplateOptions, "createPolicyTemplateOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates`, nil) + if err != nil { + return + } + + for headerName, headerValue := range createPolicyTemplateOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "CreatePolicyTemplate") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if createPolicyTemplateOptions.AcceptLanguage != nil { + builder.AddHeader("Accept-Language", fmt.Sprint(*createPolicyTemplateOptions.AcceptLanguage)) + } + + body := make(map[string]interface{}) + if createPolicyTemplateOptions.Name != nil { + body["name"] = createPolicyTemplateOptions.Name + } + if createPolicyTemplateOptions.AccountID != nil { + body["account_id"] = createPolicyTemplateOptions.AccountID + } + if createPolicyTemplateOptions.Policy != nil { + body["policy"] = createPolicyTemplateOptions.Policy + } + if createPolicyTemplateOptions.Description != nil { + body["description"] = createPolicyTemplateOptions.Description + } + if createPolicyTemplateOptions.Committed != nil { + body["committed"] = createPolicyTemplateOptions.Committed + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyTemplate) + if err != nil { + return + } + response.Result = result + } + + return +} + +// GetPolicyTemplate : Retrieve latest policy template version by template ID +// Retrieve the latest version of a policy template by providing a policy template ID. +func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyTemplate(getPolicyTemplateOptions *GetPolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + return iamPolicyManagement.GetPolicyTemplateWithContext(context.Background(), getPolicyTemplateOptions) +} + +// GetPolicyTemplateWithContext is an alternate form of the GetPolicyTemplate method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyTemplateWithContext(ctx context.Context, getPolicyTemplateOptions *GetPolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getPolicyTemplateOptions, "getPolicyTemplateOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getPolicyTemplateOptions, "getPolicyTemplateOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_template_id": *getPolicyTemplateOptions.PolicyTemplateID, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates/{policy_template_id}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range getPolicyTemplateOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "GetPolicyTemplate") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyTemplate) + if err != nil { + return + } + response.Result = result + } + + return +} + +// DeletePolicyTemplate : Delete a policy template by ID +// Delete a policy template by providing a policy template ID. This deletes all versions of this template. A policy +// template cannot be deleted if the template version is assigned to an account. +func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyTemplate(deletePolicyTemplateOptions *DeletePolicyTemplateOptions) (response *core.DetailedResponse, err error) { + return iamPolicyManagement.DeletePolicyTemplateWithContext(context.Background(), deletePolicyTemplateOptions) +} + +// DeletePolicyTemplateWithContext is an alternate form of the DeletePolicyTemplate method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyTemplateWithContext(ctx context.Context, deletePolicyTemplateOptions *DeletePolicyTemplateOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deletePolicyTemplateOptions, "deletePolicyTemplateOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(deletePolicyTemplateOptions, "deletePolicyTemplateOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_template_id": *deletePolicyTemplateOptions.PolicyTemplateID, + } + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates/{policy_template_id}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range deletePolicyTemplateOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "DeletePolicyTemplate") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + request, err := builder.Build() + if err != nil { + return + } + + response, err = iamPolicyManagement.Service.Request(request, nil) + + return +} + +// CreatePolicyTemplateVersion : Create a new policy template version +// Creates a new policy template version Details TBD. +func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyTemplateVersion(createPolicyTemplateVersionOptions *CreatePolicyTemplateVersionOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + return iamPolicyManagement.CreatePolicyTemplateVersionWithContext(context.Background(), createPolicyTemplateVersionOptions) +} + +// CreatePolicyTemplateVersionWithContext is an alternate form of the CreatePolicyTemplateVersion method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyTemplateVersionWithContext(ctx context.Context, createPolicyTemplateVersionOptions *CreatePolicyTemplateVersionOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createPolicyTemplateVersionOptions, "createPolicyTemplateVersionOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(createPolicyTemplateVersionOptions, "createPolicyTemplateVersionOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_template_id": *createPolicyTemplateVersionOptions.PolicyTemplateID, + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates/{policy_template_id}/versions`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range createPolicyTemplateVersionOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "CreatePolicyTemplateVersion") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if createPolicyTemplateVersionOptions.Policy != nil { + body["policy"] = createPolicyTemplateVersionOptions.Policy + } + if createPolicyTemplateVersionOptions.Description != nil { + body["description"] = createPolicyTemplateVersionOptions.Description + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyTemplate) + if err != nil { + return + } + response.Result = result + } + + return +} + +// ListPolicyTemplateVersions : Retrieve policy template versions +// Retrieve the versions of a policy template by providing a policy template ID. +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyTemplateVersions(listPolicyTemplateVersionsOptions *ListPolicyTemplateVersionsOptions) (result *PolicyTemplateVersionsCollection, response *core.DetailedResponse, err error) { + return iamPolicyManagement.ListPolicyTemplateVersionsWithContext(context.Background(), listPolicyTemplateVersionsOptions) +} + +// ListPolicyTemplateVersionsWithContext is an alternate form of the ListPolicyTemplateVersions method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyTemplateVersionsWithContext(ctx context.Context, listPolicyTemplateVersionsOptions *ListPolicyTemplateVersionsOptions) (result *PolicyTemplateVersionsCollection, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listPolicyTemplateVersionsOptions, "listPolicyTemplateVersionsOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(listPolicyTemplateVersionsOptions, "listPolicyTemplateVersionsOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_template_id": *listPolicyTemplateVersionsOptions.PolicyTemplateID, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates/{policy_template_id}/versions`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range listPolicyTemplateVersionsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "ListPolicyTemplateVersions") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyTemplateVersionsCollection) + if err != nil { + return + } + response.Result = result + } + + return +} + +// ReplacePolicyTemplate : Update a policy template version +// Update a policy template version Details TBD. +func (iamPolicyManagement *IamPolicyManagementV1) ReplacePolicyTemplate(replacePolicyTemplateOptions *ReplacePolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + return iamPolicyManagement.ReplacePolicyTemplateWithContext(context.Background(), replacePolicyTemplateOptions) +} + +// ReplacePolicyTemplateWithContext is an alternate form of the ReplacePolicyTemplate method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) ReplacePolicyTemplateWithContext(ctx context.Context, replacePolicyTemplateOptions *ReplacePolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(replacePolicyTemplateOptions, "replacePolicyTemplateOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(replacePolicyTemplateOptions, "replacePolicyTemplateOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_template_id": *replacePolicyTemplateOptions.PolicyTemplateID, + "version": *replacePolicyTemplateOptions.Version, + } + + builder := core.NewRequestBuilder(core.PUT) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates/{policy_template_id}/versions/{version}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range replacePolicyTemplateOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "ReplacePolicyTemplate") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if replacePolicyTemplateOptions.IfMatch != nil { + builder.AddHeader("If-Match", fmt.Sprint(*replacePolicyTemplateOptions.IfMatch)) + } + + body := make(map[string]interface{}) + if replacePolicyTemplateOptions.Policy != nil { + body["policy"] = replacePolicyTemplateOptions.Policy + } + if replacePolicyTemplateOptions.Description != nil { + body["description"] = replacePolicyTemplateOptions.Description + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyTemplate) + if err != nil { + return + } + response.Result = result + } + + return +} + +// DeletePolicyTemplateVersion : Delete a policy template version by ID and version +// Delete a policy template by providing a policy template ID and version. You can't delete a policy template if the +// template version is assigned to an account. +func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions *DeletePolicyTemplateVersionOptions) (response *core.DetailedResponse, err error) { + return iamPolicyManagement.DeletePolicyTemplateVersionWithContext(context.Background(), deletePolicyTemplateVersionOptions) +} + +// DeletePolicyTemplateVersionWithContext is an alternate form of the DeletePolicyTemplateVersion method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyTemplateVersionWithContext(ctx context.Context, deletePolicyTemplateVersionOptions *DeletePolicyTemplateVersionOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deletePolicyTemplateVersionOptions, "deletePolicyTemplateVersionOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(deletePolicyTemplateVersionOptions, "deletePolicyTemplateVersionOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_template_id": *deletePolicyTemplateVersionOptions.PolicyTemplateID, + "version": *deletePolicyTemplateVersionOptions.Version, + } + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates/{policy_template_id}/versions/{version}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range deletePolicyTemplateVersionOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "DeletePolicyTemplateVersion") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + request, err := builder.Build() + if err != nil { + return + } + + response, err = iamPolicyManagement.Service.Request(request, nil) + + return +} + +// GetPolicyTemplateVersion : Retrieve a policy template version by ID +// Retrieve a policy template by providing a policy template ID and version. +func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyTemplateVersion(getPolicyTemplateVersionOptions *GetPolicyTemplateVersionOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + return iamPolicyManagement.GetPolicyTemplateVersionWithContext(context.Background(), getPolicyTemplateVersionOptions) +} + +// GetPolicyTemplateVersionWithContext is an alternate form of the GetPolicyTemplateVersion method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyTemplateVersionWithContext(ctx context.Context, getPolicyTemplateVersionOptions *GetPolicyTemplateVersionOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getPolicyTemplateVersionOptions, "getPolicyTemplateVersionOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getPolicyTemplateVersionOptions, "getPolicyTemplateVersionOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_template_id": *getPolicyTemplateVersionOptions.PolicyTemplateID, + "version": *getPolicyTemplateVersionOptions.Version, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates/{policy_template_id}/versions/{version}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range getPolicyTemplateVersionOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "GetPolicyTemplateVersion") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyTemplate) + if err != nil { + return + } + response.Result = result + } + + return +} + +// CommitPolicyTemplate : Commit a policy template version +// Commit a policy template version Details TBD. +func (iamPolicyManagement *IamPolicyManagementV1) CommitPolicyTemplate(commitPolicyTemplateOptions *CommitPolicyTemplateOptions) (response *core.DetailedResponse, err error) { + return iamPolicyManagement.CommitPolicyTemplateWithContext(context.Background(), commitPolicyTemplateOptions) +} + +// CommitPolicyTemplateWithContext is an alternate form of the CommitPolicyTemplate method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) CommitPolicyTemplateWithContext(ctx context.Context, commitPolicyTemplateOptions *CommitPolicyTemplateOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(commitPolicyTemplateOptions, "commitPolicyTemplateOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(commitPolicyTemplateOptions, "commitPolicyTemplateOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_template_id": *commitPolicyTemplateOptions.PolicyTemplateID, + "version": *commitPolicyTemplateOptions.Version, + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_templates/{policy_template_id}/versions/{version}/commit`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range commitPolicyTemplateOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "CommitPolicyTemplate") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + if commitPolicyTemplateOptions.IfMatch != nil { + builder.AddHeader("If-Match", fmt.Sprint(*commitPolicyTemplateOptions.IfMatch)) + } + + request, err := builder.Build() + if err != nil { + return + } + + response, err = iamPolicyManagement.Service.Request(request, nil) + + return +} + +// ListPolicyAssignments : Get policies template assignments by attributes +// Get policy template assignments by attributes. The following attributes are supported: account_id, template_id, +// template_version, sort account_id is a required query parameter. Only policy template assignments that have the +// specified attributes and that the caller has read access to are returned. If the caller does not have read access to +// any policy template assignments an empty array is returned. +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyAssignments(listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions) (result *PolcyTemplateAssignmentCollection, response *core.DetailedResponse, err error) { + return iamPolicyManagement.ListPolicyAssignmentsWithContext(context.Background(), listPolicyAssignmentsOptions) +} + +// ListPolicyAssignmentsWithContext is an alternate form of the ListPolicyAssignments method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyAssignmentsWithContext(ctx context.Context, listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions) (result *PolcyTemplateAssignmentCollection, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listPolicyAssignmentsOptions, "listPolicyAssignmentsOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(listPolicyAssignmentsOptions, "listPolicyAssignmentsOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_assignments`, nil) + if err != nil { + return + } + + for headerName, headerValue := range listPolicyAssignmentsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "ListPolicyAssignments") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if listPolicyAssignmentsOptions.AcceptLanguage != nil { + builder.AddHeader("Accept-Language", fmt.Sprint(*listPolicyAssignmentsOptions.AcceptLanguage)) + } + + builder.AddQuery("account_id", fmt.Sprint(*listPolicyAssignmentsOptions.AccountID)) + if listPolicyAssignmentsOptions.TemplateID != nil { + builder.AddQuery("template_id", fmt.Sprint(*listPolicyAssignmentsOptions.TemplateID)) + } + if listPolicyAssignmentsOptions.TemplateVersion != nil { + builder.AddQuery("template_version", fmt.Sprint(*listPolicyAssignmentsOptions.TemplateVersion)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolcyTemplateAssignmentCollection) + if err != nil { + return + } + response.Result = result + } + + return +} + +// GetPolicyAssignment : Retrieve a policy assignment by ID +// Retrieve a policy template assignment by providing a policy assignment ID. +func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyAssignment(getPolicyAssignmentOptions *GetPolicyAssignmentOptions) (result *PolicyAssignmentRecord, response *core.DetailedResponse, err error) { + return iamPolicyManagement.GetPolicyAssignmentWithContext(context.Background(), getPolicyAssignmentOptions) +} + +// GetPolicyAssignmentWithContext is an alternate form of the GetPolicyAssignment method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyAssignmentWithContext(ctx context.Context, getPolicyAssignmentOptions *GetPolicyAssignmentOptions) (result *PolicyAssignmentRecord, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getPolicyAssignmentOptions, "getPolicyAssignmentOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getPolicyAssignmentOptions, "getPolicyAssignmentOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "assignment_id": *getPolicyAssignmentOptions.AssignmentID, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policy_assignments/{assignment_id}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range getPolicyAssignmentOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "GetPolicyAssignment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyAssignmentRecord) + if err != nil { + return + } + response.Result = result + } + + return +} + +// AssignmentResourceCreated : On success, includes the policy assigned. +type AssignmentResourceCreated struct { + // policy id. + ID *string `json:"id,omitempty"` +} + +// UnmarshalAssignmentResourceCreated unmarshals an instance of AssignmentResourceCreated from the specified map of raw messages. +func UnmarshalAssignmentResourceCreated(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AssignmentResourceCreated) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CommitPolicyTemplateOptions : The CommitPolicyTemplate options. +type CommitPolicyTemplateOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` + + // The policy template version. + Version *string `json:"version" validate:"required,ne="` + + // The revision number for updating a policy template version and must match the ETag value of the existing policy + // template version. The Etag can be retrieved using the GET + // /v1/policy_templates/{policy_template_id}/versions/{version} API and looking at the ETag response header. + IfMatch *string `json:"If-Match" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCommitPolicyTemplateOptions : Instantiate CommitPolicyTemplateOptions +func (*IamPolicyManagementV1) NewCommitPolicyTemplateOptions(policyTemplateID string, version string, ifMatch string) *CommitPolicyTemplateOptions { + return &CommitPolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + Version: core.StringPtr(version), + IfMatch: core.StringPtr(ifMatch), + } +} + +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *CommitPolicyTemplateOptions) SetPolicyTemplateID(policyTemplateID string) *CommitPolicyTemplateOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options +} + +// SetVersion : Allow user to set Version +func (_options *CommitPolicyTemplateOptions) SetVersion(version string) *CommitPolicyTemplateOptions { + _options.Version = core.StringPtr(version) + return _options +} + +// SetIfMatch : Allow user to set IfMatch +func (_options *CommitPolicyTemplateOptions) SetIfMatch(ifMatch string) *CommitPolicyTemplateOptions { + _options.IfMatch = core.StringPtr(ifMatch) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CommitPolicyTemplateOptions) SetHeaders(param map[string]string) *CommitPolicyTemplateOptions { + options.Headers = param + return options +} + // Control : Specifies the type of access granted by the policy. type Control struct { // Permission granted by the policy. @@ -1622,44 +2446,177 @@ func (*IamPolicyManagementV1) NewCreatePolicyOptions(typeVar string, subjects [] } } -// SetType : Allow user to set Type -func (_options *CreatePolicyOptions) SetType(typeVar string) *CreatePolicyOptions { - _options.Type = core.StringPtr(typeVar) +// SetType : Allow user to set Type +func (_options *CreatePolicyOptions) SetType(typeVar string) *CreatePolicyOptions { + _options.Type = core.StringPtr(typeVar) + return _options +} + +// SetSubjects : Allow user to set Subjects +func (_options *CreatePolicyOptions) SetSubjects(subjects []PolicySubject) *CreatePolicyOptions { + _options.Subjects = subjects + return _options +} + +// SetRoles : Allow user to set Roles +func (_options *CreatePolicyOptions) SetRoles(roles []PolicyRole) *CreatePolicyOptions { + _options.Roles = roles + return _options +} + +// SetResources : Allow user to set Resources +func (_options *CreatePolicyOptions) SetResources(resources []PolicyResource) *CreatePolicyOptions { + _options.Resources = resources + return _options +} + +// SetDescription : Allow user to set Description +func (_options *CreatePolicyOptions) SetDescription(description string) *CreatePolicyOptions { + _options.Description = core.StringPtr(description) + return _options +} + +// SetAcceptLanguage : Allow user to set AcceptLanguage +func (_options *CreatePolicyOptions) SetAcceptLanguage(acceptLanguage string) *CreatePolicyOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreatePolicyOptions) SetHeaders(param map[string]string) *CreatePolicyOptions { + options.Headers = param + return options +} + +// CreatePolicyTemplateOptions : The CreatePolicyTemplate options. +type CreatePolicyTemplateOptions struct { + // name of template. + Name *string `json:"name" validate:"required"` + + // account id where this template will be created. + AccountID *string `json:"account_id" validate:"required"` + + // The core set of properties associated with the template's policy objet. + Policy *TemplatePolicy `json:"policy" validate:"required"` + + // description of template purpose. + Description *string `json:"description,omitempty"` + + // committed status for the template. + Committed *bool `json:"committed,omitempty"` + + // Language code for translations + // * `default` - English + // * `de` - German (Standard) + // * `en` - English + // * `es` - Spanish (Spain) + // * `fr` - French (Standard) + // * `it` - Italian (Standard) + // * `ja` - Japanese + // * `ko` - Korean + // * `pt-br` - Portuguese (Brazil) + // * `zh-cn` - Chinese (Simplified, PRC) + // * `zh-tw` - (Chinese, Taiwan). + AcceptLanguage *string `json:"Accept-Language,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCreatePolicyTemplateOptions : Instantiate CreatePolicyTemplateOptions +func (*IamPolicyManagementV1) NewCreatePolicyTemplateOptions(name string, accountID string, policy *TemplatePolicy) *CreatePolicyTemplateOptions { + return &CreatePolicyTemplateOptions{ + Name: core.StringPtr(name), + AccountID: core.StringPtr(accountID), + Policy: policy, + } +} + +// SetName : Allow user to set Name +func (_options *CreatePolicyTemplateOptions) SetName(name string) *CreatePolicyTemplateOptions { + _options.Name = core.StringPtr(name) return _options } -// SetSubjects : Allow user to set Subjects -func (_options *CreatePolicyOptions) SetSubjects(subjects []PolicySubject) *CreatePolicyOptions { - _options.Subjects = subjects +// SetAccountID : Allow user to set AccountID +func (_options *CreatePolicyTemplateOptions) SetAccountID(accountID string) *CreatePolicyTemplateOptions { + _options.AccountID = core.StringPtr(accountID) return _options } -// SetRoles : Allow user to set Roles -func (_options *CreatePolicyOptions) SetRoles(roles []PolicyRole) *CreatePolicyOptions { - _options.Roles = roles +// SetPolicy : Allow user to set Policy +func (_options *CreatePolicyTemplateOptions) SetPolicy(policy *TemplatePolicy) *CreatePolicyTemplateOptions { + _options.Policy = policy return _options } -// SetResources : Allow user to set Resources -func (_options *CreatePolicyOptions) SetResources(resources []PolicyResource) *CreatePolicyOptions { - _options.Resources = resources +// SetDescription : Allow user to set Description +func (_options *CreatePolicyTemplateOptions) SetDescription(description string) *CreatePolicyTemplateOptions { + _options.Description = core.StringPtr(description) return _options } -// SetDescription : Allow user to set Description -func (_options *CreatePolicyOptions) SetDescription(description string) *CreatePolicyOptions { - _options.Description = core.StringPtr(description) +// SetCommitted : Allow user to set Committed +func (_options *CreatePolicyTemplateOptions) SetCommitted(committed bool) *CreatePolicyTemplateOptions { + _options.Committed = core.BoolPtr(committed) return _options } // SetAcceptLanguage : Allow user to set AcceptLanguage -func (_options *CreatePolicyOptions) SetAcceptLanguage(acceptLanguage string) *CreatePolicyOptions { +func (_options *CreatePolicyTemplateOptions) SetAcceptLanguage(acceptLanguage string) *CreatePolicyTemplateOptions { _options.AcceptLanguage = core.StringPtr(acceptLanguage) return _options } // SetHeaders : Allow user to set Headers -func (options *CreatePolicyOptions) SetHeaders(param map[string]string) *CreatePolicyOptions { +func (options *CreatePolicyTemplateOptions) SetHeaders(param map[string]string) *CreatePolicyTemplateOptions { + options.Headers = param + return options +} + +// CreatePolicyTemplateVersionOptions : The CreatePolicyTemplateVersion options. +type CreatePolicyTemplateVersionOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` + + // The core set of properties associated with the template's policy objet. + Policy *TemplatePolicy `json:"policy" validate:"required"` + + // description of template purpose. + Description *string `json:"description,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCreatePolicyTemplateVersionOptions : Instantiate CreatePolicyTemplateVersionOptions +func (*IamPolicyManagementV1) NewCreatePolicyTemplateVersionOptions(policyTemplateID string, policy *TemplatePolicy) *CreatePolicyTemplateVersionOptions { + return &CreatePolicyTemplateVersionOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + Policy: policy, + } +} + +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *CreatePolicyTemplateVersionOptions) SetPolicyTemplateID(policyTemplateID string) *CreatePolicyTemplateVersionOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options +} + +// SetPolicy : Allow user to set Policy +func (_options *CreatePolicyTemplateVersionOptions) SetPolicy(policy *TemplatePolicy) *CreatePolicyTemplateVersionOptions { + _options.Policy = policy + return _options +} + +// SetDescription : Allow user to set Description +func (_options *CreatePolicyTemplateVersionOptions) SetDescription(description string) *CreatePolicyTemplateVersionOptions { + _options.Description = core.StringPtr(description) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreatePolicyTemplateVersionOptions) SetHeaders(param map[string]string) *CreatePolicyTemplateVersionOptions { options.Headers = param return options } @@ -1901,6 +2858,72 @@ func (options *DeletePolicyOptions) SetHeaders(param map[string]string) *DeleteP return options } +// DeletePolicyTemplateOptions : The DeletePolicyTemplate options. +type DeletePolicyTemplateOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeletePolicyTemplateOptions : Instantiate DeletePolicyTemplateOptions +func (*IamPolicyManagementV1) NewDeletePolicyTemplateOptions(policyTemplateID string) *DeletePolicyTemplateOptions { + return &DeletePolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + } +} + +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *DeletePolicyTemplateOptions) SetPolicyTemplateID(policyTemplateID string) *DeletePolicyTemplateOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeletePolicyTemplateOptions) SetHeaders(param map[string]string) *DeletePolicyTemplateOptions { + options.Headers = param + return options +} + +// DeletePolicyTemplateVersionOptions : The DeletePolicyTemplateVersion options. +type DeletePolicyTemplateVersionOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` + + // The policy template version. + Version *string `json:"version" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeletePolicyTemplateVersionOptions : Instantiate DeletePolicyTemplateVersionOptions +func (*IamPolicyManagementV1) NewDeletePolicyTemplateVersionOptions(policyTemplateID string, version string) *DeletePolicyTemplateVersionOptions { + return &DeletePolicyTemplateVersionOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + Version: core.StringPtr(version), + } +} + +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *DeletePolicyTemplateVersionOptions) SetPolicyTemplateID(policyTemplateID string) *DeletePolicyTemplateVersionOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options +} + +// SetVersion : Allow user to set Version +func (_options *DeletePolicyTemplateVersionOptions) SetVersion(version string) *DeletePolicyTemplateVersionOptions { + _options.Version = core.StringPtr(version) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeletePolicyTemplateVersionOptions) SetHeaders(param map[string]string) *DeletePolicyTemplateVersionOptions { + options.Headers = param + return options +} + // DeleteRoleOptions : The DeleteRole options. type DeleteRoleOptions struct { // The role ID. @@ -1997,6 +3020,34 @@ func UnmarshalEnrichedRoles(m map[string]json.RawMessage, result interface{}) (e return } +// GetPolicyAssignmentOptions : The GetPolicyAssignment options. +type GetPolicyAssignmentOptions struct { + // The policy template assignment ID. + AssignmentID *string `json:"assignment_id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetPolicyAssignmentOptions : Instantiate GetPolicyAssignmentOptions +func (*IamPolicyManagementV1) NewGetPolicyAssignmentOptions(assignmentID string) *GetPolicyAssignmentOptions { + return &GetPolicyAssignmentOptions{ + AssignmentID: core.StringPtr(assignmentID), + } +} + +// SetAssignmentID : Allow user to set AssignmentID +func (_options *GetPolicyAssignmentOptions) SetAssignmentID(assignmentID string) *GetPolicyAssignmentOptions { + _options.AssignmentID = core.StringPtr(assignmentID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetPolicyAssignmentOptions) SetHeaders(param map[string]string) *GetPolicyAssignmentOptions { + options.Headers = param + return options +} + // GetPolicyOptions : The GetPolicy options. type GetPolicyOptions struct { // The policy ID. @@ -2025,6 +3076,72 @@ func (options *GetPolicyOptions) SetHeaders(param map[string]string) *GetPolicyO return options } +// GetPolicyTemplateOptions : The GetPolicyTemplate options. +type GetPolicyTemplateOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetPolicyTemplateOptions : Instantiate GetPolicyTemplateOptions +func (*IamPolicyManagementV1) NewGetPolicyTemplateOptions(policyTemplateID string) *GetPolicyTemplateOptions { + return &GetPolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + } +} + +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *GetPolicyTemplateOptions) SetPolicyTemplateID(policyTemplateID string) *GetPolicyTemplateOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetPolicyTemplateOptions) SetHeaders(param map[string]string) *GetPolicyTemplateOptions { + options.Headers = param + return options +} + +// GetPolicyTemplateVersionOptions : The GetPolicyTemplateVersion options. +type GetPolicyTemplateVersionOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` + + // The policy template version. + Version *string `json:"version" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetPolicyTemplateVersionOptions : Instantiate GetPolicyTemplateVersionOptions +func (*IamPolicyManagementV1) NewGetPolicyTemplateVersionOptions(policyTemplateID string, version string) *GetPolicyTemplateVersionOptions { + return &GetPolicyTemplateVersionOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + Version: core.StringPtr(version), + } +} + +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *GetPolicyTemplateVersionOptions) SetPolicyTemplateID(policyTemplateID string) *GetPolicyTemplateVersionOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options +} + +// SetVersion : Allow user to set Version +func (_options *GetPolicyTemplateVersionOptions) SetVersion(version string) *GetPolicyTemplateVersionOptions { + _options.Version = core.StringPtr(version) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetPolicyTemplateVersionOptions) SetHeaders(param map[string]string) *GetPolicyTemplateVersionOptions { + options.Headers = param + return options +} + // GetRoleOptions : The GetRole options. type GetRoleOptions struct { // The role ID. @@ -2232,100 +3349,242 @@ const ( ListPoliciesOptionsSortTypeConst = "type" ) -// Constants associated with the ListPoliciesOptions.Format property. -// Include additional data per policy returned -// * `include_last_permit` - returns details of when the policy last granted a permit decision and the number of times -// it has done so -// * `display` - returns the list of all actions included in each of the policy roles. -const ( - ListPoliciesOptionsFormatDisplayConst = "display" - ListPoliciesOptionsFormatIncludeLastPermitConst = "include_last_permit" -) +// Constants associated with the ListPoliciesOptions.Format property. +// Include additional data per policy returned +// * `include_last_permit` - returns details of when the policy last granted a permit decision and the number of times +// it has done so +// * `display` - returns the list of all actions included in each of the policy roles. +const ( + ListPoliciesOptionsFormatDisplayConst = "display" + ListPoliciesOptionsFormatIncludeLastPermitConst = "include_last_permit" +) + +// Constants associated with the ListPoliciesOptions.State property. +// The state of the policy. +// * `active` - returns active policies +// * `deleted` - returns non-active policies. +const ( + ListPoliciesOptionsStateActiveConst = "active" + ListPoliciesOptionsStateDeletedConst = "deleted" +) + +// NewListPoliciesOptions : Instantiate ListPoliciesOptions +func (*IamPolicyManagementV1) NewListPoliciesOptions(accountID string) *ListPoliciesOptions { + return &ListPoliciesOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *ListPoliciesOptions) SetAccountID(accountID string) *ListPoliciesOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetAcceptLanguage : Allow user to set AcceptLanguage +func (_options *ListPoliciesOptions) SetAcceptLanguage(acceptLanguage string) *ListPoliciesOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) + return _options +} + +// SetIamID : Allow user to set IamID +func (_options *ListPoliciesOptions) SetIamID(iamID string) *ListPoliciesOptions { + _options.IamID = core.StringPtr(iamID) + return _options +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *ListPoliciesOptions) SetAccessGroupID(accessGroupID string) *ListPoliciesOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetType : Allow user to set Type +func (_options *ListPoliciesOptions) SetType(typeVar string) *ListPoliciesOptions { + _options.Type = core.StringPtr(typeVar) + return _options +} + +// SetServiceType : Allow user to set ServiceType +func (_options *ListPoliciesOptions) SetServiceType(serviceType string) *ListPoliciesOptions { + _options.ServiceType = core.StringPtr(serviceType) + return _options +} + +// SetTagName : Allow user to set TagName +func (_options *ListPoliciesOptions) SetTagName(tagName string) *ListPoliciesOptions { + _options.TagName = core.StringPtr(tagName) + return _options +} + +// SetTagValue : Allow user to set TagValue +func (_options *ListPoliciesOptions) SetTagValue(tagValue string) *ListPoliciesOptions { + _options.TagValue = core.StringPtr(tagValue) + return _options +} + +// SetSort : Allow user to set Sort +func (_options *ListPoliciesOptions) SetSort(sort string) *ListPoliciesOptions { + _options.Sort = core.StringPtr(sort) + return _options +} + +// SetFormat : Allow user to set Format +func (_options *ListPoliciesOptions) SetFormat(format string) *ListPoliciesOptions { + _options.Format = core.StringPtr(format) + return _options +} + +// SetState : Allow user to set State +func (_options *ListPoliciesOptions) SetState(state string) *ListPoliciesOptions { + _options.State = core.StringPtr(state) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListPoliciesOptions) SetHeaders(param map[string]string) *ListPoliciesOptions { + options.Headers = param + return options +} + +// ListPolicyAssignmentsOptions : The ListPolicyAssignments options. +type ListPolicyAssignmentsOptions struct { + // The account GUID in which the policies belong to. + AccountID *string `json:"account_id" validate:"required"` + + // Language code for translations + // * `default` - English + // * `de` - German (Standard) + // * `en` - English + // * `es` - Spanish (Spain) + // * `fr` - French (Standard) + // * `it` - Italian (Standard) + // * `ja` - Japanese + // * `ko` - Korean + // * `pt-br` - Portuguese (Brazil) + // * `zh-cn` - Chinese (Simplified, PRC) + // * `zh-tw` - (Chinese, Taiwan). + AcceptLanguage *string `json:"Accept-Language,omitempty"` + + // Optional template id. + TemplateID *string `json:"template_id,omitempty"` + + // Optional policy template version. + TemplateVersion *string `json:"template_version,omitempty"` -// Constants associated with the ListPoliciesOptions.State property. -// The state of the policy. -// * `active` - returns active policies -// * `deleted` - returns non-active policies. -const ( - ListPoliciesOptionsStateActiveConst = "active" - ListPoliciesOptionsStateDeletedConst = "deleted" -) + // Allows users to set headers on API requests + Headers map[string]string +} -// NewListPoliciesOptions : Instantiate ListPoliciesOptions -func (*IamPolicyManagementV1) NewListPoliciesOptions(accountID string) *ListPoliciesOptions { - return &ListPoliciesOptions{ +// NewListPolicyAssignmentsOptions : Instantiate ListPolicyAssignmentsOptions +func (*IamPolicyManagementV1) NewListPolicyAssignmentsOptions(accountID string) *ListPolicyAssignmentsOptions { + return &ListPolicyAssignmentsOptions{ AccountID: core.StringPtr(accountID), } } // SetAccountID : Allow user to set AccountID -func (_options *ListPoliciesOptions) SetAccountID(accountID string) *ListPoliciesOptions { +func (_options *ListPolicyAssignmentsOptions) SetAccountID(accountID string) *ListPolicyAssignmentsOptions { _options.AccountID = core.StringPtr(accountID) return _options } // SetAcceptLanguage : Allow user to set AcceptLanguage -func (_options *ListPoliciesOptions) SetAcceptLanguage(acceptLanguage string) *ListPoliciesOptions { +func (_options *ListPolicyAssignmentsOptions) SetAcceptLanguage(acceptLanguage string) *ListPolicyAssignmentsOptions { _options.AcceptLanguage = core.StringPtr(acceptLanguage) return _options } -// SetIamID : Allow user to set IamID -func (_options *ListPoliciesOptions) SetIamID(iamID string) *ListPoliciesOptions { - _options.IamID = core.StringPtr(iamID) +// SetTemplateID : Allow user to set TemplateID +func (_options *ListPolicyAssignmentsOptions) SetTemplateID(templateID string) *ListPolicyAssignmentsOptions { + _options.TemplateID = core.StringPtr(templateID) return _options } -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *ListPoliciesOptions) SetAccessGroupID(accessGroupID string) *ListPoliciesOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) +// SetTemplateVersion : Allow user to set TemplateVersion +func (_options *ListPolicyAssignmentsOptions) SetTemplateVersion(templateVersion string) *ListPolicyAssignmentsOptions { + _options.TemplateVersion = core.StringPtr(templateVersion) return _options } -// SetType : Allow user to set Type -func (_options *ListPoliciesOptions) SetType(typeVar string) *ListPoliciesOptions { - _options.Type = core.StringPtr(typeVar) - return _options +// SetHeaders : Allow user to set Headers +func (options *ListPolicyAssignmentsOptions) SetHeaders(param map[string]string) *ListPolicyAssignmentsOptions { + options.Headers = param + return options } -// SetServiceType : Allow user to set ServiceType -func (_options *ListPoliciesOptions) SetServiceType(serviceType string) *ListPoliciesOptions { - _options.ServiceType = core.StringPtr(serviceType) - return _options +// ListPolicyTemplateVersionsOptions : The ListPolicyTemplateVersions options. +type ListPolicyTemplateVersionsOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string } -// SetTagName : Allow user to set TagName -func (_options *ListPoliciesOptions) SetTagName(tagName string) *ListPoliciesOptions { - _options.TagName = core.StringPtr(tagName) - return _options +// NewListPolicyTemplateVersionsOptions : Instantiate ListPolicyTemplateVersionsOptions +func (*IamPolicyManagementV1) NewListPolicyTemplateVersionsOptions(policyTemplateID string) *ListPolicyTemplateVersionsOptions { + return &ListPolicyTemplateVersionsOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + } } -// SetTagValue : Allow user to set TagValue -func (_options *ListPoliciesOptions) SetTagValue(tagValue string) *ListPoliciesOptions { - _options.TagValue = core.StringPtr(tagValue) +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *ListPolicyTemplateVersionsOptions) SetPolicyTemplateID(policyTemplateID string) *ListPolicyTemplateVersionsOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) return _options } -// SetSort : Allow user to set Sort -func (_options *ListPoliciesOptions) SetSort(sort string) *ListPoliciesOptions { - _options.Sort = core.StringPtr(sort) - return _options +// SetHeaders : Allow user to set Headers +func (options *ListPolicyTemplateVersionsOptions) SetHeaders(param map[string]string) *ListPolicyTemplateVersionsOptions { + options.Headers = param + return options } -// SetFormat : Allow user to set Format -func (_options *ListPoliciesOptions) SetFormat(format string) *ListPoliciesOptions { - _options.Format = core.StringPtr(format) +// ListPolicyTemplatesOptions : The ListPolicyTemplates options. +type ListPolicyTemplatesOptions struct { + // The account GUID that the policy templates belong to. + AccountID *string `json:"account_id" validate:"required"` + + // Language code for translations + // * `default` - English + // * `de` - German (Standard) + // * `en` - English + // * `es` - Spanish (Spain) + // * `fr` - French (Standard) + // * `it` - Italian (Standard) + // * `ja` - Japanese + // * `ko` - Korean + // * `pt-br` - Portuguese (Brazil) + // * `zh-cn` - Chinese (Simplified, PRC) + // * `zh-tw` - (Chinese, Taiwan). + AcceptLanguage *string `json:"Accept-Language,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListPolicyTemplatesOptions : Instantiate ListPolicyTemplatesOptions +func (*IamPolicyManagementV1) NewListPolicyTemplatesOptions(accountID string) *ListPolicyTemplatesOptions { + return &ListPolicyTemplatesOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *ListPolicyTemplatesOptions) SetAccountID(accountID string) *ListPolicyTemplatesOptions { + _options.AccountID = core.StringPtr(accountID) return _options } -// SetState : Allow user to set State -func (_options *ListPoliciesOptions) SetState(state string) *ListPoliciesOptions { - _options.State = core.StringPtr(state) +// SetAcceptLanguage : Allow user to set AcceptLanguage +func (_options *ListPolicyTemplatesOptions) SetAcceptLanguage(acceptLanguage string) *ListPolicyTemplatesOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) return _options } // SetHeaders : Allow user to set Headers -func (options *ListPoliciesOptions) SetHeaders(param map[string]string) *ListPoliciesOptions { +func (options *ListPolicyTemplatesOptions) SetHeaders(param map[string]string) *ListPolicyTemplatesOptions { options.Headers = param return options } @@ -2594,6 +3853,187 @@ func (options *ListV2PoliciesOptions) SetHeaders(param map[string]string) *ListV return options } +// PolcyTemplateAssignmentCollection : A collection of policies assignments. +type PolcyTemplateAssignmentCollection struct { + // List of policy assignments. + Assignments []PolicyAssignmentRecord `json:"assignments,omitempty"` +} + +// UnmarshalPolcyTemplateAssignmentCollection unmarshals an instance of PolcyTemplateAssignmentCollection from the specified map of raw messages. +func UnmarshalPolcyTemplateAssignmentCollection(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolcyTemplateAssignmentCollection) + err = core.UnmarshalModel(m, "assignments", &obj.Assignments, UnmarshalPolicyAssignmentRecord) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyAssignmentRecord : The set of properties associated with the policy template assignment. +type PolicyAssignmentRecord struct { + // policy template id. + TemplateID *string `json:"template_id" validate:"required"` + + // policy template version. + TemplateVersion *string `json:"template_version" validate:"required"` + + // Passed in value to correlate with other assignments. + AssignmentID *string `json:"assignment_id" validate:"required"` + + // Assignment target type. + TargetType *string `json:"target_type" validate:"required"` + + // assignment target id. + Target *string `json:"target" validate:"required"` + + // Policy assignment ID. + ID *string `json:"id,omitempty"` + + // The href URL that links to the policies assignments API by policy assignment ID. + Href *string `json:"href,omitempty"` + + // The UTC timestamp when the policy assignment was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + + // The iam ID of the entity that created the policy assignment. + CreatedByID *string `json:"created_by_id,omitempty"` + + // The UTC timestamp when the policy assignment was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` + + // The iam ID of the entity that last modified the policy assignment. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` + + // Object for each account assigned. + Resources []PolicyAssignmentResources `json:"resources,omitempty"` +} + +// Constants associated with the PolicyAssignmentRecord.TargetType property. +// Assignment target type. +const ( + PolicyAssignmentRecordTargetTypeAccountConst = "Account" +) + +// UnmarshalPolicyAssignmentRecord unmarshals an instance of PolicyAssignmentRecord from the specified map of raw messages. +func UnmarshalPolicyAssignmentRecord(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyAssignmentRecord) + err = core.UnmarshalPrimitive(m, "template_id", &obj.TemplateID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "template_version", &obj.TemplateVersion) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "assignment_id", &obj.AssignmentID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "target_type", &obj.TargetType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "target", &obj.Target) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalPolicyAssignmentResources) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyAssignmentResources : The policy assignment resources. +type PolicyAssignmentResources struct { + // Account ID where resources are assigned. + Target *string `json:"target,omitempty"` + + // Set of properties for the assigned resource. + Policy *PolicyAssignmentResourcesPolicy `json:"policy,omitempty"` +} + +// UnmarshalPolicyAssignmentResources unmarshals an instance of PolicyAssignmentResources from the specified map of raw messages. +func UnmarshalPolicyAssignmentResources(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyAssignmentResources) + err = core.UnmarshalPrimitive(m, "target", &obj.Target) + if err != nil { + return + } + err = core.UnmarshalModel(m, "policy", &obj.Policy, UnmarshalPolicyAssignmentResourcesPolicy) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyAssignmentResourcesPolicy : Set of properties for the assigned resource. +type PolicyAssignmentResourcesPolicy struct { + // On success, includes the policy assigned. + ResourceCreated *AssignmentResourceCreated `json:"resource_created" validate:"required"` + + // The error response from API. + ErrorMessage *ErrorResponse `json:"error_message,omitempty"` + + // The policy assignment status. + Status *string `json:"status" validate:"required"` +} + +// Constants associated with the PolicyAssignmentResourcesPolicy.Status property. +// The policy assignment status. +const ( + PolicyAssignmentResourcesPolicyStatusFailedConst = "failed" + PolicyAssignmentResourcesPolicyStatusInProgressConst = "in_progress" + PolicyAssignmentResourcesPolicyStatusSucceedWithErrorsConst = "succeed_with_errors" + PolicyAssignmentResourcesPolicyStatusSucceededConst = "succeeded" +) + +// UnmarshalPolicyAssignmentResourcesPolicy unmarshals an instance of PolicyAssignmentResourcesPolicy from the specified map of raw messages. +func UnmarshalPolicyAssignmentResourcesPolicy(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyAssignmentResourcesPolicy) + err = core.UnmarshalModel(m, "resource_created", &obj.ResourceCreated, UnmarshalAssignmentResourceCreated) + if err != nil { + return + } + err = core.UnmarshalModel(m, "error_message", &obj.ErrorMessage, UnmarshalErrorResponse) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status", &obj.Status) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // PolicyRole : A role associated with a policy. type PolicyRole struct { // The role Cloud Resource Name (CRN) granted by the policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. @@ -2602,31 +4042,159 @@ type PolicyRole struct { // The display name of the role. DisplayName *string `json:"display_name,omitempty"` - // The description of the role. - Description *string `json:"description,omitempty"` + // The description of the role. + Description *string `json:"description,omitempty"` +} + +// NewPolicyRole : Instantiate PolicyRole (Generic Model Constructor) +func (*IamPolicyManagementV1) NewPolicyRole(roleID string) (_model *PolicyRole, err error) { + _model = &PolicyRole{ + RoleID: core.StringPtr(roleID), + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalPolicyRole unmarshals an instance of PolicyRole from the specified map of raw messages. +func UnmarshalPolicyRole(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyRole) + err = core.UnmarshalPrimitive(m, "role_id", &obj.RoleID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyTemplate : The core set of properties associated with the policy template. +type PolicyTemplate struct { + // name of template. + Name *string `json:"name" validate:"required"` + + // description of template purpose. + Description *string `json:"description,omitempty"` + + // account id where this template will be created. + AccountID *string `json:"account_id" validate:"required"` + + // Template vesrsion. + Version *string `json:"version" validate:"required"` + + // Template vesrsion committed status. + Committed *bool `json:"committed" validate:"required"` + + // The core set of properties associated with the template's policy objet. + Policy *TemplatePolicy `json:"policy" validate:"required"` + + // The policy template ID. + ID *string `json:"id,omitempty"` + + // The href URL that links to the policy templates API by policy tempalte ID. + Href *string `json:"href,omitempty"` + + // The UTC timestamp when the policy template was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + + // The iam ID of the entity that created the policy template. + CreatedByID *string `json:"created_by_id,omitempty"` + + // The UTC timestamp when the policy template was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` + + // The iam ID of the entity that last modified the policy template. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` } -// NewPolicyRole : Instantiate PolicyRole (Generic Model Constructor) -func (*IamPolicyManagementV1) NewPolicyRole(roleID string) (_model *PolicyRole, err error) { - _model = &PolicyRole{ - RoleID: core.StringPtr(roleID), +// UnmarshalPolicyTemplate unmarshals an instance of PolicyTemplate from the specified map of raw messages. +func UnmarshalPolicyTemplate(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyTemplate) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return } - err = core.ValidateStruct(_model, "required parameters") - return -} - -// UnmarshalPolicyRole unmarshals an instance of PolicyRole from the specified map of raw messages. -func UnmarshalPolicyRole(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(PolicyRole) - err = core.UnmarshalPrimitive(m, "role_id", &obj.RoleID) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) if err != nil { return } - err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) if err != nil { return } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) + err = core.UnmarshalPrimitive(m, "version", &obj.Version) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "committed", &obj.Committed) + if err != nil { + return + } + err = core.UnmarshalModel(m, "policy", &obj.Policy, UnmarshalTemplatePolicy) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyTemplateCollection : A collection of policy Templates. +type PolicyTemplateCollection struct { + // List of policy templates. + PolicyTemplates []PolicyTemplate `json:"policy_templates,omitempty"` +} + +// UnmarshalPolicyTemplateCollection unmarshals an instance of PolicyTemplateCollection from the specified map of raw messages. +func UnmarshalPolicyTemplateCollection(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyTemplateCollection) + err = core.UnmarshalModel(m, "policy_templates", &obj.PolicyTemplates, UnmarshalPolicyTemplate) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyTemplateVersionsCollection : A collection of policy Template versions. +type PolicyTemplateVersionsCollection struct { + // List of policy templates versions. + Versions []PolicyTemplate `json:"versions,omitempty"` +} + +// UnmarshalPolicyTemplateVersionsCollection unmarshals an instance of PolicyTemplateVersionsCollection from the specified map of raw messages. +func UnmarshalPolicyTemplateVersionsCollection(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyTemplateVersionsCollection) + err = core.UnmarshalModel(m, "versions", &obj.Versions, UnmarshalPolicyTemplate) if err != nil { return } @@ -2722,6 +4290,75 @@ func (options *ReplacePolicyOptions) SetHeaders(param map[string]string) *Replac return options } +// ReplacePolicyTemplateOptions : The ReplacePolicyTemplate options. +type ReplacePolicyTemplateOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` + + // The policy template version. + Version *string `json:"version" validate:"required,ne="` + + // The revision number for updating a policy template version and must match the ETag value of the existing policy + // template version. The Etag can be retrieved using the GET + // /v1/policy_templates/{policy_template_id}/versions/{version} API and looking at the ETag response header. + IfMatch *string `json:"If-Match" validate:"required"` + + // The core set of properties associated with the template's policy objet. + Policy *TemplatePolicy `json:"policy" validate:"required"` + + // description of template purpose. + Description *string `json:"description,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewReplacePolicyTemplateOptions : Instantiate ReplacePolicyTemplateOptions +func (*IamPolicyManagementV1) NewReplacePolicyTemplateOptions(policyTemplateID string, version string, ifMatch string, policy *TemplatePolicy) *ReplacePolicyTemplateOptions { + return &ReplacePolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + Version: core.StringPtr(version), + IfMatch: core.StringPtr(ifMatch), + Policy: policy, + } +} + +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *ReplacePolicyTemplateOptions) SetPolicyTemplateID(policyTemplateID string) *ReplacePolicyTemplateOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options +} + +// SetVersion : Allow user to set Version +func (_options *ReplacePolicyTemplateOptions) SetVersion(version string) *ReplacePolicyTemplateOptions { + _options.Version = core.StringPtr(version) + return _options +} + +// SetIfMatch : Allow user to set IfMatch +func (_options *ReplacePolicyTemplateOptions) SetIfMatch(ifMatch string) *ReplacePolicyTemplateOptions { + _options.IfMatch = core.StringPtr(ifMatch) + return _options +} + +// SetPolicy : Allow user to set Policy +func (_options *ReplacePolicyTemplateOptions) SetPolicy(policy *TemplatePolicy) *ReplacePolicyTemplateOptions { + _options.Policy = policy + return _options +} + +// SetDescription : Allow user to set Description +func (_options *ReplacePolicyTemplateOptions) SetDescription(description string) *ReplacePolicyTemplateOptions { + _options.Description = core.StringPtr(description) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ReplacePolicyTemplateOptions) SetHeaders(param map[string]string) *ReplacePolicyTemplateOptions { + options.Headers = param + return options +} + // ReplaceRoleOptions : The ReplaceRole options. type ReplaceRoleOptions struct { // The role ID. @@ -3018,6 +4655,101 @@ func UnmarshalRuleAttribute(m map[string]json.RawMessage, result interface{}) (e return } +// TemplateMetada : Origin Template information. +type TemplateMetada struct { + // Origin Template CRN. + CRN *string `json:"crn,omitempty"` + + // Template version. + Version *string `json:"version,omitempty"` +} + +// UnmarshalTemplateMetada unmarshals an instance of TemplateMetada from the specified map of raw messages. +func UnmarshalTemplateMetada(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(TemplateMetada) + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "version", &obj.Version) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// TemplatePolicy : The core set of properties associated with the template's policy objet. +type TemplatePolicy struct { + // The policy type; either 'access' or 'authorization'. + Type *string `json:"type" validate:"required"` + + // Allows the customer to use their own words to record the purpose/context related to a policy. + Description *string `json:"description,omitempty"` + + // The resource attributes to which the policy grants access. + Resource *V2PolicyResource `json:"resource" validate:"required"` + + // Indicates pattern of rule, either 'time-based-conditions:once', 'time-based-conditions:weekly:all-day', or + // 'time-based-conditions:weekly:custom-hours'. + Pattern *string `json:"pattern,omitempty"` + + // Additional access conditions associated with the policy. + Rule V2PolicyRuleIntf `json:"rule,omitempty"` + + // Specifies the type of access granted by the policy. + Control *Control `json:"control" validate:"required"` +} + +// Constants associated with the TemplatePolicy.Type property. +// The policy type; either 'access' or 'authorization'. +const ( + TemplatePolicyTypeAccessConst = "access" + TemplatePolicyTypeAuthorizationConst = "authorization" +) + +// NewTemplatePolicy : Instantiate TemplatePolicy (Generic Model Constructor) +func (*IamPolicyManagementV1) NewTemplatePolicy(typeVar string, resource *V2PolicyResource, control *Control) (_model *TemplatePolicy, err error) { + _model = &TemplatePolicy{ + Type: core.StringPtr(typeVar), + Resource: resource, + Control: control, + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalTemplatePolicy unmarshals an instance of TemplatePolicy from the specified map of raw messages. +func UnmarshalTemplatePolicy(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(TemplatePolicy) + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resource", &obj.Resource, UnmarshalV2PolicyResource) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "pattern", &obj.Pattern) + if err != nil { + return + } + err = core.UnmarshalModel(m, "rule", &obj.Rule, UnmarshalV2PolicyRule) + if err != nil { + return + } + err = core.UnmarshalModel(m, "control", &obj.Control, UnmarshalControl) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // UpdatePolicyStateOptions : The UpdatePolicyState options. type UpdatePolicyStateOptions struct { // The policy ID. @@ -3123,6 +4855,9 @@ type V2Policy struct { // The optional count of times that policy has provided a permit, when passing query parameter // format=include_last_permit. LastPermitFrequency *int64 `json:"last_permit_frequency,omitempty"` + + // Origin Template information. + Template *TemplateMetada `json:"template,omitempty"` } // Constants associated with the V2Policy.Type property. @@ -3206,6 +4941,10 @@ func UnmarshalV2Policy(m map[string]json.RawMessage, result interface{}) (err er if err != nil { return } + err = core.UnmarshalModel(m, "template", &obj.Template, UnmarshalTemplateMetada) + if err != nil { + return + } reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) return } @@ -3499,6 +5238,37 @@ func UnmarshalV2PolicySubjectAttribute(m map[string]json.RawMessage, result inte return } +// ConflictsWith : Details of conflicting resource. +type ConflictsWith struct { + // The revision number of the resource. + Etag *string `json:"etag,omitempty"` + + // The conflicting role id. + Role *string `json:"role,omitempty"` + + // The conflicting policy id. + Policy *string `json:"policy,omitempty"` +} + +// UnmarshalConflictsWith unmarshals an instance of ConflictsWith from the specified map of raw messages. +func UnmarshalConflictsWith(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ConflictsWith) + err = core.UnmarshalPrimitive(m, "etag", &obj.Etag) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "role", &obj.Role) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "policy", &obj.Policy) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // CustomRole : An additional set of properties associated with a role. type CustomRole struct { // The role ID. Composed of hexadecimal characters. @@ -3602,6 +5372,114 @@ func UnmarshalCustomRole(m map[string]json.RawMessage, result interface{}) (err return } +// ErrorDetails : Additional error details. +type ErrorDetails struct { + // Details of conflicting resource. + ConflictsWith *ConflictsWith `json:"conflicts_with,omitempty"` +} + +// UnmarshalErrorDetails unmarshals an instance of ErrorDetails from the specified map of raw messages. +func UnmarshalErrorDetails(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ErrorDetails) + err = core.UnmarshalModel(m, "conflicts_with", &obj.ConflictsWith, UnmarshalConflictsWith) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ErrorObject : ErrorObject struct +type ErrorObject struct { + // The API error code for the error. + Code *string `json:"code" validate:"required"` + + // The error message returned by the API. + Message *string `json:"message" validate:"required"` + + // Additional error details. + Details *ErrorDetails `json:"details,omitempty"` + + // Additional info for error. + MoreInfo *string `json:"more_info,omitempty"` +} + +// Constants associated with the ErrorObject.Code property. +// The API error code for the error. +const ( + ErrorObjectCodeInsufficentPermissionsConst = "insufficent_permissions" + ErrorObjectCodeInvalidBodyConst = "invalid_body" + ErrorObjectCodeInvalidTokenConst = "invalid_token" + ErrorObjectCodeMissingRequiredQueryParameterConst = "missing_required_query_parameter" + ErrorObjectCodeNotFoundConst = "not_found" + ErrorObjectCodePolicyAssignmentConflictErrorConst = "policy_assignment_conflict_error" + ErrorObjectCodePolicyAssignmentNotFoundConst = "policy_assignment_not_found" + ErrorObjectCodePolicyConflictErrorConst = "policy_conflict_error" + ErrorObjectCodePolicyNotFoundConst = "policy_not_found" + ErrorObjectCodePolicyTemplateConflictErrorConst = "policy_template_conflict_error" + ErrorObjectCodePolicyTemplateNotFoundConst = "policy_template_not_found" + ErrorObjectCodeRequestNotProcessedConst = "request_not_processed" + ErrorObjectCodeRoleConflictErrorConst = "role_conflict_error" + ErrorObjectCodeRoleNotFoundConst = "role_not_found" + ErrorObjectCodeTooManyRequestsConst = "too_many_requests" + ErrorObjectCodeUnableToProcessConst = "unable_to_process" + ErrorObjectCodeUnsupportedContentTypeConst = "unsupported_content_type" +) + +// UnmarshalErrorObject unmarshals an instance of ErrorObject from the specified map of raw messages. +func UnmarshalErrorObject(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ErrorObject) + err = core.UnmarshalPrimitive(m, "code", &obj.Code) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "message", &obj.Message) + if err != nil { + return + } + err = core.UnmarshalModel(m, "details", &obj.Details, UnmarshalErrorDetails) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "more_info", &obj.MoreInfo) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ErrorResponse : The error response from API. +type ErrorResponse struct { + // The unique transaction id for the request. + Trace *string `json:"trace,omitempty"` + + // The errors encountered during the response. + Errors []ErrorObject `json:"errors,omitempty"` + + // The http error code of the response. + StatusCode *int64 `json:"status_code,omitempty"` +} + +// UnmarshalErrorResponse unmarshals an instance of ErrorResponse from the specified map of raw messages. +func UnmarshalErrorResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ErrorResponse) + err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + if err != nil { + return + } + err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalErrorObject) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // Policy : The core set of properties associated with a policy. type Policy struct { // The policy ID. @@ -3639,6 +5517,9 @@ type Policy struct { // The policy state. State *string `json:"state,omitempty"` + + // Origin Template information. + Template *TemplateMetada `json:"template,omitempty"` } // Constants associated with the Policy.State property. @@ -3699,6 +5580,10 @@ func UnmarshalPolicy(m map[string]json.RawMessage, result interface{}) (err erro if err != nil { return } + err = core.UnmarshalModel(m, "template", &obj.Template, UnmarshalTemplateMetada) + if err != nil { + return + } reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) return } diff --git a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go index 7ea2cbef..99746112 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go @@ -2,7 +2,7 @@ // +build examples /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,13 +56,17 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { config map[string]string configLoaded bool = false - exampleUserID = "IBMid-user1" - exampleServiceName = "iam-groups" - exampleAccountID string - examplePolicyID string - examplePolicyETag string - exampleCustomRoleID string - exampleCustomRoleETag string + exampleUserID = "IBMid-user1" + exampleServiceName = "iam-groups" + exampleAccountID string + examplePolicyID string + examplePolicyETag string + exampleCustomRoleID string + exampleCustomRoleETag string + examplePolicyTemplateName = "PolicySampleTemplateTest" + examplePolicyTemplateID string + examplePolicyTemplateETag string + examplePolicyTemplateVersion string ) var shouldSkipTest = func() { @@ -676,5 +680,344 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { Expect(response.StatusCode).To(Equal(204)) }) + It(`ListPolicyTemplates request example`, func() { + fmt.Println("\nListPolicyTemplates() result:") + // begin-list_policy_templates + + listPolicyTemplatesOptions := iamPolicyManagementService.NewListPolicyTemplatesOptions( + exampleAccountID, + ) + + policyTemplateCollection, response, err := iamPolicyManagementService.ListPolicyTemplates(listPolicyTemplatesOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policyTemplateCollection, "", " ") + fmt.Println(string(b)) + + // end-list_policy_templates + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplateCollection).ToNot(BeNil()) + }) + It(`CreatePolicyTemplate request example`, func() { + fmt.Println("\nCreatePolicyTemplate() result:") + // begin-create_policy_template + + policyRole := &iampolicymanagementv1.Roles{ + RoleID: core.StringPtr("crn:v1:bluemix:public:iam::::role:Viewer"), + } + v2PolicyGrant := &iampolicymanagementv1.Grant{ + Roles: []iampolicymanagementv1.Roles{*policyRole}, + } + v2PolicyControl := &iampolicymanagementv1.Control{ + Grant: v2PolicyGrant, + } + serviceNameResourceAttribute := &iampolicymanagementv1.V2PolicyResourceAttribute{ + Key: core.StringPtr("serviceName"), + Operator: core.StringPtr("stringEquals"), + Value: core.StringPtr("iam-access-management"), + } + policyResource := &iampolicymanagementv1.V2PolicyResource{ + Attributes: []iampolicymanagementv1.V2PolicyResourceAttribute{ + *serviceNameResourceAttribute}, + } + + templatePolicyModel := &iampolicymanagementv1.TemplatePolicy{ + Type: core.StringPtr("access"), + Description: core.StringPtr("Test Template"), + Resource: policyResource, + Control: v2PolicyControl, + } + + createPolicyTemplateOptions := iamPolicyManagementService.NewCreatePolicyTemplateOptions( + examplePolicyTemplateName, + exampleAccountID, + templatePolicyModel, + ) + + policyTemplate, response, err := iamPolicyManagementService.CreatePolicyTemplate(createPolicyTemplateOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policyTemplate, "", " ") + fmt.Println(string(b)) + + // end-create_policy_template + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(policyTemplate).ToNot(BeNil()) + + examplePolicyTemplateID = *policyTemplate.ID + + }) + It(`GetPolicyTemplate request example`, func() { + fmt.Println("\nGetPolicyTemplate() result:") + // begin-get_policy_template + + getPolicyTemplateOptions := iamPolicyManagementService.NewGetPolicyTemplateOptions( + examplePolicyTemplateID, + ) + + policyTemplate, response, err := iamPolicyManagementService.GetPolicyTemplate(getPolicyTemplateOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policyTemplate, "", " ") + fmt.Println(string(b)) + + // end-get_policy_template + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplate).ToNot(BeNil()) + + // examplePolicyTemplateETag = response.GetHeaders().Get("ETag") + + }) + + It(`CreatePolicyTemplateVersion request example`, func() { + fmt.Println("\nCreatePolicyTemplateVersion() result:") + // begin-create_policy_template_version + + v2PolicyGrant := &iampolicymanagementv1.Grant{ + Roles: []iampolicymanagementv1.Roles{ + {core.StringPtr("crn:v1:bluemix:public:iam::::role:Viewer")}, + {core.StringPtr("crn:v1:bluemix:public:iam::::role:Administrator")}, + }, + } + + v2PolicyControl := &iampolicymanagementv1.Control{ + Grant: v2PolicyGrant, + } + serviceNameResourceAttribute := &iampolicymanagementv1.V2PolicyResourceAttribute{ + Key: core.StringPtr("serviceName"), + Operator: core.StringPtr("stringEquals"), + Value: core.StringPtr("watson"), + } + policyResource := &iampolicymanagementv1.V2PolicyResource{ + Attributes: []iampolicymanagementv1.V2PolicyResourceAttribute{ + *serviceNameResourceAttribute}, + } + + templatePolicyModel := &iampolicymanagementv1.TemplatePolicy{ + Type: core.StringPtr("access"), + Description: core.StringPtr("Test Template v2"), + Resource: policyResource, + Control: v2PolicyControl, + } + + createPolicyTemplateVersionOptions := iamPolicyManagementService.NewCreatePolicyTemplateVersionOptions( + examplePolicyTemplateID, + templatePolicyModel, + ) + + policyTemplate, response, err := iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policyTemplate, "", " ") + fmt.Println(string(b)) + + // end-create_policy_template_version + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(policyTemplate).ToNot(BeNil()) + + examplePolicyTemplateVersion = *policyTemplate.Version + examplePolicyTemplateETag = response.GetHeaders().Get("ETag") + + }) + + It(`ListPolicyTemplateVersions request example`, func() { + fmt.Println("\nListPolicyTemplateVersions() result:") + // begin-list_policy_template_versions + + listPolicyTemplateVersionsOptions := iamPolicyManagementService.NewListPolicyTemplateVersionsOptions( + examplePolicyTemplateID, + ) + + policyTemplateVersionsCollection, response, err := iamPolicyManagementService.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policyTemplateVersionsCollection, "", " ") + fmt.Println(string(b)) + + // end-list_policy_template_versions + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplateVersionsCollection).ToNot(BeNil()) + }) + + It(`ReplacePolicyTemplate request example`, func() { + fmt.Println("\nReplacePolicyTemplate() result:") + // begin-replace_policy_template + v2PolicyGrant := &iampolicymanagementv1.Grant{ + Roles: []iampolicymanagementv1.Roles{ + {core.StringPtr("crn:v1:bluemix:public:iam::::role:Viewer")}, + {core.StringPtr("crn:v1:bluemix:public:iam::::role:Administrator")}, + }, + } + + v2PolicyControl := &iampolicymanagementv1.Control{ + Grant: v2PolicyGrant, + } + serviceNameResourceAttribute := &iampolicymanagementv1.V2PolicyResourceAttribute{ + Key: core.StringPtr("serviceName"), + Operator: core.StringPtr("stringEquals"), + Value: core.StringPtr("watson"), + } + policyResource := &iampolicymanagementv1.V2PolicyResource{ + Attributes: []iampolicymanagementv1.V2PolicyResourceAttribute{ + *serviceNameResourceAttribute}, + } + + templatePolicyModel := &iampolicymanagementv1.TemplatePolicy{ + Type: core.StringPtr("access"), + Description: core.StringPtr("Test Template v2"), + Resource: policyResource, + Control: v2PolicyControl, + } + + replacePolicyTemplateOptions := iamPolicyManagementService.NewReplacePolicyTemplateOptions( + examplePolicyTemplateID, + examplePolicyTemplateVersion, + examplePolicyTemplateETag, + templatePolicyModel, + ) + + policyTemplate, response, err := iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policyTemplate, "", " ") + fmt.Println(string(b)) + + // end-replace_policy_template + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplate).ToNot(BeNil()) + + examplePolicyTemplateVersion = *policyTemplate.Version + examplePolicyTemplateETag = response.GetHeaders().Get("ETag") + }) + It(`GetPolicyTemplateVersion request example`, func() { + fmt.Println("\nGetPolicyTemplateVersion() result:") + // begin-get_policy_template_version + + getPolicyTemplateVersionOptions := iamPolicyManagementService.NewGetPolicyTemplateVersionOptions( + examplePolicyTemplateID, + examplePolicyTemplateVersion, + ) + + policyTemplate, response, err := iamPolicyManagementService.GetPolicyTemplateVersion(getPolicyTemplateVersionOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policyTemplate, "", " ") + fmt.Println(string(b)) + + // end-get_policy_template_version + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplate).ToNot(BeNil()) + }) + + It(`CommitPolicyTemplate request example`, func() { + fmt.Println("\nCommitPolicyTemplate() result:") + // begin-commit_policy_template + + commitPolicyTemplateOptions := iamPolicyManagementService.NewCommitPolicyTemplateOptions( + examplePolicyTemplateID, + examplePolicyTemplateVersion, + examplePolicyTemplateETag, + ) + + response, err := iamPolicyManagementService.CommitPolicyTemplate(commitPolicyTemplateOptions) + if err != nil { + panic(err) + } + if response.StatusCode != 204 { + fmt.Printf("\nUnexpected response status code received from CommitPolicyTemplate(): %d\n", response.StatusCode) + } + + // end-commit_policy_template + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + + It(`ListPolicyAssignments request example`, func() { + fmt.Println("\nListPolicyAssignments() result:") + // begin-list_Policy Assignments + + listPolicyAssignmentsOptions := iamPolicyManagementService.NewListPolicyAssignmentsOptions( + exampleAccountID, + ) + + polcyTemplateAssignmentCollection, response, err := iamPolicyManagementService.ListPolicyAssignments(listPolicyAssignmentsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(polcyTemplateAssignmentCollection, "", " ") + fmt.Println(string(b)) + + // end-list_Policy Assignments + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(polcyTemplateAssignmentCollection).ToNot(BeNil()) + }) + + It(`DeletePolicyTemplateVersion request example`, func() { + // begin-delete_policy_template_version + + deletePolicyTemplateVersionOptions := iamPolicyManagementService.NewDeletePolicyTemplateVersionOptions( + examplePolicyTemplateID, + examplePolicyTemplateVersion, + ) + + response, err := iamPolicyManagementService.DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions) + if err != nil { + panic(err) + } + if response.StatusCode != 204 { + fmt.Printf("\nUnexpected response status code received from DeletePolicyTemplateVersion(): %d\n", response.StatusCode) + } + + // end-delete_policy_template_version + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + + It(`DeletePolicyTemplate request example`, func() { + // begin-delete_policy_template + + deletePolicyTemplateOptions := iamPolicyManagementService.NewDeletePolicyTemplateOptions( + examplePolicyTemplateID, + ) + + response, err := iamPolicyManagementService.DeletePolicyTemplate(deletePolicyTemplateOptions) + if err != nil { + panic(err) + } + if response.StatusCode != 204 { + fmt.Printf("\nUnexpected response status code received from DeletePolicyTemplate(): %d\n", response.StatusCode) + } + + // end-delete_policy_template + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) }) diff --git a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go index 7ae6efe4..9c7eb3bd 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go @@ -40,7 +40,8 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { const externalConfigFile = "../iam_policy_management.env" var ( - service *iampolicymanagementv1.IamPolicyManagementV1 + service *iampolicymanagementv1.IamPolicyManagementV1 + err error config map[string]string configLoaded bool = false @@ -56,10 +57,13 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { testEditorRoleCrn string = "crn:v1:bluemix:public:iam::::role:Editor" testServiceName string = "iam-groups" - testCustomRoleId string = "" - testCustomRoleETag string = "" - testCustomRoleName string = "TestGoRole" + strconv.Itoa(rand.Intn(100000)) - testServiceRoleCrn string = "crn:v1:bluemix:public:iam-identity::::serviceRole:ServiceIdCreator" + testCustomRoleId string = "" + testCustomRoleETag string = "" + testCustomRoleName string = "TestGoRole" + strconv.Itoa(rand.Intn(100000)) + testServiceRoleCrn string = "crn:v1:bluemix:public:iam-identity::::serviceRole:ServiceIdCreator" + testPolicyTemplateID string = "" + testPolicyTemplateETag string = "" + testPolicyTemplateVersion string = "" ) var shouldSkipTest = func() { @@ -643,6 +647,317 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) }) + Describe(`CreatePolicyTemplate - Create a policy template`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CreatePolicyTemplate(createPolicyTemplateOptions *CreatePolicyTemplateOptions)`, func() { + v2PolicyResourceAttributeModel := &iampolicymanagementv1.V2PolicyResourceAttribute{ + Key: core.StringPtr("serviceName"), + Operator: core.StringPtr("stringEquals"), + Value: core.StringPtr("iam-access-management"), + } + + v2PolicyResourceModel := &iampolicymanagementv1.V2PolicyResource{ + Attributes: []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel}, + } + + rolesModel := &iampolicymanagementv1.Roles{ + RoleID: core.StringPtr(testViewerRoleCrn), + } + + grantModel := &iampolicymanagementv1.Grant{ + Roles: []iampolicymanagementv1.Roles{*rolesModel}, + } + + controlModel := &iampolicymanagementv1.Control{ + Grant: grantModel, + } + + templatePolicyModel := &iampolicymanagementv1.TemplatePolicy{ + Type: core.StringPtr("access"), + Description: core.StringPtr("Test Policy For Template"), + Resource: v2PolicyResourceModel, + Control: controlModel, + } + + createPolicyTemplateOptions := &iampolicymanagementv1.CreatePolicyTemplateOptions{ + Name: core.StringPtr("PolicySampleTemplate"), + AccountID: core.StringPtr(testAccountID), + Policy: templatePolicyModel, + Description: core.StringPtr("Test PolicySampleTemplate"), + Committed: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("default"), + } + + policyTemplate, response, err := service.CreatePolicyTemplate(createPolicyTemplateOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(policyTemplate).ToNot(BeNil()) + Expect(policyTemplate.Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + + testPolicyTemplateID = *policyTemplate.ID + }) + }) + + Describe(`ListPolicyTemplates - Get policy templates by attributes`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListPolicyTemplates(listPolicyTemplatesOptions *ListPolicyTemplatesOptions)`, func() { + listPolicyTemplatesOptions := &iampolicymanagementv1.ListPolicyTemplatesOptions{ + AccountID: core.StringPtr(testAccountID), + AcceptLanguage: core.StringPtr("default"), + } + + policyTemplateCollection, response, err := service.ListPolicyTemplates(listPolicyTemplatesOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplateCollection).ToNot(BeNil()) + + Expect(policyTemplateCollection.PolicyTemplates[0].Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplateCollection.PolicyTemplates[0].Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplateCollection.PolicyTemplates[0].AccountID).To(Equal(core.StringPtr(testAccountID))) + }) + }) + + Describe(`GetPolicyTemplate - Retrieve latest policy template version by template ID`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetPolicyTemplate(getPolicyTemplateOptions *GetPolicyTemplateOptions)`, func() { + getPolicyTemplateOptions := &iampolicymanagementv1.GetPolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + } + + policyTemplate, response, err := service.GetPolicyTemplate(getPolicyTemplateOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplate).ToNot(BeNil()) + + Expect(policyTemplate.Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + }) + }) + + Describe(`CreatePolicyTemplateVersion - Create a new policy template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CreatePolicyTemplateVersion(createPolicyTemplateVersionOptions *CreatePolicyTemplateVersionOptions)`, func() { + v2PolicyResourceAttributeModel := &iampolicymanagementv1.V2PolicyResourceAttribute{ + Key: core.StringPtr("serviceName"), + Operator: core.StringPtr("stringEquals"), + Value: core.StringPtr("watson"), + } + + v2PolicyResourceModel := &iampolicymanagementv1.V2PolicyResource{ + Attributes: []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel}, + } + + rolesModel := &iampolicymanagementv1.Roles{ + RoleID: core.StringPtr(testEditorRoleCrn), + } + + grantModel := &iampolicymanagementv1.Grant{ + Roles: []iampolicymanagementv1.Roles{*rolesModel}, + } + + controlModel := &iampolicymanagementv1.Control{ + Grant: grantModel, + } + + templatePolicyModel := &iampolicymanagementv1.TemplatePolicy{ + Type: core.StringPtr("access"), + Description: core.StringPtr("Watson Policy Template"), + Resource: v2PolicyResourceModel, + Control: controlModel, + } + + createPolicyTemplateVersionOptions := &iampolicymanagementv1.CreatePolicyTemplateVersionOptions{ + PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + Policy: templatePolicyModel, + Description: core.StringPtr("Watson Policy Template version"), + } + + policyTemplate, response, err := service.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(policyTemplate).ToNot(BeNil()) + + Expect(policyTemplate.Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + + testPolicyTemplateVersion = *policyTemplate.Version + testPolicyTemplateETag = response.GetHeaders().Get(etagHeader) + }) + }) + + Describe(`ListPolicyTemplateVersions - Retrieve policy template versions`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListPolicyTemplateVersions(listPolicyTemplateVersionsOptions *ListPolicyTemplateVersionsOptions)`, func() { + listPolicyTemplateVersionsOptions := &iampolicymanagementv1.ListPolicyTemplateVersionsOptions{ + PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + } + + policyTemplateVersionsCollection, response, err := service.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplateVersionsCollection).ToNot(BeNil()) + }) + }) + + Describe(`ReplacePolicyTemplate - Update a policy template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ReplacePolicyTemplate(replacePolicyTemplateOptions *ReplacePolicyTemplateOptions)`, func() { + v2PolicyResourceAttributeModel := &iampolicymanagementv1.V2PolicyResourceAttribute{ + Key: core.StringPtr("serviceName"), + Operator: core.StringPtr("stringEquals"), + Value: core.StringPtr("watson"), + } + + v2PolicyResourceModel := &iampolicymanagementv1.V2PolicyResource{ + Attributes: []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel}, + } + + rolesModel := &iampolicymanagementv1.Roles{ + RoleID: core.StringPtr(testViewerRoleCrn), + } + + grantModel := &iampolicymanagementv1.Grant{ + Roles: []iampolicymanagementv1.Roles{*rolesModel}, + } + + controlModel := &iampolicymanagementv1.Control{ + Grant: grantModel, + } + + templatePolicyModel := &iampolicymanagementv1.TemplatePolicy{ + Type: core.StringPtr("access"), + Description: core.StringPtr("Version Update"), + Resource: v2PolicyResourceModel, + Control: controlModel, + } + + replacePolicyTemplateOptions := &iampolicymanagementv1.ReplacePolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + Version: core.StringPtr(testPolicyTemplateVersion), + IfMatch: core.StringPtr(testPolicyTemplateETag), + Policy: templatePolicyModel, + Description: core.StringPtr("Template version update"), + } + + policyTemplate, response, err := service.ReplacePolicyTemplate(replacePolicyTemplateOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplate).ToNot(BeNil()) + + Expect(policyTemplate.Version).To(Equal(core.StringPtr("2"))) + Expect(policyTemplate.Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + + testPolicyTemplateETag = response.GetHeaders().Get(etagHeader) + + }) + }) + + Describe(`GetPolicyTemplateVersion - Retrieve a policy template version by ID`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetPolicyTemplateVersion(getPolicyTemplateVersionOptions *GetPolicyTemplateVersionOptions)`, func() { + getPolicyTemplateVersionOptions := &iampolicymanagementv1.GetPolicyTemplateVersionOptions{ + PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + Version: core.StringPtr(testPolicyTemplateVersion), + } + + policyTemplate, response, err := service.GetPolicyTemplateVersion(getPolicyTemplateVersionOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyTemplate).ToNot(BeNil()) + + Expect(policyTemplate.Version).To(Equal(core.StringPtr("2"))) + Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + }) + }) + + Describe(`CommitPolicyTemplate - Commit a policy template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CommitPolicyTemplate(commitPolicyTemplateOptions *CommitPolicyTemplateOptions)`, func() { + commitPolicyTemplateOptions := &iampolicymanagementv1.CommitPolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + Version: core.StringPtr(testPolicyTemplateVersion), + IfMatch: core.StringPtr(testPolicyTemplateETag), + } + + response, err := service.CommitPolicyTemplate(commitPolicyTemplateOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) + + Describe(`ListPolicyAssignments - Get policies template assignments by attributes`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListPolicyAssignments(listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions)`, func() { + listPolicyAssignmentsOptions := &iampolicymanagementv1.ListPolicyAssignmentsOptions{ + AccountID: core.StringPtr(testAccountID), + AcceptLanguage: core.StringPtr("default"), + TemplateID: core.StringPtr(testPolicyTemplateID), + TemplateVersion: core.StringPtr(testPolicyTemplateVersion), + } + + polcyTemplateAssignmentCollection, response, err := service.ListPolicyAssignments(listPolicyAssignmentsOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(polcyTemplateAssignmentCollection).ToNot(BeNil()) + }) + }) + + Describe(`DeletePolicyTemplateVersion - Delete a policy template version by ID and version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions *DeletePolicyTemplateVersionOptions)`, func() { + deletePolicyTemplateVersionOptions := &iampolicymanagementv1.DeletePolicyTemplateVersionOptions{ + PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + Version: core.StringPtr(testPolicyTemplateVersion), + } + + response, err := service.DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) + + Describe(`DeletePolicyTemplate - Delete a policy template by ID`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`DeletePolicyTemplate(deletePolicyTemplateOptions *DeletePolicyTemplateOptions)`, func() { + deletePolicyTemplateOptions := &iampolicymanagementv1.DeletePolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + } + + response, err := service.DeletePolicyTemplate(deletePolicyTemplateOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) + // clean up all test groups AfterSuite(func() { if !configLoaded { diff --git a/iampolicymanagementv1/iam_policy_management_v1_test.go b/iampolicymanagementv1/iam_policy_management_v1_test.go index df3e174c..8ce9c5ad 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_test.go @@ -259,7 +259,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policies": [{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}]}`) + fmt.Fprintf(res, "%s", `{"policies": [{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}]}`) })) }) It(`Invoke ListPolicies successfully with retries`, func() { @@ -335,7 +335,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policies": [{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}]}`) + fmt.Fprintf(res, "%s", `{"policies": [{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}]}`) })) }) It(`Invoke ListPolicies successfully`, func() { @@ -578,7 +578,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke CreatePolicy successfully with retries`, func() { @@ -685,7 +685,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke CreatePolicy successfully`, func() { @@ -1004,7 +1004,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke ReplacePolicy successfully with retries`, func() { @@ -1112,7 +1112,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke ReplacePolicy successfully`, func() { @@ -1378,7 +1378,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke GetPolicy successfully with retries`, func() { @@ -1432,7 +1432,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke GetPolicy successfully`, func() { @@ -1680,7 +1680,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke UpdatePolicyState successfully with retries`, func() { @@ -1754,7 +1754,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke UpdatePolicyState successfully`, func() { @@ -3033,7 +3033,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policies": [{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19}]}`) + fmt.Fprintf(res, "%s", `{"policies": [{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19, "template": {"crn": "CRN", "version": "Version"}}]}`) })) }) It(`Invoke ListV2Policies successfully with retries`, func() { @@ -3109,7 +3109,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policies": [{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19}]}`) + fmt.Fprintf(res, "%s", `{"policies": [{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19, "template": {"crn": "CRN", "version": "Version"}}]}`) })) }) It(`Invoke ListV2Policies successfully`, func() { @@ -3369,7 +3369,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19}`) + fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19, "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke CreateV2Policy successfully with retries`, func() { @@ -3493,7 +3493,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19}`) + fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19, "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke CreateV2Policy successfully`, func() { @@ -3880,7 +3880,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19}`) + fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19, "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke ReplaceV2Policy successfully with retries`, func() { @@ -4005,7 +4005,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19}`) + fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19, "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke ReplaceV2Policy successfully`, func() { @@ -4325,7 +4325,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19}`) + fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19, "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke GetV2Policy successfully with retries`, func() { @@ -4381,7 +4381,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19}`) + fmt.Fprintf(res, "%s", `{"type": "access", "description": "Description", "subject": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "Value"}]}, "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "id": "ID", "href": "Href", "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "active", "last_permit_at": "LastPermitAt", "last_permit_frequency": 19, "template": {"crn": "CRN", "version": "Version"}}`) })) }) It(`Invoke GetV2Policy successfully`, func() { @@ -4548,12 +4548,3020 @@ var _ = Describe(`IamPolicyManagementV1`, func() { }) }) }) + Describe(`ListPolicyTemplates(listPolicyTemplatesOptions *ListPolicyTemplatesOptions) - Operation response error`, func() { + listPolicyTemplatesPath := "/v1/policy_templates" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyTemplatesPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListPolicyTemplates with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyTemplatesOptions model + listPolicyTemplatesOptionsModel := new(iampolicymanagementv1.ListPolicyTemplatesOptions) + listPolicyTemplatesOptionsModel.AccountID = core.StringPtr("testString") + listPolicyTemplatesOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyTemplatesOptionsModel.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 := iamPolicyManagementService.ListPolicyTemplates(listPolicyTemplatesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.ListPolicyTemplates(listPolicyTemplatesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListPolicyTemplates(listPolicyTemplatesOptions *ListPolicyTemplatesOptions)`, func() { + listPolicyTemplatesPath := "/v1/policy_templates" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyTemplatesPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"policy_templates": [{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}]}`) + })) + }) + It(`Invoke ListPolicyTemplates successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the ListPolicyTemplatesOptions model + listPolicyTemplatesOptionsModel := new(iampolicymanagementv1.ListPolicyTemplatesOptions) + listPolicyTemplatesOptionsModel.AccountID = core.StringPtr("testString") + listPolicyTemplatesOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyTemplatesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.ListPolicyTemplatesWithContext(ctx, listPolicyTemplatesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.ListPolicyTemplates(listPolicyTemplatesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.ListPolicyTemplatesWithContext(ctx, listPolicyTemplatesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyTemplatesPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"policy_templates": [{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}]}`) + })) + }) + It(`Invoke ListPolicyTemplates successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.ListPolicyTemplates(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListPolicyTemplatesOptions model + listPolicyTemplatesOptionsModel := new(iampolicymanagementv1.ListPolicyTemplatesOptions) + listPolicyTemplatesOptionsModel.AccountID = core.StringPtr("testString") + listPolicyTemplatesOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyTemplatesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.ListPolicyTemplates(listPolicyTemplatesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListPolicyTemplates with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyTemplatesOptions model + listPolicyTemplatesOptionsModel := new(iampolicymanagementv1.ListPolicyTemplatesOptions) + listPolicyTemplatesOptionsModel.AccountID = core.StringPtr("testString") + listPolicyTemplatesOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyTemplatesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.ListPolicyTemplates(listPolicyTemplatesOptionsModel) + 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 ListPolicyTemplatesOptions model with no property values + listPolicyTemplatesOptionsModelNew := new(iampolicymanagementv1.ListPolicyTemplatesOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.ListPolicyTemplates(listPolicyTemplatesOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListPolicyTemplates successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyTemplatesOptions model + listPolicyTemplatesOptionsModel := new(iampolicymanagementv1.ListPolicyTemplatesOptions) + listPolicyTemplatesOptionsModel.AccountID = core.StringPtr("testString") + listPolicyTemplatesOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyTemplatesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.ListPolicyTemplates(listPolicyTemplatesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreatePolicyTemplate(createPolicyTemplateOptions *CreatePolicyTemplateOptions) - Operation response error`, func() { + createPolicyTemplatePath := "/v1/policy_templates" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createPolicyTemplatePath)) + Expect(req.Method).To(Equal("POST")) + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreatePolicyTemplate with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateOptions model + createPolicyTemplateOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateOptions) + createPolicyTemplateOptionsModel.Name = core.StringPtr("testString") + createPolicyTemplateOptionsModel.AccountID = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Policy = templatePolicyModel + createPolicyTemplateOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Committed = core.BoolPtr(true) + createPolicyTemplateOptionsModel.AcceptLanguage = core.StringPtr("default") + createPolicyTemplateOptionsModel.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 := iamPolicyManagementService.CreatePolicyTemplate(createPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.CreatePolicyTemplate(createPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreatePolicyTemplate(createPolicyTemplateOptions *CreatePolicyTemplateOptions)`, func() { + createPolicyTemplatePath := "/v1/policy_templates" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createPolicyTemplatePath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke CreatePolicyTemplate successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateOptions model + createPolicyTemplateOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateOptions) + createPolicyTemplateOptionsModel.Name = core.StringPtr("testString") + createPolicyTemplateOptionsModel.AccountID = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Policy = templatePolicyModel + createPolicyTemplateOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Committed = core.BoolPtr(true) + createPolicyTemplateOptionsModel.AcceptLanguage = core.StringPtr("default") + createPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.CreatePolicyTemplateWithContext(ctx, createPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.CreatePolicyTemplate(createPolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.CreatePolicyTemplateWithContext(ctx, createPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createPolicyTemplatePath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke CreatePolicyTemplate successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.CreatePolicyTemplate(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateOptions model + createPolicyTemplateOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateOptions) + createPolicyTemplateOptionsModel.Name = core.StringPtr("testString") + createPolicyTemplateOptionsModel.AccountID = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Policy = templatePolicyModel + createPolicyTemplateOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Committed = core.BoolPtr(true) + createPolicyTemplateOptionsModel.AcceptLanguage = core.StringPtr("default") + createPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.CreatePolicyTemplate(createPolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreatePolicyTemplate with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateOptions model + createPolicyTemplateOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateOptions) + createPolicyTemplateOptionsModel.Name = core.StringPtr("testString") + createPolicyTemplateOptionsModel.AccountID = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Policy = templatePolicyModel + createPolicyTemplateOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Committed = core.BoolPtr(true) + createPolicyTemplateOptionsModel.AcceptLanguage = core.StringPtr("default") + createPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.CreatePolicyTemplate(createPolicyTemplateOptionsModel) + 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 CreatePolicyTemplateOptions model with no property values + createPolicyTemplateOptionsModelNew := new(iampolicymanagementv1.CreatePolicyTemplateOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.CreatePolicyTemplate(createPolicyTemplateOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(201) + })) + }) + It(`Invoke CreatePolicyTemplate successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateOptions model + createPolicyTemplateOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateOptions) + createPolicyTemplateOptionsModel.Name = core.StringPtr("testString") + createPolicyTemplateOptionsModel.AccountID = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Policy = templatePolicyModel + createPolicyTemplateOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateOptionsModel.Committed = core.BoolPtr(true) + createPolicyTemplateOptionsModel.AcceptLanguage = core.StringPtr("default") + createPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.CreatePolicyTemplate(createPolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetPolicyTemplate(getPolicyTemplateOptions *GetPolicyTemplateOptions) - Operation response error`, func() { + getPolicyTemplatePath := "/v1/policy_templates/testString" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyTemplatePath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetPolicyTemplate with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyTemplateOptions model + getPolicyTemplateOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateOptions) + getPolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateOptionsModel.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 := iamPolicyManagementService.GetPolicyTemplate(getPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.GetPolicyTemplate(getPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetPolicyTemplate(getPolicyTemplateOptions *GetPolicyTemplateOptions)`, func() { + getPolicyTemplatePath := "/v1/policy_templates/testString" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyTemplatePath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke GetPolicyTemplate successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the GetPolicyTemplateOptions model + getPolicyTemplateOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateOptions) + getPolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.GetPolicyTemplateWithContext(ctx, getPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.GetPolicyTemplate(getPolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.GetPolicyTemplateWithContext(ctx, getPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyTemplatePath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke GetPolicyTemplate successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.GetPolicyTemplate(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetPolicyTemplateOptions model + getPolicyTemplateOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateOptions) + getPolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.GetPolicyTemplate(getPolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetPolicyTemplate with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyTemplateOptions model + getPolicyTemplateOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateOptions) + getPolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.GetPolicyTemplate(getPolicyTemplateOptionsModel) + 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 GetPolicyTemplateOptions model with no property values + getPolicyTemplateOptionsModelNew := new(iampolicymanagementv1.GetPolicyTemplateOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.GetPolicyTemplate(getPolicyTemplateOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetPolicyTemplate successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyTemplateOptions model + getPolicyTemplateOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateOptions) + getPolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.GetPolicyTemplate(getPolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeletePolicyTemplate(deletePolicyTemplateOptions *DeletePolicyTemplateOptions)`, func() { + deletePolicyTemplatePath := "/v1/policy_templates/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deletePolicyTemplatePath)) + Expect(req.Method).To(Equal("DELETE")) + + res.WriteHeader(204) + })) + }) + It(`Invoke DeletePolicyTemplate successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := iamPolicyManagementService.DeletePolicyTemplate(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeletePolicyTemplateOptions model + deletePolicyTemplateOptionsModel := new(iampolicymanagementv1.DeletePolicyTemplateOptions) + deletePolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + deletePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = iamPolicyManagementService.DeletePolicyTemplate(deletePolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeletePolicyTemplate with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the DeletePolicyTemplateOptions model + deletePolicyTemplateOptionsModel := new(iampolicymanagementv1.DeletePolicyTemplateOptions) + deletePolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + deletePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := iamPolicyManagementService.DeletePolicyTemplate(deletePolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeletePolicyTemplateOptions model with no property values + deletePolicyTemplateOptionsModelNew := new(iampolicymanagementv1.DeletePolicyTemplateOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = iamPolicyManagementService.DeletePolicyTemplate(deletePolicyTemplateOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreatePolicyTemplateVersion(createPolicyTemplateVersionOptions *CreatePolicyTemplateVersionOptions) - Operation response error`, func() { + createPolicyTemplateVersionPath := "/v1/policy_templates/testString/versions" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createPolicyTemplateVersionPath)) + Expect(req.Method).To(Equal("POST")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreatePolicyTemplateVersion with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateVersionOptions model + createPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateVersionOptions) + createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel + createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.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 := iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreatePolicyTemplateVersion(createPolicyTemplateVersionOptions *CreatePolicyTemplateVersionOptions)`, func() { + createPolicyTemplateVersionPath := "/v1/policy_templates/testString/versions" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createPolicyTemplateVersionPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke CreatePolicyTemplateVersion successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateVersionOptions model + createPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateVersionOptions) + createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel + createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.CreatePolicyTemplateVersionWithContext(ctx, createPolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.CreatePolicyTemplateVersionWithContext(ctx, createPolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createPolicyTemplateVersionPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke CreatePolicyTemplateVersion successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.CreatePolicyTemplateVersion(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateVersionOptions model + createPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateVersionOptions) + createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel + createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreatePolicyTemplateVersion with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateVersionOptions model + createPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateVersionOptions) + createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel + createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptionsModel) + 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 CreatePolicyTemplateVersionOptions model with no property values + createPolicyTemplateVersionOptionsModelNew := new(iampolicymanagementv1.CreatePolicyTemplateVersionOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(201) + })) + }) + It(`Invoke CreatePolicyTemplateVersion successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the CreatePolicyTemplateVersionOptions model + createPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.CreatePolicyTemplateVersionOptions) + createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel + createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListPolicyTemplateVersions(listPolicyTemplateVersionsOptions *ListPolicyTemplateVersionsOptions) - Operation response error`, func() { + listPolicyTemplateVersionsPath := "/v1/policy_templates/testString/versions" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyTemplateVersionsPath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListPolicyTemplateVersions with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyTemplateVersionsOptions model + listPolicyTemplateVersionsOptionsModel := new(iampolicymanagementv1.ListPolicyTemplateVersionsOptions) + listPolicyTemplateVersionsOptionsModel.PolicyTemplateID = core.StringPtr("testString") + listPolicyTemplateVersionsOptionsModel.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 := iamPolicyManagementService.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListPolicyTemplateVersions(listPolicyTemplateVersionsOptions *ListPolicyTemplateVersionsOptions)`, func() { + listPolicyTemplateVersionsPath := "/v1/policy_templates/testString/versions" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyTemplateVersionsPath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"versions": [{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}]}`) + })) + }) + It(`Invoke ListPolicyTemplateVersions successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the ListPolicyTemplateVersionsOptions model + listPolicyTemplateVersionsOptionsModel := new(iampolicymanagementv1.ListPolicyTemplateVersionsOptions) + listPolicyTemplateVersionsOptionsModel.PolicyTemplateID = core.StringPtr("testString") + listPolicyTemplateVersionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.ListPolicyTemplateVersionsWithContext(ctx, listPolicyTemplateVersionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.ListPolicyTemplateVersionsWithContext(ctx, listPolicyTemplateVersionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyTemplateVersionsPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"versions": [{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}]}`) + })) + }) + It(`Invoke ListPolicyTemplateVersions successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.ListPolicyTemplateVersions(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListPolicyTemplateVersionsOptions model + listPolicyTemplateVersionsOptionsModel := new(iampolicymanagementv1.ListPolicyTemplateVersionsOptions) + listPolicyTemplateVersionsOptionsModel.PolicyTemplateID = core.StringPtr("testString") + listPolicyTemplateVersionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListPolicyTemplateVersions with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyTemplateVersionsOptions model + listPolicyTemplateVersionsOptionsModel := new(iampolicymanagementv1.ListPolicyTemplateVersionsOptions) + listPolicyTemplateVersionsOptionsModel.PolicyTemplateID = core.StringPtr("testString") + listPolicyTemplateVersionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptionsModel) + 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 ListPolicyTemplateVersionsOptions model with no property values + listPolicyTemplateVersionsOptionsModelNew := new(iampolicymanagementv1.ListPolicyTemplateVersionsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListPolicyTemplateVersions successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyTemplateVersionsOptions model + listPolicyTemplateVersionsOptionsModel := new(iampolicymanagementv1.ListPolicyTemplateVersionsOptions) + listPolicyTemplateVersionsOptionsModel.PolicyTemplateID = core.StringPtr("testString") + listPolicyTemplateVersionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ReplacePolicyTemplate(replacePolicyTemplateOptions *ReplacePolicyTemplateOptions) - Operation response error`, func() { + replacePolicyTemplatePath := "/v1/policy_templates/testString/versions/testString" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replacePolicyTemplatePath)) + 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"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ReplacePolicyTemplate with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the ReplacePolicyTemplateOptions model + replacePolicyTemplateOptionsModel := new(iampolicymanagementv1.ReplacePolicyTemplateOptions) + replacePolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Version = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Policy = templatePolicyModel + replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.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 := iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ReplacePolicyTemplate(replacePolicyTemplateOptions *ReplacePolicyTemplateOptions)`, func() { + replacePolicyTemplatePath := "/v1/policy_templates/testString/versions/testString" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replacePolicyTemplatePath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke ReplacePolicyTemplate successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the ReplacePolicyTemplateOptions model + replacePolicyTemplateOptionsModel := new(iampolicymanagementv1.ReplacePolicyTemplateOptions) + replacePolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Version = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Policy = templatePolicyModel + replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.ReplacePolicyTemplateWithContext(ctx, replacePolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.ReplacePolicyTemplateWithContext(ctx, replacePolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replacePolicyTemplatePath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke ReplacePolicyTemplate successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.ReplacePolicyTemplate(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the ReplacePolicyTemplateOptions model + replacePolicyTemplateOptionsModel := new(iampolicymanagementv1.ReplacePolicyTemplateOptions) + replacePolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Version = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Policy = templatePolicyModel + replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ReplacePolicyTemplate with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the ReplacePolicyTemplateOptions model + replacePolicyTemplateOptionsModel := new(iampolicymanagementv1.ReplacePolicyTemplateOptions) + replacePolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Version = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Policy = templatePolicyModel + replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptionsModel) + 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 ReplacePolicyTemplateOptions model with no property values + replacePolicyTemplateOptionsModelNew := new(iampolicymanagementv1.ReplacePolicyTemplateOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ReplacePolicyTemplate successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + rolesModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + controlModel.Grant = grantModel + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + + // Construct an instance of the ReplacePolicyTemplateOptions model + replacePolicyTemplateOptionsModel := new(iampolicymanagementv1.ReplacePolicyTemplateOptions) + replacePolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Version = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Policy = templatePolicyModel + replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions *DeletePolicyTemplateVersionOptions)`, func() { + deletePolicyTemplateVersionPath := "/v1/policy_templates/testString/versions/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deletePolicyTemplateVersionPath)) + Expect(req.Method).To(Equal("DELETE")) + + res.WriteHeader(204) + })) + }) + It(`Invoke DeletePolicyTemplateVersion successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := iamPolicyManagementService.DeletePolicyTemplateVersion(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeletePolicyTemplateVersionOptions model + deletePolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.DeletePolicyTemplateVersionOptions) + deletePolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + deletePolicyTemplateVersionOptionsModel.Version = core.StringPtr("testString") + deletePolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = iamPolicyManagementService.DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeletePolicyTemplateVersion with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the DeletePolicyTemplateVersionOptions model + deletePolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.DeletePolicyTemplateVersionOptions) + deletePolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + deletePolicyTemplateVersionOptionsModel.Version = core.StringPtr("testString") + deletePolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := iamPolicyManagementService.DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeletePolicyTemplateVersionOptions model with no property values + deletePolicyTemplateVersionOptionsModelNew := new(iampolicymanagementv1.DeletePolicyTemplateVersionOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = iamPolicyManagementService.DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetPolicyTemplateVersion(getPolicyTemplateVersionOptions *GetPolicyTemplateVersionOptions) - Operation response error`, func() { + getPolicyTemplateVersionPath := "/v1/policy_templates/testString/versions/testString" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetPolicyTemplateVersion with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyTemplateVersionOptions model + getPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateVersionOptions) + getPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Version = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.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 := iamPolicyManagementService.GetPolicyTemplateVersion(getPolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.GetPolicyTemplateVersion(getPolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetPolicyTemplateVersion(getPolicyTemplateVersionOptions *GetPolicyTemplateVersionOptions)`, func() { + getPolicyTemplateVersionPath := "/v1/policy_templates/testString/versions/testString" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke GetPolicyTemplateVersion successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the GetPolicyTemplateVersionOptions model + getPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateVersionOptions) + getPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Version = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.GetPolicyTemplateVersionWithContext(ctx, getPolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.GetPolicyTemplateVersion(getPolicyTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.GetPolicyTemplateVersionWithContext(ctx, getPolicyTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "policy": {"type": "access", "description": "Description", "resource": {"attributes": [{"key": "Key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "Key", "value": "Value", "operator": "stringEquals"}]}, "pattern": "Pattern", "rule": {"key": "Key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "RoleID"}]}}}, "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + })) + }) + It(`Invoke GetPolicyTemplateVersion successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.GetPolicyTemplateVersion(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetPolicyTemplateVersionOptions model + getPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateVersionOptions) + getPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Version = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.GetPolicyTemplateVersion(getPolicyTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetPolicyTemplateVersion with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyTemplateVersionOptions model + getPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateVersionOptions) + getPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Version = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.GetPolicyTemplateVersion(getPolicyTemplateVersionOptionsModel) + 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 GetPolicyTemplateVersionOptions model with no property values + getPolicyTemplateVersionOptionsModelNew := new(iampolicymanagementv1.GetPolicyTemplateVersionOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.GetPolicyTemplateVersion(getPolicyTemplateVersionOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetPolicyTemplateVersion successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyTemplateVersionOptions model + getPolicyTemplateVersionOptionsModel := new(iampolicymanagementv1.GetPolicyTemplateVersionOptions) + getPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Version = core.StringPtr("testString") + getPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.GetPolicyTemplateVersion(getPolicyTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CommitPolicyTemplate(commitPolicyTemplateOptions *CommitPolicyTemplateOptions)`, func() { + commitPolicyTemplatePath := "/v1/policy_templates/testString/versions/testString/commit" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(commitPolicyTemplatePath)) + Expect(req.Method).To(Equal("POST")) + + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.WriteHeader(204) + })) + }) + It(`Invoke CommitPolicyTemplate successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := iamPolicyManagementService.CommitPolicyTemplate(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the CommitPolicyTemplateOptions model + commitPolicyTemplateOptionsModel := new(iampolicymanagementv1.CommitPolicyTemplateOptions) + commitPolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + commitPolicyTemplateOptionsModel.Version = core.StringPtr("testString") + commitPolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") + commitPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = iamPolicyManagementService.CommitPolicyTemplate(commitPolicyTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke CommitPolicyTemplate with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the CommitPolicyTemplateOptions model + commitPolicyTemplateOptionsModel := new(iampolicymanagementv1.CommitPolicyTemplateOptions) + commitPolicyTemplateOptionsModel.PolicyTemplateID = core.StringPtr("testString") + commitPolicyTemplateOptionsModel.Version = core.StringPtr("testString") + commitPolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") + commitPolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := iamPolicyManagementService.CommitPolicyTemplate(commitPolicyTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the CommitPolicyTemplateOptions model with no property values + commitPolicyTemplateOptionsModelNew := new(iampolicymanagementv1.CommitPolicyTemplateOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = iamPolicyManagementService.CommitPolicyTemplate(commitPolicyTemplateOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListPolicyAssignments(listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions) - Operation response error`, func() { + listPolicyAssignmentsPath := "/v1/policy_assignments" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyAssignmentsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["template_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["template_version"]).To(Equal([]string{"testString"})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListPolicyAssignments with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyAssignmentsOptions model + listPolicyAssignmentsOptionsModel := new(iampolicymanagementv1.ListPolicyAssignmentsOptions) + listPolicyAssignmentsOptionsModel.AccountID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyAssignmentsOptionsModel.TemplateID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.TemplateVersion = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.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 := iamPolicyManagementService.ListPolicyAssignments(listPolicyAssignmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.ListPolicyAssignments(listPolicyAssignmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListPolicyAssignments(listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions)`, func() { + listPolicyAssignmentsPath := "/v1/policy_assignments" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyAssignmentsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["template_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["template_version"]).To(Equal([]string{"testString"})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}]}`) + })) + }) + It(`Invoke ListPolicyAssignments successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the ListPolicyAssignmentsOptions model + listPolicyAssignmentsOptionsModel := new(iampolicymanagementv1.ListPolicyAssignmentsOptions) + listPolicyAssignmentsOptionsModel.AccountID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyAssignmentsOptionsModel.TemplateID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.TemplateVersion = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.ListPolicyAssignmentsWithContext(ctx, listPolicyAssignmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.ListPolicyAssignments(listPolicyAssignmentsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.ListPolicyAssignmentsWithContext(ctx, listPolicyAssignmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listPolicyAssignmentsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Accept-Language"]).ToNot(BeNil()) + Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "default"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["template_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["template_version"]).To(Equal([]string{"testString"})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}]}`) + })) + }) + It(`Invoke ListPolicyAssignments successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.ListPolicyAssignments(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListPolicyAssignmentsOptions model + listPolicyAssignmentsOptionsModel := new(iampolicymanagementv1.ListPolicyAssignmentsOptions) + listPolicyAssignmentsOptionsModel.AccountID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyAssignmentsOptionsModel.TemplateID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.TemplateVersion = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.ListPolicyAssignments(listPolicyAssignmentsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListPolicyAssignments with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyAssignmentsOptions model + listPolicyAssignmentsOptionsModel := new(iampolicymanagementv1.ListPolicyAssignmentsOptions) + listPolicyAssignmentsOptionsModel.AccountID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyAssignmentsOptionsModel.TemplateID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.TemplateVersion = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.ListPolicyAssignments(listPolicyAssignmentsOptionsModel) + 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 ListPolicyAssignmentsOptions model with no property values + listPolicyAssignmentsOptionsModelNew := new(iampolicymanagementv1.ListPolicyAssignmentsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.ListPolicyAssignments(listPolicyAssignmentsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListPolicyAssignments successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the ListPolicyAssignmentsOptions model + listPolicyAssignmentsOptionsModel := new(iampolicymanagementv1.ListPolicyAssignmentsOptions) + listPolicyAssignmentsOptionsModel.AccountID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.AcceptLanguage = core.StringPtr("default") + listPolicyAssignmentsOptionsModel.TemplateID = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.TemplateVersion = core.StringPtr("testString") + listPolicyAssignmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.ListPolicyAssignments(listPolicyAssignmentsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetPolicyAssignment(getPolicyAssignmentOptions *GetPolicyAssignmentOptions) - Operation response error`, func() { + getPolicyAssignmentPath := "/v1/policy_assignments/testString" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyAssignmentPath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetPolicyAssignment with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyAssignmentOptions model + getPolicyAssignmentOptionsModel := new(iampolicymanagementv1.GetPolicyAssignmentOptions) + getPolicyAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getPolicyAssignmentOptionsModel.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 := iamPolicyManagementService.GetPolicyAssignment(getPolicyAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.GetPolicyAssignment(getPolicyAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetPolicyAssignment(getPolicyAssignmentOptions *GetPolicyAssignmentOptions)`, func() { + getPolicyAssignmentPath := "/v1/policy_assignments/testString" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyAssignmentPath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}`) + })) + }) + It(`Invoke GetPolicyAssignment successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the GetPolicyAssignmentOptions model + getPolicyAssignmentOptionsModel := new(iampolicymanagementv1.GetPolicyAssignmentOptions) + getPolicyAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getPolicyAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.GetPolicyAssignmentWithContext(ctx, getPolicyAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.GetPolicyAssignment(getPolicyAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.GetPolicyAssignmentWithContext(ctx, getPolicyAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPolicyAssignmentPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}`) + })) + }) + It(`Invoke GetPolicyAssignment successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.GetPolicyAssignment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetPolicyAssignmentOptions model + getPolicyAssignmentOptionsModel := new(iampolicymanagementv1.GetPolicyAssignmentOptions) + getPolicyAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getPolicyAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.GetPolicyAssignment(getPolicyAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetPolicyAssignment with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyAssignmentOptions model + getPolicyAssignmentOptionsModel := new(iampolicymanagementv1.GetPolicyAssignmentOptions) + getPolicyAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getPolicyAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.GetPolicyAssignment(getPolicyAssignmentOptionsModel) + 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 GetPolicyAssignmentOptions model with no property values + getPolicyAssignmentOptionsModelNew := new(iampolicymanagementv1.GetPolicyAssignmentOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.GetPolicyAssignment(getPolicyAssignmentOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetPolicyAssignment successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the GetPolicyAssignmentOptions model + getPolicyAssignmentOptionsModel := new(iampolicymanagementv1.GetPolicyAssignmentOptions) + getPolicyAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getPolicyAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamPolicyManagementService.GetPolicyAssignment(getPolicyAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`Model constructor tests`, func() { Context(`Using a service client instance`, func() { iamPolicyManagementService, _ := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ URL: "http://iampolicymanagementv1modelgenerator.com", Authenticator: &core.NoAuthAuthenticator{}, }) + It(`Invoke NewCommitPolicyTemplateOptions successfully`, func() { + // Construct an instance of the CommitPolicyTemplateOptions model + policyTemplateID := "testString" + version := "testString" + ifMatch := "testString" + commitPolicyTemplateOptionsModel := iamPolicyManagementService.NewCommitPolicyTemplateOptions(policyTemplateID, version, ifMatch) + commitPolicyTemplateOptionsModel.SetPolicyTemplateID("testString") + commitPolicyTemplateOptionsModel.SetVersion("testString") + commitPolicyTemplateOptionsModel.SetIfMatch("testString") + commitPolicyTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(commitPolicyTemplateOptionsModel).ToNot(BeNil()) + Expect(commitPolicyTemplateOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) + Expect(commitPolicyTemplateOptionsModel.Version).To(Equal(core.StringPtr("testString"))) + Expect(commitPolicyTemplateOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) + Expect(commitPolicyTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewControl successfully`, func() { var grant *iampolicymanagementv1.Grant = nil _, err := iamPolicyManagementService.NewControl(grant) @@ -4630,6 +7638,187 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(createPolicyOptionsModel.AcceptLanguage).To(Equal(core.StringPtr("default"))) Expect(createPolicyOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewCreatePolicyTemplateOptions successfully`, func() { + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + Expect(v2PolicyResourceAttributeModel).ToNot(BeNil()) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + Expect(v2PolicyResourceAttributeModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceAttributeModel.Operator).To(Equal(core.StringPtr("stringEquals"))) + Expect(v2PolicyResourceAttributeModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + Expect(v2PolicyResourceTagModel).ToNot(BeNil()) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + Expect(v2PolicyResourceTagModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceTagModel.Value).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceTagModel.Operator).To(Equal(core.StringPtr("stringEquals"))) + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + Expect(v2PolicyResourceModel).ToNot(BeNil()) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + Expect(v2PolicyResourceModel.Attributes).To(Equal([]iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel})) + Expect(v2PolicyResourceModel.Tags).To(Equal([]iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel})) + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + Expect(v2PolicyRuleModel).ToNot(BeNil()) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + Expect(v2PolicyRuleModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyRuleModel.Operator).To(Equal(core.StringPtr("timeLessThan"))) + Expect(v2PolicyRuleModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + Expect(rolesModel).ToNot(BeNil()) + rolesModel.RoleID = core.StringPtr("testString") + Expect(rolesModel.RoleID).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + Expect(grantModel).ToNot(BeNil()) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + Expect(grantModel.Roles).To(Equal([]iampolicymanagementv1.Roles{*rolesModel})) + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + Expect(controlModel).ToNot(BeNil()) + controlModel.Grant = grantModel + Expect(controlModel.Grant).To(Equal(grantModel)) + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + Expect(templatePolicyModel).ToNot(BeNil()) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + Expect(templatePolicyModel.Type).To(Equal(core.StringPtr("access"))) + Expect(templatePolicyModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(templatePolicyModel.Resource).To(Equal(v2PolicyResourceModel)) + Expect(templatePolicyModel.Pattern).To(Equal(core.StringPtr("testString"))) + Expect(templatePolicyModel.Rule).To(Equal(v2PolicyRuleModel)) + Expect(templatePolicyModel.Control).To(Equal(controlModel)) + + // Construct an instance of the CreatePolicyTemplateOptions model + createPolicyTemplateOptionsName := "testString" + createPolicyTemplateOptionsAccountID := "testString" + var createPolicyTemplateOptionsPolicy *iampolicymanagementv1.TemplatePolicy = nil + createPolicyTemplateOptionsModel := iamPolicyManagementService.NewCreatePolicyTemplateOptions(createPolicyTemplateOptionsName, createPolicyTemplateOptionsAccountID, createPolicyTemplateOptionsPolicy) + createPolicyTemplateOptionsModel.SetName("testString") + createPolicyTemplateOptionsModel.SetAccountID("testString") + createPolicyTemplateOptionsModel.SetPolicy(templatePolicyModel) + createPolicyTemplateOptionsModel.SetDescription("testString") + createPolicyTemplateOptionsModel.SetCommitted(true) + createPolicyTemplateOptionsModel.SetAcceptLanguage("default") + createPolicyTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createPolicyTemplateOptionsModel).ToNot(BeNil()) + Expect(createPolicyTemplateOptionsModel.Name).To(Equal(core.StringPtr("testString"))) + Expect(createPolicyTemplateOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) + Expect(createPolicyTemplateOptionsModel.Policy).To(Equal(templatePolicyModel)) + Expect(createPolicyTemplateOptionsModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(createPolicyTemplateOptionsModel.Committed).To(Equal(core.BoolPtr(true))) + Expect(createPolicyTemplateOptionsModel.AcceptLanguage).To(Equal(core.StringPtr("default"))) + Expect(createPolicyTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewCreatePolicyTemplateVersionOptions successfully`, func() { + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + Expect(v2PolicyResourceAttributeModel).ToNot(BeNil()) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + Expect(v2PolicyResourceAttributeModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceAttributeModel.Operator).To(Equal(core.StringPtr("stringEquals"))) + Expect(v2PolicyResourceAttributeModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + Expect(v2PolicyResourceTagModel).ToNot(BeNil()) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + Expect(v2PolicyResourceTagModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceTagModel.Value).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceTagModel.Operator).To(Equal(core.StringPtr("stringEquals"))) + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + Expect(v2PolicyResourceModel).ToNot(BeNil()) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + Expect(v2PolicyResourceModel.Attributes).To(Equal([]iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel})) + Expect(v2PolicyResourceModel.Tags).To(Equal([]iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel})) + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + Expect(v2PolicyRuleModel).ToNot(BeNil()) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + Expect(v2PolicyRuleModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyRuleModel.Operator).To(Equal(core.StringPtr("timeLessThan"))) + Expect(v2PolicyRuleModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + Expect(rolesModel).ToNot(BeNil()) + rolesModel.RoleID = core.StringPtr("testString") + Expect(rolesModel.RoleID).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + Expect(grantModel).ToNot(BeNil()) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + Expect(grantModel.Roles).To(Equal([]iampolicymanagementv1.Roles{*rolesModel})) + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + Expect(controlModel).ToNot(BeNil()) + controlModel.Grant = grantModel + Expect(controlModel.Grant).To(Equal(grantModel)) + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + Expect(templatePolicyModel).ToNot(BeNil()) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + Expect(templatePolicyModel.Type).To(Equal(core.StringPtr("access"))) + Expect(templatePolicyModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(templatePolicyModel.Resource).To(Equal(v2PolicyResourceModel)) + Expect(templatePolicyModel.Pattern).To(Equal(core.StringPtr("testString"))) + Expect(templatePolicyModel.Rule).To(Equal(v2PolicyRuleModel)) + Expect(templatePolicyModel.Control).To(Equal(controlModel)) + + // Construct an instance of the CreatePolicyTemplateVersionOptions model + policyTemplateID := "testString" + var createPolicyTemplateVersionOptionsPolicy *iampolicymanagementv1.TemplatePolicy = nil + createPolicyTemplateVersionOptionsModel := iamPolicyManagementService.NewCreatePolicyTemplateVersionOptions(policyTemplateID, createPolicyTemplateVersionOptionsPolicy) + createPolicyTemplateVersionOptionsModel.SetPolicyTemplateID("testString") + createPolicyTemplateVersionOptionsModel.SetPolicy(templatePolicyModel) + createPolicyTemplateVersionOptionsModel.SetDescription("testString") + createPolicyTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createPolicyTemplateVersionOptionsModel).ToNot(BeNil()) + Expect(createPolicyTemplateVersionOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) + Expect(createPolicyTemplateVersionOptionsModel.Policy).To(Equal(templatePolicyModel)) + Expect(createPolicyTemplateVersionOptionsModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(createPolicyTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewCreateRoleOptions successfully`, func() { // Construct an instance of the CreateRoleOptions model createRoleOptionsDisplayName := "testString" @@ -4763,6 +7952,29 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(deletePolicyOptionsModel.PolicyID).To(Equal(core.StringPtr("testString"))) Expect(deletePolicyOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewDeletePolicyTemplateOptions successfully`, func() { + // Construct an instance of the DeletePolicyTemplateOptions model + policyTemplateID := "testString" + deletePolicyTemplateOptionsModel := iamPolicyManagementService.NewDeletePolicyTemplateOptions(policyTemplateID) + deletePolicyTemplateOptionsModel.SetPolicyTemplateID("testString") + deletePolicyTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deletePolicyTemplateOptionsModel).ToNot(BeNil()) + Expect(deletePolicyTemplateOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) + Expect(deletePolicyTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeletePolicyTemplateVersionOptions successfully`, func() { + // Construct an instance of the DeletePolicyTemplateVersionOptions model + policyTemplateID := "testString" + version := "testString" + deletePolicyTemplateVersionOptionsModel := iamPolicyManagementService.NewDeletePolicyTemplateVersionOptions(policyTemplateID, version) + deletePolicyTemplateVersionOptionsModel.SetPolicyTemplateID("testString") + deletePolicyTemplateVersionOptionsModel.SetVersion("testString") + deletePolicyTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deletePolicyTemplateVersionOptionsModel).ToNot(BeNil()) + Expect(deletePolicyTemplateVersionOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) + Expect(deletePolicyTemplateVersionOptionsModel.Version).To(Equal(core.StringPtr("testString"))) + Expect(deletePolicyTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewDeleteRoleOptions successfully`, func() { // Construct an instance of the DeleteRoleOptions model roleID := "testString" @@ -4783,6 +7995,16 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(deleteV2PolicyOptionsModel.ID).To(Equal(core.StringPtr("testString"))) Expect(deleteV2PolicyOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewGetPolicyAssignmentOptions successfully`, func() { + // Construct an instance of the GetPolicyAssignmentOptions model + assignmentID := "testString" + getPolicyAssignmentOptionsModel := iamPolicyManagementService.NewGetPolicyAssignmentOptions(assignmentID) + getPolicyAssignmentOptionsModel.SetAssignmentID("testString") + getPolicyAssignmentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getPolicyAssignmentOptionsModel).ToNot(BeNil()) + Expect(getPolicyAssignmentOptionsModel.AssignmentID).To(Equal(core.StringPtr("testString"))) + Expect(getPolicyAssignmentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewGetPolicyOptions successfully`, func() { // Construct an instance of the GetPolicyOptions model policyID := "testString" @@ -4793,6 +8015,29 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(getPolicyOptionsModel.PolicyID).To(Equal(core.StringPtr("testString"))) Expect(getPolicyOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewGetPolicyTemplateOptions successfully`, func() { + // Construct an instance of the GetPolicyTemplateOptions model + policyTemplateID := "testString" + getPolicyTemplateOptionsModel := iamPolicyManagementService.NewGetPolicyTemplateOptions(policyTemplateID) + getPolicyTemplateOptionsModel.SetPolicyTemplateID("testString") + getPolicyTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getPolicyTemplateOptionsModel).ToNot(BeNil()) + Expect(getPolicyTemplateOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) + Expect(getPolicyTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetPolicyTemplateVersionOptions successfully`, func() { + // Construct an instance of the GetPolicyTemplateVersionOptions model + policyTemplateID := "testString" + version := "testString" + getPolicyTemplateVersionOptionsModel := iamPolicyManagementService.NewGetPolicyTemplateVersionOptions(policyTemplateID, version) + getPolicyTemplateVersionOptionsModel.SetPolicyTemplateID("testString") + getPolicyTemplateVersionOptionsModel.SetVersion("testString") + getPolicyTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getPolicyTemplateVersionOptionsModel).ToNot(BeNil()) + Expect(getPolicyTemplateVersionOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) + Expect(getPolicyTemplateVersionOptionsModel.Version).To(Equal(core.StringPtr("testString"))) + Expect(getPolicyTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewGetRoleOptions successfully`, func() { // Construct an instance of the GetRoleOptions model roleID := "testString" @@ -4851,6 +8096,44 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(listPoliciesOptionsModel.State).To(Equal(core.StringPtr("active"))) Expect(listPoliciesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewListPolicyAssignmentsOptions successfully`, func() { + // Construct an instance of the ListPolicyAssignmentsOptions model + accountID := "testString" + listPolicyAssignmentsOptionsModel := iamPolicyManagementService.NewListPolicyAssignmentsOptions(accountID) + listPolicyAssignmentsOptionsModel.SetAccountID("testString") + listPolicyAssignmentsOptionsModel.SetAcceptLanguage("default") + listPolicyAssignmentsOptionsModel.SetTemplateID("testString") + listPolicyAssignmentsOptionsModel.SetTemplateVersion("testString") + listPolicyAssignmentsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listPolicyAssignmentsOptionsModel).ToNot(BeNil()) + Expect(listPolicyAssignmentsOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) + Expect(listPolicyAssignmentsOptionsModel.AcceptLanguage).To(Equal(core.StringPtr("default"))) + Expect(listPolicyAssignmentsOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(listPolicyAssignmentsOptionsModel.TemplateVersion).To(Equal(core.StringPtr("testString"))) + Expect(listPolicyAssignmentsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListPolicyTemplateVersionsOptions successfully`, func() { + // Construct an instance of the ListPolicyTemplateVersionsOptions model + policyTemplateID := "testString" + listPolicyTemplateVersionsOptionsModel := iamPolicyManagementService.NewListPolicyTemplateVersionsOptions(policyTemplateID) + listPolicyTemplateVersionsOptionsModel.SetPolicyTemplateID("testString") + listPolicyTemplateVersionsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listPolicyTemplateVersionsOptionsModel).ToNot(BeNil()) + Expect(listPolicyTemplateVersionsOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) + Expect(listPolicyTemplateVersionsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListPolicyTemplatesOptions successfully`, func() { + // Construct an instance of the ListPolicyTemplatesOptions model + accountID := "testString" + listPolicyTemplatesOptionsModel := iamPolicyManagementService.NewListPolicyTemplatesOptions(accountID) + listPolicyTemplatesOptionsModel.SetAccountID("testString") + listPolicyTemplatesOptionsModel.SetAcceptLanguage("default") + listPolicyTemplatesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listPolicyTemplatesOptionsModel).ToNot(BeNil()) + Expect(listPolicyTemplatesOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) + Expect(listPolicyTemplatesOptionsModel.AcceptLanguage).To(Equal(core.StringPtr("default"))) + Expect(listPolicyTemplatesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewListRolesOptions successfully`, func() { // Construct an instance of the ListRolesOptions model listRolesOptionsModel := iamPolicyManagementService.NewListRolesOptions() @@ -4981,6 +8264,99 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(replacePolicyOptionsModel.Description).To(Equal(core.StringPtr("testString"))) Expect(replacePolicyOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewReplacePolicyTemplateOptions successfully`, func() { + // Construct an instance of the V2PolicyResourceAttribute model + v2PolicyResourceAttributeModel := new(iampolicymanagementv1.V2PolicyResourceAttribute) + Expect(v2PolicyResourceAttributeModel).ToNot(BeNil()) + v2PolicyResourceAttributeModel.Key = core.StringPtr("testString") + v2PolicyResourceAttributeModel.Operator = core.StringPtr("stringEquals") + v2PolicyResourceAttributeModel.Value = core.StringPtr("testString") + Expect(v2PolicyResourceAttributeModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceAttributeModel.Operator).To(Equal(core.StringPtr("stringEquals"))) + Expect(v2PolicyResourceAttributeModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the V2PolicyResourceTag model + v2PolicyResourceTagModel := new(iampolicymanagementv1.V2PolicyResourceTag) + Expect(v2PolicyResourceTagModel).ToNot(BeNil()) + v2PolicyResourceTagModel.Key = core.StringPtr("testString") + v2PolicyResourceTagModel.Value = core.StringPtr("testString") + v2PolicyResourceTagModel.Operator = core.StringPtr("stringEquals") + Expect(v2PolicyResourceTagModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceTagModel.Value).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyResourceTagModel.Operator).To(Equal(core.StringPtr("stringEquals"))) + + // Construct an instance of the V2PolicyResource model + v2PolicyResourceModel := new(iampolicymanagementv1.V2PolicyResource) + Expect(v2PolicyResourceModel).ToNot(BeNil()) + v2PolicyResourceModel.Attributes = []iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel} + v2PolicyResourceModel.Tags = []iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel} + Expect(v2PolicyResourceModel.Attributes).To(Equal([]iampolicymanagementv1.V2PolicyResourceAttribute{*v2PolicyResourceAttributeModel})) + Expect(v2PolicyResourceModel.Tags).To(Equal([]iampolicymanagementv1.V2PolicyResourceTag{*v2PolicyResourceTagModel})) + + // Construct an instance of the V2PolicyRuleRuleAttribute model + v2PolicyRuleModel := new(iampolicymanagementv1.V2PolicyRuleRuleAttribute) + Expect(v2PolicyRuleModel).ToNot(BeNil()) + v2PolicyRuleModel.Key = core.StringPtr("testString") + v2PolicyRuleModel.Operator = core.StringPtr("timeLessThan") + v2PolicyRuleModel.Value = core.StringPtr("testString") + Expect(v2PolicyRuleModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(v2PolicyRuleModel.Operator).To(Equal(core.StringPtr("timeLessThan"))) + Expect(v2PolicyRuleModel.Value).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the Roles model + rolesModel := new(iampolicymanagementv1.Roles) + Expect(rolesModel).ToNot(BeNil()) + rolesModel.RoleID = core.StringPtr("testString") + Expect(rolesModel.RoleID).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the Grant model + grantModel := new(iampolicymanagementv1.Grant) + Expect(grantModel).ToNot(BeNil()) + grantModel.Roles = []iampolicymanagementv1.Roles{*rolesModel} + Expect(grantModel.Roles).To(Equal([]iampolicymanagementv1.Roles{*rolesModel})) + + // Construct an instance of the Control model + controlModel := new(iampolicymanagementv1.Control) + Expect(controlModel).ToNot(BeNil()) + controlModel.Grant = grantModel + Expect(controlModel.Grant).To(Equal(grantModel)) + + // Construct an instance of the TemplatePolicy model + templatePolicyModel := new(iampolicymanagementv1.TemplatePolicy) + Expect(templatePolicyModel).ToNot(BeNil()) + templatePolicyModel.Type = core.StringPtr("access") + templatePolicyModel.Description = core.StringPtr("testString") + templatePolicyModel.Resource = v2PolicyResourceModel + templatePolicyModel.Pattern = core.StringPtr("testString") + templatePolicyModel.Rule = v2PolicyRuleModel + templatePolicyModel.Control = controlModel + Expect(templatePolicyModel.Type).To(Equal(core.StringPtr("access"))) + Expect(templatePolicyModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(templatePolicyModel.Resource).To(Equal(v2PolicyResourceModel)) + Expect(templatePolicyModel.Pattern).To(Equal(core.StringPtr("testString"))) + Expect(templatePolicyModel.Rule).To(Equal(v2PolicyRuleModel)) + Expect(templatePolicyModel.Control).To(Equal(controlModel)) + + // Construct an instance of the ReplacePolicyTemplateOptions model + policyTemplateID := "testString" + version := "testString" + ifMatch := "testString" + var replacePolicyTemplateOptionsPolicy *iampolicymanagementv1.TemplatePolicy = nil + replacePolicyTemplateOptionsModel := iamPolicyManagementService.NewReplacePolicyTemplateOptions(policyTemplateID, version, ifMatch, replacePolicyTemplateOptionsPolicy) + replacePolicyTemplateOptionsModel.SetPolicyTemplateID("testString") + replacePolicyTemplateOptionsModel.SetVersion("testString") + replacePolicyTemplateOptionsModel.SetIfMatch("testString") + replacePolicyTemplateOptionsModel.SetPolicy(templatePolicyModel) + replacePolicyTemplateOptionsModel.SetDescription("testString") + replacePolicyTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(replacePolicyTemplateOptionsModel).ToNot(BeNil()) + Expect(replacePolicyTemplateOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) + Expect(replacePolicyTemplateOptionsModel.Version).To(Equal(core.StringPtr("testString"))) + Expect(replacePolicyTemplateOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) + Expect(replacePolicyTemplateOptionsModel.Policy).To(Equal(templatePolicyModel)) + Expect(replacePolicyTemplateOptionsModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(replacePolicyTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewReplaceRoleOptions successfully`, func() { // Construct an instance of the ReplaceRoleOptions model roleID := "testString" @@ -5117,6 +8493,13 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(_model).ToNot(BeNil()) Expect(err).To(BeNil()) }) + It(`Invoke NewTemplatePolicy successfully`, func() { + typeVar := "access" + var resource *iampolicymanagementv1.V2PolicyResource = nil + var control *iampolicymanagementv1.Control = nil + _, err := iamPolicyManagementService.NewTemplatePolicy(typeVar, resource, control) + Expect(err).ToNot(BeNil()) + }) It(`Invoke NewUpdatePolicyStateOptions successfully`, func() { // Construct an instance of the UpdatePolicyStateOptions model policyID := "testString" From 685c8f644575eb2e9629438a8cb5ad66320cb387 Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Fri, 19 May 2023 14:57:38 +0530 Subject: [PATCH 2/9] feat(IAM Policy Management): policy assignment test update Signed-off-by: Vivek.Jain3 --- iampolicymanagementv1/iam_policy_management_v1.go | 4 ++-- iampolicymanagementv1/iam_policy_management_v1_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1.go b/iampolicymanagementv1/iam_policy_management_v1.go index b5ec4351..f6914568 100644 --- a/iampolicymanagementv1/iam_policy_management_v1.go +++ b/iampolicymanagementv1/iam_policy_management_v1.go @@ -3856,13 +3856,13 @@ func (options *ListV2PoliciesOptions) SetHeaders(param map[string]string) *ListV // PolcyTemplateAssignmentCollection : A collection of policies assignments. type PolcyTemplateAssignmentCollection struct { // List of policy assignments. - Assignments []PolicyAssignmentRecord `json:"assignments,omitempty"` + PolicyAssignments []PolicyAssignmentRecord `json:"policy_assignments,omitempty"` } // UnmarshalPolcyTemplateAssignmentCollection unmarshals an instance of PolcyTemplateAssignmentCollection from the specified map of raw messages. func UnmarshalPolcyTemplateAssignmentCollection(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PolcyTemplateAssignmentCollection) - err = core.UnmarshalModel(m, "assignments", &obj.Assignments, UnmarshalPolicyAssignmentRecord) + err = core.UnmarshalModel(m, "policy_assignments", &obj.PolicyAssignments, UnmarshalPolicyAssignmentRecord) if err != nil { return } diff --git a/iampolicymanagementv1/iam_policy_management_v1_test.go b/iampolicymanagementv1/iam_policy_management_v1_test.go index 8ce9c5ad..f7c92937 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_test.go @@ -7161,7 +7161,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}]}`) + fmt.Fprintf(res, "%s", `{"policy_assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}]}`) })) }) It(`Invoke ListPolicyAssignments successfully with retries`, func() { @@ -7223,7 +7223,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}]}`) + fmt.Fprintf(res, "%s", `{"policy_assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}]}`) })) }) It(`Invoke ListPolicyAssignments successfully`, func() { From 2a3fd59206a89bdea75be869562e2cbb04ba95a0 Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Mon, 22 May 2023 17:24:59 +0530 Subject: [PATCH 3/9] feat(IAM Policy Management): regenerate sdk after yaml update Signed-off-by: Vivek.Jain3 --- iampolicymanagementv1/iam_policy_management_v1.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1.go b/iampolicymanagementv1/iam_policy_management_v1.go index f6914568..0e149eaf 100644 --- a/iampolicymanagementv1/iam_policy_management_v1.go +++ b/iampolicymanagementv1/iam_policy_management_v1.go @@ -4089,7 +4089,7 @@ type PolicyTemplate struct { Version *string `json:"version" validate:"required"` // Template vesrsion committed status. - Committed *bool `json:"committed" validate:"required"` + Committed *bool `json:"committed,omitempty"` // The core set of properties associated with the template's policy objet. Policy *TemplatePolicy `json:"policy" validate:"required"` From 1d30ad4b7cc3faf735228a6d7780ab93f76e28e7 Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Tue, 23 May 2023 14:20:39 +0530 Subject: [PATCH 4/9] feat(IAM Policy Management): regenerate sdk after yaml update, test added for PolicyAssignment by id Signed-off-by: Vivek.Jain3 --- .../iam_policy_management_v1.go | 98 ++++++++++++++++--- .../iam_policy_management_v1_examples_test.go | 55 ++++++++++- .../iam_policy_management_v1_test.go | 8 +- 3 files changed, 140 insertions(+), 21 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1.go b/iampolicymanagementv1/iam_policy_management_v1.go index 0e149eaf..c81a9271 100644 --- a/iampolicymanagementv1/iam_policy_management_v1.go +++ b/iampolicymanagementv1/iam_policy_management_v1.go @@ -3870,6 +3870,58 @@ func UnmarshalPolcyTemplateAssignmentCollection(m map[string]json.RawMessage, re return } +// PolicyAssignmentOptions : The set of properties required for a policy assignment. +type PolicyAssignmentOptions struct { + // The policy subject type; either 'iam_id' or 'access_group_id'. + SubjectType *string `json:"subject_type" validate:"required"` + + // The policy subject id. + SubjectID *string `json:"subject_id" validate:"required"` + + // The policy assignment requester id. + RootRequesterID *string `json:"root_requester_id" validate:"required"` + + // The template id where this policy is being assigned from. + RootTemplateID *string `json:"root_template_id,omitempty"` + + // The template version where this policy is being assigned from. + RootTemplateVersion *string `json:"root_template_version,omitempty"` +} + +// Constants associated with the PolicyAssignmentOptions.SubjectType property. +// The policy subject type; either 'iam_id' or 'access_group_id'. +const ( + PolicyAssignmentOptionsSubjectTypeAccessGroupIDConst = "access_group_id" + PolicyAssignmentOptionsSubjectTypeIamIDConst = "iam_id" +) + +// UnmarshalPolicyAssignmentOptions unmarshals an instance of PolicyAssignmentOptions from the specified map of raw messages. +func UnmarshalPolicyAssignmentOptions(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyAssignmentOptions) + err = core.UnmarshalPrimitive(m, "subject_type", &obj.SubjectType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "subject_id", &obj.SubjectID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "root_requester_id", &obj.RootRequesterID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "root_template_id", &obj.RootTemplateID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "root_template_version", &obj.RootTemplateVersion) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // PolicyAssignmentRecord : The set of properties associated with the policy template assignment. type PolicyAssignmentRecord struct { // policy template id. @@ -3890,6 +3942,9 @@ type PolicyAssignmentRecord struct { // Policy assignment ID. ID *string `json:"id,omitempty"` + // The account GUID that the policies assignments belong to.. + AccountID *string `json:"account_id,omitempty"` + // The href URL that links to the policies assignments API by policy assignment ID. Href *string `json:"href,omitempty"` @@ -3905,8 +3960,14 @@ type PolicyAssignmentRecord struct { // The iam ID of the entity that last modified the policy assignment. LastModifiedByID *string `json:"last_modified_by_id,omitempty"` + // Object for each properties for a policy assignment. + Options []PolicyAssignmentOptions `json:"options,omitempty"` + // Object for each account assigned. Resources []PolicyAssignmentResources `json:"resources,omitempty"` + + // The policy assignment status. + Status *string `json:"status" validate:"required"` } // Constants associated with the PolicyAssignmentRecord.TargetType property. @@ -3915,6 +3976,15 @@ const ( PolicyAssignmentRecordTargetTypeAccountConst = "Account" ) +// Constants associated with the PolicyAssignmentRecord.Status property. +// The policy assignment status. +const ( + PolicyAssignmentRecordStatusFailedConst = "failed" + PolicyAssignmentRecordStatusInProgressConst = "in_progress" + PolicyAssignmentRecordStatusSucceedWithErrorsConst = "succeed_with_errors" + PolicyAssignmentRecordStatusSucceededConst = "succeeded" +) + // UnmarshalPolicyAssignmentRecord unmarshals an instance of PolicyAssignmentRecord from the specified map of raw messages. func UnmarshalPolicyAssignmentRecord(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PolicyAssignmentRecord) @@ -3942,6 +4012,10 @@ func UnmarshalPolicyAssignmentRecord(m map[string]json.RawMessage, result interf if err != nil { return } + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } err = core.UnmarshalPrimitive(m, "href", &obj.Href) if err != nil { return @@ -3962,10 +4036,18 @@ func UnmarshalPolicyAssignmentRecord(m map[string]json.RawMessage, result interf if err != nil { return } + err = core.UnmarshalModel(m, "options", &obj.Options, UnmarshalPolicyAssignmentOptions) + if err != nil { + return + } err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalPolicyAssignmentResources) if err != nil { return } + err = core.UnmarshalPrimitive(m, "status", &obj.Status) + if err != nil { + return + } reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) return } @@ -4001,20 +4083,8 @@ type PolicyAssignmentResourcesPolicy struct { // The error response from API. ErrorMessage *ErrorResponse `json:"error_message,omitempty"` - - // The policy assignment status. - Status *string `json:"status" validate:"required"` } -// Constants associated with the PolicyAssignmentResourcesPolicy.Status property. -// The policy assignment status. -const ( - PolicyAssignmentResourcesPolicyStatusFailedConst = "failed" - PolicyAssignmentResourcesPolicyStatusInProgressConst = "in_progress" - PolicyAssignmentResourcesPolicyStatusSucceedWithErrorsConst = "succeed_with_errors" - PolicyAssignmentResourcesPolicyStatusSucceededConst = "succeeded" -) - // UnmarshalPolicyAssignmentResourcesPolicy unmarshals an instance of PolicyAssignmentResourcesPolicy from the specified map of raw messages. func UnmarshalPolicyAssignmentResourcesPolicy(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PolicyAssignmentResourcesPolicy) @@ -4026,10 +4096,6 @@ func UnmarshalPolicyAssignmentResourcesPolicy(m map[string]json.RawMessage, resu if err != nil { return } - err = core.UnmarshalPrimitive(m, "status", &obj.Status) - if err != nil { - return - } reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) return } diff --git a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go index 99746112..7fd4c988 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go @@ -67,6 +67,8 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { examplePolicyTemplateID string examplePolicyTemplateETag string examplePolicyTemplateVersion string + // change testPolicyAssignmentId id after prod account setup + testPolicyAssignmentId = "442c6fc4-2f74-41b2-bf4d-98342614cd22" ) var shouldSkipTest = func() { @@ -774,7 +776,7 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { Expect(response.StatusCode).To(Equal(200)) Expect(policyTemplate).ToNot(BeNil()) - // examplePolicyTemplateETag = response.GetHeaders().Get("ETag") + examplePolicyTemplateETag = response.GetHeaders().Get("ETag") }) @@ -974,6 +976,57 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(polcyTemplateAssignmentCollection).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TemplateID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TargetType).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TemplateVersion).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Target).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].AssignmentID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Options).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Status).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].AccountID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Resources).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].CreatedAt).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].CreatedByID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedAt).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedByID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Href).ToNot(BeNil()) + }) + + It(`GetPolicyAssignment request example`, func() { + fmt.Println("\nGetPolicyAssignment() result:") + // begin-get_policy_assignment + + getPolicyAssignmentOptions := iamPolicyManagementService.NewGetPolicyAssignmentOptions( + testPolicyAssignmentId, + ) + + policyAssignmentRecord, response, err := iamPolicyManagementService.GetPolicyAssignment(getPolicyAssignmentOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policyAssignmentRecord, "", " ") + fmt.Println(string(b)) + + // end-get_policy_assignment + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyAssignmentRecord).ToNot(BeNil()) + Expect(policyAssignmentRecord.TemplateID).ToNot(BeNil()) + Expect(policyAssignmentRecord.TargetType).ToNot(BeNil()) + Expect(policyAssignmentRecord.TemplateVersion).ToNot(BeNil()) + Expect(policyAssignmentRecord.Target).ToNot(BeNil()) + Expect(policyAssignmentRecord.AssignmentID).ToNot(BeNil()) + Expect(policyAssignmentRecord.Options).ToNot(BeNil()) + Expect(policyAssignmentRecord.Status).ToNot(BeNil()) + Expect(policyAssignmentRecord.AccountID).ToNot(BeNil()) + Expect(policyAssignmentRecord.Resources).ToNot(BeNil()) + Expect(policyAssignmentRecord.CreatedAt).ToNot(BeNil()) + Expect(policyAssignmentRecord.CreatedByID).ToNot(BeNil()) + Expect(policyAssignmentRecord.LastModifiedAt).ToNot(BeNil()) + Expect(policyAssignmentRecord.LastModifiedByID).ToNot(BeNil()) + Expect(policyAssignmentRecord.Href).ToNot(BeNil()) }) It(`DeletePolicyTemplateVersion request example`, func() { diff --git a/iampolicymanagementv1/iam_policy_management_v1_test.go b/iampolicymanagementv1/iam_policy_management_v1_test.go index f7c92937..7d752226 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_test.go @@ -7161,7 +7161,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policy_assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}]}`) + fmt.Fprintf(res, "%s", `{"policy_assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}]}`) })) }) It(`Invoke ListPolicyAssignments successfully with retries`, func() { @@ -7223,7 +7223,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policy_assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}]}`) + fmt.Fprintf(res, "%s", `{"policy_assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}]}`) })) }) It(`Invoke ListPolicyAssignments successfully`, func() { @@ -7390,7 +7390,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}`) + fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}`) })) }) It(`Invoke GetPolicyAssignment successfully with retries`, func() { @@ -7444,7 +7444,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}, "status": "in_progress"}}]}`) + fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}`) })) }) It(`Invoke GetPolicyAssignment successfully`, func() { From cae8648604c903cbdea81c11123cdc96a36869fa Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Tue, 23 May 2023 14:39:23 +0530 Subject: [PATCH 5/9] feat(IAM Policy Management): integration test added for GET PolicyAssignment by id Signed-off-by: Vivek.Jain3 --- .../iam_policy_management_v1_examples_test.go | 5 +- ...m_policy_management_v1_integration_test.go | 53 +++++++++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go index 7fd4c988..d03ec8c5 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go @@ -774,7 +774,10 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) - Expect(policyTemplate).ToNot(BeNil()) + Expect(policyTemplate.AccountID).ToNot(BeNil()) + Expect(policyTemplate.Version).ToNot(BeNil()) + Expect(policyTemplate.Name).ToNot(BeNil()) + Expect(policyTemplate.Policy).ToNot(BeNil()) examplePolicyTemplateETag = response.GetHeaders().Get("ETag") diff --git a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go index 9c7eb3bd..2cacdfde 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go @@ -64,6 +64,8 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { testPolicyTemplateID string = "" testPolicyTemplateETag string = "" testPolicyTemplateVersion string = "" + // change testPolicyAssignmentId id after prod account setup + testPolicyAssignmentId = "442c6fc4-2f74-41b2-bf4d-98342614cd22" ) var shouldSkipTest = func() { @@ -914,16 +916,59 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) It(`ListPolicyAssignments(listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions)`, func() { listPolicyAssignmentsOptions := &iampolicymanagementv1.ListPolicyAssignmentsOptions{ - AccountID: core.StringPtr(testAccountID), - AcceptLanguage: core.StringPtr("default"), - TemplateID: core.StringPtr(testPolicyTemplateID), - TemplateVersion: core.StringPtr(testPolicyTemplateVersion), + AccountID: core.StringPtr(testAccountID), + AcceptLanguage: core.StringPtr("default"), } polcyTemplateAssignmentCollection, response, err := service.ListPolicyAssignments(listPolicyAssignmentsOptions) Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(polcyTemplateAssignmentCollection).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TemplateID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TargetType).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TemplateVersion).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Target).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].AssignmentID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Options).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Status).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].AccountID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Resources).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].CreatedAt).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].CreatedByID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedAt).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedByID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Href).ToNot(BeNil()) + }) + }) + + Describe(`GetPolicyAssignment - Retrieve a policy assignment by ID`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetPolicyAssignment(getPolicyAssignmentOptions *GetPolicyAssignmentOptions)`, func() { + getPolicyAssignmentOptions := &iampolicymanagementv1.GetPolicyAssignmentOptions{ + AssignmentID: core.StringPtr(testPolicyAssignmentId), + } + + policyAssignmentRecord, response, err := service.GetPolicyAssignment(getPolicyAssignmentOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policyAssignmentRecord).ToNot(BeNil()) + Expect(policyAssignmentRecord.TemplateID).ToNot(BeNil()) + Expect(policyAssignmentRecord.TargetType).ToNot(BeNil()) + Expect(policyAssignmentRecord.TemplateVersion).ToNot(BeNil()) + Expect(policyAssignmentRecord.Target).ToNot(BeNil()) + Expect(policyAssignmentRecord.AssignmentID).ToNot(BeNil()) + Expect(policyAssignmentRecord.Options).ToNot(BeNil()) + Expect(policyAssignmentRecord.Status).ToNot(BeNil()) + Expect(policyAssignmentRecord.AccountID).ToNot(BeNil()) + Expect(policyAssignmentRecord.Resources).ToNot(BeNil()) + Expect(policyAssignmentRecord.CreatedAt).ToNot(BeNil()) + Expect(policyAssignmentRecord.CreatedByID).ToNot(BeNil()) + Expect(policyAssignmentRecord.LastModifiedAt).ToNot(BeNil()) + Expect(policyAssignmentRecord.LastModifiedByID).ToNot(BeNil()) + Expect(policyAssignmentRecord.Href).ToNot(BeNil()) }) }) From 24cc68a63ec31898a1fae17a4f18877f562b215d Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Thu, 25 May 2023 12:52:14 +0530 Subject: [PATCH 6/9] feat(IAM Policy Management): test flow update, code refactor Signed-off-by: Vivek.Jain3 --- .../iam_policy_management_v1_examples_test.go | 5 +++-- ...iam_policy_management_v1_integration_test.go | 17 +++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go index d03ec8c5..66d361c9 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go @@ -67,8 +67,7 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { examplePolicyTemplateID string examplePolicyTemplateETag string examplePolicyTemplateVersion string - // change testPolicyAssignmentId id after prod account setup - testPolicyAssignmentId = "442c6fc4-2f74-41b2-bf4d-98342614cd22" + testPolicyAssignmentId string ) var shouldSkipTest = func() { @@ -994,6 +993,8 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedAt).ToNot(BeNil()) Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedByID).ToNot(BeNil()) Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Href).ToNot(BeNil()) + + testPolicyAssignmentId = *polcyTemplateAssignmentCollection.PolicyAssignments[0].ID }) It(`GetPolicyAssignment request example`, func() { diff --git a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go index 2cacdfde..ff8436df 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go @@ -64,8 +64,8 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { testPolicyTemplateID string = "" testPolicyTemplateETag string = "" testPolicyTemplateVersion string = "" - // change testPolicyAssignmentId id after prod account setup - testPolicyAssignmentId = "442c6fc4-2f74-41b2-bf4d-98342614cd22" + testPolicyAssignmentId string = "" + examplePolicyTemplateName = "PolicySampleTemplateTestV1" ) var shouldSkipTest = func() { @@ -684,7 +684,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { } createPolicyTemplateOptions := &iampolicymanagementv1.CreatePolicyTemplateOptions{ - Name: core.StringPtr("PolicySampleTemplate"), + Name: core.StringPtr(examplePolicyTemplateName), AccountID: core.StringPtr(testAccountID), Policy: templatePolicyModel, Description: core.StringPtr("Test PolicySampleTemplate"), @@ -696,7 +696,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(201)) Expect(policyTemplate).ToNot(BeNil()) - Expect(policyTemplate.Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplate.Name).To(Equal(core.StringPtr(examplePolicyTemplateName))) Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) @@ -719,7 +719,6 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(response.StatusCode).To(Equal(200)) Expect(policyTemplateCollection).ToNot(BeNil()) - Expect(policyTemplateCollection.PolicyTemplates[0].Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) Expect(policyTemplateCollection.PolicyTemplates[0].Policy.Type).To(Equal(core.StringPtr("access"))) Expect(policyTemplateCollection.PolicyTemplates[0].AccountID).To(Equal(core.StringPtr(testAccountID))) }) @@ -739,7 +738,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(response.StatusCode).To(Equal(200)) Expect(policyTemplate).ToNot(BeNil()) - Expect(policyTemplate.Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplate.Name).To(Equal(core.StringPtr(examplePolicyTemplateName))) Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) }) @@ -790,7 +789,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(response.StatusCode).To(Equal(201)) Expect(policyTemplate).ToNot(BeNil()) - Expect(policyTemplate.Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplate.Name).To(Equal(core.StringPtr(examplePolicyTemplateName))) Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) @@ -863,7 +862,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(policyTemplate).ToNot(BeNil()) Expect(policyTemplate.Version).To(Equal(core.StringPtr("2"))) - Expect(policyTemplate.Name).To(Equal(core.StringPtr("PolicySampleTemplate"))) + Expect(policyTemplate.Name).To(Equal(core.StringPtr(examplePolicyTemplateName))) Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) @@ -939,6 +938,8 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedAt).ToNot(BeNil()) Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedByID).ToNot(BeNil()) Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Href).ToNot(BeNil()) + + testPolicyAssignmentId = *polcyTemplateAssignmentCollection.PolicyAssignments[0].ID }) }) From cc724b75e4eb3f2ff2a1b316ed09adb26958f7ce Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Thu, 1 Jun 2023 16:35:34 +0530 Subject: [PATCH 7/9] feat(IAM Policy Management): code refactor integration test Signed-off-by: Vivek.Jain3 --- ...m_policy_management_v1_integration_test.go | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go index ff8436df..80576110 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go @@ -684,8 +684,8 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { } createPolicyTemplateOptions := &iampolicymanagementv1.CreatePolicyTemplateOptions{ - Name: core.StringPtr(examplePolicyTemplateName), - AccountID: core.StringPtr(testAccountID), + Name: &examplePolicyTemplateName, + AccountID: &testAccountID, Policy: templatePolicyModel, Description: core.StringPtr("Test PolicySampleTemplate"), Committed: core.BoolPtr(true), @@ -710,7 +710,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) It(`ListPolicyTemplates(listPolicyTemplatesOptions *ListPolicyTemplatesOptions)`, func() { listPolicyTemplatesOptions := &iampolicymanagementv1.ListPolicyTemplatesOptions{ - AccountID: core.StringPtr(testAccountID), + AccountID: &testAccountID, AcceptLanguage: core.StringPtr("default"), } @@ -720,7 +720,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(policyTemplateCollection).ToNot(BeNil()) Expect(policyTemplateCollection.PolicyTemplates[0].Policy.Type).To(Equal(core.StringPtr("access"))) - Expect(policyTemplateCollection.PolicyTemplates[0].AccountID).To(Equal(core.StringPtr(testAccountID))) + Expect(policyTemplateCollection.PolicyTemplates[0].AccountID).To(Equal(&testAccountID)) }) }) @@ -730,7 +730,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) It(`GetPolicyTemplate(getPolicyTemplateOptions *GetPolicyTemplateOptions)`, func() { getPolicyTemplateOptions := &iampolicymanagementv1.GetPolicyTemplateOptions{ - PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + PolicyTemplateID: &testPolicyTemplateID, } policyTemplate, response, err := service.GetPolicyTemplate(getPolicyTemplateOptions) @@ -738,9 +738,9 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(response.StatusCode).To(Equal(200)) Expect(policyTemplate).ToNot(BeNil()) - Expect(policyTemplate.Name).To(Equal(core.StringPtr(examplePolicyTemplateName))) + Expect(policyTemplate.Name).To(Equal(&examplePolicyTemplateName)) Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) - Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + Expect(policyTemplate.AccountID).To(Equal(&testAccountID)) }) }) @@ -760,7 +760,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { } rolesModel := &iampolicymanagementv1.Roles{ - RoleID: core.StringPtr(testEditorRoleCrn), + RoleID: &testEditorRoleCrn, } grantModel := &iampolicymanagementv1.Grant{ @@ -779,7 +779,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { } createPolicyTemplateVersionOptions := &iampolicymanagementv1.CreatePolicyTemplateVersionOptions{ - PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + PolicyTemplateID: &testPolicyTemplateID, Policy: templatePolicyModel, Description: core.StringPtr("Watson Policy Template version"), } @@ -789,9 +789,9 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(response.StatusCode).To(Equal(201)) Expect(policyTemplate).ToNot(BeNil()) - Expect(policyTemplate.Name).To(Equal(core.StringPtr(examplePolicyTemplateName))) + Expect(policyTemplate.Name).To(Equal(&examplePolicyTemplateName)) Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) - Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + Expect(policyTemplate.AccountID).To(Equal(&testAccountID)) testPolicyTemplateVersion = *policyTemplate.Version testPolicyTemplateETag = response.GetHeaders().Get(etagHeader) @@ -804,7 +804,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) It(`ListPolicyTemplateVersions(listPolicyTemplateVersionsOptions *ListPolicyTemplateVersionsOptions)`, func() { listPolicyTemplateVersionsOptions := &iampolicymanagementv1.ListPolicyTemplateVersionsOptions{ - PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + PolicyTemplateID: &testPolicyTemplateID, } policyTemplateVersionsCollection, response, err := service.ListPolicyTemplateVersions(listPolicyTemplateVersionsOptions) @@ -830,7 +830,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { } rolesModel := &iampolicymanagementv1.Roles{ - RoleID: core.StringPtr(testViewerRoleCrn), + RoleID: &testViewerRoleCrn, } grantModel := &iampolicymanagementv1.Grant{ @@ -849,9 +849,9 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { } replacePolicyTemplateOptions := &iampolicymanagementv1.ReplacePolicyTemplateOptions{ - PolicyTemplateID: core.StringPtr(testPolicyTemplateID), - Version: core.StringPtr(testPolicyTemplateVersion), - IfMatch: core.StringPtr(testPolicyTemplateETag), + PolicyTemplateID: &testPolicyTemplateID, + Version: &testPolicyTemplateVersion, + IfMatch: &testPolicyTemplateETag, Policy: templatePolicyModel, Description: core.StringPtr("Template version update"), } @@ -862,9 +862,9 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(policyTemplate).ToNot(BeNil()) Expect(policyTemplate.Version).To(Equal(core.StringPtr("2"))) - Expect(policyTemplate.Name).To(Equal(core.StringPtr(examplePolicyTemplateName))) + Expect(policyTemplate.Name).To(Equal(&examplePolicyTemplateName)) Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) - Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + Expect(policyTemplate.AccountID).To(Equal(&testAccountID)) testPolicyTemplateETag = response.GetHeaders().Get(etagHeader) @@ -877,8 +877,8 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) It(`GetPolicyTemplateVersion(getPolicyTemplateVersionOptions *GetPolicyTemplateVersionOptions)`, func() { getPolicyTemplateVersionOptions := &iampolicymanagementv1.GetPolicyTemplateVersionOptions{ - PolicyTemplateID: core.StringPtr(testPolicyTemplateID), - Version: core.StringPtr(testPolicyTemplateVersion), + PolicyTemplateID: &testPolicyTemplateID, + Version: &testPolicyTemplateVersion, } policyTemplate, response, err := service.GetPolicyTemplateVersion(getPolicyTemplateVersionOptions) @@ -888,7 +888,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(policyTemplate.Version).To(Equal(core.StringPtr("2"))) Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) - Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID))) + Expect(policyTemplate.AccountID).To(Equal(&testAccountID)) }) }) @@ -898,9 +898,9 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) It(`CommitPolicyTemplate(commitPolicyTemplateOptions *CommitPolicyTemplateOptions)`, func() { commitPolicyTemplateOptions := &iampolicymanagementv1.CommitPolicyTemplateOptions{ - PolicyTemplateID: core.StringPtr(testPolicyTemplateID), - Version: core.StringPtr(testPolicyTemplateVersion), - IfMatch: core.StringPtr(testPolicyTemplateETag), + PolicyTemplateID: &testPolicyTemplateID, + Version: &testPolicyTemplateVersion, + IfMatch: &testPolicyTemplateETag, } response, err := service.CommitPolicyTemplate(commitPolicyTemplateOptions) @@ -979,8 +979,8 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) It(`DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions *DeletePolicyTemplateVersionOptions)`, func() { deletePolicyTemplateVersionOptions := &iampolicymanagementv1.DeletePolicyTemplateVersionOptions{ - PolicyTemplateID: core.StringPtr(testPolicyTemplateID), - Version: core.StringPtr(testPolicyTemplateVersion), + PolicyTemplateID: &testPolicyTemplateID, + Version: &testPolicyTemplateVersion, } response, err := service.DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions) @@ -995,7 +995,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { }) It(`DeletePolicyTemplate(deletePolicyTemplateOptions *DeletePolicyTemplateOptions)`, func() { deletePolicyTemplateOptions := &iampolicymanagementv1.DeletePolicyTemplateOptions{ - PolicyTemplateID: core.StringPtr(testPolicyTemplateID), + PolicyTemplateID: &testPolicyTemplateID, } response, err := service.DeletePolicyTemplate(deletePolicyTemplateOptions) From cb0b4fdb05c8efa8578ccb9902051804c0f8e1f1 Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Mon, 26 Jun 2023 15:46:16 +0530 Subject: [PATCH 8/9] feat(IAM Policy Management): re-gen API service model Signed-off-by: Vivek.Jain3 --- .../iam_policy_management_v1.go | 24 +++++++++++++++++++ .../iam_policy_management_v1_test.go | 14 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/iampolicymanagementv1/iam_policy_management_v1.go b/iampolicymanagementv1/iam_policy_management_v1.go index c81a9271..f7b8f550 100644 --- a/iampolicymanagementv1/iam_policy_management_v1.go +++ b/iampolicymanagementv1/iam_policy_management_v1.go @@ -1825,6 +1825,9 @@ func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyTemplateVersionWit if createPolicyTemplateVersionOptions.Description != nil { body["description"] = createPolicyTemplateVersionOptions.Description } + if createPolicyTemplateVersionOptions.Committed != nil { + body["committed"] = createPolicyTemplateVersionOptions.Committed + } _, err = builder.SetBodyContentJSON(body) if err != nil { return @@ -1962,6 +1965,9 @@ func (iamPolicyManagement *IamPolicyManagementV1) ReplacePolicyTemplateWithConte if replacePolicyTemplateOptions.Description != nil { body["description"] = replacePolicyTemplateOptions.Description } + if replacePolicyTemplateOptions.Committed != nil { + body["committed"] = replacePolicyTemplateOptions.Committed + } _, err = builder.SetBodyContentJSON(body) if err != nil { return @@ -2585,6 +2591,9 @@ type CreatePolicyTemplateVersionOptions struct { // description of template purpose. Description *string `json:"description,omitempty"` + // Template vesrsion committed status. + Committed *bool `json:"committed,omitempty"` + // Allows users to set headers on API requests Headers map[string]string } @@ -2615,6 +2624,12 @@ func (_options *CreatePolicyTemplateVersionOptions) SetDescription(description s return _options } +// SetCommitted : Allow user to set Committed +func (_options *CreatePolicyTemplateVersionOptions) SetCommitted(committed bool) *CreatePolicyTemplateVersionOptions { + _options.Committed = core.BoolPtr(committed) + return _options +} + // SetHeaders : Allow user to set Headers func (options *CreatePolicyTemplateVersionOptions) SetHeaders(param map[string]string) *CreatePolicyTemplateVersionOptions { options.Headers = param @@ -4375,6 +4390,9 @@ type ReplacePolicyTemplateOptions struct { // description of template purpose. Description *string `json:"description,omitempty"` + // Template vesrsion committed status. + Committed *bool `json:"committed,omitempty"` + // Allows users to set headers on API requests Headers map[string]string } @@ -4419,6 +4437,12 @@ func (_options *ReplacePolicyTemplateOptions) SetDescription(description string) return _options } +// SetCommitted : Allow user to set Committed +func (_options *ReplacePolicyTemplateOptions) SetCommitted(committed bool) *ReplacePolicyTemplateOptions { + _options.Committed = core.BoolPtr(committed) + return _options +} + // SetHeaders : Allow user to set Headers func (options *ReplacePolicyTemplateOptions) SetHeaders(param map[string]string) *ReplacePolicyTemplateOptions { options.Headers = param diff --git a/iampolicymanagementv1/iam_policy_management_v1_test.go b/iampolicymanagementv1/iam_policy_management_v1_test.go index 7d752226..949fc060 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_test.go @@ -5621,6 +5621,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Committed = core.BoolPtr(true) createPolicyTemplateVersionOptionsModel.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 := iamPolicyManagementService.CreatePolicyTemplateVersion(createPolicyTemplateVersionOptionsModel) @@ -5734,6 +5735,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Committed = core.BoolPtr(true) createPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -5855,6 +5857,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Committed = core.BoolPtr(true) createPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -5921,6 +5924,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Committed = core.BoolPtr(true) createPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := iamPolicyManagementService.SetServiceURL("") @@ -6008,6 +6012,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { createPolicyTemplateVersionOptionsModel.PolicyTemplateID = core.StringPtr("testString") createPolicyTemplateVersionOptionsModel.Policy = templatePolicyModel createPolicyTemplateVersionOptionsModel.Description = core.StringPtr("testString") + createPolicyTemplateVersionOptionsModel.Committed = core.BoolPtr(true) createPolicyTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation @@ -6311,6 +6316,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") replacePolicyTemplateOptionsModel.Policy = templatePolicyModel replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Committed = core.BoolPtr(true) replacePolicyTemplateOptionsModel.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 := iamPolicyManagementService.ReplacePolicyTemplate(replacePolicyTemplateOptionsModel) @@ -6428,6 +6434,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") replacePolicyTemplateOptionsModel.Policy = templatePolicyModel replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Committed = core.BoolPtr(true) replacePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -6553,6 +6560,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") replacePolicyTemplateOptionsModel.Policy = templatePolicyModel replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Committed = core.BoolPtr(true) replacePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -6621,6 +6629,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") replacePolicyTemplateOptionsModel.Policy = templatePolicyModel replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Committed = core.BoolPtr(true) replacePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := iamPolicyManagementService.SetServiceURL("") @@ -6710,6 +6719,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { replacePolicyTemplateOptionsModel.IfMatch = core.StringPtr("testString") replacePolicyTemplateOptionsModel.Policy = templatePolicyModel replacePolicyTemplateOptionsModel.Description = core.StringPtr("testString") + replacePolicyTemplateOptionsModel.Committed = core.BoolPtr(true) replacePolicyTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation @@ -7812,11 +7822,13 @@ var _ = Describe(`IamPolicyManagementV1`, func() { createPolicyTemplateVersionOptionsModel.SetPolicyTemplateID("testString") createPolicyTemplateVersionOptionsModel.SetPolicy(templatePolicyModel) createPolicyTemplateVersionOptionsModel.SetDescription("testString") + createPolicyTemplateVersionOptionsModel.SetCommitted(true) createPolicyTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(createPolicyTemplateVersionOptionsModel).ToNot(BeNil()) Expect(createPolicyTemplateVersionOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) Expect(createPolicyTemplateVersionOptionsModel.Policy).To(Equal(templatePolicyModel)) Expect(createPolicyTemplateVersionOptionsModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(createPolicyTemplateVersionOptionsModel.Committed).To(Equal(core.BoolPtr(true))) Expect(createPolicyTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewCreateRoleOptions successfully`, func() { @@ -8348,6 +8360,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { replacePolicyTemplateOptionsModel.SetIfMatch("testString") replacePolicyTemplateOptionsModel.SetPolicy(templatePolicyModel) replacePolicyTemplateOptionsModel.SetDescription("testString") + replacePolicyTemplateOptionsModel.SetCommitted(true) replacePolicyTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(replacePolicyTemplateOptionsModel).ToNot(BeNil()) Expect(replacePolicyTemplateOptionsModel.PolicyTemplateID).To(Equal(core.StringPtr("testString"))) @@ -8355,6 +8368,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(replacePolicyTemplateOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) Expect(replacePolicyTemplateOptionsModel.Policy).To(Equal(templatePolicyModel)) Expect(replacePolicyTemplateOptionsModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(replacePolicyTemplateOptionsModel.Committed).To(Equal(core.BoolPtr(true))) Expect(replacePolicyTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewReplaceRoleOptions successfully`, func() { From 73fd1e265b284982e7e808d3ff940d473c117882 Mon Sep 17 00:00:00 2001 From: "Vivek.Jain3" Date: Thu, 3 Aug 2023 18:22:06 +0530 Subject: [PATCH 9/9] feat(IAM Policy Management): re-gen service after recent API changes, Tests update for Policy Template Signed-off-by: Vivek.Jain3 --- .../iam_policy_management_v1.go | 1512 +++++++++-------- .../iam_policy_management_v1_examples_test.go | 34 +- ...m_policy_management_v1_integration_test.go | 34 +- .../iam_policy_management_v1_test.go | 64 +- 4 files changed, 829 insertions(+), 815 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1.go b/iampolicymanagementv1/iam_policy_management_v1.go index f7b8f550..eed7f91d 100644 --- a/iampolicymanagementv1/iam_policy_management_v1.go +++ b/iampolicymanagementv1/iam_policy_management_v1.go @@ -166,12 +166,12 @@ func (iamPolicyManagement *IamPolicyManagementV1) DisableRetries() { // account_id, iam_id, access_group_id, type, service_type, sort, format and state. account_id is a required query // parameter. Only policies that have the specified attributes and that the caller has read access to are returned. If // the caller does not have read access to any policies an empty array is returned. -func (iamPolicyManagement *IamPolicyManagementV1) ListPolicies(listPoliciesOptions *ListPoliciesOptions) (result *PolicyList, response *core.DetailedResponse, err error) { +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicies(listPoliciesOptions *ListPoliciesOptions) (result *PolicyCollection, response *core.DetailedResponse, err error) { return iamPolicyManagement.ListPoliciesWithContext(context.Background(), listPoliciesOptions) } // ListPoliciesWithContext is an alternate form of the ListPolicies method which supports a Context parameter -func (iamPolicyManagement *IamPolicyManagementV1) ListPoliciesWithContext(ctx context.Context, listPoliciesOptions *ListPoliciesOptions) (result *PolicyList, response *core.DetailedResponse, err error) { +func (iamPolicyManagement *IamPolicyManagementV1) ListPoliciesWithContext(ctx context.Context, listPoliciesOptions *ListPoliciesOptions) (result *PolicyCollection, response *core.DetailedResponse, err error) { err = core.ValidateNotNil(listPoliciesOptions, "listPoliciesOptions cannot be nil") if err != nil { return @@ -242,7 +242,7 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListPoliciesWithContext(ctx co return } if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyList) + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyCollection) if err != nil { return } @@ -684,12 +684,12 @@ func (iamPolicyManagement *IamPolicyManagementV1) UpdatePolicyStateWithContext(c // service_group_id, source_service_name and policy_type. Both service_name and service_group_id attributes are mutually // exclusive. Only roles that match the filter and that the caller has read access to are returned. If the caller does // not have read access to any roles an empty array is returned. -func (iamPolicyManagement *IamPolicyManagementV1) ListRoles(listRolesOptions *ListRolesOptions) (result *RoleList, response *core.DetailedResponse, err error) { +func (iamPolicyManagement *IamPolicyManagementV1) ListRoles(listRolesOptions *ListRolesOptions) (result *RoleCollection, response *core.DetailedResponse, err error) { return iamPolicyManagement.ListRolesWithContext(context.Background(), listRolesOptions) } // ListRolesWithContext is an alternate form of the ListRoles method which supports a Context parameter -func (iamPolicyManagement *IamPolicyManagementV1) ListRolesWithContext(ctx context.Context, listRolesOptions *ListRolesOptions) (result *RoleList, response *core.DetailedResponse, err error) { +func (iamPolicyManagement *IamPolicyManagementV1) ListRolesWithContext(ctx context.Context, listRolesOptions *ListRolesOptions) (result *RoleCollection, response *core.DetailedResponse, err error) { err = core.ValidateStruct(listRolesOptions, "listRolesOptions") if err != nil { return @@ -743,7 +743,7 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListRolesWithContext(ctx conte return } if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRoleList) + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRoleCollection) if err != nil { return } @@ -1136,7 +1136,7 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListV2PoliciesWithContext(ctx // The policy resource must include either the **`serviceType`**, **`serviceName`**, **`resourceGroupId`** or // **`service_group_id`** attribute and the **`accountId`** attribute. In the rule field, you can specify a single // condition by using **`key`**, **`value`**, and condition **`operator`**, or a set of **`conditions`** with a -// combination **`operator`**. The possible combination operators are **`and`** and **`or`**. Combine conditions to +// combination **`operator`**. The possible combination operators are **`and`** and **`or`**. Combine conditions to // specify a time-based restriction (e.g., access only during business hours, during the Monday-Friday work week). For // example, a policy can grant access Monday-Friday, 9:00am-5:00pm using the following rule: // ```json @@ -1281,7 +1281,7 @@ func (iamPolicyManagement *IamPolicyManagementV1) CreateV2PolicyWithContext(ctx // The policy resource must include either the **`serviceType`**, **`serviceName`**, **`resourceGroupId`** or // **`service_group_id`** attribute and the **`accountId`** attribute. In the rule field, you can specify a single // condition by using **`key`**, **`value`**, and condition **`operator`**, or a set of **`conditions`** with a -// combination **`operator`**. The possible combination operators are **`and`** and **`or`**. Combine conditions to +// combination **`operator`**. The possible combination operators are **`and`** and **`or`**. Combine conditions to // specify a time-based restriction (e.g., access only during business hours, during the Monday-Friday work week). For // example, a policy can grant access Monday-Friday, 9:00am-5:00pm using the following rule: // ```json @@ -1524,11 +1524,12 @@ func (iamPolicyManagement *IamPolicyManagementV1) DeleteV2PolicyWithContext(ctx return } -// ListPolicyTemplates : Get policy templates by attributes -// Get policy templates and filter by attributes through query parameters. The following attributes are supported: -// account_id account_id is a required query parameter. Only policy templates that have the specified attributes and -// that the caller has read access to are returned. If the caller does not have read access to any policy templates an -// empty array is returned. +// ListPolicyTemplates : List policy templates by attributes +// List policy templates and filter by attributes by using query parameters. The following attributes are supported: +// `account_id`. +// `account_id` is a required query parameter. Only policy templates that have the specified attributes and that the +// caller has read access to are returned. If the caller does not have read access to any policy templates an empty +// array is returned. func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyTemplates(listPolicyTemplatesOptions *ListPolicyTemplatesOptions) (result *PolicyTemplateCollection, response *core.DetailedResponse, err error) { return iamPolicyManagement.ListPolicyTemplatesWithContext(context.Background(), listPolicyTemplatesOptions) } @@ -1589,7 +1590,8 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyTemplatesWithContext } // CreatePolicyTemplate : Create a policy template -// Creates a policy template. +// Create a policy template. Policy templates define a policy without requiring a subject, and you can use them to grant +// access to multiple subjects. func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyTemplate(createPolicyTemplateOptions *CreatePolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { return iamPolicyManagement.CreatePolicyTemplateWithContext(context.Background(), createPolicyTemplateOptions) } @@ -1669,7 +1671,7 @@ func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyTemplateWithContex return } -// GetPolicyTemplate : Retrieve latest policy template version by template ID +// GetPolicyTemplate : Retrieve latest version of a policy template // Retrieve the latest version of a policy template by providing a policy template ID. func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyTemplate(getPolicyTemplateOptions *GetPolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { return iamPolicyManagement.GetPolicyTemplateWithContext(context.Background(), getPolicyTemplateOptions) @@ -1729,9 +1731,10 @@ func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyTemplateWithContext(c return } -// DeletePolicyTemplate : Delete a policy template by ID -// Delete a policy template by providing a policy template ID. This deletes all versions of this template. A policy -// template cannot be deleted if the template version is assigned to an account. +// DeletePolicyTemplate : Delete a policy template +// Delete a policy template by providing the policy template ID. This deletes all versions of this template. A policy +// template can't be deleted if any version of the template is assigned to one or more child accounts. You must remove +// the policy assignments first. func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyTemplate(deletePolicyTemplateOptions *DeletePolicyTemplateOptions) (response *core.DetailedResponse, err error) { return iamPolicyManagement.DeletePolicyTemplateWithContext(context.Background(), deletePolicyTemplateOptions) } @@ -1779,7 +1782,8 @@ func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyTemplateWithContex } // CreatePolicyTemplateVersion : Create a new policy template version -// Creates a new policy template version Details TBD. +// Create a new version of a policy template. Use this if you need to make updates to a policy template that is +// committed. func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyTemplateVersion(createPolicyTemplateVersionOptions *CreatePolicyTemplateVersionOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { return iamPolicyManagement.CreatePolicyTemplateVersionWithContext(context.Background(), createPolicyTemplateVersionOptions) } @@ -1915,7 +1919,7 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyTemplateVersionsWith } // ReplacePolicyTemplate : Update a policy template version -// Update a policy template version Details TBD. +// Update a specific version of a policy template. You can use this only if the version isn't committed. func (iamPolicyManagement *IamPolicyManagementV1) ReplacePolicyTemplate(replacePolicyTemplateOptions *ReplacePolicyTemplateOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { return iamPolicyManagement.ReplacePolicyTemplateWithContext(context.Background(), replacePolicyTemplateOptions) } @@ -1994,9 +1998,10 @@ func (iamPolicyManagement *IamPolicyManagementV1) ReplacePolicyTemplateWithConte return } -// DeletePolicyTemplateVersion : Delete a policy template version by ID and version -// Delete a policy template by providing a policy template ID and version. You can't delete a policy template if the -// template version is assigned to an account. +// DeletePolicyTemplateVersion : Delete a policy template version +// Delete a specific version of a policy template by providing a policy template ID and version number. You can't delete +// a policy template version that is assigned to one or more child accounts. You must remove the policy assignments +// first. func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions *DeletePolicyTemplateVersionOptions) (response *core.DetailedResponse, err error) { return iamPolicyManagement.DeletePolicyTemplateVersionWithContext(context.Background(), deletePolicyTemplateVersionOptions) } @@ -2044,8 +2049,8 @@ func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyTemplateVersionWit return } -// GetPolicyTemplateVersion : Retrieve a policy template version by ID -// Retrieve a policy template by providing a policy template ID and version. +// GetPolicyTemplateVersion : Retrieve a policy template version +// Retrieve a policy template by providing a policy template ID and version number. func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyTemplateVersion(getPolicyTemplateVersionOptions *GetPolicyTemplateVersionOptions) (result *PolicyTemplate, response *core.DetailedResponse, err error) { return iamPolicyManagement.GetPolicyTemplateVersionWithContext(context.Background(), getPolicyTemplateVersionOptions) } @@ -2106,7 +2111,8 @@ func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyTemplateVersionWithCo } // CommitPolicyTemplate : Commit a policy template version -// Commit a policy template version Details TBD. +// Commit a policy template version. You can make no further changes to the policy template once it's committed. If you +// need to make updates after committing a version, create a new version. func (iamPolicyManagement *IamPolicyManagementV1) CommitPolicyTemplate(commitPolicyTemplateOptions *CommitPolicyTemplateOptions) (response *core.DetailedResponse, err error) { return iamPolicyManagement.CommitPolicyTemplateWithContext(context.Background(), commitPolicyTemplateOptions) } @@ -2157,17 +2163,18 @@ func (iamPolicyManagement *IamPolicyManagementV1) CommitPolicyTemplateWithContex return } -// ListPolicyAssignments : Get policies template assignments by attributes -// Get policy template assignments by attributes. The following attributes are supported: account_id, template_id, -// template_version, sort account_id is a required query parameter. Only policy template assignments that have the -// specified attributes and that the caller has read access to are returned. If the caller does not have read access to -// any policy template assignments an empty array is returned. -func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyAssignments(listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions) (result *PolcyTemplateAssignmentCollection, response *core.DetailedResponse, err error) { +// ListPolicyAssignments : Get policy template assignments +// Get policy template assignments by attributes. The following attributes are supported: +// `account_id`, `template_id`, `template_version`, `sort`. +// `account_id` is a required query parameter. Only policy template assignments that have the specified attributes and +// that the caller has read access to are returned. If the caller does not have read access to any policy template +// assignments an empty array is returned. +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyAssignments(listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions) (result *PolicyTemplateAssignmentCollection, response *core.DetailedResponse, err error) { return iamPolicyManagement.ListPolicyAssignmentsWithContext(context.Background(), listPolicyAssignmentsOptions) } // ListPolicyAssignmentsWithContext is an alternate form of the ListPolicyAssignments method which supports a Context parameter -func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyAssignmentsWithContext(ctx context.Context, listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions) (result *PolcyTemplateAssignmentCollection, response *core.DetailedResponse, err error) { +func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyAssignmentsWithContext(ctx context.Context, listPolicyAssignmentsOptions *ListPolicyAssignmentsOptions) (result *PolicyTemplateAssignmentCollection, response *core.DetailedResponse, err error) { err = core.ValidateNotNil(listPolicyAssignmentsOptions, "listPolicyAssignmentsOptions cannot be nil") if err != nil { return @@ -2217,7 +2224,7 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyAssignmentsWithConte return } if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolcyTemplateAssignmentCollection) + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyTemplateAssignmentCollection) if err != nil { return } @@ -2227,14 +2234,14 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListPolicyAssignmentsWithConte return } -// GetPolicyAssignment : Retrieve a policy assignment by ID +// GetPolicyAssignment : Retrieve a policy assignment // Retrieve a policy template assignment by providing a policy assignment ID. -func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyAssignment(getPolicyAssignmentOptions *GetPolicyAssignmentOptions) (result *PolicyAssignmentRecord, response *core.DetailedResponse, err error) { +func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyAssignment(getPolicyAssignmentOptions *GetPolicyAssignmentOptions) (result *PolicyAssignment, response *core.DetailedResponse, err error) { return iamPolicyManagement.GetPolicyAssignmentWithContext(context.Background(), getPolicyAssignmentOptions) } // GetPolicyAssignmentWithContext is an alternate form of the GetPolicyAssignment method which supports a Context parameter -func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyAssignmentWithContext(ctx context.Context, getPolicyAssignmentOptions *GetPolicyAssignmentOptions) (result *PolicyAssignmentRecord, response *core.DetailedResponse, err error) { +func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyAssignmentWithContext(ctx context.Context, getPolicyAssignmentOptions *GetPolicyAssignmentOptions) (result *PolicyAssignment, response *core.DetailedResponse, err error) { err = core.ValidateNotNil(getPolicyAssignmentOptions, "getPolicyAssignmentOptions cannot be nil") if err != nil { return @@ -2277,7 +2284,7 @@ func (iamPolicyManagement *IamPolicyManagementV1) GetPolicyAssignmentWithContext return } if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyAssignmentRecord) + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicyAssignment) if err != nil { return } @@ -2354,6 +2361,37 @@ func (options *CommitPolicyTemplateOptions) SetHeaders(param map[string]string) return options } +// ConflictsWith : Details of conflicting resource. +type ConflictsWith struct { + // The revision number of the resource. + Etag *string `json:"etag,omitempty"` + + // The conflicting role id. + Role *string `json:"role,omitempty"` + + // The conflicting policy id. + Policy *string `json:"policy,omitempty"` +} + +// UnmarshalConflictsWith unmarshals an instance of ConflictsWith from the specified map of raw messages. +func UnmarshalConflictsWith(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ConflictsWith) + err = core.UnmarshalPrimitive(m, "etag", &obj.Etag) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "role", &obj.Role) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "policy", &obj.Policy) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // Control : Specifies the type of access granted by the policy. type Control struct { // Permission granted by the policy. @@ -2496,19 +2534,21 @@ func (options *CreatePolicyOptions) SetHeaders(param map[string]string) *CreateP // CreatePolicyTemplateOptions : The CreatePolicyTemplate options. type CreatePolicyTemplateOptions struct { - // name of template. + // Required field when creating a new template. Otherwise this field is optional. If the field is included it will + // change the name value for all existing versions of the template. Name *string `json:"name" validate:"required"` - // account id where this template will be created. + // Enterprise account ID where this template will be created. AccountID *string `json:"account_id" validate:"required"` // The core set of properties associated with the template's policy objet. Policy *TemplatePolicy `json:"policy" validate:"required"` - // description of template purpose. + // Description of the policy template. This is shown to users in the enterprise account. Use this to describe the + // purpose or context of the policy for enterprise users managing IAM templates. Description *string `json:"description,omitempty"` - // committed status for the template. + // Committed status of the template. Committed *bool `json:"committed,omitempty"` // Language code for translations @@ -2588,10 +2628,11 @@ type CreatePolicyTemplateVersionOptions struct { // The core set of properties associated with the template's policy objet. Policy *TemplatePolicy `json:"policy" validate:"required"` - // description of template purpose. + // Description of the policy template. This is shown to users in the enterprise account. Use this to describe the + // purpose or context of the policy for enterprise users managing IAM templates. Description *string `json:"description,omitempty"` - // Template vesrsion committed status. + // Committed status of the template version. Committed *bool `json:"committed,omitempty"` // Allows users to set headers on API requests @@ -2742,7 +2783,7 @@ type CreateV2PolicyOptions struct { // The policy type; either 'access' or 'authorization'. Type *string `json:"type" validate:"required"` - // Allows the customer to use their own words to record the purpose/context related to a policy. + // Description of the policy. Description *string `json:"description,omitempty"` // The subject attributes for whom the policy grants access. @@ -2845,6 +2886,109 @@ func (options *CreateV2PolicyOptions) SetHeaders(param map[string]string) *Creat return options } +// CustomRole : An additional set of properties associated with a role. +type CustomRole struct { + // The role ID. Composed of hexadecimal characters. + ID *string `json:"id,omitempty"` + + // The display name of the role that is shown in the console. + DisplayName *string `json:"display_name" validate:"required"` + + // The description of the role. + Description *string `json:"description,omitempty"` + + // The actions of the role. For more information, see [IAM roles and + // actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + Actions []string `json:"actions" validate:"required"` + + // The role Cloud Resource Name (CRN). Example CRN: + // 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. + CRN *string `json:"crn,omitempty"` + + // The name of the role that is used in the CRN. Can only be alphanumeric and has to be capitalized. + Name *string `json:"name" validate:"required"` + + // The account GUID. + AccountID *string `json:"account_id" validate:"required"` + + // The service name. + ServiceName *string `json:"service_name" validate:"required"` + + // The UTC timestamp when the role was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + + // The iam ID of the entity that created the role. + CreatedByID *string `json:"created_by_id,omitempty"` + + // The UTC timestamp when the role was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` + + // The iam ID of the entity that last modified the policy. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` + + // The href link back to the role. + Href *string `json:"href,omitempty"` +} + +// UnmarshalCustomRole unmarshals an instance of CustomRole from the specified map of raw messages. +func UnmarshalCustomRole(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CustomRole) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "actions", &obj.Actions) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "service_name", &obj.ServiceName) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // DeletePolicyOptions : The DeletePolicy options. type DeletePolicyOptions struct { // The policy ID. @@ -3035,6 +3179,114 @@ func UnmarshalEnrichedRoles(m map[string]json.RawMessage, result interface{}) (e return } +// ErrorDetails : Additional error details. +type ErrorDetails struct { + // Details of conflicting resource. + ConflictsWith *ConflictsWith `json:"conflicts_with,omitempty"` +} + +// UnmarshalErrorDetails unmarshals an instance of ErrorDetails from the specified map of raw messages. +func UnmarshalErrorDetails(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ErrorDetails) + err = core.UnmarshalModel(m, "conflicts_with", &obj.ConflictsWith, UnmarshalConflictsWith) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ErrorObject : ErrorObject struct +type ErrorObject struct { + // The API error code for the error. + Code *string `json:"code" validate:"required"` + + // The error message returned by the API. + Message *string `json:"message" validate:"required"` + + // Additional error details. + Details *ErrorDetails `json:"details,omitempty"` + + // Additional info for error. + MoreInfo *string `json:"more_info,omitempty"` +} + +// Constants associated with the ErrorObject.Code property. +// The API error code for the error. +const ( + ErrorObjectCodeInsufficentPermissionsConst = "insufficent_permissions" + ErrorObjectCodeInvalidBodyConst = "invalid_body" + ErrorObjectCodeInvalidTokenConst = "invalid_token" + ErrorObjectCodeMissingRequiredQueryParameterConst = "missing_required_query_parameter" + ErrorObjectCodeNotFoundConst = "not_found" + ErrorObjectCodePolicyAssignmentConflictErrorConst = "policy_assignment_conflict_error" + ErrorObjectCodePolicyAssignmentNotFoundConst = "policy_assignment_not_found" + ErrorObjectCodePolicyConflictErrorConst = "policy_conflict_error" + ErrorObjectCodePolicyNotFoundConst = "policy_not_found" + ErrorObjectCodePolicyTemplateConflictErrorConst = "policy_template_conflict_error" + ErrorObjectCodePolicyTemplateNotFoundConst = "policy_template_not_found" + ErrorObjectCodeRequestNotProcessedConst = "request_not_processed" + ErrorObjectCodeRoleConflictErrorConst = "role_conflict_error" + ErrorObjectCodeRoleNotFoundConst = "role_not_found" + ErrorObjectCodeTooManyRequestsConst = "too_many_requests" + ErrorObjectCodeUnableToProcessConst = "unable_to_process" + ErrorObjectCodeUnsupportedContentTypeConst = "unsupported_content_type" +) + +// UnmarshalErrorObject unmarshals an instance of ErrorObject from the specified map of raw messages. +func UnmarshalErrorObject(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ErrorObject) + err = core.UnmarshalPrimitive(m, "code", &obj.Code) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "message", &obj.Message) + if err != nil { + return + } + err = core.UnmarshalModel(m, "details", &obj.Details, UnmarshalErrorDetails) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "more_info", &obj.MoreInfo) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ErrorResponse : The error response from API. +type ErrorResponse struct { + // The unique transaction id for the request. + Trace *string `json:"trace,omitempty"` + + // The errors encountered during the response. + Errors []ErrorObject `json:"errors,omitempty"` + + // The http error code of the response. + StatusCode *int64 `json:"status_code,omitempty"` +} + +// UnmarshalErrorResponse unmarshals an instance of ErrorResponse from the specified map of raw messages. +func UnmarshalErrorResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ErrorResponse) + err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + if err != nil { + return + } + err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalErrorObject) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // GetPolicyAssignmentOptions : The GetPolicyAssignment options. type GetPolicyAssignmentOptions struct { // The policy template assignment ID. @@ -3868,68 +4120,107 @@ func (options *ListV2PoliciesOptions) SetHeaders(param map[string]string) *ListV return options } -// PolcyTemplateAssignmentCollection : A collection of policies assignments. -type PolcyTemplateAssignmentCollection struct { - // List of policy assignments. - PolicyAssignments []PolicyAssignmentRecord `json:"policy_assignments,omitempty"` -} +// Policy : The core set of properties associated with a policy. +type Policy struct { + // The policy ID. + ID *string `json:"id,omitempty"` -// UnmarshalPolcyTemplateAssignmentCollection unmarshals an instance of PolcyTemplateAssignmentCollection from the specified map of raw messages. -func UnmarshalPolcyTemplateAssignmentCollection(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(PolcyTemplateAssignmentCollection) - err = core.UnmarshalModel(m, "policy_assignments", &obj.PolicyAssignments, UnmarshalPolicyAssignmentRecord) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} + // The policy type; either 'access' or 'authorization'. + Type *string `json:"type" validate:"required"` -// PolicyAssignmentOptions : The set of properties required for a policy assignment. -type PolicyAssignmentOptions struct { - // The policy subject type; either 'iam_id' or 'access_group_id'. - SubjectType *string `json:"subject_type" validate:"required"` + // Customer-defined description. + Description *string `json:"description,omitempty"` - // The policy subject id. - SubjectID *string `json:"subject_id" validate:"required"` + // The subjects associated with a policy. + Subjects []PolicySubject `json:"subjects" validate:"required"` - // The policy assignment requester id. - RootRequesterID *string `json:"root_requester_id" validate:"required"` + // A set of role cloud resource names (CRNs) granted by the policy. + Roles []PolicyRole `json:"roles" validate:"required"` - // The template id where this policy is being assigned from. - RootTemplateID *string `json:"root_template_id,omitempty"` + // The resources associated with a policy. + Resources []PolicyResource `json:"resources" validate:"required"` - // The template version where this policy is being assigned from. - RootTemplateVersion *string `json:"root_template_version,omitempty"` + // The href link back to the policy. + Href *string `json:"href,omitempty"` + + // The UTC timestamp when the policy was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + + // The iam ID of the entity that created the policy. + CreatedByID *string `json:"created_by_id,omitempty"` + + // The UTC timestamp when the policy was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` + + // The iam ID of the entity that last modified the policy. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` + + // The policy state. + State *string `json:"state,omitempty"` + + // Origin Template information. + Template *TemplateMetadata `json:"template,omitempty"` } -// Constants associated with the PolicyAssignmentOptions.SubjectType property. -// The policy subject type; either 'iam_id' or 'access_group_id'. +// Constants associated with the Policy.State property. +// The policy state. const ( - PolicyAssignmentOptionsSubjectTypeAccessGroupIDConst = "access_group_id" - PolicyAssignmentOptionsSubjectTypeIamIDConst = "iam_id" + PolicyStateActiveConst = "active" + PolicyStateDeletedConst = "deleted" ) -// UnmarshalPolicyAssignmentOptions unmarshals an instance of PolicyAssignmentOptions from the specified map of raw messages. -func UnmarshalPolicyAssignmentOptions(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(PolicyAssignmentOptions) - err = core.UnmarshalPrimitive(m, "subject_type", &obj.SubjectType) +// UnmarshalPolicy unmarshals an instance of Policy from the specified map of raw messages. +func UnmarshalPolicy(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Policy) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) if err != nil { return } - err = core.UnmarshalPrimitive(m, "subject_id", &obj.SubjectID) + err = core.UnmarshalPrimitive(m, "type", &obj.Type) if err != nil { return } - err = core.UnmarshalPrimitive(m, "root_requester_id", &obj.RootRequesterID) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) if err != nil { return } - err = core.UnmarshalPrimitive(m, "root_template_id", &obj.RootTemplateID) + err = core.UnmarshalModel(m, "subjects", &obj.Subjects, UnmarshalPolicySubject) if err != nil { return } - err = core.UnmarshalPrimitive(m, "root_template_version", &obj.RootTemplateVersion) + err = core.UnmarshalModel(m, "roles", &obj.Roles, UnmarshalPolicyRole) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalPolicyResource) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "state", &obj.State) + if err != nil { + return + } + err = core.UnmarshalModel(m, "template", &obj.Template, UnmarshalTemplateMetadata) if err != nil { return } @@ -3937,8 +4228,8 @@ func UnmarshalPolicyAssignmentOptions(m map[string]json.RawMessage, result inter return } -// PolicyAssignmentRecord : The set of properties associated with the policy template assignment. -type PolicyAssignmentRecord struct { +// PolicyAssignment : The set of properties associated with the policy template assignment. +type PolicyAssignment struct { // policy template id. TemplateID *string `json:"template_id" validate:"required"` @@ -3951,9 +4242,12 @@ type PolicyAssignmentRecord struct { // Assignment target type. TargetType *string `json:"target_type" validate:"required"` - // assignment target id. + // ID of the target account. Target *string `json:"target" validate:"required"` + // List of objects with required properties for a policy assignment. + Options []PolicyAssignmentRequestOptionsItem `json:"options" validate:"required"` + // Policy assignment ID. ID *string `json:"id,omitempty"` @@ -3975,9 +4269,6 @@ type PolicyAssignmentRecord struct { // The iam ID of the entity that last modified the policy assignment. LastModifiedByID *string `json:"last_modified_by_id,omitempty"` - // Object for each properties for a policy assignment. - Options []PolicyAssignmentOptions `json:"options,omitempty"` - // Object for each account assigned. Resources []PolicyAssignmentResources `json:"resources,omitempty"` @@ -3985,24 +4276,24 @@ type PolicyAssignmentRecord struct { Status *string `json:"status" validate:"required"` } -// Constants associated with the PolicyAssignmentRecord.TargetType property. +// Constants associated with the PolicyAssignment.TargetType property. // Assignment target type. const ( - PolicyAssignmentRecordTargetTypeAccountConst = "Account" + PolicyAssignmentTargetTypeAccountConst = "Account" ) -// Constants associated with the PolicyAssignmentRecord.Status property. +// Constants associated with the PolicyAssignment.Status property. // The policy assignment status. const ( - PolicyAssignmentRecordStatusFailedConst = "failed" - PolicyAssignmentRecordStatusInProgressConst = "in_progress" - PolicyAssignmentRecordStatusSucceedWithErrorsConst = "succeed_with_errors" - PolicyAssignmentRecordStatusSucceededConst = "succeeded" + PolicyAssignmentStatusFailedConst = "failed" + PolicyAssignmentStatusInProgressConst = "in_progress" + PolicyAssignmentStatusSucceedWithErrorsConst = "succeed_with_errors" + PolicyAssignmentStatusSucceededConst = "succeeded" ) -// UnmarshalPolicyAssignmentRecord unmarshals an instance of PolicyAssignmentRecord from the specified map of raw messages. -func UnmarshalPolicyAssignmentRecord(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(PolicyAssignmentRecord) +// UnmarshalPolicyAssignment unmarshals an instance of PolicyAssignment from the specified map of raw messages. +func UnmarshalPolicyAssignment(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyAssignment) err = core.UnmarshalPrimitive(m, "template_id", &obj.TemplateID) if err != nil { return @@ -4023,6 +4314,10 @@ func UnmarshalPolicyAssignmentRecord(m map[string]json.RawMessage, result interf if err != nil { return } + err = core.UnmarshalModel(m, "options", &obj.Options, UnmarshalPolicyAssignmentRequestOptionsItem) + if err != nil { + return + } err = core.UnmarshalPrimitive(m, "id", &obj.ID) if err != nil { return @@ -4051,15 +4346,63 @@ func UnmarshalPolicyAssignmentRecord(m map[string]json.RawMessage, result interf if err != nil { return } - err = core.UnmarshalModel(m, "options", &obj.Options, UnmarshalPolicyAssignmentOptions) + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalPolicyAssignmentResources) if err != nil { return } - err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalPolicyAssignmentResources) + err = core.UnmarshalPrimitive(m, "status", &obj.Status) if err != nil { return } - err = core.UnmarshalPrimitive(m, "status", &obj.Status) + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyAssignmentRequestOptionsItem : The set of properties required for a policy assignment. +type PolicyAssignmentRequestOptionsItem struct { + // The policy subject type; either 'iam_id' or 'access_group_id'. + SubjectType *string `json:"subject_type" validate:"required"` + + // The policy subject id. + SubjectID *string `json:"subject_id" validate:"required"` + + // The policy assignment requester id. + RootRequesterID *string `json:"root_requester_id" validate:"required"` + + // The template id where this policy is being assigned from. + RootTemplateID *string `json:"root_template_id,omitempty"` + + // The template version where this policy is being assigned from. + RootTemplateVersion *string `json:"root_template_version,omitempty"` +} + +// Constants associated with the PolicyAssignmentRequestOptionsItem.SubjectType property. +// The policy subject type; either 'iam_id' or 'access_group_id'. +const ( + PolicyAssignmentRequestOptionsItemSubjectTypeAccessGroupIDConst = "access_group_id" + PolicyAssignmentRequestOptionsItemSubjectTypeIamIDConst = "iam_id" +) + +// UnmarshalPolicyAssignmentRequestOptionsItem unmarshals an instance of PolicyAssignmentRequestOptionsItem from the specified map of raw messages. +func UnmarshalPolicyAssignmentRequestOptionsItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyAssignmentRequestOptionsItem) + err = core.UnmarshalPrimitive(m, "subject_type", &obj.SubjectType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "subject_id", &obj.SubjectID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "root_requester_id", &obj.RootRequesterID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "root_template_id", &obj.RootTemplateID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "root_template_version", &obj.RootTemplateVersion) if err != nil { return } @@ -4115,6 +4458,47 @@ func UnmarshalPolicyAssignmentResourcesPolicy(m map[string]json.RawMessage, resu return } +// PolicyCollection : A collection of policies. +type PolicyCollection struct { + // List of policies. + Policies []Policy `json:"policies,omitempty"` +} + +// UnmarshalPolicyCollection unmarshals an instance of PolicyCollection from the specified map of raw messages. +func UnmarshalPolicyCollection(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyCollection) + err = core.UnmarshalModel(m, "policies", &obj.Policies, UnmarshalPolicy) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyResource : The attributes of the resource. Note that only one resource is allowed in a policy. +type PolicyResource struct { + // List of resource attributes. + Attributes []ResourceAttribute `json:"attributes,omitempty"` + + // List of access management tags. + Tags []ResourceTag `json:"tags,omitempty"` +} + +// UnmarshalPolicyResource unmarshals an instance of PolicyResource from the specified map of raw messages. +func UnmarshalPolicyResource(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyResource) + err = core.UnmarshalModel(m, "attributes", &obj.Attributes, UnmarshalResourceAttribute) + if err != nil { + return + } + err = core.UnmarshalModel(m, "tags", &obj.Tags, UnmarshalResourceTag) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // PolicyRole : A role associated with a policy. type PolicyRole struct { // The role Cloud Resource Name (CRN) granted by the policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. @@ -4155,21 +4539,40 @@ func UnmarshalPolicyRole(m map[string]json.RawMessage, result interface{}) (err return } +// PolicySubject : The subject attribute values that must match in order for this policy to apply in a permission decision. +type PolicySubject struct { + // List of subject attributes. + Attributes []SubjectAttribute `json:"attributes,omitempty"` +} + +// UnmarshalPolicySubject unmarshals an instance of PolicySubject from the specified map of raw messages. +func UnmarshalPolicySubject(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicySubject) + err = core.UnmarshalModel(m, "attributes", &obj.Attributes, UnmarshalSubjectAttribute) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // PolicyTemplate : The core set of properties associated with the policy template. type PolicyTemplate struct { - // name of template. + // Required field when creating a new template. Otherwise this field is optional. If the field is included it will + // change the name value for all existing versions of the template. Name *string `json:"name" validate:"required"` - // description of template purpose. + // Description of the policy template. This is shown to users in the enterprise account. Use this to describe the + // purpose or context of the policy for enterprise users managing IAM templates. Description *string `json:"description,omitempty"` - // account id where this template will be created. + // Enterprise account ID where this template will be created. AccountID *string `json:"account_id" validate:"required"` - // Template vesrsion. + // Template version. Version *string `json:"version" validate:"required"` - // Template vesrsion committed status. + // Committed status of the template version. Committed *bool `json:"committed,omitempty"` // The core set of properties associated with the template's policy objet. @@ -4178,7 +4581,7 @@ type PolicyTemplate struct { // The policy template ID. ID *string `json:"id,omitempty"` - // The href URL that links to the policy templates API by policy tempalte ID. + // The href URL that links to the policy templates API by policy template ID. Href *string `json:"href,omitempty"` // The UTC timestamp when the policy template was created. @@ -4249,6 +4652,23 @@ func UnmarshalPolicyTemplate(m map[string]json.RawMessage, result interface{}) ( return } +// PolicyTemplateAssignmentCollection : A collection of policies assignments. +type PolicyTemplateAssignmentCollection struct { + // List of policy assignments. + Assignments []PolicyAssignment `json:"assignments,omitempty"` +} + +// UnmarshalPolicyTemplateAssignmentCollection unmarshals an instance of PolicyTemplateAssignmentCollection from the specified map of raw messages. +func UnmarshalPolicyTemplateAssignmentCollection(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyTemplateAssignmentCollection) + err = core.UnmarshalModel(m, "assignments", &obj.Assignments, UnmarshalPolicyAssignment) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // PolicyTemplateCollection : A collection of policy Templates. type PolicyTemplateCollection struct { // List of policy templates. @@ -4266,7 +4686,7 @@ func UnmarshalPolicyTemplateCollection(m map[string]json.RawMessage, result inte return } -// PolicyTemplateVersionsCollection : A collection of policy Template versions. +// PolicyTemplateVersionsCollection : A collection of versions for a specific policy template. type PolicyTemplateVersionsCollection struct { // List of policy templates versions. Versions []PolicyTemplate `json:"versions,omitempty"` @@ -4387,10 +4807,11 @@ type ReplacePolicyTemplateOptions struct { // The core set of properties associated with the template's policy objet. Policy *TemplatePolicy `json:"policy" validate:"required"` - // description of template purpose. + // Description of the policy template. This is shown to users in the enterprise account. Use this to describe the + // purpose or context of the policy for enterprise users managing IAM templates. Description *string `json:"description,omitempty"` - // Template vesrsion committed status. + // Committed status of the template version. Committed *bool `json:"committed,omitempty"` // Allows users to set headers on API requests @@ -4533,7 +4954,7 @@ type ReplaceV2PolicyOptions struct { // The policy type; either 'access' or 'authorization'. Type *string `json:"type" validate:"required"` - // Allows the customer to use their own words to record the purpose/context related to a policy. + // Description of the policy. Description *string `json:"description,omitempty"` // The subject attributes for whom the policy grants access. @@ -4630,30 +5051,40 @@ func (options *ReplaceV2PolicyOptions) SetHeaders(param map[string]string) *Repl return options } -// RoleAction : An action that can be performed by the policy subject when assigned role. -type RoleAction struct { - // Unique identifier for action with structure service.resource.action e.g., cbr.rule.read. - ID *string `json:"id" validate:"required"` +// ResourceAttribute : An attribute associated with a resource. +type ResourceAttribute struct { + // The name of an attribute. + Name *string `json:"name" validate:"required"` - // Service defined display name for action. - DisplayName *string `json:"display_name" validate:"required"` + // The value of an attribute. + Value *string `json:"value" validate:"required"` - // Service defined description for action. - Description *string `json:"description" validate:"required"` + // The operator of an attribute. + Operator *string `json:"operator,omitempty"` } -// UnmarshalRoleAction unmarshals an instance of RoleAction from the specified map of raw messages. -func UnmarshalRoleAction(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(RoleAction) - err = core.UnmarshalPrimitive(m, "id", &obj.ID) +// NewResourceAttribute : Instantiate ResourceAttribute (Generic Model Constructor) +func (*IamPolicyManagementV1) NewResourceAttribute(name string, value string) (_model *ResourceAttribute, err error) { + _model = &ResourceAttribute{ + Name: core.StringPtr(name), + Value: core.StringPtr(value), + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalResourceAttribute unmarshals an instance of ResourceAttribute from the specified map of raw messages. +func UnmarshalResourceAttribute(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ResourceAttribute) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) if err != nil { return } - err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) + err = core.UnmarshalPrimitive(m, "value", &obj.Value) if err != nil { return } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) if err != nil { return } @@ -4661,16 +5092,169 @@ func UnmarshalRoleAction(m map[string]json.RawMessage, result interface{}) (err return } -// Roles : A role associated with a policy. -type Roles struct { - // The role Cloud Resource Name (CRN) granted by the policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. - RoleID *string `json:"role_id" validate:"required"` +// ResourceTag : A tag associated with a resource. +type ResourceTag struct { + // The name of an access management tag. + Name *string `json:"name" validate:"required"` + + // The value of an access management tag. + Value *string `json:"value" validate:"required"` + + // The operator of an access management tag. + Operator *string `json:"operator,omitempty"` } -// NewRoles : Instantiate Roles (Generic Model Constructor) -func (*IamPolicyManagementV1) NewRoles(roleID string) (_model *Roles, err error) { - _model = &Roles{ - RoleID: core.StringPtr(roleID), +// NewResourceTag : Instantiate ResourceTag (Generic Model Constructor) +func (*IamPolicyManagementV1) NewResourceTag(name string, value string) (_model *ResourceTag, err error) { + _model = &ResourceTag{ + Name: core.StringPtr(name), + Value: core.StringPtr(value), + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalResourceTag unmarshals an instance of ResourceTag from the specified map of raw messages. +func UnmarshalResourceTag(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ResourceTag) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Role : A role resource. +type Role struct { + // The display name of the role that is shown in the console. + DisplayName *string `json:"display_name" validate:"required"` + + // The description of the role. + Description *string `json:"description,omitempty"` + + // The actions of the role. For more information, see [IAM roles and + // actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + Actions []string `json:"actions" validate:"required"` + + // The role Cloud Resource Name (CRN). Example CRN: + // 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. + CRN *string `json:"crn,omitempty"` +} + +// NewRole : Instantiate Role (Generic Model Constructor) +func (*IamPolicyManagementV1) NewRole(displayName string, actions []string) (_model *Role, err error) { + _model = &Role{ + DisplayName: core.StringPtr(displayName), + Actions: actions, + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalRole unmarshals an instance of Role from the specified map of raw messages. +func UnmarshalRole(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Role) + err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "actions", &obj.Actions) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RoleAction : An action that can be performed by the policy subject when assigned role. +type RoleAction struct { + // Unique identifier for action with structure service.resource.action e.g., cbr.rule.read. + ID *string `json:"id" validate:"required"` + + // Service defined display name for action. + DisplayName *string `json:"display_name" validate:"required"` + + // Service defined description for action. + Description *string `json:"description" validate:"required"` +} + +// UnmarshalRoleAction unmarshals an instance of RoleAction from the specified map of raw messages. +func UnmarshalRoleAction(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RoleAction) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RoleCollection : A collection of roles returned by the 'list roles' operation. +type RoleCollection struct { + // List of custom roles. + CustomRoles []CustomRole `json:"custom_roles,omitempty"` + + // List of service roles. + ServiceRoles []Role `json:"service_roles,omitempty"` + + // List of system roles. + SystemRoles []Role `json:"system_roles,omitempty"` +} + +// UnmarshalRoleCollection unmarshals an instance of RoleCollection from the specified map of raw messages. +func UnmarshalRoleCollection(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RoleCollection) + err = core.UnmarshalModel(m, "custom_roles", &obj.CustomRoles, UnmarshalCustomRole) + if err != nil { + return + } + err = core.UnmarshalModel(m, "service_roles", &obj.ServiceRoles, UnmarshalRole) + if err != nil { + return + } + err = core.UnmarshalModel(m, "system_roles", &obj.SystemRoles, UnmarshalRole) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Roles : A role associated with a policy. +type Roles struct { + // The role Cloud Resource Name (CRN) granted by the policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. + RoleID *string `json:"role_id" validate:"required"` +} + +// NewRoles : Instantiate Roles (Generic Model Constructor) +func (*IamPolicyManagementV1) NewRoles(roleID string) (_model *Roles, err error) { + _model = &Roles{ + RoleID: core.StringPtr(roleID), } err = core.ValidateStruct(_model, "required parameters") return @@ -4745,8 +5329,42 @@ func UnmarshalRuleAttribute(m map[string]json.RawMessage, result interface{}) (e return } -// TemplateMetada : Origin Template information. -type TemplateMetada struct { +// SubjectAttribute : An attribute associated with a subject. +type SubjectAttribute struct { + // The name of an attribute. + Name *string `json:"name" validate:"required"` + + // The value of an attribute. + Value *string `json:"value" validate:"required"` +} + +// NewSubjectAttribute : Instantiate SubjectAttribute (Generic Model Constructor) +func (*IamPolicyManagementV1) NewSubjectAttribute(name string, value string) (_model *SubjectAttribute, err error) { + _model = &SubjectAttribute{ + Name: core.StringPtr(name), + Value: core.StringPtr(value), + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalSubjectAttribute unmarshals an instance of SubjectAttribute from the specified map of raw messages. +func UnmarshalSubjectAttribute(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SubjectAttribute) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// TemplateMetadata : Origin Template information. +type TemplateMetadata struct { // Origin Template CRN. CRN *string `json:"crn,omitempty"` @@ -4754,9 +5372,9 @@ type TemplateMetada struct { Version *string `json:"version,omitempty"` } -// UnmarshalTemplateMetada unmarshals an instance of TemplateMetada from the specified map of raw messages. -func UnmarshalTemplateMetada(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(TemplateMetada) +// UnmarshalTemplateMetadata unmarshals an instance of TemplateMetadata from the specified map of raw messages. +func UnmarshalTemplateMetadata(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(TemplateMetadata) err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) if err != nil { return @@ -4774,7 +5392,8 @@ type TemplatePolicy struct { // The policy type; either 'access' or 'authorization'. Type *string `json:"type" validate:"required"` - // Allows the customer to use their own words to record the purpose/context related to a policy. + // Description of the policy. This is shown in child accounts when an access group or trusted profile template uses the + // policy template to assign access. Description *string `json:"description,omitempty"` // The resource attributes to which the policy grants access. @@ -4900,7 +5519,7 @@ type V2Policy struct { // The policy type; either 'access' or 'authorization'. Type *string `json:"type" validate:"required"` - // Allows the customer to use their own words to record the purpose/context related to a policy. + // Description of the policy. Description *string `json:"description,omitempty"` // The subject attributes for whom the policy grants access. @@ -4947,7 +5566,7 @@ type V2Policy struct { LastPermitFrequency *int64 `json:"last_permit_frequency,omitempty"` // Origin Template information. - Template *TemplateMetada `json:"template,omitempty"` + Template *TemplateMetadata `json:"template,omitempty"` } // Constants associated with the V2Policy.Type property. @@ -5031,7 +5650,7 @@ func UnmarshalV2Policy(m map[string]json.RawMessage, result interface{}) (err er if err != nil { return } - err = core.UnmarshalModel(m, "template", &obj.Template, UnmarshalTemplateMetada) + err = core.UnmarshalModel(m, "template", &obj.Template, UnmarshalTemplateMetadata) if err != nil { return } @@ -5328,611 +5947,6 @@ func UnmarshalV2PolicySubjectAttribute(m map[string]json.RawMessage, result inte return } -// ConflictsWith : Details of conflicting resource. -type ConflictsWith struct { - // The revision number of the resource. - Etag *string `json:"etag,omitempty"` - - // The conflicting role id. - Role *string `json:"role,omitempty"` - - // The conflicting policy id. - Policy *string `json:"policy,omitempty"` -} - -// UnmarshalConflictsWith unmarshals an instance of ConflictsWith from the specified map of raw messages. -func UnmarshalConflictsWith(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(ConflictsWith) - err = core.UnmarshalPrimitive(m, "etag", &obj.Etag) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "role", &obj.Role) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "policy", &obj.Policy) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// CustomRole : An additional set of properties associated with a role. -type CustomRole struct { - // The role ID. Composed of hexadecimal characters. - ID *string `json:"id,omitempty"` - - // The display name of the role that is shown in the console. - DisplayName *string `json:"display_name" validate:"required"` - - // The description of the role. - Description *string `json:"description,omitempty"` - - // The actions of the role. For more information, see [IAM roles and - // actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). - Actions []string `json:"actions" validate:"required"` - - // The role Cloud Resource Name (CRN). Example CRN: - // 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. - CRN *string `json:"crn,omitempty"` - - // The name of the role that is used in the CRN. Can only be alphanumeric and has to be capitalized. - Name *string `json:"name" validate:"required"` - - // The account GUID. - AccountID *string `json:"account_id" validate:"required"` - - // The service name. - ServiceName *string `json:"service_name" validate:"required"` - - // The UTC timestamp when the role was created. - CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` - - // The iam ID of the entity that created the role. - CreatedByID *string `json:"created_by_id,omitempty"` - - // The UTC timestamp when the role was last modified. - LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` - - // The iam ID of the entity that last modified the policy. - LastModifiedByID *string `json:"last_modified_by_id,omitempty"` - - // The href link back to the role. - Href *string `json:"href,omitempty"` -} - -// UnmarshalCustomRole unmarshals an instance of CustomRole from the specified map of raw messages. -func UnmarshalCustomRole(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(CustomRole) - err = core.UnmarshalPrimitive(m, "id", &obj.ID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "actions", &obj.Actions) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "name", &obj.Name) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "service_name", &obj.ServiceName) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "href", &obj.Href) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// ErrorDetails : Additional error details. -type ErrorDetails struct { - // Details of conflicting resource. - ConflictsWith *ConflictsWith `json:"conflicts_with,omitempty"` -} - -// UnmarshalErrorDetails unmarshals an instance of ErrorDetails from the specified map of raw messages. -func UnmarshalErrorDetails(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(ErrorDetails) - err = core.UnmarshalModel(m, "conflicts_with", &obj.ConflictsWith, UnmarshalConflictsWith) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// ErrorObject : ErrorObject struct -type ErrorObject struct { - // The API error code for the error. - Code *string `json:"code" validate:"required"` - - // The error message returned by the API. - Message *string `json:"message" validate:"required"` - - // Additional error details. - Details *ErrorDetails `json:"details,omitempty"` - - // Additional info for error. - MoreInfo *string `json:"more_info,omitempty"` -} - -// Constants associated with the ErrorObject.Code property. -// The API error code for the error. -const ( - ErrorObjectCodeInsufficentPermissionsConst = "insufficent_permissions" - ErrorObjectCodeInvalidBodyConst = "invalid_body" - ErrorObjectCodeInvalidTokenConst = "invalid_token" - ErrorObjectCodeMissingRequiredQueryParameterConst = "missing_required_query_parameter" - ErrorObjectCodeNotFoundConst = "not_found" - ErrorObjectCodePolicyAssignmentConflictErrorConst = "policy_assignment_conflict_error" - ErrorObjectCodePolicyAssignmentNotFoundConst = "policy_assignment_not_found" - ErrorObjectCodePolicyConflictErrorConst = "policy_conflict_error" - ErrorObjectCodePolicyNotFoundConst = "policy_not_found" - ErrorObjectCodePolicyTemplateConflictErrorConst = "policy_template_conflict_error" - ErrorObjectCodePolicyTemplateNotFoundConst = "policy_template_not_found" - ErrorObjectCodeRequestNotProcessedConst = "request_not_processed" - ErrorObjectCodeRoleConflictErrorConst = "role_conflict_error" - ErrorObjectCodeRoleNotFoundConst = "role_not_found" - ErrorObjectCodeTooManyRequestsConst = "too_many_requests" - ErrorObjectCodeUnableToProcessConst = "unable_to_process" - ErrorObjectCodeUnsupportedContentTypeConst = "unsupported_content_type" -) - -// UnmarshalErrorObject unmarshals an instance of ErrorObject from the specified map of raw messages. -func UnmarshalErrorObject(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(ErrorObject) - err = core.UnmarshalPrimitive(m, "code", &obj.Code) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "message", &obj.Message) - if err != nil { - return - } - err = core.UnmarshalModel(m, "details", &obj.Details, UnmarshalErrorDetails) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "more_info", &obj.MoreInfo) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// ErrorResponse : The error response from API. -type ErrorResponse struct { - // The unique transaction id for the request. - Trace *string `json:"trace,omitempty"` - - // The errors encountered during the response. - Errors []ErrorObject `json:"errors,omitempty"` - - // The http error code of the response. - StatusCode *int64 `json:"status_code,omitempty"` -} - -// UnmarshalErrorResponse unmarshals an instance of ErrorResponse from the specified map of raw messages. -func UnmarshalErrorResponse(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(ErrorResponse) - err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) - if err != nil { - return - } - err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalErrorObject) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// Policy : The core set of properties associated with a policy. -type Policy struct { - // The policy ID. - ID *string `json:"id,omitempty"` - - // The policy type; either 'access' or 'authorization'. - Type *string `json:"type" validate:"required"` - - // Customer-defined description. - Description *string `json:"description,omitempty"` - - // The subjects associated with a policy. - Subjects []PolicySubject `json:"subjects" validate:"required"` - - // A set of role cloud resource names (CRNs) granted by the policy. - Roles []PolicyRole `json:"roles" validate:"required"` - - // The resources associated with a policy. - Resources []PolicyResource `json:"resources" validate:"required"` - - // The href link back to the policy. - Href *string `json:"href,omitempty"` - - // The UTC timestamp when the policy was created. - CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` - - // The iam ID of the entity that created the policy. - CreatedByID *string `json:"created_by_id,omitempty"` - - // The UTC timestamp when the policy was last modified. - LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` - - // The iam ID of the entity that last modified the policy. - LastModifiedByID *string `json:"last_modified_by_id,omitempty"` - - // The policy state. - State *string `json:"state,omitempty"` - - // Origin Template information. - Template *TemplateMetada `json:"template,omitempty"` -} - -// Constants associated with the Policy.State property. -// The policy state. -const ( - PolicyStateActiveConst = "active" - PolicyStateDeletedConst = "deleted" -) - -// UnmarshalPolicy unmarshals an instance of Policy from the specified map of raw messages. -func UnmarshalPolicy(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Policy) - err = core.UnmarshalPrimitive(m, "id", &obj.ID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "type", &obj.Type) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) - if err != nil { - return - } - err = core.UnmarshalModel(m, "subjects", &obj.Subjects, UnmarshalPolicySubject) - if err != nil { - return - } - err = core.UnmarshalModel(m, "roles", &obj.Roles, UnmarshalPolicyRole) - if err != nil { - return - } - err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalPolicyResource) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "href", &obj.Href) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "state", &obj.State) - if err != nil { - return - } - err = core.UnmarshalModel(m, "template", &obj.Template, UnmarshalTemplateMetada) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// PolicyList : A collection of policies. -type PolicyList struct { - // List of policies. - Policies []Policy `json:"policies,omitempty"` -} - -// UnmarshalPolicyList unmarshals an instance of PolicyList from the specified map of raw messages. -func UnmarshalPolicyList(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(PolicyList) - err = core.UnmarshalModel(m, "policies", &obj.Policies, UnmarshalPolicy) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// PolicyResource : The attributes of the resource. Note that only one resource is allowed in a policy. -type PolicyResource struct { - // List of resource attributes. - Attributes []ResourceAttribute `json:"attributes,omitempty"` - - // List of access management tags. - Tags []ResourceTag `json:"tags,omitempty"` -} - -// UnmarshalPolicyResource unmarshals an instance of PolicyResource from the specified map of raw messages. -func UnmarshalPolicyResource(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(PolicyResource) - err = core.UnmarshalModel(m, "attributes", &obj.Attributes, UnmarshalResourceAttribute) - if err != nil { - return - } - err = core.UnmarshalModel(m, "tags", &obj.Tags, UnmarshalResourceTag) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// PolicySubject : The subject attribute values that must match in order for this policy to apply in a permission decision. -type PolicySubject struct { - // List of subject attributes. - Attributes []SubjectAttribute `json:"attributes,omitempty"` -} - -// UnmarshalPolicySubject unmarshals an instance of PolicySubject from the specified map of raw messages. -func UnmarshalPolicySubject(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(PolicySubject) - err = core.UnmarshalModel(m, "attributes", &obj.Attributes, UnmarshalSubjectAttribute) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// ResourceAttribute : An attribute associated with a resource. -type ResourceAttribute struct { - // The name of an attribute. - Name *string `json:"name" validate:"required"` - - // The value of an attribute. - Value *string `json:"value" validate:"required"` - - // The operator of an attribute. - Operator *string `json:"operator,omitempty"` -} - -// NewResourceAttribute : Instantiate ResourceAttribute (Generic Model Constructor) -func (*IamPolicyManagementV1) NewResourceAttribute(name string, value string) (_model *ResourceAttribute, err error) { - _model = &ResourceAttribute{ - Name: core.StringPtr(name), - Value: core.StringPtr(value), - } - err = core.ValidateStruct(_model, "required parameters") - return -} - -// UnmarshalResourceAttribute unmarshals an instance of ResourceAttribute from the specified map of raw messages. -func UnmarshalResourceAttribute(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(ResourceAttribute) - err = core.UnmarshalPrimitive(m, "name", &obj.Name) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "value", &obj.Value) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// ResourceTag : A tag associated with a resource. -type ResourceTag struct { - // The name of an access management tag. - Name *string `json:"name" validate:"required"` - - // The value of an access management tag. - Value *string `json:"value" validate:"required"` - - // The operator of an access management tag. - Operator *string `json:"operator,omitempty"` -} - -// NewResourceTag : Instantiate ResourceTag (Generic Model Constructor) -func (*IamPolicyManagementV1) NewResourceTag(name string, value string) (_model *ResourceTag, err error) { - _model = &ResourceTag{ - Name: core.StringPtr(name), - Value: core.StringPtr(value), - } - err = core.ValidateStruct(_model, "required parameters") - return -} - -// UnmarshalResourceTag unmarshals an instance of ResourceTag from the specified map of raw messages. -func UnmarshalResourceTag(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(ResourceTag) - err = core.UnmarshalPrimitive(m, "name", &obj.Name) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "value", &obj.Value) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// Role : A role resource. -type Role struct { - // The display name of the role that is shown in the console. - DisplayName *string `json:"display_name" validate:"required"` - - // The description of the role. - Description *string `json:"description,omitempty"` - - // The actions of the role. For more information, see [IAM roles and - // actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). - Actions []string `json:"actions" validate:"required"` - - // The role Cloud Resource Name (CRN). Example CRN: - // 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. - CRN *string `json:"crn,omitempty"` -} - -// NewRole : Instantiate Role (Generic Model Constructor) -func (*IamPolicyManagementV1) NewRole(displayName string, actions []string) (_model *Role, err error) { - _model = &Role{ - DisplayName: core.StringPtr(displayName), - Actions: actions, - } - err = core.ValidateStruct(_model, "required parameters") - return -} - -// UnmarshalRole unmarshals an instance of Role from the specified map of raw messages. -func UnmarshalRole(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Role) - err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "actions", &obj.Actions) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// RoleList : A collection of roles returned by the 'list roles' operation. -type RoleList struct { - // List of custom roles. - CustomRoles []CustomRole `json:"custom_roles,omitempty"` - - // List of service roles. - ServiceRoles []Role `json:"service_roles,omitempty"` - - // List of system roles. - SystemRoles []Role `json:"system_roles,omitempty"` -} - -// UnmarshalRoleList unmarshals an instance of RoleList from the specified map of raw messages. -func UnmarshalRoleList(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(RoleList) - err = core.UnmarshalModel(m, "custom_roles", &obj.CustomRoles, UnmarshalCustomRole) - if err != nil { - return - } - err = core.UnmarshalModel(m, "service_roles", &obj.ServiceRoles, UnmarshalRole) - if err != nil { - return - } - err = core.UnmarshalModel(m, "system_roles", &obj.SystemRoles, UnmarshalRole) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// SubjectAttribute : An attribute associated with a subject. -type SubjectAttribute struct { - // The name of an attribute. - Name *string `json:"name" validate:"required"` - - // The value of an attribute. - Value *string `json:"value" validate:"required"` -} - -// NewSubjectAttribute : Instantiate SubjectAttribute (Generic Model Constructor) -func (*IamPolicyManagementV1) NewSubjectAttribute(name string, value string) (_model *SubjectAttribute, err error) { - _model = &SubjectAttribute{ - Name: core.StringPtr(name), - Value: core.StringPtr(value), - } - err = core.ValidateStruct(_model, "required parameters") - return -} - -// UnmarshalSubjectAttribute unmarshals an instance of SubjectAttribute from the specified map of raw messages. -func UnmarshalSubjectAttribute(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(SubjectAttribute) - err = core.UnmarshalPrimitive(m, "name", &obj.Name) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "value", &obj.Value) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - // ControlResponseControl : Specifies the type of access granted by the policy. // This model "extends" ControlResponse type ControlResponseControl struct { diff --git a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go index 66d361c9..634a3084 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go @@ -978,23 +978,23 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(polcyTemplateAssignmentCollection).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TemplateID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TargetType).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TemplateVersion).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Target).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].AssignmentID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Options).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Status).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].AccountID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Resources).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].CreatedAt).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].CreatedByID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedAt).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedByID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Href).ToNot(BeNil()) - - testPolicyAssignmentId = *polcyTemplateAssignmentCollection.PolicyAssignments[0].ID + Expect(polcyTemplateAssignmentCollection.Assignments).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].TemplateID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].TargetType).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].TemplateVersion).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Target).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].AssignmentID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Options).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Status).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].AccountID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Resources).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].CreatedAt).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].CreatedByID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].LastModifiedAt).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].LastModifiedByID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Href).ToNot(BeNil()) + + testPolicyAssignmentId = *polcyTemplateAssignmentCollection.Assignments[0].ID }) It(`GetPolicyAssignment request example`, func() { diff --git a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go index 80576110..3b80e7ff 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go @@ -923,23 +923,23 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(polcyTemplateAssignmentCollection).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TemplateID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TargetType).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].TemplateVersion).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Target).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].AssignmentID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Options).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Status).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].AccountID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Resources).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].CreatedAt).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].CreatedByID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedAt).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].LastModifiedByID).ToNot(BeNil()) - Expect(polcyTemplateAssignmentCollection.PolicyAssignments[0].Href).ToNot(BeNil()) - - testPolicyAssignmentId = *polcyTemplateAssignmentCollection.PolicyAssignments[0].ID + Expect(polcyTemplateAssignmentCollection.Assignments).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].TemplateID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].TargetType).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].TemplateVersion).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Target).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].AssignmentID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Options).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Status).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].AccountID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Resources).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].CreatedAt).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].CreatedByID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].LastModifiedAt).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].LastModifiedByID).ToNot(BeNil()) + Expect(polcyTemplateAssignmentCollection.Assignments[0].Href).ToNot(BeNil()) + + testPolicyAssignmentId = *polcyTemplateAssignmentCollection.Assignments[0].ID }) }) diff --git a/iampolicymanagementv1/iam_policy_management_v1_test.go b/iampolicymanagementv1/iam_policy_management_v1_test.go index 949fc060..4454ff35 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_test.go @@ -7171,7 +7171,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policy_assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}]}`) + fmt.Fprintf(res, "%s", `{"assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}]}`) })) }) It(`Invoke ListPolicyAssignments successfully with retries`, func() { @@ -7233,7 +7233,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policy_assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}]}`) + fmt.Fprintf(res, "%s", `{"assignments": [{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}]}`) })) }) It(`Invoke ListPolicyAssignments successfully`, func() { @@ -7400,7 +7400,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}`) + fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}`) })) }) It(`Invoke GetPolicyAssignment successfully with retries`, func() { @@ -7454,7 +7454,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}`) + fmt.Fprintf(res, "%s", `{"template_id": "TemplateID", "template_version": "TemplateVersion", "assignment_id": "AssignmentID", "target_type": "Account", "target": "Target", "options": [{"subject_type": "iam_id", "subject_id": "SubjectID", "root_requester_id": "RootRequesterID", "root_template_id": "RootTemplateID", "root_template_version": "RootTemplateVersion"}], "id": "ID", "account_id": "AccountID", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "resources": [{"target": "Target", "policy": {"resource_created": {"id": "ID"}, "error_message": {"trace": "Trace", "errors": [{"code": "insufficent_permissions", "message": "Message", "details": {"conflicts_with": {"etag": "Etag", "role": "Role", "policy": "Policy"}}, "more_info": "MoreInfo"}], "status_code": 10}}}], "status": "in_progress"}`) })) }) It(`Invoke GetPolicyAssignment successfully`, func() { @@ -8493,6 +8493,27 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(replaceV2PolicyOptionsModel.Rule).To(Equal(v2PolicyRuleModel)) Expect(replaceV2PolicyOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewResourceAttribute successfully`, func() { + name := "testString" + value := "testString" + _model, err := iamPolicyManagementService.NewResourceAttribute(name, value) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewResourceTag successfully`, func() { + name := "testString" + value := "testString" + _model, err := iamPolicyManagementService.NewResourceTag(name, value) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRole successfully`, func() { + displayName := "testString" + actions := []string{"testString"} + _model, err := iamPolicyManagementService.NewRole(displayName, actions) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) It(`Invoke NewRoles successfully`, func() { roleID := "testString" _model, err := iamPolicyManagementService.NewRoles(roleID) @@ -8507,6 +8528,13 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(_model).ToNot(BeNil()) Expect(err).To(BeNil()) }) + It(`Invoke NewSubjectAttribute successfully`, func() { + name := "testString" + value := "testString" + _model, err := iamPolicyManagementService.NewSubjectAttribute(name, value) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) It(`Invoke NewTemplatePolicy successfully`, func() { typeVar := "access" var resource *iampolicymanagementv1.V2PolicyResource = nil @@ -8565,34 +8593,6 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(_model).ToNot(BeNil()) Expect(err).To(BeNil()) }) - It(`Invoke NewResourceAttribute successfully`, func() { - name := "testString" - value := "testString" - _model, err := iamPolicyManagementService.NewResourceAttribute(name, value) - Expect(_model).ToNot(BeNil()) - Expect(err).To(BeNil()) - }) - It(`Invoke NewResourceTag successfully`, func() { - name := "testString" - value := "testString" - _model, err := iamPolicyManagementService.NewResourceTag(name, value) - Expect(_model).ToNot(BeNil()) - Expect(err).To(BeNil()) - }) - It(`Invoke NewRole successfully`, func() { - displayName := "testString" - actions := []string{"testString"} - _model, err := iamPolicyManagementService.NewRole(displayName, actions) - Expect(_model).ToNot(BeNil()) - Expect(err).To(BeNil()) - }) - It(`Invoke NewSubjectAttribute successfully`, func() { - name := "testString" - value := "testString" - _model, err := iamPolicyManagementService.NewSubjectAttribute(name, value) - Expect(_model).ToNot(BeNil()) - Expect(err).To(BeNil()) - }) It(`Invoke NewV2PolicyRuleRuleAttribute successfully`, func() { key := "testString" operator := "timeLessThan"