From 45c5ec8a42a96e0e55f9086304f7d8650a03ad59 Mon Sep 17 00:00:00 2001 From: HARI K ARLA Date: Sun, 23 Jul 2023 02:01:13 +0530 Subject: [PATCH] feat (IAM Access Groups): Add support for access group templates Signed-off-by: HARI K ARLA --- iamaccessgroupsv2/iam_access_groups_v2.go | 5995 +++++++++++++---- .../iam_access_groups_v2_examples_test.go | 536 +- .../iam_access_groups_v2_integration_test.go | 593 +- .../iam_access_groups_v2_suite_test.go | 2 +- .../iam_access_groups_v2_test.go | 4893 +++++++++++++- 5 files changed, 10623 insertions(+), 1396 deletions(-) diff --git a/iamaccessgroupsv2/iam_access_groups_v2.go b/iamaccessgroupsv2/iam_access_groups_v2.go index 0c436ab1..4cc930d5 100644 --- a/iamaccessgroupsv2/iam_access_groups_v2.go +++ b/iamaccessgroupsv2/iam_access_groups_v2.go @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2020, 2022. + * (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. @@ -15,7 +15,7 @@ */ /* - * IBM OpenAPI SDK Code Generator Version: 3.60.0-13f6e1ba-20221019-164457 + * IBM OpenAPI SDK Code Generator Version: 3.74.0-89f1dbab-20230630-160213 */ // Package iamaccessgroupsv2 : Operations and models for the IamAccessGroupsV2 service @@ -284,6 +284,9 @@ func (iamAccessGroups *IamAccessGroupsV2) ListAccessGroupsWithContext(ctx contex if listAccessGroupsOptions.IamID != nil { builder.AddQuery("iam_id", fmt.Sprint(*listAccessGroupsOptions.IamID)) } + if listAccessGroupsOptions.Search != nil { + builder.AddQuery("search", fmt.Sprint(*listAccessGroupsOptions.Search)) + } if listAccessGroupsOptions.MembershipType != nil { builder.AddQuery("membership_type", fmt.Sprint(*listAccessGroupsOptions.MembershipType)) } @@ -551,7 +554,7 @@ func (iamAccessGroups *IamAccessGroupsV2) IsMemberOfAccessGroupWithContext(ctx c pathParamsMap := map[string]string{ "access_group_id": *isMemberOfAccessGroupOptions.AccessGroupID, - "iam_id": *isMemberOfAccessGroupOptions.IamID, + "iam_id": *isMemberOfAccessGroupOptions.IamID, } builder := core.NewRequestBuilder(core.HEAD) @@ -767,7 +770,7 @@ func (iamAccessGroups *IamAccessGroupsV2) RemoveMemberFromAccessGroupWithContext pathParamsMap := map[string]string{ "access_group_id": *removeMemberFromAccessGroupOptions.AccessGroupID, - "iam_id": *removeMemberFromAccessGroupOptions.IamID, + "iam_id": *removeMemberFromAccessGroupOptions.IamID, } builder := core.NewRequestBuilder(core.DELETE) @@ -1192,7 +1195,7 @@ func (iamAccessGroups *IamAccessGroupsV2) GetAccessGroupRuleWithContext(ctx cont pathParamsMap := map[string]string{ "access_group_id": *getAccessGroupRuleOptions.AccessGroupID, - "rule_id": *getAccessGroupRuleOptions.RuleID, + "rule_id": *getAccessGroupRuleOptions.RuleID, } builder := core.NewRequestBuilder(core.GET) @@ -1257,7 +1260,7 @@ func (iamAccessGroups *IamAccessGroupsV2) ReplaceAccessGroupRuleWithContext(ctx pathParamsMap := map[string]string{ "access_group_id": *replaceAccessGroupRuleOptions.AccessGroupID, - "rule_id": *replaceAccessGroupRuleOptions.RuleID, + "rule_id": *replaceAccessGroupRuleOptions.RuleID, } builder := core.NewRequestBuilder(core.PUT) @@ -1344,7 +1347,7 @@ func (iamAccessGroups *IamAccessGroupsV2) RemoveAccessGroupRuleWithContext(ctx c pathParamsMap := map[string]string{ "access_group_id": *removeAccessGroupRuleOptions.AccessGroupID, - "rule_id": *removeAccessGroupRuleOptions.RuleID, + "rule_id": *removeAccessGroupRuleOptions.RuleID, } builder := core.NewRequestBuilder(core.DELETE) @@ -1511,1066 +1514,1135 @@ func (iamAccessGroups *IamAccessGroupsV2) UpdateAccountSettingsWithContext(ctx c return } -// AccountSettings : The access groups settings for a specific account. -type AccountSettings struct { - // The account id of the settings being shown. - AccountID *string `json:"account_id,omitempty"` - - // The timestamp the settings were last edited at. - LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` - - // The `iam_id` of the entity that last modified the settings. - LastModifiedByID *string `json:"last_modified_by_id,omitempty"` - - // This flag controls the public access feature within the account. It is set to true by default. Note: When this flag - // is set to false, all policies within the account attached to the Public Access group will be deleted. - PublicAccessEnabled *bool `json:"public_access_enabled,omitempty"` +// CreateTemplate : Create Template +// Endpoint to create an access group template. +func (iamAccessGroups *IamAccessGroupsV2) CreateTemplate(createTemplateOptions *CreateTemplateOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.CreateTemplateWithContext(context.Background(), createTemplateOptions) } -// UnmarshalAccountSettings unmarshals an instance of AccountSettings from the specified map of raw messages. -func UnmarshalAccountSettings(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(AccountSettings) - err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) +// CreateTemplateWithContext is an alternate form of the CreateTemplate method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) CreateTemplateWithContext(ctx context.Context, createTemplateOptions *CreateTemplateOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createTemplateOptions, "createTemplateOptions cannot be nil") if err != nil { return } - err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) + err = core.ValidateStruct(createTemplateOptions, "createTemplateOptions") if err != nil { return } - err = core.UnmarshalPrimitive(m, "public_access_enabled", &obj.PublicAccessEnabled) + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates`, nil) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} -// AddAccessGroupRuleOptions : The AddAccessGroupRule options. -type AddAccessGroupRuleOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` - - // The number of hours that the rule lives for. - Expiration *int64 `json:"expiration" validate:"required"` - - // The url of the identity provider. - RealmName *string `json:"realm_name" validate:"required"` - - // A list of conditions the rule must satisfy. - Conditions []RuleConditions `json:"conditions" validate:"required"` - - // The name of the rule. - Name *string `json:"name,omitempty"` - - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewAddAccessGroupRuleOptions : Instantiate AddAccessGroupRuleOptions -func (*IamAccessGroupsV2) NewAddAccessGroupRuleOptions(accessGroupID string, expiration int64, realmName string, conditions []RuleConditions) *AddAccessGroupRuleOptions { - return &AddAccessGroupRuleOptions{ - AccessGroupID: core.StringPtr(accessGroupID), - Expiration: core.Int64Ptr(expiration), - RealmName: core.StringPtr(realmName), - Conditions: conditions, + for headerName, headerValue := range createTemplateOptions.Headers { + builder.AddHeader(headerName, headerValue) } -} - -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *AddAccessGroupRuleOptions) SetAccessGroupID(accessGroupID string) *AddAccessGroupRuleOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options -} - -// SetExpiration : Allow user to set Expiration -func (_options *AddAccessGroupRuleOptions) SetExpiration(expiration int64) *AddAccessGroupRuleOptions { - _options.Expiration = core.Int64Ptr(expiration) - return _options -} - -// SetRealmName : Allow user to set RealmName -func (_options *AddAccessGroupRuleOptions) SetRealmName(realmName string) *AddAccessGroupRuleOptions { - _options.RealmName = core.StringPtr(realmName) - return _options -} - -// SetConditions : Allow user to set Conditions -func (_options *AddAccessGroupRuleOptions) SetConditions(conditions []RuleConditions) *AddAccessGroupRuleOptions { - _options.Conditions = conditions - return _options -} -// SetName : Allow user to set Name -func (_options *AddAccessGroupRuleOptions) SetName(name string) *AddAccessGroupRuleOptions { - _options.Name = core.StringPtr(name) - return _options -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "CreateTemplate") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if createTemplateOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*createTemplateOptions.TransactionID)) + } -// SetTransactionID : Allow user to set TransactionID -func (_options *AddAccessGroupRuleOptions) SetTransactionID(transactionID string) *AddAccessGroupRuleOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options -} + body := make(map[string]interface{}) + if createTemplateOptions.Name != nil { + body["name"] = createTemplateOptions.Name + } + if createTemplateOptions.AccountID != nil { + body["account_id"] = createTemplateOptions.AccountID + } + if createTemplateOptions.Description != nil { + body["description"] = createTemplateOptions.Description + } + if createTemplateOptions.Group != nil { + body["group"] = createTemplateOptions.Group + } + if createTemplateOptions.PolicyTemplateReferences != nil { + body["policy_template_references"] = createTemplateOptions.PolicyTemplateReferences + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } -// SetHeaders : Allow user to set Headers -func (options *AddAccessGroupRuleOptions) SetHeaders(param map[string]string) *AddAccessGroupRuleOptions { - options.Headers = param - return options -} + request, err := builder.Build() + if err != nil { + return + } -// AddGroupMembersRequestMembersItem : AddGroupMembersRequestMembersItem struct -type AddGroupMembersRequestMembersItem struct { - // The IBMid, service ID or trusted profile ID of the member. - IamID *string `json:"iam_id" validate:"required"` + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateTemplateResponse) + if err != nil { + return + } + response.Result = result + } - // The type of the member, must be either "user", "service" or "profile". - Type *string `json:"type" validate:"required"` + return } -// NewAddGroupMembersRequestMembersItem : Instantiate AddGroupMembersRequestMembersItem (Generic Model Constructor) -func (*IamAccessGroupsV2) NewAddGroupMembersRequestMembersItem(iamID string, typeVar string) (_model *AddGroupMembersRequestMembersItem, err error) { - _model = &AddGroupMembersRequestMembersItem{ - IamID: core.StringPtr(iamID), - Type: core.StringPtr(typeVar), - } - err = core.ValidateStruct(_model, "required parameters") - return +// ListTemplates : List Templates +// Endpoint to list access group templates in a given account. +func (iamAccessGroups *IamAccessGroupsV2) ListTemplates(listTemplatesOptions *ListTemplatesOptions) (result *ListTemplatesResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.ListTemplatesWithContext(context.Background(), listTemplatesOptions) } -// UnmarshalAddGroupMembersRequestMembersItem unmarshals an instance of AddGroupMembersRequestMembersItem from the specified map of raw messages. -func UnmarshalAddGroupMembersRequestMembersItem(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(AddGroupMembersRequestMembersItem) - err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) +// ListTemplatesWithContext is an alternate form of the ListTemplates method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) ListTemplatesWithContext(ctx context.Context, listTemplatesOptions *ListTemplatesOptions) (result *ListTemplatesResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listTemplatesOptions, "listTemplatesOptions cannot be nil") if err != nil { return } - err = core.UnmarshalPrimitive(m, "type", &obj.Type) + err = core.ValidateStruct(listTemplatesOptions, "listTemplatesOptions") if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// AddGroupMembersResponse : The members added to an access group. -type AddGroupMembersResponse struct { - // The members added to an access group. - Members []AddGroupMembersResponseMembersItem `json:"members,omitempty"` -} -// UnmarshalAddGroupMembersResponse unmarshals an instance of AddGroupMembersResponse from the specified map of raw messages. -func UnmarshalAddGroupMembersResponse(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(AddGroupMembersResponse) - err = core.UnmarshalModel(m, "members", &obj.Members, UnmarshalAddGroupMembersResponseMembersItem) + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates`, nil) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} -// AddGroupMembersResponseMembersItem : AddGroupMembersResponseMembersItem struct -type AddGroupMembersResponseMembersItem struct { - // The IBMid or Service Id of the member. - IamID *string `json:"iam_id,omitempty"` + for headerName, headerValue := range listTemplatesOptions.Headers { + builder.AddHeader(headerName, headerValue) + } - // The member type - either `user`, `service` or `profile`. - Type *string `json:"type,omitempty"` + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "ListTemplates") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if listTemplatesOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*listTemplatesOptions.TransactionID)) + } - // The timestamp the membership was created at. - CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + builder.AddQuery("account_id", fmt.Sprint(*listTemplatesOptions.AccountID)) + if listTemplatesOptions.Limit != nil { + builder.AddQuery("limit", fmt.Sprint(*listTemplatesOptions.Limit)) + } + if listTemplatesOptions.Offset != nil { + builder.AddQuery("offset", fmt.Sprint(*listTemplatesOptions.Offset)) + } + if listTemplatesOptions.Verbose != nil { + builder.AddQuery("verbose", fmt.Sprint(*listTemplatesOptions.Verbose)) + } - // The `iam_id` of the entity that created the membership. - CreatedByID *string `json:"created_by_id,omitempty"` + request, err := builder.Build() + if err != nil { + return + } - // The outcome of the operation on this `iam_id`. - StatusCode *int64 `json:"status_code,omitempty"` + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListTemplatesResponse) + if err != nil { + return + } + response.Result = result + } - // A transaction-id that can be used for debugging purposes. - Trace *string `json:"trace,omitempty"` + return +} - // A list of errors that occurred when trying to add members to a group. - Errors []Error `json:"errors,omitempty"` +// CreateTemplateVersion : Create template version +// Endpoint to create a new template version. +func (iamAccessGroups *IamAccessGroupsV2) CreateTemplateVersion(createTemplateVersionOptions *CreateTemplateVersionOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.CreateTemplateVersionWithContext(context.Background(), createTemplateVersionOptions) } -// UnmarshalAddGroupMembersResponseMembersItem unmarshals an instance of AddGroupMembersResponseMembersItem from the specified map of raw messages. -func UnmarshalAddGroupMembersResponseMembersItem(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(AddGroupMembersResponseMembersItem) - err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) +// CreateTemplateVersionWithContext is an alternate form of the CreateTemplateVersion method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) CreateTemplateVersionWithContext(ctx context.Context, createTemplateVersionOptions *CreateTemplateVersionOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createTemplateVersionOptions, "createTemplateVersionOptions cannot be nil") if err != nil { return } - err = core.UnmarshalPrimitive(m, "type", &obj.Type) + err = core.ValidateStruct(createTemplateVersionOptions, "createTemplateVersionOptions") if err != nil { return } - err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) - if err != nil { - return + + pathParamsMap := map[string]string{ + "template_id": *createTemplateVersionOptions.TemplateID, } - err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates/{template_id}/versions`, pathParamsMap) if err != nil { return } - err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + + for headerName, headerValue := range createTemplateVersionOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "CreateTemplateVersion") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if createTemplateVersionOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*createTemplateVersionOptions.TransactionID)) + } + + body := make(map[string]interface{}) + if createTemplateVersionOptions.Name != nil { + body["name"] = createTemplateVersionOptions.Name + } + if createTemplateVersionOptions.Description != nil { + body["description"] = createTemplateVersionOptions.Description + } + if createTemplateVersionOptions.Group != nil { + body["group"] = createTemplateVersionOptions.Group + } + if createTemplateVersionOptions.PolicyTemplateReferences != nil { + body["policy_template_references"] = createTemplateVersionOptions.PolicyTemplateReferences + } + _, err = builder.SetBodyContentJSON(body) if err != nil { return } - err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + + request, err := builder.Build() if err != nil { return } - err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalError) + + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// AddMemberToMultipleAccessGroupsOptions : The AddMemberToMultipleAccessGroups options. -type AddMemberToMultipleAccessGroupsOptions struct { - // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the - // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the - // Authorization token. - AccountID *string `json:"account_id" validate:"required"` + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateTemplateResponse) + if err != nil { + return + } + response.Result = result + } - // The IAM identifier. - IamID *string `json:"iam_id" validate:"required,ne="` + return +} - // The type of the member, must be either "user", "service" or "profile". - Type *string `json:"type,omitempty"` +// ListTemplateVersions : List template versions +// Endpoint to list all the versions of a template. +func (iamAccessGroups *IamAccessGroupsV2) ListTemplateVersions(listTemplateVersionsOptions *ListTemplateVersionsOptions) (result *ListTemplateVersionsResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.ListTemplateVersionsWithContext(context.Background(), listTemplateVersionsOptions) +} - // The ids of the access groups a given member is to be added to. - Groups []string `json:"groups,omitempty"` +// ListTemplateVersionsWithContext is an alternate form of the ListTemplateVersions method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) ListTemplateVersionsWithContext(ctx context.Context, listTemplateVersionsOptions *ListTemplateVersionsOptions) (result *ListTemplateVersionsResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listTemplateVersionsOptions, "listTemplateVersionsOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(listTemplateVersionsOptions, "listTemplateVersionsOptions") + if err != nil { + return + } - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` + pathParamsMap := map[string]string{ + "template_id": *listTemplateVersionsOptions.TemplateID, + } - // Allows users to set headers on API requests - Headers map[string]string -} + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates/{template_id}/versions`, pathParamsMap) + if err != nil { + return + } -// NewAddMemberToMultipleAccessGroupsOptions : Instantiate AddMemberToMultipleAccessGroupsOptions -func (*IamAccessGroupsV2) NewAddMemberToMultipleAccessGroupsOptions(accountID string, iamID string) *AddMemberToMultipleAccessGroupsOptions { - return &AddMemberToMultipleAccessGroupsOptions{ - AccountID: core.StringPtr(accountID), - IamID: core.StringPtr(iamID), + for headerName, headerValue := range listTemplateVersionsOptions.Headers { + builder.AddHeader(headerName, headerValue) } -} -// SetAccountID : Allow user to set AccountID -func (_options *AddMemberToMultipleAccessGroupsOptions) SetAccountID(accountID string) *AddMemberToMultipleAccessGroupsOptions { - _options.AccountID = core.StringPtr(accountID) - return _options -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "ListTemplateVersions") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") -// SetIamID : Allow user to set IamID -func (_options *AddMemberToMultipleAccessGroupsOptions) SetIamID(iamID string) *AddMemberToMultipleAccessGroupsOptions { - _options.IamID = core.StringPtr(iamID) - return _options -} + if listTemplateVersionsOptions.Limit != nil { + builder.AddQuery("limit", fmt.Sprint(*listTemplateVersionsOptions.Limit)) + } + if listTemplateVersionsOptions.Offset != nil { + builder.AddQuery("offset", fmt.Sprint(*listTemplateVersionsOptions.Offset)) + } -// SetType : Allow user to set Type -func (_options *AddMemberToMultipleAccessGroupsOptions) SetType(typeVar string) *AddMemberToMultipleAccessGroupsOptions { - _options.Type = core.StringPtr(typeVar) - return _options -} + request, err := builder.Build() + if err != nil { + return + } -// SetGroups : Allow user to set Groups -func (_options *AddMemberToMultipleAccessGroupsOptions) SetGroups(groups []string) *AddMemberToMultipleAccessGroupsOptions { - _options.Groups = groups - return _options -} + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListTemplateVersionsResponse) + if err != nil { + return + } + response.Result = result + } -// SetTransactionID : Allow user to set TransactionID -func (_options *AddMemberToMultipleAccessGroupsOptions) SetTransactionID(transactionID string) *AddMemberToMultipleAccessGroupsOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options + return } -// SetHeaders : Allow user to set Headers -func (options *AddMemberToMultipleAccessGroupsOptions) SetHeaders(param map[string]string) *AddMemberToMultipleAccessGroupsOptions { - options.Headers = param - return options +// GetTemplateVersion : Get template version +// Endpoint to get a specific template version. +func (iamAccessGroups *IamAccessGroupsV2) GetTemplateVersion(getTemplateVersionOptions *GetTemplateVersionOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.GetTemplateVersionWithContext(context.Background(), getTemplateVersionOptions) } -// AddMembersToAccessGroupOptions : The AddMembersToAccessGroup options. -type AddMembersToAccessGroupOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` - - // An array of member objects to add to an access group. - Members []AddGroupMembersRequestMembersItem `json:"members,omitempty"` +// GetTemplateVersionWithContext is an alternate form of the GetTemplateVersion method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) GetTemplateVersionWithContext(ctx context.Context, getTemplateVersionOptions *GetTemplateVersionOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getTemplateVersionOptions, "getTemplateVersionOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getTemplateVersionOptions, "getTemplateVersionOptions") + if err != nil { + return + } - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` + pathParamsMap := map[string]string{ + "template_id": *getTemplateVersionOptions.TemplateID, + "version_num": *getTemplateVersionOptions.VersionNum, + } - // Allows users to set headers on API requests - Headers map[string]string -} + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates/{template_id}/versions/{version_num}`, pathParamsMap) + if err != nil { + return + } -// NewAddMembersToAccessGroupOptions : Instantiate AddMembersToAccessGroupOptions -func (*IamAccessGroupsV2) NewAddMembersToAccessGroupOptions(accessGroupID string) *AddMembersToAccessGroupOptions { - return &AddMembersToAccessGroupOptions{ - AccessGroupID: core.StringPtr(accessGroupID), + for headerName, headerValue := range getTemplateVersionOptions.Headers { + builder.AddHeader(headerName, headerValue) } -} -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *AddMembersToAccessGroupOptions) SetAccessGroupID(accessGroupID string) *AddMembersToAccessGroupOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "GetTemplateVersion") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if getTemplateVersionOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*getTemplateVersionOptions.TransactionID)) + } -// SetMembers : Allow user to set Members -func (_options *AddMembersToAccessGroupOptions) SetMembers(members []AddGroupMembersRequestMembersItem) *AddMembersToAccessGroupOptions { - _options.Members = members - return _options -} + request, err := builder.Build() + if err != nil { + return + } -// SetTransactionID : Allow user to set TransactionID -func (_options *AddMembersToAccessGroupOptions) SetTransactionID(transactionID string) *AddMembersToAccessGroupOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options -} + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateTemplateResponse) + if err != nil { + return + } + response.Result = result + } -// SetHeaders : Allow user to set Headers -func (options *AddMembersToAccessGroupOptions) SetHeaders(param map[string]string) *AddMembersToAccessGroupOptions { - options.Headers = param - return options + return } -// AddMembershipMultipleGroupsResponse : The response from the add member to multiple access groups request. -type AddMembershipMultipleGroupsResponse struct { - // The iam_id of a member. - IamID *string `json:"iam_id,omitempty"` - - // The list of access groups a member was added to. - Groups []AddMembershipMultipleGroupsResponseGroupsItem `json:"groups,omitempty"` +// UpdateTemplateVersion : Update template version +// Endpoint to update a template version. +func (iamAccessGroups *IamAccessGroupsV2) UpdateTemplateVersion(updateTemplateVersionOptions *UpdateTemplateVersionOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.UpdateTemplateVersionWithContext(context.Background(), updateTemplateVersionOptions) } -// UnmarshalAddMembershipMultipleGroupsResponse unmarshals an instance of AddMembershipMultipleGroupsResponse from the specified map of raw messages. -func UnmarshalAddMembershipMultipleGroupsResponse(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(AddMembershipMultipleGroupsResponse) - err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) +// UpdateTemplateVersionWithContext is an alternate form of the UpdateTemplateVersion method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) UpdateTemplateVersionWithContext(ctx context.Context, updateTemplateVersionOptions *UpdateTemplateVersionOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(updateTemplateVersionOptions, "updateTemplateVersionOptions cannot be nil") if err != nil { return } - err = core.UnmarshalModel(m, "groups", &obj.Groups, UnmarshalAddMembershipMultipleGroupsResponseGroupsItem) + err = core.ValidateStruct(updateTemplateVersionOptions, "updateTemplateVersionOptions") if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} -// AddMembershipMultipleGroupsResponseGroupsItem : AddMembershipMultipleGroupsResponseGroupsItem struct -type AddMembershipMultipleGroupsResponseGroupsItem struct { - // The access group that the member is to be added to. - AccessGroupID *string `json:"access_group_id,omitempty"` + pathParamsMap := map[string]string{ + "template_id": *updateTemplateVersionOptions.TemplateID, + "version_num": *updateTemplateVersionOptions.VersionNum, + } - // The outcome of the add membership operation on this `access_group_id`. - StatusCode *int64 `json:"status_code,omitempty"` + builder := core.NewRequestBuilder(core.PUT) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates/{template_id}/versions/{version_num}`, pathParamsMap) + if err != nil { + return + } - // A transaction-id that can be used for debugging purposes. - Trace *string `json:"trace,omitempty"` + for headerName, headerValue := range updateTemplateVersionOptions.Headers { + builder.AddHeader(headerName, headerValue) + } - // List of errors encountered when adding member to access group. - Errors []Error `json:"errors,omitempty"` -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "UpdateTemplateVersion") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if updateTemplateVersionOptions.IfMatch != nil { + builder.AddHeader("If-Match", fmt.Sprint(*updateTemplateVersionOptions.IfMatch)) + } + if updateTemplateVersionOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*updateTemplateVersionOptions.TransactionID)) + } -// UnmarshalAddMembershipMultipleGroupsResponseGroupsItem unmarshals an instance of AddMembershipMultipleGroupsResponseGroupsItem from the specified map of raw messages. -func UnmarshalAddMembershipMultipleGroupsResponseGroupsItem(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(AddMembershipMultipleGroupsResponseGroupsItem) - err = core.UnmarshalPrimitive(m, "access_group_id", &obj.AccessGroupID) - if err != nil { - return + body := make(map[string]interface{}) + if updateTemplateVersionOptions.ID != nil { + body["id"] = updateTemplateVersionOptions.ID } - err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + if updateTemplateVersionOptions.Name != nil { + body["name"] = updateTemplateVersionOptions.Name + } + if updateTemplateVersionOptions.Description != nil { + body["description"] = updateTemplateVersionOptions.Description + } + if updateTemplateVersionOptions.AccountID != nil { + body["account_id"] = updateTemplateVersionOptions.AccountID + } + if updateTemplateVersionOptions.Version != nil { + body["version"] = updateTemplateVersionOptions.Version + } + if updateTemplateVersionOptions.Committed != nil { + body["committed"] = updateTemplateVersionOptions.Committed + } + if updateTemplateVersionOptions.Group != nil { + body["group"] = updateTemplateVersionOptions.Group + } + if updateTemplateVersionOptions.PolicyTemplateReferences != nil { + body["policy_template_references"] = updateTemplateVersionOptions.PolicyTemplateReferences + } + if updateTemplateVersionOptions.Href != nil { + body["href"] = updateTemplateVersionOptions.Href + } + if updateTemplateVersionOptions.CreatedAt != nil { + body["created_at"] = updateTemplateVersionOptions.CreatedAt + } + if updateTemplateVersionOptions.CreatedByID != nil { + body["created_by_id"] = updateTemplateVersionOptions.CreatedByID + } + if updateTemplateVersionOptions.LastModifiedAt != nil { + body["last_modified_at"] = updateTemplateVersionOptions.LastModifiedAt + } + if updateTemplateVersionOptions.LastModifiedByID != nil { + body["last_modified_by_id"] = updateTemplateVersionOptions.LastModifiedByID + } + _, err = builder.SetBodyContentJSON(body) if err != nil { return } - err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + + request, err := builder.Build() if err != nil { return } - err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalError) + + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateTemplateResponse) + if err != nil { + return + } + response.Result = result + } + return } -// CreateAccessGroupOptions : The CreateAccessGroup options. -type CreateAccessGroupOptions struct { - // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the - // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the - // Authorization token. - AccountID *string `json:"account_id" validate:"required"` - - // Assign the specified name to the access group. This field is case-insensitive and has a limit of 100 characters. The - // group name has to be unique within an account. - Name *string `json:"name" validate:"required"` +// DeleteTemplateVersion : Delete template version +// Endpoint to delete a template version. +func (iamAccessGroups *IamAccessGroupsV2) DeleteTemplateVersion(deleteTemplateVersionOptions *DeleteTemplateVersionOptions) (response *core.DetailedResponse, err error) { + return iamAccessGroups.DeleteTemplateVersionWithContext(context.Background(), deleteTemplateVersionOptions) +} - // Assign an optional description for the access group. This field has a limit of 250 characters. - Description *string `json:"description,omitempty"` +// DeleteTemplateVersionWithContext is an alternate form of the DeleteTemplateVersion method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) DeleteTemplateVersionWithContext(ctx context.Context, deleteTemplateVersionOptions *DeleteTemplateVersionOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteTemplateVersionOptions, "deleteTemplateVersionOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(deleteTemplateVersionOptions, "deleteTemplateVersionOptions") + if err != nil { + return + } - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` + pathParamsMap := map[string]string{ + "template_id": *deleteTemplateVersionOptions.TemplateID, + "version_num": *deleteTemplateVersionOptions.VersionNum, + } - // Allows users to set headers on API requests - Headers map[string]string -} + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates/{template_id}/versions/{version_num}`, pathParamsMap) + if err != nil { + return + } -// NewCreateAccessGroupOptions : Instantiate CreateAccessGroupOptions -func (*IamAccessGroupsV2) NewCreateAccessGroupOptions(accountID string, name string) *CreateAccessGroupOptions { - return &CreateAccessGroupOptions{ - AccountID: core.StringPtr(accountID), - Name: core.StringPtr(name), + for headerName, headerValue := range deleteTemplateVersionOptions.Headers { + builder.AddHeader(headerName, headerValue) } -} -// SetAccountID : Allow user to set AccountID -func (_options *CreateAccessGroupOptions) SetAccountID(accountID string) *CreateAccessGroupOptions { - _options.AccountID = core.StringPtr(accountID) - return _options -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "DeleteTemplateVersion") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + if deleteTemplateVersionOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*deleteTemplateVersionOptions.TransactionID)) + } -// SetName : Allow user to set Name -func (_options *CreateAccessGroupOptions) SetName(name string) *CreateAccessGroupOptions { - _options.Name = core.StringPtr(name) - return _options -} + request, err := builder.Build() + if err != nil { + return + } -// SetDescription : Allow user to set Description -func (_options *CreateAccessGroupOptions) SetDescription(description string) *CreateAccessGroupOptions { - _options.Description = core.StringPtr(description) - return _options -} + response, err = iamAccessGroups.Service.Request(request, nil) -// SetTransactionID : Allow user to set TransactionID -func (_options *CreateAccessGroupOptions) SetTransactionID(transactionID string) *CreateAccessGroupOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options + return } -// SetHeaders : Allow user to set Headers -func (options *CreateAccessGroupOptions) SetHeaders(param map[string]string) *CreateAccessGroupOptions { - options.Headers = param - return options +// CommitTemplate : Commit a template +// Endpoint to commit a template. After you commit the template, the version is immutable. +func (iamAccessGroups *IamAccessGroupsV2) CommitTemplate(commitTemplateOptions *CommitTemplateOptions) (response *core.DetailedResponse, err error) { + return iamAccessGroups.CommitTemplateWithContext(context.Background(), commitTemplateOptions) } -// DeleteAccessGroupOptions : The DeleteAccessGroup options. -type DeleteAccessGroupOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` - - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` +// CommitTemplateWithContext is an alternate form of the CommitTemplate method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) CommitTemplateWithContext(ctx context.Context, commitTemplateOptions *CommitTemplateOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(commitTemplateOptions, "commitTemplateOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(commitTemplateOptions, "commitTemplateOptions") + if err != nil { + return + } - // If force is true, delete the group as well as its associated members and rules. - Force *bool `json:"force,omitempty"` + pathParamsMap := map[string]string{ + "template_id": *commitTemplateOptions.TemplateID, + "version_num": *commitTemplateOptions.VersionNum, + } - // Allows users to set headers on API requests - Headers map[string]string -} + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates/{template_id}/versions/{version_num}/commit`, pathParamsMap) + if err != nil { + return + } -// NewDeleteAccessGroupOptions : Instantiate DeleteAccessGroupOptions -func (*IamAccessGroupsV2) NewDeleteAccessGroupOptions(accessGroupID string) *DeleteAccessGroupOptions { - return &DeleteAccessGroupOptions{ - AccessGroupID: core.StringPtr(accessGroupID), + for headerName, headerValue := range commitTemplateOptions.Headers { + builder.AddHeader(headerName, headerValue) } -} -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *DeleteAccessGroupOptions) SetAccessGroupID(accessGroupID string) *DeleteAccessGroupOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "CommitTemplate") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + if commitTemplateOptions.IfMatch != nil { + builder.AddHeader("If-Match", fmt.Sprint(*commitTemplateOptions.IfMatch)) + } + if commitTemplateOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*commitTemplateOptions.TransactionID)) + } -// SetTransactionID : Allow user to set TransactionID -func (_options *DeleteAccessGroupOptions) SetTransactionID(transactionID string) *DeleteAccessGroupOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options -} + request, err := builder.Build() + if err != nil { + return + } -// SetForce : Allow user to set Force -func (_options *DeleteAccessGroupOptions) SetForce(force bool) *DeleteAccessGroupOptions { - _options.Force = core.BoolPtr(force) - return _options -} + response, err = iamAccessGroups.Service.Request(request, nil) -// SetHeaders : Allow user to set Headers -func (options *DeleteAccessGroupOptions) SetHeaders(param map[string]string) *DeleteAccessGroupOptions { - options.Headers = param - return options + return } -// DeleteFromAllGroupsResponse : The response from the delete member from access groups request. -type DeleteFromAllGroupsResponse struct { - // The `iam_id` of the member to removed from groups. - IamID *string `json:"iam_id,omitempty"` - - // The groups the member was removed from. - Groups []DeleteFromAllGroupsResponseGroupsItem `json:"groups,omitempty"` +// GetLatestTemplateVersion : Get latest template version +// Endpoint to get the latest version of a template. +func (iamAccessGroups *IamAccessGroupsV2) GetLatestTemplateVersion(getLatestTemplateVersionOptions *GetLatestTemplateVersionOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.GetLatestTemplateVersionWithContext(context.Background(), getLatestTemplateVersionOptions) } -// UnmarshalDeleteFromAllGroupsResponse unmarshals an instance of DeleteFromAllGroupsResponse from the specified map of raw messages. -func UnmarshalDeleteFromAllGroupsResponse(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(DeleteFromAllGroupsResponse) - err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) +// GetLatestTemplateVersionWithContext is an alternate form of the GetLatestTemplateVersion method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) GetLatestTemplateVersionWithContext(ctx context.Context, getLatestTemplateVersionOptions *GetLatestTemplateVersionOptions) (result *CreateTemplateResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getLatestTemplateVersionOptions, "getLatestTemplateVersionOptions cannot be nil") if err != nil { return } - err = core.UnmarshalModel(m, "groups", &obj.Groups, UnmarshalDeleteFromAllGroupsResponseGroupsItem) + err = core.ValidateStruct(getLatestTemplateVersionOptions, "getLatestTemplateVersionOptions") if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// DeleteFromAllGroupsResponseGroupsItem : DeleteFromAllGroupsResponseGroupsItem struct -type DeleteFromAllGroupsResponseGroupsItem struct { - // The access group that the member is to be deleted from. - AccessGroupID *string `json:"access_group_id,omitempty"` - - // The outcome of the delete operation on this `access_group_id`. - StatusCode *int64 `json:"status_code,omitempty"` - - // A transaction-id that can be used for debugging purposes. - Trace *string `json:"trace,omitempty"` - // A list of errors that occurred when trying to remove a member from groups. - Errors []Error `json:"errors,omitempty"` -} + pathParamsMap := map[string]string{ + "template_id": *getLatestTemplateVersionOptions.TemplateID, + } -// UnmarshalDeleteFromAllGroupsResponseGroupsItem unmarshals an instance of DeleteFromAllGroupsResponseGroupsItem from the specified map of raw messages. -func UnmarshalDeleteFromAllGroupsResponseGroupsItem(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(DeleteFromAllGroupsResponseGroupsItem) - err = core.UnmarshalPrimitive(m, "access_group_id", &obj.AccessGroupID) + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates/{template_id}`, pathParamsMap) if err != nil { return } - err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) - if err != nil { - return + + for headerName, headerValue := range getLatestTemplateVersionOptions.Headers { + builder.AddHeader(headerName, headerValue) } - err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "GetLatestTemplateVersion") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if getLatestTemplateVersionOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*getLatestTemplateVersionOptions.TransactionID)) + } + + request, err := builder.Build() if err != nil { return } - err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalError) + + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateTemplateResponse) + if err != nil { + return + } + response.Result = result + } + return } -// DeleteGroupBulkMembersResponse : The access group id and the members removed from it. -type DeleteGroupBulkMembersResponse struct { - // The access group id. - AccessGroupID *string `json:"access_group_id,omitempty"` - - // The `iam_id`s removed from the access group. - Members []DeleteGroupBulkMembersResponseMembersItem `json:"members,omitempty"` +// DeleteTemplate : Delete template +// Endpoint to delete a template. All access assigned by that template is deleted from all of the accounts where the +// template was assigned. +func (iamAccessGroups *IamAccessGroupsV2) DeleteTemplate(deleteTemplateOptions *DeleteTemplateOptions) (response *core.DetailedResponse, err error) { + return iamAccessGroups.DeleteTemplateWithContext(context.Background(), deleteTemplateOptions) } -// UnmarshalDeleteGroupBulkMembersResponse unmarshals an instance of DeleteGroupBulkMembersResponse from the specified map of raw messages. -func UnmarshalDeleteGroupBulkMembersResponse(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(DeleteGroupBulkMembersResponse) - err = core.UnmarshalPrimitive(m, "access_group_id", &obj.AccessGroupID) +// DeleteTemplateWithContext is an alternate form of the DeleteTemplate method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) DeleteTemplateWithContext(ctx context.Context, deleteTemplateOptions *DeleteTemplateOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteTemplateOptions, "deleteTemplateOptions cannot be nil") if err != nil { return } - err = core.UnmarshalModel(m, "members", &obj.Members, UnmarshalDeleteGroupBulkMembersResponseMembersItem) + err = core.ValidateStruct(deleteTemplateOptions, "deleteTemplateOptions") if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} -// DeleteGroupBulkMembersResponseMembersItem : DeleteGroupBulkMembersResponseMembersItem struct -type DeleteGroupBulkMembersResponseMembersItem struct { - // The `iam_id` to be deleted. - IamID *string `json:"iam_id,omitempty"` + pathParamsMap := map[string]string{ + "template_id": *deleteTemplateOptions.TemplateID, + } - // A transaction-id that can be used for debugging purposes. - Trace *string `json:"trace,omitempty"` + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_templates/{template_id}`, pathParamsMap) + if err != nil { + return + } - // The outcome of the delete membership operation on this `access_group_id`. - StatusCode *int64 `json:"status_code,omitempty"` + for headerName, headerValue := range deleteTemplateOptions.Headers { + builder.AddHeader(headerName, headerValue) + } - // A list of errors that occurred when trying to remove a member from groups. - Errors []Error `json:"errors,omitempty"` -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "DeleteTemplate") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + if deleteTemplateOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*deleteTemplateOptions.TransactionID)) + } -// UnmarshalDeleteGroupBulkMembersResponseMembersItem unmarshals an instance of DeleteGroupBulkMembersResponseMembersItem from the specified map of raw messages. -func UnmarshalDeleteGroupBulkMembersResponseMembersItem(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(DeleteGroupBulkMembersResponseMembersItem) - err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) + request, err := builder.Build() if err != nil { return } - err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + + response, err = iamAccessGroups.Service.Request(request, nil) + + return +} + +// CreateAssignment : Create assignment +// Endpoint to assign a template to an account/account group. +func (iamAccessGroups *IamAccessGroupsV2) CreateAssignment(createAssignmentOptions *CreateAssignmentOptions) (result *TemplateCreateAssignmentResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.CreateAssignmentWithContext(context.Background(), createAssignmentOptions) +} + +// CreateAssignmentWithContext is an alternate form of the CreateAssignment method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) CreateAssignmentWithContext(ctx context.Context, createAssignmentOptions *CreateAssignmentOptions) (result *TemplateCreateAssignmentResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createAssignmentOptions, "createAssignmentOptions cannot be nil") if err != nil { return } - err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + err = core.ValidateStruct(createAssignmentOptions, "createAssignmentOptions") if err != nil { return } - err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalError) + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_assignments`, nil) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} -// Error : Error contains the code and message for an error returned to the user code is a string identifying the problem, -// examples "missing_field", "reserved_value" message is a string explaining the solution to the problem that was -// encountered. -type Error struct { - // A human-readable error code represented by a snake case string. - Code *string `json:"code,omitempty"` + for headerName, headerValue := range createAssignmentOptions.Headers { + builder.AddHeader(headerName, headerValue) + } - // A specific error message that details the issue or an action to take. - Message *string `json:"message,omitempty"` -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "CreateAssignment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if createAssignmentOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*createAssignmentOptions.TransactionID)) + } -// UnmarshalError unmarshals an instance of Error from the specified map of raw messages. -func UnmarshalError(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Error) - err = core.UnmarshalPrimitive(m, "code", &obj.Code) + body := make(map[string]interface{}) + if createAssignmentOptions.TemplateID != nil { + body["template_id"] = createAssignmentOptions.TemplateID + } + if createAssignmentOptions.TemplateVersion != nil { + body["template_version"] = createAssignmentOptions.TemplateVersion + } + if createAssignmentOptions.TargetType != nil { + body["target_type"] = createAssignmentOptions.TargetType + } + if createAssignmentOptions.Target != nil { + body["target"] = createAssignmentOptions.Target + } + _, err = builder.SetBodyContentJSON(body) if err != nil { return } - err = core.UnmarshalPrimitive(m, "message", &obj.Message) + + request, err := builder.Build() if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// GetAccessGroupOptions : The GetAccessGroup options. -type GetAccessGroupOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` - - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` - - // If show_federated is true, the group will return an is_federated value that is set to true if rules exist for the - // group. - ShowFederated *bool `json:"show_federated,omitempty"` - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewGetAccessGroupOptions : Instantiate GetAccessGroupOptions -func (*IamAccessGroupsV2) NewGetAccessGroupOptions(accessGroupID string) *GetAccessGroupOptions { - return &GetAccessGroupOptions{ - AccessGroupID: core.StringPtr(accessGroupID), + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalTemplateCreateAssignmentResponse) + if err != nil { + return + } + response.Result = result } -} -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *GetAccessGroupOptions) SetAccessGroupID(accessGroupID string) *GetAccessGroupOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options + return } -// SetTransactionID : Allow user to set TransactionID -func (_options *GetAccessGroupOptions) SetTransactionID(transactionID string) *GetAccessGroupOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options +// ListAssignments : List Assignments +// Endpoint to list template assignments. +func (iamAccessGroups *IamAccessGroupsV2) ListAssignments(listAssignmentsOptions *ListAssignmentsOptions) (result *TemplatesListAssignmentResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.ListAssignmentsWithContext(context.Background(), listAssignmentsOptions) } -// SetShowFederated : Allow user to set ShowFederated -func (_options *GetAccessGroupOptions) SetShowFederated(showFederated bool) *GetAccessGroupOptions { - _options.ShowFederated = core.BoolPtr(showFederated) - return _options -} +// ListAssignmentsWithContext is an alternate form of the ListAssignments method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) ListAssignmentsWithContext(ctx context.Context, listAssignmentsOptions *ListAssignmentsOptions) (result *TemplatesListAssignmentResponse, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(listAssignmentsOptions, "listAssignmentsOptions") + if err != nil { + return + } -// SetHeaders : Allow user to set Headers -func (options *GetAccessGroupOptions) SetHeaders(param map[string]string) *GetAccessGroupOptions { - options.Headers = param - return options -} + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_assignments`, nil) + if err != nil { + return + } -// GetAccessGroupRuleOptions : The GetAccessGroupRule options. -type GetAccessGroupRuleOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + for headerName, headerValue := range listAssignmentsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } - // The rule to get. - RuleID *string `json:"rule_id" validate:"required,ne="` + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "ListAssignments") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` + if listAssignmentsOptions.AccountID != nil { + builder.AddQuery("account_id", fmt.Sprint(*listAssignmentsOptions.AccountID)) + } - // Allows users to set headers on API requests - Headers map[string]string -} + request, err := builder.Build() + if err != nil { + return + } -// NewGetAccessGroupRuleOptions : Instantiate GetAccessGroupRuleOptions -func (*IamAccessGroupsV2) NewGetAccessGroupRuleOptions(accessGroupID string, ruleID string) *GetAccessGroupRuleOptions { - return &GetAccessGroupRuleOptions{ - AccessGroupID: core.StringPtr(accessGroupID), - RuleID: core.StringPtr(ruleID), + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalTemplatesListAssignmentResponse) + if err != nil { + return + } + response.Result = result } -} -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *GetAccessGroupRuleOptions) SetAccessGroupID(accessGroupID string) *GetAccessGroupRuleOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options + return } -// SetRuleID : Allow user to set RuleID -func (_options *GetAccessGroupRuleOptions) SetRuleID(ruleID string) *GetAccessGroupRuleOptions { - _options.RuleID = core.StringPtr(ruleID) - return _options +// GetAssignment : Get assignment +// Get a specific template assignment. +func (iamAccessGroups *IamAccessGroupsV2) GetAssignment(getAssignmentOptions *GetAssignmentOptions) (result *GetTemplateAssignmentResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.GetAssignmentWithContext(context.Background(), getAssignmentOptions) } -// SetTransactionID : Allow user to set TransactionID -func (_options *GetAccessGroupRuleOptions) SetTransactionID(transactionID string) *GetAccessGroupRuleOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options -} +// GetAssignmentWithContext is an alternate form of the GetAssignment method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) GetAssignmentWithContext(ctx context.Context, getAssignmentOptions *GetAssignmentOptions) (result *GetTemplateAssignmentResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getAssignmentOptions, "getAssignmentOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getAssignmentOptions, "getAssignmentOptions") + if err != nil { + return + } -// SetHeaders : Allow user to set Headers -func (options *GetAccessGroupRuleOptions) SetHeaders(param map[string]string) *GetAccessGroupRuleOptions { - options.Headers = param - return options -} + pathParamsMap := map[string]string{ + "assignment_id": *getAssignmentOptions.AssignmentID, + } -// GetAccountSettingsOptions : The GetAccountSettings options. -type GetAccountSettingsOptions struct { - // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the - // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the - // Authorization token. - AccountID *string `json:"account_id" validate:"required"` + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_assignments/{assignment_id}`, pathParamsMap) + if err != nil { + return + } - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` + for headerName, headerValue := range getAssignmentOptions.Headers { + builder.AddHeader(headerName, headerValue) + } - // Allows users to set headers on API requests - Headers map[string]string -} + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "GetAssignment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + if getAssignmentOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*getAssignmentOptions.TransactionID)) + } -// NewGetAccountSettingsOptions : Instantiate GetAccountSettingsOptions -func (*IamAccessGroupsV2) NewGetAccountSettingsOptions(accountID string) *GetAccountSettingsOptions { - return &GetAccountSettingsOptions{ - AccountID: core.StringPtr(accountID), + if getAssignmentOptions.Verbose != nil { + builder.AddQuery("verbose", fmt.Sprint(*getAssignmentOptions.Verbose)) } -} -// SetAccountID : Allow user to set AccountID -func (_options *GetAccountSettingsOptions) SetAccountID(accountID string) *GetAccountSettingsOptions { - _options.AccountID = core.StringPtr(accountID) - return _options -} + request, err := builder.Build() + if err != nil { + return + } -// SetTransactionID : Allow user to set TransactionID -func (_options *GetAccountSettingsOptions) SetTransactionID(transactionID string) *GetAccountSettingsOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options -} + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalGetTemplateAssignmentResponse) + if err != nil { + return + } + response.Result = result + } -// SetHeaders : Allow user to set Headers -func (options *GetAccountSettingsOptions) SetHeaders(param map[string]string) *GetAccountSettingsOptions { - options.Headers = param - return options + return } -// Group : An IAM access group. -type Group struct { - // The group's access group ID. - ID *string `json:"id,omitempty"` - - // The group's name. - Name *string `json:"name,omitempty"` - - // The group's description - if defined. - Description *string `json:"description,omitempty"` - - // The account id where the group was created. - AccountID *string `json:"account_id,omitempty"` - - // The timestamp the group was created at. - CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` - - // The `iam_id` of the entity that created the group. - CreatedByID *string `json:"created_by_id,omitempty"` - - // The timestamp the group was last edited at. - LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` - - // The `iam_id` of the entity that last modified the group name or description. - LastModifiedByID *string `json:"last_modified_by_id,omitempty"` - - // A url to the given group resource. - Href *string `json:"href,omitempty"` - - // This is set to true if rules exist for the group. - IsFederated *bool `json:"is_federated,omitempty"` +// UpdateAssignment : Update Assignment +// Endpoint to update template assignment. +func (iamAccessGroups *IamAccessGroupsV2) UpdateAssignment(updateAssignmentOptions *UpdateAssignmentOptions) (result *GetTemplateAssignmentResponse, response *core.DetailedResponse, err error) { + return iamAccessGroups.UpdateAssignmentWithContext(context.Background(), updateAssignmentOptions) } -// UnmarshalGroup unmarshals an instance of Group from the specified map of raw messages. -func UnmarshalGroup(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Group) - err = core.UnmarshalPrimitive(m, "id", &obj.ID) +// UpdateAssignmentWithContext is an alternate form of the UpdateAssignment method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) UpdateAssignmentWithContext(ctx context.Context, updateAssignmentOptions *UpdateAssignmentOptions) (result *GetTemplateAssignmentResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(updateAssignmentOptions, "updateAssignmentOptions cannot be nil") if err != nil { return } - err = core.UnmarshalPrimitive(m, "name", &obj.Name) + err = core.ValidateStruct(updateAssignmentOptions, "updateAssignmentOptions") if err != nil { return } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) - if err != nil { - return + + pathParamsMap := map[string]string{ + "assignment_id": *updateAssignmentOptions.AssignmentID, } - err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + + builder := core.NewRequestBuilder(core.PATCH) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_assignments/{assignment_id}`, pathParamsMap) if err != nil { return } - err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) - if err != nil { - return + + for headerName, headerValue := range updateAssignmentOptions.Headers { + builder.AddHeader(headerName, headerValue) } - err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) - if err != nil { - return + + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "UpdateAssignment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) } - err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) - if err != nil { - return + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if updateAssignmentOptions.IfMatch != nil { + builder.AddHeader("If-Match", fmt.Sprint(*updateAssignmentOptions.IfMatch)) } - err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) + + body := make(map[string]interface{}) + if updateAssignmentOptions.TemplateVersion != nil { + body["template_version"] = updateAssignmentOptions.TemplateVersion + } + _, err = builder.SetBodyContentJSON(body) if err != nil { return } - err = core.UnmarshalPrimitive(m, "href", &obj.Href) + + request, err := builder.Build() if err != nil { return } - err = core.UnmarshalPrimitive(m, "is_federated", &obj.IsFederated) + + var rawResponse map[string]json.RawMessage + response, err = iamAccessGroups.Service.Request(request, &rawResponse) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalGetTemplateAssignmentResponse) + if err != nil { + return + } + response.Result = result + } + return } -// GroupMembersList : The members of a group. -type GroupMembersList struct { - // Limit on how many items can be returned. - Limit *int64 `json:"limit" validate:"required"` - - // The offset of the first item returned in the result set. - Offset *int64 `json:"offset" validate:"required"` - - // The total number of items that match the query. - TotalCount *int64 `json:"total_count" validate:"required"` - - // A link object. - First *HrefStruct `json:"first,omitempty"` - - // A link object. - Previous *HrefStruct `json:"previous,omitempty"` - - // A link object. - Next *HrefStruct `json:"next,omitempty"` - - // A link object. - Last *HrefStruct `json:"last,omitempty"` - - // The members of an access group. - Members []ListGroupMembersResponseMember `json:"members,omitempty"` +// DeleteAssignment : Delete assignment +// Endpoint to delete template assignment. +func (iamAccessGroups *IamAccessGroupsV2) DeleteAssignment(deleteAssignmentOptions *DeleteAssignmentOptions) (response *core.DetailedResponse, err error) { + return iamAccessGroups.DeleteAssignmentWithContext(context.Background(), deleteAssignmentOptions) } -// UnmarshalGroupMembersList unmarshals an instance of GroupMembersList from the specified map of raw messages. -func UnmarshalGroupMembersList(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(GroupMembersList) - err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) +// DeleteAssignmentWithContext is an alternate form of the DeleteAssignment method which supports a Context parameter +func (iamAccessGroups *IamAccessGroupsV2) DeleteAssignmentWithContext(ctx context.Context, deleteAssignmentOptions *DeleteAssignmentOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteAssignmentOptions, "deleteAssignmentOptions cannot be nil") if err != nil { return } - err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + err = core.ValidateStruct(deleteAssignmentOptions, "deleteAssignmentOptions") if err != nil { return } - err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) - if err != nil { - return + + pathParamsMap := map[string]string{ + "assignment_id": *deleteAssignmentOptions.AssignmentID, } - err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalHrefStruct) + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamAccessGroups.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamAccessGroups.Service.Options.URL, `/v1/group_assignments/{assignment_id}`, pathParamsMap) if err != nil { return } - err = core.UnmarshalModel(m, "previous", &obj.Previous, UnmarshalHrefStruct) - if err != nil { - return + + for headerName, headerValue := range deleteAssignmentOptions.Headers { + builder.AddHeader(headerName, headerValue) } - err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalHrefStruct) - if err != nil { - return + + sdkHeaders := common.GetSdkHeaders("iam_access_groups", "V2", "DeleteAssignment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) } - err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalHrefStruct) - if err != nil { - return + if deleteAssignmentOptions.TransactionID != nil { + builder.AddHeader("Transaction-Id", fmt.Sprint(*deleteAssignmentOptions.TransactionID)) } - err = core.UnmarshalModel(m, "members", &obj.Members, UnmarshalListGroupMembersResponseMember) + + request, err := builder.Build() if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + + response, err = iamAccessGroups.Service.Request(request, nil) + return } -// Retrieve the value to be passed to a request to access the next page of results -func (resp *GroupMembersList) GetNextOffset() (*int64, error) { - if core.IsNil(resp.Next) { - return nil, nil - } - offset, err := core.GetQueryParam(resp.Next.Href, "offset") - if err != nil || offset == nil { - return nil, err - } - var offsetValue int64 - offsetValue, err = strconv.ParseInt(*offset, 10, 64) +// AccessActionControls : Control whether or not child account administrators can add access policies to the enterprise-managed access group in +// their account. +type AccessActionControls struct { + // Action control for managing (Add, Remove & Update) child account access policies in an enterprise-managed access + // group. + Add *bool `json:"add,omitempty"` +} + +// UnmarshalAccessActionControls unmarshals an instance of AccessActionControls from the specified map of raw messages. +func UnmarshalAccessActionControls(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AccessActionControls) + err = core.UnmarshalPrimitive(m, "add", &obj.Add) if err != nil { - return nil, err + return } - return core.Int64Ptr(offsetValue), nil + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// GroupsList : The list of access groups returned as part of a response. -type GroupsList struct { - // Limit on how many items can be returned. - Limit *int64 `json:"limit" validate:"required"` - - // The offset of the first item returned in the result set. - Offset *int64 `json:"offset" validate:"required"` - - // The total number of items that match the query. - TotalCount *int64 `json:"total_count" validate:"required"` +// AccessGroupInput : Access Group Input Component. +type AccessGroupInput struct { + // access group input name. + Name *string `json:"name" validate:"required"` - // A link object. - First *HrefStruct `json:"first,omitempty"` + // access group input description. + Description *string `json:"description,omitempty"` - // A link object. - Previous *HrefStruct `json:"previous,omitempty"` + // Members Input component. + Members *MembersInput `json:"members,omitempty"` - // A link object. - Next *HrefStruct `json:"next,omitempty"` + // Assertions Input Component. + Assertions *AssertionsInput `json:"assertions,omitempty"` - // A link object. - Last *HrefStruct `json:"last,omitempty"` + // Access Group Action Controls component. + ActionControls *GroupActionControls `json:"action_controls,omitempty"` +} - // An array of access groups. - Groups []Group `json:"groups,omitempty"` +// NewAccessGroupInput : Instantiate AccessGroupInput (Generic Model Constructor) +func (*IamAccessGroupsV2) NewAccessGroupInput(name string) (_model *AccessGroupInput, err error) { + _model = &AccessGroupInput{ + Name: core.StringPtr(name), + } + err = core.ValidateStruct(_model, "required parameters") + return } -// UnmarshalGroupsList unmarshals an instance of GroupsList from the specified map of raw messages. -func UnmarshalGroupsList(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(GroupsList) - err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) +// UnmarshalAccessGroupInput unmarshals an instance of AccessGroupInput from the specified map of raw messages. +func UnmarshalAccessGroupInput(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AccessGroupInput) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) if err != nil { return } - err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + err = core.UnmarshalPrimitive(m, "description", &obj.Description) if err != nil { return } - err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + err = core.UnmarshalModel(m, "members", &obj.Members, UnmarshalMembersInput) if err != nil { return } - err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalHrefStruct) + err = core.UnmarshalModel(m, "assertions", &obj.Assertions, UnmarshalAssertionsInput) if err != nil { return } - err = core.UnmarshalModel(m, "previous", &obj.Previous, UnmarshalHrefStruct) + err = core.UnmarshalModel(m, "action_controls", &obj.ActionControls, UnmarshalGroupActionControls) if err != nil { return } - err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalHrefStruct) + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AccountSettings : The access groups settings for a specific account. +type AccountSettings struct { + // The account id of the settings being shown. + AccountID *string `json:"account_id,omitempty"` + + // The timestamp the settings were last edited at. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` + + // The `iam_id` of the entity that last modified the settings. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` + + // This flag controls the public access feature within the account. It is set to true by default. Note: When this flag + // is set to false, all policies within the account attached to the Public Access group will be deleted. + PublicAccessEnabled *bool `json:"public_access_enabled,omitempty"` +} + +// UnmarshalAccountSettings unmarshals an instance of AccountSettings from the specified map of raw messages. +func UnmarshalAccountSettings(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AccountSettings) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) if err != nil { return } - err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalHrefStruct) + err = core.UnmarshalPrimitive(m, "last_modified_at", &obj.LastModifiedAt) if err != nil { return } - err = core.UnmarshalModel(m, "groups", &obj.Groups, UnmarshalGroup) + err = core.UnmarshalPrimitive(m, "last_modified_by_id", &obj.LastModifiedByID) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// Retrieve the value to be passed to a request to access the next page of results -func (resp *GroupsList) GetNextOffset() (*int64, error) { - if core.IsNil(resp.Next) { - return nil, nil - } - offset, err := core.GetQueryParam(resp.Next.Href, "offset") - if err != nil || offset == nil { - return nil, err - } - var offsetValue int64 - offsetValue, err = strconv.ParseInt(*offset, 10, 64) - if err != nil { - return nil, err - } - return core.Int64Ptr(offsetValue), nil -} - -// HrefStruct : A link object. -type HrefStruct struct { - // A string containing the link’s URL. - Href *string `json:"href,omitempty"` -} - -// UnmarshalHrefStruct unmarshals an instance of HrefStruct from the specified map of raw messages. -func UnmarshalHrefStruct(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(HrefStruct) - err = core.UnmarshalPrimitive(m, "href", &obj.Href) + err = core.UnmarshalPrimitive(m, "public_access_enabled", &obj.PublicAccessEnabled) if err != nil { return } @@ -2578,13 +2650,23 @@ func UnmarshalHrefStruct(m map[string]json.RawMessage, result interface{}) (err return } -// IsMemberOfAccessGroupOptions : The IsMemberOfAccessGroup options. -type IsMemberOfAccessGroupOptions struct { +// AddAccessGroupRuleOptions : The AddAccessGroupRule options. +type AddAccessGroupRuleOptions struct { // The access group identifier. AccessGroupID *string `json:"access_group_id" validate:"required,ne="` - // The IAM identifier. - IamID *string `json:"iam_id" validate:"required,ne="` + // Session duration in hours. Access group membership is revoked after this time period expires. Users must log back in + // to refresh their access group membership. + Expiration *int64 `json:"expiration" validate:"required"` + + // The URL of the identity provider (IdP). + RealmName *string `json:"realm_name" validate:"required"` + + // A list of conditions that identities must satisfy to gain access group membership. + Conditions []RuleConditions `json:"conditions" validate:"required"` + + // The name of the dynaimic rule. + Name *string `json:"name,omitempty"` // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you @@ -2595,138 +2677,245 @@ type IsMemberOfAccessGroupOptions struct { Headers map[string]string } -// NewIsMemberOfAccessGroupOptions : Instantiate IsMemberOfAccessGroupOptions -func (*IamAccessGroupsV2) NewIsMemberOfAccessGroupOptions(accessGroupID string, iamID string) *IsMemberOfAccessGroupOptions { - return &IsMemberOfAccessGroupOptions{ +// NewAddAccessGroupRuleOptions : Instantiate AddAccessGroupRuleOptions +func (*IamAccessGroupsV2) NewAddAccessGroupRuleOptions(accessGroupID string, expiration int64, realmName string, conditions []RuleConditions) *AddAccessGroupRuleOptions { + return &AddAccessGroupRuleOptions{ AccessGroupID: core.StringPtr(accessGroupID), - IamID: core.StringPtr(iamID), + Expiration: core.Int64Ptr(expiration), + RealmName: core.StringPtr(realmName), + Conditions: conditions, } } // SetAccessGroupID : Allow user to set AccessGroupID -func (_options *IsMemberOfAccessGroupOptions) SetAccessGroupID(accessGroupID string) *IsMemberOfAccessGroupOptions { +func (_options *AddAccessGroupRuleOptions) SetAccessGroupID(accessGroupID string) *AddAccessGroupRuleOptions { _options.AccessGroupID = core.StringPtr(accessGroupID) return _options } -// SetIamID : Allow user to set IamID -func (_options *IsMemberOfAccessGroupOptions) SetIamID(iamID string) *IsMemberOfAccessGroupOptions { - _options.IamID = core.StringPtr(iamID) +// SetExpiration : Allow user to set Expiration +func (_options *AddAccessGroupRuleOptions) SetExpiration(expiration int64) *AddAccessGroupRuleOptions { + _options.Expiration = core.Int64Ptr(expiration) return _options } -// SetTransactionID : Allow user to set TransactionID -func (_options *IsMemberOfAccessGroupOptions) SetTransactionID(transactionID string) *IsMemberOfAccessGroupOptions { - _options.TransactionID = core.StringPtr(transactionID) +// SetRealmName : Allow user to set RealmName +func (_options *AddAccessGroupRuleOptions) SetRealmName(realmName string) *AddAccessGroupRuleOptions { + _options.RealmName = core.StringPtr(realmName) + return _options +} + +// SetConditions : Allow user to set Conditions +func (_options *AddAccessGroupRuleOptions) SetConditions(conditions []RuleConditions) *AddAccessGroupRuleOptions { + _options.Conditions = conditions + return _options +} + +// SetName : Allow user to set Name +func (_options *AddAccessGroupRuleOptions) SetName(name string) *AddAccessGroupRuleOptions { + _options.Name = core.StringPtr(name) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *AddAccessGroupRuleOptions) SetTransactionID(transactionID string) *AddAccessGroupRuleOptions { + _options.TransactionID = core.StringPtr(transactionID) return _options } // SetHeaders : Allow user to set Headers -func (options *IsMemberOfAccessGroupOptions) SetHeaders(param map[string]string) *IsMemberOfAccessGroupOptions { +func (options *AddAccessGroupRuleOptions) SetHeaders(param map[string]string) *AddAccessGroupRuleOptions { options.Headers = param return options } -// ListAccessGroupMembersOptions : The ListAccessGroupMembers options. -type ListAccessGroupMembersOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` +// AddGroupMembersRequestMembersItem : AddGroupMembersRequestMembersItem struct +type AddGroupMembersRequestMembersItem struct { + // The IBMid, service ID or trusted profile ID of the member. + IamID *string `json:"iam_id" validate:"required"` - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` + // The type of the member, must be either "user", "service" or "profile". + Type *string `json:"type" validate:"required"` +} - // Filters members by membership type. Membership type can be either `static`, `dynamic` or `all`. `static` lists those - // members explicitly added to the access group, `dynamic` lists those members part of access group via dynamic rules - // at the moment. `all` lists both static and dynamic members. - MembershipType *string `json:"membership_type,omitempty"` +// NewAddGroupMembersRequestMembersItem : Instantiate AddGroupMembersRequestMembersItem (Generic Model Constructor) +func (*IamAccessGroupsV2) NewAddGroupMembersRequestMembersItem(iamID string, typeVar string) (_model *AddGroupMembersRequestMembersItem, err error) { + _model = &AddGroupMembersRequestMembersItem{ + IamID: core.StringPtr(iamID), + Type: core.StringPtr(typeVar), + } + err = core.ValidateStruct(_model, "required parameters") + return +} - // Return up to this limit of results where limit is between 0 and 100. - Limit *int64 `json:"limit,omitempty"` +// UnmarshalAddGroupMembersRequestMembersItem unmarshals an instance of AddGroupMembersRequestMembersItem from the specified map of raw messages. +func UnmarshalAddGroupMembersRequestMembersItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AddGroupMembersRequestMembersItem) + err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} - // The offset of the first result item to be returned. - Offset *int64 `json:"offset,omitempty"` +// AddGroupMembersResponse : The members added to an access group. +type AddGroupMembersResponse struct { + // The members added to an access group. + Members []AddGroupMembersResponseMembersItem `json:"members,omitempty"` +} - // Filter the results by member type. +// UnmarshalAddGroupMembersResponse unmarshals an instance of AddGroupMembersResponse from the specified map of raw messages. +func UnmarshalAddGroupMembersResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AddGroupMembersResponse) + err = core.UnmarshalModel(m, "members", &obj.Members, UnmarshalAddGroupMembersResponseMembersItem) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AddGroupMembersResponseMembersItem : AddGroupMembersResponseMembersItem struct +type AddGroupMembersResponseMembersItem struct { + // The IBMid or Service Id of the member. + IamID *string `json:"iam_id,omitempty"` + + // The member type - either `user`, `service` or `profile`. Type *string `json:"type,omitempty"` - // Return user's email and name for each user ID or the name for each service ID or trusted profile. - Verbose *bool `json:"verbose,omitempty"` + // The timestamp of when the membership was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` - // If verbose is true, sort the results by id, name, or email. - Sort *string `json:"sort,omitempty"` + // The `iam_id` of the entity that created the membership. + CreatedByID *string `json:"created_by_id,omitempty"` - // Allows users to set headers on API requests - Headers map[string]string + // The outcome of the operation on this `iam_id`. + StatusCode *int64 `json:"status_code,omitempty"` + + // A transaction-id that can be used for debugging purposes. + Trace *string `json:"trace,omitempty"` + + // A list of errors that occurred when trying to add members to a group. + Errors []Error `json:"errors,omitempty"` } -// NewListAccessGroupMembersOptions : Instantiate ListAccessGroupMembersOptions -func (*IamAccessGroupsV2) NewListAccessGroupMembersOptions(accessGroupID string) *ListAccessGroupMembersOptions { - return &ListAccessGroupMembersOptions{ - AccessGroupID: core.StringPtr(accessGroupID), +// UnmarshalAddGroupMembersResponseMembersItem unmarshals an instance of AddGroupMembersResponseMembersItem from the specified map of raw messages. +func UnmarshalAddGroupMembersResponseMembersItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AddGroupMembersResponseMembersItem) + err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + 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, "status_code", &obj.StatusCode) + if err != nil { + return } + err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + if err != nil { + return + } + err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalError) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *ListAccessGroupMembersOptions) SetAccessGroupID(accessGroupID string) *ListAccessGroupMembersOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options -} +// AddMemberToMultipleAccessGroupsOptions : The AddMemberToMultipleAccessGroups options. +type AddMemberToMultipleAccessGroupsOptions struct { + // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the + // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the + // Authorization token. + AccountID *string `json:"account_id" validate:"required"` -// SetTransactionID : Allow user to set TransactionID -func (_options *ListAccessGroupMembersOptions) SetTransactionID(transactionID string) *ListAccessGroupMembersOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options + // The IAM identifier. + IamID *string `json:"iam_id" validate:"required,ne="` + + // The type of the member, must be either "user", "service" or "profile". + Type *string `json:"type,omitempty"` + + // The ids of the access groups a given member is to be added to. + Groups []string `json:"groups,omitempty"` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string } -// SetMembershipType : Allow user to set MembershipType -func (_options *ListAccessGroupMembersOptions) SetMembershipType(membershipType string) *ListAccessGroupMembersOptions { - _options.MembershipType = core.StringPtr(membershipType) - return _options +// NewAddMemberToMultipleAccessGroupsOptions : Instantiate AddMemberToMultipleAccessGroupsOptions +func (*IamAccessGroupsV2) NewAddMemberToMultipleAccessGroupsOptions(accountID string, iamID string) *AddMemberToMultipleAccessGroupsOptions { + return &AddMemberToMultipleAccessGroupsOptions{ + AccountID: core.StringPtr(accountID), + IamID: core.StringPtr(iamID), + } } -// SetLimit : Allow user to set Limit -func (_options *ListAccessGroupMembersOptions) SetLimit(limit int64) *ListAccessGroupMembersOptions { - _options.Limit = core.Int64Ptr(limit) +// SetAccountID : Allow user to set AccountID +func (_options *AddMemberToMultipleAccessGroupsOptions) SetAccountID(accountID string) *AddMemberToMultipleAccessGroupsOptions { + _options.AccountID = core.StringPtr(accountID) return _options } -// SetOffset : Allow user to set Offset -func (_options *ListAccessGroupMembersOptions) SetOffset(offset int64) *ListAccessGroupMembersOptions { - _options.Offset = core.Int64Ptr(offset) +// SetIamID : Allow user to set IamID +func (_options *AddMemberToMultipleAccessGroupsOptions) SetIamID(iamID string) *AddMemberToMultipleAccessGroupsOptions { + _options.IamID = core.StringPtr(iamID) return _options } // SetType : Allow user to set Type -func (_options *ListAccessGroupMembersOptions) SetType(typeVar string) *ListAccessGroupMembersOptions { +func (_options *AddMemberToMultipleAccessGroupsOptions) SetType(typeVar string) *AddMemberToMultipleAccessGroupsOptions { _options.Type = core.StringPtr(typeVar) return _options } -// SetVerbose : Allow user to set Verbose -func (_options *ListAccessGroupMembersOptions) SetVerbose(verbose bool) *ListAccessGroupMembersOptions { - _options.Verbose = core.BoolPtr(verbose) +// SetGroups : Allow user to set Groups +func (_options *AddMemberToMultipleAccessGroupsOptions) SetGroups(groups []string) *AddMemberToMultipleAccessGroupsOptions { + _options.Groups = groups return _options } -// SetSort : Allow user to set Sort -func (_options *ListAccessGroupMembersOptions) SetSort(sort string) *ListAccessGroupMembersOptions { - _options.Sort = core.StringPtr(sort) +// SetTransactionID : Allow user to set TransactionID +func (_options *AddMemberToMultipleAccessGroupsOptions) SetTransactionID(transactionID string) *AddMemberToMultipleAccessGroupsOptions { + _options.TransactionID = core.StringPtr(transactionID) return _options } // SetHeaders : Allow user to set Headers -func (options *ListAccessGroupMembersOptions) SetHeaders(param map[string]string) *ListAccessGroupMembersOptions { +func (options *AddMemberToMultipleAccessGroupsOptions) SetHeaders(param map[string]string) *AddMemberToMultipleAccessGroupsOptions { options.Headers = param return options } -// ListAccessGroupRulesOptions : The ListAccessGroupRules options. -type ListAccessGroupRulesOptions struct { +// AddMembersToAccessGroupOptions : The AddMembersToAccessGroup options. +type AddMembersToAccessGroupOptions struct { // The access group identifier. AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + // An array of member objects to add to an access group. + Members []AddGroupMembersRequestMembersItem `json:"members,omitempty"` + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you // choose. If no transaction ID is passed in, then a random ID is generated. @@ -2736,193 +2925,3221 @@ type ListAccessGroupRulesOptions struct { Headers map[string]string } -// NewListAccessGroupRulesOptions : Instantiate ListAccessGroupRulesOptions -func (*IamAccessGroupsV2) NewListAccessGroupRulesOptions(accessGroupID string) *ListAccessGroupRulesOptions { - return &ListAccessGroupRulesOptions{ +// NewAddMembersToAccessGroupOptions : Instantiate AddMembersToAccessGroupOptions +func (*IamAccessGroupsV2) NewAddMembersToAccessGroupOptions(accessGroupID string) *AddMembersToAccessGroupOptions { + return &AddMembersToAccessGroupOptions{ AccessGroupID: core.StringPtr(accessGroupID), } } // SetAccessGroupID : Allow user to set AccessGroupID -func (_options *ListAccessGroupRulesOptions) SetAccessGroupID(accessGroupID string) *ListAccessGroupRulesOptions { +func (_options *AddMembersToAccessGroupOptions) SetAccessGroupID(accessGroupID string) *AddMembersToAccessGroupOptions { _options.AccessGroupID = core.StringPtr(accessGroupID) return _options } +// SetMembers : Allow user to set Members +func (_options *AddMembersToAccessGroupOptions) SetMembers(members []AddGroupMembersRequestMembersItem) *AddMembersToAccessGroupOptions { + _options.Members = members + return _options +} + // SetTransactionID : Allow user to set TransactionID -func (_options *ListAccessGroupRulesOptions) SetTransactionID(transactionID string) *ListAccessGroupRulesOptions { +func (_options *AddMembersToAccessGroupOptions) SetTransactionID(transactionID string) *AddMembersToAccessGroupOptions { _options.TransactionID = core.StringPtr(transactionID) return _options } // SetHeaders : Allow user to set Headers -func (options *ListAccessGroupRulesOptions) SetHeaders(param map[string]string) *ListAccessGroupRulesOptions { +func (options *AddMembersToAccessGroupOptions) SetHeaders(param map[string]string) *AddMembersToAccessGroupOptions { options.Headers = param return options } -// ListAccessGroupsOptions : The ListAccessGroups options. -type ListAccessGroupsOptions struct { - // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the - // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the - // Authorization token. - AccountID *string `json:"account_id" validate:"required"` - - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` - - // Return groups for member ID (IBMid, service ID or trusted profile ID). +// AddMembershipMultipleGroupsResponse : The response from the add member to multiple access groups request. +type AddMembershipMultipleGroupsResponse struct { + // The iam_id of a member. IamID *string `json:"iam_id,omitempty"` - // Membership type need to be specified along with iam_id and must be either `static`, `dynamic` or `all`. If - // membership type is `static`, members explicitly added to the group will be shown. If membership type is `dynamic`, - // members accessing the access group at the moment via dynamic rules will be shown. If membership type is `all`, both - // static and dynamic members will be shown. - MembershipType *string `json:"membership_type,omitempty"` + // The list of access groups a member was added to. + Groups []AddMembershipMultipleGroupsResponseGroupsItem `json:"groups,omitempty"` +} - // Return up to this limit of results where limit is between 0 and 100. - Limit *int64 `json:"limit,omitempty"` +// UnmarshalAddMembershipMultipleGroupsResponse unmarshals an instance of AddMembershipMultipleGroupsResponse from the specified map of raw messages. +func UnmarshalAddMembershipMultipleGroupsResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AddMembershipMultipleGroupsResponse) + err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "groups", &obj.Groups, UnmarshalAddMembershipMultipleGroupsResponseGroupsItem) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} - // The offset of the first result item to be returned. - Offset *int64 `json:"offset,omitempty"` +// AddMembershipMultipleGroupsResponseGroupsItem : AddMembershipMultipleGroupsResponseGroupsItem struct +type AddMembershipMultipleGroupsResponseGroupsItem struct { + // The access group that the member is to be added to. + AccessGroupID *string `json:"access_group_id,omitempty"` - // Sort the results by id, name, description, or is_federated flag. - Sort *string `json:"sort,omitempty"` + // The outcome of the add membership operation on this `access_group_id`. + StatusCode *int64 `json:"status_code,omitempty"` - // If show_federated is true, each group listed will return an is_federated value that is set to true if rules exist - // for the group. - ShowFederated *bool `json:"show_federated,omitempty"` + // A transaction-id that can be used for debugging purposes. + Trace *string `json:"trace,omitempty"` - // If hide_public_access is true, do not include the Public Access Group in the results. - HidePublicAccess *bool `json:"hide_public_access,omitempty"` + // List of errors encountered when adding member to access group. + Errors []Error `json:"errors,omitempty"` +} + +// UnmarshalAddMembershipMultipleGroupsResponseGroupsItem unmarshals an instance of AddMembershipMultipleGroupsResponseGroupsItem from the specified map of raw messages. +func UnmarshalAddMembershipMultipleGroupsResponseGroupsItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AddMembershipMultipleGroupsResponseGroupsItem) + err = core.UnmarshalPrimitive(m, "access_group_id", &obj.AccessGroupID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + if err != nil { + return + } + err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalError) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AssertionsActionControls : Assertions Action Controls component. Inner action controls will override these action controls. +type AssertionsActionControls struct { + // Action control for managing (Add, Remove & Update) child account dynamic rules in an enterprise-managed access + // group. + Add *bool `json:"add,omitempty"` + + // Action control for removing enterprise-managed dynamic rules in an enterprise-managed access group. + Remove *bool `json:"remove,omitempty"` + + // Action control for updating enterprise-managed dynamic rules in an enterprise-managed access group. + Update *bool `json:"update,omitempty"` +} + +// UnmarshalAssertionsActionControls unmarshals an instance of AssertionsActionControls from the specified map of raw messages. +func UnmarshalAssertionsActionControls(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AssertionsActionControls) + err = core.UnmarshalPrimitive(m, "add", &obj.Add) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "remove", &obj.Remove) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "update", &obj.Update) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AssertionsInput : Assertions Input Component. +type AssertionsInput struct { + // assertions input rules. + Rules []RuleInput `json:"rules,omitempty"` + + // Assertions Action Controls component. Inner action controls will override these action controls. + ActionControls *AssertionsActionControls `json:"action_controls,omitempty"` +} + +// UnmarshalAssertionsInput unmarshals an instance of AssertionsInput from the specified map of raw messages. +func UnmarshalAssertionsInput(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AssertionsInput) + err = core.UnmarshalModel(m, "rules", &obj.Rules, UnmarshalRuleInput) + if err != nil { + return + } + err = core.UnmarshalModel(m, "action_controls", &obj.ActionControls, UnmarshalAssertionsActionControls) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AssignmentResourceAccessGroup : Assignment Resource Access Group. +type AssignmentResourceAccessGroup struct { + // Assignment resource entry. + Group *AssignmentResourceEntry `json:"group" validate:"required"` + + // List of member resources of the group. + Members []AssignmentResourceEntry `json:"members" validate:"required"` + + // List of rules associated with the group. + Rules []AssignmentResourceEntry `json:"rules" validate:"required"` +} + +// UnmarshalAssignmentResourceAccessGroup unmarshals an instance of AssignmentResourceAccessGroup from the specified map of raw messages. +func UnmarshalAssignmentResourceAccessGroup(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AssignmentResourceAccessGroup) + err = core.UnmarshalModel(m, "group", &obj.Group, UnmarshalAssignmentResourceEntry) + if err != nil { + return + } + err = core.UnmarshalModel(m, "members", &obj.Members, UnmarshalAssignmentResourceEntry) + if err != nil { + return + } + err = core.UnmarshalModel(m, "rules", &obj.Rules, UnmarshalAssignmentResourceEntry) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AssignmentResourceEntry : Assignment resource entry. +type AssignmentResourceEntry struct { + // Assignment Resource Entry Id. + ID *string `json:"id" validate:"required"` + + // Optional name of the resource. + Name *string `json:"name,omitempty"` + + // Optional version of the resource. + Version *string `json:"version,omitempty"` + + // Resource in assignment resource entry. + Resource *string `json:"resource" validate:"required"` + + // Error in assignment resource entry. + Error *string `json:"error" validate:"required"` + + // Optional operation on the resource. + Operation *string `json:"operation,omitempty"` + + // Status of assignment resource entry. + Status *string `json:"status" validate:"required"` +} + +// UnmarshalAssignmentResourceEntry unmarshals an instance of AssignmentResourceEntry from the specified map of raw messages. +func UnmarshalAssignmentResourceEntry(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AssignmentResourceEntry) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "version", &obj.Version) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "resource", &obj.Resource) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "error", &obj.Error) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operation", &obj.Operation) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status", &obj.Status) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CommitTemplateOptions : The CommitTemplate options. +type CommitTemplateOptions struct { + // template id parameter. + TemplateID *string `json:"template_id" validate:"required,ne="` + + // version number in path. + VersionNum *string `json:"version_num" validate:"required,ne="` + + // ETag value of the template version document. + IfMatch *string `json:"If-Match" validate:"required"` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` // Allows users to set headers on API requests Headers map[string]string } -// NewListAccessGroupsOptions : Instantiate ListAccessGroupsOptions -func (*IamAccessGroupsV2) NewListAccessGroupsOptions(accountID string) *ListAccessGroupsOptions { - return &ListAccessGroupsOptions{ - AccountID: core.StringPtr(accountID), +// NewCommitTemplateOptions : Instantiate CommitTemplateOptions +func (*IamAccessGroupsV2) NewCommitTemplateOptions(templateID string, versionNum string, ifMatch string) *CommitTemplateOptions { + return &CommitTemplateOptions{ + TemplateID: core.StringPtr(templateID), + VersionNum: core.StringPtr(versionNum), + IfMatch: core.StringPtr(ifMatch), } } -// SetAccountID : Allow user to set AccountID -func (_options *ListAccessGroupsOptions) SetAccountID(accountID string) *ListAccessGroupsOptions { - _options.AccountID = core.StringPtr(accountID) +// SetTemplateID : Allow user to set TemplateID +func (_options *CommitTemplateOptions) SetTemplateID(templateID string) *CommitTemplateOptions { + _options.TemplateID = core.StringPtr(templateID) return _options } -// SetTransactionID : Allow user to set TransactionID -func (_options *ListAccessGroupsOptions) SetTransactionID(transactionID string) *ListAccessGroupsOptions { - _options.TransactionID = core.StringPtr(transactionID) +// SetVersionNum : Allow user to set VersionNum +func (_options *CommitTemplateOptions) SetVersionNum(versionNum string) *CommitTemplateOptions { + _options.VersionNum = core.StringPtr(versionNum) return _options } -// SetIamID : Allow user to set IamID -func (_options *ListAccessGroupsOptions) SetIamID(iamID string) *ListAccessGroupsOptions { - _options.IamID = core.StringPtr(iamID) +// SetIfMatch : Allow user to set IfMatch +func (_options *CommitTemplateOptions) SetIfMatch(ifMatch string) *CommitTemplateOptions { + _options.IfMatch = core.StringPtr(ifMatch) return _options } -// SetMembershipType : Allow user to set MembershipType -func (_options *ListAccessGroupsOptions) SetMembershipType(membershipType string) *ListAccessGroupsOptions { - _options.MembershipType = core.StringPtr(membershipType) +// SetTransactionID : Allow user to set TransactionID +func (_options *CommitTemplateOptions) SetTransactionID(transactionID string) *CommitTemplateOptions { + _options.TransactionID = core.StringPtr(transactionID) return _options } -// SetLimit : Allow user to set Limit -func (_options *ListAccessGroupsOptions) SetLimit(limit int64) *ListAccessGroupsOptions { - _options.Limit = core.Int64Ptr(limit) +// SetHeaders : Allow user to set Headers +func (options *CommitTemplateOptions) SetHeaders(param map[string]string) *CommitTemplateOptions { + options.Headers = param + return options +} + +// ConditionInput : Condition Input component. +type ConditionInput struct { + // condition input claim. + Claim *string `json:"claim,omitempty"` + + // condition input operator. + Operator *string `json:"operator,omitempty"` + + // condition input value. + Value *string `json:"value,omitempty"` +} + +// UnmarshalConditionInput unmarshals an instance of ConditionInput from the specified map of raw messages. +func UnmarshalConditionInput(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ConditionInput) + err = core.UnmarshalPrimitive(m, "claim", &obj.Claim) + 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 +} + +// CreateAccessGroupOptions : The CreateAccessGroup options. +type CreateAccessGroupOptions struct { + // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the + // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the + // Authorization token. + AccountID *string `json:"account_id" validate:"required"` + + // Give the access group a unique name that doesn't conflict with an existing access group in the account. This field + // is case-insensitive and has a limit of 100 characters. + Name *string `json:"name" validate:"required"` + + // Assign an optional description for the access group. This field has a limit of 250 characters. + Description *string `json:"description,omitempty"` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCreateAccessGroupOptions : Instantiate CreateAccessGroupOptions +func (*IamAccessGroupsV2) NewCreateAccessGroupOptions(accountID string, name string) *CreateAccessGroupOptions { + return &CreateAccessGroupOptions{ + AccountID: core.StringPtr(accountID), + Name: core.StringPtr(name), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *CreateAccessGroupOptions) SetAccountID(accountID string) *CreateAccessGroupOptions { + _options.AccountID = core.StringPtr(accountID) return _options } -// SetOffset : Allow user to set Offset -func (_options *ListAccessGroupsOptions) SetOffset(offset int64) *ListAccessGroupsOptions { - _options.Offset = core.Int64Ptr(offset) +// SetName : Allow user to set Name +func (_options *CreateAccessGroupOptions) SetName(name string) *CreateAccessGroupOptions { + _options.Name = core.StringPtr(name) return _options } -// SetSort : Allow user to set Sort -func (_options *ListAccessGroupsOptions) SetSort(sort string) *ListAccessGroupsOptions { - _options.Sort = core.StringPtr(sort) +// SetDescription : Allow user to set Description +func (_options *CreateAccessGroupOptions) SetDescription(description string) *CreateAccessGroupOptions { + _options.Description = core.StringPtr(description) return _options } -// SetShowFederated : Allow user to set ShowFederated -func (_options *ListAccessGroupsOptions) SetShowFederated(showFederated bool) *ListAccessGroupsOptions { - _options.ShowFederated = core.BoolPtr(showFederated) +// SetTransactionID : Allow user to set TransactionID +func (_options *CreateAccessGroupOptions) SetTransactionID(transactionID string) *CreateAccessGroupOptions { + _options.TransactionID = core.StringPtr(transactionID) return _options } -// SetHidePublicAccess : Allow user to set HidePublicAccess -func (_options *ListAccessGroupsOptions) SetHidePublicAccess(hidePublicAccess bool) *ListAccessGroupsOptions { - _options.HidePublicAccess = core.BoolPtr(hidePublicAccess) - return _options +// SetHeaders : Allow user to set Headers +func (options *CreateAccessGroupOptions) SetHeaders(param map[string]string) *CreateAccessGroupOptions { + options.Headers = param + return options +} + +// CreateAssignmentOptions : The CreateAssignment options. +type CreateAssignmentOptions struct { + // The unique identifier of the template to be assigned. + TemplateID *string `json:"template_id" validate:"required"` + + // The version number of the template to be assigned. + TemplateVersion *string `json:"template_version" validate:"required"` + + // The type of the entity to which the template should be assigned, e.g. 'Account', 'AccountGroup', etc. + TargetType *string `json:"target_type" validate:"required"` + + // The unique identifier of the entity to which the template should be assigned. + Target *string `json:"target" validate:"required"` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// Constants associated with the CreateAssignmentOptions.TargetType property. +// The type of the entity to which the template should be assigned, e.g. 'Account', 'AccountGroup', etc. +const ( + CreateAssignmentOptionsTargetTypeAccountConst = "Account" + CreateAssignmentOptionsTargetTypeAccountgroupConst = "AccountGroup" +) + +// NewCreateAssignmentOptions : Instantiate CreateAssignmentOptions +func (*IamAccessGroupsV2) NewCreateAssignmentOptions(templateID string, templateVersion string, targetType string, target string) *CreateAssignmentOptions { + return &CreateAssignmentOptions{ + TemplateID: core.StringPtr(templateID), + TemplateVersion: core.StringPtr(templateVersion), + TargetType: core.StringPtr(targetType), + Target: core.StringPtr(target), + } +} + +// SetTemplateID : Allow user to set TemplateID +func (_options *CreateAssignmentOptions) SetTemplateID(templateID string) *CreateAssignmentOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options +} + +// SetTemplateVersion : Allow user to set TemplateVersion +func (_options *CreateAssignmentOptions) SetTemplateVersion(templateVersion string) *CreateAssignmentOptions { + _options.TemplateVersion = core.StringPtr(templateVersion) + return _options +} + +// SetTargetType : Allow user to set TargetType +func (_options *CreateAssignmentOptions) SetTargetType(targetType string) *CreateAssignmentOptions { + _options.TargetType = core.StringPtr(targetType) + return _options +} + +// SetTarget : Allow user to set Target +func (_options *CreateAssignmentOptions) SetTarget(target string) *CreateAssignmentOptions { + _options.Target = core.StringPtr(target) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *CreateAssignmentOptions) SetTransactionID(transactionID string) *CreateAssignmentOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateAssignmentOptions) SetHeaders(param map[string]string) *CreateAssignmentOptions { + options.Headers = param + return options +} + +// CreateTemplateOptions : The CreateTemplate options. +type CreateTemplateOptions struct { + // create template input name. + Name *string `json:"name" validate:"required"` + + // create template input account id. + AccountID *string `json:"account_id" validate:"required"` + + // create template input description. + Description *string `json:"description,omitempty"` + + // Access Group Input Component. + Group *AccessGroupInput `json:"group,omitempty"` + + // policy template references. + PolicyTemplateReferences []PolicyTemplatesInput `json:"policy_template_references,omitempty"` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCreateTemplateOptions : Instantiate CreateTemplateOptions +func (*IamAccessGroupsV2) NewCreateTemplateOptions(name string, accountID string) *CreateTemplateOptions { + return &CreateTemplateOptions{ + Name: core.StringPtr(name), + AccountID: core.StringPtr(accountID), + } +} + +// SetName : Allow user to set Name +func (_options *CreateTemplateOptions) SetName(name string) *CreateTemplateOptions { + _options.Name = core.StringPtr(name) + return _options +} + +// SetAccountID : Allow user to set AccountID +func (_options *CreateTemplateOptions) SetAccountID(accountID string) *CreateTemplateOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetDescription : Allow user to set Description +func (_options *CreateTemplateOptions) SetDescription(description string) *CreateTemplateOptions { + _options.Description = core.StringPtr(description) + return _options +} + +// SetGroup : Allow user to set Group +func (_options *CreateTemplateOptions) SetGroup(group *AccessGroupInput) *CreateTemplateOptions { + _options.Group = group + return _options +} + +// SetPolicyTemplateReferences : Allow user to set PolicyTemplateReferences +func (_options *CreateTemplateOptions) SetPolicyTemplateReferences(policyTemplateReferences []PolicyTemplatesInput) *CreateTemplateOptions { + _options.PolicyTemplateReferences = policyTemplateReferences + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *CreateTemplateOptions) SetTransactionID(transactionID string) *CreateTemplateOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateTemplateOptions) SetHeaders(param map[string]string) *CreateTemplateOptions { + options.Headers = param + return options +} + +// CreateTemplateResponse : Successful response output for create template. +type CreateTemplateResponse struct { + // The ID of the access group template. + ID *string `json:"id" validate:"required"` + + // The name of the access group template. + Name *string `json:"name" validate:"required"` + + // The description of the access group template. + Description *string `json:"description" validate:"required"` + + // The ID of the account to which the access group template is assigned. + AccountID *string `json:"account_id" validate:"required"` + + // The version of the access group template. + Version *string `json:"version" validate:"required"` + + // A boolean indicating whether the access group template is committed. + Committed *bool `json:"committed" validate:"required"` + + // Access Group Input Component. + Group *AccessGroupInput `json:"group" validate:"required"` + + // References to policy templates assigned to the access group template. + PolicyTemplateReferences []PolicyTemplatesInput `json:"policy_template_references" validate:"required"` + + // The URL of the access group template resource. + Href *string `json:"href" validate:"required"` + + // The date and time when the access group template was created. + CreatedAt *strfmt.DateTime `json:"created_at" validate:"required"` + + // The ID of the user who created the access group template. + CreatedByID *string `json:"created_by_id" validate:"required"` + + // The date and time when the access group template was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at" validate:"required"` + + // The ID of the user who last modified the access group template. + LastModifiedByID *string `json:"last_modified_by_id" validate:"required"` +} + +// NewCreateTemplateResponse : Instantiate CreateTemplateResponse (Generic Model Constructor) +func (*IamAccessGroupsV2) NewCreateTemplateResponse(id string, name string, description string, accountID string, version string, committed bool, group *AccessGroupInput, policyTemplateReferences []PolicyTemplatesInput, href string, createdAt *strfmt.DateTime, createdByID string, lastModifiedAt *strfmt.DateTime, lastModifiedByID string) (_model *CreateTemplateResponse, err error) { + _model = &CreateTemplateResponse{ + ID: core.StringPtr(id), + Name: core.StringPtr(name), + Description: core.StringPtr(description), + AccountID: core.StringPtr(accountID), + Version: core.StringPtr(version), + Committed: core.BoolPtr(committed), + Group: group, + PolicyTemplateReferences: policyTemplateReferences, + Href: core.StringPtr(href), + CreatedAt: createdAt, + CreatedByID: core.StringPtr(createdByID), + LastModifiedAt: lastModifiedAt, + LastModifiedByID: core.StringPtr(lastModifiedByID), + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalCreateTemplateResponse unmarshals an instance of CreateTemplateResponse from the specified map of raw messages. +func UnmarshalCreateTemplateResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreateTemplateResponse) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "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, "group", &obj.Group, UnmarshalAccessGroupInput) + if err != nil { + return + } + err = core.UnmarshalModel(m, "policy_template_references", &obj.PolicyTemplateReferences, UnmarshalPolicyTemplatesInput) + 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 +} + +// CreateTemplateVersionOptions : The CreateTemplateVersion options. +type CreateTemplateVersionOptions struct { + // parameter template id. + TemplateID *string `json:"template_id" validate:"required,ne="` + + // The name of the template version. + Name *string `json:"name,omitempty"` + + // The description of the template version. + Description *string `json:"description,omitempty"` + + // Access Group Input Component. + Group *AccessGroupInput `json:"group,omitempty"` + + // The policy templates associated with the template version. + PolicyTemplateReferences []PolicyTemplatesInput `json:"policy_template_references,omitempty"` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCreateTemplateVersionOptions : Instantiate CreateTemplateVersionOptions +func (*IamAccessGroupsV2) NewCreateTemplateVersionOptions(templateID string) *CreateTemplateVersionOptions { + return &CreateTemplateVersionOptions{ + TemplateID: core.StringPtr(templateID), + } +} + +// SetTemplateID : Allow user to set TemplateID +func (_options *CreateTemplateVersionOptions) SetTemplateID(templateID string) *CreateTemplateVersionOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options +} + +// SetName : Allow user to set Name +func (_options *CreateTemplateVersionOptions) SetName(name string) *CreateTemplateVersionOptions { + _options.Name = core.StringPtr(name) + return _options +} + +// SetDescription : Allow user to set Description +func (_options *CreateTemplateVersionOptions) SetDescription(description string) *CreateTemplateVersionOptions { + _options.Description = core.StringPtr(description) + return _options +} + +// SetGroup : Allow user to set Group +func (_options *CreateTemplateVersionOptions) SetGroup(group *AccessGroupInput) *CreateTemplateVersionOptions { + _options.Group = group + return _options +} + +// SetPolicyTemplateReferences : Allow user to set PolicyTemplateReferences +func (_options *CreateTemplateVersionOptions) SetPolicyTemplateReferences(policyTemplateReferences []PolicyTemplatesInput) *CreateTemplateVersionOptions { + _options.PolicyTemplateReferences = policyTemplateReferences + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *CreateTemplateVersionOptions) SetTransactionID(transactionID string) *CreateTemplateVersionOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateTemplateVersionOptions) SetHeaders(param map[string]string) *CreateTemplateVersionOptions { + options.Headers = param + return options +} + +// DeleteAccessGroupOptions : The DeleteAccessGroup options. +type DeleteAccessGroupOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // If force is true, delete the group as well as its associated members and rules. + Force *bool `json:"force,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteAccessGroupOptions : Instantiate DeleteAccessGroupOptions +func (*IamAccessGroupsV2) NewDeleteAccessGroupOptions(accessGroupID string) *DeleteAccessGroupOptions { + return &DeleteAccessGroupOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *DeleteAccessGroupOptions) SetAccessGroupID(accessGroupID string) *DeleteAccessGroupOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *DeleteAccessGroupOptions) SetTransactionID(transactionID string) *DeleteAccessGroupOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetForce : Allow user to set Force +func (_options *DeleteAccessGroupOptions) SetForce(force bool) *DeleteAccessGroupOptions { + _options.Force = core.BoolPtr(force) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteAccessGroupOptions) SetHeaders(param map[string]string) *DeleteAccessGroupOptions { + options.Headers = param + return options +} + +// DeleteAssignmentOptions : The DeleteAssignment options. +type DeleteAssignmentOptions struct { + // assignment id path parameter. + AssignmentID *string `json:"assignment_id" validate:"required,ne="` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteAssignmentOptions : Instantiate DeleteAssignmentOptions +func (*IamAccessGroupsV2) NewDeleteAssignmentOptions(assignmentID string) *DeleteAssignmentOptions { + return &DeleteAssignmentOptions{ + AssignmentID: core.StringPtr(assignmentID), + } +} + +// SetAssignmentID : Allow user to set AssignmentID +func (_options *DeleteAssignmentOptions) SetAssignmentID(assignmentID string) *DeleteAssignmentOptions { + _options.AssignmentID = core.StringPtr(assignmentID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *DeleteAssignmentOptions) SetTransactionID(transactionID string) *DeleteAssignmentOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteAssignmentOptions) SetHeaders(param map[string]string) *DeleteAssignmentOptions { + options.Headers = param + return options +} + +// DeleteFromAllGroupsResponse : The response from the delete member from access groups request. +type DeleteFromAllGroupsResponse struct { + // The `iam_id` of the member to removed from groups. + IamID *string `json:"iam_id,omitempty"` + + // The groups the member was removed from. + Groups []DeleteFromAllGroupsResponseGroupsItem `json:"groups,omitempty"` +} + +// UnmarshalDeleteFromAllGroupsResponse unmarshals an instance of DeleteFromAllGroupsResponse from the specified map of raw messages. +func UnmarshalDeleteFromAllGroupsResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DeleteFromAllGroupsResponse) + err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "groups", &obj.Groups, UnmarshalDeleteFromAllGroupsResponseGroupsItem) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DeleteFromAllGroupsResponseGroupsItem : DeleteFromAllGroupsResponseGroupsItem struct +type DeleteFromAllGroupsResponseGroupsItem struct { + // The access group that the member is to be deleted from. + AccessGroupID *string `json:"access_group_id,omitempty"` + + // The outcome of the delete operation on this `access_group_id`. + StatusCode *int64 `json:"status_code,omitempty"` + + // A transaction-id that can be used for debugging purposes. + Trace *string `json:"trace,omitempty"` + + // A list of errors that occurred when trying to remove a member from groups. + Errors []Error `json:"errors,omitempty"` +} + +// UnmarshalDeleteFromAllGroupsResponseGroupsItem unmarshals an instance of DeleteFromAllGroupsResponseGroupsItem from the specified map of raw messages. +func UnmarshalDeleteFromAllGroupsResponseGroupsItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DeleteFromAllGroupsResponseGroupsItem) + err = core.UnmarshalPrimitive(m, "access_group_id", &obj.AccessGroupID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + if err != nil { + return + } + err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalError) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DeleteGroupBulkMembersResponse : The access group id and the members removed from it. +type DeleteGroupBulkMembersResponse struct { + // The access group id. + AccessGroupID *string `json:"access_group_id,omitempty"` + + // The `iam_id`s removed from the access group. + Members []DeleteGroupBulkMembersResponseMembersItem `json:"members,omitempty"` +} + +// UnmarshalDeleteGroupBulkMembersResponse unmarshals an instance of DeleteGroupBulkMembersResponse from the specified map of raw messages. +func UnmarshalDeleteGroupBulkMembersResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DeleteGroupBulkMembersResponse) + err = core.UnmarshalPrimitive(m, "access_group_id", &obj.AccessGroupID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "members", &obj.Members, UnmarshalDeleteGroupBulkMembersResponseMembersItem) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DeleteGroupBulkMembersResponseMembersItem : DeleteGroupBulkMembersResponseMembersItem struct +type DeleteGroupBulkMembersResponseMembersItem struct { + // The `iam_id` to be deleted. + IamID *string `json:"iam_id,omitempty"` + + // A transaction-id that can be used for debugging purposes. + Trace *string `json:"trace,omitempty"` + + // The outcome of the delete membership operation on this `access_group_id`. + StatusCode *int64 `json:"status_code,omitempty"` + + // A list of errors that occurred when trying to remove a member from groups. + Errors []Error `json:"errors,omitempty"` +} + +// UnmarshalDeleteGroupBulkMembersResponseMembersItem unmarshals an instance of DeleteGroupBulkMembersResponseMembersItem from the specified map of raw messages. +func UnmarshalDeleteGroupBulkMembersResponseMembersItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DeleteGroupBulkMembersResponseMembersItem) + err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) + if err != nil { + return + } + err = core.UnmarshalModel(m, "errors", &obj.Errors, UnmarshalError) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DeleteTemplateOptions : The DeleteTemplate options. +type DeleteTemplateOptions struct { + // template id parameter. + TemplateID *string `json:"template_id" validate:"required,ne="` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteTemplateOptions : Instantiate DeleteTemplateOptions +func (*IamAccessGroupsV2) NewDeleteTemplateOptions(templateID string) *DeleteTemplateOptions { + return &DeleteTemplateOptions{ + TemplateID: core.StringPtr(templateID), + } +} + +// SetTemplateID : Allow user to set TemplateID +func (_options *DeleteTemplateOptions) SetTemplateID(templateID string) *DeleteTemplateOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *DeleteTemplateOptions) SetTransactionID(transactionID string) *DeleteTemplateOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteTemplateOptions) SetHeaders(param map[string]string) *DeleteTemplateOptions { + options.Headers = param + return options +} + +// DeleteTemplateVersionOptions : The DeleteTemplateVersion options. +type DeleteTemplateVersionOptions struct { + // template id parameter. + TemplateID *string `json:"template_id" validate:"required,ne="` + + // version number in path. + VersionNum *string `json:"version_num" validate:"required,ne="` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteTemplateVersionOptions : Instantiate DeleteTemplateVersionOptions +func (*IamAccessGroupsV2) NewDeleteTemplateVersionOptions(templateID string, versionNum string) *DeleteTemplateVersionOptions { + return &DeleteTemplateVersionOptions{ + TemplateID: core.StringPtr(templateID), + VersionNum: core.StringPtr(versionNum), + } +} + +// SetTemplateID : Allow user to set TemplateID +func (_options *DeleteTemplateVersionOptions) SetTemplateID(templateID string) *DeleteTemplateVersionOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options +} + +// SetVersionNum : Allow user to set VersionNum +func (_options *DeleteTemplateVersionOptions) SetVersionNum(versionNum string) *DeleteTemplateVersionOptions { + _options.VersionNum = core.StringPtr(versionNum) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *DeleteTemplateVersionOptions) SetTransactionID(transactionID string) *DeleteTemplateVersionOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteTemplateVersionOptions) SetHeaders(param map[string]string) *DeleteTemplateVersionOptions { + options.Headers = param + return options +} + +// Error : Error contains the code and message for an error returned to the user code is a string identifying the problem, +// examples "missing_field", "reserved_value" message is a string explaining the solution to the problem that was +// encountered. +type Error struct { + // A human-readable error code represented by a snake case string. + Code *string `json:"code,omitempty"` + + // A specific error message that details the issue or an action to take. + Message *string `json:"message,omitempty"` +} + +// UnmarshalError unmarshals an instance of Error from the specified map of raw messages. +func UnmarshalError(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Error) + err = core.UnmarshalPrimitive(m, "code", &obj.Code) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "message", &obj.Message) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GetAccessGroupOptions : The GetAccessGroup options. +type GetAccessGroupOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // If show_federated is true, the group will return an is_federated value that is set to true if rules exist for the + // group. + ShowFederated *bool `json:"show_federated,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetAccessGroupOptions : Instantiate GetAccessGroupOptions +func (*IamAccessGroupsV2) NewGetAccessGroupOptions(accessGroupID string) *GetAccessGroupOptions { + return &GetAccessGroupOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *GetAccessGroupOptions) SetAccessGroupID(accessGroupID string) *GetAccessGroupOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *GetAccessGroupOptions) SetTransactionID(transactionID string) *GetAccessGroupOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetShowFederated : Allow user to set ShowFederated +func (_options *GetAccessGroupOptions) SetShowFederated(showFederated bool) *GetAccessGroupOptions { + _options.ShowFederated = core.BoolPtr(showFederated) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetAccessGroupOptions) SetHeaders(param map[string]string) *GetAccessGroupOptions { + options.Headers = param + return options +} + +// GetAccessGroupRuleOptions : The GetAccessGroupRule options. +type GetAccessGroupRuleOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // The rule to get. + RuleID *string `json:"rule_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetAccessGroupRuleOptions : Instantiate GetAccessGroupRuleOptions +func (*IamAccessGroupsV2) NewGetAccessGroupRuleOptions(accessGroupID string, ruleID string) *GetAccessGroupRuleOptions { + return &GetAccessGroupRuleOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + RuleID: core.StringPtr(ruleID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *GetAccessGroupRuleOptions) SetAccessGroupID(accessGroupID string) *GetAccessGroupRuleOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetRuleID : Allow user to set RuleID +func (_options *GetAccessGroupRuleOptions) SetRuleID(ruleID string) *GetAccessGroupRuleOptions { + _options.RuleID = core.StringPtr(ruleID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *GetAccessGroupRuleOptions) SetTransactionID(transactionID string) *GetAccessGroupRuleOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetAccessGroupRuleOptions) SetHeaders(param map[string]string) *GetAccessGroupRuleOptions { + options.Headers = param + return options +} + +// GetAccountSettingsOptions : The GetAccountSettings options. +type GetAccountSettingsOptions struct { + // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the + // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the + // Authorization token. + AccountID *string `json:"account_id" validate:"required"` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetAccountSettingsOptions : Instantiate GetAccountSettingsOptions +func (*IamAccessGroupsV2) NewGetAccountSettingsOptions(accountID string) *GetAccountSettingsOptions { + return &GetAccountSettingsOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *GetAccountSettingsOptions) SetAccountID(accountID string) *GetAccountSettingsOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *GetAccountSettingsOptions) SetTransactionID(transactionID string) *GetAccountSettingsOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetAccountSettingsOptions) SetHeaders(param map[string]string) *GetAccountSettingsOptions { + options.Headers = param + return options +} + +// GetAssignmentOptions : The GetAssignment options. +type GetAssignmentOptions struct { + // assignment id parameter. + AssignmentID *string `json:"assignment_id" validate:"required,ne="` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Returns resources access group template assigned, possible values `true` or `false`. + Verbose *bool `json:"verbose,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetAssignmentOptions : Instantiate GetAssignmentOptions +func (*IamAccessGroupsV2) NewGetAssignmentOptions(assignmentID string) *GetAssignmentOptions { + return &GetAssignmentOptions{ + AssignmentID: core.StringPtr(assignmentID), + } +} + +// SetAssignmentID : Allow user to set AssignmentID +func (_options *GetAssignmentOptions) SetAssignmentID(assignmentID string) *GetAssignmentOptions { + _options.AssignmentID = core.StringPtr(assignmentID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *GetAssignmentOptions) SetTransactionID(transactionID string) *GetAssignmentOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetVerbose : Allow user to set Verbose +func (_options *GetAssignmentOptions) SetVerbose(verbose bool) *GetAssignmentOptions { + _options.Verbose = core.BoolPtr(verbose) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetAssignmentOptions) SetHeaders(param map[string]string) *GetAssignmentOptions { + options.Headers = param + return options +} + +// GetLatestTemplateVersionOptions : The GetLatestTemplateVersion options. +type GetLatestTemplateVersionOptions struct { + // template id parameter. + TemplateID *string `json:"template_id" validate:"required,ne="` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetLatestTemplateVersionOptions : Instantiate GetLatestTemplateVersionOptions +func (*IamAccessGroupsV2) NewGetLatestTemplateVersionOptions(templateID string) *GetLatestTemplateVersionOptions { + return &GetLatestTemplateVersionOptions{ + TemplateID: core.StringPtr(templateID), + } +} + +// SetTemplateID : Allow user to set TemplateID +func (_options *GetLatestTemplateVersionOptions) SetTemplateID(templateID string) *GetLatestTemplateVersionOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *GetLatestTemplateVersionOptions) SetTransactionID(transactionID string) *GetLatestTemplateVersionOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetLatestTemplateVersionOptions) SetHeaders(param map[string]string) *GetLatestTemplateVersionOptions { + options.Headers = param + return options +} + +// GetTemplateAssignmentResponse : Response object containing the details of a template assignment. +type GetTemplateAssignmentResponse struct { + // The ID of the assignment. + ID *string `json:"id" validate:"required"` + + // The ID of the account that the assignment belongs to. + AccountID *string `json:"account_id" validate:"required"` + + // The ID of the template that the assignment is based on. + TemplateID *string `json:"template_id" validate:"required"` + + // The version of the template that the assignment is based on. + TemplateVersion *string `json:"template_version" validate:"required"` + + // The type of the entity that the assignment applies to. + TargetType *string `json:"target_type" validate:"required"` + + // The ID of the entity that the assignment applies to. + Target *string `json:"target" validate:"required"` + + // The operation that the assignment applies to (e.g. 'create', 'update', 'delete'). + Operation *string `json:"operation" validate:"required"` + + // The status of the assignment (e.g. 'pending', 'success', 'failure'). + Status *string `json:"status" validate:"required"` + + // List of resources for the assignment. + Resources []ResourceListWithTargetAccountID `json:"resources,omitempty"` + + // The URL of the assignment resource. + Href *string `json:"href" validate:"required"` + + // The date and time when the assignment was created. + CreatedAt *strfmt.DateTime `json:"created_at" validate:"required"` + + // The user or system that created the assignment. + CreatedBy *string `json:"created_by" validate:"required"` + + // The date and time when the assignment was last updated. + UpdatedAt *strfmt.DateTime `json:"updated_at" validate:"required"` + + // The user or system that last updated the assignment. + UpdatedBy *string `json:"updated_by" validate:"required"` +} + +// UnmarshalGetTemplateAssignmentResponse unmarshals an instance of GetTemplateAssignmentResponse from the specified map of raw messages. +func UnmarshalGetTemplateAssignmentResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(GetTemplateAssignmentResponse) + 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, "template_id", &obj.TemplateID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "template_version", &obj.TemplateVersion) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "target_type", &obj.TargetType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "target", &obj.Target) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operation", &obj.Operation) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status", &obj.Status) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalResourceListWithTargetAccountID) + 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", &obj.CreatedBy) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "updated_at", &obj.UpdatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "updated_by", &obj.UpdatedBy) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GetTemplateVersionOptions : The GetTemplateVersion options. +type GetTemplateVersionOptions struct { + // template id parameter. + TemplateID *string `json:"template_id" validate:"required,ne="` + + // path parameter verison number. + VersionNum *string `json:"version_num" validate:"required,ne="` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetTemplateVersionOptions : Instantiate GetTemplateVersionOptions +func (*IamAccessGroupsV2) NewGetTemplateVersionOptions(templateID string, versionNum string) *GetTemplateVersionOptions { + return &GetTemplateVersionOptions{ + TemplateID: core.StringPtr(templateID), + VersionNum: core.StringPtr(versionNum), + } +} + +// SetTemplateID : Allow user to set TemplateID +func (_options *GetTemplateVersionOptions) SetTemplateID(templateID string) *GetTemplateVersionOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options +} + +// SetVersionNum : Allow user to set VersionNum +func (_options *GetTemplateVersionOptions) SetVersionNum(versionNum string) *GetTemplateVersionOptions { + _options.VersionNum = core.StringPtr(versionNum) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *GetTemplateVersionOptions) SetTransactionID(transactionID string) *GetTemplateVersionOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetTemplateVersionOptions) SetHeaders(param map[string]string) *GetTemplateVersionOptions { + options.Headers = param + return options +} + +// Group : An IAM access group. +type Group struct { + // The group's access group ID. + ID *string `json:"id,omitempty"` + + // The group's name. + Name *string `json:"name,omitempty"` + + // The group's description - if defined. + Description *string `json:"description,omitempty"` + + // The account id where the group was created. + AccountID *string `json:"account_id,omitempty"` + + // The timestamp of when the group was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + + // The `iam_id` of the entity that created the group. + CreatedByID *string `json:"created_by_id,omitempty"` + + // The timestamp of when the group was last edited. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` + + // The `iam_id` of the entity that last modified the group name or description. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` + + // A url to the given group resource. + Href *string `json:"href,omitempty"` + + // This is set to true if rules exist for the group. + IsFederated *bool `json:"is_federated,omitempty"` +} + +// UnmarshalGroup unmarshals an instance of Group from the specified map of raw messages. +func UnmarshalGroup(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Group) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + 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 + } + err = core.UnmarshalPrimitive(m, "is_federated", &obj.IsFederated) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GroupActionControls : Access Group Action Controls component. +type GroupActionControls struct { + // Control whether or not child account administrators can add access policies to the enterprise-managed access group + // in their account. + Access *AccessActionControls `json:"access,omitempty"` +} + +// UnmarshalGroupActionControls unmarshals an instance of GroupActionControls from the specified map of raw messages. +func UnmarshalGroupActionControls(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(GroupActionControls) + err = core.UnmarshalModel(m, "access", &obj.Access, UnmarshalAccessActionControls) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GroupMembersList : The members of a group. +type GroupMembersList struct { + // Limit on how many items can be returned. + Limit *int64 `json:"limit" validate:"required"` + + // The offset of the first item returned in the result set. + Offset *int64 `json:"offset" validate:"required"` + + // The total number of items that match the query. + TotalCount *int64 `json:"total_count" validate:"required"` + + // A link object. + First *HrefStruct `json:"first,omitempty"` + + // A link object. + Previous *HrefStruct `json:"previous,omitempty"` + + // A link object. + Next *HrefStruct `json:"next,omitempty"` + + // A link object. + Last *HrefStruct `json:"last,omitempty"` + + // The members of an access group. + Members []ListGroupMembersResponseMember `json:"members,omitempty"` +} + +// UnmarshalGroupMembersList unmarshals an instance of GroupMembersList from the specified map of raw messages. +func UnmarshalGroupMembersList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(GroupMembersList) + err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "previous", &obj.Previous, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "members", &obj.Members, UnmarshalListGroupMembersResponseMember) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Retrieve the value to be passed to a request to access the next page of results +func (resp *GroupMembersList) GetNextOffset() (*int64, error) { + if core.IsNil(resp.Next) { + return nil, nil + } + offset, err := core.GetQueryParam(resp.Next.Href, "offset") + if err != nil || offset == nil { + return nil, err + } + var offsetValue int64 + offsetValue, err = strconv.ParseInt(*offset, 10, 64) + if err != nil { + return nil, err + } + return core.Int64Ptr(offsetValue), nil +} + +// GroupsList : The list of access groups returned as part of a response. +type GroupsList struct { + // Limit on how many items can be returned. + Limit *int64 `json:"limit" validate:"required"` + + // The offset of the first item returned in the result set. + Offset *int64 `json:"offset" validate:"required"` + + // The total number of items that match the query. + TotalCount *int64 `json:"total_count" validate:"required"` + + // A link object. + First *HrefStruct `json:"first,omitempty"` + + // A link object. + Previous *HrefStruct `json:"previous,omitempty"` + + // A link object. + Next *HrefStruct `json:"next,omitempty"` + + // A link object. + Last *HrefStruct `json:"last,omitempty"` + + // An array of access groups. + Groups []Group `json:"groups,omitempty"` +} + +// UnmarshalGroupsList unmarshals an instance of GroupsList from the specified map of raw messages. +func UnmarshalGroupsList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(GroupsList) + err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "previous", &obj.Previous, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "groups", &obj.Groups, UnmarshalGroup) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Retrieve the value to be passed to a request to access the next page of results +func (resp *GroupsList) GetNextOffset() (*int64, error) { + if core.IsNil(resp.Next) { + return nil, nil + } + offset, err := core.GetQueryParam(resp.Next.Href, "offset") + if err != nil || offset == nil { + return nil, err + } + var offsetValue int64 + offsetValue, err = strconv.ParseInt(*offset, 10, 64) + if err != nil { + return nil, err + } + return core.Int64Ptr(offsetValue), nil +} + +// HrefStruct : A link object. +type HrefStruct struct { + // A string containing the link’s URL. + Href *string `json:"href,omitempty"` +} + +// UnmarshalHrefStruct unmarshals an instance of HrefStruct from the specified map of raw messages. +func UnmarshalHrefStruct(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(HrefStruct) + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// IsMemberOfAccessGroupOptions : The IsMemberOfAccessGroup options. +type IsMemberOfAccessGroupOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // The IAM identifier. + IamID *string `json:"iam_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewIsMemberOfAccessGroupOptions : Instantiate IsMemberOfAccessGroupOptions +func (*IamAccessGroupsV2) NewIsMemberOfAccessGroupOptions(accessGroupID string, iamID string) *IsMemberOfAccessGroupOptions { + return &IsMemberOfAccessGroupOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + IamID: core.StringPtr(iamID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *IsMemberOfAccessGroupOptions) SetAccessGroupID(accessGroupID string) *IsMemberOfAccessGroupOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetIamID : Allow user to set IamID +func (_options *IsMemberOfAccessGroupOptions) SetIamID(iamID string) *IsMemberOfAccessGroupOptions { + _options.IamID = core.StringPtr(iamID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *IsMemberOfAccessGroupOptions) SetTransactionID(transactionID string) *IsMemberOfAccessGroupOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *IsMemberOfAccessGroupOptions) SetHeaders(param map[string]string) *IsMemberOfAccessGroupOptions { + options.Headers = param + return options +} + +// ListAccessGroupMembersOptions : The ListAccessGroupMembers options. +type ListAccessGroupMembersOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Filters members by membership type. Filter by `static`, `dynamic` or `all`. `static` lists the members explicitly + // added to the access group, and `dynamic` lists the members that are part of the access group at that time via + // dynamic rules. `all` lists both static and dynamic members. + MembershipType *string `json:"membership_type,omitempty"` + + // Return up to this limit of results where limit is between 0 and 100. + Limit *int64 `json:"limit,omitempty"` + + // The offset of the first result item to be returned. + Offset *int64 `json:"offset,omitempty"` + + // Filter the results by member type. + Type *string `json:"type,omitempty"` + + // Return user's email and name for each user ID or the name for each service ID or trusted profile. + Verbose *bool `json:"verbose,omitempty"` + + // If verbose is true, sort the results by id, name, or email. + Sort *string `json:"sort,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListAccessGroupMembersOptions : Instantiate ListAccessGroupMembersOptions +func (*IamAccessGroupsV2) NewListAccessGroupMembersOptions(accessGroupID string) *ListAccessGroupMembersOptions { + return &ListAccessGroupMembersOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *ListAccessGroupMembersOptions) SetAccessGroupID(accessGroupID string) *ListAccessGroupMembersOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *ListAccessGroupMembersOptions) SetTransactionID(transactionID string) *ListAccessGroupMembersOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetMembershipType : Allow user to set MembershipType +func (_options *ListAccessGroupMembersOptions) SetMembershipType(membershipType string) *ListAccessGroupMembersOptions { + _options.MembershipType = core.StringPtr(membershipType) + return _options +} + +// SetLimit : Allow user to set Limit +func (_options *ListAccessGroupMembersOptions) SetLimit(limit int64) *ListAccessGroupMembersOptions { + _options.Limit = core.Int64Ptr(limit) + return _options +} + +// SetOffset : Allow user to set Offset +func (_options *ListAccessGroupMembersOptions) SetOffset(offset int64) *ListAccessGroupMembersOptions { + _options.Offset = core.Int64Ptr(offset) + return _options +} + +// SetType : Allow user to set Type +func (_options *ListAccessGroupMembersOptions) SetType(typeVar string) *ListAccessGroupMembersOptions { + _options.Type = core.StringPtr(typeVar) + return _options +} + +// SetVerbose : Allow user to set Verbose +func (_options *ListAccessGroupMembersOptions) SetVerbose(verbose bool) *ListAccessGroupMembersOptions { + _options.Verbose = core.BoolPtr(verbose) + return _options +} + +// SetSort : Allow user to set Sort +func (_options *ListAccessGroupMembersOptions) SetSort(sort string) *ListAccessGroupMembersOptions { + _options.Sort = core.StringPtr(sort) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListAccessGroupMembersOptions) SetHeaders(param map[string]string) *ListAccessGroupMembersOptions { + options.Headers = param + return options +} + +// ListAccessGroupRulesOptions : The ListAccessGroupRules options. +type ListAccessGroupRulesOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListAccessGroupRulesOptions : Instantiate ListAccessGroupRulesOptions +func (*IamAccessGroupsV2) NewListAccessGroupRulesOptions(accessGroupID string) *ListAccessGroupRulesOptions { + return &ListAccessGroupRulesOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *ListAccessGroupRulesOptions) SetAccessGroupID(accessGroupID string) *ListAccessGroupRulesOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *ListAccessGroupRulesOptions) SetTransactionID(transactionID string) *ListAccessGroupRulesOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListAccessGroupRulesOptions) SetHeaders(param map[string]string) *ListAccessGroupRulesOptions { + options.Headers = param + return options +} + +// ListAccessGroupsOptions : The ListAccessGroups options. +type ListAccessGroupsOptions struct { + // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the + // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the + // Authorization token. + AccountID *string `json:"account_id" validate:"required"` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Return groups for member ID (IBMid, service ID or trusted profile ID). + IamID *string `json:"iam_id,omitempty"` + + // Use search to filter access groups list by id, name or description. + // * `search=id:` - To list access groups by id + // * `search=name:` - To list access groups by name + // * `search=description:` - To list access groups by description. + Search *string `json:"search,omitempty"` + + // Membership type need to be specified along with iam_id and must be either `static`, `dynamic` or `all`. If + // membership type is `static`, members explicitly added to the group will be shown. If membership type is `dynamic`, + // members accessing the access group at the moment via dynamic rules will be shown. If membership type is `all`, both + // static and dynamic members will be shown. + MembershipType *string `json:"membership_type,omitempty"` + + // Return up to this limit of results where limit is between 0 and 100. + Limit *int64 `json:"limit,omitempty"` + + // The offset of the first result item to be returned. + Offset *int64 `json:"offset,omitempty"` + + // Sort the results by id, name, description, or is_federated flag. + Sort *string `json:"sort,omitempty"` + + // If show_federated is true, each group listed will return an is_federated value that is set to true if rules exist + // for the group. + ShowFederated *bool `json:"show_federated,omitempty"` + + // If hide_public_access is true, do not include the Public Access Group in the results. + HidePublicAccess *bool `json:"hide_public_access,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListAccessGroupsOptions : Instantiate ListAccessGroupsOptions +func (*IamAccessGroupsV2) NewListAccessGroupsOptions(accountID string) *ListAccessGroupsOptions { + return &ListAccessGroupsOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *ListAccessGroupsOptions) SetAccountID(accountID string) *ListAccessGroupsOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *ListAccessGroupsOptions) SetTransactionID(transactionID string) *ListAccessGroupsOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetIamID : Allow user to set IamID +func (_options *ListAccessGroupsOptions) SetIamID(iamID string) *ListAccessGroupsOptions { + _options.IamID = core.StringPtr(iamID) + return _options +} + +// SetSearch : Allow user to set Search +func (_options *ListAccessGroupsOptions) SetSearch(search string) *ListAccessGroupsOptions { + _options.Search = core.StringPtr(search) + return _options +} + +// SetMembershipType : Allow user to set MembershipType +func (_options *ListAccessGroupsOptions) SetMembershipType(membershipType string) *ListAccessGroupsOptions { + _options.MembershipType = core.StringPtr(membershipType) + return _options +} + +// SetLimit : Allow user to set Limit +func (_options *ListAccessGroupsOptions) SetLimit(limit int64) *ListAccessGroupsOptions { + _options.Limit = core.Int64Ptr(limit) + return _options +} + +// SetOffset : Allow user to set Offset +func (_options *ListAccessGroupsOptions) SetOffset(offset int64) *ListAccessGroupsOptions { + _options.Offset = core.Int64Ptr(offset) + return _options +} + +// SetSort : Allow user to set Sort +func (_options *ListAccessGroupsOptions) SetSort(sort string) *ListAccessGroupsOptions { + _options.Sort = core.StringPtr(sort) + return _options +} + +// SetShowFederated : Allow user to set ShowFederated +func (_options *ListAccessGroupsOptions) SetShowFederated(showFederated bool) *ListAccessGroupsOptions { + _options.ShowFederated = core.BoolPtr(showFederated) + return _options +} + +// SetHidePublicAccess : Allow user to set HidePublicAccess +func (_options *ListAccessGroupsOptions) SetHidePublicAccess(hidePublicAccess bool) *ListAccessGroupsOptions { + _options.HidePublicAccess = core.BoolPtr(hidePublicAccess) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListAccessGroupsOptions) SetHeaders(param map[string]string) *ListAccessGroupsOptions { + options.Headers = param + return options +} + +// ListAssignmentsOptions : The ListAssignments options. +type ListAssignmentsOptions struct { + // query parameter account id. + AccountID *string `json:"account_id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListAssignmentsOptions : Instantiate ListAssignmentsOptions +func (*IamAccessGroupsV2) NewListAssignmentsOptions() *ListAssignmentsOptions { + return &ListAssignmentsOptions{} +} + +// SetAccountID : Allow user to set AccountID +func (_options *ListAssignmentsOptions) SetAccountID(accountID string) *ListAssignmentsOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListAssignmentsOptions) SetHeaders(param map[string]string) *ListAssignmentsOptions { + options.Headers = param + return options +} + +// ListGroupMembersResponseMember : A single member of an access group in a list. +type ListGroupMembersResponseMember struct { + // The IBMid or Service Id of the member. + IamID *string `json:"iam_id,omitempty"` + + // The member type - either `user`, `service` or `profile`. + Type *string `json:"type,omitempty"` + + // The membership type - either `static` or `dynamic`. + MembershipType *string `json:"membership_type,omitempty"` + + // The user's or service id's name. + Name *string `json:"name,omitempty"` + + // If the member type is user, this is the user's email. + Email *string `json:"email,omitempty"` + + // If the member type is service, this is the service id's description. + Description *string `json:"description,omitempty"` + + // A url to the given member resource. + Href *string `json:"href,omitempty"` + + // The timestamp the membership was created at. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + + // The `iam_id` of the entity that created the membership. + CreatedByID *string `json:"created_by_id,omitempty"` +} + +// UnmarshalListGroupMembersResponseMember unmarshals an instance of ListGroupMembersResponseMember from the specified map of raw messages. +func UnmarshalListGroupMembersResponseMember(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ListGroupMembersResponseMember) + err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "membership_type", &obj.MembershipType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "email", &obj.Email) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + 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 + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ListTemplateVersionsOptions : The ListTemplateVersions options. +type ListTemplateVersionsOptions struct { + // template id parameter. + TemplateID *string `json:"template_id" validate:"required,ne="` + + // limit parameter. + Limit *int64 `json:"limit,omitempty"` + + // offset parameter. + Offset *int64 `json:"offset,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListTemplateVersionsOptions : Instantiate ListTemplateVersionsOptions +func (*IamAccessGroupsV2) NewListTemplateVersionsOptions(templateID string) *ListTemplateVersionsOptions { + return &ListTemplateVersionsOptions{ + TemplateID: core.StringPtr(templateID), + } +} + +// SetTemplateID : Allow user to set TemplateID +func (_options *ListTemplateVersionsOptions) SetTemplateID(templateID string) *ListTemplateVersionsOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options +} + +// SetLimit : Allow user to set Limit +func (_options *ListTemplateVersionsOptions) SetLimit(limit int64) *ListTemplateVersionsOptions { + _options.Limit = core.Int64Ptr(limit) + return _options +} + +// SetOffset : Allow user to set Offset +func (_options *ListTemplateVersionsOptions) SetOffset(offset int64) *ListTemplateVersionsOptions { + _options.Offset = core.Int64Ptr(offset) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListTemplateVersionsOptions) SetHeaders(param map[string]string) *ListTemplateVersionsOptions { + options.Headers = param + return options +} + +// ListTemplateVersionsResponse : Response object for listing template versions. +type ListTemplateVersionsResponse struct { + // The maximum number of resources to return. + Limit *int64 `json:"limit" validate:"required"` + + // The offset of the first resource in the list. + Offset *int64 `json:"offset" validate:"required"` + + // The total number of resources in the list. + TotalCount *int64 `json:"total_count" validate:"required"` + + // A link object. + First *HrefStruct `json:"first" validate:"required"` + + // A link object. + Previous *HrefStruct `json:"previous,omitempty"` + + // A link object. + Next *HrefStruct `json:"next,omitempty"` + + // A link object. + Last *HrefStruct `json:"last" validate:"required"` + + // A list of access group template versions. + GroupTemplateVersions []ListTemplatesVersionsResponse `json:"group_template_versions" validate:"required"` +} + +// UnmarshalListTemplateVersionsResponse unmarshals an instance of ListTemplateVersionsResponse from the specified map of raw messages. +func UnmarshalListTemplateVersionsResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ListTemplateVersionsResponse) + err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "previous", &obj.Previous, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "group_template_versions", &obj.GroupTemplateVersions, UnmarshalListTemplatesVersionsResponse) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Retrieve the value to be passed to a request to access the next page of results +func (resp *ListTemplateVersionsResponse) GetNextOffset() (*int64, error) { + if core.IsNil(resp.Next) { + return nil, nil + } + offset, err := core.GetQueryParam(resp.Next.Href, "offset") + if err != nil || offset == nil { + return nil, err + } + var offsetValue int64 + offsetValue, err = strconv.ParseInt(*offset, 10, 64) + if err != nil { + return nil, err + } + return core.Int64Ptr(offsetValue), nil +} + +// ListTemplatesOptions : The ListTemplates options. +type ListTemplatesOptions struct { + // query parameter account id. + AccountID *string `json:"account_id" validate:"required"` + + // An optional transaction id for the request. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // limit parameter. + Limit *int64 `json:"limit,omitempty"` + + // offset parameter. + Offset *int64 `json:"offset,omitempty"` + + // query parameter verbose. + Verbose *bool `json:"verbose,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListTemplatesOptions : Instantiate ListTemplatesOptions +func (*IamAccessGroupsV2) NewListTemplatesOptions(accountID string) *ListTemplatesOptions { + return &ListTemplatesOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *ListTemplatesOptions) SetAccountID(accountID string) *ListTemplatesOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *ListTemplatesOptions) SetTransactionID(transactionID string) *ListTemplatesOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetLimit : Allow user to set Limit +func (_options *ListTemplatesOptions) SetLimit(limit int64) *ListTemplatesOptions { + _options.Limit = core.Int64Ptr(limit) + return _options +} + +// SetOffset : Allow user to set Offset +func (_options *ListTemplatesOptions) SetOffset(offset int64) *ListTemplatesOptions { + _options.Offset = core.Int64Ptr(offset) + return _options +} + +// SetVerbose : Allow user to set Verbose +func (_options *ListTemplatesOptions) SetVerbose(verbose bool) *ListTemplatesOptions { + _options.Verbose = core.BoolPtr(verbose) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListTemplatesOptions) SetHeaders(param map[string]string) *ListTemplatesOptions { + options.Headers = param + return options +} + +// ListTemplatesResponse : Response object for listing templates. +type ListTemplatesResponse struct { + // The maximum number of resources to return. + Limit *int64 `json:"limit" validate:"required"` + + // The offset of the first resource in the list. + Offset *int64 `json:"offset" validate:"required"` + + // The total number of resources in the list. + TotalCount *int64 `json:"total_count" validate:"required"` + + // A link object. + First *HrefStruct `json:"first" validate:"required"` + + // A link object. + Previous *HrefStruct `json:"previous,omitempty"` + + // A link object. + Next *HrefStruct `json:"next,omitempty"` + + // A link object. + Last *HrefStruct `json:"last" validate:"required"` + + // A list of templates. + GroupTemplates []TemplateItem `json:"group_templates" validate:"required"` +} + +// UnmarshalListTemplatesResponse unmarshals an instance of ListTemplatesResponse from the specified map of raw messages. +func UnmarshalListTemplatesResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ListTemplatesResponse) + err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "previous", &obj.Previous, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "group_templates", &obj.GroupTemplates, UnmarshalTemplateItem) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Retrieve the value to be passed to a request to access the next page of results +func (resp *ListTemplatesResponse) GetNextOffset() (*int64, error) { + if core.IsNil(resp.Next) { + return nil, nil + } + offset, err := core.GetQueryParam(resp.Next.Href, "offset") + if err != nil || offset == nil { + return nil, err + } + var offsetValue int64 + offsetValue, err = strconv.ParseInt(*offset, 10, 64) + if err != nil { + return nil, err + } + return core.Int64Ptr(offsetValue), nil +} + +// ListTemplatesVersionsResponse : Response object for a single access group template version. +type ListTemplatesVersionsResponse struct { + // The name of the template. + Name *string `json:"name" validate:"required"` + + // The description of the template. + Description *string `json:"description" validate:"required"` + + // The ID of the account associated with the template. + AccountID *string `json:"account_id" validate:"required"` + + // The version number of the template. + Version *string `json:"version" validate:"required"` + + // A boolean indicating whether the template is committed or not. + Committed *bool `json:"committed" validate:"required"` + + // Access Group Input Component. + Group *AccessGroupInput `json:"group" validate:"required"` + + // A list of policy templates associated with the template. + PolicyTemplateReferences []PolicyTemplatesInput `json:"policy_template_references" validate:"required"` + + // The URL to the template resource. + Href *string `json:"href" validate:"required"` + + // The date and time the template was created. + CreatedAt *string `json:"created_at" validate:"required"` + + // The ID of the user who created the template. + CreatedByID *string `json:"created_by_id" validate:"required"` + + // The date and time the template was last modified. + LastModifiedAt *string `json:"last_modified_at" validate:"required"` + + // The ID of the user who last modified the template. + LastModifiedByID *string `json:"last_modified_by_id" validate:"required"` +} + +// UnmarshalListTemplatesVersionsResponse unmarshals an instance of ListTemplatesVersionsResponse from the specified map of raw messages. +func UnmarshalListTemplatesVersionsResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ListTemplatesVersionsResponse) + 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, "group", &obj.Group, UnmarshalAccessGroupInput) + if err != nil { + return + } + err = core.UnmarshalModel(m, "policy_template_references", &obj.PolicyTemplateReferences, UnmarshalPolicyTemplatesInput) + 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 +} + +// MembersActionControls : Control whether or not child account administrators can add and remove members from the enterprise-managed access +// group in their account. +type MembersActionControls struct { + // Action control for managing (Add & Remove) child account members in an enterprise-managed access group. + Add *bool `json:"add,omitempty"` + + // Action control for removing enterprise-managed members in an enterprise-managed access group. + Remove *bool `json:"remove,omitempty"` +} + +// UnmarshalMembersActionControls unmarshals an instance of MembersActionControls from the specified map of raw messages. +func UnmarshalMembersActionControls(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(MembersActionControls) + err = core.UnmarshalPrimitive(m, "add", &obj.Add) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "remove", &obj.Remove) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// MembersInput : Members Input component. +type MembersInput struct { + // Users array. + Users []string `json:"users,omitempty"` + + // Service ids array. + ServiceIds []string `json:"service_ids,omitempty"` + + // Control whether or not child account administrators can add and remove members from the enterprise-managed access + // group in their account. + ActionControls *MembersActionControls `json:"action_controls,omitempty"` +} + +// UnmarshalMembersInput unmarshals an instance of MembersInput from the specified map of raw messages. +func UnmarshalMembersInput(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(MembersInput) + err = core.UnmarshalPrimitive(m, "users", &obj.Users) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "service_ids", &obj.ServiceIds) + if err != nil { + return + } + err = core.UnmarshalModel(m, "action_controls", &obj.ActionControls, UnmarshalMembersActionControls) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PolicyTemplatesInput : Policy Templates Input component. +type PolicyTemplatesInput struct { + // policy template input id. + ID *string `json:"id,omitempty"` + + // policy template input version. + Version *string `json:"version,omitempty"` +} + +// UnmarshalPolicyTemplatesInput unmarshals an instance of PolicyTemplatesInput from the specified map of raw messages. +func UnmarshalPolicyTemplatesInput(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PolicyTemplatesInput) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "version", &obj.Version) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RemoveAccessGroupRuleOptions : The RemoveAccessGroupRule options. +type RemoveAccessGroupRuleOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // The rule to get. + RuleID *string `json:"rule_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewRemoveAccessGroupRuleOptions : Instantiate RemoveAccessGroupRuleOptions +func (*IamAccessGroupsV2) NewRemoveAccessGroupRuleOptions(accessGroupID string, ruleID string) *RemoveAccessGroupRuleOptions { + return &RemoveAccessGroupRuleOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + RuleID: core.StringPtr(ruleID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *RemoveAccessGroupRuleOptions) SetAccessGroupID(accessGroupID string) *RemoveAccessGroupRuleOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetRuleID : Allow user to set RuleID +func (_options *RemoveAccessGroupRuleOptions) SetRuleID(ruleID string) *RemoveAccessGroupRuleOptions { + _options.RuleID = core.StringPtr(ruleID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *RemoveAccessGroupRuleOptions) SetTransactionID(transactionID string) *RemoveAccessGroupRuleOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *RemoveAccessGroupRuleOptions) SetHeaders(param map[string]string) *RemoveAccessGroupRuleOptions { + options.Headers = param + return options +} + +// RemoveMemberFromAccessGroupOptions : The RemoveMemberFromAccessGroup options. +type RemoveMemberFromAccessGroupOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // The IAM identifier. + IamID *string `json:"iam_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewRemoveMemberFromAccessGroupOptions : Instantiate RemoveMemberFromAccessGroupOptions +func (*IamAccessGroupsV2) NewRemoveMemberFromAccessGroupOptions(accessGroupID string, iamID string) *RemoveMemberFromAccessGroupOptions { + return &RemoveMemberFromAccessGroupOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + IamID: core.StringPtr(iamID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *RemoveMemberFromAccessGroupOptions) SetAccessGroupID(accessGroupID string) *RemoveMemberFromAccessGroupOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetIamID : Allow user to set IamID +func (_options *RemoveMemberFromAccessGroupOptions) SetIamID(iamID string) *RemoveMemberFromAccessGroupOptions { + _options.IamID = core.StringPtr(iamID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *RemoveMemberFromAccessGroupOptions) SetTransactionID(transactionID string) *RemoveMemberFromAccessGroupOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *RemoveMemberFromAccessGroupOptions) SetHeaders(param map[string]string) *RemoveMemberFromAccessGroupOptions { + options.Headers = param + return options +} + +// RemoveMemberFromAllAccessGroupsOptions : The RemoveMemberFromAllAccessGroups options. +type RemoveMemberFromAllAccessGroupsOptions struct { + // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the + // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the + // Authorization token. + AccountID *string `json:"account_id" validate:"required"` + + // The IAM identifier. + IamID *string `json:"iam_id" validate:"required,ne="` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewRemoveMemberFromAllAccessGroupsOptions : Instantiate RemoveMemberFromAllAccessGroupsOptions +func (*IamAccessGroupsV2) NewRemoveMemberFromAllAccessGroupsOptions(accountID string, iamID string) *RemoveMemberFromAllAccessGroupsOptions { + return &RemoveMemberFromAllAccessGroupsOptions{ + AccountID: core.StringPtr(accountID), + IamID: core.StringPtr(iamID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *RemoveMemberFromAllAccessGroupsOptions) SetAccountID(accountID string) *RemoveMemberFromAllAccessGroupsOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetIamID : Allow user to set IamID +func (_options *RemoveMemberFromAllAccessGroupsOptions) SetIamID(iamID string) *RemoveMemberFromAllAccessGroupsOptions { + _options.IamID = core.StringPtr(iamID) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *RemoveMemberFromAllAccessGroupsOptions) SetTransactionID(transactionID string) *RemoveMemberFromAllAccessGroupsOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *RemoveMemberFromAllAccessGroupsOptions) SetHeaders(param map[string]string) *RemoveMemberFromAllAccessGroupsOptions { + options.Headers = param + return options +} + +// RemoveMembersFromAccessGroupOptions : The RemoveMembersFromAccessGroup options. +type RemoveMembersFromAccessGroupOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // The `iam_id`s to remove from the access group. This field has a limit of 50 `iam_id`s. + Members []string `json:"members,omitempty"` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewRemoveMembersFromAccessGroupOptions : Instantiate RemoveMembersFromAccessGroupOptions +func (*IamAccessGroupsV2) NewRemoveMembersFromAccessGroupOptions(accessGroupID string) *RemoveMembersFromAccessGroupOptions { + return &RemoveMembersFromAccessGroupOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *RemoveMembersFromAccessGroupOptions) SetAccessGroupID(accessGroupID string) *RemoveMembersFromAccessGroupOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetMembers : Allow user to set Members +func (_options *RemoveMembersFromAccessGroupOptions) SetMembers(members []string) *RemoveMembersFromAccessGroupOptions { + _options.Members = members + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *RemoveMembersFromAccessGroupOptions) SetTransactionID(transactionID string) *RemoveMembersFromAccessGroupOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *RemoveMembersFromAccessGroupOptions) SetHeaders(param map[string]string) *RemoveMembersFromAccessGroupOptions { + options.Headers = param + return options +} + +// ReplaceAccessGroupRuleOptions : The ReplaceAccessGroupRule options. +type ReplaceAccessGroupRuleOptions struct { + // The access group identifier. + AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + + // The rule to get. + RuleID *string `json:"rule_id" validate:"required,ne="` + + // The current revision number of the rule being updated. This can be found in the Get Rule response ETag header. + IfMatch *string `json:"If-Match" validate:"required"` + + // Session duration in hours. Access group membership is revoked after this time period expires. Users must log back in + // to refresh their access group membership. + Expiration *int64 `json:"expiration" validate:"required"` + + // The URL of the identity provider (IdP). + RealmName *string `json:"realm_name" validate:"required"` + + // A list of conditions that identities must satisfy to gain access group membership. + Conditions []RuleConditions `json:"conditions" validate:"required"` + + // The name of the dynaimic rule. + Name *string `json:"name,omitempty"` + + // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple + // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you + // choose. If no transaction ID is passed in, then a random ID is generated. + TransactionID *string `json:"Transaction-Id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewReplaceAccessGroupRuleOptions : Instantiate ReplaceAccessGroupRuleOptions +func (*IamAccessGroupsV2) NewReplaceAccessGroupRuleOptions(accessGroupID string, ruleID string, ifMatch string, expiration int64, realmName string, conditions []RuleConditions) *ReplaceAccessGroupRuleOptions { + return &ReplaceAccessGroupRuleOptions{ + AccessGroupID: core.StringPtr(accessGroupID), + RuleID: core.StringPtr(ruleID), + IfMatch: core.StringPtr(ifMatch), + Expiration: core.Int64Ptr(expiration), + RealmName: core.StringPtr(realmName), + Conditions: conditions, + } +} + +// SetAccessGroupID : Allow user to set AccessGroupID +func (_options *ReplaceAccessGroupRuleOptions) SetAccessGroupID(accessGroupID string) *ReplaceAccessGroupRuleOptions { + _options.AccessGroupID = core.StringPtr(accessGroupID) + return _options +} + +// SetRuleID : Allow user to set RuleID +func (_options *ReplaceAccessGroupRuleOptions) SetRuleID(ruleID string) *ReplaceAccessGroupRuleOptions { + _options.RuleID = core.StringPtr(ruleID) + return _options +} + +// SetIfMatch : Allow user to set IfMatch +func (_options *ReplaceAccessGroupRuleOptions) SetIfMatch(ifMatch string) *ReplaceAccessGroupRuleOptions { + _options.IfMatch = core.StringPtr(ifMatch) + return _options +} + +// SetExpiration : Allow user to set Expiration +func (_options *ReplaceAccessGroupRuleOptions) SetExpiration(expiration int64) *ReplaceAccessGroupRuleOptions { + _options.Expiration = core.Int64Ptr(expiration) + return _options +} + +// SetRealmName : Allow user to set RealmName +func (_options *ReplaceAccessGroupRuleOptions) SetRealmName(realmName string) *ReplaceAccessGroupRuleOptions { + _options.RealmName = core.StringPtr(realmName) + return _options +} + +// SetConditions : Allow user to set Conditions +func (_options *ReplaceAccessGroupRuleOptions) SetConditions(conditions []RuleConditions) *ReplaceAccessGroupRuleOptions { + _options.Conditions = conditions + return _options +} + +// SetName : Allow user to set Name +func (_options *ReplaceAccessGroupRuleOptions) SetName(name string) *ReplaceAccessGroupRuleOptions { + _options.Name = core.StringPtr(name) + return _options +} + +// SetTransactionID : Allow user to set TransactionID +func (_options *ReplaceAccessGroupRuleOptions) SetTransactionID(transactionID string) *ReplaceAccessGroupRuleOptions { + _options.TransactionID = core.StringPtr(transactionID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ReplaceAccessGroupRuleOptions) SetHeaders(param map[string]string) *ReplaceAccessGroupRuleOptions { + options.Headers = param + return options +} + +// ResourceListWithTargetAccountID : Object containing details of a resource list with target account ID. +type ResourceListWithTargetAccountID struct { + // The ID of the entity that the resource list applies to. + Target *string `json:"target,omitempty"` + + // Assignment Resource Access Group. + Group *AssignmentResourceAccessGroup `json:"group,omitempty"` + + // List of policy template references for the resource list. + PolicyTemplateReferences []AssignmentResourceEntry `json:"policy_template_references,omitempty"` +} + +// UnmarshalResourceListWithTargetAccountID unmarshals an instance of ResourceListWithTargetAccountID from the specified map of raw messages. +func UnmarshalResourceListWithTargetAccountID(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ResourceListWithTargetAccountID) + err = core.UnmarshalPrimitive(m, "target", &obj.Target) + if err != nil { + return + } + err = core.UnmarshalModel(m, "group", &obj.Group, UnmarshalAssignmentResourceAccessGroup) + if err != nil { + return + } + err = core.UnmarshalModel(m, "policy_template_references", &obj.PolicyTemplateReferences, UnmarshalAssignmentResourceEntry) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Rule : A dynamic rule of an access group. +type Rule struct { + // The rule id. + ID *string `json:"id,omitempty"` + + // The name of the rule. + Name *string `json:"name,omitempty"` + + // Session duration in hours. Access group membership is revoked after this time period expires. Users must log back in + // to refresh their access group membership. Must be between 1 and 24. + Expiration *int64 `json:"expiration,omitempty"` + + // The URL of the identity provider. + RealmName *string `json:"realm_name,omitempty"` + + // The group id that the dynamic rule is assigned to. + AccessGroupID *string `json:"access_group_id,omitempty"` + + // The account id that the group is in. + AccountID *string `json:"account_id,omitempty"` + + // A list of conditions that identities must satisfy to gain access group membership. + Conditions []RuleConditions `json:"conditions,omitempty"` + + // The timestamp for when the rule was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + + // The `iam_id` of the entity that created the dynamic rule. + CreatedByID *string `json:"created_by_id,omitempty"` + + // The timestamp for when the dynamic rule was last edited. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` + + // The IAM id that last modified the rule. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` +} + +// UnmarshalRule unmarshals an instance of Rule from the specified map of raw messages. +func UnmarshalRule(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Rule) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "expiration", &obj.Expiration) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "realm_name", &obj.RealmName) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "access_group_id", &obj.AccessGroupID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "conditions", &obj.Conditions, UnmarshalRuleConditions) + 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 +} + +// RuleConditions : The conditions of a dynamic rule. +type RuleConditions struct { + // The claim to evaluate against. This will be found in the `ext` claims of a user's login request. + Claim *string `json:"claim" validate:"required"` + + // The operation to perform on the claim. + Operator *string `json:"operator" validate:"required"` + + // The stringified JSON value that the claim is compared to using the operator. + Value *string `json:"value" validate:"required"` +} + +// Constants associated with the RuleConditions.Operator property. +// The operation to perform on the claim. +const ( + RuleConditionsOperatorContainsConst = "CONTAINS" + RuleConditionsOperatorEqualsConst = "EQUALS" + RuleConditionsOperatorEqualsIgnoreCaseConst = "EQUALS_IGNORE_CASE" + RuleConditionsOperatorInConst = "IN" + RuleConditionsOperatorNotEqualsConst = "NOT_EQUALS" + RuleConditionsOperatorNotEqualsIgnoreCaseConst = "NOT_EQUALS_IGNORE_CASE" +) + +// NewRuleConditions : Instantiate RuleConditions (Generic Model Constructor) +func (*IamAccessGroupsV2) NewRuleConditions(claim string, operator string, value string) (_model *RuleConditions, err error) { + _model = &RuleConditions{ + Claim: core.StringPtr(claim), + Operator: core.StringPtr(operator), + Value: core.StringPtr(value), + } + err = core.ValidateStruct(_model, "required parameters") + return +} + +// UnmarshalRuleConditions unmarshals an instance of RuleConditions from the specified map of raw messages. +func UnmarshalRuleConditions(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleConditions) + err = core.UnmarshalPrimitive(m, "claim", &obj.Claim) + 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 +} + +// RuleInput : Rule Input component. +type RuleInput struct { + // rule input name. + Name *string `json:"name,omitempty"` + + // rule input expiration. + Expiration *int64 `json:"expiration,omitempty"` + + // rule input realm name. + RealmName *string `json:"realm_name,omitempty"` + + // rule input conditions. + Conditions []ConditionInput `json:"conditions,omitempty"` + + // Control whether or not child account administrators can update and remove dynamic rules from the enterprise-managed + // access group in their account. These action controls will override outer level action controls. + ActionControls *RulesActionControls `json:"action_controls,omitempty"` +} + +// UnmarshalRuleInput unmarshals an instance of RuleInput from the specified map of raw messages. +func UnmarshalRuleInput(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RuleInput) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "expiration", &obj.Expiration) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "realm_name", &obj.RealmName) + if err != nil { + return + } + err = core.UnmarshalModel(m, "conditions", &obj.Conditions, UnmarshalConditionInput) + if err != nil { + return + } + err = core.UnmarshalModel(m, "action_controls", &obj.ActionControls, UnmarshalRulesActionControls) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RulesActionControls : Control whether or not child account administrators can update and remove dynamic rules from the enterprise-managed +// access group in their account. These action controls will override outer level action controls. +type RulesActionControls struct { + // Action control for removing enterprise-managed dynamic rule in an enterprise-managed access group. + Remove *bool `json:"remove,omitempty"` + + // Action control for updating enterprise-managed dynamic rule in an enterprise-managed access group. + Update *bool `json:"update,omitempty"` +} + +// UnmarshalRulesActionControls unmarshals an instance of RulesActionControls from the specified map of raw messages. +func UnmarshalRulesActionControls(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RulesActionControls) + err = core.UnmarshalPrimitive(m, "remove", &obj.Remove) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "update", &obj.Update) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RulesList : A list of dynamic rules attached to the access group. +type RulesList struct { + // A list of dynamic rules. + Rules []Rule `json:"rules,omitempty"` } -// SetHeaders : Allow user to set Headers -func (options *ListAccessGroupsOptions) SetHeaders(param map[string]string) *ListAccessGroupsOptions { - options.Headers = param - return options +// UnmarshalRulesList unmarshals an instance of RulesList from the specified map of raw messages. +func UnmarshalRulesList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(RulesList) + err = core.UnmarshalModel(m, "rules", &obj.Rules, UnmarshalRule) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// ListGroupMembersResponseMember : A single member of an access group in a list. -type ListGroupMembersResponseMember struct { - // The IBMid or Service Id of the member. - IamID *string `json:"iam_id,omitempty"` +// TemplateCreateAssignmentResponse : Response object containing the details of a template assignment. +type TemplateCreateAssignmentResponse struct { + // The ID of the assignment. + ID *string `json:"id" validate:"required"` - // The member type - either `user`, `service` or `profile`. - Type *string `json:"type,omitempty"` + // The ID of the account that the assignment belongs to. + AccountID *string `json:"account_id" validate:"required"` - // The membership type - either `static` or `dynamic`. - MembershipType *string `json:"membership_type,omitempty"` + // The ID of the template that the assignment is based on. + TemplateID *string `json:"template_id" validate:"required"` - // The user's or service id's name. - Name *string `json:"name,omitempty"` + // The version of the template that the assignment is based on. + TemplateVersion *string `json:"template_version" validate:"required"` - // If the member type is user, this is the user's email. - Email *string `json:"email,omitempty"` + // The type of the entity that the assignment applies to. + TargetType *string `json:"target_type" validate:"required"` - // If the member type is service, this is the service id's description. - Description *string `json:"description,omitempty"` + // The ID of the entity that the assignment applies to. + Target *string `json:"target" validate:"required"` - // A url to the given member resource. - Href *string `json:"href,omitempty"` + // The operation that the assignment applies to (e.g. 'assign', 'update', 'remove'). + Operation *string `json:"operation" validate:"required"` - // The timestamp the membership was created at. - CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + // The status of the assignment (e.g. 'accepted', 'in_progress', 'succeeded', 'failed'). + Status *string `json:"status" validate:"required"` - // The `iam_id` of the entity that created the membership. - CreatedByID *string `json:"created_by_id,omitempty"` + // The URL of the assignment resource. + Href *string `json:"href" validate:"required"` + + // The date and time when the assignment was created. + CreatedAt *strfmt.DateTime `json:"created_at" validate:"required"` + + // The user or system that created the assignment. + CreatedBy *string `json:"created_by" validate:"required"` + + // The date and time when the assignment was last updated. + UpdatedAt *strfmt.DateTime `json:"updated_at" validate:"required"` + + // The user or system that last updated the assignment. + UpdatedBy *string `json:"updated_by" validate:"required"` } -// UnmarshalListGroupMembersResponseMember unmarshals an instance of ListGroupMembersResponseMember from the specified map of raw messages. -func UnmarshalListGroupMembersResponseMember(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(ListGroupMembersResponseMember) - err = core.UnmarshalPrimitive(m, "iam_id", &obj.IamID) +// Constants associated with the TemplateCreateAssignmentResponse.TargetType property. +// The type of the entity that the assignment applies to. +const ( + TemplateCreateAssignmentResponseTargetTypeAccountConst = "Account" + TemplateCreateAssignmentResponseTargetTypeAccountgroupConst = "AccountGroup" +) + +// Constants associated with the TemplateCreateAssignmentResponse.Operation property. +// The operation that the assignment applies to (e.g. 'assign', 'update', 'remove'). +const ( + TemplateCreateAssignmentResponseOperationAssignConst = "assign" + TemplateCreateAssignmentResponseOperationRemoveConst = "remove" + TemplateCreateAssignmentResponseOperationUpdateConst = "update" +) + +// Constants associated with the TemplateCreateAssignmentResponse.Status property. +// The status of the assignment (e.g. 'accepted', 'in_progress', 'succeeded', 'failed'). +const ( + TemplateCreateAssignmentResponseStatusAcceptedConst = "accepted" + TemplateCreateAssignmentResponseStatusFailedConst = "failed" + TemplateCreateAssignmentResponseStatusInProgressConst = "in_progress" + TemplateCreateAssignmentResponseStatusSucceededConst = "succeeded" +) + +// UnmarshalTemplateCreateAssignmentResponse unmarshals an instance of TemplateCreateAssignmentResponse from the specified map of raw messages. +func UnmarshalTemplateCreateAssignmentResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(TemplateCreateAssignmentResponse) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) if err != nil { return } - err = core.UnmarshalPrimitive(m, "type", &obj.Type) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) if err != nil { return } - err = core.UnmarshalPrimitive(m, "membership_type", &obj.MembershipType) + err = core.UnmarshalPrimitive(m, "template_id", &obj.TemplateID) if err != nil { return } - err = core.UnmarshalPrimitive(m, "name", &obj.Name) + err = core.UnmarshalPrimitive(m, "template_version", &obj.TemplateVersion) if err != nil { return } - err = core.UnmarshalPrimitive(m, "email", &obj.Email) + err = core.UnmarshalPrimitive(m, "target_type", &obj.TargetType) if err != nil { return } - err = core.UnmarshalPrimitive(m, "description", &obj.Description) + err = core.UnmarshalPrimitive(m, "target", &obj.Target) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "operation", &obj.Operation) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status", &obj.Status) if err != nil { return } @@ -2934,7 +6151,15 @@ func UnmarshalListGroupMembersResponseMember(m map[string]json.RawMessage, resul if err != nil { return } - err = core.UnmarshalPrimitive(m, "created_by_id", &obj.CreatedByID) + err = core.UnmarshalPrimitive(m, "created_by", &obj.CreatedBy) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "updated_at", &obj.UpdatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "updated_by", &obj.UpdatedBy) if err != nil { return } @@ -2942,162 +6167,146 @@ func UnmarshalListGroupMembersResponseMember(m map[string]json.RawMessage, resul return } -// RemoveAccessGroupRuleOptions : The RemoveAccessGroupRule options. -type RemoveAccessGroupRuleOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` - - // The rule to get. - RuleID *string `json:"rule_id" validate:"required,ne="` - - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewRemoveAccessGroupRuleOptions : Instantiate RemoveAccessGroupRuleOptions -func (*IamAccessGroupsV2) NewRemoveAccessGroupRuleOptions(accessGroupID string, ruleID string) *RemoveAccessGroupRuleOptions { - return &RemoveAccessGroupRuleOptions{ - AccessGroupID: core.StringPtr(accessGroupID), - RuleID: core.StringPtr(ruleID), - } -} +// TemplateItem : TemplateItem struct +type TemplateItem struct { + // The ID of the template. + ID *string `json:"id" validate:"required"` -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *RemoveAccessGroupRuleOptions) SetAccessGroupID(accessGroupID string) *RemoveAccessGroupRuleOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options -} + // The name of the template. + Name *string `json:"name" validate:"required"` -// SetRuleID : Allow user to set RuleID -func (_options *RemoveAccessGroupRuleOptions) SetRuleID(ruleID string) *RemoveAccessGroupRuleOptions { - _options.RuleID = core.StringPtr(ruleID) - return _options -} + // The description of the template. + Description *string `json:"description" validate:"required"` -// SetTransactionID : Allow user to set TransactionID -func (_options *RemoveAccessGroupRuleOptions) SetTransactionID(transactionID string) *RemoveAccessGroupRuleOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options -} + // The version of the template. + Version *string `json:"version" validate:"required"` -// SetHeaders : Allow user to set Headers -func (options *RemoveAccessGroupRuleOptions) SetHeaders(param map[string]string) *RemoveAccessGroupRuleOptions { - options.Headers = param - return options -} + // The timestamp when the template was created. + CreatedAt *string `json:"created_at" validate:"required"` -// RemoveMemberFromAccessGroupOptions : The RemoveMemberFromAccessGroup options. -type RemoveMemberFromAccessGroupOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` + // The ID of the user who created the template. + CreatedByID *string `json:"created_by_id" validate:"required"` - // The IAM identifier. - IamID *string `json:"iam_id" validate:"required,ne="` + // The timestamp when the template was last modified. + LastModifiedAt *string `json:"last_modified_at" validate:"required"` - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` + // The ID of the user who last modified the template. + LastModifiedByID *string `json:"last_modified_by_id" validate:"required"` - // Allows users to set headers on API requests - Headers map[string]string + // The URL to access the template resource. + Href *string `json:"href" validate:"required"` } -// NewRemoveMemberFromAccessGroupOptions : Instantiate RemoveMemberFromAccessGroupOptions -func (*IamAccessGroupsV2) NewRemoveMemberFromAccessGroupOptions(accessGroupID string, iamID string) *RemoveMemberFromAccessGroupOptions { - return &RemoveMemberFromAccessGroupOptions{ - AccessGroupID: core.StringPtr(accessGroupID), - IamID: core.StringPtr(iamID), +// UnmarshalTemplateItem unmarshals an instance of TemplateItem from the specified map of raw messages. +func UnmarshalTemplateItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(TemplateItem) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "version", &obj.Version) + 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 } -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *RemoveMemberFromAccessGroupOptions) SetAccessGroupID(accessGroupID string) *RemoveMemberFromAccessGroupOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options -} - -// SetIamID : Allow user to set IamID -func (_options *RemoveMemberFromAccessGroupOptions) SetIamID(iamID string) *RemoveMemberFromAccessGroupOptions { - _options.IamID = core.StringPtr(iamID) - return _options -} - -// SetTransactionID : Allow user to set TransactionID -func (_options *RemoveMemberFromAccessGroupOptions) SetTransactionID(transactionID string) *RemoveMemberFromAccessGroupOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options -} +// TemplatesListAssignmentResponse : Response object containing a list of template assignments. +type TemplatesListAssignmentResponse struct { + // Maximum number of items returned in the response. + Limit *int64 `json:"limit" validate:"required"` -// SetHeaders : Allow user to set Headers -func (options *RemoveMemberFromAccessGroupOptions) SetHeaders(param map[string]string) *RemoveMemberFromAccessGroupOptions { - options.Headers = param - return options -} + // Index of the first item returned in the response. + Offset *int64 `json:"offset" validate:"required"` -// RemoveMemberFromAllAccessGroupsOptions : The RemoveMemberFromAllAccessGroups options. -type RemoveMemberFromAllAccessGroupsOptions struct { - // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the - // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the - // Authorization token. - AccountID *string `json:"account_id" validate:"required"` + // Total number of items matching the query. + TotalCount *int64 `json:"total_count" validate:"required"` - // The IAM identifier. - IamID *string `json:"iam_id" validate:"required,ne="` + // A link object. + First *HrefStruct `json:"first" validate:"required"` - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` + // A link object. + Last *HrefStruct `json:"last" validate:"required"` - // Allows users to set headers on API requests - Headers map[string]string + // List of template assignments. + Assignments []TemplateCreateAssignmentResponse `json:"assignments" validate:"required"` } -// NewRemoveMemberFromAllAccessGroupsOptions : Instantiate RemoveMemberFromAllAccessGroupsOptions -func (*IamAccessGroupsV2) NewRemoveMemberFromAllAccessGroupsOptions(accountID string, iamID string) *RemoveMemberFromAllAccessGroupsOptions { - return &RemoveMemberFromAllAccessGroupsOptions{ - AccountID: core.StringPtr(accountID), - IamID: core.StringPtr(iamID), +// UnmarshalTemplatesListAssignmentResponse unmarshals an instance of TemplatesListAssignmentResponse from the specified map of raw messages. +func UnmarshalTemplatesListAssignmentResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(TemplatesListAssignmentResponse) + err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) + if err != nil { + return } + err = core.UnmarshalPrimitive(m, "offset", &obj.Offset) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalHrefStruct) + if err != nil { + return + } + err = core.UnmarshalModel(m, "assignments", &obj.Assignments, UnmarshalTemplateCreateAssignmentResponse) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return } -// SetAccountID : Allow user to set AccountID -func (_options *RemoveMemberFromAllAccessGroupsOptions) SetAccountID(accountID string) *RemoveMemberFromAllAccessGroupsOptions { - _options.AccountID = core.StringPtr(accountID) - return _options -} - -// SetIamID : Allow user to set IamID -func (_options *RemoveMemberFromAllAccessGroupsOptions) SetIamID(iamID string) *RemoveMemberFromAllAccessGroupsOptions { - _options.IamID = core.StringPtr(iamID) - return _options -} - -// SetTransactionID : Allow user to set TransactionID -func (_options *RemoveMemberFromAllAccessGroupsOptions) SetTransactionID(transactionID string) *RemoveMemberFromAllAccessGroupsOptions { - _options.TransactionID = core.StringPtr(transactionID) - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *RemoveMemberFromAllAccessGroupsOptions) SetHeaders(param map[string]string) *RemoveMemberFromAllAccessGroupsOptions { - options.Headers = param - return options -} - -// RemoveMembersFromAccessGroupOptions : The RemoveMembersFromAccessGroup options. -type RemoveMembersFromAccessGroupOptions struct { +// UpdateAccessGroupOptions : The UpdateAccessGroup options. +type UpdateAccessGroupOptions struct { // The access group identifier. AccessGroupID *string `json:"access_group_id" validate:"required,ne="` - // The `iam_id`s to remove from the access group. This field has a limit of 50 `iam_id`s. - Members []string `json:"members,omitempty"` + // The current revision number of the group being updated. This can be found in the Create/Get access group response + // ETag header. + IfMatch *string `json:"If-Match" validate:"required"` + + // Give the access group a unique name that doesn't conflict with an existing access group in the account. This field + // is case-insensitive and has a limit of 100 characters. + Name *string `json:"name,omitempty"` + + // Assign an optional description for the access group. This field has a limit of 250 characters. + Description *string `json:"description,omitempty"` // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you @@ -3108,59 +6317,60 @@ type RemoveMembersFromAccessGroupOptions struct { Headers map[string]string } -// NewRemoveMembersFromAccessGroupOptions : Instantiate RemoveMembersFromAccessGroupOptions -func (*IamAccessGroupsV2) NewRemoveMembersFromAccessGroupOptions(accessGroupID string) *RemoveMembersFromAccessGroupOptions { - return &RemoveMembersFromAccessGroupOptions{ +// NewUpdateAccessGroupOptions : Instantiate UpdateAccessGroupOptions +func (*IamAccessGroupsV2) NewUpdateAccessGroupOptions(accessGroupID string, ifMatch string) *UpdateAccessGroupOptions { + return &UpdateAccessGroupOptions{ AccessGroupID: core.StringPtr(accessGroupID), + IfMatch: core.StringPtr(ifMatch), } } // SetAccessGroupID : Allow user to set AccessGroupID -func (_options *RemoveMembersFromAccessGroupOptions) SetAccessGroupID(accessGroupID string) *RemoveMembersFromAccessGroupOptions { +func (_options *UpdateAccessGroupOptions) SetAccessGroupID(accessGroupID string) *UpdateAccessGroupOptions { _options.AccessGroupID = core.StringPtr(accessGroupID) return _options } -// SetMembers : Allow user to set Members -func (_options *RemoveMembersFromAccessGroupOptions) SetMembers(members []string) *RemoveMembersFromAccessGroupOptions { - _options.Members = members +// SetIfMatch : Allow user to set IfMatch +func (_options *UpdateAccessGroupOptions) SetIfMatch(ifMatch string) *UpdateAccessGroupOptions { + _options.IfMatch = core.StringPtr(ifMatch) + return _options +} + +// SetName : Allow user to set Name +func (_options *UpdateAccessGroupOptions) SetName(name string) *UpdateAccessGroupOptions { + _options.Name = core.StringPtr(name) + return _options +} + +// SetDescription : Allow user to set Description +func (_options *UpdateAccessGroupOptions) SetDescription(description string) *UpdateAccessGroupOptions { + _options.Description = core.StringPtr(description) return _options } // SetTransactionID : Allow user to set TransactionID -func (_options *RemoveMembersFromAccessGroupOptions) SetTransactionID(transactionID string) *RemoveMembersFromAccessGroupOptions { +func (_options *UpdateAccessGroupOptions) SetTransactionID(transactionID string) *UpdateAccessGroupOptions { _options.TransactionID = core.StringPtr(transactionID) return _options } // SetHeaders : Allow user to set Headers -func (options *RemoveMembersFromAccessGroupOptions) SetHeaders(param map[string]string) *RemoveMembersFromAccessGroupOptions { +func (options *UpdateAccessGroupOptions) SetHeaders(param map[string]string) *UpdateAccessGroupOptions { options.Headers = param return options } -// ReplaceAccessGroupRuleOptions : The ReplaceAccessGroupRule options. -type ReplaceAccessGroupRuleOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` - - // The rule to get. - RuleID *string `json:"rule_id" validate:"required,ne="` - - // The current revision number of the rule being updated. This can be found in the Get Rule response ETag header. - IfMatch *string `json:"If-Match" validate:"required"` - - // The number of hours that the rule lives for. - Expiration *int64 `json:"expiration" validate:"required"` - - // The url of the identity provider. - RealmName *string `json:"realm_name" validate:"required"` - - // A list of conditions the rule must satisfy. - Conditions []RuleConditions `json:"conditions" validate:"required"` +// UpdateAccountSettingsOptions : The UpdateAccountSettings options. +type UpdateAccountSettingsOptions struct { + // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the + // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the + // Authorization token. + AccountID *string `json:"account_id" validate:"required"` - // The name of the rule. - Name *string `json:"name,omitempty"` + // This flag controls the public access feature within the account. It is set to true by default. Note: When this flag + // is set to false, all policies within the account attached to the Public Access group will be deleted. + PublicAccessEnabled *bool `json:"public_access_enabled,omitempty"` // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you @@ -3171,345 +6381,256 @@ type ReplaceAccessGroupRuleOptions struct { Headers map[string]string } -// NewReplaceAccessGroupRuleOptions : Instantiate ReplaceAccessGroupRuleOptions -func (*IamAccessGroupsV2) NewReplaceAccessGroupRuleOptions(accessGroupID string, ruleID string, ifMatch string, expiration int64, realmName string, conditions []RuleConditions) *ReplaceAccessGroupRuleOptions { - return &ReplaceAccessGroupRuleOptions{ - AccessGroupID: core.StringPtr(accessGroupID), - RuleID: core.StringPtr(ruleID), - IfMatch: core.StringPtr(ifMatch), - Expiration: core.Int64Ptr(expiration), - RealmName: core.StringPtr(realmName), - Conditions: conditions, +// NewUpdateAccountSettingsOptions : Instantiate UpdateAccountSettingsOptions +func (*IamAccessGroupsV2) NewUpdateAccountSettingsOptions(accountID string) *UpdateAccountSettingsOptions { + return &UpdateAccountSettingsOptions{ + AccountID: core.StringPtr(accountID), } } -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *ReplaceAccessGroupRuleOptions) SetAccessGroupID(accessGroupID string) *ReplaceAccessGroupRuleOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) - return _options -} - -// SetRuleID : Allow user to set RuleID -func (_options *ReplaceAccessGroupRuleOptions) SetRuleID(ruleID string) *ReplaceAccessGroupRuleOptions { - _options.RuleID = core.StringPtr(ruleID) - return _options -} - -// SetIfMatch : Allow user to set IfMatch -func (_options *ReplaceAccessGroupRuleOptions) SetIfMatch(ifMatch string) *ReplaceAccessGroupRuleOptions { - _options.IfMatch = core.StringPtr(ifMatch) - return _options -} - -// SetExpiration : Allow user to set Expiration -func (_options *ReplaceAccessGroupRuleOptions) SetExpiration(expiration int64) *ReplaceAccessGroupRuleOptions { - _options.Expiration = core.Int64Ptr(expiration) - return _options -} - -// SetRealmName : Allow user to set RealmName -func (_options *ReplaceAccessGroupRuleOptions) SetRealmName(realmName string) *ReplaceAccessGroupRuleOptions { - _options.RealmName = core.StringPtr(realmName) - return _options -} - -// SetConditions : Allow user to set Conditions -func (_options *ReplaceAccessGroupRuleOptions) SetConditions(conditions []RuleConditions) *ReplaceAccessGroupRuleOptions { - _options.Conditions = conditions +// SetAccountID : Allow user to set AccountID +func (_options *UpdateAccountSettingsOptions) SetAccountID(accountID string) *UpdateAccountSettingsOptions { + _options.AccountID = core.StringPtr(accountID) return _options } -// SetName : Allow user to set Name -func (_options *ReplaceAccessGroupRuleOptions) SetName(name string) *ReplaceAccessGroupRuleOptions { - _options.Name = core.StringPtr(name) +// SetPublicAccessEnabled : Allow user to set PublicAccessEnabled +func (_options *UpdateAccountSettingsOptions) SetPublicAccessEnabled(publicAccessEnabled bool) *UpdateAccountSettingsOptions { + _options.PublicAccessEnabled = core.BoolPtr(publicAccessEnabled) return _options } // SetTransactionID : Allow user to set TransactionID -func (_options *ReplaceAccessGroupRuleOptions) SetTransactionID(transactionID string) *ReplaceAccessGroupRuleOptions { +func (_options *UpdateAccountSettingsOptions) SetTransactionID(transactionID string) *UpdateAccountSettingsOptions { _options.TransactionID = core.StringPtr(transactionID) return _options } // SetHeaders : Allow user to set Headers -func (options *ReplaceAccessGroupRuleOptions) SetHeaders(param map[string]string) *ReplaceAccessGroupRuleOptions { +func (options *UpdateAccountSettingsOptions) SetHeaders(param map[string]string) *UpdateAccountSettingsOptions { options.Headers = param return options } -// Rule : A rule of an access group. -type Rule struct { - // The rule id. - ID *string `json:"id,omitempty"` - - // The name of the rule. - Name *string `json:"name,omitempty"` - - // The number of hours that the rule lives for (Must be between 1 and 24). - Expiration *int64 `json:"expiration,omitempty"` - - // The url of the identity provider. - RealmName *string `json:"realm_name,omitempty"` - - // The group id that the rule is assigned to. - AccessGroupID *string `json:"access_group_id,omitempty"` - - // The account id that the group is in. - AccountID *string `json:"account_id,omitempty"` - - // A list of conditions the rule must satisfy. - Conditions []RuleConditions `json:"conditions,omitempty"` - - // The timestamp the rule was created at. - CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` - - // The `iam_id` of the entity that created the rule. - CreatedByID *string `json:"created_by_id,omitempty"` - - // The timestamp the rule was last edited at. - LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` - - // The IAM id that last modified the rule. - LastModifiedByID *string `json:"last_modified_by_id,omitempty"` -} - -// UnmarshalRule unmarshals an instance of Rule from the specified map of raw messages. -func UnmarshalRule(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Rule) - err = core.UnmarshalPrimitive(m, "id", &obj.ID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "name", &obj.Name) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "expiration", &obj.Expiration) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "realm_name", &obj.RealmName) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "access_group_id", &obj.AccessGroupID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) - if err != nil { - return - } - err = core.UnmarshalModel(m, "conditions", &obj.Conditions, UnmarshalRuleConditions) - 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 -} +// UpdateAssignmentOptions : The UpdateAssignment options. +type UpdateAssignmentOptions struct { + // ID of the Assignment Record. + AssignmentID *string `json:"assignment_id" validate:"required,ne="` -// RuleConditions : The conditions of a rule. -type RuleConditions struct { - // The claim to evaluate against. This will be found in the `ext` claims of a user's login request. - Claim *string `json:"claim" validate:"required"` + // Version of the Assignment to be updated. Specify the version that you retrieved when reading the Assignment. This + // value helps identifying parallel usage of this API. Pass * to indicate to update any version available. This might + // result in stale updates. + IfMatch *string `json:"If-Match" validate:"required"` - // The operation to perform on the claim. - Operator *string `json:"operator" validate:"required"` + // Template version which shall be applied to the assignment. + TemplateVersion *string `json:"template_version,omitempty"` - // The stringified JSON value that the claim is compared to using the operator. - Value *string `json:"value" validate:"required"` + // Allows users to set headers on API requests + Headers map[string]string } -// Constants associated with the RuleConditions.Operator property. -// The operation to perform on the claim. -const ( - RuleConditionsOperatorContainsConst = "CONTAINS" - RuleConditionsOperatorEqualsConst = "EQUALS" - RuleConditionsOperatorEqualsIgnoreCaseConst = "EQUALS_IGNORE_CASE" - RuleConditionsOperatorInConst = "IN" - RuleConditionsOperatorNotEqualsConst = "NOT_EQUALS" - RuleConditionsOperatorNotEqualsIgnoreCaseConst = "NOT_EQUALS_IGNORE_CASE" -) - -// NewRuleConditions : Instantiate RuleConditions (Generic Model Constructor) -func (*IamAccessGroupsV2) NewRuleConditions(claim string, operator string, value string) (_model *RuleConditions, err error) { - _model = &RuleConditions{ - Claim: core.StringPtr(claim), - Operator: core.StringPtr(operator), - Value: core.StringPtr(value), +// NewUpdateAssignmentOptions : Instantiate UpdateAssignmentOptions +func (*IamAccessGroupsV2) NewUpdateAssignmentOptions(assignmentID string, ifMatch string) *UpdateAssignmentOptions { + return &UpdateAssignmentOptions{ + AssignmentID: core.StringPtr(assignmentID), + IfMatch: core.StringPtr(ifMatch), } - err = core.ValidateStruct(_model, "required parameters") - return } - -// UnmarshalRuleConditions unmarshals an instance of RuleConditions from the specified map of raw messages. -func UnmarshalRuleConditions(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(RuleConditions) - err = core.UnmarshalPrimitive(m, "claim", &obj.Claim) - 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 + +// SetAssignmentID : Allow user to set AssignmentID +func (_options *UpdateAssignmentOptions) SetAssignmentID(assignmentID string) *UpdateAssignmentOptions { + _options.AssignmentID = core.StringPtr(assignmentID) + return _options } -// RulesList : A list of rules attached to the access group. -type RulesList struct { - // A list of rules. - Rules []Rule `json:"rules,omitempty"` +// SetIfMatch : Allow user to set IfMatch +func (_options *UpdateAssignmentOptions) SetIfMatch(ifMatch string) *UpdateAssignmentOptions { + _options.IfMatch = core.StringPtr(ifMatch) + return _options } -// UnmarshalRulesList unmarshals an instance of RulesList from the specified map of raw messages. -func UnmarshalRulesList(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(RulesList) - err = core.UnmarshalModel(m, "rules", &obj.Rules, UnmarshalRule) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return +// SetTemplateVersion : Allow user to set TemplateVersion +func (_options *UpdateAssignmentOptions) SetTemplateVersion(templateVersion string) *UpdateAssignmentOptions { + _options.TemplateVersion = core.StringPtr(templateVersion) + return _options } -// UpdateAccessGroupOptions : The UpdateAccessGroup options. -type UpdateAccessGroupOptions struct { - // The access group identifier. - AccessGroupID *string `json:"access_group_id" validate:"required,ne="` +// SetHeaders : Allow user to set Headers +func (options *UpdateAssignmentOptions) SetHeaders(param map[string]string) *UpdateAssignmentOptions { + options.Headers = param + return options +} - // The current revision number of the group being updated. This can be found in the Create/Get access group response - // ETag header. +// UpdateTemplateVersionOptions : The UpdateTemplateVersion options. +type UpdateTemplateVersionOptions struct { + // ID of the template. + TemplateID *string `json:"template_id" validate:"required,ne="` + + // Version number of the template. + VersionNum *string `json:"version_num" validate:"required,ne="` + + // ETag value of the template version document. IfMatch *string `json:"If-Match" validate:"required"` - // Assign the specified name to the access group. This field is case-insensitive and has a limit of 100 characters. The - // group name has to be unique within an account. + // The ID of the access group template. + ID *string `json:"id,omitempty"` + + // The name of the access group template. Name *string `json:"name,omitempty"` - // Assign an optional description for the access group. This field has a limit of 250 characters. + // The description of the access group template. Description *string `json:"description,omitempty"` - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. + // The ID of the account to which the access group template is assigned. + AccountID *string `json:"account_id,omitempty"` + + // The version of the access group template. + Version *string `json:"version,omitempty"` + + // A boolean indicating whether the access group template is committed. + Committed *bool `json:"committed,omitempty"` + + // Access Group Input Component. + Group *AccessGroupInput `json:"group,omitempty"` + + // References to policy templates assigned to the access group template. + PolicyTemplateReferences []PolicyTemplatesInput `json:"policy_template_references,omitempty"` + + // The URL of the access group template resource. + Href *string `json:"href,omitempty"` + + // The date and time when the access group template was created. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` + + // The ID of the user who created the access group template. + CreatedByID *string `json:"created_by_id,omitempty"` + + // The date and time when the access group template was last modified. + LastModifiedAt *strfmt.DateTime `json:"last_modified_at,omitempty"` + + // The ID of the user who last modified the access group template. + LastModifiedByID *string `json:"last_modified_by_id,omitempty"` + + // transaction id in header. TransactionID *string `json:"Transaction-Id,omitempty"` // Allows users to set headers on API requests Headers map[string]string } -// NewUpdateAccessGroupOptions : Instantiate UpdateAccessGroupOptions -func (*IamAccessGroupsV2) NewUpdateAccessGroupOptions(accessGroupID string, ifMatch string) *UpdateAccessGroupOptions { - return &UpdateAccessGroupOptions{ - AccessGroupID: core.StringPtr(accessGroupID), - IfMatch: core.StringPtr(ifMatch), +// NewUpdateTemplateVersionOptions : Instantiate UpdateTemplateVersionOptions +func (*IamAccessGroupsV2) NewUpdateTemplateVersionOptions(templateID string, versionNum string, ifMatch string) *UpdateTemplateVersionOptions { + return &UpdateTemplateVersionOptions{ + TemplateID: core.StringPtr(templateID), + VersionNum: core.StringPtr(versionNum), + IfMatch: core.StringPtr(ifMatch), } } -// SetAccessGroupID : Allow user to set AccessGroupID -func (_options *UpdateAccessGroupOptions) SetAccessGroupID(accessGroupID string) *UpdateAccessGroupOptions { - _options.AccessGroupID = core.StringPtr(accessGroupID) +// SetTemplateID : Allow user to set TemplateID +func (_options *UpdateTemplateVersionOptions) SetTemplateID(templateID string) *UpdateTemplateVersionOptions { + _options.TemplateID = core.StringPtr(templateID) + return _options +} + +// SetVersionNum : Allow user to set VersionNum +func (_options *UpdateTemplateVersionOptions) SetVersionNum(versionNum string) *UpdateTemplateVersionOptions { + _options.VersionNum = core.StringPtr(versionNum) return _options } // SetIfMatch : Allow user to set IfMatch -func (_options *UpdateAccessGroupOptions) SetIfMatch(ifMatch string) *UpdateAccessGroupOptions { +func (_options *UpdateTemplateVersionOptions) SetIfMatch(ifMatch string) *UpdateTemplateVersionOptions { _options.IfMatch = core.StringPtr(ifMatch) return _options } +// SetID : Allow user to set ID +func (_options *UpdateTemplateVersionOptions) SetID(id string) *UpdateTemplateVersionOptions { + _options.ID = core.StringPtr(id) + return _options +} + // SetName : Allow user to set Name -func (_options *UpdateAccessGroupOptions) SetName(name string) *UpdateAccessGroupOptions { +func (_options *UpdateTemplateVersionOptions) SetName(name string) *UpdateTemplateVersionOptions { _options.Name = core.StringPtr(name) return _options } // SetDescription : Allow user to set Description -func (_options *UpdateAccessGroupOptions) SetDescription(description string) *UpdateAccessGroupOptions { +func (_options *UpdateTemplateVersionOptions) SetDescription(description string) *UpdateTemplateVersionOptions { _options.Description = core.StringPtr(description) return _options } -// SetTransactionID : Allow user to set TransactionID -func (_options *UpdateAccessGroupOptions) SetTransactionID(transactionID string) *UpdateAccessGroupOptions { - _options.TransactionID = core.StringPtr(transactionID) +// SetAccountID : Allow user to set AccountID +func (_options *UpdateTemplateVersionOptions) SetAccountID(accountID string) *UpdateTemplateVersionOptions { + _options.AccountID = core.StringPtr(accountID) return _options } -// SetHeaders : Allow user to set Headers -func (options *UpdateAccessGroupOptions) SetHeaders(param map[string]string) *UpdateAccessGroupOptions { - options.Headers = param - return options +// SetVersion : Allow user to set Version +func (_options *UpdateTemplateVersionOptions) SetVersion(version string) *UpdateTemplateVersionOptions { + _options.Version = core.StringPtr(version) + return _options } -// UpdateAccountSettingsOptions : The UpdateAccountSettings options. -type UpdateAccountSettingsOptions struct { - // Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must match the - // account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the - // Authorization token. - AccountID *string `json:"account_id" validate:"required"` +// SetCommitted : Allow user to set Committed +func (_options *UpdateTemplateVersionOptions) SetCommitted(committed bool) *UpdateTemplateVersionOptions { + _options.Committed = core.BoolPtr(committed) + return _options +} - // This flag controls the public access feature within the account. It is set to true by default. Note: When this flag - // is set to false, all policies within the account attached to the Public Access group will be deleted. - PublicAccessEnabled *bool `json:"public_access_enabled,omitempty"` +// SetGroup : Allow user to set Group +func (_options *UpdateTemplateVersionOptions) SetGroup(group *AccessGroupInput) *UpdateTemplateVersionOptions { + _options.Group = group + return _options +} - // An optional transaction ID can be passed to your request, which can be useful for tracking calls through multiple - // services by using one identifier. The header key must be set to Transaction-Id and the value is anything that you - // choose. If no transaction ID is passed in, then a random ID is generated. - TransactionID *string `json:"Transaction-Id,omitempty"` +// SetPolicyTemplateReferences : Allow user to set PolicyTemplateReferences +func (_options *UpdateTemplateVersionOptions) SetPolicyTemplateReferences(policyTemplateReferences []PolicyTemplatesInput) *UpdateTemplateVersionOptions { + _options.PolicyTemplateReferences = policyTemplateReferences + return _options +} - // Allows users to set headers on API requests - Headers map[string]string +// SetHref : Allow user to set Href +func (_options *UpdateTemplateVersionOptions) SetHref(href string) *UpdateTemplateVersionOptions { + _options.Href = core.StringPtr(href) + return _options } -// NewUpdateAccountSettingsOptions : Instantiate UpdateAccountSettingsOptions -func (*IamAccessGroupsV2) NewUpdateAccountSettingsOptions(accountID string) *UpdateAccountSettingsOptions { - return &UpdateAccountSettingsOptions{ - AccountID: core.StringPtr(accountID), - } +// SetCreatedAt : Allow user to set CreatedAt +func (_options *UpdateTemplateVersionOptions) SetCreatedAt(createdAt *strfmt.DateTime) *UpdateTemplateVersionOptions { + _options.CreatedAt = createdAt + return _options } -// SetAccountID : Allow user to set AccountID -func (_options *UpdateAccountSettingsOptions) SetAccountID(accountID string) *UpdateAccountSettingsOptions { - _options.AccountID = core.StringPtr(accountID) +// SetCreatedByID : Allow user to set CreatedByID +func (_options *UpdateTemplateVersionOptions) SetCreatedByID(createdByID string) *UpdateTemplateVersionOptions { + _options.CreatedByID = core.StringPtr(createdByID) return _options } -// SetPublicAccessEnabled : Allow user to set PublicAccessEnabled -func (_options *UpdateAccountSettingsOptions) SetPublicAccessEnabled(publicAccessEnabled bool) *UpdateAccountSettingsOptions { - _options.PublicAccessEnabled = core.BoolPtr(publicAccessEnabled) +// SetLastModifiedAt : Allow user to set LastModifiedAt +func (_options *UpdateTemplateVersionOptions) SetLastModifiedAt(lastModifiedAt *strfmt.DateTime) *UpdateTemplateVersionOptions { + _options.LastModifiedAt = lastModifiedAt + return _options +} + +// SetLastModifiedByID : Allow user to set LastModifiedByID +func (_options *UpdateTemplateVersionOptions) SetLastModifiedByID(lastModifiedByID string) *UpdateTemplateVersionOptions { + _options.LastModifiedByID = core.StringPtr(lastModifiedByID) return _options } // SetTransactionID : Allow user to set TransactionID -func (_options *UpdateAccountSettingsOptions) SetTransactionID(transactionID string) *UpdateAccountSettingsOptions { +func (_options *UpdateTemplateVersionOptions) SetTransactionID(transactionID string) *UpdateTemplateVersionOptions { _options.TransactionID = core.StringPtr(transactionID) return _options } // SetHeaders : Allow user to set Headers -func (options *UpdateAccountSettingsOptions) SetHeaders(param map[string]string) *UpdateAccountSettingsOptions { +func (options *UpdateTemplateVersionOptions) SetHeaders(param map[string]string) *UpdateTemplateVersionOptions { options.Headers = param return options } @@ -3518,9 +6639,9 @@ func (options *UpdateAccountSettingsOptions) SetHeaders(param map[string]string) // AccessGroupsPager can be used to simplify the use of the "ListAccessGroups" method. // type AccessGroupsPager struct { - hasNext bool - options *ListAccessGroupsOptions - client *IamAccessGroupsV2 + hasNext bool + options *ListAccessGroupsOptions + client *IamAccessGroupsV2 pageContext struct { next *int64 } @@ -3605,9 +6726,9 @@ func (pager *AccessGroupsPager) GetAll() (allItems []Group, err error) { // AccessGroupMembersPager can be used to simplify the use of the "ListAccessGroupMembers" method. // type AccessGroupMembersPager struct { - hasNext bool - options *ListAccessGroupMembersOptions - client *IamAccessGroupsV2 + hasNext bool + options *ListAccessGroupMembersOptions + client *IamAccessGroupsV2 pageContext struct { next *int64 } @@ -3687,3 +6808,177 @@ func (pager *AccessGroupMembersPager) GetNext() (page []ListGroupMembersResponse func (pager *AccessGroupMembersPager) GetAll() (allItems []ListGroupMembersResponseMember, err error) { return pager.GetAllWithContext(context.Background()) } + +// +// TemplatesPager can be used to simplify the use of the "ListTemplates" method. +// +type TemplatesPager struct { + hasNext bool + options *ListTemplatesOptions + client *IamAccessGroupsV2 + pageContext struct { + next *int64 + } +} + +// NewTemplatesPager returns a new TemplatesPager instance. +func (iamAccessGroups *IamAccessGroupsV2) NewTemplatesPager(options *ListTemplatesOptions) (pager *TemplatesPager, err error) { + if options.Offset != nil && *options.Offset != 0 { + err = fmt.Errorf("the 'options.Offset' field should not be set") + return + } + + var optionsCopy ListTemplatesOptions = *options + pager = &TemplatesPager{ + hasNext: true, + options: &optionsCopy, + client: iamAccessGroups, + } + return +} + +// HasNext returns true if there are potentially more results to be retrieved. +func (pager *TemplatesPager) HasNext() bool { + return pager.hasNext +} + +// GetNextWithContext returns the next page of results using the specified Context. +func (pager *TemplatesPager) GetNextWithContext(ctx context.Context) (page []TemplateItem, err error) { + if !pager.HasNext() { + return nil, fmt.Errorf("no more results available") + } + + pager.options.Offset = pager.pageContext.next + + result, _, err := pager.client.ListTemplatesWithContext(ctx, pager.options) + if err != nil { + return + } + + var next *int64 + if result.Next != nil { + var offset *int64 + offset, err = core.GetQueryParamAsInt(result.Next.Href, "offset") + if err != nil { + err = fmt.Errorf("error retrieving 'offset' query parameter from URL '%s': %s", *result.Next.Href, err.Error()) + return + } + next = offset + } + pager.pageContext.next = next + pager.hasNext = (pager.pageContext.next != nil) + page = result.GroupTemplates + + return +} + +// GetAllWithContext returns all results by invoking GetNextWithContext() repeatedly +// until all pages of results have been retrieved. +func (pager *TemplatesPager) GetAllWithContext(ctx context.Context) (allItems []TemplateItem, err error) { + for pager.HasNext() { + var nextPage []TemplateItem + nextPage, err = pager.GetNextWithContext(ctx) + if err != nil { + return + } + allItems = append(allItems, nextPage...) + } + return +} + +// GetNext invokes GetNextWithContext() using context.Background() as the Context parameter. +func (pager *TemplatesPager) GetNext() (page []TemplateItem, err error) { + return pager.GetNextWithContext(context.Background()) +} + +// GetAll invokes GetAllWithContext() using context.Background() as the Context parameter. +func (pager *TemplatesPager) GetAll() (allItems []TemplateItem, err error) { + return pager.GetAllWithContext(context.Background()) +} + +// +// TemplateVersionsPager can be used to simplify the use of the "ListTemplateVersions" method. +// +type TemplateVersionsPager struct { + hasNext bool + options *ListTemplateVersionsOptions + client *IamAccessGroupsV2 + pageContext struct { + next *int64 + } +} + +// NewTemplateVersionsPager returns a new TemplateVersionsPager instance. +func (iamAccessGroups *IamAccessGroupsV2) NewTemplateVersionsPager(options *ListTemplateVersionsOptions) (pager *TemplateVersionsPager, err error) { + if options.Offset != nil && *options.Offset != 0 { + err = fmt.Errorf("the 'options.Offset' field should not be set") + return + } + + var optionsCopy ListTemplateVersionsOptions = *options + pager = &TemplateVersionsPager{ + hasNext: true, + options: &optionsCopy, + client: iamAccessGroups, + } + return +} + +// HasNext returns true if there are potentially more results to be retrieved. +func (pager *TemplateVersionsPager) HasNext() bool { + return pager.hasNext +} + +// GetNextWithContext returns the next page of results using the specified Context. +func (pager *TemplateVersionsPager) GetNextWithContext(ctx context.Context) (page []ListTemplatesVersionsResponse, err error) { + if !pager.HasNext() { + return nil, fmt.Errorf("no more results available") + } + + pager.options.Offset = pager.pageContext.next + + result, _, err := pager.client.ListTemplateVersionsWithContext(ctx, pager.options) + if err != nil { + return + } + + var next *int64 + if result.Next != nil { + var offset *int64 + offset, err = core.GetQueryParamAsInt(result.Next.Href, "offset") + if err != nil { + err = fmt.Errorf("error retrieving 'offset' query parameter from URL '%s': %s", *result.Next.Href, err.Error()) + return + } + next = offset + } + pager.pageContext.next = next + pager.hasNext = (pager.pageContext.next != nil) + page = result.GroupTemplateVersions + + return +} + +// GetAllWithContext returns all results by invoking GetNextWithContext() repeatedly +// until all pages of results have been retrieved. +func (pager *TemplateVersionsPager) GetAllWithContext(ctx context.Context) (allItems []ListTemplatesVersionsResponse, err error) { + for pager.HasNext() { + var nextPage []ListTemplatesVersionsResponse + nextPage, err = pager.GetNextWithContext(ctx) + if err != nil { + return + } + allItems = append(allItems, nextPage...) + } + return +} + +// GetNext invokes GetNextWithContext() using context.Background() as the Context parameter. +func (pager *TemplateVersionsPager) GetNext() (page []ListTemplatesVersionsResponse, err error) { + return pager.GetNextWithContext(context.Background()) +} + +// GetAll invokes GetAllWithContext() using context.Background() as the Context parameter. +func (pager *TemplateVersionsPager) GetAll() (allItems []ListTemplatesVersionsResponse, err error) { + return pager.GetAllWithContext(context.Background()) +} diff --git a/iamaccessgroupsv2/iam_access_groups_v2_examples_test.go b/iamaccessgroupsv2/iam_access_groups_v2_examples_test.go index 03f79776..87140645 100644 --- a/iamaccessgroupsv2/iam_access_groups_v2_examples_test.go +++ b/iamaccessgroupsv2/iam_access_groups_v2_examples_test.go @@ -1,8 +1,7 @@ -//go:build examples // +build examples /** - * (C) Copyright IBM Corp. 2022. + * (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. @@ -23,11 +22,10 @@ import ( "encoding/json" "fmt" "os" + "time" "github.com/IBM/go-sdk-core/v5/core" "github.com/IBM/platform-services-go-sdk/iamaccessgroupsv2" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" ) // @@ -58,6 +56,13 @@ var _ = Describe(`IamAccessGroupsV2 Examples Tests`, func() { testProfileID string testClaimRuleID string testClaimRuleEtag string + testPolicyTemplateID string + testAccountGroupID string + testTemplateId string + testTemplateVersionEtag string + testTemplateLatestVersionEtag string + testAssignmentID string + testAssignmentEtag string ) var shouldSkipTest = func() { @@ -82,6 +87,8 @@ var _ = Describe(`IamAccessGroupsV2 Examples Tests`, func() { testAccountID = config["TEST_ACCOUNT_ID"] testProfileID = config["TEST_PROFILE_ID"] + testPolicyTemplateID = config["TEST_POLICY_TEMPLATE_ID"] + testAccountGroupID = config["TEST_ACCOUNT_GROUP_ID"] shouldSkipTest = func() {} }) }) @@ -592,7 +599,6 @@ var _ = Describe(`IamAccessGroupsV2 Examples Tests`, func() { Expect(accountSettings).ToNot(BeNil()) }) - It(`DeleteAccessGroup request example`, func() { // begin-delete_access_group @@ -614,5 +620,525 @@ var _ = Describe(`IamAccessGroupsV2 Examples Tests`, func() { Expect(response.StatusCode).To(Equal(204)) }) + It(`CreateTemplate request example`, func() { + fmt.Println("\nCreateTemplate() result:") + // begin-create_template + + membersActionControlsModel := &iamaccessgroupsv2.MembersActionControls{ + Add: core.BoolPtr(true), + Remove: core.BoolPtr(false), + } + + membersInputModel := &iamaccessgroupsv2.MembersInput{ + Users: []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"}, + ActionControls: membersActionControlsModel, + } + + conditionInputModel := &iamaccessgroupsv2.ConditionInput{ + Claim: core.StringPtr("blueGroup"), + Operator: core.StringPtr("CONTAINS"), + Value: core.StringPtr(`"test-bluegroup-saml"`), + } + + rulesActionControlsModel := &iamaccessgroupsv2.RulesActionControls{ + Remove: core.BoolPtr(false), + Update: core.BoolPtr(false), + } + + ruleInputModel := &iamaccessgroupsv2.RuleInput{ + Name: core.StringPtr("Manager group rule"), + Expiration: core.Int64Ptr(int64(12)), + RealmName: core.StringPtr("https://idp.example.org/SAML2"), + Conditions: []iamaccessgroupsv2.ConditionInput{*conditionInputModel}, + ActionControls: rulesActionControlsModel, + } + + assertionsActionControlsModel := &iamaccessgroupsv2.AssertionsActionControls{ + Add: core.BoolPtr(false), + Remove: core.BoolPtr(true), + Update: core.BoolPtr(true), + } + + assertionsInputModel := &iamaccessgroupsv2.AssertionsInput{ + Rules: []iamaccessgroupsv2.RuleInput{*ruleInputModel}, + ActionControls: assertionsActionControlsModel, + } + + accessActionControlsModel := &iamaccessgroupsv2.AccessActionControls{ + Add: core.BoolPtr(false), + } + + groupActionControlsModel := &iamaccessgroupsv2.GroupActionControls{ + Access: accessActionControlsModel, + } + + accessGroupInputModel := &iamaccessgroupsv2.AccessGroupInput{ + Name: core.StringPtr("IAM Admin Group"), + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Members: membersInputModel, + Assertions: assertionsInputModel, + ActionControls: groupActionControlsModel, + } + + policyTemplatesInputModel := &iamaccessgroupsv2.PolicyTemplatesInput{ + ID: &testPolicyTemplateID, + Version: core.StringPtr("1"), + } + + createTemplateOptions := iamAccessGroupsService.NewCreateTemplateOptions( + "IAM Admin Group template", + testAccountID, + ) + createTemplateOptions.SetDescription("This access group template allows admin access to all IAM platform services in the account.") + createTemplateOptions.SetGroup(accessGroupInputModel) + createTemplateOptions.SetPolicyTemplateReferences([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}) + + createTemplateResponse, response, err := iamAccessGroupsService.CreateTemplate(createTemplateOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(createTemplateResponse, "", " ") + fmt.Println(string(b)) + // end-create_template + testTemplateId = *createTemplateResponse.ID + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createTemplateResponse).ToNot(BeNil()) + }) + It(`ListTemplates request example`, func() { + fmt.Println("\nListTemplates() result:") + // begin-list_templates + listTemplatesOptions := &iamaccessgroupsv2.ListTemplatesOptions{ + AccountID: &testAccountID, + TransactionID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(50)), + Verbose: core.BoolPtr(true), + } + + pager, err := iamAccessGroupsService.NewTemplatesPager(listTemplatesOptions) + if err != nil { + panic(err) + } + + var allResults []iamaccessgroupsv2.TemplateItem + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + b, _ := json.MarshalIndent(allResults, "", " ") + fmt.Println(string(b)) + // end-list_templates + }) + It(`CreateTemplateVersion request example`, func() { + fmt.Println("\nCreateTemplateVersion() result:") + // begin-create_template_version + + membersActionControlsModel := &iamaccessgroupsv2.MembersActionControls{ + Add: core.BoolPtr(true), + Remove: core.BoolPtr(false), + } + + membersInputModel := &iamaccessgroupsv2.MembersInput{ + Users: []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"}, + ActionControls: membersActionControlsModel, + } + + conditionInputModel := &iamaccessgroupsv2.ConditionInput{ + Claim: core.StringPtr("blueGroup"), + Operator: core.StringPtr("CONTAINS"), + Value: core.StringPtr(`"test-bluegroup-saml"`), + } + + ruleInputModel := &iamaccessgroupsv2.RuleInput{ + Name: core.StringPtr("Manager group rule"), + Expiration: core.Int64Ptr(int64(12)), + RealmName: core.StringPtr("https://idp.example.org/SAML2"), + Conditions: []iamaccessgroupsv2.ConditionInput{*conditionInputModel}, + } + + assertionsActionControlsModel := &iamaccessgroupsv2.AssertionsActionControls{ + Add: core.BoolPtr(false), + } + + assertionsInputModel := &iamaccessgroupsv2.AssertionsInput{ + Rules: []iamaccessgroupsv2.RuleInput{*ruleInputModel}, + ActionControls: assertionsActionControlsModel, + } + + accessActionControlsModel := &iamaccessgroupsv2.AccessActionControls{ + Add: core.BoolPtr(false), + } + + groupActionControlsModel := &iamaccessgroupsv2.GroupActionControls{ + Access: accessActionControlsModel, + } + + accessGroupInputModel := &iamaccessgroupsv2.AccessGroupInput{ + Name: core.StringPtr("IAM Admin Group 8"), + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Members: membersInputModel, + Assertions: assertionsInputModel, + ActionControls: groupActionControlsModel, + } + + policyTemplatesInputModel := &iamaccessgroupsv2.PolicyTemplatesInput{ + ID: &testPolicyTemplateID, + Version: core.StringPtr("1"), + } + + createTemplateVersionOptions := iamAccessGroupsService.NewCreateTemplateVersionOptions( + testTemplateId, + ) + createTemplateVersionOptions.SetName("IAM Admin Group template 2") + createTemplateVersionOptions.SetDescription("This access group template allows admin access to all IAM platform services in the account.") + createTemplateVersionOptions.SetGroup(accessGroupInputModel) + createTemplateVersionOptions.SetPolicyTemplateReferences([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}) + + createTemplateResponse, response, err := iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(createTemplateResponse, "", " ") + fmt.Println(string(b)) + + // end-create_template_version + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createTemplateResponse).ToNot(BeNil()) + }) + It(`ListTemplateVersions request example`, func() { + fmt.Println("\nListTemplateVersions() result:") + // begin-list_template_versions + listTemplateVersionsOptions := &iamaccessgroupsv2.ListTemplateVersionsOptions{ + TemplateID: &testTemplateId, + Limit: core.Int64Ptr(int64(100)), + } + + pager, err := iamAccessGroupsService.NewTemplateVersionsPager(listTemplateVersionsOptions) + if err != nil { + panic(err) + } + + var allResults []iamaccessgroupsv2.ListTemplatesVersionsResponse + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + b, _ := json.MarshalIndent(allResults, "", " ") + fmt.Println(string(b)) + // end-list_template_versions + }) + It(`GetTemplateVersion request example`, func() { + fmt.Println("\nGetTemplateVersion() result:") + // begin-get_template_version + + getTemplateVersionOptions := iamAccessGroupsService.NewGetTemplateVersionOptions( + testTemplateId, + "2", + ) + + createTemplateResponse, response, err := iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(createTemplateResponse, "", " ") + fmt.Println(string(b)) + + // end-get_template_version + testTemplateVersionEtag = response.Headers.Get("ETag") + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(createTemplateResponse).ToNot(BeNil()) + }) + It(`UpdateTemplateVersion request example`, func() { + fmt.Println("\nUpdateTemplateVersion() result:") + // begin-update_template_version + + membersActionControlsModel := &iamaccessgroupsv2.MembersActionControls{ + Add: core.BoolPtr(true), + Remove: core.BoolPtr(false), + } + + membersInputModel := &iamaccessgroupsv2.MembersInput{ + Users: []string{"IBMid-665000T8WY"}, + ActionControls: membersActionControlsModel, + } + + conditionInputModel := &iamaccessgroupsv2.ConditionInput{ + Claim: core.StringPtr("blueGroup"), + Operator: core.StringPtr("CONTAINS"), + Value: core.StringPtr(`"test-bluegroup-saml"`), + } + + rulesActionControlsModel := &iamaccessgroupsv2.RulesActionControls{ + Remove: core.BoolPtr(false), + Update: core.BoolPtr(false), + } + + ruleInputModel := &iamaccessgroupsv2.RuleInput{ + Name: core.StringPtr("Manager group rule"), + Expiration: core.Int64Ptr(int64(12)), + RealmName: core.StringPtr("https://idp.example.org/SAML2"), + Conditions: []iamaccessgroupsv2.ConditionInput{*conditionInputModel}, + ActionControls: rulesActionControlsModel, + } + + assertionsActionControlsModel := &iamaccessgroupsv2.AssertionsActionControls{ + Add: core.BoolPtr(false), + } + + assertionsInputModel := &iamaccessgroupsv2.AssertionsInput{ + Rules: []iamaccessgroupsv2.RuleInput{*ruleInputModel}, + ActionControls: assertionsActionControlsModel, + } + + accessActionControlsModel := &iamaccessgroupsv2.AccessActionControls{ + Add: core.BoolPtr(false), + } + + groupActionControlsModel := &iamaccessgroupsv2.GroupActionControls{ + Access: accessActionControlsModel, + } + + accessGroupInputModel := &iamaccessgroupsv2.AccessGroupInput{ + Name: core.StringPtr("IAM Admin Group 8"), + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Members: membersInputModel, + Assertions: assertionsInputModel, + ActionControls: groupActionControlsModel, + } + + policyTemplatesInputModel := &iamaccessgroupsv2.PolicyTemplatesInput{ + ID: &testPolicyTemplateID, + Version: core.StringPtr("1"), + } + + updateTemplateVersionOptions := iamAccessGroupsService.NewUpdateTemplateVersionOptions( + testTemplateId, + "2", + testTemplateVersionEtag, + ) + updateTemplateVersionOptions.SetName("IAM Admin Group template 2") + updateTemplateVersionOptions.SetDescription("This access group template allows admin access to all IAM platform services in the account.") + updateTemplateVersionOptions.SetGroup(accessGroupInputModel) + updateTemplateVersionOptions.SetPolicyTemplateReferences([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}) + updateTemplateVersionOptions.SetTransactionID("83adf5bd-de790caa3") + + createTemplateResponse, response, err := iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(createTemplateResponse, "", " ") + fmt.Println(string(b)) + + // end-update_template_version + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createTemplateResponse).ToNot(BeNil()) + }) + It(`GetLatestTemplateVersion request example`, func() { + fmt.Println("\nGetLatestTemplateVersion() result:") + // begin-get_latest_template_version + + getLatestTemplateVersionOptions := iamAccessGroupsService.NewGetLatestTemplateVersionOptions( + testTemplateId, + ) + + createTemplateResponse, response, err := iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(createTemplateResponse, "", " ") + fmt.Println(string(b)) + + // end-get_latest_template_version + testTemplateLatestVersionEtag = response.Headers.Get("ETag") + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(createTemplateResponse).ToNot(BeNil()) + }) + It(`CommitTemplate request example`, func() { + // begin-commit_template + + commitTemplateOptions := iamAccessGroupsService.NewCommitTemplateOptions( + testTemplateId, + "2", + testTemplateLatestVersionEtag, + ) + + response, err := iamAccessGroupsService.CommitTemplate(commitTemplateOptions) + if err != nil { + panic(err) + } + if response.StatusCode != 204 { + fmt.Printf("\nUnexpected response status code received from CommitTemplate(): %d\n", response.StatusCode) + } + + // end-commit_template + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + It(`CreateAssignment request example`, func() { + fmt.Println("\nCreateAssignment() result:") + // begin-create_assignment + + createAssignmentOptions := iamAccessGroupsService.NewCreateAssignmentOptions( + testTemplateId, + "2", + "AccountGroup", + testAccountGroupID, + ) + + templateCreateAssignmentResponse, response, err := iamAccessGroupsService.CreateAssignment(createAssignmentOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(templateCreateAssignmentResponse, "", " ") + fmt.Println(string(b)) + + // end-create_assignment + time.Sleep(60 * time.Second) + testAssignmentID = *templateCreateAssignmentResponse.ID + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(202)) + Expect(templateCreateAssignmentResponse).ToNot(BeNil()) + }) + It(`ListAssignments request example`, func() { + fmt.Println("\nListAssignments() result:") + // begin-list_assignments + + listAssignmentsOptions := iamAccessGroupsService.NewListAssignmentsOptions() + listAssignmentsOptions.SetAccountID(testAccountID) + + templatesListAssignmentResponse, response, err := iamAccessGroupsService.ListAssignments(listAssignmentsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(templatesListAssignmentResponse, "", " ") + fmt.Println(string(b)) + + // end-list_assignments + time.Sleep(60 * time.Second) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(templatesListAssignmentResponse).ToNot(BeNil()) + }) + It(`GetAssignment request example`, func() { + fmt.Println("\nGetAssignment() result:") + // begin-get_assignment + + getAssignmentOptions := iamAccessGroupsService.NewGetAssignmentOptions( + testAssignmentID, + ) + + getTemplateAssignmentResponse, response, err := iamAccessGroupsService.GetAssignment(getAssignmentOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(getTemplateAssignmentResponse, "", " ") + fmt.Println(string(b)) + + // end-get_assignment + testAssignmentEtag = response.Headers.Get("ETag") + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(getTemplateAssignmentResponse).ToNot(BeNil()) + }) + + It(`UpdateAssignment request example`, func() { + fmt.Println("\nUpdateAssignment() result:") + // begin-update_assignment + + updateAssignmentOptions := iamAccessGroupsService.NewUpdateAssignmentOptions( + testAssignmentID, + testAssignmentEtag, + ) + updateAssignmentOptions.SetTemplateVersion("2") + + getTemplateAssignmentResponse, response, err := iamAccessGroupsService.UpdateAssignment(updateAssignmentOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(getTemplateAssignmentResponse, "", " ") + fmt.Println(string(b)) + + // end-update_assignment + time.Sleep(90 * time.Second) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(202)) + Expect(getTemplateAssignmentResponse).ToNot(BeNil()) + }) + It(`DeleteAssignment request example`, func() { + // begin-delete_assignment + + deleteAssignmentOptions := iamAccessGroupsService.NewDeleteAssignmentOptions( + testAssignmentID, + ) + + response, err := iamAccessGroupsService.DeleteAssignment(deleteAssignmentOptions) + if err != nil { + panic(err) + } + if response.StatusCode != 202 { + fmt.Printf("\nUnexpected response status code received from DeleteAssignment(): %d\n", response.StatusCode) + } + + // end-delete_assignment + time.Sleep(90 * time.Second) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(202)) + }) + It(`DeleteTemplateVersion request example`, func() { + // begin-delete_template_version + + deleteTemplateVersionOptions := iamAccessGroupsService.NewDeleteTemplateVersionOptions( + testTemplateId, + "1", + ) + + response, err := iamAccessGroupsService.DeleteTemplateVersion(deleteTemplateVersionOptions) + if err != nil { + panic(err) + } + if response.StatusCode != 204 { + fmt.Printf("\nUnexpected response status code received from DeleteTemplateVersion(): %d\n", response.StatusCode) + } + + // end-delete_template_version + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + It(`DeleteTemplate request example`, func() { + // begin-delete_template + + deleteTemplateOptions := iamAccessGroupsService.NewDeleteTemplateOptions( + testTemplateId, + ) + + response, err := iamAccessGroupsService.DeleteTemplate(deleteTemplateOptions) + if err != nil { + panic(err) + } + if response.StatusCode != 204 { + fmt.Printf("\nUnexpected response status code received from DeleteTemplate(): %d\n", response.StatusCode) + } + + // end-delete_template + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) }) diff --git a/iamaccessgroupsv2/iam_access_groups_v2_integration_test.go b/iamaccessgroupsv2/iam_access_groups_v2_integration_test.go index dde62ad9..6a915990 100644 --- a/iamaccessgroupsv2/iam_access_groups_v2_integration_test.go +++ b/iamaccessgroupsv2/iam_access_groups_v2_integration_test.go @@ -1,8 +1,7 @@ -//go:build integration // +build integration /** - * (C) Copyright IBM Corp. 2020, 2022. + * (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. @@ -27,9 +26,6 @@ import ( "strconv" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/IBM/go-sdk-core/v5/core" "github.com/IBM/platform-services-go-sdk/iamaccessgroupsv2" ) @@ -43,15 +39,22 @@ var _ = Describe("IAM Access Groups - Integration Tests", func() { config map[string]string configLoaded bool = false - testAccountID string - testGroupName string = "SDK Test Group - Golang" - testGroupDescription string = "This group is used for integration test purposes. It can be deleted at any time." - testGroupEtag string - testGroupID string - testUserID string = "IBMid-" + strconv.Itoa(rand.Intn(100000)) - testClaimRuleID string + testAccountID string + testGroupName string = "SDK Test Group - Golang" + testGroupDescription string = "This group is used for integration test purposes. It can be deleted at any time." + testGroupEtag string + testGroupID string + testUserID string = "IBMid-" + strconv.Itoa(rand.Intn(100000)) + testClaimRuleID string testClaimRuleEtag string testAccountSettings *iamaccessgroupsv2.AccountSettings + testPolicyTemplateID string + testTemplateID string + testTemplateEtag string + testLatestVersionETag string + testAccountGroupID string + testAssignmentID string + testAssignmentEtag string userType string = "user" etagHeader string = "Etag" @@ -72,6 +75,8 @@ var _ = Describe("IAM Access Groups - Integration Tests", func() { config, err = core.GetServiceProperties(iamaccessgroupsv2.DefaultServiceName) if err == nil { testAccountID = config["TEST_ACCOUNT_ID"] + testPolicyTemplateID = config["TEST_POLICY_TEMPLATE_ID"] + testAccountGroupID = config["TEST_ACCOUNT_GROUP_ID"] if testAccountID != "" { configLoaded = true } @@ -485,4 +490,568 @@ var _ = Describe("IAM Access Groups - Integration Tests", func() { } } }) + + Describe(`CreateTemplate - Create Template`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CreateTemplate(createTemplateOptions *CreateTemplateOptions)`, func() { + membersActionControlsModel := &iamaccessgroupsv2.MembersActionControls{ + Add: core.BoolPtr(true), + Remove: core.BoolPtr(false), + } + + membersInputModel := &iamaccessgroupsv2.MembersInput{ + Users: []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"}, + ActionControls: membersActionControlsModel, + } + + conditionInputModel := &iamaccessgroupsv2.ConditionInput{ + Claim: core.StringPtr("blueGroup"), + Operator: core.StringPtr("CONTAINS"), + Value: core.StringPtr("\"test-bluegroup-saml\""), + } + + rulesActionControlsModel := &iamaccessgroupsv2.RulesActionControls{ + Remove: core.BoolPtr(false), + Update: core.BoolPtr(false), + } + + ruleInputModel := &iamaccessgroupsv2.RuleInput{ + Name: core.StringPtr("Manager group rule"), + Expiration: core.Int64Ptr(int64(12)), + RealmName: core.StringPtr("https://idp.example.org/SAML2"), + Conditions: []iamaccessgroupsv2.ConditionInput{*conditionInputModel}, + ActionControls: rulesActionControlsModel, + } + + assertionsActionControlsModel := &iamaccessgroupsv2.AssertionsActionControls{ + Add: core.BoolPtr(false), + Remove: core.BoolPtr(true), + Update: core.BoolPtr(true), + } + + assertionsInputModel := &iamaccessgroupsv2.AssertionsInput{ + Rules: []iamaccessgroupsv2.RuleInput{*ruleInputModel}, + ActionControls: assertionsActionControlsModel, + } + + accessActionControlsModel := &iamaccessgroupsv2.AccessActionControls{ + Add: core.BoolPtr(false), + } + + groupActionControlsModel := &iamaccessgroupsv2.GroupActionControls{ + Access: accessActionControlsModel, + } + + accessGroupInputModel := &iamaccessgroupsv2.AccessGroupInput{ + Name: core.StringPtr("IAM Admin Group"), + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Members: membersInputModel, + Assertions: assertionsInputModel, + ActionControls: groupActionControlsModel, + } + + policyTemplatesInputModel := &iamaccessgroupsv2.PolicyTemplatesInput{ + ID: &testPolicyTemplateID, + Version: core.StringPtr("1"), + } + + createTemplateOptions := &iamaccessgroupsv2.CreateTemplateOptions{ + Name: core.StringPtr("IAM Admin Group template"), + AccountID: &testAccountID, + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Group: accessGroupInputModel, + PolicyTemplateReferences: []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}, + TransactionID: core.StringPtr("testString"), + } + + createTemplateResponse, response, err := iamAccessGroupsService.CreateTemplate(createTemplateOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createTemplateResponse).ToNot(BeNil()) + testTemplateID = *createTemplateResponse.ID + }) + }) + + Describe(`ListTemplates - List Templates`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListTemplates(listTemplatesOptions *ListTemplatesOptions) with pagination`, func(){ + listTemplatesOptions := &iamaccessgroupsv2.ListTemplatesOptions{ + AccountID: &testAccountID, + TransactionID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(50)), + Offset: core.Int64Ptr(int64(0)), + Verbose: core.BoolPtr(true), + } + + listTemplatesOptions.Offset = nil + listTemplatesOptions.Limit = core.Int64Ptr(1) + + var allResults []iamaccessgroupsv2.TemplateItem + for { + listTemplatesResponse, response, err := iamAccessGroupsService.ListTemplates(listTemplatesOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(listTemplatesResponse).ToNot(BeNil()) + allResults = append(allResults, listTemplatesResponse.GroupTemplates...) + + listTemplatesOptions.Offset, err = listTemplatesResponse.GetNextOffset() + Expect(err).To(BeNil()) + + if listTemplatesOptions.Offset == nil { + break + } + } + fmt.Fprintf(GinkgoWriter, "Retrieved a total of %d item(s) with pagination.\n", len(allResults)) + }) + It(`ListTemplates(listTemplatesOptions *ListTemplatesOptions) using TemplatesPager`, func(){ + listTemplatesOptions := &iamaccessgroupsv2.ListTemplatesOptions{ + AccountID: &testAccountID, + TransactionID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(50)), + Verbose: core.BoolPtr(true), + } + + // Test GetNext(). + pager, err := iamAccessGroupsService.NewTemplatesPager(listTemplatesOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []iamaccessgroupsv2.TemplateItem + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = iamAccessGroupsService.NewTemplatesPager(listTemplatesOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allItems, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allItems).ToNot(BeNil()) + + Expect(len(allItems)).To(Equal(len(allResults))) + fmt.Fprintf(GinkgoWriter, "ListTemplates() returned a total of %d item(s) using TemplatesPager.\n", len(allResults)) + }) + }) + + Describe(`CreateTemplateVersion - Create template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CreateTemplateVersion(createTemplateVersionOptions *CreateTemplateVersionOptions)`, func() { + membersActionControlsModel := &iamaccessgroupsv2.MembersActionControls{ + Add: core.BoolPtr(true), + Remove: core.BoolPtr(false), + } + + membersInputModel := &iamaccessgroupsv2.MembersInput{ + Users: []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"}, + ActionControls: membersActionControlsModel, + } + + conditionInputModel := &iamaccessgroupsv2.ConditionInput{ + Claim: core.StringPtr("blueGroup"), + Operator: core.StringPtr("CONTAINS"), + Value: core.StringPtr("\"test-bluegroup-saml\""), + } + + rulesActionControlsModel := &iamaccessgroupsv2.RulesActionControls{ + Remove: core.BoolPtr(true), + Update: core.BoolPtr(true), + } + + ruleInputModel := &iamaccessgroupsv2.RuleInput{ + Name: core.StringPtr("Manager group rule"), + Expiration: core.Int64Ptr(int64(12)), + RealmName: core.StringPtr("https://idp.example.org/SAML2"), + Conditions: []iamaccessgroupsv2.ConditionInput{*conditionInputModel}, + ActionControls: rulesActionControlsModel, + } + + assertionsActionControlsModel := &iamaccessgroupsv2.AssertionsActionControls{ + Add: core.BoolPtr(false), + Remove: core.BoolPtr(true), + Update: core.BoolPtr(true), + } + + assertionsInputModel := &iamaccessgroupsv2.AssertionsInput{ + Rules: []iamaccessgroupsv2.RuleInput{*ruleInputModel}, + ActionControls: assertionsActionControlsModel, + } + + accessActionControlsModel := &iamaccessgroupsv2.AccessActionControls{ + Add: core.BoolPtr(false), + } + + groupActionControlsModel := &iamaccessgroupsv2.GroupActionControls{ + Access: accessActionControlsModel, + } + + accessGroupInputModel := &iamaccessgroupsv2.AccessGroupInput{ + Name: core.StringPtr("IAM Admin Group 8"), + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Members: membersInputModel, + Assertions: assertionsInputModel, + ActionControls: groupActionControlsModel, + } + + policyTemplatesInputModel := &iamaccessgroupsv2.PolicyTemplatesInput{ + ID: &testPolicyTemplateID, + Version: core.StringPtr("1"), + } + + createTemplateVersionOptions := &iamaccessgroupsv2.CreateTemplateVersionOptions{ + TemplateID: &testTemplateID, + Name: core.StringPtr("IAM Admin Group template 2"), + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Group: accessGroupInputModel, + PolicyTemplateReferences: []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}, + TransactionID: core.StringPtr("testString"), + } + + createTemplateResponse, response, err := iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createTemplateResponse).ToNot(BeNil()) + }) + }) + + Describe(`ListTemplateVersions - List template versions`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListTemplateVersions(listTemplateVersionsOptions *ListTemplateVersionsOptions) with pagination`, func(){ + listTemplateVersionsOptions := &iamaccessgroupsv2.ListTemplateVersionsOptions{ + TemplateID: &testTemplateID, + Limit: core.Int64Ptr(int64(100)), + Offset: core.Int64Ptr(int64(0)), + } + + listTemplateVersionsOptions.Offset = nil + listTemplateVersionsOptions.Limit = core.Int64Ptr(1) + + var allResults []iamaccessgroupsv2.ListTemplatesVersionsResponse + for { + listTemplateVersionsResponse, response, err := iamAccessGroupsService.ListTemplateVersions(listTemplateVersionsOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(listTemplateVersionsResponse).ToNot(BeNil()) + allResults = append(allResults, listTemplateVersionsResponse.GroupTemplateVersions...) + + listTemplateVersionsOptions.Offset, err = listTemplateVersionsResponse.GetNextOffset() + Expect(err).To(BeNil()) + + if listTemplateVersionsOptions.Offset == nil { + break + } + } + fmt.Fprintf(GinkgoWriter, "Retrieved a total of %d item(s) with pagination.\n", len(allResults)) + }) + It(`ListTemplateVersions(listTemplateVersionsOptions *ListTemplateVersionsOptions) using TemplateVersionsPager`, func(){ + listTemplateVersionsOptions := &iamaccessgroupsv2.ListTemplateVersionsOptions{ + TemplateID: &testTemplateID, + Limit: core.Int64Ptr(int64(100)), + } + + // Test GetNext(). + pager, err := iamAccessGroupsService.NewTemplateVersionsPager(listTemplateVersionsOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []iamaccessgroupsv2.ListTemplatesVersionsResponse + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = iamAccessGroupsService.NewTemplateVersionsPager(listTemplateVersionsOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allItems, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allItems).ToNot(BeNil()) + + Expect(len(allItems)).To(Equal(len(allResults))) + fmt.Fprintf(GinkgoWriter, "ListTemplateVersions() returned a total of %d item(s) using TemplateVersionsPager.\n", len(allResults)) + }) + }) + + Describe(`GetTemplateVersion - Get template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetTemplateVersion(getTemplateVersionOptions *GetTemplateVersionOptions)`, func() { + getTemplateVersionOptions := &iamaccessgroupsv2.GetTemplateVersionOptions{ + TemplateID: &testTemplateID, + VersionNum: core.StringPtr("1"), + TransactionID: core.StringPtr("testString"), + } + + createTemplateResponse, response, err := iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(createTemplateResponse).ToNot(BeNil()) + testTemplateEtag = response.GetHeaders().Get(etagHeader) + + }) + }) + + Describe(`UpdateTemplateVersion - Update template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`UpdateTemplateVersion(updateTemplateVersionOptions *UpdateTemplateVersionOptions)`, func() { + membersActionControlsModel := &iamaccessgroupsv2.MembersActionControls{ + Add: core.BoolPtr(true), + Remove: core.BoolPtr(false), + } + + membersInputModel := &iamaccessgroupsv2.MembersInput{ + Users: []string{"IBMid-665000T8WY"}, + ActionControls: membersActionControlsModel, + } + + conditionInputModel := &iamaccessgroupsv2.ConditionInput{ + Claim: core.StringPtr("blueGroup"), + Operator: core.StringPtr("CONTAINS"), + Value: core.StringPtr("\"test-bluegroup-saml\""), + } + + rulesActionControlsModel := &iamaccessgroupsv2.RulesActionControls{ + Remove: core.BoolPtr(false), + Update: core.BoolPtr(false), + } + + ruleInputModel := &iamaccessgroupsv2.RuleInput{ + Name: core.StringPtr("Manager group rule"), + Expiration: core.Int64Ptr(int64(12)), + RealmName: core.StringPtr("https://idp.example.org/SAML2"), + Conditions: []iamaccessgroupsv2.ConditionInput{*conditionInputModel}, + ActionControls: rulesActionControlsModel, + } + + assertionsActionControlsModel := &iamaccessgroupsv2.AssertionsActionControls{ + Add: core.BoolPtr(false), + Remove: core.BoolPtr(true), + Update: core.BoolPtr(true), + } + + assertionsInputModel := &iamaccessgroupsv2.AssertionsInput{ + Rules: []iamaccessgroupsv2.RuleInput{*ruleInputModel}, + ActionControls: assertionsActionControlsModel, + } + + accessActionControlsModel := &iamaccessgroupsv2.AccessActionControls{ + Add: core.BoolPtr(false), + } + + groupActionControlsModel := &iamaccessgroupsv2.GroupActionControls{ + Access: accessActionControlsModel, + } + + accessGroupInputModel := &iamaccessgroupsv2.AccessGroupInput{ + Name: core.StringPtr("IAM Admin Group 8"), + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Members: membersInputModel, + Assertions: assertionsInputModel, + ActionControls: groupActionControlsModel, + } + + policyTemplatesInputModel := &iamaccessgroupsv2.PolicyTemplatesInput{ + ID: &testPolicyTemplateID, + Version: core.StringPtr("1"), + } + + updateTemplateVersionOptions := &iamaccessgroupsv2.UpdateTemplateVersionOptions{ + TemplateID: &testTemplateID, + IfMatch: &testTemplateEtag, + VersionNum: core.StringPtr("1"), + Name: core.StringPtr("IAM Admin Group template 2"), + Description: core.StringPtr("This access group template allows admin access to all IAM platform services in the account."), + Group: accessGroupInputModel, + PolicyTemplateReferences: []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}, + } + + createTemplateResponse, response, err := iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(createTemplateResponse).ToNot(BeNil()) + }) + }) + + Describe(`GetLatestTemplateVersion - Get latest template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetLatestTemplateVersion(getLatestTemplateVersionOptions *GetLatestTemplateVersionOptions)`, func() { + getLatestTemplateVersionOptions := &iamaccessgroupsv2.GetLatestTemplateVersionOptions{ + TemplateID: &testTemplateID, + TransactionID: core.StringPtr("testString"), + } + + createTemplateResponse, response, err := iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(createTemplateResponse).ToNot(BeNil()) + testLatestVersionETag = response.GetHeaders().Get(etagHeader) + + }) + }) + + Describe(`CommitTemplate - Commit a template`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CommitTemplate(commitTemplateOptions *CommitTemplateOptions)`, func() { + commitTemplateOptions := &iamaccessgroupsv2.CommitTemplateOptions{ + TemplateID: &testTemplateID, + VersionNum: core.StringPtr("2"), + IfMatch: &testLatestVersionETag, + TransactionID: core.StringPtr("testString"), + } + + response, err := iamAccessGroupsService.CommitTemplate(commitTemplateOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) + + Describe(`CreateAssignment - Create assignment`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CreateAssignment(createAssignmentOptions *CreateAssignmentOptions)`, func() { + createAssignmentOptions := &iamaccessgroupsv2.CreateAssignmentOptions{ + TemplateID: &testTemplateID, + TemplateVersion: core.StringPtr("2"), + TargetType: core.StringPtr("AccountGroup"), + Target: &testAccountGroupID, + TransactionID: core.StringPtr("testString"), + } + + templateCreateAssignmentResponse, response, err := iamAccessGroupsService.CreateAssignment(createAssignmentOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(202)) + Expect(templateCreateAssignmentResponse).ToNot(BeNil()) + testAssignmentID = *templateCreateAssignmentResponse.ID + time.Sleep(90 * time.Second) + + }) + }) + + Describe(`ListAssignments - List Assignments`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListAssignments(listAssignmentsOptions *ListAssignmentsOptions)`, func() { + listAssignmentsOptions := &iamaccessgroupsv2.ListAssignmentsOptions{ + AccountID: &testAccountID, + } + + templatesListAssignmentResponse, response, err := iamAccessGroupsService.ListAssignments(listAssignmentsOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(templatesListAssignmentResponse).ToNot(BeNil()) + }) + }) + + Describe(`GetAssignment - Get assignment`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetAssignment(getAssignmentOptions *GetAssignmentOptions)`, func() { + getAssignmentOptions := &iamaccessgroupsv2.GetAssignmentOptions{ + AssignmentID: &testAssignmentID, + TransactionID: core.StringPtr("testString"), + } + + getTemplateAssignmentResponse, response, err := iamAccessGroupsService.GetAssignment(getAssignmentOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(getTemplateAssignmentResponse).ToNot(BeNil()) + testAssignmentEtag = response.GetHeaders().Get(etagHeader) + }) + }) + + Describe(`UpdateAssignment - Update Assignment`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`UpdateAssignment(updateAssignmentOptions *UpdateAssignmentOptions)`, func() { + updateAssignmentOptions := &iamaccessgroupsv2.UpdateAssignmentOptions{ + AssignmentID: &testAssignmentID, + IfMatch: &testAssignmentEtag, + TemplateVersion: core.StringPtr("2"), + } + + getTemplateAssignmentResponse, response, err := iamAccessGroupsService.UpdateAssignment(updateAssignmentOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(202)) + Expect(getTemplateAssignmentResponse).ToNot(BeNil()) + time.Sleep(90 * time.Second) + }) + }) + + Describe(`DeleteAssignment - Delete assignment`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`DeleteAssignment(deleteAssignmentOptions *DeleteAssignmentOptions)`, func() { + deleteAssignmentOptions := &iamaccessgroupsv2.DeleteAssignmentOptions{ + AssignmentID: &testAssignmentID, + TransactionID: core.StringPtr("testString"), + } + + response, err := iamAccessGroupsService.DeleteAssignment(deleteAssignmentOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(202)) + time.Sleep(90 * time.Second) + }) + }) + + Describe(`DeleteTemplateVersion - Delete template version`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`DeleteTemplateVersion(deleteTemplateVersionOptions *DeleteTemplateVersionOptions)`, func() { + deleteTemplateVersionOptions := &iamaccessgroupsv2.DeleteTemplateVersionOptions{ + TemplateID: &testTemplateID, + VersionNum: core.StringPtr("2"), + TransactionID: core.StringPtr("testString"), + } + + response, err := iamAccessGroupsService.DeleteTemplateVersion(deleteTemplateVersionOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) + + Describe(`DeleteTemplate - Delete template`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`DeleteTemplate(deleteTemplateOptions *DeleteTemplateOptions)`, func() { + deleteTemplateOptions := &iamaccessgroupsv2.DeleteTemplateOptions{ + TemplateID: &testTemplateID, + TransactionID: core.StringPtr("testString"), + } + + response, err := iamAccessGroupsService.DeleteTemplate(deleteTemplateOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + }) + }) + }) diff --git a/iamaccessgroupsv2/iam_access_groups_v2_suite_test.go b/iamaccessgroupsv2/iam_access_groups_v2_suite_test.go index ebf02554..af11f141 100644 --- a/iamaccessgroupsv2/iam_access_groups_v2_suite_test.go +++ b/iamaccessgroupsv2/iam_access_groups_v2_suite_test.go @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2022. + * (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. diff --git a/iamaccessgroupsv2/iam_access_groups_v2_test.go b/iamaccessgroupsv2/iam_access_groups_v2_test.go index d9472d81..faee8c16 100644 --- a/iamaccessgroupsv2/iam_access_groups_v2_test.go +++ b/iamaccessgroupsv2/iam_access_groups_v2_test.go @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2022. + * (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. @@ -445,9 +445,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["iam_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["search"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["membership_type"]).To(Equal([]string{"static"})) Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) - Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) Expect(req.URL.Query()["sort"]).To(Equal([]string{"name"})) // TODO: Add check for show_federated query parameter // TODO: Add check for hide_public_access query parameter @@ -469,9 +470,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") listAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupsOptionsModel.IamID = core.StringPtr("testString") + listAccessGroupsOptionsModel.Search = core.StringPtr("testString") listAccessGroupsOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupsOptionsModel.Sort = core.StringPtr("name") listAccessGroupsOptionsModel.ShowFederated = core.BoolPtr(false) listAccessGroupsOptionsModel.HidePublicAccess = core.BoolPtr(false) @@ -509,9 +511,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["iam_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["search"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["membership_type"]).To(Equal([]string{"static"})) Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) - Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) Expect(req.URL.Query()["sort"]).To(Equal([]string{"name"})) // TODO: Add check for show_federated query parameter // TODO: Add check for hide_public_access query parameter @@ -538,9 +541,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") listAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupsOptionsModel.IamID = core.StringPtr("testString") + listAccessGroupsOptionsModel.Search = core.StringPtr("testString") listAccessGroupsOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupsOptionsModel.Sort = core.StringPtr("name") listAccessGroupsOptionsModel.ShowFederated = core.BoolPtr(false) listAccessGroupsOptionsModel.HidePublicAccess = core.BoolPtr(false) @@ -584,9 +588,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["iam_id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["search"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["membership_type"]).To(Equal([]string{"static"})) Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) - Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) Expect(req.URL.Query()["sort"]).To(Equal([]string{"name"})) // TODO: Add check for show_federated query parameter // TODO: Add check for hide_public_access query parameter @@ -615,9 +620,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") listAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupsOptionsModel.IamID = core.StringPtr("testString") + listAccessGroupsOptionsModel.Search = core.StringPtr("testString") listAccessGroupsOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupsOptionsModel.Sort = core.StringPtr("name") listAccessGroupsOptionsModel.ShowFederated = core.BoolPtr(false) listAccessGroupsOptionsModel.HidePublicAccess = core.BoolPtr(false) @@ -643,9 +649,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") listAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupsOptionsModel.IamID = core.StringPtr("testString") + listAccessGroupsOptionsModel.Search = core.StringPtr("testString") listAccessGroupsOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupsOptionsModel.Sort = core.StringPtr("name") listAccessGroupsOptionsModel.ShowFederated = core.BoolPtr(false) listAccessGroupsOptionsModel.HidePublicAccess = core.BoolPtr(false) @@ -692,9 +699,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") listAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupsOptionsModel.IamID = core.StringPtr("testString") + listAccessGroupsOptionsModel.Search = core.StringPtr("testString") listAccessGroupsOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupsOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupsOptionsModel.Sort = core.StringPtr("name") listAccessGroupsOptionsModel.ShowFederated = core.BoolPtr(false) listAccessGroupsOptionsModel.HidePublicAccess = core.BoolPtr(false) @@ -786,6 +794,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { AccountID: core.StringPtr("testString"), TransactionID: core.StringPtr("testString"), IamID: core.StringPtr("testString"), + Search: core.StringPtr("testString"), MembershipType: core.StringPtr("static"), Limit: core.Int64Ptr(int64(10)), Sort: core.StringPtr("name"), @@ -818,6 +827,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { AccountID: core.StringPtr("testString"), TransactionID: core.StringPtr("testString"), IamID: core.StringPtr("testString"), + Search: core.StringPtr("testString"), MembershipType: core.StringPtr("static"), Limit: core.Int64Ptr(int64(10)), Sort: core.StringPtr("name"), @@ -1791,7 +1801,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["membership_type"]).To(Equal([]string{"static"})) Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) - Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) Expect(req.URL.Query()["type"]).To(Equal([]string{"testString"})) // TODO: Add check for verbose query parameter Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"})) @@ -1814,7 +1824,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupMembersOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupMembersOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupMembersOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupMembersOptionsModel.Type = core.StringPtr("testString") listAccessGroupMembersOptionsModel.Verbose = core.BoolPtr(false) listAccessGroupMembersOptionsModel.Sort = core.StringPtr("testString") @@ -1852,7 +1862,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["membership_type"]).To(Equal([]string{"static"})) Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) - Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) Expect(req.URL.Query()["type"]).To(Equal([]string{"testString"})) // TODO: Add check for verbose query parameter Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"})) @@ -1880,7 +1890,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupMembersOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupMembersOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupMembersOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupMembersOptionsModel.Type = core.StringPtr("testString") listAccessGroupMembersOptionsModel.Verbose = core.BoolPtr(false) listAccessGroupMembersOptionsModel.Sort = core.StringPtr("testString") @@ -1924,7 +1934,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["membership_type"]).To(Equal([]string{"static"})) Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) - Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) Expect(req.URL.Query()["type"]).To(Equal([]string{"testString"})) // TODO: Add check for verbose query parameter Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"})) @@ -1954,7 +1964,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupMembersOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupMembersOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupMembersOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupMembersOptionsModel.Type = core.StringPtr("testString") listAccessGroupMembersOptionsModel.Verbose = core.BoolPtr(false) listAccessGroupMembersOptionsModel.Sort = core.StringPtr("testString") @@ -1981,7 +1991,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupMembersOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupMembersOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupMembersOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupMembersOptionsModel.Type = core.StringPtr("testString") listAccessGroupMembersOptionsModel.Verbose = core.BoolPtr(false) listAccessGroupMembersOptionsModel.Sort = core.StringPtr("testString") @@ -2029,7 +2039,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupMembersOptionsModel.TransactionID = core.StringPtr("testString") listAccessGroupMembersOptionsModel.MembershipType = core.StringPtr("static") listAccessGroupMembersOptionsModel.Limit = core.Int64Ptr(int64(10)) - listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(38)) + listAccessGroupMembersOptionsModel.Offset = core.Int64Ptr(int64(0)) listAccessGroupMembersOptionsModel.Type = core.StringPtr("testString") listAccessGroupMembersOptionsModel.Verbose = core.BoolPtr(false) listAccessGroupMembersOptionsModel.Sort = core.StringPtr("testString") @@ -2765,7 +2775,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { addMemberToMultipleAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.IamID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Type = core.StringPtr("user") - addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"access-group-id-1"} + addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"AccessGroupId-b0d32f56-f85c-4bf1-af37-7bbd92b1b2b3"} addMemberToMultipleAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Expect response parsing to fail since we are receiving a text/plain response @@ -2839,7 +2849,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { addMemberToMultipleAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.IamID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Type = core.StringPtr("user") - addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"access-group-id-1"} + addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"AccessGroupId-b0d32f56-f85c-4bf1-af37-7bbd92b1b2b3"} addMemberToMultipleAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} @@ -2921,7 +2931,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { addMemberToMultipleAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.IamID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Type = core.StringPtr("user") - addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"access-group-id-1"} + addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"AccessGroupId-b0d32f56-f85c-4bf1-af37-7bbd92b1b2b3"} addMemberToMultipleAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} @@ -2945,7 +2955,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { addMemberToMultipleAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.IamID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Type = core.StringPtr("user") - addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"access-group-id-1"} + addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"AccessGroupId-b0d32f56-f85c-4bf1-af37-7bbd92b1b2b3"} addMemberToMultipleAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) @@ -2990,7 +3000,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { addMemberToMultipleAccessGroupsOptionsModel.AccountID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.IamID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Type = core.StringPtr("user") - addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"access-group-id-1"} + addMemberToMultipleAccessGroupsOptionsModel.Groups = []string{"AccessGroupId-b0d32f56-f85c-4bf1-af37-7bbd92b1b2b3"} addMemberToMultipleAccessGroupsOptionsModel.TransactionID = core.StringPtr("testString") addMemberToMultipleAccessGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} @@ -4647,12 +4657,4254 @@ var _ = Describe(`IamAccessGroupsV2`, func() { }) }) }) + Describe(`CreateTemplate(createTemplateOptions *CreateTemplateOptions) - Operation response error`, func() { + createTemplatePath := "/v1/group_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(createTemplatePath)) + Expect(req.Method).To(Equal("POST")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateTemplate with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateOptions model + createTemplateOptionsModel := new(iamaccessgroupsv2.CreateTemplateOptions) + createTemplateOptionsModel.Name = core.StringPtr("IAM Admin Group template") + createTemplateOptionsModel.AccountID = core.StringPtr("accountID-123") + createTemplateOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateOptionsModel.Group = accessGroupInputModel + createTemplateOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateOptionsModel.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 := iamAccessGroupsService.CreateTemplate(createTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.CreateTemplate(createTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateTemplate(createTemplateOptions *CreateTemplateOptions)`, func() { + createTemplatePath := "/v1/group_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(createTemplatePath)) + 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["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][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(201) + fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 CreateTemplate successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateOptions model + createTemplateOptionsModel := new(iamaccessgroupsv2.CreateTemplateOptions) + createTemplateOptionsModel.Name = core.StringPtr("IAM Admin Group template") + createTemplateOptionsModel.AccountID = core.StringPtr("accountID-123") + createTemplateOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateOptionsModel.Group = accessGroupInputModel + createTemplateOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateOptionsModel.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 := iamAccessGroupsService.CreateTemplateWithContext(ctx, createTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.CreateTemplate(createTemplateOptionsModel) + 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 = iamAccessGroupsService.CreateTemplateWithContext(ctx, createTemplateOptionsModel) + 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(createTemplatePath)) + 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["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 CreateTemplate successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.CreateTemplate(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateOptions model + createTemplateOptionsModel := new(iamaccessgroupsv2.CreateTemplateOptions) + createTemplateOptionsModel.Name = core.StringPtr("IAM Admin Group template") + createTemplateOptionsModel.AccountID = core.StringPtr("accountID-123") + createTemplateOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateOptionsModel.Group = accessGroupInputModel + createTemplateOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.CreateTemplate(createTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreateTemplate with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateOptions model + createTemplateOptionsModel := new(iamaccessgroupsv2.CreateTemplateOptions) + createTemplateOptionsModel.Name = core.StringPtr("IAM Admin Group template") + createTemplateOptionsModel.AccountID = core.StringPtr("accountID-123") + createTemplateOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateOptionsModel.Group = accessGroupInputModel + createTemplateOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.CreateTemplate(createTemplateOptionsModel) + 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 CreateTemplateOptions model with no property values + createTemplateOptionsModelNew := new(iamaccessgroupsv2.CreateTemplateOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.CreateTemplate(createTemplateOptionsModelNew) + 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 CreateTemplate successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateOptions model + createTemplateOptionsModel := new(iamaccessgroupsv2.CreateTemplateOptions) + createTemplateOptionsModel.Name = core.StringPtr("IAM Admin Group template") + createTemplateOptionsModel.AccountID = core.StringPtr("accountID-123") + createTemplateOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateOptionsModel.Group = accessGroupInputModel + createTemplateOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.CreateTemplate(createTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListTemplates(listTemplatesOptions *ListTemplatesOptions) - Operation response error`, func() { + listTemplatesPath := "/v1/group_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(listTemplatesPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"accountID-123"})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(50))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) + // TODO: Add check for verbose query parameter + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListTemplates with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListTemplatesOptions model + listTemplatesOptionsModel := new(iamaccessgroupsv2.ListTemplatesOptions) + listTemplatesOptionsModel.AccountID = core.StringPtr("accountID-123") + listTemplatesOptionsModel.TransactionID = core.StringPtr("testString") + listTemplatesOptionsModel.Limit = core.Int64Ptr(int64(50)) + listTemplatesOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplatesOptionsModel.Verbose = core.BoolPtr(true) + listTemplatesOptionsModel.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 := iamAccessGroupsService.ListTemplates(listTemplatesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.ListTemplates(listTemplatesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListTemplates(listTemplatesOptions *ListTemplatesOptions)`, func() { + listTemplatesPath := "/v1/group_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(listTemplatesPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"accountID-123"})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(50))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) + // TODO: Add check for verbose query parameter + // 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", `{"limit": 5, "offset": 6, "total_count": 10, "first": {"href": "Href"}, "previous": {"href": "Href"}, "next": {"href": "Href"}, "last": {"href": "Href"}, "group_templates": [{"id": "ID", "name": "Name", "description": "Description", "version": "Version", "created_at": "CreatedAt", "created_by_id": "CreatedByID", "last_modified_at": "LastModifiedAt", "last_modified_by_id": "LastModifiedByID", "href": "Href"}]}`) + })) + }) + It(`Invoke ListTemplates successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the ListTemplatesOptions model + listTemplatesOptionsModel := new(iamaccessgroupsv2.ListTemplatesOptions) + listTemplatesOptionsModel.AccountID = core.StringPtr("accountID-123") + listTemplatesOptionsModel.TransactionID = core.StringPtr("testString") + listTemplatesOptionsModel.Limit = core.Int64Ptr(int64(50)) + listTemplatesOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplatesOptionsModel.Verbose = core.BoolPtr(true) + listTemplatesOptionsModel.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 := iamAccessGroupsService.ListTemplatesWithContext(ctx, listTemplatesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.ListTemplates(listTemplatesOptionsModel) + 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 = iamAccessGroupsService.ListTemplatesWithContext(ctx, listTemplatesOptionsModel) + 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(listTemplatesPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"accountID-123"})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(50))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) + // TODO: Add check for verbose query parameter + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"limit": 5, "offset": 6, "total_count": 10, "first": {"href": "Href"}, "previous": {"href": "Href"}, "next": {"href": "Href"}, "last": {"href": "Href"}, "group_templates": [{"id": "ID", "name": "Name", "description": "Description", "version": "Version", "created_at": "CreatedAt", "created_by_id": "CreatedByID", "last_modified_at": "LastModifiedAt", "last_modified_by_id": "LastModifiedByID", "href": "Href"}]}`) + })) + }) + It(`Invoke ListTemplates successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.ListTemplates(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListTemplatesOptions model + listTemplatesOptionsModel := new(iamaccessgroupsv2.ListTemplatesOptions) + listTemplatesOptionsModel.AccountID = core.StringPtr("accountID-123") + listTemplatesOptionsModel.TransactionID = core.StringPtr("testString") + listTemplatesOptionsModel.Limit = core.Int64Ptr(int64(50)) + listTemplatesOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplatesOptionsModel.Verbose = core.BoolPtr(true) + listTemplatesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.ListTemplates(listTemplatesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListTemplates with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListTemplatesOptions model + listTemplatesOptionsModel := new(iamaccessgroupsv2.ListTemplatesOptions) + listTemplatesOptionsModel.AccountID = core.StringPtr("accountID-123") + listTemplatesOptionsModel.TransactionID = core.StringPtr("testString") + listTemplatesOptionsModel.Limit = core.Int64Ptr(int64(50)) + listTemplatesOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplatesOptionsModel.Verbose = core.BoolPtr(true) + listTemplatesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.ListTemplates(listTemplatesOptionsModel) + 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 ListTemplatesOptions model with no property values + listTemplatesOptionsModelNew := new(iamaccessgroupsv2.ListTemplatesOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.ListTemplates(listTemplatesOptionsModelNew) + 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 ListTemplates successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListTemplatesOptions model + listTemplatesOptionsModel := new(iamaccessgroupsv2.ListTemplatesOptions) + listTemplatesOptionsModel.AccountID = core.StringPtr("accountID-123") + listTemplatesOptionsModel.TransactionID = core.StringPtr("testString") + listTemplatesOptionsModel.Limit = core.Int64Ptr(int64(50)) + listTemplatesOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplatesOptionsModel.Verbose = core.BoolPtr(true) + listTemplatesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.ListTemplates(listTemplatesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Test pagination helper method on response`, func() { + It(`Invoke GetNextOffset successfully`, func() { + responseObject := new(iamaccessgroupsv2.ListTemplatesResponse) + nextObject := new(iamaccessgroupsv2.HrefStruct) + nextObject.Href = core.StringPtr("ibm.com?offset=135") + responseObject.Next = nextObject + + value, err := responseObject.GetNextOffset() + Expect(err).To(BeNil()) + Expect(value).To(Equal(core.Int64Ptr(int64(135)))) + }) + It(`Invoke GetNextOffset without a "Next" property in the response`, func() { + responseObject := new(iamaccessgroupsv2.ListTemplatesResponse) + + value, err := responseObject.GetNextOffset() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextOffset without any query params in the "Next" URL`, func() { + responseObject := new(iamaccessgroupsv2.ListTemplatesResponse) + nextObject := new(iamaccessgroupsv2.HrefStruct) + nextObject.Href = core.StringPtr("ibm.com") + responseObject.Next = nextObject + + value, err := responseObject.GetNextOffset() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextOffset with a non-integer query param in the "Next" URL`, func() { + responseObject := new(iamaccessgroupsv2.ListTemplatesResponse) + nextObject := new(iamaccessgroupsv2.HrefStruct) + nextObject.Href = core.StringPtr("ibm.com?offset=tiger") + responseObject.Next = nextObject + + value, err := responseObject.GetNextOffset() + Expect(err).NotTo(BeNil()) + Expect(value).To(BeNil()) + }) + }) + Context(`Using mock server endpoint - paginated response`, func() { + BeforeEach(func() { + var requestNumber int = 0 + 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(listTemplatesPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + requestNumber++ + if requestNumber == 1 { + fmt.Fprintf(res, "%s", `{"group_templates":[{"id":"ID","name":"Name","description":"Description","version":"Version","created_at":"CreatedAt","created_by_id":"CreatedByID","last_modified_at":"LastModifiedAt","last_modified_by_id":"LastModifiedByID","href":"Href"}],"next":{"href":"https://myhost.com/somePath?offset=1"},"total_count":2,"limit":1}`) + } else if requestNumber == 2 { + fmt.Fprintf(res, "%s", `{"group_templates":[{"id":"ID","name":"Name","description":"Description","version":"Version","created_at":"CreatedAt","created_by_id":"CreatedByID","last_modified_at":"LastModifiedAt","last_modified_by_id":"LastModifiedByID","href":"Href"}],"total_count":2,"limit":1}`) + } else { + res.WriteHeader(400) + } + })) + }) + It(`Use TemplatesPager.GetNext successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + listTemplatesOptionsModel := &iamaccessgroupsv2.ListTemplatesOptions{ + AccountID: core.StringPtr("accountID-123"), + TransactionID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(50)), + Verbose: core.BoolPtr(true), + } + + pager, err := iamAccessGroupsService.NewTemplatesPager(listTemplatesOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []iamaccessgroupsv2.TemplateItem + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + Expect(len(allResults)).To(Equal(2)) + }) + It(`Use TemplatesPager.GetAll successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + listTemplatesOptionsModel := &iamaccessgroupsv2.ListTemplatesOptions{ + AccountID: core.StringPtr("accountID-123"), + TransactionID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(50)), + Verbose: core.BoolPtr(true), + } + + pager, err := iamAccessGroupsService.NewTemplatesPager(listTemplatesOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allResults, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allResults).ToNot(BeNil()) + Expect(len(allResults)).To(Equal(2)) + }) + }) + }) + Describe(`CreateTemplateVersion(createTemplateVersionOptions *CreateTemplateVersionOptions) - Operation response error`, func() { + createTemplateVersionPath := "/v1/group_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(createTemplateVersionPath)) + Expect(req.Method).To(Equal("POST")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateTemplateVersion with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(true) + rulesActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateVersionOptions model + createTemplateVersionOptionsModel := new(iamaccessgroupsv2.CreateTemplateVersionOptions) + createTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + createTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + createTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateVersionOptionsModel.Group = accessGroupInputModel + createTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateVersionOptionsModel.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 := iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateTemplateVersion(createTemplateVersionOptions *CreateTemplateVersionOptions)`, func() { + createTemplateVersionPath := "/v1/group_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(createTemplateVersionPath)) + 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["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][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(201) + fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 CreateTemplateVersion successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(true) + rulesActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateVersionOptions model + createTemplateVersionOptionsModel := new(iamaccessgroupsv2.CreateTemplateVersionOptions) + createTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + createTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + createTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateVersionOptionsModel.Group = accessGroupInputModel + createTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateVersionOptionsModel.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 := iamAccessGroupsService.CreateTemplateVersionWithContext(ctx, createTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptionsModel) + 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 = iamAccessGroupsService.CreateTemplateVersionWithContext(ctx, createTemplateVersionOptionsModel) + 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(createTemplateVersionPath)) + 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["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 CreateTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.CreateTemplateVersion(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(true) + rulesActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateVersionOptions model + createTemplateVersionOptionsModel := new(iamaccessgroupsv2.CreateTemplateVersionOptions) + createTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + createTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + createTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateVersionOptionsModel.Group = accessGroupInputModel + createTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreateTemplateVersion with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(true) + rulesActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateVersionOptions model + createTemplateVersionOptionsModel := new(iamaccessgroupsv2.CreateTemplateVersionOptions) + createTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + createTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + createTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateVersionOptionsModel.Group = accessGroupInputModel + createTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptionsModel) + 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 CreateTemplateVersionOptions model with no property values + createTemplateVersionOptionsModelNew := new(iamaccessgroupsv2.CreateTemplateVersionOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptionsModelNew) + 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 CreateTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(true) + rulesActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the CreateTemplateVersionOptions model + createTemplateVersionOptionsModel := new(iamaccessgroupsv2.CreateTemplateVersionOptions) + createTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + createTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + createTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + createTemplateVersionOptionsModel.Group = accessGroupInputModel + createTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + createTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + createTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.CreateTemplateVersion(createTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListTemplateVersions(listTemplateVersionsOptions *ListTemplateVersionsOptions) - Operation response error`, func() { + listTemplateVersionsPath := "/v1/group_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(listTemplateVersionsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListTemplateVersions with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListTemplateVersionsOptions model + listTemplateVersionsOptionsModel := new(iamaccessgroupsv2.ListTemplateVersionsOptions) + listTemplateVersionsOptionsModel.TemplateID = core.StringPtr("testString") + listTemplateVersionsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listTemplateVersionsOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplateVersionsOptionsModel.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 := iamAccessGroupsService.ListTemplateVersions(listTemplateVersionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.ListTemplateVersions(listTemplateVersionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListTemplateVersions(listTemplateVersionsOptions *ListTemplateVersionsOptions)`, func() { + listTemplateVersionsPath := "/v1/group_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(listTemplateVersionsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) + // 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", `{"limit": 5, "offset": 6, "total_count": 10, "first": {"href": "Href"}, "previous": {"href": "Href"}, "next": {"href": "Href"}, "last": {"href": "Href"}, "group_template_versions": [{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "href": "Href", "created_at": "CreatedAt", "created_by_id": "CreatedByID", "last_modified_at": "LastModifiedAt", "last_modified_by_id": "LastModifiedByID"}]}`) + })) + }) + It(`Invoke ListTemplateVersions successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the ListTemplateVersionsOptions model + listTemplateVersionsOptionsModel := new(iamaccessgroupsv2.ListTemplateVersionsOptions) + listTemplateVersionsOptionsModel.TemplateID = core.StringPtr("testString") + listTemplateVersionsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listTemplateVersionsOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplateVersionsOptionsModel.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 := iamAccessGroupsService.ListTemplateVersionsWithContext(ctx, listTemplateVersionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.ListTemplateVersions(listTemplateVersionsOptionsModel) + 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 = iamAccessGroupsService.ListTemplateVersionsWithContext(ctx, listTemplateVersionsOptionsModel) + 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(listTemplateVersionsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(0))})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"limit": 5, "offset": 6, "total_count": 10, "first": {"href": "Href"}, "previous": {"href": "Href"}, "next": {"href": "Href"}, "last": {"href": "Href"}, "group_template_versions": [{"name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "href": "Href", "created_at": "CreatedAt", "created_by_id": "CreatedByID", "last_modified_at": "LastModifiedAt", "last_modified_by_id": "LastModifiedByID"}]}`) + })) + }) + It(`Invoke ListTemplateVersions successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.ListTemplateVersions(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListTemplateVersionsOptions model + listTemplateVersionsOptionsModel := new(iamaccessgroupsv2.ListTemplateVersionsOptions) + listTemplateVersionsOptionsModel.TemplateID = core.StringPtr("testString") + listTemplateVersionsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listTemplateVersionsOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplateVersionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.ListTemplateVersions(listTemplateVersionsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListTemplateVersions with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListTemplateVersionsOptions model + listTemplateVersionsOptionsModel := new(iamaccessgroupsv2.ListTemplateVersionsOptions) + listTemplateVersionsOptionsModel.TemplateID = core.StringPtr("testString") + listTemplateVersionsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listTemplateVersionsOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplateVersionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.ListTemplateVersions(listTemplateVersionsOptionsModel) + 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 ListTemplateVersionsOptions model with no property values + listTemplateVersionsOptionsModelNew := new(iamaccessgroupsv2.ListTemplateVersionsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.ListTemplateVersions(listTemplateVersionsOptionsModelNew) + 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 ListTemplateVersions successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListTemplateVersionsOptions model + listTemplateVersionsOptionsModel := new(iamaccessgroupsv2.ListTemplateVersionsOptions) + listTemplateVersionsOptionsModel.TemplateID = core.StringPtr("testString") + listTemplateVersionsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listTemplateVersionsOptionsModel.Offset = core.Int64Ptr(int64(0)) + listTemplateVersionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.ListTemplateVersions(listTemplateVersionsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Test pagination helper method on response`, func() { + It(`Invoke GetNextOffset successfully`, func() { + responseObject := new(iamaccessgroupsv2.ListTemplateVersionsResponse) + nextObject := new(iamaccessgroupsv2.HrefStruct) + nextObject.Href = core.StringPtr("ibm.com?offset=135") + responseObject.Next = nextObject + + value, err := responseObject.GetNextOffset() + Expect(err).To(BeNil()) + Expect(value).To(Equal(core.Int64Ptr(int64(135)))) + }) + It(`Invoke GetNextOffset without a "Next" property in the response`, func() { + responseObject := new(iamaccessgroupsv2.ListTemplateVersionsResponse) + + value, err := responseObject.GetNextOffset() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextOffset without any query params in the "Next" URL`, func() { + responseObject := new(iamaccessgroupsv2.ListTemplateVersionsResponse) + nextObject := new(iamaccessgroupsv2.HrefStruct) + nextObject.Href = core.StringPtr("ibm.com") + responseObject.Next = nextObject + + value, err := responseObject.GetNextOffset() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextOffset with a non-integer query param in the "Next" URL`, func() { + responseObject := new(iamaccessgroupsv2.ListTemplateVersionsResponse) + nextObject := new(iamaccessgroupsv2.HrefStruct) + nextObject.Href = core.StringPtr("ibm.com?offset=tiger") + responseObject.Next = nextObject + + value, err := responseObject.GetNextOffset() + Expect(err).NotTo(BeNil()) + Expect(value).To(BeNil()) + }) + }) + Context(`Using mock server endpoint - paginated response`, func() { + BeforeEach(func() { + var requestNumber int = 0 + 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(listTemplateVersionsPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + requestNumber++ + if requestNumber == 1 { + fmt.Fprintf(res, "%s", `{"next":{"href":"https://myhost.com/somePath?offset=1"},"total_count":2,"group_template_versions":[{"name":"Name","description":"Description","account_id":"AccountID","version":"Version","committed":false,"group":{"name":"Name","description":"Description","members":{"users":["Users"],"service_ids":["ServiceIds"],"action_controls":{"add":false,"remove":true}},"assertions":{"rules":[{"name":"Name","expiration":10,"realm_name":"RealmName","conditions":[{"claim":"Claim","operator":"Operator","value":"Value"}],"action_controls":{"remove":true,"update":true}}],"action_controls":{"add":false,"remove":true,"update":true}},"action_controls":{"access":{"add":false}}},"policy_template_references":[{"id":"ID","version":"Version"}],"href":"Href","created_at":"CreatedAt","created_by_id":"CreatedByID","last_modified_at":"LastModifiedAt","last_modified_by_id":"LastModifiedByID"}],"limit":1}`) + } else if requestNumber == 2 { + fmt.Fprintf(res, "%s", `{"total_count":2,"group_template_versions":[{"name":"Name","description":"Description","account_id":"AccountID","version":"Version","committed":false,"group":{"name":"Name","description":"Description","members":{"users":["Users"],"service_ids":["ServiceIds"],"action_controls":{"add":false,"remove":true}},"assertions":{"rules":[{"name":"Name","expiration":10,"realm_name":"RealmName","conditions":[{"claim":"Claim","operator":"Operator","value":"Value"}],"action_controls":{"remove":true,"update":true}}],"action_controls":{"add":false,"remove":true,"update":true}},"action_controls":{"access":{"add":false}}},"policy_template_references":[{"id":"ID","version":"Version"}],"href":"Href","created_at":"CreatedAt","created_by_id":"CreatedByID","last_modified_at":"LastModifiedAt","last_modified_by_id":"LastModifiedByID"}],"limit":1}`) + } else { + res.WriteHeader(400) + } + })) + }) + It(`Use TemplateVersionsPager.GetNext successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + listTemplateVersionsOptionsModel := &iamaccessgroupsv2.ListTemplateVersionsOptions{ + TemplateID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(100)), + } + + pager, err := iamAccessGroupsService.NewTemplateVersionsPager(listTemplateVersionsOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []iamaccessgroupsv2.ListTemplatesVersionsResponse + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + Expect(len(allResults)).To(Equal(2)) + }) + It(`Use TemplateVersionsPager.GetAll successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + listTemplateVersionsOptionsModel := &iamaccessgroupsv2.ListTemplateVersionsOptions{ + TemplateID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(100)), + } + + pager, err := iamAccessGroupsService.NewTemplateVersionsPager(listTemplateVersionsOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allResults, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allResults).ToNot(BeNil()) + Expect(len(allResults)).To(Equal(2)) + }) + }) + }) + Describe(`GetTemplateVersion(getTemplateVersionOptions *GetTemplateVersionOptions) - Operation response error`, func() { + getTemplateVersionPath := "/v1/group_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(getTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetTemplateVersion with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetTemplateVersionOptions model + getTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetTemplateVersionOptions) + getTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + getTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getTemplateVersionOptionsModel.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 := iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetTemplateVersion(getTemplateVersionOptions *GetTemplateVersionOptions)`, func() { + getTemplateVersionPath := "/v1/group_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(getTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // 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", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 GetTemplateVersion successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the GetTemplateVersionOptions model + getTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetTemplateVersionOptions) + getTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + getTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getTemplateVersionOptionsModel.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 := iamAccessGroupsService.GetTemplateVersionWithContext(ctx, getTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptionsModel) + 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 = iamAccessGroupsService.GetTemplateVersionWithContext(ctx, getTemplateVersionOptionsModel) + 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(getTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 GetTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.GetTemplateVersion(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetTemplateVersionOptions model + getTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetTemplateVersionOptions) + getTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + getTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetTemplateVersion with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetTemplateVersionOptions model + getTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetTemplateVersionOptions) + getTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + getTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptionsModel) + 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 GetTemplateVersionOptions model with no property values + getTemplateVersionOptionsModelNew := new(iamaccessgroupsv2.GetTemplateVersionOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptionsModelNew) + 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 GetTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetTemplateVersionOptions model + getTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetTemplateVersionOptions) + getTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + getTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.GetTemplateVersion(getTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateTemplateVersion(updateTemplateVersionOptions *UpdateTemplateVersionOptions) - Operation response error`, func() { + updateTemplateVersionPath := "/v1/group_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(updateTemplateVersionPath)) + Expect(req.Method).To(Equal("PUT")) + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "83adf5bd-de790caa3"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateTemplateVersion with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the UpdateTemplateVersionOptions model + updateTemplateVersionOptionsModel := new(iamaccessgroupsv2.UpdateTemplateVersionOptions) + updateTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + updateTemplateVersionOptionsModel.IfMatch = core.StringPtr("testString") + updateTemplateVersionOptionsModel.ID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + updateTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + updateTemplateVersionOptionsModel.AccountID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Version = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Committed = core.BoolPtr(true) + updateTemplateVersionOptionsModel.Group = accessGroupInputModel + updateTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + updateTemplateVersionOptionsModel.Href = core.StringPtr("testString") + updateTemplateVersionOptionsModel.CreatedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.CreatedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.LastModifiedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.LastModifiedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.TransactionID = core.StringPtr("83adf5bd-de790caa3") + updateTemplateVersionOptionsModel.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 := iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateTemplateVersion(updateTemplateVersionOptions *UpdateTemplateVersionOptions)`, func() { + updateTemplateVersionPath := "/v1/group_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(updateTemplateVersionPath)) + 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"))) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "83adf5bd-de790caa3"))) + // 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", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 UpdateTemplateVersion successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the UpdateTemplateVersionOptions model + updateTemplateVersionOptionsModel := new(iamaccessgroupsv2.UpdateTemplateVersionOptions) + updateTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + updateTemplateVersionOptionsModel.IfMatch = core.StringPtr("testString") + updateTemplateVersionOptionsModel.ID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + updateTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + updateTemplateVersionOptionsModel.AccountID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Version = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Committed = core.BoolPtr(true) + updateTemplateVersionOptionsModel.Group = accessGroupInputModel + updateTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + updateTemplateVersionOptionsModel.Href = core.StringPtr("testString") + updateTemplateVersionOptionsModel.CreatedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.CreatedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.LastModifiedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.LastModifiedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.TransactionID = core.StringPtr("83adf5bd-de790caa3") + updateTemplateVersionOptionsModel.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 := iamAccessGroupsService.UpdateTemplateVersionWithContext(ctx, updateTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptionsModel) + 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 = iamAccessGroupsService.UpdateTemplateVersionWithContext(ctx, updateTemplateVersionOptionsModel) + 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(updateTemplateVersionPath)) + 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"))) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "83adf5bd-de790caa3"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 UpdateTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.UpdateTemplateVersion(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the UpdateTemplateVersionOptions model + updateTemplateVersionOptionsModel := new(iamaccessgroupsv2.UpdateTemplateVersionOptions) + updateTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + updateTemplateVersionOptionsModel.IfMatch = core.StringPtr("testString") + updateTemplateVersionOptionsModel.ID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + updateTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + updateTemplateVersionOptionsModel.AccountID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Version = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Committed = core.BoolPtr(true) + updateTemplateVersionOptionsModel.Group = accessGroupInputModel + updateTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + updateTemplateVersionOptionsModel.Href = core.StringPtr("testString") + updateTemplateVersionOptionsModel.CreatedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.CreatedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.LastModifiedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.LastModifiedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.TransactionID = core.StringPtr("83adf5bd-de790caa3") + updateTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke UpdateTemplateVersion with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the UpdateTemplateVersionOptions model + updateTemplateVersionOptionsModel := new(iamaccessgroupsv2.UpdateTemplateVersionOptions) + updateTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + updateTemplateVersionOptionsModel.IfMatch = core.StringPtr("testString") + updateTemplateVersionOptionsModel.ID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + updateTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + updateTemplateVersionOptionsModel.AccountID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Version = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Committed = core.BoolPtr(true) + updateTemplateVersionOptionsModel.Group = accessGroupInputModel + updateTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + updateTemplateVersionOptionsModel.Href = core.StringPtr("testString") + updateTemplateVersionOptionsModel.CreatedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.CreatedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.LastModifiedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.LastModifiedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.TransactionID = core.StringPtr("83adf5bd-de790caa3") + updateTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptionsModel) + 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 UpdateTemplateVersionOptions model with no property values + updateTemplateVersionOptionsModelNew := new(iamaccessgroupsv2.UpdateTemplateVersionOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptionsModelNew) + 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 UpdateTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + membersInputModel.Users = []string{"IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + accessActionControlsModel.Add = core.BoolPtr(false) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + groupActionControlsModel.Access = accessActionControlsModel + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + + // Construct an instance of the UpdateTemplateVersionOptions model + updateTemplateVersionOptionsModel := new(iamaccessgroupsv2.UpdateTemplateVersionOptions) + updateTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + updateTemplateVersionOptionsModel.IfMatch = core.StringPtr("testString") + updateTemplateVersionOptionsModel.ID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Name = core.StringPtr("IAM Admin Group template 2") + updateTemplateVersionOptionsModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + updateTemplateVersionOptionsModel.AccountID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Version = core.StringPtr("testString") + updateTemplateVersionOptionsModel.Committed = core.BoolPtr(true) + updateTemplateVersionOptionsModel.Group = accessGroupInputModel + updateTemplateVersionOptionsModel.PolicyTemplateReferences = []iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel} + updateTemplateVersionOptionsModel.Href = core.StringPtr("testString") + updateTemplateVersionOptionsModel.CreatedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.CreatedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.LastModifiedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + updateTemplateVersionOptionsModel.LastModifiedByID = core.StringPtr("testString") + updateTemplateVersionOptionsModel.TransactionID = core.StringPtr("83adf5bd-de790caa3") + updateTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.UpdateTemplateVersion(updateTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteTemplateVersion(deleteTemplateVersionOptions *DeleteTemplateVersionOptions)`, func() { + deleteTemplateVersionPath := "/v1/group_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(deleteTemplateVersionPath)) + Expect(req.Method).To(Equal("DELETE")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.WriteHeader(204) + })) + }) + It(`Invoke DeleteTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := iamAccessGroupsService.DeleteTemplateVersion(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeleteTemplateVersionOptions model + deleteTemplateVersionOptionsModel := new(iamaccessgroupsv2.DeleteTemplateVersionOptions) + deleteTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + deleteTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + deleteTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + deleteTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = iamAccessGroupsService.DeleteTemplateVersion(deleteTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeleteTemplateVersion with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the DeleteTemplateVersionOptions model + deleteTemplateVersionOptionsModel := new(iamaccessgroupsv2.DeleteTemplateVersionOptions) + deleteTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + deleteTemplateVersionOptionsModel.VersionNum = core.StringPtr("testString") + deleteTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + deleteTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := iamAccessGroupsService.DeleteTemplateVersion(deleteTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeleteTemplateVersionOptions model with no property values + deleteTemplateVersionOptionsModelNew := new(iamaccessgroupsv2.DeleteTemplateVersionOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = iamAccessGroupsService.DeleteTemplateVersion(deleteTemplateVersionOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CommitTemplate(commitTemplateOptions *CommitTemplateOptions)`, func() { + commitTemplatePath := "/v1/group_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(commitTemplatePath)) + 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"))) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.WriteHeader(204) + })) + }) + It(`Invoke CommitTemplate successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := iamAccessGroupsService.CommitTemplate(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the CommitTemplateOptions model + commitTemplateOptionsModel := new(iamaccessgroupsv2.CommitTemplateOptions) + commitTemplateOptionsModel.TemplateID = core.StringPtr("testString") + commitTemplateOptionsModel.VersionNum = core.StringPtr("testString") + commitTemplateOptionsModel.IfMatch = core.StringPtr("testString") + commitTemplateOptionsModel.TransactionID = core.StringPtr("testString") + commitTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = iamAccessGroupsService.CommitTemplate(commitTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke CommitTemplate with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the CommitTemplateOptions model + commitTemplateOptionsModel := new(iamaccessgroupsv2.CommitTemplateOptions) + commitTemplateOptionsModel.TemplateID = core.StringPtr("testString") + commitTemplateOptionsModel.VersionNum = core.StringPtr("testString") + commitTemplateOptionsModel.IfMatch = core.StringPtr("testString") + commitTemplateOptionsModel.TransactionID = core.StringPtr("testString") + commitTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := iamAccessGroupsService.CommitTemplate(commitTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the CommitTemplateOptions model with no property values + commitTemplateOptionsModelNew := new(iamaccessgroupsv2.CommitTemplateOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = iamAccessGroupsService.CommitTemplate(commitTemplateOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetLatestTemplateVersion(getLatestTemplateVersionOptions *GetLatestTemplateVersionOptions) - Operation response error`, func() { + getLatestTemplateVersionPath := "/v1/group_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(getLatestTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetLatestTemplateVersion with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetLatestTemplateVersionOptions model + getLatestTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetLatestTemplateVersionOptions) + getLatestTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.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 := iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetLatestTemplateVersion(getLatestTemplateVersionOptions *GetLatestTemplateVersionOptions)`, func() { + getLatestTemplateVersionPath := "/v1/group_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(getLatestTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // 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", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 GetLatestTemplateVersion successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the GetLatestTemplateVersionOptions model + getLatestTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetLatestTemplateVersionOptions) + getLatestTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.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 := iamAccessGroupsService.GetLatestTemplateVersionWithContext(ctx, getLatestTemplateVersionOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptionsModel) + 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 = iamAccessGroupsService.GetLatestTemplateVersionWithContext(ctx, getLatestTemplateVersionOptionsModel) + 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(getLatestTemplateVersionPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "description": "Description", "account_id": "AccountID", "version": "Version", "committed": false, "group": {"name": "Name", "description": "Description", "members": {"users": ["Users"], "service_ids": ["ServiceIds"], "action_controls": {"add": false, "remove": true}}, "assertions": {"rules": [{"name": "Name", "expiration": 10, "realm_name": "RealmName", "conditions": [{"claim": "Claim", "operator": "Operator", "value": "Value"}], "action_controls": {"remove": true, "update": true}}], "action_controls": {"add": false, "remove": true, "update": true}}, "action_controls": {"access": {"add": false}}}, "policy_template_references": [{"id": "ID", "version": "Version"}], "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 GetLatestTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.GetLatestTemplateVersion(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetLatestTemplateVersionOptions model + getLatestTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetLatestTemplateVersionOptions) + getLatestTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetLatestTemplateVersion with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetLatestTemplateVersionOptions model + getLatestTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetLatestTemplateVersionOptions) + getLatestTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptionsModel) + 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 GetLatestTemplateVersionOptions model with no property values + getLatestTemplateVersionOptionsModelNew := new(iamaccessgroupsv2.GetLatestTemplateVersionOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptionsModelNew) + 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 GetLatestTemplateVersion successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetLatestTemplateVersionOptions model + getLatestTemplateVersionOptionsModel := new(iamaccessgroupsv2.GetLatestTemplateVersionOptions) + getLatestTemplateVersionOptionsModel.TemplateID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.TransactionID = core.StringPtr("testString") + getLatestTemplateVersionOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.GetLatestTemplateVersion(getLatestTemplateVersionOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteTemplate(deleteTemplateOptions *DeleteTemplateOptions)`, func() { + deleteTemplatePath := "/v1/group_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(deleteTemplatePath)) + Expect(req.Method).To(Equal("DELETE")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.WriteHeader(204) + })) + }) + It(`Invoke DeleteTemplate successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := iamAccessGroupsService.DeleteTemplate(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeleteTemplateOptions model + deleteTemplateOptionsModel := new(iamaccessgroupsv2.DeleteTemplateOptions) + deleteTemplateOptionsModel.TemplateID = core.StringPtr("testString") + deleteTemplateOptionsModel.TransactionID = core.StringPtr("testString") + deleteTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = iamAccessGroupsService.DeleteTemplate(deleteTemplateOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeleteTemplate with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the DeleteTemplateOptions model + deleteTemplateOptionsModel := new(iamaccessgroupsv2.DeleteTemplateOptions) + deleteTemplateOptionsModel.TemplateID = core.StringPtr("testString") + deleteTemplateOptionsModel.TransactionID = core.StringPtr("testString") + deleteTemplateOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := iamAccessGroupsService.DeleteTemplate(deleteTemplateOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeleteTemplateOptions model with no property values + deleteTemplateOptionsModelNew := new(iamaccessgroupsv2.DeleteTemplateOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = iamAccessGroupsService.DeleteTemplate(deleteTemplateOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateAssignment(createAssignmentOptions *CreateAssignmentOptions) - Operation response error`, func() { + createAssignmentPath := "/v1/group_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(createAssignmentPath)) + Expect(req.Method).To(Equal("POST")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(202) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateAssignment with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the CreateAssignmentOptions model + createAssignmentOptionsModel := new(iamaccessgroupsv2.CreateAssignmentOptions) + createAssignmentOptionsModel.TemplateID = core.StringPtr("AccessGroupTemplateId-4be4") + createAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + createAssignmentOptionsModel.TargetType = core.StringPtr("AccountGroup") + createAssignmentOptionsModel.Target = core.StringPtr("0a45594d0f-123") + createAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + createAssignmentOptionsModel.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 := iamAccessGroupsService.CreateAssignment(createAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.CreateAssignment(createAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateAssignment(createAssignmentOptions *CreateAssignmentOptions)`, func() { + createAssignmentPath := "/v1/group_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(createAssignmentPath)) + 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["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][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(202) + fmt.Fprintf(res, "%s", `{"id": "ID", "account_id": "AccountID", "template_id": "TemplateID", "template_version": "TemplateVersion", "target_type": "Account", "target": "Target", "operation": "assign", "status": "accepted", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00.000Z", "updated_by": "UpdatedBy"}`) + })) + }) + It(`Invoke CreateAssignment successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the CreateAssignmentOptions model + createAssignmentOptionsModel := new(iamaccessgroupsv2.CreateAssignmentOptions) + createAssignmentOptionsModel.TemplateID = core.StringPtr("AccessGroupTemplateId-4be4") + createAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + createAssignmentOptionsModel.TargetType = core.StringPtr("AccountGroup") + createAssignmentOptionsModel.Target = core.StringPtr("0a45594d0f-123") + createAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + createAssignmentOptionsModel.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 := iamAccessGroupsService.CreateAssignmentWithContext(ctx, createAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.CreateAssignment(createAssignmentOptionsModel) + 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 = iamAccessGroupsService.CreateAssignmentWithContext(ctx, createAssignmentOptionsModel) + 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(createAssignmentPath)) + 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["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(202) + fmt.Fprintf(res, "%s", `{"id": "ID", "account_id": "AccountID", "template_id": "TemplateID", "template_version": "TemplateVersion", "target_type": "Account", "target": "Target", "operation": "assign", "status": "accepted", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00.000Z", "updated_by": "UpdatedBy"}`) + })) + }) + It(`Invoke CreateAssignment successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.CreateAssignment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the CreateAssignmentOptions model + createAssignmentOptionsModel := new(iamaccessgroupsv2.CreateAssignmentOptions) + createAssignmentOptionsModel.TemplateID = core.StringPtr("AccessGroupTemplateId-4be4") + createAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + createAssignmentOptionsModel.TargetType = core.StringPtr("AccountGroup") + createAssignmentOptionsModel.Target = core.StringPtr("0a45594d0f-123") + createAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + createAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.CreateAssignment(createAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreateAssignment with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the CreateAssignmentOptions model + createAssignmentOptionsModel := new(iamaccessgroupsv2.CreateAssignmentOptions) + createAssignmentOptionsModel.TemplateID = core.StringPtr("AccessGroupTemplateId-4be4") + createAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + createAssignmentOptionsModel.TargetType = core.StringPtr("AccountGroup") + createAssignmentOptionsModel.Target = core.StringPtr("0a45594d0f-123") + createAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + createAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.CreateAssignment(createAssignmentOptionsModel) + 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 CreateAssignmentOptions model with no property values + createAssignmentOptionsModelNew := new(iamaccessgroupsv2.CreateAssignmentOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.CreateAssignment(createAssignmentOptionsModelNew) + 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(202) + })) + }) + It(`Invoke CreateAssignment successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the CreateAssignmentOptions model + createAssignmentOptionsModel := new(iamaccessgroupsv2.CreateAssignmentOptions) + createAssignmentOptionsModel.TemplateID = core.StringPtr("AccessGroupTemplateId-4be4") + createAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + createAssignmentOptionsModel.TargetType = core.StringPtr("AccountGroup") + createAssignmentOptionsModel.Target = core.StringPtr("0a45594d0f-123") + createAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + createAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.CreateAssignment(createAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListAssignments(listAssignmentsOptions *ListAssignmentsOptions) - Operation response error`, func() { + listAssignmentsPath := "/v1/group_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(listAssignmentsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"accountID-123"})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListAssignments with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListAssignmentsOptions model + listAssignmentsOptionsModel := new(iamaccessgroupsv2.ListAssignmentsOptions) + listAssignmentsOptionsModel.AccountID = core.StringPtr("accountID-123") + listAssignmentsOptionsModel.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 := iamAccessGroupsService.ListAssignments(listAssignmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.ListAssignments(listAssignmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListAssignments(listAssignmentsOptions *ListAssignmentsOptions)`, func() { + listAssignmentsPath := "/v1/group_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(listAssignmentsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"accountID-123"})) + // 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", `{"limit": 5, "offset": 6, "total_count": 10, "first": {"href": "Href"}, "last": {"href": "Href"}, "assignments": [{"id": "ID", "account_id": "AccountID", "template_id": "TemplateID", "template_version": "TemplateVersion", "target_type": "Account", "target": "Target", "operation": "assign", "status": "accepted", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00.000Z", "updated_by": "UpdatedBy"}]}`) + })) + }) + It(`Invoke ListAssignments successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the ListAssignmentsOptions model + listAssignmentsOptionsModel := new(iamaccessgroupsv2.ListAssignmentsOptions) + listAssignmentsOptionsModel.AccountID = core.StringPtr("accountID-123") + listAssignmentsOptionsModel.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 := iamAccessGroupsService.ListAssignmentsWithContext(ctx, listAssignmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.ListAssignments(listAssignmentsOptionsModel) + 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 = iamAccessGroupsService.ListAssignmentsWithContext(ctx, listAssignmentsOptionsModel) + 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(listAssignmentsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"accountID-123"})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"limit": 5, "offset": 6, "total_count": 10, "first": {"href": "Href"}, "last": {"href": "Href"}, "assignments": [{"id": "ID", "account_id": "AccountID", "template_id": "TemplateID", "template_version": "TemplateVersion", "target_type": "Account", "target": "Target", "operation": "assign", "status": "accepted", "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00.000Z", "updated_by": "UpdatedBy"}]}`) + })) + }) + It(`Invoke ListAssignments successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.ListAssignments(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListAssignmentsOptions model + listAssignmentsOptionsModel := new(iamaccessgroupsv2.ListAssignmentsOptions) + listAssignmentsOptionsModel.AccountID = core.StringPtr("accountID-123") + listAssignmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.ListAssignments(listAssignmentsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListAssignments with error: Operation request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListAssignmentsOptions model + listAssignmentsOptionsModel := new(iamaccessgroupsv2.ListAssignmentsOptions) + listAssignmentsOptionsModel.AccountID = core.StringPtr("accountID-123") + listAssignmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.ListAssignments(listAssignmentsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListAssignments successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the ListAssignmentsOptions model + listAssignmentsOptionsModel := new(iamaccessgroupsv2.ListAssignmentsOptions) + listAssignmentsOptionsModel.AccountID = core.StringPtr("accountID-123") + listAssignmentsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.ListAssignments(listAssignmentsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetAssignment(getAssignmentOptions *GetAssignmentOptions) - Operation response error`, func() { + getAssignmentPath := "/v1/group_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(getAssignmentPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // TODO: Add check for verbose query parameter + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetAssignment with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetAssignmentOptions model + getAssignmentOptionsModel := new(iamaccessgroupsv2.GetAssignmentOptions) + getAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + getAssignmentOptionsModel.Verbose = core.BoolPtr(false) + getAssignmentOptionsModel.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 := iamAccessGroupsService.GetAssignment(getAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.GetAssignment(getAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetAssignment(getAssignmentOptions *GetAssignmentOptions)`, func() { + getAssignmentPath := "/v1/group_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(getAssignmentPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // TODO: Add check for verbose query parameter + // 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", `{"id": "ID", "account_id": "AccountID", "template_id": "TemplateID", "template_version": "TemplateVersion", "target_type": "TargetType", "target": "Target", "operation": "Operation", "status": "Status", "resources": [{"target": "Target", "group": {"group": {"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}, "members": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}], "rules": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}]}, "policy_template_references": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00.000Z", "updated_by": "UpdatedBy"}`) + })) + }) + It(`Invoke GetAssignment successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the GetAssignmentOptions model + getAssignmentOptionsModel := new(iamaccessgroupsv2.GetAssignmentOptions) + getAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + getAssignmentOptionsModel.Verbose = core.BoolPtr(false) + getAssignmentOptionsModel.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 := iamAccessGroupsService.GetAssignmentWithContext(ctx, getAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.GetAssignment(getAssignmentOptionsModel) + 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 = iamAccessGroupsService.GetAssignmentWithContext(ctx, getAssignmentOptionsModel) + 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(getAssignmentPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // TODO: Add check for verbose query parameter + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"id": "ID", "account_id": "AccountID", "template_id": "TemplateID", "template_version": "TemplateVersion", "target_type": "TargetType", "target": "Target", "operation": "Operation", "status": "Status", "resources": [{"target": "Target", "group": {"group": {"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}, "members": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}], "rules": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}]}, "policy_template_references": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00.000Z", "updated_by": "UpdatedBy"}`) + })) + }) + It(`Invoke GetAssignment successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.GetAssignment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetAssignmentOptions model + getAssignmentOptionsModel := new(iamaccessgroupsv2.GetAssignmentOptions) + getAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + getAssignmentOptionsModel.Verbose = core.BoolPtr(false) + getAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.GetAssignment(getAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetAssignment with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetAssignmentOptions model + getAssignmentOptionsModel := new(iamaccessgroupsv2.GetAssignmentOptions) + getAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + getAssignmentOptionsModel.Verbose = core.BoolPtr(false) + getAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.GetAssignment(getAssignmentOptionsModel) + 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 GetAssignmentOptions model with no property values + getAssignmentOptionsModelNew := new(iamaccessgroupsv2.GetAssignmentOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.GetAssignment(getAssignmentOptionsModelNew) + 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 GetAssignment successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the GetAssignmentOptions model + getAssignmentOptionsModel := new(iamaccessgroupsv2.GetAssignmentOptions) + getAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + getAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + getAssignmentOptionsModel.Verbose = core.BoolPtr(false) + getAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.GetAssignment(getAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateAssignment(updateAssignmentOptions *UpdateAssignmentOptions) - Operation response error`, func() { + updateAssignmentPath := "/v1/group_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(updateAssignmentPath)) + Expect(req.Method).To(Equal("PATCH")) + 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(202) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateAssignment with error: Operation response processing error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the UpdateAssignmentOptions model + updateAssignmentOptionsModel := new(iamaccessgroupsv2.UpdateAssignmentOptions) + updateAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + updateAssignmentOptionsModel.IfMatch = core.StringPtr("testString") + updateAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + updateAssignmentOptionsModel.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 := iamAccessGroupsService.UpdateAssignment(updateAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamAccessGroupsService.EnableRetries(0, 0) + result, response, operationErr = iamAccessGroupsService.UpdateAssignment(updateAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateAssignment(updateAssignmentOptions *UpdateAssignmentOptions)`, func() { + updateAssignmentPath := "/v1/group_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(updateAssignmentPath)) + Expect(req.Method).To(Equal("PATCH")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + 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(202) + fmt.Fprintf(res, "%s", `{"id": "ID", "account_id": "AccountID", "template_id": "TemplateID", "template_version": "TemplateVersion", "target_type": "TargetType", "target": "Target", "operation": "Operation", "status": "Status", "resources": [{"target": "Target", "group": {"group": {"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}, "members": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}], "rules": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}]}, "policy_template_references": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00.000Z", "updated_by": "UpdatedBy"}`) + })) + }) + It(`Invoke UpdateAssignment successfully with retries`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + iamAccessGroupsService.EnableRetries(0, 0) + + // Construct an instance of the UpdateAssignmentOptions model + updateAssignmentOptionsModel := new(iamaccessgroupsv2.UpdateAssignmentOptions) + updateAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + updateAssignmentOptionsModel.IfMatch = core.StringPtr("testString") + updateAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + updateAssignmentOptionsModel.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 := iamAccessGroupsService.UpdateAssignmentWithContext(ctx, updateAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamAccessGroupsService.DisableRetries() + result, response, operationErr := iamAccessGroupsService.UpdateAssignment(updateAssignmentOptionsModel) + 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 = iamAccessGroupsService.UpdateAssignmentWithContext(ctx, updateAssignmentOptionsModel) + 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(updateAssignmentPath)) + Expect(req.Method).To(Equal("PATCH")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + 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(202) + fmt.Fprintf(res, "%s", `{"id": "ID", "account_id": "AccountID", "template_id": "TemplateID", "template_version": "TemplateVersion", "target_type": "TargetType", "target": "Target", "operation": "Operation", "status": "Status", "resources": [{"target": "Target", "group": {"group": {"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}, "members": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}], "rules": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}]}, "policy_template_references": [{"id": "ID", "name": "Name", "version": "Version", "resource": "Resource", "error": "Error", "operation": "Operation", "status": "Status"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00.000Z", "updated_by": "UpdatedBy"}`) + })) + }) + It(`Invoke UpdateAssignment successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamAccessGroupsService.UpdateAssignment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the UpdateAssignmentOptions model + updateAssignmentOptionsModel := new(iamaccessgroupsv2.UpdateAssignmentOptions) + updateAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + updateAssignmentOptionsModel.IfMatch = core.StringPtr("testString") + updateAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + updateAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamAccessGroupsService.UpdateAssignment(updateAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke UpdateAssignment with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the UpdateAssignmentOptions model + updateAssignmentOptionsModel := new(iamaccessgroupsv2.UpdateAssignmentOptions) + updateAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + updateAssignmentOptionsModel.IfMatch = core.StringPtr("testString") + updateAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + updateAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamAccessGroupsService.UpdateAssignment(updateAssignmentOptionsModel) + 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 UpdateAssignmentOptions model with no property values + updateAssignmentOptionsModelNew := new(iamaccessgroupsv2.UpdateAssignmentOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamAccessGroupsService.UpdateAssignment(updateAssignmentOptionsModelNew) + 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(202) + })) + }) + It(`Invoke UpdateAssignment successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the UpdateAssignmentOptions model + updateAssignmentOptionsModel := new(iamaccessgroupsv2.UpdateAssignmentOptions) + updateAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + updateAssignmentOptionsModel.IfMatch = core.StringPtr("testString") + updateAssignmentOptionsModel.TemplateVersion = core.StringPtr("1") + updateAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := iamAccessGroupsService.UpdateAssignment(updateAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteAssignment(deleteAssignmentOptions *DeleteAssignmentOptions)`, func() { + deleteAssignmentPath := "/v1/group_assignments/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(deleteAssignmentPath)) + Expect(req.Method).To(Equal("DELETE")) + + Expect(req.Header["Transaction-Id"]).ToNot(BeNil()) + Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.WriteHeader(202) + })) + }) + It(`Invoke DeleteAssignment successfully`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := iamAccessGroupsService.DeleteAssignment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeleteAssignmentOptions model + deleteAssignmentOptionsModel := new(iamaccessgroupsv2.DeleteAssignmentOptions) + deleteAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + deleteAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + deleteAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = iamAccessGroupsService.DeleteAssignment(deleteAssignmentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeleteAssignment with error: Operation validation and request error`, func() { + iamAccessGroupsService, serviceErr := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamAccessGroupsService).ToNot(BeNil()) + + // Construct an instance of the DeleteAssignmentOptions model + deleteAssignmentOptionsModel := new(iamaccessgroupsv2.DeleteAssignmentOptions) + deleteAssignmentOptionsModel.AssignmentID = core.StringPtr("testString") + deleteAssignmentOptionsModel.TransactionID = core.StringPtr("testString") + deleteAssignmentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamAccessGroupsService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := iamAccessGroupsService.DeleteAssignment(deleteAssignmentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeleteAssignmentOptions model with no property values + deleteAssignmentOptionsModelNew := new(iamaccessgroupsv2.DeleteAssignmentOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = iamAccessGroupsService.DeleteAssignment(deleteAssignmentOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`Model constructor tests`, func() { Context(`Using a service client instance`, func() { iamAccessGroupsService, _ := iamaccessgroupsv2.NewIamAccessGroupsV2(&iamaccessgroupsv2.IamAccessGroupsV2Options{ URL: "http://iamaccessgroupsv2modelgenerator.com", Authenticator: &core.NoAuthAuthenticator{}, }) + It(`Invoke NewAccessGroupInput successfully`, func() { + name := "testString" + _model, err := iamAccessGroupsService.NewAccessGroupInput(name) + Expect(_model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) It(`Invoke NewAddAccessGroupRuleOptions successfully`, func() { // Construct an instance of the RuleConditions model ruleConditionsModel := new(iamaccessgroupsv2.RuleConditions) @@ -4701,14 +8953,14 @@ var _ = Describe(`IamAccessGroupsV2`, func() { addMemberToMultipleAccessGroupsOptionsModel.SetAccountID("testString") addMemberToMultipleAccessGroupsOptionsModel.SetIamID("testString") addMemberToMultipleAccessGroupsOptionsModel.SetType("user") - addMemberToMultipleAccessGroupsOptionsModel.SetGroups([]string{"access-group-id-1"}) + addMemberToMultipleAccessGroupsOptionsModel.SetGroups([]string{"AccessGroupId-b0d32f56-f85c-4bf1-af37-7bbd92b1b2b3"}) addMemberToMultipleAccessGroupsOptionsModel.SetTransactionID("testString") addMemberToMultipleAccessGroupsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(addMemberToMultipleAccessGroupsOptionsModel).ToNot(BeNil()) Expect(addMemberToMultipleAccessGroupsOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) Expect(addMemberToMultipleAccessGroupsOptionsModel.IamID).To(Equal(core.StringPtr("testString"))) Expect(addMemberToMultipleAccessGroupsOptionsModel.Type).To(Equal(core.StringPtr("user"))) - Expect(addMemberToMultipleAccessGroupsOptionsModel.Groups).To(Equal([]string{"access-group-id-1"})) + Expect(addMemberToMultipleAccessGroupsOptionsModel.Groups).To(Equal([]string{"AccessGroupId-b0d32f56-f85c-4bf1-af37-7bbd92b1b2b3"})) Expect(addMemberToMultipleAccessGroupsOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) Expect(addMemberToMultipleAccessGroupsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) @@ -4734,6 +8986,24 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(addMembersToAccessGroupOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) Expect(addMembersToAccessGroupOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewCommitTemplateOptions successfully`, func() { + // Construct an instance of the CommitTemplateOptions model + templateID := "testString" + versionNum := "testString" + ifMatch := "testString" + commitTemplateOptionsModel := iamAccessGroupsService.NewCommitTemplateOptions(templateID, versionNum, ifMatch) + commitTemplateOptionsModel.SetTemplateID("testString") + commitTemplateOptionsModel.SetVersionNum("testString") + commitTemplateOptionsModel.SetIfMatch("testString") + commitTemplateOptionsModel.SetTransactionID("testString") + commitTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(commitTemplateOptionsModel).ToNot(BeNil()) + Expect(commitTemplateOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(commitTemplateOptionsModel.VersionNum).To(Equal(core.StringPtr("testString"))) + Expect(commitTemplateOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) + Expect(commitTemplateOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(commitTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewCreateAccessGroupOptions successfully`, func() { // Construct an instance of the CreateAccessGroupOptions model accountID := "testString" @@ -4751,6 +9021,289 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(createAccessGroupOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) Expect(createAccessGroupOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewCreateAssignmentOptions successfully`, func() { + // Construct an instance of the CreateAssignmentOptions model + createAssignmentOptionsTemplateID := "AccessGroupTemplateId-4be4" + createAssignmentOptionsTemplateVersion := "1" + createAssignmentOptionsTargetType := "AccountGroup" + createAssignmentOptionsTarget := "0a45594d0f-123" + createAssignmentOptionsModel := iamAccessGroupsService.NewCreateAssignmentOptions(createAssignmentOptionsTemplateID, createAssignmentOptionsTemplateVersion, createAssignmentOptionsTargetType, createAssignmentOptionsTarget) + createAssignmentOptionsModel.SetTemplateID("AccessGroupTemplateId-4be4") + createAssignmentOptionsModel.SetTemplateVersion("1") + createAssignmentOptionsModel.SetTargetType("AccountGroup") + createAssignmentOptionsModel.SetTarget("0a45594d0f-123") + createAssignmentOptionsModel.SetTransactionID("testString") + createAssignmentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createAssignmentOptionsModel).ToNot(BeNil()) + Expect(createAssignmentOptionsModel.TemplateID).To(Equal(core.StringPtr("AccessGroupTemplateId-4be4"))) + Expect(createAssignmentOptionsModel.TemplateVersion).To(Equal(core.StringPtr("1"))) + Expect(createAssignmentOptionsModel.TargetType).To(Equal(core.StringPtr("AccountGroup"))) + Expect(createAssignmentOptionsModel.Target).To(Equal(core.StringPtr("0a45594d0f-123"))) + Expect(createAssignmentOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(createAssignmentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewCreateTemplateOptions successfully`, func() { + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + Expect(membersActionControlsModel).ToNot(BeNil()) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + Expect(membersActionControlsModel.Add).To(Equal(core.BoolPtr(true))) + Expect(membersActionControlsModel.Remove).To(Equal(core.BoolPtr(false))) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + Expect(membersInputModel).ToNot(BeNil()) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + Expect(membersInputModel.Users).To(Equal([]string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"})) + Expect(membersInputModel.ServiceIds).To(Equal([]string{"testString"})) + Expect(membersInputModel.ActionControls).To(Equal(membersActionControlsModel)) + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + Expect(conditionInputModel).ToNot(BeNil()) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + Expect(conditionInputModel.Claim).To(Equal(core.StringPtr("blueGroup"))) + Expect(conditionInputModel.Operator).To(Equal(core.StringPtr("CONTAINS"))) + Expect(conditionInputModel.Value).To(Equal(core.StringPtr(`"test-bluegroup-saml"`))) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + Expect(rulesActionControlsModel).ToNot(BeNil()) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + Expect(rulesActionControlsModel.Remove).To(Equal(core.BoolPtr(false))) + Expect(rulesActionControlsModel.Update).To(Equal(core.BoolPtr(false))) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + Expect(ruleInputModel).ToNot(BeNil()) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + Expect(ruleInputModel.Name).To(Equal(core.StringPtr("Manager group rule"))) + Expect(ruleInputModel.Expiration).To(Equal(core.Int64Ptr(int64(12)))) + Expect(ruleInputModel.RealmName).To(Equal(core.StringPtr("https://idp.example.org/SAML2"))) + Expect(ruleInputModel.Conditions).To(Equal([]iamaccessgroupsv2.ConditionInput{*conditionInputModel})) + Expect(ruleInputModel.ActionControls).To(Equal(rulesActionControlsModel)) + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + Expect(assertionsActionControlsModel).ToNot(BeNil()) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + Expect(assertionsActionControlsModel.Add).To(Equal(core.BoolPtr(false))) + Expect(assertionsActionControlsModel.Remove).To(Equal(core.BoolPtr(true))) + Expect(assertionsActionControlsModel.Update).To(Equal(core.BoolPtr(true))) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + Expect(assertionsInputModel).ToNot(BeNil()) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + Expect(assertionsInputModel.Rules).To(Equal([]iamaccessgroupsv2.RuleInput{*ruleInputModel})) + Expect(assertionsInputModel.ActionControls).To(Equal(assertionsActionControlsModel)) + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + Expect(accessActionControlsModel).ToNot(BeNil()) + accessActionControlsModel.Add = core.BoolPtr(false) + Expect(accessActionControlsModel.Add).To(Equal(core.BoolPtr(false))) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + Expect(groupActionControlsModel).ToNot(BeNil()) + groupActionControlsModel.Access = accessActionControlsModel + Expect(groupActionControlsModel.Access).To(Equal(accessActionControlsModel)) + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + Expect(accessGroupInputModel).ToNot(BeNil()) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + Expect(accessGroupInputModel.Name).To(Equal(core.StringPtr("IAM Admin Group"))) + Expect(accessGroupInputModel.Description).To(Equal(core.StringPtr("This access group template allows admin access to all IAM platform services in the account."))) + Expect(accessGroupInputModel.Members).To(Equal(membersInputModel)) + Expect(accessGroupInputModel.Assertions).To(Equal(assertionsInputModel)) + Expect(accessGroupInputModel.ActionControls).To(Equal(groupActionControlsModel)) + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + Expect(policyTemplatesInputModel).ToNot(BeNil()) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + Expect(policyTemplatesInputModel.ID).To(Equal(core.StringPtr("policyTemplateId-123"))) + Expect(policyTemplatesInputModel.Version).To(Equal(core.StringPtr("1"))) + + // Construct an instance of the CreateTemplateOptions model + createTemplateOptionsName := "IAM Admin Group template" + createTemplateOptionsAccountID := "accountID-123" + createTemplateOptionsModel := iamAccessGroupsService.NewCreateTemplateOptions(createTemplateOptionsName, createTemplateOptionsAccountID) + createTemplateOptionsModel.SetName("IAM Admin Group template") + createTemplateOptionsModel.SetAccountID("accountID-123") + createTemplateOptionsModel.SetDescription("This access group template allows admin access to all IAM platform services in the account.") + createTemplateOptionsModel.SetGroup(accessGroupInputModel) + createTemplateOptionsModel.SetPolicyTemplateReferences([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}) + createTemplateOptionsModel.SetTransactionID("testString") + createTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createTemplateOptionsModel).ToNot(BeNil()) + Expect(createTemplateOptionsModel.Name).To(Equal(core.StringPtr("IAM Admin Group template"))) + Expect(createTemplateOptionsModel.AccountID).To(Equal(core.StringPtr("accountID-123"))) + Expect(createTemplateOptionsModel.Description).To(Equal(core.StringPtr("This access group template allows admin access to all IAM platform services in the account."))) + Expect(createTemplateOptionsModel.Group).To(Equal(accessGroupInputModel)) + Expect(createTemplateOptionsModel.PolicyTemplateReferences).To(Equal([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel})) + Expect(createTemplateOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(createTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewCreateTemplateResponse successfully`, func() { + id := "testString" + name := "testString" + description := "testString" + accountID := "testString" + version := "testString" + committed := true + var group *iamaccessgroupsv2.AccessGroupInput = nil + policyTemplateReferences := []iamaccessgroupsv2.PolicyTemplatesInput{} + href := "testString" + createdAt := CreateMockDateTime("2019-01-01T12:00:00.000Z") + createdByID := "testString" + lastModifiedAt := CreateMockDateTime("2019-01-01T12:00:00.000Z") + lastModifiedByID := "testString" + _, err := iamAccessGroupsService.NewCreateTemplateResponse(id, name, description, accountID, version, committed, group, policyTemplateReferences, href, createdAt, createdByID, lastModifiedAt, lastModifiedByID) + Expect(err).ToNot(BeNil()) + }) + It(`Invoke NewCreateTemplateVersionOptions successfully`, func() { + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + Expect(membersActionControlsModel).ToNot(BeNil()) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + Expect(membersActionControlsModel.Add).To(Equal(core.BoolPtr(true))) + Expect(membersActionControlsModel.Remove).To(Equal(core.BoolPtr(false))) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + Expect(membersInputModel).ToNot(BeNil()) + membersInputModel.Users = []string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + Expect(membersInputModel.Users).To(Equal([]string{"IBMid-50PJGPKYJJ", "IBMid-665000T8WY"})) + Expect(membersInputModel.ServiceIds).To(Equal([]string{"testString"})) + Expect(membersInputModel.ActionControls).To(Equal(membersActionControlsModel)) + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + Expect(conditionInputModel).ToNot(BeNil()) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + Expect(conditionInputModel.Claim).To(Equal(core.StringPtr("blueGroup"))) + Expect(conditionInputModel.Operator).To(Equal(core.StringPtr("CONTAINS"))) + Expect(conditionInputModel.Value).To(Equal(core.StringPtr(`"test-bluegroup-saml"`))) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + Expect(rulesActionControlsModel).ToNot(BeNil()) + rulesActionControlsModel.Remove = core.BoolPtr(true) + rulesActionControlsModel.Update = core.BoolPtr(true) + Expect(rulesActionControlsModel.Remove).To(Equal(core.BoolPtr(true))) + Expect(rulesActionControlsModel.Update).To(Equal(core.BoolPtr(true))) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + Expect(ruleInputModel).ToNot(BeNil()) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + Expect(ruleInputModel.Name).To(Equal(core.StringPtr("Manager group rule"))) + Expect(ruleInputModel.Expiration).To(Equal(core.Int64Ptr(int64(12)))) + Expect(ruleInputModel.RealmName).To(Equal(core.StringPtr("https://idp.example.org/SAML2"))) + Expect(ruleInputModel.Conditions).To(Equal([]iamaccessgroupsv2.ConditionInput{*conditionInputModel})) + Expect(ruleInputModel.ActionControls).To(Equal(rulesActionControlsModel)) + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + Expect(assertionsActionControlsModel).ToNot(BeNil()) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + Expect(assertionsActionControlsModel.Add).To(Equal(core.BoolPtr(false))) + Expect(assertionsActionControlsModel.Remove).To(Equal(core.BoolPtr(true))) + Expect(assertionsActionControlsModel.Update).To(Equal(core.BoolPtr(true))) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + Expect(assertionsInputModel).ToNot(BeNil()) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + Expect(assertionsInputModel.Rules).To(Equal([]iamaccessgroupsv2.RuleInput{*ruleInputModel})) + Expect(assertionsInputModel.ActionControls).To(Equal(assertionsActionControlsModel)) + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + Expect(accessActionControlsModel).ToNot(BeNil()) + accessActionControlsModel.Add = core.BoolPtr(false) + Expect(accessActionControlsModel.Add).To(Equal(core.BoolPtr(false))) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + Expect(groupActionControlsModel).ToNot(BeNil()) + groupActionControlsModel.Access = accessActionControlsModel + Expect(groupActionControlsModel.Access).To(Equal(accessActionControlsModel)) + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + Expect(accessGroupInputModel).ToNot(BeNil()) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + Expect(accessGroupInputModel.Name).To(Equal(core.StringPtr("IAM Admin Group 8"))) + Expect(accessGroupInputModel.Description).To(Equal(core.StringPtr("This access group template allows admin access to all IAM platform services in the account."))) + Expect(accessGroupInputModel.Members).To(Equal(membersInputModel)) + Expect(accessGroupInputModel.Assertions).To(Equal(assertionsInputModel)) + Expect(accessGroupInputModel.ActionControls).To(Equal(groupActionControlsModel)) + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + Expect(policyTemplatesInputModel).ToNot(BeNil()) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + Expect(policyTemplatesInputModel.ID).To(Equal(core.StringPtr("policyTemplateId-123"))) + Expect(policyTemplatesInputModel.Version).To(Equal(core.StringPtr("1"))) + + // Construct an instance of the CreateTemplateVersionOptions model + templateID := "testString" + createTemplateVersionOptionsModel := iamAccessGroupsService.NewCreateTemplateVersionOptions(templateID) + createTemplateVersionOptionsModel.SetTemplateID("testString") + createTemplateVersionOptionsModel.SetName("IAM Admin Group template 2") + createTemplateVersionOptionsModel.SetDescription("This access group template allows admin access to all IAM platform services in the account.") + createTemplateVersionOptionsModel.SetGroup(accessGroupInputModel) + createTemplateVersionOptionsModel.SetPolicyTemplateReferences([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}) + createTemplateVersionOptionsModel.SetTransactionID("testString") + createTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createTemplateVersionOptionsModel).ToNot(BeNil()) + Expect(createTemplateVersionOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(createTemplateVersionOptionsModel.Name).To(Equal(core.StringPtr("IAM Admin Group template 2"))) + Expect(createTemplateVersionOptionsModel.Description).To(Equal(core.StringPtr("This access group template allows admin access to all IAM platform services in the account."))) + Expect(createTemplateVersionOptionsModel.Group).To(Equal(accessGroupInputModel)) + Expect(createTemplateVersionOptionsModel.PolicyTemplateReferences).To(Equal([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel})) + Expect(createTemplateVersionOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(createTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewDeleteAccessGroupOptions successfully`, func() { // Construct an instance of the DeleteAccessGroupOptions model accessGroupID := "testString" @@ -4765,6 +9318,45 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(deleteAccessGroupOptionsModel.Force).To(Equal(core.BoolPtr(false))) Expect(deleteAccessGroupOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewDeleteAssignmentOptions successfully`, func() { + // Construct an instance of the DeleteAssignmentOptions model + assignmentID := "testString" + deleteAssignmentOptionsModel := iamAccessGroupsService.NewDeleteAssignmentOptions(assignmentID) + deleteAssignmentOptionsModel.SetAssignmentID("testString") + deleteAssignmentOptionsModel.SetTransactionID("testString") + deleteAssignmentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteAssignmentOptionsModel).ToNot(BeNil()) + Expect(deleteAssignmentOptionsModel.AssignmentID).To(Equal(core.StringPtr("testString"))) + Expect(deleteAssignmentOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(deleteAssignmentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteTemplateOptions successfully`, func() { + // Construct an instance of the DeleteTemplateOptions model + templateID := "testString" + deleteTemplateOptionsModel := iamAccessGroupsService.NewDeleteTemplateOptions(templateID) + deleteTemplateOptionsModel.SetTemplateID("testString") + deleteTemplateOptionsModel.SetTransactionID("testString") + deleteTemplateOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteTemplateOptionsModel).ToNot(BeNil()) + Expect(deleteTemplateOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(deleteTemplateOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(deleteTemplateOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteTemplateVersionOptions successfully`, func() { + // Construct an instance of the DeleteTemplateVersionOptions model + templateID := "testString" + versionNum := "testString" + deleteTemplateVersionOptionsModel := iamAccessGroupsService.NewDeleteTemplateVersionOptions(templateID, versionNum) + deleteTemplateVersionOptionsModel.SetTemplateID("testString") + deleteTemplateVersionOptionsModel.SetVersionNum("testString") + deleteTemplateVersionOptionsModel.SetTransactionID("testString") + deleteTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteTemplateVersionOptionsModel).ToNot(BeNil()) + Expect(deleteTemplateVersionOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(deleteTemplateVersionOptionsModel.VersionNum).To(Equal(core.StringPtr("testString"))) + Expect(deleteTemplateVersionOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(deleteTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewGetAccessGroupOptions successfully`, func() { // Construct an instance of the GetAccessGroupOptions model accessGroupID := "testString" @@ -4806,6 +9398,47 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(getAccountSettingsOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) Expect(getAccountSettingsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewGetAssignmentOptions successfully`, func() { + // Construct an instance of the GetAssignmentOptions model + assignmentID := "testString" + getAssignmentOptionsModel := iamAccessGroupsService.NewGetAssignmentOptions(assignmentID) + getAssignmentOptionsModel.SetAssignmentID("testString") + getAssignmentOptionsModel.SetTransactionID("testString") + getAssignmentOptionsModel.SetVerbose(false) + getAssignmentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getAssignmentOptionsModel).ToNot(BeNil()) + Expect(getAssignmentOptionsModel.AssignmentID).To(Equal(core.StringPtr("testString"))) + Expect(getAssignmentOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(getAssignmentOptionsModel.Verbose).To(Equal(core.BoolPtr(false))) + Expect(getAssignmentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetLatestTemplateVersionOptions successfully`, func() { + // Construct an instance of the GetLatestTemplateVersionOptions model + templateID := "testString" + getLatestTemplateVersionOptionsModel := iamAccessGroupsService.NewGetLatestTemplateVersionOptions(templateID) + getLatestTemplateVersionOptionsModel.SetTemplateID("testString") + getLatestTemplateVersionOptionsModel.SetTransactionID("testString") + getLatestTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getLatestTemplateVersionOptionsModel).ToNot(BeNil()) + Expect(getLatestTemplateVersionOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(getLatestTemplateVersionOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(getLatestTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetTemplateVersionOptions successfully`, func() { + // Construct an instance of the GetTemplateVersionOptions model + templateID := "testString" + versionNum := "testString" + getTemplateVersionOptionsModel := iamAccessGroupsService.NewGetTemplateVersionOptions(templateID, versionNum) + getTemplateVersionOptionsModel.SetTemplateID("testString") + getTemplateVersionOptionsModel.SetVersionNum("testString") + getTemplateVersionOptionsModel.SetTransactionID("testString") + getTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getTemplateVersionOptionsModel).ToNot(BeNil()) + Expect(getTemplateVersionOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(getTemplateVersionOptionsModel.VersionNum).To(Equal(core.StringPtr("testString"))) + Expect(getTemplateVersionOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(getTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewIsMemberOfAccessGroupOptions successfully`, func() { // Construct an instance of the IsMemberOfAccessGroupOptions model accessGroupID := "testString" @@ -4829,7 +9462,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupMembersOptionsModel.SetTransactionID("testString") listAccessGroupMembersOptionsModel.SetMembershipType("static") listAccessGroupMembersOptionsModel.SetLimit(int64(10)) - listAccessGroupMembersOptionsModel.SetOffset(int64(38)) + listAccessGroupMembersOptionsModel.SetOffset(int64(0)) listAccessGroupMembersOptionsModel.SetType("testString") listAccessGroupMembersOptionsModel.SetVerbose(false) listAccessGroupMembersOptionsModel.SetSort("testString") @@ -4839,7 +9472,7 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(listAccessGroupMembersOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) Expect(listAccessGroupMembersOptionsModel.MembershipType).To(Equal(core.StringPtr("static"))) Expect(listAccessGroupMembersOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(10)))) - Expect(listAccessGroupMembersOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(38)))) + Expect(listAccessGroupMembersOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(0)))) Expect(listAccessGroupMembersOptionsModel.Type).To(Equal(core.StringPtr("testString"))) Expect(listAccessGroupMembersOptionsModel.Verbose).To(Equal(core.BoolPtr(false))) Expect(listAccessGroupMembersOptionsModel.Sort).To(Equal(core.StringPtr("testString"))) @@ -4864,9 +9497,10 @@ var _ = Describe(`IamAccessGroupsV2`, func() { listAccessGroupsOptionsModel.SetAccountID("testString") listAccessGroupsOptionsModel.SetTransactionID("testString") listAccessGroupsOptionsModel.SetIamID("testString") + listAccessGroupsOptionsModel.SetSearch("testString") listAccessGroupsOptionsModel.SetMembershipType("static") listAccessGroupsOptionsModel.SetLimit(int64(10)) - listAccessGroupsOptionsModel.SetOffset(int64(38)) + listAccessGroupsOptionsModel.SetOffset(int64(0)) listAccessGroupsOptionsModel.SetSort("name") listAccessGroupsOptionsModel.SetShowFederated(false) listAccessGroupsOptionsModel.SetHidePublicAccess(false) @@ -4875,14 +9509,56 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(listAccessGroupsOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) Expect(listAccessGroupsOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) Expect(listAccessGroupsOptionsModel.IamID).To(Equal(core.StringPtr("testString"))) + Expect(listAccessGroupsOptionsModel.Search).To(Equal(core.StringPtr("testString"))) Expect(listAccessGroupsOptionsModel.MembershipType).To(Equal(core.StringPtr("static"))) Expect(listAccessGroupsOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(10)))) - Expect(listAccessGroupsOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(38)))) + Expect(listAccessGroupsOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(0)))) Expect(listAccessGroupsOptionsModel.Sort).To(Equal(core.StringPtr("name"))) Expect(listAccessGroupsOptionsModel.ShowFederated).To(Equal(core.BoolPtr(false))) Expect(listAccessGroupsOptionsModel.HidePublicAccess).To(Equal(core.BoolPtr(false))) Expect(listAccessGroupsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewListAssignmentsOptions successfully`, func() { + // Construct an instance of the ListAssignmentsOptions model + listAssignmentsOptionsModel := iamAccessGroupsService.NewListAssignmentsOptions() + listAssignmentsOptionsModel.SetAccountID("accountID-123") + listAssignmentsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listAssignmentsOptionsModel).ToNot(BeNil()) + Expect(listAssignmentsOptionsModel.AccountID).To(Equal(core.StringPtr("accountID-123"))) + Expect(listAssignmentsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListTemplateVersionsOptions successfully`, func() { + // Construct an instance of the ListTemplateVersionsOptions model + templateID := "testString" + listTemplateVersionsOptionsModel := iamAccessGroupsService.NewListTemplateVersionsOptions(templateID) + listTemplateVersionsOptionsModel.SetTemplateID("testString") + listTemplateVersionsOptionsModel.SetLimit(int64(100)) + listTemplateVersionsOptionsModel.SetOffset(int64(0)) + listTemplateVersionsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listTemplateVersionsOptionsModel).ToNot(BeNil()) + Expect(listTemplateVersionsOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(listTemplateVersionsOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(100)))) + Expect(listTemplateVersionsOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(0)))) + Expect(listTemplateVersionsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListTemplatesOptions successfully`, func() { + // Construct an instance of the ListTemplatesOptions model + accountID := "accountID-123" + listTemplatesOptionsModel := iamAccessGroupsService.NewListTemplatesOptions(accountID) + listTemplatesOptionsModel.SetAccountID("accountID-123") + listTemplatesOptionsModel.SetTransactionID("testString") + listTemplatesOptionsModel.SetLimit(int64(50)) + listTemplatesOptionsModel.SetOffset(int64(0)) + listTemplatesOptionsModel.SetVerbose(true) + listTemplatesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listTemplatesOptionsModel).ToNot(BeNil()) + Expect(listTemplatesOptionsModel.AccountID).To(Equal(core.StringPtr("accountID-123"))) + Expect(listTemplatesOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) + Expect(listTemplatesOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(50)))) + Expect(listTemplatesOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(0)))) + Expect(listTemplatesOptionsModel.Verbose).To(Equal(core.BoolPtr(true))) + Expect(listTemplatesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewRemoveAccessGroupRuleOptions successfully`, func() { // Construct an instance of the RemoveAccessGroupRuleOptions model accessGroupID := "testString" @@ -5022,6 +9698,167 @@ var _ = Describe(`IamAccessGroupsV2`, func() { Expect(updateAccountSettingsOptionsModel.TransactionID).To(Equal(core.StringPtr("testString"))) Expect(updateAccountSettingsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewUpdateAssignmentOptions successfully`, func() { + // Construct an instance of the UpdateAssignmentOptions model + assignmentID := "testString" + ifMatch := "testString" + updateAssignmentOptionsModel := iamAccessGroupsService.NewUpdateAssignmentOptions(assignmentID, ifMatch) + updateAssignmentOptionsModel.SetAssignmentID("testString") + updateAssignmentOptionsModel.SetIfMatch("testString") + updateAssignmentOptionsModel.SetTemplateVersion("1") + updateAssignmentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(updateAssignmentOptionsModel).ToNot(BeNil()) + Expect(updateAssignmentOptionsModel.AssignmentID).To(Equal(core.StringPtr("testString"))) + Expect(updateAssignmentOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) + Expect(updateAssignmentOptionsModel.TemplateVersion).To(Equal(core.StringPtr("1"))) + Expect(updateAssignmentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewUpdateTemplateVersionOptions successfully`, func() { + // Construct an instance of the MembersActionControls model + membersActionControlsModel := new(iamaccessgroupsv2.MembersActionControls) + Expect(membersActionControlsModel).ToNot(BeNil()) + membersActionControlsModel.Add = core.BoolPtr(true) + membersActionControlsModel.Remove = core.BoolPtr(false) + Expect(membersActionControlsModel.Add).To(Equal(core.BoolPtr(true))) + Expect(membersActionControlsModel.Remove).To(Equal(core.BoolPtr(false))) + + // Construct an instance of the MembersInput model + membersInputModel := new(iamaccessgroupsv2.MembersInput) + Expect(membersInputModel).ToNot(BeNil()) + membersInputModel.Users = []string{"IBMid-665000T8WY"} + membersInputModel.ServiceIds = []string{"testString"} + membersInputModel.ActionControls = membersActionControlsModel + Expect(membersInputModel.Users).To(Equal([]string{"IBMid-665000T8WY"})) + Expect(membersInputModel.ServiceIds).To(Equal([]string{"testString"})) + Expect(membersInputModel.ActionControls).To(Equal(membersActionControlsModel)) + + // Construct an instance of the ConditionInput model + conditionInputModel := new(iamaccessgroupsv2.ConditionInput) + Expect(conditionInputModel).ToNot(BeNil()) + conditionInputModel.Claim = core.StringPtr("blueGroup") + conditionInputModel.Operator = core.StringPtr("CONTAINS") + conditionInputModel.Value = core.StringPtr(`"test-bluegroup-saml"`) + Expect(conditionInputModel.Claim).To(Equal(core.StringPtr("blueGroup"))) + Expect(conditionInputModel.Operator).To(Equal(core.StringPtr("CONTAINS"))) + Expect(conditionInputModel.Value).To(Equal(core.StringPtr(`"test-bluegroup-saml"`))) + + // Construct an instance of the RulesActionControls model + rulesActionControlsModel := new(iamaccessgroupsv2.RulesActionControls) + Expect(rulesActionControlsModel).ToNot(BeNil()) + rulesActionControlsModel.Remove = core.BoolPtr(false) + rulesActionControlsModel.Update = core.BoolPtr(false) + Expect(rulesActionControlsModel.Remove).To(Equal(core.BoolPtr(false))) + Expect(rulesActionControlsModel.Update).To(Equal(core.BoolPtr(false))) + + // Construct an instance of the RuleInput model + ruleInputModel := new(iamaccessgroupsv2.RuleInput) + Expect(ruleInputModel).ToNot(BeNil()) + ruleInputModel.Name = core.StringPtr("Manager group rule") + ruleInputModel.Expiration = core.Int64Ptr(int64(12)) + ruleInputModel.RealmName = core.StringPtr("https://idp.example.org/SAML2") + ruleInputModel.Conditions = []iamaccessgroupsv2.ConditionInput{*conditionInputModel} + ruleInputModel.ActionControls = rulesActionControlsModel + Expect(ruleInputModel.Name).To(Equal(core.StringPtr("Manager group rule"))) + Expect(ruleInputModel.Expiration).To(Equal(core.Int64Ptr(int64(12)))) + Expect(ruleInputModel.RealmName).To(Equal(core.StringPtr("https://idp.example.org/SAML2"))) + Expect(ruleInputModel.Conditions).To(Equal([]iamaccessgroupsv2.ConditionInput{*conditionInputModel})) + Expect(ruleInputModel.ActionControls).To(Equal(rulesActionControlsModel)) + + // Construct an instance of the AssertionsActionControls model + assertionsActionControlsModel := new(iamaccessgroupsv2.AssertionsActionControls) + Expect(assertionsActionControlsModel).ToNot(BeNil()) + assertionsActionControlsModel.Add = core.BoolPtr(false) + assertionsActionControlsModel.Remove = core.BoolPtr(true) + assertionsActionControlsModel.Update = core.BoolPtr(true) + Expect(assertionsActionControlsModel.Add).To(Equal(core.BoolPtr(false))) + Expect(assertionsActionControlsModel.Remove).To(Equal(core.BoolPtr(true))) + Expect(assertionsActionControlsModel.Update).To(Equal(core.BoolPtr(true))) + + // Construct an instance of the AssertionsInput model + assertionsInputModel := new(iamaccessgroupsv2.AssertionsInput) + Expect(assertionsInputModel).ToNot(BeNil()) + assertionsInputModel.Rules = []iamaccessgroupsv2.RuleInput{*ruleInputModel} + assertionsInputModel.ActionControls = assertionsActionControlsModel + Expect(assertionsInputModel.Rules).To(Equal([]iamaccessgroupsv2.RuleInput{*ruleInputModel})) + Expect(assertionsInputModel.ActionControls).To(Equal(assertionsActionControlsModel)) + + // Construct an instance of the AccessActionControls model + accessActionControlsModel := new(iamaccessgroupsv2.AccessActionControls) + Expect(accessActionControlsModel).ToNot(BeNil()) + accessActionControlsModel.Add = core.BoolPtr(false) + Expect(accessActionControlsModel.Add).To(Equal(core.BoolPtr(false))) + + // Construct an instance of the GroupActionControls model + groupActionControlsModel := new(iamaccessgroupsv2.GroupActionControls) + Expect(groupActionControlsModel).ToNot(BeNil()) + groupActionControlsModel.Access = accessActionControlsModel + Expect(groupActionControlsModel.Access).To(Equal(accessActionControlsModel)) + + // Construct an instance of the AccessGroupInput model + accessGroupInputModel := new(iamaccessgroupsv2.AccessGroupInput) + Expect(accessGroupInputModel).ToNot(BeNil()) + accessGroupInputModel.Name = core.StringPtr("IAM Admin Group 8") + accessGroupInputModel.Description = core.StringPtr("This access group template allows admin access to all IAM platform services in the account.") + accessGroupInputModel.Members = membersInputModel + accessGroupInputModel.Assertions = assertionsInputModel + accessGroupInputModel.ActionControls = groupActionControlsModel + Expect(accessGroupInputModel.Name).To(Equal(core.StringPtr("IAM Admin Group 8"))) + Expect(accessGroupInputModel.Description).To(Equal(core.StringPtr("This access group template allows admin access to all IAM platform services in the account."))) + Expect(accessGroupInputModel.Members).To(Equal(membersInputModel)) + Expect(accessGroupInputModel.Assertions).To(Equal(assertionsInputModel)) + Expect(accessGroupInputModel.ActionControls).To(Equal(groupActionControlsModel)) + + // Construct an instance of the PolicyTemplatesInput model + policyTemplatesInputModel := new(iamaccessgroupsv2.PolicyTemplatesInput) + Expect(policyTemplatesInputModel).ToNot(BeNil()) + policyTemplatesInputModel.ID = core.StringPtr("policyTemplateId-123") + policyTemplatesInputModel.Version = core.StringPtr("1") + Expect(policyTemplatesInputModel.ID).To(Equal(core.StringPtr("policyTemplateId-123"))) + Expect(policyTemplatesInputModel.Version).To(Equal(core.StringPtr("1"))) + + // Construct an instance of the UpdateTemplateVersionOptions model + templateID := "testString" + versionNum := "testString" + ifMatch := "testString" + updateTemplateVersionOptionsModel := iamAccessGroupsService.NewUpdateTemplateVersionOptions(templateID, versionNum, ifMatch) + updateTemplateVersionOptionsModel.SetTemplateID("testString") + updateTemplateVersionOptionsModel.SetVersionNum("testString") + updateTemplateVersionOptionsModel.SetIfMatch("testString") + updateTemplateVersionOptionsModel.SetID("testString") + updateTemplateVersionOptionsModel.SetName("IAM Admin Group template 2") + updateTemplateVersionOptionsModel.SetDescription("This access group template allows admin access to all IAM platform services in the account.") + updateTemplateVersionOptionsModel.SetAccountID("testString") + updateTemplateVersionOptionsModel.SetVersion("testString") + updateTemplateVersionOptionsModel.SetCommitted(true) + updateTemplateVersionOptionsModel.SetGroup(accessGroupInputModel) + updateTemplateVersionOptionsModel.SetPolicyTemplateReferences([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel}) + updateTemplateVersionOptionsModel.SetHref("testString") + updateTemplateVersionOptionsModel.SetCreatedAt(CreateMockDateTime("2019-01-01T12:00:00.000Z")) + updateTemplateVersionOptionsModel.SetCreatedByID("testString") + updateTemplateVersionOptionsModel.SetLastModifiedAt(CreateMockDateTime("2019-01-01T12:00:00.000Z")) + updateTemplateVersionOptionsModel.SetLastModifiedByID("testString") + updateTemplateVersionOptionsModel.SetTransactionID("83adf5bd-de790caa3") + updateTemplateVersionOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(updateTemplateVersionOptionsModel).ToNot(BeNil()) + Expect(updateTemplateVersionOptionsModel.TemplateID).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.VersionNum).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.ID).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.Name).To(Equal(core.StringPtr("IAM Admin Group template 2"))) + Expect(updateTemplateVersionOptionsModel.Description).To(Equal(core.StringPtr("This access group template allows admin access to all IAM platform services in the account."))) + Expect(updateTemplateVersionOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.Version).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.Committed).To(Equal(core.BoolPtr(true))) + Expect(updateTemplateVersionOptionsModel.Group).To(Equal(accessGroupInputModel)) + Expect(updateTemplateVersionOptionsModel.PolicyTemplateReferences).To(Equal([]iamaccessgroupsv2.PolicyTemplatesInput{*policyTemplatesInputModel})) + Expect(updateTemplateVersionOptionsModel.Href).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.CreatedAt).To(Equal(CreateMockDateTime("2019-01-01T12:00:00.000Z"))) + Expect(updateTemplateVersionOptionsModel.CreatedByID).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.LastModifiedAt).To(Equal(CreateMockDateTime("2019-01-01T12:00:00.000Z"))) + Expect(updateTemplateVersionOptionsModel.LastModifiedByID).To(Equal(core.StringPtr("testString"))) + Expect(updateTemplateVersionOptionsModel.TransactionID).To(Equal(core.StringPtr("83adf5bd-de790caa3"))) + Expect(updateTemplateVersionOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) }) }) Describe(`Utility function tests`, func() {