From 2837a9840c828bafbbca2410485a8678f06ba7c8 Mon Sep 17 00:00:00 2001 From: vivekj3 <100437319+vivekj3@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:50:34 +0530 Subject: [PATCH] =?UTF-8?q?feat(IAM=20Policy=20Management):=20re-gen=20ser?= =?UTF-8?q?vice=20after=20recent=20API=20changes,=E2=80=A6=20(#259)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 | 4885 ++++++++++++----- .../iam_policy_management_v1_examples_test.go | 416 +- ...m_policy_management_v1_integration_test.go | 371 +- .../iam_policy_management_v1_test.go | 3489 +++++++++++- 4 files changed, 7654 insertions(+), 1507 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1.go b/iampolicymanagementv1/iam_policy_management_v1.go index 0d2d9778..eed7f91d 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 @@ -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,25 +1524,1731 @@ func (iamPolicyManagement *IamPolicyManagementV1) DeleteV2PolicyWithContext(ctx return } +// 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) +} + +// 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 +// 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) +} + +// 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 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) +} + +// 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 +// 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) +} + +// 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 +// 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) +} + +// 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 + } + if createPolicyTemplateVersionOptions.Committed != nil { + body["committed"] = createPolicyTemplateVersionOptions.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 +} + +// 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 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) +} + +// 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 + } + if replacePolicyTemplateOptions.Committed != nil { + body["committed"] = replacePolicyTemplateOptions.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 +} + +// 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) +} + +// 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 +// 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) +} + +// 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. 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) +} + +// 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 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 *PolicyTemplateAssignmentCollection, 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, UnmarshalPolicyTemplateAssignmentCollection) + if err != nil { + return + } + response.Result = result + } + + return +} + +// GetPolicyAssignment : Retrieve a policy assignment +// Retrieve a policy template assignment by providing a policy assignment ID. +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 *PolicyAssignment, 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, UnmarshalPolicyAssignment) + 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 +} + +// 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. Grant *Grant `json:"grant" validate:"required"` } -// NewControl : Instantiate Control (Generic Model Constructor) -func (*IamPolicyManagementV1) NewControl(grant *Grant) (_model *Control, err error) { - _model = &Control{ - Grant: grant, +// NewControl : Instantiate Control (Generic Model Constructor) +func (*IamPolicyManagementV1) NewControl(grant *Grant) (_model *Control, err error) { + _model = &Control{ + Grant: grant, + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalControl unmarshals an instance of Control from the specified map of raw messages. +func UnmarshalControl(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Control) + err = core.UnmarshalModel(m, "grant", &obj.Grant, UnmarshalGrant) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ControlResponse : ControlResponse struct +// Models which "extend" this model: +// - ControlResponseControl +// - ControlResponseControlWithEnrichedRoles +type ControlResponse struct { + // Permission granted by the policy. + Grant *Grant `json:"grant,omitempty"` +} +func (*ControlResponse) isaControlResponse() bool { + return true +} + +type ControlResponseIntf interface { + isaControlResponse() bool +} + +// UnmarshalControlResponse unmarshals an instance of ControlResponse from the specified map of raw messages. +func UnmarshalControlResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ControlResponse) + err = core.UnmarshalModel(m, "grant", &obj.Grant, UnmarshalGrant) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreatePolicyOptions : The CreatePolicy options. +type CreatePolicyOptions struct { + // The policy type; either 'access' or 'authorization'. + Type *string `json:"type" validate:"required"` + + // 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"` + + // Customer-defined description. + Description *string `json:"description,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 +} + +// NewCreatePolicyOptions : Instantiate CreatePolicyOptions +func (*IamPolicyManagementV1) NewCreatePolicyOptions(typeVar string, subjects []PolicySubject, roles []PolicyRole, resources []PolicyResource) *CreatePolicyOptions { + return &CreatePolicyOptions{ + Type: core.StringPtr(typeVar), + Subjects: subjects, + Roles: roles, + Resources: resources, + } +} + +// 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 { + // 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"` + + // 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 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 of 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 +} + +// SetAccountID : Allow user to set AccountID +func (_options *CreatePolicyTemplateOptions) SetAccountID(accountID string) *CreatePolicyTemplateOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetPolicy : Allow user to set Policy +func (_options *CreatePolicyTemplateOptions) SetPolicy(policy *TemplatePolicy) *CreatePolicyTemplateOptions { + _options.Policy = policy + return _options +} + +// SetDescription : Allow user to set Description +func (_options *CreatePolicyTemplateOptions) SetDescription(description string) *CreatePolicyTemplateOptions { + _options.Description = core.StringPtr(description) + return _options +} + +// 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 *CreatePolicyTemplateOptions) SetAcceptLanguage(acceptLanguage string) *CreatePolicyTemplateOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) + return _options +} + +// SetHeaders : Allow user to set Headers +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 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 of the template version. + Committed *bool `json:"committed,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 +} + +// 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 + return options +} + +// CreateRoleOptions : The CreateRole options. +type CreateRoleOptions struct { + // The display name of the role that is shown in the console. + DisplayName *string `json:"display_name" validate:"required"` + + // 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 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 description of the role. + Description *string `json:"description,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 +} + +// NewCreateRoleOptions : Instantiate CreateRoleOptions +func (*IamPolicyManagementV1) NewCreateRoleOptions(displayName string, actions []string, name string, accountID string, serviceName string) *CreateRoleOptions { + return &CreateRoleOptions{ + DisplayName: core.StringPtr(displayName), + Actions: actions, + Name: core.StringPtr(name), + AccountID: core.StringPtr(accountID), + ServiceName: core.StringPtr(serviceName), + } +} + +// SetDisplayName : Allow user to set DisplayName +func (_options *CreateRoleOptions) SetDisplayName(displayName string) *CreateRoleOptions { + _options.DisplayName = core.StringPtr(displayName) + return _options +} + +// SetActions : Allow user to set Actions +func (_options *CreateRoleOptions) SetActions(actions []string) *CreateRoleOptions { + _options.Actions = actions + return _options +} + +// SetName : Allow user to set Name +func (_options *CreateRoleOptions) SetName(name string) *CreateRoleOptions { + _options.Name = core.StringPtr(name) + return _options +} + +// SetAccountID : Allow user to set AccountID +func (_options *CreateRoleOptions) SetAccountID(accountID string) *CreateRoleOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetServiceName : Allow user to set ServiceName +func (_options *CreateRoleOptions) SetServiceName(serviceName string) *CreateRoleOptions { + _options.ServiceName = core.StringPtr(serviceName) + return _options +} + +// SetDescription : Allow user to set Description +func (_options *CreateRoleOptions) SetDescription(description string) *CreateRoleOptions { + _options.Description = core.StringPtr(description) + return _options +} + +// SetAcceptLanguage : Allow user to set AcceptLanguage +func (_options *CreateRoleOptions) SetAcceptLanguage(acceptLanguage string) *CreateRoleOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateRoleOptions) SetHeaders(param map[string]string) *CreateRoleOptions { + options.Headers = param + return options +} + +// CreateV2PolicyOptions : The CreateV2Policy options. +type CreateV2PolicyOptions struct { + // Specifies the type of access granted by the policy. + Control *Control `json:"control" validate:"required"` + + // The policy type; either 'access' or 'authorization'. + Type *string `json:"type" validate:"required"` + + // Description of the policy. + Description *string `json:"description,omitempty"` + + // The subject attributes for whom the policy grants access. + Subject *V2PolicySubject `json:"subject,omitempty"` + + // The resource attributes to which the policy grants access. + Resource *V2PolicyResource `json:"resource,omitempty"` + + // 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"` + + // 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 +} + +// Constants associated with the CreateV2PolicyOptions.Type property. +// The policy type; either 'access' or 'authorization'. +const ( + CreateV2PolicyOptionsTypeAccessConst = "access" + CreateV2PolicyOptionsTypeAuthorizationConst = "authorization" +) + +// NewCreateV2PolicyOptions : Instantiate CreateV2PolicyOptions +func (*IamPolicyManagementV1) NewCreateV2PolicyOptions(control *Control, typeVar string) *CreateV2PolicyOptions { + return &CreateV2PolicyOptions{ + Control: control, + Type: core.StringPtr(typeVar), + } +} + +// SetControl : Allow user to set Control +func (_options *CreateV2PolicyOptions) SetControl(control *Control) *CreateV2PolicyOptions { + _options.Control = control + return _options +} + +// SetType : Allow user to set Type +func (_options *CreateV2PolicyOptions) SetType(typeVar string) *CreateV2PolicyOptions { + _options.Type = core.StringPtr(typeVar) + return _options +} + +// SetDescription : Allow user to set Description +func (_options *CreateV2PolicyOptions) SetDescription(description string) *CreateV2PolicyOptions { + _options.Description = core.StringPtr(description) + return _options +} + +// SetSubject : Allow user to set Subject +func (_options *CreateV2PolicyOptions) SetSubject(subject *V2PolicySubject) *CreateV2PolicyOptions { + _options.Subject = subject + return _options +} + +// SetResource : Allow user to set Resource +func (_options *CreateV2PolicyOptions) SetResource(resource *V2PolicyResource) *CreateV2PolicyOptions { + _options.Resource = resource + return _options +} + +// SetPattern : Allow user to set Pattern +func (_options *CreateV2PolicyOptions) SetPattern(pattern string) *CreateV2PolicyOptions { + _options.Pattern = core.StringPtr(pattern) + return _options +} + +// SetRule : Allow user to set Rule +func (_options *CreateV2PolicyOptions) SetRule(rule V2PolicyRuleIntf) *CreateV2PolicyOptions { + _options.Rule = rule + return _options +} + +// SetAcceptLanguage : Allow user to set AcceptLanguage +func (_options *CreateV2PolicyOptions) SetAcceptLanguage(acceptLanguage string) *CreateV2PolicyOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateV2PolicyOptions) SetHeaders(param map[string]string) *CreateV2PolicyOptions { + options.Headers = param + 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.ValidateStruct(_model, "required parameters") + 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 } -// UnmarshalControl unmarshals an instance of Control from the specified map of raw messages. -func UnmarshalControl(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Control) - err = core.UnmarshalModel(m, "grant", &obj.Grant, UnmarshalGrant) +// DeletePolicyOptions : The DeletePolicy options. +type DeletePolicyOptions struct { + // The policy ID. + PolicyID *string `json:"policy_id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeletePolicyOptions : Instantiate DeletePolicyOptions +func (*IamPolicyManagementV1) NewDeletePolicyOptions(policyID string) *DeletePolicyOptions { + return &DeletePolicyOptions{ + PolicyID: core.StringPtr(policyID), + } +} + +// SetPolicyID : Allow user to set PolicyID +func (_options *DeletePolicyOptions) SetPolicyID(policyID string) *DeletePolicyOptions { + _options.PolicyID = core.StringPtr(policyID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeletePolicyOptions) SetHeaders(param map[string]string) *DeletePolicyOptions { + options.Headers = param + 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. + RoleID *string `json:"role_id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteRoleOptions : Instantiate DeleteRoleOptions +func (*IamPolicyManagementV1) NewDeleteRoleOptions(roleID string) *DeleteRoleOptions { + return &DeleteRoleOptions{ + RoleID: core.StringPtr(roleID), + } +} + +// SetRoleID : Allow user to set RoleID +func (_options *DeleteRoleOptions) SetRoleID(roleID string) *DeleteRoleOptions { + _options.RoleID = core.StringPtr(roleID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteRoleOptions) SetHeaders(param map[string]string) *DeleteRoleOptions { + options.Headers = param + return options +} + +// DeleteV2PolicyOptions : The DeleteV2Policy options. +type DeleteV2PolicyOptions struct { + // The policy ID. + ID *string `json:"id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteV2PolicyOptions : Instantiate DeleteV2PolicyOptions +func (*IamPolicyManagementV1) NewDeleteV2PolicyOptions(id string) *DeleteV2PolicyOptions { + return &DeleteV2PolicyOptions{ + ID: core.StringPtr(id), + } +} + +// SetID : Allow user to set ID +func (_options *DeleteV2PolicyOptions) SetID(id string) *DeleteV2PolicyOptions { + _options.ID = core.StringPtr(id) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteV2PolicyOptions) SetHeaders(param map[string]string) *DeleteV2PolicyOptions { + options.Headers = param + return options +} + +// EnrichedRoles : A role associated with a policy with additional information (display_name, description, actions) when +// `format=display`. +type EnrichedRoles 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"` + + // The service defined (or user defined if a custom role) display name of the role. + DisplayName *string `json:"display_name,omitempty"` + + // The service defined (or user defined if a custom role) 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 []RoleAction `json:"actions" validate:"required"` +} + +// UnmarshalEnrichedRoles unmarshals an instance of EnrichedRoles from the specified map of raw messages. +func UnmarshalEnrichedRoles(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(EnrichedRoles) + 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 + } + err = core.UnmarshalModel(m, "actions", &obj.Actions, UnmarshalRoleAction) + 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 } @@ -1550,26 +3256,30 @@ func UnmarshalControl(m map[string]json.RawMessage, result interface{}) (err err return } -// ControlResponse : ControlResponse struct -// Models which "extend" this model: -// - ControlResponseControl -// - ControlResponseControlWithEnrichedRoles -type ControlResponse struct { - // Permission granted by the policy. - Grant *Grant `json:"grant,omitempty"` -} -func (*ControlResponse) isaControlResponse() bool { - return true -} +// ErrorResponse : The error response from API. +type ErrorResponse struct { + // The unique transaction id for the request. + Trace *string `json:"trace,omitempty"` -type ControlResponseIntf interface { - isaControlResponse() bool + // The errors encountered during the response. + Errors []ErrorObject `json:"errors,omitempty"` + + // The http error code of the response. + StatusCode *int64 `json:"status_code,omitempty"` } -// UnmarshalControlResponse unmarshals an instance of ControlResponse from the specified map of raw messages. -func UnmarshalControlResponse(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(ControlResponse) - err = core.UnmarshalModel(m, "grant", &obj.Grant, UnmarshalGrant) +// 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 } @@ -1577,214 +3287,255 @@ func UnmarshalControlResponse(m map[string]json.RawMessage, result interface{}) return } -// CreatePolicyOptions : The CreatePolicy options. -type CreatePolicyOptions struct { - // The policy type; either 'access' or 'authorization'. - Type *string `json:"type" validate:"required"` +// GetPolicyAssignmentOptions : The GetPolicyAssignment options. +type GetPolicyAssignmentOptions struct { + // The policy template assignment ID. + AssignmentID *string `json:"assignment_id" validate:"required,ne="` - // The subjects associated with a policy. - Subjects []PolicySubject `json:"subjects" validate:"required"` + // Allows users to set headers on API requests + Headers map[string]string +} - // A set of role cloud resource names (CRNs) granted by the policy. - Roles []PolicyRole `json:"roles" validate:"required"` +// NewGetPolicyAssignmentOptions : Instantiate GetPolicyAssignmentOptions +func (*IamPolicyManagementV1) NewGetPolicyAssignmentOptions(assignmentID string) *GetPolicyAssignmentOptions { + return &GetPolicyAssignmentOptions{ + AssignmentID: core.StringPtr(assignmentID), + } +} - // The resources associated with a policy. - Resources []PolicyResource `json:"resources" validate:"required"` +// SetAssignmentID : Allow user to set AssignmentID +func (_options *GetPolicyAssignmentOptions) SetAssignmentID(assignmentID string) *GetPolicyAssignmentOptions { + _options.AssignmentID = core.StringPtr(assignmentID) + return _options +} - // Customer-defined description. - Description *string `json:"description,omitempty"` +// SetHeaders : Allow user to set Headers +func (options *GetPolicyAssignmentOptions) SetHeaders(param map[string]string) *GetPolicyAssignmentOptions { + options.Headers = param + return options +} - // 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"` +// GetPolicyOptions : The GetPolicy options. +type GetPolicyOptions struct { + // The policy ID. + PolicyID *string `json:"policy_id" validate:"required,ne="` // Allows users to set headers on API requests Headers map[string]string } -// NewCreatePolicyOptions : Instantiate CreatePolicyOptions -func (*IamPolicyManagementV1) NewCreatePolicyOptions(typeVar string, subjects []PolicySubject, roles []PolicyRole, resources []PolicyResource) *CreatePolicyOptions { - return &CreatePolicyOptions{ - Type: core.StringPtr(typeVar), - Subjects: subjects, - Roles: roles, - Resources: resources, +// NewGetPolicyOptions : Instantiate GetPolicyOptions +func (*IamPolicyManagementV1) NewGetPolicyOptions(policyID string) *GetPolicyOptions { + return &GetPolicyOptions{ + PolicyID: core.StringPtr(policyID), } } -// SetType : Allow user to set Type -func (_options *CreatePolicyOptions) SetType(typeVar string) *CreatePolicyOptions { - _options.Type = core.StringPtr(typeVar) +// SetPolicyID : Allow user to set PolicyID +func (_options *GetPolicyOptions) SetPolicyID(policyID string) *GetPolicyOptions { + _options.PolicyID = core.StringPtr(policyID) return _options } -// SetSubjects : Allow user to set Subjects -func (_options *CreatePolicyOptions) SetSubjects(subjects []PolicySubject) *CreatePolicyOptions { - _options.Subjects = subjects - return _options +// SetHeaders : Allow user to set Headers +func (options *GetPolicyOptions) SetHeaders(param map[string]string) *GetPolicyOptions { + options.Headers = param + return options } -// SetRoles : Allow user to set Roles -func (_options *CreatePolicyOptions) SetRoles(roles []PolicyRole) *CreatePolicyOptions { - _options.Roles = roles - return _options -} +// GetPolicyTemplateOptions : The GetPolicyTemplate options. +type GetPolicyTemplateOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` -// SetResources : Allow user to set Resources -func (_options *CreatePolicyOptions) SetResources(resources []PolicyResource) *CreatePolicyOptions { - _options.Resources = resources - return _options + // Allows users to set headers on API requests + Headers map[string]string } -// SetDescription : Allow user to set Description -func (_options *CreatePolicyOptions) SetDescription(description string) *CreatePolicyOptions { - _options.Description = core.StringPtr(description) - return _options +// NewGetPolicyTemplateOptions : Instantiate GetPolicyTemplateOptions +func (*IamPolicyManagementV1) NewGetPolicyTemplateOptions(policyTemplateID string) *GetPolicyTemplateOptions { + return &GetPolicyTemplateOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + } } -// SetAcceptLanguage : Allow user to set AcceptLanguage -func (_options *CreatePolicyOptions) SetAcceptLanguage(acceptLanguage string) *CreatePolicyOptions { - _options.AcceptLanguage = core.StringPtr(acceptLanguage) +// 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 *CreatePolicyOptions) SetHeaders(param map[string]string) *CreatePolicyOptions { +func (options *GetPolicyTemplateOptions) SetHeaders(param map[string]string) *GetPolicyTemplateOptions { options.Headers = param return options } -// CreateRoleOptions : The CreateRole options. -type CreateRoleOptions struct { - // The display name of the role that is shown in the console. - DisplayName *string `json:"display_name" validate:"required"` +// GetPolicyTemplateVersionOptions : The GetPolicyTemplateVersion options. +type GetPolicyTemplateVersionOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` - // 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 policy template version. + Version *string `json:"version" validate:"required,ne="` - // 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"` + // Allows users to set headers on API requests + Headers map[string]string +} - // The account GUID. - AccountID *string `json:"account_id" validate:"required"` +// NewGetPolicyTemplateVersionOptions : Instantiate GetPolicyTemplateVersionOptions +func (*IamPolicyManagementV1) NewGetPolicyTemplateVersionOptions(policyTemplateID string, version string) *GetPolicyTemplateVersionOptions { + return &GetPolicyTemplateVersionOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), + Version: core.StringPtr(version), + } +} - // The service name. - ServiceName *string `json:"service_name" validate:"required"` +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *GetPolicyTemplateVersionOptions) SetPolicyTemplateID(policyTemplateID string) *GetPolicyTemplateVersionOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options +} - // The description of the role. - Description *string `json:"description,omitempty"` +// SetVersion : Allow user to set Version +func (_options *GetPolicyTemplateVersionOptions) SetVersion(version string) *GetPolicyTemplateVersionOptions { + _options.Version = core.StringPtr(version) + return _options +} - // 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"` +// 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. + RoleID *string `json:"role_id" validate:"required,ne="` // Allows users to set headers on API requests Headers map[string]string } -// NewCreateRoleOptions : Instantiate CreateRoleOptions -func (*IamPolicyManagementV1) NewCreateRoleOptions(displayName string, actions []string, name string, accountID string, serviceName string) *CreateRoleOptions { - return &CreateRoleOptions{ - DisplayName: core.StringPtr(displayName), - Actions: actions, - Name: core.StringPtr(name), - AccountID: core.StringPtr(accountID), - ServiceName: core.StringPtr(serviceName), +// NewGetRoleOptions : Instantiate GetRoleOptions +func (*IamPolicyManagementV1) NewGetRoleOptions(roleID string) *GetRoleOptions { + return &GetRoleOptions{ + RoleID: core.StringPtr(roleID), } } -// SetDisplayName : Allow user to set DisplayName -func (_options *CreateRoleOptions) SetDisplayName(displayName string) *CreateRoleOptions { - _options.DisplayName = core.StringPtr(displayName) +// SetRoleID : Allow user to set RoleID +func (_options *GetRoleOptions) SetRoleID(roleID string) *GetRoleOptions { + _options.RoleID = core.StringPtr(roleID) return _options } -// SetActions : Allow user to set Actions -func (_options *CreateRoleOptions) SetActions(actions []string) *CreateRoleOptions { - _options.Actions = actions - return _options +// SetHeaders : Allow user to set Headers +func (options *GetRoleOptions) SetHeaders(param map[string]string) *GetRoleOptions { + options.Headers = param + return options } -// SetName : Allow user to set Name -func (_options *CreateRoleOptions) SetName(name string) *CreateRoleOptions { - _options.Name = core.StringPtr(name) - return _options -} +// GetV2PolicyOptions : The GetV2Policy options. +type GetV2PolicyOptions struct { + // The policy ID. + ID *string `json:"id" validate:"required,ne="` -// SetAccountID : Allow user to set AccountID -func (_options *CreateRoleOptions) SetAccountID(accountID string) *CreateRoleOptions { - _options.AccountID = core.StringPtr(accountID) - return _options + // Include additional data for 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 and translations for all relevant + // fields. + Format *string `json:"format,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string } -// SetServiceName : Allow user to set ServiceName -func (_options *CreateRoleOptions) SetServiceName(serviceName string) *CreateRoleOptions { - _options.ServiceName = core.StringPtr(serviceName) - return _options +// Constants associated with the GetV2PolicyOptions.Format property. +// Include additional data for 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 and translations for all relevant +// fields. +const ( + GetV2PolicyOptionsFormatDisplayConst = "display" + GetV2PolicyOptionsFormatIncludeLastPermitConst = "include_last_permit" +) + +// NewGetV2PolicyOptions : Instantiate GetV2PolicyOptions +func (*IamPolicyManagementV1) NewGetV2PolicyOptions(id string) *GetV2PolicyOptions { + return &GetV2PolicyOptions{ + ID: core.StringPtr(id), + } } -// SetDescription : Allow user to set Description -func (_options *CreateRoleOptions) SetDescription(description string) *CreateRoleOptions { - _options.Description = core.StringPtr(description) +// SetID : Allow user to set ID +func (_options *GetV2PolicyOptions) SetID(id string) *GetV2PolicyOptions { + _options.ID = core.StringPtr(id) return _options } -// SetAcceptLanguage : Allow user to set AcceptLanguage -func (_options *CreateRoleOptions) SetAcceptLanguage(acceptLanguage string) *CreateRoleOptions { - _options.AcceptLanguage = core.StringPtr(acceptLanguage) +// SetFormat : Allow user to set Format +func (_options *GetV2PolicyOptions) SetFormat(format string) *GetV2PolicyOptions { + _options.Format = core.StringPtr(format) return _options } // SetHeaders : Allow user to set Headers -func (options *CreateRoleOptions) SetHeaders(param map[string]string) *CreateRoleOptions { +func (options *GetV2PolicyOptions) SetHeaders(param map[string]string) *GetV2PolicyOptions { options.Headers = param return options } -// CreateV2PolicyOptions : The CreateV2Policy options. -type CreateV2PolicyOptions struct { - // Specifies the type of access granted by the policy. - Control *Control `json:"control" validate:"required"` - - // The policy type; either 'access' or 'authorization'. - Type *string `json:"type" validate:"required"` +// Grant : Permission granted by the policy. +type Grant struct { + // A set of role cloud resource names (CRNs) granted by the policy. + Roles []Roles `json:"roles" validate:"required"` +} - // Allows the customer to use their own words to record the purpose/context related to a policy. - Description *string `json:"description,omitempty"` +// NewGrant : Instantiate Grant (Generic Model Constructor) +func (*IamPolicyManagementV1) NewGrant(roles []Roles) (_model *Grant, err error) { + _model = &Grant{ + Roles: roles, + } + err = core.ValidateStruct(_model, "required parameters") + return +} - // The subject attributes for whom the policy grants access. - Subject *V2PolicySubject `json:"subject,omitempty"` +// UnmarshalGrant unmarshals an instance of Grant from the specified map of raw messages. +func UnmarshalGrant(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Grant) + err = core.UnmarshalModel(m, "roles", &obj.Roles, UnmarshalRoles) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} - // The resource attributes to which the policy grants access. - Resource *V2PolicyResource `json:"resource,omitempty"` +// GrantWithEnrichedRoles : Permission granted by the policy with translated roles and additional role information. +type GrantWithEnrichedRoles struct { + // A set of roles granted by the policy. + Roles []EnrichedRoles `json:"roles" 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"` +// UnmarshalGrantWithEnrichedRoles unmarshals an instance of GrantWithEnrichedRoles from the specified map of raw messages. +func UnmarshalGrantWithEnrichedRoles(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(GrantWithEnrichedRoles) + err = core.UnmarshalModel(m, "roles", &obj.Roles, UnmarshalEnrichedRoles) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} - // Additional access conditions associated with the policy. - Rule V2PolicyRuleIntf `json:"rule,omitempty"` +// ListPoliciesOptions : The ListPolicies options. +type ListPoliciesOptions struct { + // The account GUID that the policies belong to. + AccountID *string `json:"account_id" validate:"required"` // Language code for translations // * `default` - English @@ -1800,357 +3551,396 @@ type CreateV2PolicyOptions struct { // * `zh-tw` - (Chinese, Taiwan). AcceptLanguage *string `json:"Accept-Language,omitempty"` + // Optional IAM ID used to identify the subject. + IamID *string `json:"iam_id,omitempty"` + + // Optional access group id. + AccessGroupID *string `json:"access_group_id,omitempty"` + + // Optional type of policy. + Type *string `json:"type,omitempty"` + + // Optional type of service. + ServiceType *string `json:"service_type,omitempty"` + + // Optional name of the access tag in the policy. + TagName *string `json:"tag_name,omitempty"` + + // Optional value of the access tag in the policy. + TagValue *string `json:"tag_value,omitempty"` + + // Optional top level policy field to sort results. Ascending sort is default. Descending sort available by prepending + // '-' to field. Example '-last_modified_at'. + Sort *string `json:"sort,omitempty"` + + // 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. + Format *string `json:"format,omitempty"` + + // The state of the policy. + // * `active` - returns active policies + // * `deleted` - returns non-active policies. + State *string `json:"state,omitempty"` + // Allows users to set headers on API requests Headers map[string]string } -// Constants associated with the CreateV2PolicyOptions.Type property. -// The policy type; either 'access' or 'authorization'. +// Constants associated with the ListPoliciesOptions.Type property. +// Optional type of policy. const ( - CreateV2PolicyOptionsTypeAccessConst = "access" - CreateV2PolicyOptionsTypeAuthorizationConst = "authorization" + ListPoliciesOptionsTypeAccessConst = "access" + ListPoliciesOptionsTypeAuthorizationConst = "authorization" ) -// NewCreateV2PolicyOptions : Instantiate CreateV2PolicyOptions -func (*IamPolicyManagementV1) NewCreateV2PolicyOptions(control *Control, typeVar string) *CreateV2PolicyOptions { - return &CreateV2PolicyOptions{ - Control: control, - Type: core.StringPtr(typeVar), +// Constants associated with the ListPoliciesOptions.ServiceType property. +// Optional type of service. +const ( + ListPoliciesOptionsServiceTypePlatformServiceConst = "platform_service" + ListPoliciesOptionsServiceTypeServiceConst = "service" +) + +// Constants associated with the ListPoliciesOptions.Sort property. +// Optional top level policy field to sort results. Ascending sort is default. Descending sort available by prepending +// '-' to field. Example '-last_modified_at'. +const ( + ListPoliciesOptionsSortCreatedAtConst = "created_at" + ListPoliciesOptionsSortCreatedByIDConst = "created_by_id" + ListPoliciesOptionsSortHrefConst = "href" + ListPoliciesOptionsSortIDConst = "id" + ListPoliciesOptionsSortLastModifiedAtConst = "last_modified_at" + ListPoliciesOptionsSortLastModifiedByIDConst = "last_modified_by_id" + ListPoliciesOptionsSortStateConst = "state" + 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.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), } } -// SetControl : Allow user to set Control -func (_options *CreateV2PolicyOptions) SetControl(control *Control) *CreateV2PolicyOptions { - _options.Control = control +// SetAccountID : Allow user to set AccountID +func (_options *ListPoliciesOptions) SetAccountID(accountID string) *ListPoliciesOptions { + _options.AccountID = core.StringPtr(accountID) return _options } -// SetType : Allow user to set Type -func (_options *CreateV2PolicyOptions) SetType(typeVar string) *CreateV2PolicyOptions { - _options.Type = core.StringPtr(typeVar) +// SetAcceptLanguage : Allow user to set AcceptLanguage +func (_options *ListPoliciesOptions) SetAcceptLanguage(acceptLanguage string) *ListPoliciesOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) return _options } -// SetDescription : Allow user to set Description -func (_options *CreateV2PolicyOptions) SetDescription(description string) *CreateV2PolicyOptions { - _options.Description = core.StringPtr(description) +// SetIamID : Allow user to set IamID +func (_options *ListPoliciesOptions) SetIamID(iamID string) *ListPoliciesOptions { + _options.IamID = core.StringPtr(iamID) return _options } -// SetSubject : Allow user to set Subject -func (_options *CreateV2PolicyOptions) SetSubject(subject *V2PolicySubject) *CreateV2PolicyOptions { - _options.Subject = subject +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *ListPoliciesOptions) SetAccessGroupID(accessGroupID string) *ListPoliciesOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) return _options } -// SetResource : Allow user to set Resource -func (_options *CreateV2PolicyOptions) SetResource(resource *V2PolicyResource) *CreateV2PolicyOptions { - _options.Resource = resource +// SetType : Allow user to set Type +func (_options *ListPoliciesOptions) SetType(typeVar string) *ListPoliciesOptions { + _options.Type = core.StringPtr(typeVar) return _options } -// SetPattern : Allow user to set Pattern -func (_options *CreateV2PolicyOptions) SetPattern(pattern string) *CreateV2PolicyOptions { - _options.Pattern = core.StringPtr(pattern) +// SetServiceType : Allow user to set ServiceType +func (_options *ListPoliciesOptions) SetServiceType(serviceType string) *ListPoliciesOptions { + _options.ServiceType = core.StringPtr(serviceType) return _options } -// SetRule : Allow user to set Rule -func (_options *CreateV2PolicyOptions) SetRule(rule V2PolicyRuleIntf) *CreateV2PolicyOptions { - _options.Rule = rule +// SetTagName : Allow user to set TagName +func (_options *ListPoliciesOptions) SetTagName(tagName string) *ListPoliciesOptions { + _options.TagName = core.StringPtr(tagName) return _options } -// SetAcceptLanguage : Allow user to set AcceptLanguage -func (_options *CreateV2PolicyOptions) SetAcceptLanguage(acceptLanguage string) *CreateV2PolicyOptions { - _options.AcceptLanguage = core.StringPtr(acceptLanguage) +// SetTagValue : Allow user to set TagValue +func (_options *ListPoliciesOptions) SetTagValue(tagValue string) *ListPoliciesOptions { + _options.TagValue = core.StringPtr(tagValue) return _options } -// SetHeaders : Allow user to set Headers -func (options *CreateV2PolicyOptions) SetHeaders(param map[string]string) *CreateV2PolicyOptions { - options.Headers = param - return options -} - -// DeletePolicyOptions : The DeletePolicy options. -type DeletePolicyOptions struct { - // The policy ID. - PolicyID *string `json:"policy_id" validate:"required,ne="` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewDeletePolicyOptions : Instantiate DeletePolicyOptions -func (*IamPolicyManagementV1) NewDeletePolicyOptions(policyID string) *DeletePolicyOptions { - return &DeletePolicyOptions{ - PolicyID: core.StringPtr(policyID), - } -} - -// SetPolicyID : Allow user to set PolicyID -func (_options *DeletePolicyOptions) SetPolicyID(policyID string) *DeletePolicyOptions { - _options.PolicyID = core.StringPtr(policyID) +// 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 *DeletePolicyOptions) SetHeaders(param map[string]string) *DeletePolicyOptions { - options.Headers = param - return options -} - -// DeleteRoleOptions : The DeleteRole options. -type DeleteRoleOptions struct { - // The role ID. - RoleID *string `json:"role_id" validate:"required,ne="` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewDeleteRoleOptions : Instantiate DeleteRoleOptions -func (*IamPolicyManagementV1) NewDeleteRoleOptions(roleID string) *DeleteRoleOptions { - return &DeleteRoleOptions{ - RoleID: core.StringPtr(roleID), - } -} - -// SetRoleID : Allow user to set RoleID -func (_options *DeleteRoleOptions) SetRoleID(roleID string) *DeleteRoleOptions { - _options.RoleID = core.StringPtr(roleID) +// SetFormat : Allow user to set Format +func (_options *ListPoliciesOptions) SetFormat(format string) *ListPoliciesOptions { + _options.Format = core.StringPtr(format) return _options } -// SetHeaders : Allow user to set Headers -func (options *DeleteRoleOptions) SetHeaders(param map[string]string) *DeleteRoleOptions { - options.Headers = param - return options -} - -// DeleteV2PolicyOptions : The DeleteV2Policy options. -type DeleteV2PolicyOptions struct { - // The policy ID. - ID *string `json:"id" validate:"required,ne="` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewDeleteV2PolicyOptions : Instantiate DeleteV2PolicyOptions -func (*IamPolicyManagementV1) NewDeleteV2PolicyOptions(id string) *DeleteV2PolicyOptions { - return &DeleteV2PolicyOptions{ - ID: core.StringPtr(id), - } -} - -// SetID : Allow user to set ID -func (_options *DeleteV2PolicyOptions) SetID(id string) *DeleteV2PolicyOptions { - _options.ID = core.StringPtr(id) +// 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 *DeleteV2PolicyOptions) SetHeaders(param map[string]string) *DeleteV2PolicyOptions { +func (options *ListPoliciesOptions) SetHeaders(param map[string]string) *ListPoliciesOptions { options.Headers = param return options } -// EnrichedRoles : A role associated with a policy with additional information (display_name, description, actions) when -// `format=display`. -type EnrichedRoles 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"` +// ListPolicyAssignmentsOptions : The ListPolicyAssignments options. +type ListPolicyAssignmentsOptions struct { + // The account GUID in which the policies belong to. + AccountID *string `json:"account_id" validate:"required"` - // The service defined (or user defined if a custom role) display name of the role. - DisplayName *string `json:"display_name,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"` - // The service defined (or user defined if a custom role) description of the role. - Description *string `json:"description,omitempty"` + // Optional template id. + TemplateID *string `json:"template_id,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 []RoleAction `json:"actions" validate:"required"` + // Optional policy template version. + TemplateVersion *string `json:"template_version,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string } -// UnmarshalEnrichedRoles unmarshals an instance of EnrichedRoles from the specified map of raw messages. -func UnmarshalEnrichedRoles(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(EnrichedRoles) - 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 - } - err = core.UnmarshalModel(m, "actions", &obj.Actions, UnmarshalRoleAction) - if err != nil { - return +// NewListPolicyAssignmentsOptions : Instantiate ListPolicyAssignmentsOptions +func (*IamPolicyManagementV1) NewListPolicyAssignmentsOptions(accountID string) *ListPolicyAssignmentsOptions { + return &ListPolicyAssignmentsOptions{ + AccountID: core.StringPtr(accountID), } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return } -// GetPolicyOptions : The GetPolicy options. -type GetPolicyOptions struct { - // The policy ID. - PolicyID *string `json:"policy_id" validate:"required,ne="` +// SetAccountID : Allow user to set AccountID +func (_options *ListPolicyAssignmentsOptions) SetAccountID(accountID string) *ListPolicyAssignmentsOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} - // Allows users to set headers on API requests - Headers map[string]string +// SetAcceptLanguage : Allow user to set AcceptLanguage +func (_options *ListPolicyAssignmentsOptions) SetAcceptLanguage(acceptLanguage string) *ListPolicyAssignmentsOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) + return _options } -// NewGetPolicyOptions : Instantiate GetPolicyOptions -func (*IamPolicyManagementV1) NewGetPolicyOptions(policyID string) *GetPolicyOptions { - return &GetPolicyOptions{ - PolicyID: core.StringPtr(policyID), - } +// SetTemplateID : Allow user to set TemplateID +func (_options *ListPolicyAssignmentsOptions) SetTemplateID(templateID string) *ListPolicyAssignmentsOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options } -// SetPolicyID : Allow user to set PolicyID -func (_options *GetPolicyOptions) SetPolicyID(policyID string) *GetPolicyOptions { - _options.PolicyID = core.StringPtr(policyID) +// SetTemplateVersion : Allow user to set TemplateVersion +func (_options *ListPolicyAssignmentsOptions) SetTemplateVersion(templateVersion string) *ListPolicyAssignmentsOptions { + _options.TemplateVersion = core.StringPtr(templateVersion) return _options } // SetHeaders : Allow user to set Headers -func (options *GetPolicyOptions) SetHeaders(param map[string]string) *GetPolicyOptions { +func (options *ListPolicyAssignmentsOptions) SetHeaders(param map[string]string) *ListPolicyAssignmentsOptions { options.Headers = param return options } -// GetRoleOptions : The GetRole options. -type GetRoleOptions struct { - // The role ID. - RoleID *string `json:"role_id" validate:"required,ne="` +// 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 } -// NewGetRoleOptions : Instantiate GetRoleOptions -func (*IamPolicyManagementV1) NewGetRoleOptions(roleID string) *GetRoleOptions { - return &GetRoleOptions{ - RoleID: core.StringPtr(roleID), +// NewListPolicyTemplateVersionsOptions : Instantiate ListPolicyTemplateVersionsOptions +func (*IamPolicyManagementV1) NewListPolicyTemplateVersionsOptions(policyTemplateID string) *ListPolicyTemplateVersionsOptions { + return &ListPolicyTemplateVersionsOptions{ + PolicyTemplateID: core.StringPtr(policyTemplateID), } } -// SetRoleID : Allow user to set RoleID -func (_options *GetRoleOptions) SetRoleID(roleID string) *GetRoleOptions { - _options.RoleID = core.StringPtr(roleID) +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *ListPolicyTemplateVersionsOptions) SetPolicyTemplateID(policyTemplateID string) *ListPolicyTemplateVersionsOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) return _options } // SetHeaders : Allow user to set Headers -func (options *GetRoleOptions) SetHeaders(param map[string]string) *GetRoleOptions { +func (options *ListPolicyTemplateVersionsOptions) SetHeaders(param map[string]string) *ListPolicyTemplateVersionsOptions { options.Headers = param return options } -// GetV2PolicyOptions : The GetV2Policy options. -type GetV2PolicyOptions struct { - // The policy ID. - ID *string `json:"id" validate:"required,ne="` +// ListPolicyTemplatesOptions : The ListPolicyTemplates options. +type ListPolicyTemplatesOptions struct { + // The account GUID that the policy templates belong to. + AccountID *string `json:"account_id" validate:"required"` - // Include additional data for 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 and translations for all relevant - // fields. - Format *string `json:"format,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 } -// Constants associated with the GetV2PolicyOptions.Format property. -// Include additional data for 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 and translations for all relevant -// fields. -const ( - GetV2PolicyOptionsFormatDisplayConst = "display" - GetV2PolicyOptionsFormatIncludeLastPermitConst = "include_last_permit" -) - -// NewGetV2PolicyOptions : Instantiate GetV2PolicyOptions -func (*IamPolicyManagementV1) NewGetV2PolicyOptions(id string) *GetV2PolicyOptions { - return &GetV2PolicyOptions{ - ID: core.StringPtr(id), +// NewListPolicyTemplatesOptions : Instantiate ListPolicyTemplatesOptions +func (*IamPolicyManagementV1) NewListPolicyTemplatesOptions(accountID string) *ListPolicyTemplatesOptions { + return &ListPolicyTemplatesOptions{ + AccountID: core.StringPtr(accountID), } } -// SetID : Allow user to set ID -func (_options *GetV2PolicyOptions) SetID(id string) *GetV2PolicyOptions { - _options.ID = core.StringPtr(id) +// SetAccountID : Allow user to set AccountID +func (_options *ListPolicyTemplatesOptions) SetAccountID(accountID string) *ListPolicyTemplatesOptions { + _options.AccountID = core.StringPtr(accountID) return _options } -// SetFormat : Allow user to set Format -func (_options *GetV2PolicyOptions) SetFormat(format string) *GetV2PolicyOptions { - _options.Format = core.StringPtr(format) +// 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 *GetV2PolicyOptions) SetHeaders(param map[string]string) *GetV2PolicyOptions { +func (options *ListPolicyTemplatesOptions) SetHeaders(param map[string]string) *ListPolicyTemplatesOptions { options.Headers = param return options } -// Grant : Permission granted by the policy. -type Grant struct { - // A set of role cloud resource names (CRNs) granted by the policy. - Roles []Roles `json:"roles" validate:"required"` +// ListRolesOptions : The ListRoles options. +type ListRolesOptions struct { + // 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 account GUID in which the roles belong to. + AccountID *string `json:"account_id,omitempty"` + + // Optional name of IAM enabled service. + ServiceName *string `json:"service_name,omitempty"` + + // Optional name of source IAM enabled service. + SourceServiceName *string `json:"source_service_name,omitempty"` + + // Optional Policy Type. + PolicyType *string `json:"policy_type,omitempty"` + + // Optional id of service group. + ServiceGroupID *string `json:"service_group_id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string } -// NewGrant : Instantiate Grant (Generic Model Constructor) -func (*IamPolicyManagementV1) NewGrant(roles []Roles) (_model *Grant, err error) { - _model = &Grant{ - Roles: roles, - } - err = core.ValidateStruct(_model, "required parameters") - return +// NewListRolesOptions : Instantiate ListRolesOptions +func (*IamPolicyManagementV1) NewListRolesOptions() *ListRolesOptions { + return &ListRolesOptions{} } -// UnmarshalGrant unmarshals an instance of Grant from the specified map of raw messages. -func UnmarshalGrant(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Grant) - err = core.UnmarshalModel(m, "roles", &obj.Roles, UnmarshalRoles) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return +// SetAcceptLanguage : Allow user to set AcceptLanguage +func (_options *ListRolesOptions) SetAcceptLanguage(acceptLanguage string) *ListRolesOptions { + _options.AcceptLanguage = core.StringPtr(acceptLanguage) + return _options } -// GrantWithEnrichedRoles : Permission granted by the policy with translated roles and additional role information. -type GrantWithEnrichedRoles struct { - // A set of roles granted by the policy. - Roles []EnrichedRoles `json:"roles" validate:"required"` +// SetAccountID : Allow user to set AccountID +func (_options *ListRolesOptions) SetAccountID(accountID string) *ListRolesOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } -// UnmarshalGrantWithEnrichedRoles unmarshals an instance of GrantWithEnrichedRoles from the specified map of raw messages. -func UnmarshalGrantWithEnrichedRoles(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(GrantWithEnrichedRoles) - err = core.UnmarshalModel(m, "roles", &obj.Roles, UnmarshalEnrichedRoles) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return +// SetServiceName : Allow user to set ServiceName +func (_options *ListRolesOptions) SetServiceName(serviceName string) *ListRolesOptions { + _options.ServiceName = core.StringPtr(serviceName) + return _options } -// ListPoliciesOptions : The ListPolicies options. -type ListPoliciesOptions struct { - // The account GUID that the policies belong to. +// SetSourceServiceName : Allow user to set SourceServiceName +func (_options *ListRolesOptions) SetSourceServiceName(sourceServiceName string) *ListRolesOptions { + _options.SourceServiceName = core.StringPtr(sourceServiceName) + return _options +} + +// SetPolicyType : Allow user to set PolicyType +func (_options *ListRolesOptions) SetPolicyType(policyType string) *ListRolesOptions { + _options.PolicyType = core.StringPtr(policyType) + return _options +} + +// SetServiceGroupID : Allow user to set ServiceGroupID +func (_options *ListRolesOptions) SetServiceGroupID(serviceGroupID string) *ListRolesOptions { + _options.ServiceGroupID = core.StringPtr(serviceGroupID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListRolesOptions) SetHeaders(param map[string]string) *ListRolesOptions { + options.Headers = param + return options +} + +// ListV2PoliciesOptions : The ListV2Policies options. +type ListV2PoliciesOptions struct { + // The account GUID in which the policies belong to. AccountID *string `json:"account_id" validate:"required"` // Language code for translations @@ -2179,20 +3969,33 @@ type ListPoliciesOptions struct { // Optional type of service. ServiceType *string `json:"service_type,omitempty"` - // Optional name of the access tag in the policy. - TagName *string `json:"tag_name,omitempty"` + // Optional name of service. + ServiceName *string `json:"service_name,omitempty"` - // Optional value of the access tag in the policy. - TagValue *string `json:"tag_value,omitempty"` + // Optional ID of service group. + ServiceGroupID *string `json:"service_group_id,omitempty"` // Optional top level policy field to sort results. Ascending sort is default. Descending sort available by prepending - // '-' to field. Example '-last_modified_at'. + // '-' to field, for example, '-last_modified_at'. Note that last permit information is only included when + // 'format=include_last_permit', for example, "format=include_last_permit&sort=last_permit_at" Example fields that can + // be sorted on: + // - 'id' + // - 'type' + // - 'href' + // - 'created_at' + // - 'created_by_id' + // - 'last_modified_at' + // - 'last_modified_by_id' + // - 'state' + // - 'last_permit_at' + // - 'last_permit_frequency'. Sort *string `json:"sort,omitempty"` // 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. + // * `display` - returns the list of all actions included in each of the policy roles and translations for all relevant + // fields. Format *string `json:"format,omitempty"` // The state of the policy. @@ -2204,394 +4007,496 @@ type ListPoliciesOptions struct { Headers map[string]string } -// Constants associated with the ListPoliciesOptions.Type property. +// Constants associated with the ListV2PoliciesOptions.Type property. // Optional type of policy. const ( - ListPoliciesOptionsTypeAccessConst = "access" - ListPoliciesOptionsTypeAuthorizationConst = "authorization" + ListV2PoliciesOptionsTypeAccessConst = "access" + ListV2PoliciesOptionsTypeAuthorizationConst = "authorization" ) -// Constants associated with the ListPoliciesOptions.ServiceType property. +// Constants associated with the ListV2PoliciesOptions.ServiceType property. // Optional type of service. const ( - ListPoliciesOptionsServiceTypePlatformServiceConst = "platform_service" - ListPoliciesOptionsServiceTypeServiceConst = "service" -) - -// Constants associated with the ListPoliciesOptions.Sort property. -// Optional top level policy field to sort results. Ascending sort is default. Descending sort available by prepending -// '-' to field. Example '-last_modified_at'. -const ( - ListPoliciesOptionsSortCreatedAtConst = "created_at" - ListPoliciesOptionsSortCreatedByIDConst = "created_by_id" - ListPoliciesOptionsSortHrefConst = "href" - ListPoliciesOptionsSortIDConst = "id" - ListPoliciesOptionsSortLastModifiedAtConst = "last_modified_at" - ListPoliciesOptionsSortLastModifiedByIDConst = "last_modified_by_id" - ListPoliciesOptionsSortStateConst = "state" - ListPoliciesOptionsSortTypeConst = "type" + ListV2PoliciesOptionsServiceTypePlatformServiceConst = "platform_service" + ListV2PoliciesOptionsServiceTypeServiceConst = "service" ) -// Constants associated with the ListPoliciesOptions.Format property. +// Constants associated with the ListV2PoliciesOptions.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. +// * `display` - returns the list of all actions included in each of the policy roles and translations for all relevant +// fields. const ( - ListPoliciesOptionsFormatDisplayConst = "display" - ListPoliciesOptionsFormatIncludeLastPermitConst = "include_last_permit" + ListV2PoliciesOptionsFormatDisplayConst = "display" + ListV2PoliciesOptionsFormatIncludeLastPermitConst = "include_last_permit" ) -// Constants associated with the ListPoliciesOptions.State property. +// Constants associated with the ListV2PoliciesOptions.State property. // The state of the policy. // * `active` - returns active policies // * `deleted` - returns non-active policies. const ( - ListPoliciesOptionsStateActiveConst = "active" - ListPoliciesOptionsStateDeletedConst = "deleted" + ListV2PoliciesOptionsStateActiveConst = "active" + ListV2PoliciesOptionsStateDeletedConst = "deleted" ) -// NewListPoliciesOptions : Instantiate ListPoliciesOptions -func (*IamPolicyManagementV1) NewListPoliciesOptions(accountID string) *ListPoliciesOptions { - return &ListPoliciesOptions{ +// NewListV2PoliciesOptions : Instantiate ListV2PoliciesOptions +func (*IamPolicyManagementV1) NewListV2PoliciesOptions(accountID string) *ListV2PoliciesOptions { + return &ListV2PoliciesOptions{ AccountID: core.StringPtr(accountID), } } // SetAccountID : Allow user to set AccountID -func (_options *ListPoliciesOptions) SetAccountID(accountID string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetAccountID(accountID string) *ListV2PoliciesOptions { _options.AccountID = core.StringPtr(accountID) return _options } // SetAcceptLanguage : Allow user to set AcceptLanguage -func (_options *ListPoliciesOptions) SetAcceptLanguage(acceptLanguage string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetAcceptLanguage(acceptLanguage string) *ListV2PoliciesOptions { _options.AcceptLanguage = core.StringPtr(acceptLanguage) return _options } // SetIamID : Allow user to set IamID -func (_options *ListPoliciesOptions) SetIamID(iamID string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetIamID(iamID string) *ListV2PoliciesOptions { _options.IamID = core.StringPtr(iamID) return _options } // SetAccessGroupID : Allow user to set AccessGroupID -func (_options *ListPoliciesOptions) SetAccessGroupID(accessGroupID string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetAccessGroupID(accessGroupID string) *ListV2PoliciesOptions { _options.AccessGroupID = core.StringPtr(accessGroupID) return _options } // SetType : Allow user to set Type -func (_options *ListPoliciesOptions) SetType(typeVar string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetType(typeVar string) *ListV2PoliciesOptions { _options.Type = core.StringPtr(typeVar) return _options } // SetServiceType : Allow user to set ServiceType -func (_options *ListPoliciesOptions) SetServiceType(serviceType string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetServiceType(serviceType string) *ListV2PoliciesOptions { _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) +// SetServiceName : Allow user to set ServiceName +func (_options *ListV2PoliciesOptions) SetServiceName(serviceName string) *ListV2PoliciesOptions { + _options.ServiceName = core.StringPtr(serviceName) return _options } -// SetTagValue : Allow user to set TagValue -func (_options *ListPoliciesOptions) SetTagValue(tagValue string) *ListPoliciesOptions { - _options.TagValue = core.StringPtr(tagValue) +// SetServiceGroupID : Allow user to set ServiceGroupID +func (_options *ListV2PoliciesOptions) SetServiceGroupID(serviceGroupID string) *ListV2PoliciesOptions { + _options.ServiceGroupID = core.StringPtr(serviceGroupID) return _options } // SetSort : Allow user to set Sort -func (_options *ListPoliciesOptions) SetSort(sort string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetSort(sort string) *ListV2PoliciesOptions { _options.Sort = core.StringPtr(sort) return _options } // SetFormat : Allow user to set Format -func (_options *ListPoliciesOptions) SetFormat(format string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetFormat(format string) *ListV2PoliciesOptions { _options.Format = core.StringPtr(format) return _options } // SetState : Allow user to set State -func (_options *ListPoliciesOptions) SetState(state string) *ListPoliciesOptions { +func (_options *ListV2PoliciesOptions) SetState(state string) *ListV2PoliciesOptions { _options.State = core.StringPtr(state) return _options } // SetHeaders : Allow user to set Headers -func (options *ListPoliciesOptions) SetHeaders(param map[string]string) *ListPoliciesOptions { +func (options *ListV2PoliciesOptions) SetHeaders(param map[string]string) *ListV2PoliciesOptions { options.Headers = param return options } -// ListRolesOptions : The ListRoles options. -type ListRolesOptions struct { - // 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"` +// Policy : The core set of properties associated with a policy. +type Policy struct { + // The policy ID. + ID *string `json:"id,omitempty"` - // Optional account GUID in which the roles belong to. - AccountID *string `json:"account_id,omitempty"` + // The policy type; either 'access' or 'authorization'. + Type *string `json:"type" validate:"required"` - // Optional name of IAM enabled service. - ServiceName *string `json:"service_name,omitempty"` + // Customer-defined description. + Description *string `json:"description,omitempty"` - // Optional name of source IAM enabled service. - SourceServiceName *string `json:"source_service_name,omitempty"` + // The subjects associated with a policy. + Subjects []PolicySubject `json:"subjects" validate:"required"` - // Optional Policy Type. - PolicyType *string `json:"policy_type,omitempty"` + // A set of role cloud resource names (CRNs) granted by the policy. + Roles []PolicyRole `json:"roles" validate:"required"` - // Optional id of service group. - ServiceGroupID *string `json:"service_group_id,omitempty"` + // The resources associated with a policy. + Resources []PolicyResource `json:"resources" validate:"required"` - // Allows users to set headers on API requests - Headers map[string]string -} + // The href link back to the policy. + Href *string `json:"href,omitempty"` -// NewListRolesOptions : Instantiate ListRolesOptions -func (*IamPolicyManagementV1) NewListRolesOptions() *ListRolesOptions { - return &ListRolesOptions{} -} + // The UTC timestamp when the policy was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` -// SetAcceptLanguage : Allow user to set AcceptLanguage -func (_options *ListRolesOptions) SetAcceptLanguage(acceptLanguage string) *ListRolesOptions { - _options.AcceptLanguage = core.StringPtr(acceptLanguage) - return _options -} + // The iam ID of the entity that created the policy. + CreatedByID *string `json:"created_by_id,omitempty"` -// SetAccountID : Allow user to set AccountID -func (_options *ListRolesOptions) SetAccountID(accountID string) *ListRolesOptions { - _options.AccountID = core.StringPtr(accountID) - return _options -} + // The UTC timestamp when the policy was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` -// SetServiceName : Allow user to set ServiceName -func (_options *ListRolesOptions) SetServiceName(serviceName string) *ListRolesOptions { - _options.ServiceName = core.StringPtr(serviceName) - return _options -} + // The iam ID of the entity that last modified the policy. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` -// SetSourceServiceName : Allow user to set SourceServiceName -func (_options *ListRolesOptions) SetSourceServiceName(sourceServiceName string) *ListRolesOptions { - _options.SourceServiceName = core.StringPtr(sourceServiceName) - return _options -} + // The policy state. + State *string `json:"state,omitempty"` -// SetPolicyType : Allow user to set PolicyType -func (_options *ListRolesOptions) SetPolicyType(policyType string) *ListRolesOptions { - _options.PolicyType = core.StringPtr(policyType) - return _options + // Origin Template information. + Template *TemplateMetadata `json:"template,omitempty"` } -// SetServiceGroupID : Allow user to set ServiceGroupID -func (_options *ListRolesOptions) SetServiceGroupID(serviceGroupID string) *ListRolesOptions { - _options.ServiceGroupID = core.StringPtr(serviceGroupID) - return _options -} +// Constants associated with the Policy.State property. +// The policy state. +const ( + PolicyStateActiveConst = "active" + PolicyStateDeletedConst = "deleted" +) -// SetHeaders : Allow user to set Headers -func (options *ListRolesOptions) SetHeaders(param map[string]string) *ListRolesOptions { - options.Headers = param - return options +// 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, UnmarshalTemplateMetadata) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// ListV2PoliciesOptions : The ListV2Policies options. -type ListV2PoliciesOptions struct { - // The account GUID in which the policies belong to. - AccountID *string `json:"account_id" validate:"required"` +// PolicyAssignment : The set of properties associated with the policy template assignment. +type PolicyAssignment struct { + // policy template id. + TemplateID *string `json:"template_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"` + // policy template version. + TemplateVersion *string `json:"template_version" validate:"required"` - // Optional IAM ID used to identify the subject. - IamID *string `json:"iam_id,omitempty"` + // Passed in value to correlate with other assignments. + AssignmentID *string `json:"assignment_id" validate:"required"` - // Optional access group id. - AccessGroupID *string `json:"access_group_id,omitempty"` + // Assignment target type. + TargetType *string `json:"target_type" validate:"required"` - // Optional type of policy. - Type *string `json:"type,omitempty"` + // ID of the target account. + Target *string `json:"target" validate:"required"` - // Optional type of service. - ServiceType *string `json:"service_type,omitempty"` + // List of objects with required properties for a policy assignment. + Options []PolicyAssignmentRequestOptionsItem `json:"options" validate:"required"` - // Optional name of service. - ServiceName *string `json:"service_name,omitempty"` + // Policy assignment ID. + ID *string `json:"id,omitempty"` - // Optional ID of service group. - ServiceGroupID *string `json:"service_group_id,omitempty"` + // The account GUID that the policies assignments belong to.. + AccountID *string `json:"account_id,omitempty"` - // Optional top level policy field to sort results. Ascending sort is default. Descending sort available by prepending - // '-' to field, for example, '-last_modified_at'. Note that last permit information is only included when - // 'format=include_last_permit', for example, "format=include_last_permit&sort=last_permit_at" Example fields that can - // be sorted on: - // - 'id' - // - 'type' - // - 'href' - // - 'created_at' - // - 'created_by_id' - // - 'last_modified_at' - // - 'last_modified_by_id' - // - 'state' - // - 'last_permit_at' - // - 'last_permit_frequency'. - Sort *string `json:"sort,omitempty"` + // The href URL that links to the policies assignments API by policy assignment ID. + Href *string `json:"href,omitempty"` - // 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 and translations for all relevant - // fields. - Format *string `json:"format,omitempty"` + // The UTC timestamp when the policy assignment was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` - // The state of the policy. - // * `active` - returns active policies - // * `deleted` - returns non-active policies. - State *string `json:"state,omitempty"` + // The iam ID of the entity that created the policy assignment. + CreatedByID *string `json:"created_by_id,omitempty"` - // Allows users to set headers on API requests - Headers map[string]string -} + // The UTC timestamp when the policy assignment was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` -// Constants associated with the ListV2PoliciesOptions.Type property. -// Optional type of policy. -const ( - ListV2PoliciesOptionsTypeAccessConst = "access" - ListV2PoliciesOptionsTypeAuthorizationConst = "authorization" -) + // The iam ID of the entity that last modified the policy assignment. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` -// Constants associated with the ListV2PoliciesOptions.ServiceType property. -// Optional type of service. -const ( - ListV2PoliciesOptionsServiceTypePlatformServiceConst = "platform_service" - ListV2PoliciesOptionsServiceTypeServiceConst = "service" -) + // Object for each account assigned. + Resources []PolicyAssignmentResources `json:"resources,omitempty"` -// Constants associated with the ListV2PoliciesOptions.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 and translations for all relevant -// fields. + // The policy assignment status. + Status *string `json:"status" validate:"required"` +} + +// Constants associated with the PolicyAssignment.TargetType property. +// Assignment target type. const ( - ListV2PoliciesOptionsFormatDisplayConst = "display" - ListV2PoliciesOptionsFormatIncludeLastPermitConst = "include_last_permit" + PolicyAssignmentTargetTypeAccountConst = "Account" ) -// Constants associated with the ListV2PoliciesOptions.State property. -// The state of the policy. -// * `active` - returns active policies -// * `deleted` - returns non-active policies. +// Constants associated with the PolicyAssignment.Status property. +// The policy assignment status. const ( - ListV2PoliciesOptionsStateActiveConst = "active" - ListV2PoliciesOptionsStateDeletedConst = "deleted" + PolicyAssignmentStatusFailedConst = "failed" + PolicyAssignmentStatusInProgressConst = "in_progress" + PolicyAssignmentStatusSucceedWithErrorsConst = "succeed_with_errors" + PolicyAssignmentStatusSucceededConst = "succeeded" ) -// NewListV2PoliciesOptions : Instantiate ListV2PoliciesOptions -func (*IamPolicyManagementV1) NewListV2PoliciesOptions(accountID string) *ListV2PoliciesOptions { - return &ListV2PoliciesOptions{ - AccountID: core.StringPtr(accountID), +// 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 + } + 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.UnmarshalModel(m, "options", &obj.Options, UnmarshalPolicyAssignmentRequestOptionsItem) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + 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 + } + 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 + } + err = core.UnmarshalPrimitive(m, "status", &obj.Status) + if err != nil { + return } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// SetAccountID : Allow user to set AccountID -func (_options *ListV2PoliciesOptions) SetAccountID(accountID string) *ListV2PoliciesOptions { - _options.AccountID = core.StringPtr(accountID) - return _options -} +// 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"` -// SetAcceptLanguage : Allow user to set AcceptLanguage -func (_options *ListV2PoliciesOptions) SetAcceptLanguage(acceptLanguage string) *ListV2PoliciesOptions { - _options.AcceptLanguage = core.StringPtr(acceptLanguage) - return _options -} + // The policy subject id. + SubjectID *string `json:"subject_id" validate:"required"` -// SetIamID : Allow user to set IamID -func (_options *ListV2PoliciesOptions) SetIamID(iamID string) *ListV2PoliciesOptions { - _options.IamID = core.StringPtr(iamID) - return _options + // 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"` } -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *ListV2PoliciesOptions) SetAccessGroupID(accessGroupID string) *ListV2PoliciesOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options +// 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 + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// SetType : Allow user to set Type -func (_options *ListV2PoliciesOptions) SetType(typeVar string) *ListV2PoliciesOptions { - _options.Type = core.StringPtr(typeVar) - return _options +// 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"` } -// SetServiceType : Allow user to set ServiceType -func (_options *ListV2PoliciesOptions) SetServiceType(serviceType string) *ListV2PoliciesOptions { - _options.ServiceType = core.StringPtr(serviceType) - return _options +// 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 } -// SetServiceName : Allow user to set ServiceName -func (_options *ListV2PoliciesOptions) SetServiceName(serviceName string) *ListV2PoliciesOptions { - _options.ServiceName = core.StringPtr(serviceName) - return _options +// 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"` } -// SetServiceGroupID : Allow user to set ServiceGroupID -func (_options *ListV2PoliciesOptions) SetServiceGroupID(serviceGroupID string) *ListV2PoliciesOptions { - _options.ServiceGroupID = core.StringPtr(serviceGroupID) - return _options +// 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 + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// SetSort : Allow user to set Sort -func (_options *ListV2PoliciesOptions) SetSort(sort string) *ListV2PoliciesOptions { - _options.Sort = core.StringPtr(sort) - return _options +// PolicyCollection : A collection of policies. +type PolicyCollection struct { + // List of policies. + Policies []Policy `json:"policies,omitempty"` } -// SetFormat : Allow user to set Format -func (_options *ListV2PoliciesOptions) SetFormat(format string) *ListV2PoliciesOptions { - _options.Format = core.StringPtr(format) - return _options +// 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 } -// SetState : Allow user to set State -func (_options *ListV2PoliciesOptions) SetState(state string) *ListV2PoliciesOptions { - _options.State = core.StringPtr(state) - return _options +// 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"` } -// SetHeaders : Allow user to set Headers -func (options *ListV2PoliciesOptions) SetHeaders(param map[string]string) *ListV2PoliciesOptions { - options.Headers = param - return options +// 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. @@ -2634,451 +4539,422 @@ func UnmarshalPolicyRole(m map[string]json.RawMessage, result interface{}) (err return } -// ReplacePolicyOptions : The ReplacePolicy options. -type ReplacePolicyOptions struct { - // The policy ID. - PolicyID *string `json:"policy_id" validate:"required,ne="` - - // The revision number for updating a policy and must match the ETag value of the existing policy. The Etag can be - // retrieved using the GET /v1/policies/{policy_id} API and looking at the ETag response header. - IfMatch *string `json:"If-Match" validate:"required"` - - // The policy type; either 'access' or 'authorization'. - Type *string `json:"type" validate:"required"` - - // 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"` - - // Customer-defined description. - Description *string `json:"description,omitempty"` - - // Allows users to set headers on API requests - Headers map[string]string +// 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"` } -// NewReplacePolicyOptions : Instantiate ReplacePolicyOptions -func (*IamPolicyManagementV1) NewReplacePolicyOptions(policyID string, ifMatch string, typeVar string, subjects []PolicySubject, roles []PolicyRole, resources []PolicyResource) *ReplacePolicyOptions { - return &ReplacePolicyOptions{ - PolicyID: core.StringPtr(policyID), - IfMatch: core.StringPtr(ifMatch), - Type: core.StringPtr(typeVar), - Subjects: subjects, - Roles: roles, - Resources: resources, +// 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 } -// SetPolicyID : Allow user to set PolicyID -func (_options *ReplacePolicyOptions) SetPolicyID(policyID string) *ReplacePolicyOptions { - _options.PolicyID = core.StringPtr(policyID) - return _options -} - -// SetIfMatch : Allow user to set IfMatch -func (_options *ReplacePolicyOptions) SetIfMatch(ifMatch string) *ReplacePolicyOptions { - _options.IfMatch = core.StringPtr(ifMatch) - return _options -} - -// SetType : Allow user to set Type -func (_options *ReplacePolicyOptions) SetType(typeVar string) *ReplacePolicyOptions { - _options.Type = core.StringPtr(typeVar) - return _options -} +// PolicyTemplate : The core set of properties associated with the policy template. +type PolicyTemplate struct { + // 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"` -// SetSubjects : Allow user to set Subjects -func (_options *ReplacePolicyOptions) SetSubjects(subjects []PolicySubject) *ReplacePolicyOptions { - _options.Subjects = subjects - return _options -} + // 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"` -// SetRoles : Allow user to set Roles -func (_options *ReplacePolicyOptions) SetRoles(roles []PolicyRole) *ReplacePolicyOptions { - _options.Roles = roles - return _options -} + // Enterprise account ID where this template will be created. + AccountID *string `json:"account_id" validate:"required"` -// SetResources : Allow user to set Resources -func (_options *ReplacePolicyOptions) SetResources(resources []PolicyResource) *ReplacePolicyOptions { - _options.Resources = resources - return _options -} + // Template version. + Version *string `json:"version" validate:"required"` -// SetDescription : Allow user to set Description -func (_options *ReplacePolicyOptions) SetDescription(description string) *ReplacePolicyOptions { - _options.Description = core.StringPtr(description) - return _options -} + // Committed status of the template version. + Committed *bool `json:"committed,omitempty"` -// SetHeaders : Allow user to set Headers -func (options *ReplacePolicyOptions) SetHeaders(param map[string]string) *ReplacePolicyOptions { - options.Headers = param - return options -} + // The core set of properties associated with the template's policy objet. + Policy *TemplatePolicy `json:"policy" validate:"required"` -// ReplaceRoleOptions : The ReplaceRole options. -type ReplaceRoleOptions struct { - // The role ID. - RoleID *string `json:"role_id" validate:"required,ne="` + // The policy template ID. + ID *string `json:"id,omitempty"` - // The revision number for updating a role and must match the ETag value of the existing role. The Etag can be - // retrieved using the GET /v2/roles/{role_id} API and looking at the ETag response header. - IfMatch *string `json:"If-Match" validate:"required"` + // The href URL that links to the policy templates API by policy template ID. + Href *string `json:"href,omitempty"` - // The display name of the role that is shown in the console. - DisplayName *string `json:"display_name" validate:"required"` + // The UTC timestamp when the policy template was created. + CreatedAt *strfmt.DateTime `json:"created_at,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 iam ID of the entity that created the policy template. + CreatedByID *string `json:"created_by_id,omitempty"` - // The description of the role. - Description *string `json:"description,omitempty"` + // The UTC timestamp when the policy template was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` - // Allows users to set headers on API requests - Headers map[string]string + // The iam ID of the entity that last modified the policy template. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` } -// NewReplaceRoleOptions : Instantiate ReplaceRoleOptions -func (*IamPolicyManagementV1) NewReplaceRoleOptions(roleID string, ifMatch string, displayName string, actions []string) *ReplaceRoleOptions { - return &ReplaceRoleOptions{ - RoleID: core.StringPtr(roleID), - IfMatch: core.StringPtr(ifMatch), - DisplayName: core.StringPtr(displayName), - Actions: actions, +// 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.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + 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 } -// SetRoleID : Allow user to set RoleID -func (_options *ReplaceRoleOptions) SetRoleID(roleID string) *ReplaceRoleOptions { - _options.RoleID = core.StringPtr(roleID) - return _options +// PolicyTemplateAssignmentCollection : A collection of policies assignments. +type PolicyTemplateAssignmentCollection struct { + // List of policy assignments. + Assignments []PolicyAssignment `json:"assignments,omitempty"` } -// SetIfMatch : Allow user to set IfMatch -func (_options *ReplaceRoleOptions) SetIfMatch(ifMatch string) *ReplaceRoleOptions { - _options.IfMatch = core.StringPtr(ifMatch) - return _options +// 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 } -// SetDisplayName : Allow user to set DisplayName -func (_options *ReplaceRoleOptions) SetDisplayName(displayName string) *ReplaceRoleOptions { - _options.DisplayName = core.StringPtr(displayName) - return _options +// PolicyTemplateCollection : A collection of policy Templates. +type PolicyTemplateCollection struct { + // List of policy templates. + PolicyTemplates []PolicyTemplate `json:"policy_templates,omitempty"` } -// SetActions : Allow user to set Actions -func (_options *ReplaceRoleOptions) SetActions(actions []string) *ReplaceRoleOptions { - _options.Actions = actions - return _options +// 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 } -// SetDescription : Allow user to set Description -func (_options *ReplaceRoleOptions) SetDescription(description string) *ReplaceRoleOptions { - _options.Description = core.StringPtr(description) - return _options +// PolicyTemplateVersionsCollection : A collection of versions for a specific policy template. +type PolicyTemplateVersionsCollection struct { + // List of policy templates versions. + Versions []PolicyTemplate `json:"versions,omitempty"` } -// SetHeaders : Allow user to set Headers -func (options *ReplaceRoleOptions) SetHeaders(param map[string]string) *ReplaceRoleOptions { - options.Headers = param - return options +// 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 + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// ReplaceV2PolicyOptions : The ReplaceV2Policy options. -type ReplaceV2PolicyOptions struct { +// ReplacePolicyOptions : The ReplacePolicy options. +type ReplacePolicyOptions struct { // The policy ID. - ID *string `json:"id" validate:"required,ne="` + PolicyID *string `json:"policy_id" validate:"required,ne="` // The revision number for updating a policy and must match the ETag value of the existing policy. The Etag can be - // retrieved using the GET /v2/policies/{id} API and looking at the ETag response header. + // retrieved using the GET /v1/policies/{policy_id} API and looking at the ETag response header. IfMatch *string `json:"If-Match" validate:"required"` - // Specifies the type of access granted by the policy. - Control *Control `json:"control" validate:"required"` - // 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 subject attributes for whom the policy grants access. - Subject *V2PolicySubject `json:"subject,omitempty"` + // The subjects associated with a policy. + Subjects []PolicySubject `json:"subjects" validate:"required"` - // The resource attributes to which the policy grants access. - Resource *V2PolicyResource `json:"resource,omitempty"` + // A set of role cloud resource names (CRNs) granted by the policy. + Roles []PolicyRole `json:"roles" 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"` + // The resources associated with a policy. + Resources []PolicyResource `json:"resources" validate:"required"` - // Additional access conditions associated with the policy. - Rule V2PolicyRuleIntf `json:"rule,omitempty"` + // Customer-defined description. + Description *string `json:"description,omitempty"` // Allows users to set headers on API requests Headers map[string]string -} - -// Constants associated with the ReplaceV2PolicyOptions.Type property. -// The policy type; either 'access' or 'authorization'. -const ( - ReplaceV2PolicyOptionsTypeAccessConst = "access" - ReplaceV2PolicyOptionsTypeAuthorizationConst = "authorization" -) +} -// NewReplaceV2PolicyOptions : Instantiate ReplaceV2PolicyOptions -func (*IamPolicyManagementV1) NewReplaceV2PolicyOptions(id string, ifMatch string, control *Control, typeVar string) *ReplaceV2PolicyOptions { - return &ReplaceV2PolicyOptions{ - ID: core.StringPtr(id), +// NewReplacePolicyOptions : Instantiate ReplacePolicyOptions +func (*IamPolicyManagementV1) NewReplacePolicyOptions(policyID string, ifMatch string, typeVar string, subjects []PolicySubject, roles []PolicyRole, resources []PolicyResource) *ReplacePolicyOptions { + return &ReplacePolicyOptions{ + PolicyID: core.StringPtr(policyID), IfMatch: core.StringPtr(ifMatch), - Control: control, Type: core.StringPtr(typeVar), + Subjects: subjects, + Roles: roles, + Resources: resources, } } -// SetID : Allow user to set ID -func (_options *ReplaceV2PolicyOptions) SetID(id string) *ReplaceV2PolicyOptions { - _options.ID = core.StringPtr(id) +// SetPolicyID : Allow user to set PolicyID +func (_options *ReplacePolicyOptions) SetPolicyID(policyID string) *ReplacePolicyOptions { + _options.PolicyID = core.StringPtr(policyID) return _options } // SetIfMatch : Allow user to set IfMatch -func (_options *ReplaceV2PolicyOptions) SetIfMatch(ifMatch string) *ReplaceV2PolicyOptions { +func (_options *ReplacePolicyOptions) SetIfMatch(ifMatch string) *ReplacePolicyOptions { _options.IfMatch = core.StringPtr(ifMatch) return _options } -// SetControl : Allow user to set Control -func (_options *ReplaceV2PolicyOptions) SetControl(control *Control) *ReplaceV2PolicyOptions { - _options.Control = control - return _options -} - // SetType : Allow user to set Type -func (_options *ReplaceV2PolicyOptions) SetType(typeVar string) *ReplaceV2PolicyOptions { +func (_options *ReplacePolicyOptions) SetType(typeVar string) *ReplacePolicyOptions { _options.Type = core.StringPtr(typeVar) return _options } -// SetDescription : Allow user to set Description -func (_options *ReplaceV2PolicyOptions) SetDescription(description string) *ReplaceV2PolicyOptions { - _options.Description = core.StringPtr(description) - return _options -} - -// SetSubject : Allow user to set Subject -func (_options *ReplaceV2PolicyOptions) SetSubject(subject *V2PolicySubject) *ReplaceV2PolicyOptions { - _options.Subject = subject +// SetSubjects : Allow user to set Subjects +func (_options *ReplacePolicyOptions) SetSubjects(subjects []PolicySubject) *ReplacePolicyOptions { + _options.Subjects = subjects return _options } -// SetResource : Allow user to set Resource -func (_options *ReplaceV2PolicyOptions) SetResource(resource *V2PolicyResource) *ReplaceV2PolicyOptions { - _options.Resource = resource +// SetRoles : Allow user to set Roles +func (_options *ReplacePolicyOptions) SetRoles(roles []PolicyRole) *ReplacePolicyOptions { + _options.Roles = roles return _options } -// SetPattern : Allow user to set Pattern -func (_options *ReplaceV2PolicyOptions) SetPattern(pattern string) *ReplaceV2PolicyOptions { - _options.Pattern = core.StringPtr(pattern) +// SetResources : Allow user to set Resources +func (_options *ReplacePolicyOptions) SetResources(resources []PolicyResource) *ReplacePolicyOptions { + _options.Resources = resources return _options } -// SetRule : Allow user to set Rule -func (_options *ReplaceV2PolicyOptions) SetRule(rule V2PolicyRuleIntf) *ReplaceV2PolicyOptions { - _options.Rule = rule +// SetDescription : Allow user to set Description +func (_options *ReplacePolicyOptions) SetDescription(description string) *ReplacePolicyOptions { + _options.Description = core.StringPtr(description) return _options } // SetHeaders : Allow user to set Headers -func (options *ReplaceV2PolicyOptions) SetHeaders(param map[string]string) *ReplaceV2PolicyOptions { +func (options *ReplacePolicyOptions) SetHeaders(param map[string]string) *ReplacePolicyOptions { options.Headers = param 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"` +// ReplacePolicyTemplateOptions : The ReplacePolicyTemplate options. +type ReplacePolicyTemplateOptions struct { + // The policy template ID. + PolicyTemplateID *string `json:"policy_template_id" validate:"required,ne="` - // Service defined display name for action. - DisplayName *string `json:"display_name" validate:"required"` + // The policy template version. + Version *string `json:"version" validate:"required,ne="` - // Service defined description for action. - Description *string `json:"description" validate:"required"` -} + // 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"` -// 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 -} + // The core set of properties associated with the template's policy objet. + Policy *TemplatePolicy `json:"policy" validate:"required"` -// 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"` + // 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 of the template version. + Committed *bool `json:"committed,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string } -// NewRoles : Instantiate Roles (Generic Model Constructor) -func (*IamPolicyManagementV1) NewRoles(roleID string) (_model *Roles, err error) { - _model = &Roles{ - RoleID: core.StringPtr(roleID), +// 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, } - err = core.ValidateStruct(_model, "required parameters") - return } -// UnmarshalRoles unmarshals an instance of Roles from the specified map of raw messages. -func UnmarshalRoles(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Roles) - err = core.UnmarshalPrimitive(m, "role_id", &obj.RoleID) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return +// SetPolicyTemplateID : Allow user to set PolicyTemplateID +func (_options *ReplacePolicyTemplateOptions) SetPolicyTemplateID(policyTemplateID string) *ReplacePolicyTemplateOptions { + _options.PolicyTemplateID = core.StringPtr(policyTemplateID) + return _options } -// RuleAttribute : Rule that specifies additional access granted (e.g., time-based condition). -type RuleAttribute struct { - // The name of an attribute. - Key *string `json:"key" validate:"required"` +// SetVersion : Allow user to set Version +func (_options *ReplacePolicyTemplateOptions) SetVersion(version string) *ReplacePolicyTemplateOptions { + _options.Version = core.StringPtr(version) + return _options +} - // The operator of an attribute. - Operator *string `json:"operator" validate:"required"` +// SetIfMatch : Allow user to set IfMatch +func (_options *ReplacePolicyTemplateOptions) SetIfMatch(ifMatch string) *ReplacePolicyTemplateOptions { + _options.IfMatch = core.StringPtr(ifMatch) + return _options +} - // The value of a rule or resource attribute; can be boolean or string for resource attribute. Can be string or an - // array of strings (e.g., array of days to permit access) for rule attribute. - Value interface{} `json:"value" validate:"required"` +// SetPolicy : Allow user to set Policy +func (_options *ReplacePolicyTemplateOptions) SetPolicy(policy *TemplatePolicy) *ReplacePolicyTemplateOptions { + _options.Policy = policy + return _options } -// Constants associated with the RuleAttribute.Operator property. -// The operator of an attribute. -const ( - RuleAttributeOperatorDatetimegreaterthanConst = "dateTimeGreaterThan" - RuleAttributeOperatorDatetimegreaterthanorequalsConst = "dateTimeGreaterThanOrEquals" - RuleAttributeOperatorDatetimelessthanConst = "dateTimeLessThan" - RuleAttributeOperatorDatetimelessthanorequalsConst = "dateTimeLessThanOrEquals" - RuleAttributeOperatorDayofweekanyofConst = "dayOfWeekAnyOf" - RuleAttributeOperatorDayofweekequalsConst = "dayOfWeekEquals" - RuleAttributeOperatorTimegreaterthanConst = "timeGreaterThan" - RuleAttributeOperatorTimegreaterthanorequalsConst = "timeGreaterThanOrEquals" - RuleAttributeOperatorTimelessthanConst = "timeLessThan" - RuleAttributeOperatorTimelessthanorequalsConst = "timeLessThanOrEquals" -) +// SetDescription : Allow user to set Description +func (_options *ReplacePolicyTemplateOptions) SetDescription(description string) *ReplacePolicyTemplateOptions { + _options.Description = core.StringPtr(description) + return _options +} -// NewRuleAttribute : Instantiate RuleAttribute (Generic Model Constructor) -func (*IamPolicyManagementV1) NewRuleAttribute(key string, operator string, value interface{}) (_model *RuleAttribute, err error) { - _model = &RuleAttribute{ - Key: core.StringPtr(key), - Operator: core.StringPtr(operator), - Value: value, - } - err = core.ValidateStruct(_model, "required parameters") - return +// SetCommitted : Allow user to set Committed +func (_options *ReplacePolicyTemplateOptions) SetCommitted(committed bool) *ReplacePolicyTemplateOptions { + _options.Committed = core.BoolPtr(committed) + return _options } -// UnmarshalRuleAttribute unmarshals an instance of RuleAttribute from the specified map of raw messages. -func UnmarshalRuleAttribute(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(RuleAttribute) - err = core.UnmarshalPrimitive(m, "key", &obj.Key) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "value", &obj.Value) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return +// SetHeaders : Allow user to set Headers +func (options *ReplacePolicyTemplateOptions) SetHeaders(param map[string]string) *ReplacePolicyTemplateOptions { + options.Headers = param + return options } -// UpdatePolicyStateOptions : The UpdatePolicyState options. -type UpdatePolicyStateOptions struct { - // The policy ID. - PolicyID *string `json:"policy_id" validate:"required,ne="` +// ReplaceRoleOptions : The ReplaceRole options. +type ReplaceRoleOptions struct { + // The role ID. + RoleID *string `json:"role_id" validate:"required,ne="` - // The revision number for updating a policy and must match the ETag value of the existing policy. The Etag can be - // retrieved using the GET /v1/policies/{policy_id} API and looking at the ETag response header. + // The revision number for updating a role and must match the ETag value of the existing role. The Etag can be + // retrieved using the GET /v2/roles/{role_id} API and looking at the ETag response header. IfMatch *string `json:"If-Match" validate:"required"` - // The policy state. - State *string `json:"state,omitempty"` + // The display name of the role that is shown in the console. + DisplayName *string `json:"display_name" validate:"required"` + + // 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 description of the role. + Description *string `json:"description,omitempty"` // Allows users to set headers on API requests Headers map[string]string } -// Constants associated with the UpdatePolicyStateOptions.State property. -// The policy state. -const ( - UpdatePolicyStateOptionsStateActiveConst = "active" - UpdatePolicyStateOptionsStateDeletedConst = "deleted" -) - -// NewUpdatePolicyStateOptions : Instantiate UpdatePolicyStateOptions -func (*IamPolicyManagementV1) NewUpdatePolicyStateOptions(policyID string, ifMatch string) *UpdatePolicyStateOptions { - return &UpdatePolicyStateOptions{ - PolicyID: core.StringPtr(policyID), +// NewReplaceRoleOptions : Instantiate ReplaceRoleOptions +func (*IamPolicyManagementV1) NewReplaceRoleOptions(roleID string, ifMatch string, displayName string, actions []string) *ReplaceRoleOptions { + return &ReplaceRoleOptions{ + RoleID: core.StringPtr(roleID), IfMatch: core.StringPtr(ifMatch), + DisplayName: core.StringPtr(displayName), + Actions: actions, } } -// SetPolicyID : Allow user to set PolicyID -func (_options *UpdatePolicyStateOptions) SetPolicyID(policyID string) *UpdatePolicyStateOptions { - _options.PolicyID = core.StringPtr(policyID) +// SetRoleID : Allow user to set RoleID +func (_options *ReplaceRoleOptions) SetRoleID(roleID string) *ReplaceRoleOptions { + _options.RoleID = core.StringPtr(roleID) return _options } // SetIfMatch : Allow user to set IfMatch -func (_options *UpdatePolicyStateOptions) SetIfMatch(ifMatch string) *UpdatePolicyStateOptions { +func (_options *ReplaceRoleOptions) SetIfMatch(ifMatch string) *ReplaceRoleOptions { _options.IfMatch = core.StringPtr(ifMatch) return _options } -// SetState : Allow user to set State -func (_options *UpdatePolicyStateOptions) SetState(state string) *UpdatePolicyStateOptions { - _options.State = core.StringPtr(state) +// SetDisplayName : Allow user to set DisplayName +func (_options *ReplaceRoleOptions) SetDisplayName(displayName string) *ReplaceRoleOptions { + _options.DisplayName = core.StringPtr(displayName) + return _options +} + +// SetActions : Allow user to set Actions +func (_options *ReplaceRoleOptions) SetActions(actions []string) *ReplaceRoleOptions { + _options.Actions = actions + return _options +} + +// SetDescription : Allow user to set Description +func (_options *ReplaceRoleOptions) SetDescription(description string) *ReplaceRoleOptions { + _options.Description = core.StringPtr(description) return _options } // SetHeaders : Allow user to set Headers -func (options *UpdatePolicyStateOptions) SetHeaders(param map[string]string) *UpdatePolicyStateOptions { +func (options *ReplaceRoleOptions) SetHeaders(param map[string]string) *ReplaceRoleOptions { options.Headers = param return options } -// V2Policy : The core set of properties associated with the policy. -type V2Policy struct { +// ReplaceV2PolicyOptions : The ReplaceV2Policy options. +type ReplaceV2PolicyOptions struct { + // The policy ID. + ID *string `json:"id" validate:"required,ne="` + + // The revision number for updating a policy and must match the ETag value of the existing policy. The Etag can be + // retrieved using the GET /v2/policies/{id} API and looking at the ETag response header. + IfMatch *string `json:"If-Match" validate:"required"` + + // Specifies the type of access granted by the policy. + Control *Control `json:"control" validate:"required"` + // 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. @@ -3094,165 +4970,121 @@ type V2Policy struct { // Additional access conditions associated with the policy. Rule V2PolicyRuleIntf `json:"rule,omitempty"` - // The policy ID. - ID *string `json:"id,omitempty"` - - // The href URL that links to the policies API by policy ID. - Href *string `json:"href,omitempty"` - - Control ControlResponseIntf `json:"control" validate:"required"` + // Allows users to set headers on API requests + Headers map[string]string +} - // The UTC timestamp when the policy was created. - CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` +// Constants associated with the ReplaceV2PolicyOptions.Type property. +// The policy type; either 'access' or 'authorization'. +const ( + ReplaceV2PolicyOptionsTypeAccessConst = "access" + ReplaceV2PolicyOptionsTypeAuthorizationConst = "authorization" +) - // The iam ID of the entity that created the policy. - CreatedByID *string `json:"created_by_id,omitempty"` +// NewReplaceV2PolicyOptions : Instantiate ReplaceV2PolicyOptions +func (*IamPolicyManagementV1) NewReplaceV2PolicyOptions(id string, ifMatch string, control *Control, typeVar string) *ReplaceV2PolicyOptions { + return &ReplaceV2PolicyOptions{ + ID: core.StringPtr(id), + IfMatch: core.StringPtr(ifMatch), + Control: control, + Type: core.StringPtr(typeVar), + } +} - // The UTC timestamp when the policy was last modified. - LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` +// SetID : Allow user to set ID +func (_options *ReplaceV2PolicyOptions) SetID(id string) *ReplaceV2PolicyOptions { + _options.ID = core.StringPtr(id) + return _options +} - // The iam ID of the entity that last modified the policy. - LastModifiedByID *string `json:"last_modified_by_id,omitempty"` +// SetIfMatch : Allow user to set IfMatch +func (_options *ReplaceV2PolicyOptions) SetIfMatch(ifMatch string) *ReplaceV2PolicyOptions { + _options.IfMatch = core.StringPtr(ifMatch) + return _options +} - // The policy state, either 'deleted' or 'active'. - State *string `json:"state" validate:"required"` +// SetControl : Allow user to set Control +func (_options *ReplaceV2PolicyOptions) SetControl(control *Control) *ReplaceV2PolicyOptions { + _options.Control = control + return _options +} - // The optional last permit time of policy, when passing query parameter format=include_last_permit. - LastPermitAt *string `json:"last_permit_at,omitempty"` +// SetType : Allow user to set Type +func (_options *ReplaceV2PolicyOptions) SetType(typeVar string) *ReplaceV2PolicyOptions { + _options.Type = core.StringPtr(typeVar) + return _options +} - // 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"` +// SetDescription : Allow user to set Description +func (_options *ReplaceV2PolicyOptions) SetDescription(description string) *ReplaceV2PolicyOptions { + _options.Description = core.StringPtr(description) + return _options } -// Constants associated with the V2Policy.Type property. -// The policy type; either 'access' or 'authorization'. -const ( - V2PolicyTypeAccessConst = "access" - V2PolicyTypeAuthorizationConst = "authorization" -) +// SetSubject : Allow user to set Subject +func (_options *ReplaceV2PolicyOptions) SetSubject(subject *V2PolicySubject) *ReplaceV2PolicyOptions { + _options.Subject = subject + return _options +} -// Constants associated with the V2Policy.State property. -// The policy state, either 'deleted' or 'active'. -const ( - V2PolicyStateActiveConst = "active" - V2PolicyStateDeletedConst = "deleted" -) +// SetResource : Allow user to set Resource +func (_options *ReplaceV2PolicyOptions) SetResource(resource *V2PolicyResource) *ReplaceV2PolicyOptions { + _options.Resource = resource + return _options +} -// UnmarshalV2Policy unmarshals an instance of V2Policy from the specified map of raw messages. -func UnmarshalV2Policy(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(V2Policy) - 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, "subject", &obj.Subject, UnmarshalV2PolicySubject) - 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.UnmarshalPrimitive(m, "id", &obj.ID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "href", &obj.Href) - if err != nil { - return - } - err = core.UnmarshalModel(m, "control", &obj.Control, UnmarshalControlResponse) - 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.UnmarshalPrimitive(m, "last_permit_at", &obj.LastPermitAt) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "last_permit_frequency", &obj.LastPermitFrequency) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return +// SetPattern : Allow user to set Pattern +func (_options *ReplaceV2PolicyOptions) SetPattern(pattern string) *ReplaceV2PolicyOptions { + _options.Pattern = core.StringPtr(pattern) + return _options } -// V2PolicyCollection : A collection of policies. -type V2PolicyCollection struct { - // List of policies. - Policies []V2Policy `json:"policies,omitempty"` +// SetRule : Allow user to set Rule +func (_options *ReplaceV2PolicyOptions) SetRule(rule V2PolicyRuleIntf) *ReplaceV2PolicyOptions { + _options.Rule = rule + return _options } -// UnmarshalV2PolicyCollection unmarshals an instance of V2PolicyCollection from the specified map of raw messages. -func UnmarshalV2PolicyCollection(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(V2PolicyCollection) - err = core.UnmarshalModel(m, "policies", &obj.Policies, UnmarshalV2Policy) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return +// SetHeaders : Allow user to set Headers +func (options *ReplaceV2PolicyOptions) SetHeaders(param map[string]string) *ReplaceV2PolicyOptions { + options.Headers = param + return options } -// V2PolicyResource : The resource attributes to which the policy grants access. -type V2PolicyResource struct { - // List of resource attributes to which the policy grants access. - Attributes []V2PolicyResourceAttribute `json:"attributes" validate:"required"` +// ResourceAttribute : An attribute associated with a resource. +type ResourceAttribute struct { + // The name of an attribute. + Name *string `json:"name" validate:"required"` - // Optional list of resource tags to which the policy grants access. - Tags []V2PolicyResourceTag `json:"tags,omitempty"` + // The value of an attribute. + Value *string `json:"value" validate:"required"` + + // The operator of an attribute. + Operator *string `json:"operator,omitempty"` } -// NewV2PolicyResource : Instantiate V2PolicyResource (Generic Model Constructor) -func (*IamPolicyManagementV1) NewV2PolicyResource(attributes []V2PolicyResourceAttribute) (_model *V2PolicyResource, err error) { - _model = &V2PolicyResource{ - Attributes: attributes, +// 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 } -// UnmarshalV2PolicyResource unmarshals an instance of V2PolicyResource from the specified map of raw messages. -func UnmarshalV2PolicyResource(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(V2PolicyResource) - err = core.UnmarshalModel(m, "attributes", &obj.Attributes, UnmarshalV2PolicyResourceAttribute) +// 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.UnmarshalModel(m, "tags", &obj.Tags, UnmarshalV2PolicyResourceTag) + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) if err != nil { return } @@ -3260,50 +5092,40 @@ func UnmarshalV2PolicyResource(m map[string]json.RawMessage, result interface{}) return } -// V2PolicyResourceAttribute : Resource attribute to which the policy grants access. -type V2PolicyResourceAttribute struct { - // The name of a resource attribute. - Key *string `json:"key" 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 operator of an attribute. - Operator *string `json:"operator" validate:"required"` + // The value of an access management tag. + Value *string `json:"value" validate:"required"` - // The value of a rule or resource attribute; can be boolean or string for resource attribute. Can be string or an - // array of strings (e.g., array of days to permit access) for rule attribute. - Value interface{} `json:"value" validate:"required"` + // The operator of an access management tag. + Operator *string `json:"operator,omitempty"` } -// Constants associated with the V2PolicyResourceAttribute.Operator property. -// The operator of an attribute. -const ( - V2PolicyResourceAttributeOperatorStringequalsConst = "stringEquals" - V2PolicyResourceAttributeOperatorStringexistsConst = "stringExists" - V2PolicyResourceAttributeOperatorStringmatchConst = "stringMatch" -) - -// NewV2PolicyResourceAttribute : Instantiate V2PolicyResourceAttribute (Generic Model Constructor) -func (*IamPolicyManagementV1) NewV2PolicyResourceAttribute(key string, operator string, value interface{}) (_model *V2PolicyResourceAttribute, err error) { - _model = &V2PolicyResourceAttribute{ - Key: core.StringPtr(key), - Operator: core.StringPtr(operator), - Value: value, +// 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 } -// UnmarshalV2PolicyResourceAttribute unmarshals an instance of V2PolicyResourceAttribute from the specified map of raw messages. -func UnmarshalV2PolicyResourceAttribute(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(V2PolicyResourceAttribute) - err = core.UnmarshalPrimitive(m, "key", &obj.Key) +// 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, "operator", &obj.Operator) + err = core.UnmarshalPrimitive(m, "value", &obj.Value) if err != nil { return } - err = core.UnmarshalPrimitive(m, "value", &obj.Value) + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) if err != nil { return } @@ -3311,48 +5133,49 @@ func UnmarshalV2PolicyResourceAttribute(m map[string]json.RawMessage, result int return } -// V2PolicyResourceTag : A tag associated with a resource. -type V2PolicyResourceTag struct { - // The name of an access management tag. - Key *string `json:"key" validate:"required"` +// 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 value of an access management tag. - Value *string `json:"value" validate:"required"` + // The description of the role. + Description *string `json:"description,omitempty"` - // The operator of an access management tag. - Operator *string `json:"operator" validate:"required"` -} + // 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"` -// Constants associated with the V2PolicyResourceTag.Operator property. -// The operator of an access management tag. -const ( - V2PolicyResourceTagOperatorStringequalsConst = "stringEquals" - V2PolicyResourceTagOperatorStringmatchConst = "stringMatch" -) + // The role Cloud Resource Name (CRN). Example CRN: + // 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. + CRN *string `json:"crn,omitempty"` +} -// NewV2PolicyResourceTag : Instantiate V2PolicyResourceTag (Generic Model Constructor) -func (*IamPolicyManagementV1) NewV2PolicyResourceTag(key string, value string, operator string) (_model *V2PolicyResourceTag, err error) { - _model = &V2PolicyResourceTag{ - Key: core.StringPtr(key), - Value: core.StringPtr(value), - Operator: core.StringPtr(operator), +// 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 } -// UnmarshalV2PolicyResourceTag unmarshals an instance of V2PolicyResourceTag from the specified map of raw messages. -func UnmarshalV2PolicyResourceTag(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(V2PolicyResourceTag) - err = core.UnmarshalPrimitive(m, "key", &obj.Key) +// 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, "value", &obj.Value) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) if err != nil { return } - err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + err = core.UnmarshalPrimitive(m, "actions", &obj.Actions) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) if err != nil { return } @@ -3360,64 +5183,61 @@ func UnmarshalV2PolicyResourceTag(m map[string]json.RawMessage, result interface return } -// V2PolicyRule : Additional access conditions associated with the policy. -// Models which "extend" this model: -// - V2PolicyRuleRuleAttribute -// - V2PolicyRuleRuleWithConditions -type V2PolicyRule struct { - // The name of an attribute. - Key *string `json:"key,omitempty"` - - // The operator of an attribute. - Operator *string `json:"operator,omitempty"` +// 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"` - // The value of a rule or resource attribute; can be boolean or string for resource attribute. Can be string or an - // array of strings (e.g., array of days to permit access) for rule attribute. - Value interface{} `json:"value,omitempty"` + // Service defined display name for action. + DisplayName *string `json:"display_name" validate:"required"` - // List of conditions associated with a policy, e.g., time-based conditions that grant access over a certain time - // period. - Conditions []RuleAttribute `json:"conditions,omitempty"` + // Service defined description for action. + Description *string `json:"description" validate:"required"` } -// Constants associated with the V2PolicyRule.Operator property. -// The operator of an attribute. -const ( - V2PolicyRuleOperatorDatetimegreaterthanConst = "dateTimeGreaterThan" - V2PolicyRuleOperatorDatetimegreaterthanorequalsConst = "dateTimeGreaterThanOrEquals" - V2PolicyRuleOperatorDatetimelessthanConst = "dateTimeLessThan" - V2PolicyRuleOperatorDatetimelessthanorequalsConst = "dateTimeLessThanOrEquals" - V2PolicyRuleOperatorDayofweekanyofConst = "dayOfWeekAnyOf" - V2PolicyRuleOperatorDayofweekequalsConst = "dayOfWeekEquals" - V2PolicyRuleOperatorTimegreaterthanConst = "timeGreaterThan" - V2PolicyRuleOperatorTimegreaterthanorequalsConst = "timeGreaterThanOrEquals" - V2PolicyRuleOperatorTimelessthanConst = "timeLessThan" - V2PolicyRuleOperatorTimelessthanorequalsConst = "timeLessThanOrEquals" -) -func (*V2PolicyRule) isaV2PolicyRule() bool { - return true +// 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 } -type V2PolicyRuleIntf interface { - isaV2PolicyRule() bool +// 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"` } -// UnmarshalV2PolicyRule unmarshals an instance of V2PolicyRule from the specified map of raw messages. -func UnmarshalV2PolicyRule(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(V2PolicyRule) - err = core.UnmarshalPrimitive(m, "key", &obj.Key) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) +// 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.UnmarshalPrimitive(m, "value", &obj.Value) + err = core.UnmarshalModel(m, "service_roles", &obj.ServiceRoles, UnmarshalRole) if err != nil { return } - err = core.UnmarshalModel(m, "conditions", &obj.Conditions, UnmarshalRuleAttribute) + err = core.UnmarshalModel(m, "system_roles", &obj.SystemRoles, UnmarshalRole) if err != nil { return } @@ -3425,25 +5245,25 @@ func UnmarshalV2PolicyRule(m map[string]json.RawMessage, result interface{}) (er return } -// V2PolicySubject : The subject attributes for whom the policy grants access. -type V2PolicySubject struct { - // List of subject attributes associated with policy/. - Attributes []V2PolicySubjectAttribute `json:"attributes" validate:"required"` +// 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"` } -// NewV2PolicySubject : Instantiate V2PolicySubject (Generic Model Constructor) -func (*IamPolicyManagementV1) NewV2PolicySubject(attributes []V2PolicySubjectAttribute) (_model *V2PolicySubject, err error) { - _model = &V2PolicySubject{ - Attributes: attributes, +// 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 } -// UnmarshalV2PolicySubject unmarshals an instance of V2PolicySubject from the specified map of raw messages. -func UnmarshalV2PolicySubject(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(V2PolicySubject) - err = core.UnmarshalModel(m, "attributes", &obj.Attributes, UnmarshalV2PolicySubjectAttribute) +// UnmarshalRoles unmarshals an instance of Roles from the specified map of raw messages. +func UnmarshalRoles(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Roles) + err = core.UnmarshalPrimitive(m, "role_id", &obj.RoleID) if err != nil { return } @@ -3451,38 +5271,48 @@ func UnmarshalV2PolicySubject(m map[string]json.RawMessage, result interface{}) return } -// V2PolicySubjectAttribute : Subject attribute for whom the policy grants access. -type V2PolicySubjectAttribute struct { - // The name of a subject attribute, e.g., iam_id, access_group_id. +// RuleAttribute : Rule that specifies additional access granted (e.g., time-based condition). +type RuleAttribute struct { + // The name of an attribute. Key *string `json:"key" validate:"required"` // The operator of an attribute. Operator *string `json:"operator" validate:"required"` - // The value of the ID of the subject, e.g., service ID, access group ID, IAM ID. - Value *string `json:"value" validate:"required"` + // The value of a rule or resource attribute; can be boolean or string for resource attribute. Can be string or an + // array of strings (e.g., array of days to permit access) for rule attribute. + Value interface{} `json:"value" validate:"required"` } -// Constants associated with the V2PolicySubjectAttribute.Operator property. +// Constants associated with the RuleAttribute.Operator property. // The operator of an attribute. const ( - V2PolicySubjectAttributeOperatorStringequalsConst = "stringEquals" + RuleAttributeOperatorDatetimegreaterthanConst = "dateTimeGreaterThan" + RuleAttributeOperatorDatetimegreaterthanorequalsConst = "dateTimeGreaterThanOrEquals" + RuleAttributeOperatorDatetimelessthanConst = "dateTimeLessThan" + RuleAttributeOperatorDatetimelessthanorequalsConst = "dateTimeLessThanOrEquals" + RuleAttributeOperatorDayofweekanyofConst = "dayOfWeekAnyOf" + RuleAttributeOperatorDayofweekequalsConst = "dayOfWeekEquals" + RuleAttributeOperatorTimegreaterthanConst = "timeGreaterThan" + RuleAttributeOperatorTimegreaterthanorequalsConst = "timeGreaterThanOrEquals" + RuleAttributeOperatorTimelessthanConst = "timeLessThan" + RuleAttributeOperatorTimelessthanorequalsConst = "timeLessThanOrEquals" ) -// NewV2PolicySubjectAttribute : Instantiate V2PolicySubjectAttribute (Generic Model Constructor) -func (*IamPolicyManagementV1) NewV2PolicySubjectAttribute(key string, operator string, value string) (_model *V2PolicySubjectAttribute, err error) { - _model = &V2PolicySubjectAttribute{ +// NewRuleAttribute : Instantiate RuleAttribute (Generic Model Constructor) +func (*IamPolicyManagementV1) NewRuleAttribute(key string, operator string, value interface{}) (_model *RuleAttribute, err error) { + _model = &RuleAttribute{ Key: core.StringPtr(key), Operator: core.StringPtr(operator), - Value: core.StringPtr(value), + Value: value, } err = core.ValidateStruct(_model, "required parameters") return } -// UnmarshalV2PolicySubjectAttribute unmarshals an instance of V2PolicySubjectAttribute from the specified map of raw messages. -func UnmarshalV2PolicySubjectAttribute(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(V2PolicySubjectAttribute) +// UnmarshalRuleAttribute unmarshals an instance of RuleAttribute from the specified map of raw messages. +func UnmarshalRuleAttribute(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleAttribute) err = core.UnmarshalPrimitive(m, "key", &obj.Key) if err != nil { return @@ -3499,102 +5329,129 @@ func UnmarshalV2PolicySubjectAttribute(m map[string]json.RawMessage, result inte 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. +// SubjectAttribute : An attribute associated with a subject. +type SubjectAttribute struct { + // The name of an attribute. 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"` + + // The value of an attribute. + Value *string `json:"value" validate:"required"` } -// 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 +// 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.UnmarshalPrimitive(m, "description", &obj.Description) + 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, "actions", &obj.Actions) + 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"` + + // Template version. + Version *string `json:"version,omitempty"` +} + +// 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 } - err = core.UnmarshalPrimitive(m, "name", &obj.Name) + err = core.UnmarshalPrimitive(m, "version", &obj.Version) if err != nil { return } - err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) - 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"` + + // 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. + 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.UnmarshalPrimitive(m, "service_name", &obj.ServiceName) + 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, "created_at", &obj.CreatedAt) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) if err != nil { return } - err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) + err = core.UnmarshalModel(m, "resource", &obj.Resource, UnmarshalV2PolicyResource) if err != nil { return } - err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) + err = core.UnmarshalPrimitive(m, "pattern", &obj.Pattern) if err != nil { return } - err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) + err = core.UnmarshalModel(m, "rule", &obj.Rule, UnmarshalV2PolicyRule) if err != nil { return } - err = core.UnmarshalPrimitive(m, "href", &obj.Href) + err = core.UnmarshalModel(m, "control", &obj.Control, UnmarshalControl) if err != nil { return } @@ -3602,29 +5459,90 @@ func UnmarshalCustomRole(m map[string]json.RawMessage, result interface{}) (err return } -// Policy : The core set of properties associated with a policy. -type Policy struct { +// UpdatePolicyStateOptions : The UpdatePolicyState options. +type UpdatePolicyStateOptions struct { // The policy ID. - ID *string `json:"id,omitempty"` + PolicyID *string `json:"policy_id" validate:"required,ne="` + + // The revision number for updating a policy and must match the ETag value of the existing policy. The Etag can be + // retrieved using the GET /v1/policies/{policy_id} API and looking at the ETag response header. + IfMatch *string `json:"If-Match" validate:"required"` + + // The policy state. + State *string `json:"state,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// Constants associated with the UpdatePolicyStateOptions.State property. +// The policy state. +const ( + UpdatePolicyStateOptionsStateActiveConst = "active" + UpdatePolicyStateOptionsStateDeletedConst = "deleted" +) + +// NewUpdatePolicyStateOptions : Instantiate UpdatePolicyStateOptions +func (*IamPolicyManagementV1) NewUpdatePolicyStateOptions(policyID string, ifMatch string) *UpdatePolicyStateOptions { + return &UpdatePolicyStateOptions{ + PolicyID: core.StringPtr(policyID), + IfMatch: core.StringPtr(ifMatch), + } +} + +// SetPolicyID : Allow user to set PolicyID +func (_options *UpdatePolicyStateOptions) SetPolicyID(policyID string) *UpdatePolicyStateOptions { + _options.PolicyID = core.StringPtr(policyID) + return _options +} + +// SetIfMatch : Allow user to set IfMatch +func (_options *UpdatePolicyStateOptions) SetIfMatch(ifMatch string) *UpdatePolicyStateOptions { + _options.IfMatch = core.StringPtr(ifMatch) + return _options +} +// SetState : Allow user to set State +func (_options *UpdatePolicyStateOptions) SetState(state string) *UpdatePolicyStateOptions { + _options.State = core.StringPtr(state) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *UpdatePolicyStateOptions) SetHeaders(param map[string]string) *UpdatePolicyStateOptions { + options.Headers = param + return options +} + +// V2Policy : The core set of properties associated with the policy. +type V2Policy struct { // The policy type; either 'access' or 'authorization'. Type *string `json:"type" validate:"required"` - // Customer-defined description. + // Description of the policy. Description *string `json:"description,omitempty"` - // The subjects associated with a policy. - Subjects []PolicySubject `json:"subjects" validate:"required"` + // The subject attributes for whom the policy grants access. + Subject *V2PolicySubject `json:"subject,omitempty"` - // A set of role cloud resource names (CRNs) granted by the policy. - Roles []PolicyRole `json:"roles" validate:"required"` + // The resource attributes to which the policy grants access. + Resource *V2PolicyResource `json:"resource,omitempty"` - // The resources associated with a policy. - Resources []PolicyResource `json:"resources" 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"` - // The href link back to the policy. + // Additional access conditions associated with the policy. + Rule V2PolicyRuleIntf `json:"rule,omitempty"` + + // The policy ID. + ID *string `json:"id,omitempty"` + + // The href URL that links to the policies API by policy ID. Href *string `json:"href,omitempty"` + Control ControlResponseIntf `json:"control" validate:"required"` + // The UTC timestamp when the policy was created. CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` @@ -3637,41 +5555,62 @@ type Policy struct { // 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"` + // The policy state, either 'deleted' or 'active'. + State *string `json:"state" validate:"required"` + + // The optional last permit time of policy, when passing query parameter format=include_last_permit. + LastPermitAt *string `json:"last_permit_at,omitempty"` + + // 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 *TemplateMetadata `json:"template,omitempty"` } -// Constants associated with the Policy.State property. -// The policy state. +// Constants associated with the V2Policy.Type property. +// The policy type; either 'access' or 'authorization'. const ( - PolicyStateActiveConst = "active" - PolicyStateDeletedConst = "deleted" + V2PolicyTypeAccessConst = "access" + V2PolicyTypeAuthorizationConst = "authorization" ) -// 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) +// Constants associated with the V2Policy.State property. +// The policy state, either 'deleted' or 'active'. +const ( + V2PolicyStateActiveConst = "active" + V2PolicyStateDeletedConst = "deleted" +) + +// UnmarshalV2Policy unmarshals an instance of V2Policy from the specified map of raw messages. +func UnmarshalV2Policy(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(V2Policy) + err = core.UnmarshalPrimitive(m, "type", &obj.Type) if err != nil { return } - err = core.UnmarshalPrimitive(m, "type", &obj.Type) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) if err != nil { return } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) + err = core.UnmarshalModel(m, "subject", &obj.Subject, UnmarshalV2PolicySubject) if err != nil { return } - err = core.UnmarshalModel(m, "subjects", &obj.Subjects, UnmarshalPolicySubject) + err = core.UnmarshalModel(m, "resource", &obj.Resource, UnmarshalV2PolicyResource) if err != nil { return } - err = core.UnmarshalModel(m, "roles", &obj.Roles, UnmarshalPolicyRole) + err = core.UnmarshalPrimitive(m, "pattern", &obj.Pattern) if err != nil { return } - err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalPolicyResource) + err = core.UnmarshalModel(m, "rule", &obj.Rule, UnmarshalV2PolicyRule) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) if err != nil { return } @@ -3679,6 +5618,10 @@ func UnmarshalPolicy(m map[string]json.RawMessage, result interface{}) (err erro if err != nil { return } + err = core.UnmarshalModel(m, "control", &obj.Control, UnmarshalControlResponse) + if err != nil { + return + } err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) if err != nil { return @@ -3699,20 +5642,15 @@ func UnmarshalPolicy(m map[string]json.RawMessage, result interface{}) (err erro 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) + err = core.UnmarshalPrimitive(m, "last_permit_at", &obj.LastPermitAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_permit_frequency", &obj.LastPermitFrequency) + if err != nil { + return + } + err = core.UnmarshalModel(m, "template", &obj.Template, UnmarshalTemplateMetadata) if err != nil { return } @@ -3720,23 +5658,16 @@ func UnmarshalPolicyList(m map[string]json.RawMessage, result interface{}) (err 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"` +// V2PolicyCollection : A collection of policies. +type V2PolicyCollection struct { + // List of policies. + Policies []V2Policy `json:"policies,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) +// UnmarshalV2PolicyCollection unmarshals an instance of V2PolicyCollection from the specified map of raw messages. +func UnmarshalV2PolicyCollection(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(V2PolicyCollection) + err = core.UnmarshalModel(m, "policies", &obj.Policies, UnmarshalV2Policy) if err != nil { return } @@ -3744,16 +5675,32 @@ func UnmarshalPolicyResource(m map[string]json.RawMessage, result interface{}) ( 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"` +// V2PolicyResource : The resource attributes to which the policy grants access. +type V2PolicyResource struct { + // List of resource attributes to which the policy grants access. + Attributes []V2PolicyResourceAttribute `json:"attributes" validate:"required"` + + // Optional list of resource tags to which the policy grants access. + Tags []V2PolicyResourceTag `json:"tags,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) +// NewV2PolicyResource : Instantiate V2PolicyResource (Generic Model Constructor) +func (*IamPolicyManagementV1) NewV2PolicyResource(attributes []V2PolicyResourceAttribute) (_model *V2PolicyResource, err error) { + _model = &V2PolicyResource{ + Attributes: attributes, + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalV2PolicyResource unmarshals an instance of V2PolicyResource from the specified map of raw messages. +func UnmarshalV2PolicyResource(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(V2PolicyResource) + err = core.UnmarshalModel(m, "attributes", &obj.Attributes, UnmarshalV2PolicyResourceAttribute) + if err != nil { + return + } + err = core.UnmarshalModel(m, "tags", &obj.Tags, UnmarshalV2PolicyResourceTag) if err != nil { return } @@ -3761,40 +5708,50 @@ func UnmarshalPolicySubject(m map[string]json.RawMessage, result interface{}) (e 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"` +// V2PolicyResourceAttribute : Resource attribute to which the policy grants access. +type V2PolicyResourceAttribute struct { + // The name of a resource attribute. + Key *string `json:"key" validate:"required"` // The operator of an attribute. - Operator *string `json:"operator,omitempty"` + Operator *string `json:"operator" validate:"required"` + + // The value of a rule or resource attribute; can be boolean or string for resource attribute. Can be string or an + // array of strings (e.g., array of days to permit access) for rule attribute. + Value interface{} `json:"value" validate:"required"` } -// 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), +// Constants associated with the V2PolicyResourceAttribute.Operator property. +// The operator of an attribute. +const ( + V2PolicyResourceAttributeOperatorStringequalsConst = "stringEquals" + V2PolicyResourceAttributeOperatorStringexistsConst = "stringExists" + V2PolicyResourceAttributeOperatorStringmatchConst = "stringMatch" +) + +// NewV2PolicyResourceAttribute : Instantiate V2PolicyResourceAttribute (Generic Model Constructor) +func (*IamPolicyManagementV1) NewV2PolicyResourceAttribute(key string, operator string, value interface{}) (_model *V2PolicyResourceAttribute, err error) { + _model = &V2PolicyResourceAttribute{ + Key: core.StringPtr(key), + Operator: core.StringPtr(operator), + Value: 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) +// UnmarshalV2PolicyResourceAttribute unmarshals an instance of V2PolicyResourceAttribute from the specified map of raw messages. +func UnmarshalV2PolicyResourceAttribute(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(V2PolicyResourceAttribute) + err = core.UnmarshalPrimitive(m, "key", &obj.Key) if err != nil { return } - err = core.UnmarshalPrimitive(m, "value", &obj.Value) + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) if err != nil { return } - err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) + err = core.UnmarshalPrimitive(m, "value", &obj.Value) if err != nil { return } @@ -3802,32 +5759,40 @@ func UnmarshalResourceAttribute(m map[string]json.RawMessage, result interface{} return } -// ResourceTag : A tag associated with a resource. -type ResourceTag struct { +// V2PolicyResourceTag : A tag associated with a resource. +type V2PolicyResourceTag struct { // The name of an access management tag. - Name *string `json:"name" validate:"required"` + Key *string `json:"key" 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"` + Operator *string `json:"operator" validate:"required"` } -// NewResourceTag : Instantiate ResourceTag (Generic Model Constructor) -func (*IamPolicyManagementV1) NewResourceTag(name string, value string) (_model *ResourceTag, err error) { - _model = &ResourceTag{ - Name: core.StringPtr(name), +// Constants associated with the V2PolicyResourceTag.Operator property. +// The operator of an access management tag. +const ( + V2PolicyResourceTagOperatorStringequalsConst = "stringEquals" + V2PolicyResourceTagOperatorStringmatchConst = "stringMatch" +) + +// NewV2PolicyResourceTag : Instantiate V2PolicyResourceTag (Generic Model Constructor) +func (*IamPolicyManagementV1) NewV2PolicyResourceTag(key string, value string, operator string) (_model *V2PolicyResourceTag, err error) { + _model = &V2PolicyResourceTag{ + Key: core.StringPtr(key), Value: core.StringPtr(value), + Operator: core.StringPtr(operator), } 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) +// UnmarshalV2PolicyResourceTag unmarshals an instance of V2PolicyResourceTag from the specified map of raw messages. +func UnmarshalV2PolicyResourceTag(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(V2PolicyResourceTag) + err = core.UnmarshalPrimitive(m, "key", &obj.Key) if err != nil { return } @@ -3843,49 +5808,64 @@ func UnmarshalResourceTag(m map[string]json.RawMessage, result interface{}) (err 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"` +// V2PolicyRule : Additional access conditions associated with the policy. +// Models which "extend" this model: +// - V2PolicyRuleRuleAttribute +// - V2PolicyRuleRuleWithConditions +type V2PolicyRule struct { + // The name of an attribute. + Key *string `json:"key,omitempty"` - // The description of the role. - Description *string `json:"description,omitempty"` + // The operator of an attribute. + Operator *string `json:"operator,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 value of a rule or resource attribute; can be boolean or string for resource attribute. Can be string or an + // array of strings (e.g., array of days to permit access) for rule attribute. + Value interface{} `json:"value,omitempty"` - // The role Cloud Resource Name (CRN). Example CRN: - // 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. - CRN *string `json:"crn,omitempty"` + // List of conditions associated with a policy, e.g., time-based conditions that grant access over a certain time + // period. + Conditions []RuleAttribute `json:"conditions,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 +// Constants associated with the V2PolicyRule.Operator property. +// The operator of an attribute. +const ( + V2PolicyRuleOperatorDatetimegreaterthanConst = "dateTimeGreaterThan" + V2PolicyRuleOperatorDatetimegreaterthanorequalsConst = "dateTimeGreaterThanOrEquals" + V2PolicyRuleOperatorDatetimelessthanConst = "dateTimeLessThan" + V2PolicyRuleOperatorDatetimelessthanorequalsConst = "dateTimeLessThanOrEquals" + V2PolicyRuleOperatorDayofweekanyofConst = "dayOfWeekAnyOf" + V2PolicyRuleOperatorDayofweekequalsConst = "dayOfWeekEquals" + V2PolicyRuleOperatorTimegreaterthanConst = "timeGreaterThan" + V2PolicyRuleOperatorTimegreaterthanorequalsConst = "timeGreaterThanOrEquals" + V2PolicyRuleOperatorTimelessthanConst = "timeLessThan" + V2PolicyRuleOperatorTimelessthanorequalsConst = "timeLessThanOrEquals" +) +func (*V2PolicyRule) isaV2PolicyRule() bool { + return true } -// 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) +type V2PolicyRuleIntf interface { + isaV2PolicyRule() bool +} + +// UnmarshalV2PolicyRule unmarshals an instance of V2PolicyRule from the specified map of raw messages. +func UnmarshalV2PolicyRule(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(V2PolicyRule) + err = core.UnmarshalPrimitive(m, "key", &obj.Key) if err != nil { return } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) if err != nil { return } - err = core.UnmarshalPrimitive(m, "actions", &obj.Actions) + err = core.UnmarshalPrimitive(m, "value", &obj.Value) if err != nil { return } - err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) + err = core.UnmarshalModel(m, "conditions", &obj.Conditions, UnmarshalRuleAttribute) if err != nil { return } @@ -3893,30 +5873,25 @@ func UnmarshalRole(m map[string]json.RawMessage, result interface{}) (err error) 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"` +// V2PolicySubject : The subject attributes for whom the policy grants access. +type V2PolicySubject struct { + // List of subject attributes associated with policy/. + Attributes []V2PolicySubjectAttribute `json:"attributes" validate:"required"` } -// 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 +// NewV2PolicySubject : Instantiate V2PolicySubject (Generic Model Constructor) +func (*IamPolicyManagementV1) NewV2PolicySubject(attributes []V2PolicySubjectAttribute) (_model *V2PolicySubject, err error) { + _model = &V2PolicySubject{ + Attributes: attributes, } - err = core.UnmarshalModel(m, "system_roles", &obj.SystemRoles, UnmarshalRole) + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalV2PolicySubject unmarshals an instance of V2PolicySubject from the specified map of raw messages. +func UnmarshalV2PolicySubject(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(V2PolicySubject) + err = core.UnmarshalModel(m, "attributes", &obj.Attributes, UnmarshalV2PolicySubjectAttribute) if err != nil { return } @@ -3924,29 +5899,43 @@ func UnmarshalRoleList(m map[string]json.RawMessage, result interface{}) (err er return } -// SubjectAttribute : An attribute associated with a subject. -type SubjectAttribute struct { - // The name of an attribute. - Name *string `json:"name" validate:"required"` +// V2PolicySubjectAttribute : Subject attribute for whom the policy grants access. +type V2PolicySubjectAttribute struct { + // The name of a subject attribute, e.g., iam_id, access_group_id. + Key *string `json:"key" validate:"required"` - // The value of an attribute. + // The operator of an attribute. + Operator *string `json:"operator" validate:"required"` + + // The value of the ID of the subject, e.g., service ID, access group ID, IAM ID. 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), +// Constants associated with the V2PolicySubjectAttribute.Operator property. +// The operator of an attribute. +const ( + V2PolicySubjectAttributeOperatorStringequalsConst = "stringEquals" +) + +// NewV2PolicySubjectAttribute : Instantiate V2PolicySubjectAttribute (Generic Model Constructor) +func (*IamPolicyManagementV1) NewV2PolicySubjectAttribute(key string, operator string, value string) (_model *V2PolicySubjectAttribute, err error) { + _model = &V2PolicySubjectAttribute{ + Key: core.StringPtr(key), + Operator: core.StringPtr(operator), 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) +// UnmarshalV2PolicySubjectAttribute unmarshals an instance of V2PolicySubjectAttribute from the specified map of raw messages. +func UnmarshalV2PolicySubjectAttribute(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(V2PolicySubjectAttribute) + err = core.UnmarshalPrimitive(m, "key", &obj.Key) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operator", &obj.Operator) if err != nil { return } diff --git a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go index 7ea2cbef..634a3084 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,18 @@ 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 + testPolicyAssignmentId string ) var shouldSkipTest = func() { @@ -676,5 +681,400 @@ 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.AccountID).ToNot(BeNil()) + Expect(policyTemplate.Version).ToNot(BeNil()) + Expect(policyTemplate.Name).ToNot(BeNil()) + Expect(policyTemplate.Policy).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()) + 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() { + 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() { + // 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..3b80e7ff 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,15 @@ 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 = "" + testPolicyAssignmentId string = "" + examplePolicyTemplateName = "PolicySampleTemplateTestV1" ) var shouldSkipTest = func() { @@ -643,6 +649,361 @@ 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: &examplePolicyTemplateName, + AccountID: &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(examplePolicyTemplateName))) + 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: &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].Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplateCollection.PolicyTemplates[0].AccountID).To(Equal(&testAccountID)) + }) + }) + + Describe(`GetPolicyTemplate - Retrieve latest policy template version by template ID`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetPolicyTemplate(getPolicyTemplateOptions *GetPolicyTemplateOptions)`, func() { + getPolicyTemplateOptions := &iampolicymanagementv1.GetPolicyTemplateOptions{ + PolicyTemplateID: &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(&examplePolicyTemplateName)) + Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplate.AccountID).To(Equal(&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: &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: &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(&examplePolicyTemplateName)) + Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplate.AccountID).To(Equal(&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: &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: &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: &testPolicyTemplateID, + Version: &testPolicyTemplateVersion, + IfMatch: &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(&examplePolicyTemplateName)) + Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access"))) + Expect(policyTemplate.AccountID).To(Equal(&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: &testPolicyTemplateID, + Version: &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(&testAccountID)) + }) + }) + + Describe(`CommitPolicyTemplate - Commit a policy template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CommitPolicyTemplate(commitPolicyTemplateOptions *CommitPolicyTemplateOptions)`, func() { + commitPolicyTemplateOptions := &iampolicymanagementv1.CommitPolicyTemplateOptions{ + PolicyTemplateID: &testPolicyTemplateID, + Version: &testPolicyTemplateVersion, + IfMatch: &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"), + } + + polcyTemplateAssignmentCollection, response, err := service.ListPolicyAssignments(listPolicyAssignmentsOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(polcyTemplateAssignmentCollection).ToNot(BeNil()) + 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 + }) + }) + + 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()) + }) + }) + + Describe(`DeletePolicyTemplateVersion - Delete a policy template version by ID and version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`DeletePolicyTemplateVersion(deletePolicyTemplateVersionOptions *DeletePolicyTemplateVersionOptions)`, func() { + deletePolicyTemplateVersionOptions := &iampolicymanagementv1.DeletePolicyTemplateVersionOptions{ + PolicyTemplateID: &testPolicyTemplateID, + Version: &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: &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..4454ff35 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,3030 @@ 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.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) + 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.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 + 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.Committed = core.BoolPtr(true) + 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.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("") + 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.Committed = core.BoolPtr(true) + 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.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) + 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.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 + 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.Committed = core.BoolPtr(true) + 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.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("") + 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.Committed = core.BoolPtr(true) + 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", "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() { + 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", "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() { + 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", "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() { + 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", "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() { + 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 +7648,189 @@ 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.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() { // Construct an instance of the CreateRoleOptions model createRoleOptionsDisplayName := "testString" @@ -4763,6 +7964,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 +8007,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 +8027,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 +8108,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 +8276,101 @@ 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.SetCommitted(true) + 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.Committed).To(Equal(core.BoolPtr(true))) + Expect(replacePolicyTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewReplaceRoleOptions successfully`, func() { // Construct an instance of the ReplaceRoleOptions model roleID := "testString" @@ -5103,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) @@ -5117,6 +8528,20 @@ 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 + 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" @@ -5168,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"