diff --git a/examples/iam-policy-management.v1.test.js b/examples/iam-policy-management.v1.test.js index e529efb..3200374 100644 --- a/examples/iam-policy-management.v1.test.js +++ b/examples/iam-policy-management.v1.test.js @@ -70,12 +70,18 @@ describe('IamPolicyManagementV1', () => { const exampleCustomRoleDipslayName = 'IAM Groups read access'; const exampleUserId = 'IBMid-user1'; const exampleServiceName = 'iam-groups'; + const exampleRoleTemplateName = 'RoleTemplateNodeSDKTest'; let exampleActionControlTemplateId; let exampleActionControlBaseVersion; let exampleActionControlTemplateEtag; let exampleActionControlTemplateVersion; - let exampleActionControlAssignmentId; + let exampleActionControlAssignmentId; let exampleActionControlAssignmentETag; + let exampleRoleTemplateId; + let exampleRoleTemplateEtag; + let exampleRoleTemplateVersion; + let exampleRoleAssignmentId; + let exampleRoleAssignmentETag; // begin-common @@ -1873,4 +1879,471 @@ describe('IamPolicyManagementV1', () => { } // end-update_access_management_account_settings }); + + /* Start - Custom Role Templates Examples */ + + test('createRoleTemplate request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('createRoleTemplate() result:'); + // begin-create_role_template + + const params = { + name: exampleRoleTemplateName, + accountId: exampleAccountId, + }; + + let res; + try { + res = await iamPolicyManagementService.createRoleTemplate(params); + exampleRoleTemplateId = res.result.id; + exampleRoleTemplateVersion = res.result.version; + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-create_role_template + }); + test('getRoleTemplate request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('getRoleTemplate() result:'); + // begin-get_role_template + + const params = { + roleTemplateId: exampleRoleTemplateId, + }; + + let res; + try { + res = await iamPolicyManagementService.getRoleTemplate(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + exampleRoleTemplateEtag = res.headers.etag; + + // end-get_role_template + }); + test('replaceRoleTemplate request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('replaceRoleTemplate() result:'); + // begin-replace_role_template + + // Request models needed by this operation. + + // TemplateRole + const templateRoleModel = { + name: 'GOSDKTestRoleReplace', + display_name: 'GOSDKTestRoleReplaceDisplay', + service_name: 'am-test-service', + actions: ['am-test-service.test.delete'], + }; + + const params = { + roleTemplateId: exampleRoleTemplateId, + version: exampleRoleTemplateVersion, + ifMatch: exampleRoleTemplateEtag, + role: templateRoleModel, + }; + + let res; + try { + res = await iamPolicyManagementService.replaceRoleTemplate(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-replace_role_template + }); + test('listRoleTemplates request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('listRoleTemplates() result:'); + // begin-list_role_templates + + const params = { + accountId: exampleAccountId, + state: 'active', + }; + + const allResults = []; + try { + const pager = new IamPolicyManagementV1.RoleTemplatesPager(iamPolicyManagementService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + console.log(JSON.stringify(allResults, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-list_role_templates + }); + test('createRoleTemplateVersion request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('createRoleTemplateVersion() result:'); + // begin-create_role_template_version + + // Request models needed by this operation. + + // TemplateRole + const templateRoleModel = { + name: 'GOSDKTestRoleVersionTemplate', + display_name: 'GOSDKTestRoleVersionTemplateDisplay', + service_name: 'am-test-service', + actions: ['am-test-service.test.create'], + }; + + const params = { + roleTemplateId: exampleRoleTemplateId, + role: templateRoleModel, + }; + + let res; + try { + res = await iamPolicyManagementService.createRoleTemplateVersion(params); + exampleRoleTemplateVersion = res.result.version; + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-create_role_template_version + }); + test('listRoleTemplateVersions request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('listRoleTemplateVersions() result:'); + // begin-list_role_template_versions + + const params = { + roleTemplateId: exampleRoleTemplateId, + state: 'active', + limit: 10, + }; + + const allResults = []; + try { + const pager = new IamPolicyManagementV1.RoleTemplateVersionsPager(iamPolicyManagementService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + console.log(JSON.stringify(allResults, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-list_role_template_versions + }); + test('getRoleTemplateVersion request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('getRoleTemplateVersion() result:'); + // begin-get_role_template_version + + const params = { + roleTemplateId: exampleRoleTemplateId, + version: exampleRoleTemplateVersion, + }; + + let res; + try { + res = await iamPolicyManagementService.getRoleTemplateVersion(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-get_role_template_version + }); + test('commitRoleTemplate request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + // begin-commit_role_template + + const params = { + roleTemplateId: exampleRoleTemplateId, + version: exampleRoleTemplateVersion, + }; + + try { + await iamPolicyManagementService.commitRoleTemplate(params); + } catch (err) { + console.warn(err); + } + + // end-commit_role_template + }); + test('createRoleTemplateAssignment request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('createRoleTemplateAssignment() result:'); + // begin-create_role_template_assignment + + // Request models needed by this operation. + + // AssignmentTargetDetails + const assignmentTargetDetailsModel = { + type: 'Account', + id: exampleTargetAccountId, + }; + + // RoleAssignmentTemplate + const roleAssignmentTemplateModel = { + id: exampleRoleTemplateId, + version: exampleRoleTemplateVersion, + }; + + const params = { + target: assignmentTargetDetailsModel, + templates: [roleAssignmentTemplateModel], + }; + + let res; + try { + res = await iamPolicyManagementService.createRoleTemplateAssignment(params); + exampleRoleAssignmentId = res.result.assignments[0].id; + exampleRoleAssignmentETag = res.headers.etag; + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-create_role_template_assignment + }); + test('listRoleAssignments request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('listRoleAssignments() result:'); + // begin-list_role_assignments + + const params = { + accountId: exampleAccountId, + }; + + const allResults = []; + try { + const pager = new IamPolicyManagementV1.RoleAssignmentsPager(iamPolicyManagementService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + console.log(JSON.stringify(allResults, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-list_role_assignments + }); + test('getRoleAssignment request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('getRoleAssignment() result:'); + // begin-get_role_assignment + + const params = { + assignmentId: exampleRoleAssignmentId, + }; + + let res; + try { + res = await iamPolicyManagementService.getRoleAssignment(params); + console.log(JSON.stringify(res.result, null, 2)); + exampleRoleTemplateEtag = res.headers.etag; + } catch (err) { + console.warn(err); + } + + // end-get_role_assignment + }); + test('updateRoleAssignment request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('updateRoleAssignment() result:'); + // begin-update_role_assignment + + const params = { + assignmentId: exampleRoleAssignmentId, + ifMatch: exampleRoleAssignmentETag, + templateVersion: exampleRoleTemplateVersion, + }; + + let res; + try { + res = await iamPolicyManagementService.updateRoleAssignment(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-update_role_assignment + }); + test('deleteRoleAssignment request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + // begin-delete_role_assignment + + const params = { + assignmentId: exampleRoleAssignmentId, + }; + + try { + await iamPolicyManagementService.deleteRoleAssignment(params); + } catch (err) { + console.warn(err); + } + + // end-delete_role_assignment + }); + test('deleteRoleTemplateVersion request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + // begin-delete_role_template_version + + const params = { + roleTemplateId: exampleRoleTemplateId, + version: exampleRoleTemplateVersion, + }; + + try { + await iamPolicyManagementService.deleteRoleTemplateVersion(params); + } catch (err) { + console.warn(err); + } + + // end-delete_role_template_version + }); + test('deleteRoleTemplate request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + // begin-delete_role_template + + const params = { + roleTemplateId: exampleRoleTemplateId, + }; + + try { + await iamPolicyManagementService.deleteRoleTemplate(params); + } catch (err) { + console.warn(err); + } + + // end-delete_role_template + }); + /* End - Custom Role Templates Examples */ }); diff --git a/iam-policy-management/v1.ts b/iam-policy-management/v1.ts index 8a88989..b362d34 100644 --- a/iam-policy-management/v1.ts +++ b/iam-policy-management/v1.ts @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.103.0-e8b84313-20250402-201816 + * IBM OpenAPI SDK Code Generator Version: 3.107.1-41b0fbd0-20250825-080732 */ /* eslint-disable max-classes-per-file */ @@ -3970,6 +3970,1043 @@ class IamPolicyManagementV1 extends BaseService { }), }; + return this.createRequest(parameters); + } + /************************* + * roleTemplates + ************************/ + + /** + * List role templates by attributes. + * + * List role templates and filter by attributes by using query parameters. The following attributes are supported: + * `account_id`, `name`, `role_name`, `role_service_name`, `state`, `limit`, `start`. + * `account_id` is a required query parameter. Only role templates that have the specified attributes and that the + * caller has read access to are returned. If the caller does not have read access to any role templates an empty + * array is returned. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - The account GUID that the role templates belong to. + * @param {string} [params.acceptLanguage] - Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + * @param {string} [params.name] - The role template name. + * @param {string} [params.roleName] - The template role name. + * @param {string} [params.roleServiceName] - The template role service name. + * @param {string} [params.state] - The role template state. + * @param {number} [params.limit] - The number of documents to include in the collection. + * @param {string} [params.start] - Page token that refers to the page of the collection to return. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public listRoleTemplates( + params: IamPolicyManagementV1.ListRoleTemplatesParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId']; + const _validParams = [ + 'accountId', + 'acceptLanguage', + 'name', + 'roleName', + 'roleServiceName', + 'state', + 'limit', + 'start', + 'signal', + 'headers', + ]; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'account_id': _params.accountId, + 'name': _params.name, + 'role_name': _params.roleName, + 'role_service_name': _params.roleServiceName, + 'state': _params.state, + 'limit': _params.limit, + 'start': _params.start, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'listRoleTemplates' + ); + + const parameters = { + options: { + url: '/v1/role_templates', + method: 'GET', + qs: query, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Accept-Language': _params.acceptLanguage, + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Create role template. + * + * Create a role template. Role templates define roles from an existing system or service defined role. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.name - Required field when creating a new template. Otherwise, this field is optional. If + * the field is included, it changes the name value for all existing versions of the template. + * @param {string} params.accountId - Enterprise account ID where this template is created. + * @param {string} [params.description] - Description of the role template. This is shown to users in the enterprise + * account. Use this to describe the purpose or context of the role for enterprise users managing IAM templates. + * @param {boolean} [params.committed] - Committed status of the template. If committed is set to true, then the + * template version can no longer be updated. + * @param {TemplateRole} [params.role] - The role properties that are created in an action resource when the template + * is assigned. + * @param {string} [params.acceptLanguage] - Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createRoleTemplate( + params: IamPolicyManagementV1.CreateRoleTemplateParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['name', 'accountId']; + const _validParams = [ + 'name', + 'accountId', + 'description', + 'committed', + 'role', + 'acceptLanguage', + 'signal', + 'headers', + ]; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'name': _params.name, + 'account_id': _params.accountId, + 'description': _params.description, + 'committed': _params.committed, + 'role': _params.role, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'createRoleTemplate' + ); + + const parameters = { + options: { + url: '/v1/role_templates', + method: 'POST', + body, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Accept-Language': _params.acceptLanguage, + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Retrieve the latest version of a role template. + * + * Retrieve the latest version of a role template by providing a role template ID. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.roleTemplateId - Role template ID. + * @param {string} [params.state] - The role template state. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getRoleTemplate( + params: IamPolicyManagementV1.GetRoleTemplateParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['roleTemplateId']; + const _validParams = ['roleTemplateId', 'state', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'state': _params.state, + }; + + const path = { + 'role_template_id': _params.roleTemplateId, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'getRoleTemplate' + ); + + const parameters = { + options: { + url: '/v1/role_templates/{role_template_id}', + method: 'GET', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Delete a Role template. + * + * Delete a role template by providing the role template ID. This deletes all versions of this template. A role + * template can't be deleted if any version of the template is assigned to one or more child accounts. You must remove + * the role assignments first. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.roleTemplateId - Role template ID. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteRoleTemplate( + params: IamPolicyManagementV1.DeleteRoleTemplateParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['roleTemplateId']; + const _validParams = ['roleTemplateId', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'role_template_id': _params.roleTemplateId, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'deleteRoleTemplate' + ); + + const parameters = { + options: { + url: '/v1/role_templates/{role_template_id}', + method: 'DELETE', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend(true, sdkHeaders, this.baseOptions.headers, {}, _params.headers), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Create a new role template version. + * + * Create a new version of a role template. Use this if you need to make updates to a role template that is committed. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.roleTemplateId - The role template ID. + * @param {TemplateRole} params.role - The role properties that are created in an action resource when the template is + * assigned. + * @param {string} [params.name] - Required field when creating a new template. Otherwise, this field is optional. If + * the field is included, it will change the name value for all existing versions of the template. + * @param {string} [params.description] - Description of the role template. This is shown to users in the enterprise + * account. Use this to describe the purpose or context of the role for enterprise users managing IAM templates. + * @param {boolean} [params.committed] - Committed status of the template version. If committed is set to true, then + * the template version can no longer be updated. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createRoleTemplateVersion( + params: IamPolicyManagementV1.CreateRoleTemplateVersionParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['roleTemplateId', 'role']; + const _validParams = [ + 'roleTemplateId', + 'role', + 'name', + 'description', + 'committed', + 'signal', + 'headers', + ]; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'role': _params.role, + 'name': _params.name, + 'description': _params.description, + 'committed': _params.committed, + }; + + const path = { + 'role_template_id': _params.roleTemplateId, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'createRoleTemplateVersion' + ); + + const parameters = { + options: { + url: '/v1/role_templates/{role_template_id}/versions', + method: 'POST', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Retrieve role template versions. + * + * Retrieve the versions of a role template by providing a role template ID. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.roleTemplateId - The role template ID. + * @param {string} [params.state] - Role template state. + * @param {number} [params.limit] - The number of documents to include in the collection. + * @param {string} [params.start] - Page token that refers to the page of the collection to return. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public listRoleTemplateVersions( + params: IamPolicyManagementV1.ListRoleTemplateVersionsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['roleTemplateId']; + const _validParams = ['roleTemplateId', 'state', 'limit', 'start', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'state': _params.state, + 'limit': _params.limit, + 'start': _params.start, + }; + + const path = { + 'role_template_id': _params.roleTemplateId, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'listRoleTemplateVersions' + ); + + const parameters = { + options: { + url: '/v1/role_templates/{role_template_id}/versions', + method: 'GET', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Update a role template version. + * + * Update a specific version of a role template. You can use this only if the version isn't committed. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.roleTemplateId - Role template ID. + * @param {string} params.version - Role template version. + * @param {string} params.ifMatch - The revision number for updating a role template version must match the Etag value + * of the existing role template version. The Etag can be retrieved using the GET + * /v1/role_templates/{template_id}/versions/{version} API and looking at the Etag response header. + * @param {TemplateRole} params.role - The role properties that are created in an action resource when the template is + * assigned. + * @param {string} [params.name] - Required field when creating a new template. Otherwise, this field is optional. If + * the field is included, it will change the name value for all existing versions of the template. + * @param {string} [params.description] - Description of the role template. This is shown to users in the enterprise + * account. Use this to describe the purpose or context of the role for enterprise users managing IAM templates. + * @param {boolean} [params.committed] - Committed status of the template version. If committed is set to true, then + * the template version can no longer be updated. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public replaceRoleTemplate( + params: IamPolicyManagementV1.ReplaceRoleTemplateParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['roleTemplateId', 'version', 'ifMatch', 'role']; + const _validParams = [ + 'roleTemplateId', + 'version', + 'ifMatch', + 'role', + 'name', + 'description', + 'committed', + 'signal', + 'headers', + ]; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'role': _params.role, + 'name': _params.name, + 'description': _params.description, + 'committed': _params.committed, + }; + + const path = { + 'role_template_id': _params.roleTemplateId, + 'version': _params.version, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'replaceRoleTemplate' + ); + + const parameters = { + options: { + url: '/v1/role_templates/{role_template_id}/versions/{version}', + method: 'PUT', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'If-Match': _params.ifMatch, + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Delete a role template version. + * + * Delete a specific version of a role template by providing a role template ID and version number. You can't delete a + * role template version that is assigned to one or more child accounts. You must remove the role assignments first. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.roleTemplateId - Role template ID. + * @param {string} params.version - Role template version. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteRoleTemplateVersion( + params: IamPolicyManagementV1.DeleteRoleTemplateVersionParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['roleTemplateId', 'version']; + const _validParams = ['roleTemplateId', 'version', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'role_template_id': _params.roleTemplateId, + 'version': _params.version, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'deleteRoleTemplateVersion' + ); + + const parameters = { + options: { + url: '/v1/role_templates/{role_template_id}/versions/{version}', + method: 'DELETE', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend(true, sdkHeaders, this.baseOptions.headers, {}, _params.headers), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Retrieve a role template version. + * + * Retrieve a role template by providing a role template ID and version number. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.roleTemplateId - Role template ID. + * @param {string} params.version - Role template version. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getRoleTemplateVersion( + params: IamPolicyManagementV1.GetRoleTemplateVersionParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['roleTemplateId', 'version']; + const _validParams = ['roleTemplateId', 'version', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'role_template_id': _params.roleTemplateId, + 'version': _params.version, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'getRoleTemplateVersion' + ); + + const parameters = { + options: { + url: '/v1/role_templates/{role_template_id}/versions/{version}', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Commit a role template version. + * + * Commit a role template version. You cannot make any further changes to the role template once it's committed. If + * you have to make updates after committing a version, create a new version. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.roleTemplateId - Role template ID. + * @param {string} params.version - The role template version. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public commitRoleTemplate( + params: IamPolicyManagementV1.CommitRoleTemplateParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['roleTemplateId', 'version']; + const _validParams = ['roleTemplateId', 'version', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'role_template_id': _params.roleTemplateId, + 'version': _params.version, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'commitRoleTemplate' + ); + + const parameters = { + options: { + url: '/v1/role_templates/{role_template_id}/versions/{version}/commit', + method: 'POST', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend(true, sdkHeaders, this.baseOptions.headers, {}, _params.headers), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + /************************* + * roleAssignments + ************************/ + + /** + * Get role template assignments. + * + * Get role template assignments by attributes. The following attributes are supported: + * `account_id`, `template_id`, `template_version`, `target`, `target_type`, `limit`, `start`. + * `account_id` is a required query parameter. Only role template assignments with the specified attributes and + * accessible by the caller are returned. If the caller does not have read access to any role template assignments, an + * empty array is returned. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - The account GUID in which the role assignment belongs to. + * @param {string} [params.acceptLanguage] - Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + * @param {string} [params.templateId] - Optional template ID. + * @param {string} [params.templateVersion] - Optional role template version. + * @param {number} [params.limit] - The number of documents to include in the collection. + * @param {string} [params.start] - Page token that refers to the page of the collection to return. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public listRoleAssignments( + params: IamPolicyManagementV1.ListRoleAssignmentsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId']; + const _validParams = [ + 'accountId', + 'acceptLanguage', + 'templateId', + 'templateVersion', + 'limit', + 'start', + 'signal', + 'headers', + ]; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'account_id': _params.accountId, + 'template_id': _params.templateId, + 'template_version': _params.templateVersion, + 'limit': _params.limit, + 'start': _params.start, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'listRoleAssignments' + ); + + const parameters = { + options: { + url: '/v1/role_assignments', + method: 'GET', + qs: query, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Accept-Language': _params.acceptLanguage, + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Create a role template assignment. + * + * Assign a role template to child accounts and account groups. This creates the role in the accounts and account + * groups that you specify. + * + * @param {Object} params - The parameters to send to the service. + * @param {AssignmentTargetDetails} params.target - assignment target account and type. + * @param {RoleAssignmentTemplate[]} params.templates - List of role template details for role assignment. + * @param {string} [params.acceptLanguage] - Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createRoleTemplateAssignment( + params: IamPolicyManagementV1.CreateRoleTemplateAssignmentParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['target', 'templates']; + const _validParams = ['target', 'templates', 'acceptLanguage', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'target': _params.target, + 'templates': _params.templates, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'createRoleTemplateAssignment' + ); + + const parameters = { + options: { + url: '/v1/role_assignments', + method: 'POST', + body, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Accept-Language': _params.acceptLanguage, + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Retrieve a role assignment. + * + * Retrieve a role template assignment by providing a role assignment ID. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.assignmentId - Role template assignment ID. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getRoleAssignment( + params: IamPolicyManagementV1.GetRoleAssignmentParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['assignmentId']; + const _validParams = ['assignmentId', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'assignment_id': _params.assignmentId, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'getRoleAssignment' + ); + + const parameters = { + options: { + url: '/v1/role_assignments/{assignment_id}', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Update a role assignment. + * + * Update a role assignment by providing a role assignment ID. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.assignmentId - Role template assignment ID. + * @param {string} params.ifMatch - The revision number for updating a role assignment and must match the Etag value + * of the existing role assignment. The Etag can be retrieved using the GET /v1/role_assignments/{assignment_id} API + * and looking at the Etag response header. + * @param {string} params.templateVersion - The version number of the template used to identify different versions of + * same template. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public updateRoleAssignment( + params: IamPolicyManagementV1.UpdateRoleAssignmentParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['assignmentId', 'ifMatch', 'templateVersion']; + const _validParams = ['assignmentId', 'ifMatch', 'templateVersion', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'template_version': _params.templateVersion, + }; + + const path = { + 'assignment_id': _params.assignmentId, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'updateRoleAssignment' + ); + + const parameters = { + options: { + url: '/v1/role_assignments/{assignment_id}', + method: 'PATCH', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + this.baseOptions.headers, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'If-Match': _params.ifMatch, + }, + _params.headers + ), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + + return this.createRequest(parameters); + } + + /** + * Remove a role assignment. + * + * Remove a role template assignment by providing a role assignment ID. You can't delete a role assignment if the + * status is "in_progress". + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.assignmentId - Role template assignment ID. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteRoleAssignment( + params: IamPolicyManagementV1.DeleteRoleAssignmentParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['assignmentId']; + const _validParams = ['assignmentId', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'assignment_id': _params.assignmentId, + }; + + const sdkHeaders = getSdkHeaders( + IamPolicyManagementV1.DEFAULT_SERVICE_NAME, + 'v1', + 'deleteRoleAssignment' + ); + + const parameters = { + options: { + url: '/v1/role_assignments/{assignment_id}', + method: 'DELETE', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend(true, sdkHeaders, this.baseOptions.headers, {}, _params.headers), + axiosOptions: { + signal: _params.signal, + }, + }), + }; + return this.createRequest(parameters); } } @@ -4753,36 +5790,284 @@ namespace IamPolicyManagementV1 { acceptLanguage?: string; } - /** Parameters for the `updateSettings` operation. */ - export interface UpdateSettingsParams extends DefaultParams { - /** The account GUID that the settings belong to. */ - accountId: string; - /** The revision number for updating Access Management Account Settings and must match the Etag value of the - * existing Access Management Account Settings. The Etag can be retrieved using the GET - * /v1/accounts/{account_id}/settings/access_management API and looking at the Etag response header. + /** Parameters for the `updateSettings` operation. */ + export interface UpdateSettingsParams extends DefaultParams { + /** The account GUID that the settings belong to. */ + accountId: string; + /** The revision number for updating Access Management Account Settings and must match the Etag value of the + * existing Access Management Account Settings. The Etag can be retrieved using the GET + * /v1/accounts/{account_id}/settings/access_management API and looking at the Etag response header. + */ + ifMatch: string; + /** Update to how external accounts can interact in relation to the requested account. */ + externalAccountIdentityInteraction?: ExternalAccountIdentityInteractionPatch; + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ + acceptLanguage?: string; + } + + /** Parameters for the `listActionControlTemplates` operation. */ + export interface ListActionControlTemplatesParams extends DefaultParams { + /** The account GUID that the action control templates belong to. */ + accountId: string; + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ + acceptLanguage?: string; + /** The number of documents to include in the collection. */ + limit?: number; + /** Page token that refers to the page of the collection to return. */ + start?: string; + } + + /** Parameters for the `createActionControlTemplate` operation. */ + export interface CreateActionControlTemplateParams extends DefaultParams { + /** Required field when creating a new template. Otherwise, this field is optional. If the field is included, it + * changes the name value for all existing versions of the template. + */ + name: string; + /** Enterprise account ID where this template is created. */ + accountId: string; + /** Description of the action control template. This is shown to users in the enterprise account. Use this to + * describe the purpose or context of the action control for enterprise users managing IAM templates. + */ + description?: string; + /** Committed status of the template. If committed is set to true, then the template version can no longer be + * updated. + */ + committed?: boolean; + /** The action control properties that are created in an action resource when the template is assigned. */ + actionControl?: TemplateActionControl; + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ + acceptLanguage?: string; + } + + /** Parameters for the `getActionControlTemplate` operation. */ + export interface GetActionControlTemplateParams extends DefaultParams { + /** Action control template ID. */ + actionControlTemplateId: string; + /** The action control template state. */ + state?: GetActionControlTemplateConstants.State | string; + } + + /** Constants for the `getActionControlTemplate` operation. */ + export namespace GetActionControlTemplateConstants { + /** The action control template state. */ + export enum State { + ACTIVE = 'active', + DELETED = 'deleted', + } + } + + /** Parameters for the `deleteActionControlTemplate` operation. */ + export interface DeleteActionControlTemplateParams extends DefaultParams { + /** Action control template ID. */ + actionControlTemplateId: string; + } + + /** Parameters for the `createActionControlTemplateVersion` operation. */ + export interface CreateActionControlTemplateVersionParams extends DefaultParams { + /** The action control template ID. */ + actionControlTemplateId: string; + /** Required field when creating a new template. Otherwise, this field is optional. If the field is included, it + * will change the name value for all existing versions of the template. + */ + name?: string; + /** Description of the action control template. This is shown to users in the enterprise account. Use this to + * describe the purpose or context of the action control for enterprise users managing IAM templates. + */ + description?: string; + /** The action control properties that are created in an action resource when the template is assigned. */ + actionControl?: TemplateActionControl; + /** Committed status of the template version. If committed is set to true, then the template version can no + * longer be updated. + */ + committed?: boolean; + } + + /** Parameters for the `listActionControlTemplateVersions` operation. */ + export interface ListActionControlTemplateVersionsParams extends DefaultParams { + /** The action control template ID. */ + actionControlTemplateId: string; + /** Action control template state. */ + state?: ListActionControlTemplateVersionsConstants.State | string; + /** The number of documents to include in the collection. */ + limit?: number; + /** Page token that refers to the page of the collection to return. */ + start?: string; + } + + /** Constants for the `listActionControlTemplateVersions` operation. */ + export namespace ListActionControlTemplateVersionsConstants { + /** Action control template state. */ + export enum State { + ACTIVE = 'active', + DELETED = 'deleted', + } + } + + /** Parameters for the `replaceActionControlTemplate` operation. */ + export interface ReplaceActionControlTemplateParams extends DefaultParams { + /** Action control template ID. */ + actionControlTemplateId: string; + /** Action control template version. */ + version: string; + /** The revision number for updating an action control template version must match the Etag value of the + * existing action control template version. The Etag can be retrieved using the GET + * /v1/action_control_templates/{template_id}/versions/{version} API and looking at the Etag response header. + */ + ifMatch: string; + /** Required field when creating a new template. Otherwise, this field is optional. If the field is included, it + * will change the name value for all existing versions of the template. + */ + name?: string; + /** Description of the action control template. This is shown to users in the enterprise account. Use this to + * describe the purpose or context of the action control for enterprise users managing IAM templates. + */ + description?: string; + /** The action control properties that are created in an action resource when the template is assigned. */ + actionControl?: TemplateActionControl; + /** Committed status of the template version. If committed is set to true, then the template version can no + * longer be updated. + */ + committed?: boolean; + } + + /** Parameters for the `deleteActionControlTemplateVersion` operation. */ + export interface DeleteActionControlTemplateVersionParams extends DefaultParams { + /** Action control template ID. */ + actionControlTemplateId: string; + /** Action control template version. */ + version: string; + } + + /** Parameters for the `getActionControlTemplateVersion` operation. */ + export interface GetActionControlTemplateVersionParams extends DefaultParams { + /** Action control template ID. */ + actionControlTemplateId: string; + /** Action control template version. */ + version: string; + } + + /** Parameters for the `commitActionControlTemplate` operation. */ + export interface CommitActionControlTemplateParams extends DefaultParams { + /** Action control template ID. */ + actionControlTemplateId: string; + /** The action control template version. */ + version: string; + } + + /** Parameters for the `listActionControlAssignments` operation. */ + export interface ListActionControlAssignmentsParams extends DefaultParams { + /** The account GUID in which the action control assignment belongs to. */ + accountId: string; + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ + acceptLanguage?: string; + /** Optional template ID. */ + templateId?: string; + /** Optional action control template version. */ + templateVersion?: string; + /** The number of documents to include in the collection. */ + limit?: number; + /** Page token that refers to the page of the collection to return. */ + start?: string; + } + + /** Parameters for the `createActionControlTemplateAssignment` operation. */ + export interface CreateActionControlTemplateAssignmentParams extends DefaultParams { + /** assignment target account and type. */ + target: AssignmentTargetDetails; + /** List of action control template details for action control assignment. */ + templates: ActionControlAssignmentTemplate[]; + /** Language code for translations + * * `default` - English + * * `de` - German (Standard) + * * `en` - English + * * `es` - Spanish (Spain) + * * `fr` - French (Standard) + * * `it` - Italian (Standard) + * * `ja` - Japanese + * * `ko` - Korean + * * `pt-br` - Portuguese (Brazil) + * * `zh-cn` - Chinese (Simplified, PRC) + * * `zh-tw` - (Chinese, Taiwan). + */ + acceptLanguage?: string; + } + + /** Parameters for the `getActionControlAssignment` operation. */ + export interface GetActionControlAssignmentParams extends DefaultParams { + /** Action control template assignment ID. */ + assignmentId: string; + } + + /** Parameters for the `updateActionControlAssignment` operation. */ + export interface UpdateActionControlAssignmentParams extends DefaultParams { + /** Action control template assignment ID. */ + assignmentId: string; + /** The revision number for updating an action control assignment and must match the Etag value of the existing + * action control assignment. The Etag can be retrieved using the GET + * /v1/action_control_assignments/{assignment_id} API and looking at the Etag response header. */ ifMatch: string; - /** Update to how external accounts can interact in relation to the requested account. */ - externalAccountIdentityInteraction?: ExternalAccountIdentityInteractionPatch; - /** Language code for translations - * * `default` - English - * * `de` - German (Standard) - * * `en` - English - * * `es` - Spanish (Spain) - * * `fr` - French (Standard) - * * `it` - Italian (Standard) - * * `ja` - Japanese - * * `ko` - Korean - * * `pt-br` - Portuguese (Brazil) - * * `zh-cn` - Chinese (Simplified, PRC) - * * `zh-tw` - (Chinese, Taiwan). - */ - acceptLanguage?: string; + /** The version number of the template used to identify different versions of same template. */ + templateVersion: string; } - /** Parameters for the `listActionControlTemplates` operation. */ - export interface ListActionControlTemplatesParams extends DefaultParams { - /** The account GUID that the action control templates belong to. */ + /** Parameters for the `deleteActionControlAssignment` operation. */ + export interface DeleteActionControlAssignmentParams extends DefaultParams { + /** Action control template assignment ID. */ + assignmentId: string; + } + + /** Parameters for the `listRoleTemplates` operation. */ + export interface ListRoleTemplatesParams extends DefaultParams { + /** The account GUID that the role templates belong to. */ accountId: string; /** Language code for translations * * `default` - English @@ -4798,30 +6083,47 @@ namespace IamPolicyManagementV1 { * * `zh-tw` - (Chinese, Taiwan). */ acceptLanguage?: string; + /** The role template name. */ + name?: string; + /** The template role name. */ + roleName?: string; + /** The template role service name. */ + roleServiceName?: string; + /** The role template state. */ + state?: ListRoleTemplatesConstants.State | string; /** The number of documents to include in the collection. */ limit?: number; /** Page token that refers to the page of the collection to return. */ start?: string; } - /** Parameters for the `createActionControlTemplate` operation. */ - export interface CreateActionControlTemplateParams extends DefaultParams { + /** Constants for the `listRoleTemplates` operation. */ + export namespace ListRoleTemplatesConstants { + /** The role template state. */ + export enum State { + ACTIVE = 'active', + DELETED = 'deleted', + } + } + + /** Parameters for the `createRoleTemplate` operation. */ + export interface CreateRoleTemplateParams extends DefaultParams { /** Required field when creating a new template. Otherwise, this field is optional. If the field is included, it * changes the name value for all existing versions of the template. */ name: string; /** Enterprise account ID where this template is created. */ accountId: string; - /** Description of the action control template. This is shown to users in the enterprise account. Use this to - * describe the purpose or context of the action control for enterprise users managing IAM templates. + /** Description of the role template. This is shown to users in the enterprise account. Use this to describe the + * purpose or context of the role for enterprise users managing IAM templates. */ description?: string; /** Committed status of the template. If committed is set to true, then the template version can no longer be * updated. */ committed?: boolean; - /** The action control properties that are created in an action resource when the template is assigned. */ - actionControl?: TemplateActionControl; + /** The role properties that are created in an action resource when the template is assigned. */ + role?: TemplateRole; /** Language code for translations * * `default` - English * * `de` - German (Standard) @@ -4838,124 +6140,124 @@ namespace IamPolicyManagementV1 { acceptLanguage?: string; } - /** Parameters for the `getActionControlTemplate` operation. */ - export interface GetActionControlTemplateParams extends DefaultParams { - /** Action control template ID. */ - actionControlTemplateId: string; - /** The action control template state. */ - state?: GetActionControlTemplateConstants.State | string; + /** Parameters for the `getRoleTemplate` operation. */ + export interface GetRoleTemplateParams extends DefaultParams { + /** Role template ID. */ + roleTemplateId: string; + /** The role template state. */ + state?: GetRoleTemplateConstants.State | string; } - /** Constants for the `getActionControlTemplate` operation. */ - export namespace GetActionControlTemplateConstants { - /** The action control template state. */ + /** Constants for the `getRoleTemplate` operation. */ + export namespace GetRoleTemplateConstants { + /** The role template state. */ export enum State { ACTIVE = 'active', DELETED = 'deleted', } } - /** Parameters for the `deleteActionControlTemplate` operation. */ - export interface DeleteActionControlTemplateParams extends DefaultParams { - /** Action control template ID. */ - actionControlTemplateId: string; + /** Parameters for the `deleteRoleTemplate` operation. */ + export interface DeleteRoleTemplateParams extends DefaultParams { + /** Role template ID. */ + roleTemplateId: string; } - /** Parameters for the `createActionControlTemplateVersion` operation. */ - export interface CreateActionControlTemplateVersionParams extends DefaultParams { - /** The action control template ID. */ - actionControlTemplateId: string; + /** Parameters for the `createRoleTemplateVersion` operation. */ + export interface CreateRoleTemplateVersionParams extends DefaultParams { + /** The role template ID. */ + roleTemplateId: string; + /** The role properties that are created in an action resource when the template is assigned. */ + role: TemplateRole; /** Required field when creating a new template. Otherwise, this field is optional. If the field is included, it * will change the name value for all existing versions of the template. */ name?: string; - /** Description of the action control template. This is shown to users in the enterprise account. Use this to - * describe the purpose or context of the action control for enterprise users managing IAM templates. + /** Description of the role template. This is shown to users in the enterprise account. Use this to describe the + * purpose or context of the role for enterprise users managing IAM templates. */ description?: string; - /** The action control properties that are created in an action resource when the template is assigned. */ - actionControl?: TemplateActionControl; /** Committed status of the template version. If committed is set to true, then the template version can no * longer be updated. */ committed?: boolean; } - /** Parameters for the `listActionControlTemplateVersions` operation. */ - export interface ListActionControlTemplateVersionsParams extends DefaultParams { - /** The action control template ID. */ - actionControlTemplateId: string; - /** Action control template state. */ - state?: ListActionControlTemplateVersionsConstants.State | string; + /** Parameters for the `listRoleTemplateVersions` operation. */ + export interface ListRoleTemplateVersionsParams extends DefaultParams { + /** The role template ID. */ + roleTemplateId: string; + /** Role template state. */ + state?: ListRoleTemplateVersionsConstants.State | string; /** The number of documents to include in the collection. */ limit?: number; /** Page token that refers to the page of the collection to return. */ start?: string; } - /** Constants for the `listActionControlTemplateVersions` operation. */ - export namespace ListActionControlTemplateVersionsConstants { - /** Action control template state. */ + /** Constants for the `listRoleTemplateVersions` operation. */ + export namespace ListRoleTemplateVersionsConstants { + /** Role template state. */ export enum State { ACTIVE = 'active', DELETED = 'deleted', } } - /** Parameters for the `replaceActionControlTemplate` operation. */ - export interface ReplaceActionControlTemplateParams extends DefaultParams { - /** Action control template ID. */ - actionControlTemplateId: string; - /** Action control template version. */ + /** Parameters for the `replaceRoleTemplate` operation. */ + export interface ReplaceRoleTemplateParams extends DefaultParams { + /** Role template ID. */ + roleTemplateId: string; + /** Role template version. */ version: string; - /** The revision number for updating an action control template version must match the Etag value of the - * existing action control template version. The Etag can be retrieved using the GET - * /v1/action_control_templates/{template_id}/versions/{version} API and looking at the Etag response header. + /** The revision number for updating a role template version must match the Etag value of the existing role + * template version. The Etag can be retrieved using the GET /v1/role_templates/{template_id}/versions/{version} + * API and looking at the Etag response header. */ ifMatch: string; + /** The role properties that are created in an action resource when the template is assigned. */ + role: TemplateRole; /** Required field when creating a new template. Otherwise, this field is optional. If the field is included, it * will change the name value for all existing versions of the template. */ name?: string; - /** Description of the action control template. This is shown to users in the enterprise account. Use this to - * describe the purpose or context of the action control for enterprise users managing IAM templates. + /** Description of the role template. This is shown to users in the enterprise account. Use this to describe the + * purpose or context of the role for enterprise users managing IAM templates. */ description?: string; - /** The action control properties that are created in an action resource when the template is assigned. */ - actionControl?: TemplateActionControl; /** Committed status of the template version. If committed is set to true, then the template version can no * longer be updated. */ committed?: boolean; } - /** Parameters for the `deleteActionControlTemplateVersion` operation. */ - export interface DeleteActionControlTemplateVersionParams extends DefaultParams { - /** Action control template ID. */ - actionControlTemplateId: string; - /** Action control template version. */ + /** Parameters for the `deleteRoleTemplateVersion` operation. */ + export interface DeleteRoleTemplateVersionParams extends DefaultParams { + /** Role template ID. */ + roleTemplateId: string; + /** Role template version. */ version: string; } - /** Parameters for the `getActionControlTemplateVersion` operation. */ - export interface GetActionControlTemplateVersionParams extends DefaultParams { - /** Action control template ID. */ - actionControlTemplateId: string; - /** Action control template version. */ + /** Parameters for the `getRoleTemplateVersion` operation. */ + export interface GetRoleTemplateVersionParams extends DefaultParams { + /** Role template ID. */ + roleTemplateId: string; + /** Role template version. */ version: string; } - /** Parameters for the `commitActionControlTemplate` operation. */ - export interface CommitActionControlTemplateParams extends DefaultParams { - /** Action control template ID. */ - actionControlTemplateId: string; - /** The action control template version. */ + /** Parameters for the `commitRoleTemplate` operation. */ + export interface CommitRoleTemplateParams extends DefaultParams { + /** Role template ID. */ + roleTemplateId: string; + /** The role template version. */ version: string; } - /** Parameters for the `listActionControlAssignments` operation. */ - export interface ListActionControlAssignmentsParams extends DefaultParams { - /** The account GUID in which the action control assignment belongs to. */ + /** Parameters for the `listRoleAssignments` operation. */ + export interface ListRoleAssignmentsParams extends DefaultParams { + /** The account GUID in which the role assignment belongs to. */ accountId: string; /** Language code for translations * * `default` - English @@ -4973,7 +6275,7 @@ namespace IamPolicyManagementV1 { acceptLanguage?: string; /** Optional template ID. */ templateId?: string; - /** Optional action control template version. */ + /** Optional role template version. */ templateVersion?: string; /** The number of documents to include in the collection. */ limit?: number; @@ -4981,12 +6283,12 @@ namespace IamPolicyManagementV1 { start?: string; } - /** Parameters for the `createActionControlTemplateAssignment` operation. */ - export interface CreateActionControlTemplateAssignmentParams extends DefaultParams { + /** Parameters for the `createRoleTemplateAssignment` operation. */ + export interface CreateRoleTemplateAssignmentParams extends DefaultParams { /** assignment target account and type. */ target: AssignmentTargetDetails; - /** List of action control template details for action control assignment. */ - templates: ActionControlAssignmentTemplate[]; + /** List of role template details for role assignment. */ + templates: RoleAssignmentTemplate[]; /** Language code for translations * * `default` - English * * `de` - German (Standard) @@ -5003,28 +6305,28 @@ namespace IamPolicyManagementV1 { acceptLanguage?: string; } - /** Parameters for the `getActionControlAssignment` operation. */ - export interface GetActionControlAssignmentParams extends DefaultParams { - /** Action control template assignment ID. */ + /** Parameters for the `getRoleAssignment` operation. */ + export interface GetRoleAssignmentParams extends DefaultParams { + /** Role template assignment ID. */ assignmentId: string; } - /** Parameters for the `updateActionControlAssignment` operation. */ - export interface UpdateActionControlAssignmentParams extends DefaultParams { - /** Action control template assignment ID. */ + /** Parameters for the `updateRoleAssignment` operation. */ + export interface UpdateRoleAssignmentParams extends DefaultParams { + /** Role template assignment ID. */ assignmentId: string; - /** The revision number for updating an action control assignment and must match the Etag value of the existing - * action control assignment. The Etag can be retrieved using the GET - * /v1/action_control_assignments/{assignment_id} API and looking at the Etag response header. + /** The revision number for updating a role assignment and must match the Etag value of the existing role + * assignment. The Etag can be retrieved using the GET /v1/role_assignments/{assignment_id} API and looking at the + * Etag response header. */ ifMatch: string; /** The version number of the template used to identify different versions of same template. */ templateVersion: string; } - /** Parameters for the `deleteActionControlAssignment` operation. */ - export interface DeleteActionControlAssignmentParams extends DefaultParams { - /** Action control template assignment ID. */ + /** Parameters for the `deleteRoleAssignment` operation. */ + export interface DeleteRoleAssignmentParams extends DefaultParams { + /** Role template assignment ID. */ assignmentId: string; } @@ -5120,8 +6422,8 @@ namespace IamPolicyManagementV1 { export interface ActionControlAssignmentResourceActionControl { /** On success, it includes the action control assigned. */ resource_created?: ActionControlAssignmentResourceCreated; - /** The error response from API. */ - error_message?: ErrorResponse; + /** Body parameters for assignment error. */ + error_message?: AssignmentResourceError; } /** @@ -5229,6 +6531,22 @@ namespace IamPolicyManagementV1 { id?: string; } + /** + * Body parameters for assignment error. + */ + export interface AssignmentResourceError { + /** Name of the error. */ + name?: string; + /** error code. */ + errorCode?: string; + /** Error message detailing the nature of the error. */ + message?: string; + /** Internal status code for the error. */ + code?: string; + /** The errors encountered during the response. */ + errors?: ErrorObject[]; + } + /** * assignment target account and type. */ @@ -5382,22 +6700,13 @@ namespace IamPolicyManagementV1 { RESOURCE_NOT_FOUND = 'resource_not_found', ACTION_CONTROL_TEMPLATE_NOT_FOUND = 'action_control_template_not_found', ACTION_CONTROL_ASSIGNMENT_NOT_FOUND = 'action_control_assignment_not_found', + ROLE_TEMPLATE_CONFLICT_ERROR = 'role_template_conflict_error', + ROLE_TEMPLATE_NOT_FOUND = 'role_template_not_found', + ROLE_ASSIGNMENT_NOT_FOUND = 'role_assignment_not_found', } } } - /** - * The error response from API. - */ - export interface ErrorResponse { - /** The unique transaction ID for the request. */ - trace: string; - /** The errors encountered during the response. */ - errors: ErrorObject[]; - /** The HTTP error code of the response. */ - status_code: number; - } - /** * How external accounts can interact in relation to the requested account. */ @@ -5554,8 +6863,8 @@ namespace IamPolicyManagementV1 { resource_created?: AssignmentResourceCreated; /** policy status. */ status?: string; - /** The error response from API. */ - error_message?: ErrorResponse; + /** Body parameters for assignment error. */ + error_message?: AssignmentResourceError; } /** @@ -5944,27 +7253,208 @@ namespace IamPolicyManagementV1 { } /** - * An action that can be performed by the policy subject when assigned a role. + * An action that can be performed by the policy subject when assigned a role. + */ + export interface RoleAction { + /** Unique identifier for action with structure service.resource.action. For example, cbr.rule.read. */ + id: string; + /** Services defined display name for action. */ + display_name: string; + /** Service defined description for action. */ + description: string; + } + + /** + * The set of properties associated with the assigned role template. + */ + export interface RoleAssignment { + /** Action control assignment ID. */ + id?: string; + /** The account GUID that the role assignments belong to. */ + account_id?: string; + /** The href URL that links to the role assignments API by role assignment ID. */ + href?: string; + /** The UTC timestamp when the role assignment was created. */ + created_at?: string; + /** The IAM ID of the entity that created the role assignment. */ + created_by_id?: string; + /** The UTC timestamp when the role assignment was last modified. */ + last_modified_at?: string; + /** The IAM ID of the entity that last modified the role assignment. */ + last_modified_by_id?: string; + /** The current operation of the role assignment. */ + operation?: RoleAssignment.Constants.Operation | string; + /** Resources created when role template is assigned. */ + resources?: RoleAssignmentResource[]; + /** The role template id and version that will be assigned. */ + template: RoleAssignmentTemplate; + /** assignment target account and type. */ + target: AssignmentTargetDetails; + /** The role assignment status. */ + status?: RoleAssignment.Constants.Status | string; + } + export namespace RoleAssignment { + export namespace Constants { + /** The current operation of the role assignment. */ + export enum Operation { + CREATE = 'create', + APPLY = 'apply', + UPDATE = 'update', + REMOVE = 'remove', + } + /** The role assignment status. */ + export enum Status { + ACCEPTED = 'accepted', + FAILURE = 'failure', + IN_PROGRESS = 'in_progress', + SUPERSEDED = 'superseded', + } + } + } + + /** + * A collection of role assignments. + */ + export interface RoleAssignmentCollection { + /** The number of documents to include per each page of the collection. */ + limit?: number; + /** Details with linking href to first page of requested collection. */ + first?: First; + /** Details with href linking to the following page of requested collection. */ + next?: Next; + /** Details with linking href to previous page of requested collection. */ + previous?: Previous; + /** List of role assignments. */ + assignments: RoleAssignment[]; + } + + /** + * The role assignment resources and target where the template is assigned. + */ + export interface RoleAssignmentResource { + /** assignment target account and type. */ + target: AssignmentTargetDetails; + /** Set of properties of the assigned resource or error message if assignment failed. */ + role?: RoleAssignmentResourceRole; + } + + /** + * On success, it includes the action control assigned. + */ + export interface RoleAssignmentResourceCreated { + /** role id. */ + id?: string; + } + + /** + * Set of properties of the assigned resource or error message if assignment failed. + */ + export interface RoleAssignmentResourceRole { + /** On success, it includes the action control assigned. */ + resource_created?: RoleAssignmentResourceCreated; + /** Body parameters for assignment error. */ + error_message?: AssignmentResourceError; + } + + /** + * The role template id and version that will be assigned. + */ + export interface RoleAssignmentTemplate { + /** Action control template ID. */ + id: string; + /** Action control template version. */ + version: string; + } + + /** + * A collection of roles returned by the 'list roles' operation. + */ + export interface RoleCollection { + /** List of custom roles. */ + custom_roles: CustomRole[]; + /** List of service roles. */ + service_roles: Role[]; + /** List of system roles. */ + system_roles: Role[]; + } + + /** + * The set of properties associated with the role template. + */ + export interface RoleTemplate { + /** Required field when creating a new template. Otherwise, this field is optional. If the field is included, it + * changes the name value for all existing versions of the template. + */ + name: string; + /** Description of the role template. This is shown to users in the enterprise account. Use this to describe the + * purpose or context of the role for enterprise users managing IAM templates. + */ + description: string; + /** Enterprise account ID where this template is created. */ + account_id: string; + /** Committed status of the template. If committed is set to true, then the template version can no longer be + * updated. + */ + committed?: boolean; + /** The role properties that are created in an action resource when the template is assigned. */ + role?: TemplateRole; + /** The role template ID. */ + id?: string; + /** The href URL that links to the role templates API by role template ID. */ + href?: string; + /** The UTC timestamp when the role template was created. */ + created_at?: string; + /** The IAM ID of the entity that created the role template. */ + created_by_id?: string; + /** The UTC timestamp when the role template was last modified. */ + last_modified_at?: string; + /** The IAM ID of the entity that last modified the role template. */ + last_modified_by_id?: string; + /** The version number of the template used to identify different versions of same template. */ + version: string; + /** State of role template. */ + state: RoleTemplate.Constants.State | string; + } + export namespace RoleTemplate { + export namespace Constants { + /** State of role template. */ + export enum State { + ACTIVE = 'active', + DELETED = 'deleted', + } + } + } + + /** + * A collection of role templates. */ - export interface RoleAction { - /** Unique identifier for action with structure service.resource.action. For example, cbr.rule.read. */ - id: string; - /** Services defined display name for action. */ - display_name: string; - /** Service defined description for action. */ - description: string; + export interface RoleTemplateCollection { + /** The number of documents to include per each page of the collection. */ + limit?: number; + /** Details with linking href to first page of requested collection. */ + first?: First; + /** Details with href linking to the following page of requested collection. */ + next?: Next; + /** Details with linking href to previous page of requested collection. */ + previous?: Previous; + /** List of role templates. */ + role_templates: RoleTemplate[]; } /** - * A collection of roles returned by the 'list roles' operation. + * A collection of versions for a specific role template. */ - export interface RoleCollection { - /** List of custom roles. */ - custom_roles: CustomRole[]; - /** List of service roles. */ - service_roles: Role[]; - /** List of system roles. */ - system_roles: Role[]; + export interface RoleTemplateVersionsCollection { + /** The number of documents to include per each page of the collection. */ + limit?: number; + /** Details with linking href to first page of requested collection. */ + first?: First; + /** Details with href linking to the following page of requested collection. */ + next?: Next; + /** Details with linking href to previous page of requested collection. */ + previous?: Previous; + /** List of role templates versions. */ + versions: RoleTemplate[]; } /** @@ -6100,6 +7590,22 @@ namespace IamPolicyManagementV1 { } } + /** + * The role properties that are created in an action resource when the template is assigned. + */ + export interface TemplateRole { + /** The name of the role that is used in the CRN. This must be alphanumeric and capitalized. */ + name: string; + /** The display the name of the role that is shown in the console. */ + display_name: string; + /** The service name that the role refers. */ + service_name: string; + /** Description of the role. */ + description?: string; + /** The actions of the role. */ + actions: string[]; + } + /** * The core set of properties associated with the policy. */ @@ -7215,6 +8721,252 @@ namespace IamPolicyManagementV1 { return results; } } + + /** + * RoleTemplatesPager can be used to simplify the use of listRoleTemplates(). + */ + export class RoleTemplatesPager { + protected _hasNext: boolean; + + protected pageContext: any; + + protected client: IamPolicyManagementV1; + + protected params: IamPolicyManagementV1.ListRoleTemplatesParams; + + /** + * Construct a RoleTemplatesPager object. + * + * @param {IamPolicyManagementV1} client - The service client instance used to invoke listRoleTemplates() + * @param {Object} params - The parameters to be passed to listRoleTemplates() + * @constructor + * @returns {RoleTemplatesPager} + */ + constructor( + client: IamPolicyManagementV1, + params: IamPolicyManagementV1.ListRoleTemplatesParams + ) { + if (params && params.start) { + throw new Error(`the params.start field should not be set`); + } + + this._hasNext = true; + this.pageContext = { next: undefined }; + this.client = client; + this.params = JSON.parse(JSON.stringify(params || {})); + } + + /** + * Returns true if there are potentially more results to be retrieved by invoking getNext(). + * @returns {boolean} + */ + public hasNext(): boolean { + return this._hasNext; + } + + /** + * Returns the next page of results by invoking listRoleTemplates(). + * @returns {Promise} + */ + public async getNext(): Promise { + if (!this.hasNext()) { + throw new Error('No more results available'); + } + + if (this.pageContext.next) { + this.params.start = this.pageContext.next; + } + const response = await this.client.listRoleTemplates(this.params); + const { result } = response; + + let next; + if (result && result.next) { + next = result.next.start; + } + this.pageContext.next = next; + if (!this.pageContext.next) { + this._hasNext = false; + } + return result.role_templates; + } + + /** + * Returns all results by invoking listRoleTemplates() repeatedly until all pages of results have been retrieved. + * @returns {Promise} + */ + public async getAll(): Promise { + const results: RoleTemplate[] = []; + while (this.hasNext()) { + const nextPage = await this.getNext(); + results.push(...nextPage); + } + return results; + } + } + + /** + * RoleTemplateVersionsPager can be used to simplify the use of listRoleTemplateVersions(). + */ + export class RoleTemplateVersionsPager { + protected _hasNext: boolean; + + protected pageContext: any; + + protected client: IamPolicyManagementV1; + + protected params: IamPolicyManagementV1.ListRoleTemplateVersionsParams; + + /** + * Construct a RoleTemplateVersionsPager object. + * + * @param {IamPolicyManagementV1} client - The service client instance used to invoke listRoleTemplateVersions() + * @param {Object} params - The parameters to be passed to listRoleTemplateVersions() + * @constructor + * @returns {RoleTemplateVersionsPager} + */ + constructor( + client: IamPolicyManagementV1, + params: IamPolicyManagementV1.ListRoleTemplateVersionsParams + ) { + if (params && params.start) { + throw new Error(`the params.start field should not be set`); + } + + this._hasNext = true; + this.pageContext = { next: undefined }; + this.client = client; + this.params = JSON.parse(JSON.stringify(params || {})); + } + + /** + * Returns true if there are potentially more results to be retrieved by invoking getNext(). + * @returns {boolean} + */ + public hasNext(): boolean { + return this._hasNext; + } + + /** + * Returns the next page of results by invoking listRoleTemplateVersions(). + * @returns {Promise} + */ + public async getNext(): Promise { + if (!this.hasNext()) { + throw new Error('No more results available'); + } + + if (this.pageContext.next) { + this.params.start = this.pageContext.next; + } + const response = await this.client.listRoleTemplateVersions(this.params); + const { result } = response; + + let next; + if (result && result.next) { + next = result.next.start; + } + this.pageContext.next = next; + if (!this.pageContext.next) { + this._hasNext = false; + } + return result.versions; + } + + /** + * Returns all results by invoking listRoleTemplateVersions() repeatedly until all pages of results have been retrieved. + * @returns {Promise} + */ + public async getAll(): Promise { + const results: RoleTemplate[] = []; + while (this.hasNext()) { + const nextPage = await this.getNext(); + results.push(...nextPage); + } + return results; + } + } + + /** + * RoleAssignmentsPager can be used to simplify the use of listRoleAssignments(). + */ + export class RoleAssignmentsPager { + protected _hasNext: boolean; + + protected pageContext: any; + + protected client: IamPolicyManagementV1; + + protected params: IamPolicyManagementV1.ListRoleAssignmentsParams; + + /** + * Construct a RoleAssignmentsPager object. + * + * @param {IamPolicyManagementV1} client - The service client instance used to invoke listRoleAssignments() + * @param {Object} params - The parameters to be passed to listRoleAssignments() + * @constructor + * @returns {RoleAssignmentsPager} + */ + constructor( + client: IamPolicyManagementV1, + params: IamPolicyManagementV1.ListRoleAssignmentsParams + ) { + if (params && params.start) { + throw new Error(`the params.start field should not be set`); + } + + this._hasNext = true; + this.pageContext = { next: undefined }; + this.client = client; + this.params = JSON.parse(JSON.stringify(params || {})); + } + + /** + * Returns true if there are potentially more results to be retrieved by invoking getNext(). + * @returns {boolean} + */ + public hasNext(): boolean { + return this._hasNext; + } + + /** + * Returns the next page of results by invoking listRoleAssignments(). + * @returns {Promise} + */ + public async getNext(): Promise { + if (!this.hasNext()) { + throw new Error('No more results available'); + } + + if (this.pageContext.next) { + this.params.start = this.pageContext.next; + } + const response = await this.client.listRoleAssignments(this.params); + const { result } = response; + + let next; + if (result && result.next) { + next = result.next.start; + } + this.pageContext.next = next; + if (!this.pageContext.next) { + this._hasNext = false; + } + return result.assignments; + } + + /** + * Returns all results by invoking listRoleAssignments() repeatedly until all pages of results have been retrieved. + * @returns {Promise} + */ + public async getAll(): Promise { + const results: RoleAssignment[] = []; + while (this.hasNext()) { + const nextPage = await this.getNext(); + results.push(...nextPage); + } + return results; + } + } } export = IamPolicyManagementV1; diff --git a/test/integration/iam-policy-management.v1.test.js b/test/integration/iam-policy-management.v1.test.js index f59c44c..974653a 100644 --- a/test/integration/iam-policy-management.v1.test.js +++ b/test/integration/iam-policy-management.v1.test.js @@ -152,6 +152,7 @@ describe('IamPolicyManagementV1_integration', () => { const TEST_TEMPLATE_PREFIX = 'SDKNode'; const testTemplateName = TEST_TEMPLATE_PREFIX + testUniqueId; const testActionControlTemplateName = `${TEST_TEMPLATE_PREFIX}ActionControl${testUniqueId}`; + const testCustomRoleTemplateName = `${TEST_TEMPLATE_PREFIX}Role${testUniqueId}`; let testActionControlBasicTemplateId; let testActionControlBasicTemplateVersion; let testActionControlBasicTemplateETag; @@ -159,6 +160,9 @@ describe('IamPolicyManagementV1_integration', () => { let testActionControlTemplateVersion; let testActionControlTemplateETag; let testActionControlTemplateUpdateVersion; + let testRoleTemplateId; + let testRoleTemplateVersion; + let testRoleTemplateETag; const testTemplatePolicy = { type: 'access', description: 'SDK Test Policy', @@ -1684,4 +1688,289 @@ describe('IamPolicyManagementV1_integration', () => { } }); }); + + describe('Role Template & Assignment tests', () => { + test('createRoleTemplate()', async () => { + const testTemplateDescription = 'Node SDK Test Role template Create'; + + // Request models needed by this operation. + + // TemplateRole + const templateRoleModel = { + name: testCustomRoleName, + display_name: testCustomRoleDisplayName, + service_name: testServiceName, + description: testCustomRoleDescription, + actions: testCustomRoleActions, + }; + + const params = { + name: testCustomRoleTemplateName, + accountId: testAccountId, + description: testTemplateDescription, + role: templateRoleModel, + acceptLanguage: 'default', + }; + + const res = await service.createRoleTemplate(params); + expect(res).toBeDefined(); + expect(res.status).toBe(201); + expect(res.result).toBeDefined(); + const { result } = res || {}; + testRoleTemplateId = result.id; + testRoleTemplateVersion = result.version; + testRoleTemplateETag = res.headers.etag; + }); + + test('getRoleTemplate()', async () => { + const params = { + roleTemplateId: testRoleTemplateId, + state: 'active', + }; + + const res = await service.getRoleTemplate(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('replaceRoleTemplate()', async () => { + // Request models needed by this operation. + + // TemplateRole + const templateRoleModel = { + name: `${testCustomRoleName}Updated`, + display_name: `${testCustomRoleDisplayName} Updated`, + service_name: 'am-test-service', + description: 'am-test-service service customRole', + actions: ['am-test-service.test.delete'], + }; + const params = { + roleTemplateId: testRoleTemplateId, + version: testRoleTemplateVersion, + ifMatch: testRoleTemplateETag, + role: templateRoleModel, + committed: true, + }; + + const res = await service.replaceRoleTemplate(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('listRoleTemplates()', async () => { + const params = { + accountId: testAccountId, + state: 'active', + }; + + const res = await service.listRoleTemplates(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('listRoleTemplates() via RoleTemplatesPager', async () => { + const params = { + accountId: testAccountId, + state: 'active', + limit: 10, + }; + + const allResults = []; + + // Test getNext(). + let pager = new IamPolicyManagementV1.RoleTemplatesPager(service, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + + // Test getAll(). + pager = new IamPolicyManagementV1.RoleTemplatesPager(service, params); + const allItems = await pager.getAll(); + expect(allItems).not.toBeNull(); + expect(allItems).toHaveLength(allResults.length); + console.log(`Retrieved a total of ${allResults.length} items(s) with pagination.`); + }); + + test('createRoleTemplateVersion()', async () => { + // Request models needed by this operation. + + // TemplateRole + const templateRoleModel = { + name: `${testCustomRoleName}ver`, + display_name: `${testCustomRoleDisplayName}TemplateVersion`, + service_name: 'am-test-service', + description: 'am-test-service versioon customRole', + actions: ['am-test-service.test.create'], + }; + + const params = { + roleTemplateId: testRoleTemplateId, + role: templateRoleModel, + description: 'testString', + }; + + const res = await service.createRoleTemplateVersion(params); + expect(res).toBeDefined(); + expect(res.status).toBe(201); + expect(res.result).toBeDefined(); + const { result } = res || {}; + testRoleTemplateVersion = result.version; + testRoleTemplateETag = res.headers.etag; + }); + + test('listRoleTemplateVersions()', async () => { + const params = { + roleTemplateId: testRoleTemplateId, + state: 'active', + limit: 50, + }; + + const res = await service.listRoleTemplateVersions(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('listRoleTemplateVersions() via RoleTemplateVersionsPager', async () => { + const params = { + roleTemplateId: testRoleTemplateId, + state: 'active', + limit: 10, + }; + + const allResults = []; + + // Test getNext(). + let pager = new IamPolicyManagementV1.RoleTemplateVersionsPager(service, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + + // Test getAll(). + pager = new IamPolicyManagementV1.RoleTemplateVersionsPager(service, params); + const allItems = await pager.getAll(); + expect(allItems).not.toBeNull(); + expect(allItems).toHaveLength(allResults.length); + console.log(`Retrieved a total of ${allResults.length} items(s) with pagination.`); + }); + + test('getRoleTemplateVersion()', async () => { + const params = { + roleTemplateId: testRoleTemplateId, + version: testRoleTemplateVersion, + }; + + const res = await service.getRoleTemplateVersion(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('commitRoleTemplate()', async () => { + const params = { + roleTemplateId: testRoleTemplateId, + version: testRoleTemplateVersion, + }; + + const res = await service.commitRoleTemplate(params); + expect(res).toBeDefined(); + expect(res.status).toBe(204); + expect(res.result).toBeDefined(); + }); + + test('createRoleTemplateAssignment()', async () => { + // Request models needed by this operation. + + // AssignmentTargetDetails + const assignmentTargetDetailsModel = { + type: 'Account', + id: testTargetAccountId, + }; + + // RoleAssignmentTemplate + const roleAssignmentTemplateModel = { + id: testRoleTemplateId, + version: testRoleTemplateVersion, + }; + + const params = { + target: assignmentTargetDetailsModel, + templates: [roleAssignmentTemplateModel], + acceptLanguage: 'default', + }; + + const res = await service.createRoleTemplateAssignment(params); + expect(res).toBeDefined(); + expect(res.status).toBe(201); + expect(res.result).toBeDefined(); + const { result } = res || {}; + testAssignmentId = result.assignments[0].id; + testAssignmentETag = res.headers.etag; + }); + + test('getRoleAssignment()', async () => { + const params = { + assignmentId: testAssignmentId, + }; + + const res = await service.getRoleAssignment(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('updateRoleAssignment()', async () => { + const params = { + assignmentId: testAssignmentId, + ifMatch: testAssignmentETag, + templateVersion: testRoleTemplateVersion, + }; + + const res = await service.updateRoleAssignment(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('deleteRoleAssignment()', async () => { + const params = { + assignmentId: testAssignmentId, + }; + + const res = await service.deleteRoleAssignment(params); + expect(res).toBeDefined(); + expect(res.status).toBe(204); + expect(res.result).toBeDefined(); + }); + + test('deleteRoleTemplateVersion()', async () => { + const params = { + roleTemplateId: testRoleTemplateId, + version: testRoleTemplateVersion, + }; + + const res = await service.deleteRoleTemplateVersion(params); + expect(res).toBeDefined(); + expect(res.status).toBe(204); + expect(res.result).toBeDefined(); + }); + + test('deleteRoleTemplate()', async () => { + const params = { + roleTemplateId: testRoleTemplateId, + }; + + const res = await service.deleteRoleTemplate(params); + expect(res).toBeDefined(); + expect(res.status).toBe(204); + expect(res.result).toBeDefined(); + }); + }); }); diff --git a/test/unit/iam-policy-management.v1.test.js b/test/unit/iam-policy-management.v1.test.js index 45dfd50..5b46dda 100644 --- a/test/unit/iam-policy-management.v1.test.js +++ b/test/unit/iam-policy-management.v1.test.js @@ -3392,9 +3392,9 @@ describe('IamPolicyManagementV1', () => { const serviceUrl = iamPolicyManagementServiceOptions.url; const path = '/v1/policy_assignments'; const mockPagerResponse1 = - '{"next":{"start":"1"},"assignments":[{"target":{"type":"Account","id":"id"},"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","resources":[{"target":{"type":"Account","id":"id"},"policy":{"resource_created":{"id":"id"},"status":"status","error_message":{"trace":"trace","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}],"status_code":0}}}],"subject":{"id":"id","type":"iam_id"},"template":{"id":"id","version":"version"},"status":"in_progress"}],"total_count":2,"limit":1}'; + '{"next":{"start":"1"},"assignments":[{"target":{"type":"Account","id":"id"},"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","resources":[{"target":{"type":"Account","id":"id"},"policy":{"resource_created":{"id":"id"},"status":"status","error_message":{"name":"name","errorCode":"errorCode","message":"message","code":"code","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}]}}}],"subject":{"id":"id","type":"iam_id"},"template":{"id":"id","version":"version"},"status":"in_progress"}],"total_count":2,"limit":1}'; const mockPagerResponse2 = - '{"assignments":[{"target":{"type":"Account","id":"id"},"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","resources":[{"target":{"type":"Account","id":"id"},"policy":{"resource_created":{"id":"id"},"status":"status","error_message":{"trace":"trace","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}],"status_code":0}}}],"subject":{"id":"id","type":"iam_id"},"template":{"id":"id","version":"version"},"status":"in_progress"}],"total_count":2,"limit":1}'; + '{"assignments":[{"target":{"type":"Account","id":"id"},"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","resources":[{"target":{"type":"Account","id":"id"},"policy":{"resource_created":{"id":"id"},"status":"status","error_message":{"name":"name","errorCode":"errorCode","message":"message","code":"code","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}]}}}],"subject":{"id":"id","type":"iam_id"},"template":{"id":"id","version":"version"},"status":"in_progress"}],"total_count":2,"limit":1}'; beforeEach(() => { unmock_createRequest(); @@ -5192,9 +5192,9 @@ describe('IamPolicyManagementV1', () => { const serviceUrl = iamPolicyManagementServiceOptions.url; const path = '/v1/action_control_assignments'; const mockPagerResponse1 = - '{"next":{"start":"1"},"assignments":[{"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","operation":"create","resources":[{"target":{"type":"Account","id":"id"},"action_control":{"resource_created":{"id":"id"},"error_message":{"trace":"trace","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}],"status_code":0}}}],"template":{"id":"id","version":"version"},"target":{"type":"Account","id":"id"},"status":"accepted"}],"total_count":2,"limit":1}'; + '{"next":{"start":"1"},"assignments":[{"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","operation":"create","resources":[{"target":{"type":"Account","id":"id"},"action_control":{"resource_created":{"id":"id"},"error_message":{"name":"name","errorCode":"errorCode","message":"message","code":"code","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}]}}}],"template":{"id":"id","version":"version"},"target":{"type":"Account","id":"id"},"status":"accepted"}],"total_count":2,"limit":1}'; const mockPagerResponse2 = - '{"assignments":[{"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","operation":"create","resources":[{"target":{"type":"Account","id":"id"},"action_control":{"resource_created":{"id":"id"},"error_message":{"trace":"trace","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}],"status_code":0}}}],"template":{"id":"id","version":"version"},"target":{"type":"Account","id":"id"},"status":"accepted"}],"total_count":2,"limit":1}'; + '{"assignments":[{"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","operation":"create","resources":[{"target":{"type":"Account","id":"id"},"action_control":{"resource_created":{"id":"id"},"error_message":{"name":"name","errorCode":"errorCode","message":"message","code":"code","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}]}}}],"template":{"id":"id","version":"version"},"target":{"type":"Account","id":"id"},"status":"accepted"}],"total_count":2,"limit":1}'; beforeEach(() => { unmock_createRequest(); @@ -5612,4 +5612,1615 @@ describe('IamPolicyManagementV1', () => { }); }); }); + + describe('listRoleTemplates', () => { + describe('positive tests', () => { + function __listRoleTemplatesTest() { + // Construct the params object for operation listRoleTemplates + const accountId = 'testString'; + const acceptLanguage = 'default'; + const name = 'testString'; + const roleName = 'testString'; + const roleServiceName = 'testString'; + const state = 'active'; + const limit = 50; + const start = 'testString'; + const listRoleTemplatesParams = { + accountId, + acceptLanguage, + name, + roleName, + roleServiceName, + state, + limit, + start, + }; + + const listRoleTemplatesResult = iamPolicyManagementService.listRoleTemplates(listRoleTemplatesParams); + + // all methods should return a Promise + expectToBePromise(listRoleTemplatesResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + checkUserHeader(createRequestMock, 'Accept-Language', acceptLanguage); + expect(mockRequestOptions.qs.account_id).toEqual(accountId); + expect(mockRequestOptions.qs.name).toEqual(name); + expect(mockRequestOptions.qs.role_name).toEqual(roleName); + expect(mockRequestOptions.qs.role_service_name).toEqual(roleServiceName); + expect(mockRequestOptions.qs.state).toEqual(state); + expect(mockRequestOptions.qs.limit).toEqual(limit); + expect(mockRequestOptions.qs.start).toEqual(start); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listRoleTemplatesTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __listRoleTemplatesTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __listRoleTemplatesTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const listRoleTemplatesParams = { + accountId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.listRoleTemplates(listRoleTemplatesParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.listRoleTemplates({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.listRoleTemplates(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + + describe('RoleTemplatesPager tests', () => { + const serviceUrl = iamPolicyManagementServiceOptions.url; + const path = '/v1/role_templates'; + const mockPagerResponse1 = + '{"next":{"start":"1"},"total_count":2,"limit":1,"role_templates":[{"name":"name","description":"description","account_id":"account_id","committed":false,"role":{"name":"name","display_name":"display_name","service_name":"service_name","description":"description","actions":["actions"]},"id":"id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","version":"version","state":"active"}]}'; + const mockPagerResponse2 = + '{"total_count":2,"limit":1,"role_templates":[{"name":"name","description":"description","account_id":"account_id","committed":false,"role":{"name":"name","display_name":"display_name","service_name":"service_name","description":"description","actions":["actions"]},"id":"id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","version":"version","state":"active"}]}'; + + beforeEach(() => { + unmock_createRequest(); + const scope = nock(serviceUrl) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse1) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse2); + }); + + afterEach(() => { + nock.cleanAll(); + mock_createRequest(); + }); + + test('getNext()', async () => { + const params = { + accountId: 'testString', + acceptLanguage: 'default', + name: 'testString', + roleName: 'testString', + roleServiceName: 'testString', + state: 'active', + limit: 10, + }; + const allResults = []; + const pager = new IamPolicyManagementV1.RoleTemplatesPager(iamPolicyManagementService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + + test('getAll()', async () => { + const params = { + accountId: 'testString', + acceptLanguage: 'default', + name: 'testString', + roleName: 'testString', + roleServiceName: 'testString', + state: 'active', + limit: 10, + }; + const pager = new IamPolicyManagementV1.RoleTemplatesPager(iamPolicyManagementService, params); + const allResults = await pager.getAll(); + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + }); + }); + + describe('createRoleTemplate', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // TemplateRole + const templateRoleModel = { + name: 'testString', + display_name: 'testString', + service_name: 'testString', + description: 'testString', + actions: ['testString'], + }; + + function __createRoleTemplateTest() { + // Construct the params object for operation createRoleTemplate + const name = 'testString'; + const accountId = 'testString'; + const description = 'testString'; + const committed = true; + const role = templateRoleModel; + const acceptLanguage = 'default'; + const createRoleTemplateParams = { + name, + accountId, + description, + committed, + role, + acceptLanguage, + }; + + const createRoleTemplateResult = iamPolicyManagementService.createRoleTemplate(createRoleTemplateParams); + + // all methods should return a Promise + expectToBePromise(createRoleTemplateResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates', 'POST'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + checkUserHeader(createRequestMock, 'Accept-Language', acceptLanguage); + expect(mockRequestOptions.body.name).toEqual(name); + expect(mockRequestOptions.body.account_id).toEqual(accountId); + expect(mockRequestOptions.body.description).toEqual(description); + expect(mockRequestOptions.body.committed).toEqual(committed); + expect(mockRequestOptions.body.role).toEqual(role); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createRoleTemplateTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __createRoleTemplateTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __createRoleTemplateTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const name = 'testString'; + const accountId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createRoleTemplateParams = { + name, + accountId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.createRoleTemplate(createRoleTemplateParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.createRoleTemplate({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.createRoleTemplate(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('getRoleTemplate', () => { + describe('positive tests', () => { + function __getRoleTemplateTest() { + // Construct the params object for operation getRoleTemplate + const roleTemplateId = 'testString'; + const state = 'active'; + const getRoleTemplateParams = { + roleTemplateId, + state, + }; + + const getRoleTemplateResult = iamPolicyManagementService.getRoleTemplate(getRoleTemplateParams); + + // all methods should return a Promise + expectToBePromise(getRoleTemplateResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates/{role_template_id}', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.state).toEqual(state); + expect(mockRequestOptions.path.role_template_id).toEqual(roleTemplateId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getRoleTemplateTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __getRoleTemplateTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __getRoleTemplateTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const roleTemplateId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getRoleTemplateParams = { + roleTemplateId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.getRoleTemplate(getRoleTemplateParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.getRoleTemplate({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.getRoleTemplate(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('deleteRoleTemplate', () => { + describe('positive tests', () => { + function __deleteRoleTemplateTest() { + // Construct the params object for operation deleteRoleTemplate + const roleTemplateId = 'testString'; + const deleteRoleTemplateParams = { + roleTemplateId, + }; + + const deleteRoleTemplateResult = iamPolicyManagementService.deleteRoleTemplate(deleteRoleTemplateParams); + + // all methods should return a Promise + expectToBePromise(deleteRoleTemplateResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates/{role_template_id}', 'DELETE'); + const expectedAccept = undefined; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.role_template_id).toEqual(roleTemplateId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteRoleTemplateTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __deleteRoleTemplateTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __deleteRoleTemplateTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const roleTemplateId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteRoleTemplateParams = { + roleTemplateId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.deleteRoleTemplate(deleteRoleTemplateParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.deleteRoleTemplate({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.deleteRoleTemplate(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('createRoleTemplateVersion', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // TemplateRole + const templateRoleModel = { + name: 'testString', + display_name: 'testString', + service_name: 'testString', + description: 'testString', + actions: ['testString'], + }; + + function __createRoleTemplateVersionTest() { + // Construct the params object for operation createRoleTemplateVersion + const roleTemplateId = 'testString'; + const role = templateRoleModel; + const name = 'testString'; + const description = 'testString'; + const committed = true; + const createRoleTemplateVersionParams = { + roleTemplateId, + role, + name, + description, + committed, + }; + + const createRoleTemplateVersionResult = iamPolicyManagementService.createRoleTemplateVersion(createRoleTemplateVersionParams); + + // all methods should return a Promise + expectToBePromise(createRoleTemplateVersionResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates/{role_template_id}/versions', 'POST'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.role).toEqual(role); + expect(mockRequestOptions.body.name).toEqual(name); + expect(mockRequestOptions.body.description).toEqual(description); + expect(mockRequestOptions.body.committed).toEqual(committed); + expect(mockRequestOptions.path.role_template_id).toEqual(roleTemplateId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createRoleTemplateVersionTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __createRoleTemplateVersionTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __createRoleTemplateVersionTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const roleTemplateId = 'testString'; + const role = templateRoleModel; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createRoleTemplateVersionParams = { + roleTemplateId, + role, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.createRoleTemplateVersion(createRoleTemplateVersionParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.createRoleTemplateVersion({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.createRoleTemplateVersion(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('listRoleTemplateVersions', () => { + describe('positive tests', () => { + function __listRoleTemplateVersionsTest() { + // Construct the params object for operation listRoleTemplateVersions + const roleTemplateId = 'testString'; + const state = 'active'; + const limit = 50; + const start = 'testString'; + const listRoleTemplateVersionsParams = { + roleTemplateId, + state, + limit, + start, + }; + + const listRoleTemplateVersionsResult = iamPolicyManagementService.listRoleTemplateVersions(listRoleTemplateVersionsParams); + + // all methods should return a Promise + expectToBePromise(listRoleTemplateVersionsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates/{role_template_id}/versions', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.state).toEqual(state); + expect(mockRequestOptions.qs.limit).toEqual(limit); + expect(mockRequestOptions.qs.start).toEqual(start); + expect(mockRequestOptions.path.role_template_id).toEqual(roleTemplateId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listRoleTemplateVersionsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __listRoleTemplateVersionsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __listRoleTemplateVersionsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const roleTemplateId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const listRoleTemplateVersionsParams = { + roleTemplateId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.listRoleTemplateVersions(listRoleTemplateVersionsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.listRoleTemplateVersions({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.listRoleTemplateVersions(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + + describe('RoleTemplateVersionsPager tests', () => { + const serviceUrl = iamPolicyManagementServiceOptions.url; + const path = '/v1/role_templates/testString/versions'; + const mockPagerResponse1 = + '{"next":{"start":"1"},"versions":[{"name":"name","description":"description","account_id":"account_id","committed":false,"role":{"name":"name","display_name":"display_name","service_name":"service_name","description":"description","actions":["actions"]},"id":"id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","version":"version","state":"active"}],"total_count":2,"limit":1}'; + const mockPagerResponse2 = + '{"versions":[{"name":"name","description":"description","account_id":"account_id","committed":false,"role":{"name":"name","display_name":"display_name","service_name":"service_name","description":"description","actions":["actions"]},"id":"id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","version":"version","state":"active"}],"total_count":2,"limit":1}'; + + beforeEach(() => { + unmock_createRequest(); + const scope = nock(serviceUrl) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse1) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse2); + }); + + afterEach(() => { + nock.cleanAll(); + mock_createRequest(); + }); + + test('getNext()', async () => { + const params = { + roleTemplateId: 'testString', + state: 'active', + limit: 10, + }; + const allResults = []; + const pager = new IamPolicyManagementV1.RoleTemplateVersionsPager(iamPolicyManagementService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + + test('getAll()', async () => { + const params = { + roleTemplateId: 'testString', + state: 'active', + limit: 10, + }; + const pager = new IamPolicyManagementV1.RoleTemplateVersionsPager(iamPolicyManagementService, params); + const allResults = await pager.getAll(); + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + }); + }); + + describe('replaceRoleTemplate', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // TemplateRole + const templateRoleModel = { + name: 'testString', + display_name: 'testString', + service_name: 'testString', + description: 'testString', + actions: ['testString'], + }; + + function __replaceRoleTemplateTest() { + // Construct the params object for operation replaceRoleTemplate + const roleTemplateId = 'testString'; + const version = 'testString'; + const ifMatch = 'testString'; + const role = templateRoleModel; + const name = 'testString'; + const description = 'testString'; + const committed = true; + const replaceRoleTemplateParams = { + roleTemplateId, + version, + ifMatch, + role, + name, + description, + committed, + }; + + const replaceRoleTemplateResult = iamPolicyManagementService.replaceRoleTemplate(replaceRoleTemplateParams); + + // all methods should return a Promise + expectToBePromise(replaceRoleTemplateResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates/{role_template_id}/versions/{version}', 'PUT'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + checkUserHeader(createRequestMock, 'If-Match', ifMatch); + expect(mockRequestOptions.body.role).toEqual(role); + expect(mockRequestOptions.body.name).toEqual(name); + expect(mockRequestOptions.body.description).toEqual(description); + expect(mockRequestOptions.body.committed).toEqual(committed); + expect(mockRequestOptions.path.role_template_id).toEqual(roleTemplateId); + expect(mockRequestOptions.path.version).toEqual(version); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __replaceRoleTemplateTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __replaceRoleTemplateTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __replaceRoleTemplateTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const roleTemplateId = 'testString'; + const version = 'testString'; + const ifMatch = 'testString'; + const role = templateRoleModel; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const replaceRoleTemplateParams = { + roleTemplateId, + version, + ifMatch, + role, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.replaceRoleTemplate(replaceRoleTemplateParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.replaceRoleTemplate({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.replaceRoleTemplate(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('deleteRoleTemplateVersion', () => { + describe('positive tests', () => { + function __deleteRoleTemplateVersionTest() { + // Construct the params object for operation deleteRoleTemplateVersion + const roleTemplateId = 'testString'; + const version = 'testString'; + const deleteRoleTemplateVersionParams = { + roleTemplateId, + version, + }; + + const deleteRoleTemplateVersionResult = iamPolicyManagementService.deleteRoleTemplateVersion(deleteRoleTemplateVersionParams); + + // all methods should return a Promise + expectToBePromise(deleteRoleTemplateVersionResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates/{role_template_id}/versions/{version}', 'DELETE'); + const expectedAccept = undefined; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.role_template_id).toEqual(roleTemplateId); + expect(mockRequestOptions.path.version).toEqual(version); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteRoleTemplateVersionTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __deleteRoleTemplateVersionTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __deleteRoleTemplateVersionTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const roleTemplateId = 'testString'; + const version = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteRoleTemplateVersionParams = { + roleTemplateId, + version, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.deleteRoleTemplateVersion(deleteRoleTemplateVersionParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.deleteRoleTemplateVersion({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.deleteRoleTemplateVersion(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('getRoleTemplateVersion', () => { + describe('positive tests', () => { + function __getRoleTemplateVersionTest() { + // Construct the params object for operation getRoleTemplateVersion + const roleTemplateId = 'testString'; + const version = 'testString'; + const getRoleTemplateVersionParams = { + roleTemplateId, + version, + }; + + const getRoleTemplateVersionResult = iamPolicyManagementService.getRoleTemplateVersion(getRoleTemplateVersionParams); + + // all methods should return a Promise + expectToBePromise(getRoleTemplateVersionResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates/{role_template_id}/versions/{version}', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.role_template_id).toEqual(roleTemplateId); + expect(mockRequestOptions.path.version).toEqual(version); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getRoleTemplateVersionTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __getRoleTemplateVersionTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __getRoleTemplateVersionTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const roleTemplateId = 'testString'; + const version = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getRoleTemplateVersionParams = { + roleTemplateId, + version, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.getRoleTemplateVersion(getRoleTemplateVersionParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.getRoleTemplateVersion({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.getRoleTemplateVersion(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('commitRoleTemplate', () => { + describe('positive tests', () => { + function __commitRoleTemplateTest() { + // Construct the params object for operation commitRoleTemplate + const roleTemplateId = 'testString'; + const version = 'testString'; + const commitRoleTemplateParams = { + roleTemplateId, + version, + }; + + const commitRoleTemplateResult = iamPolicyManagementService.commitRoleTemplate(commitRoleTemplateParams); + + // all methods should return a Promise + expectToBePromise(commitRoleTemplateResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_templates/{role_template_id}/versions/{version}/commit', 'POST'); + const expectedAccept = undefined; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.role_template_id).toEqual(roleTemplateId); + expect(mockRequestOptions.path.version).toEqual(version); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __commitRoleTemplateTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __commitRoleTemplateTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __commitRoleTemplateTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const roleTemplateId = 'testString'; + const version = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const commitRoleTemplateParams = { + roleTemplateId, + version, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.commitRoleTemplate(commitRoleTemplateParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.commitRoleTemplate({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.commitRoleTemplate(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('listRoleAssignments', () => { + describe('positive tests', () => { + function __listRoleAssignmentsTest() { + // Construct the params object for operation listRoleAssignments + const accountId = 'testString'; + const acceptLanguage = 'default'; + const templateId = 'testString'; + const templateVersion = 'testString'; + const limit = 50; + const start = 'testString'; + const listRoleAssignmentsParams = { + accountId, + acceptLanguage, + templateId, + templateVersion, + limit, + start, + }; + + const listRoleAssignmentsResult = iamPolicyManagementService.listRoleAssignments(listRoleAssignmentsParams); + + // all methods should return a Promise + expectToBePromise(listRoleAssignmentsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_assignments', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + checkUserHeader(createRequestMock, 'Accept-Language', acceptLanguage); + expect(mockRequestOptions.qs.account_id).toEqual(accountId); + expect(mockRequestOptions.qs.template_id).toEqual(templateId); + expect(mockRequestOptions.qs.template_version).toEqual(templateVersion); + expect(mockRequestOptions.qs.limit).toEqual(limit); + expect(mockRequestOptions.qs.start).toEqual(start); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listRoleAssignmentsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __listRoleAssignmentsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __listRoleAssignmentsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const listRoleAssignmentsParams = { + accountId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.listRoleAssignments(listRoleAssignmentsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.listRoleAssignments({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.listRoleAssignments(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + + describe('RoleAssignmentsPager tests', () => { + const serviceUrl = iamPolicyManagementServiceOptions.url; + const path = '/v1/role_assignments'; + const mockPagerResponse1 = + '{"next":{"start":"1"},"assignments":[{"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","operation":"create","resources":[{"target":{"type":"Account","id":"id"},"role":{"resource_created":{"id":"id"},"error_message":{"name":"name","errorCode":"errorCode","message":"message","code":"code","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}]}}}],"template":{"id":"id","version":"version"},"target":{"type":"Account","id":"id"},"status":"accepted"}],"total_count":2,"limit":1}'; + const mockPagerResponse2 = + '{"assignments":[{"id":"id","account_id":"account_id","href":"href","created_at":"2019-01-01T12:00:00.000Z","created_by_id":"created_by_id","last_modified_at":"2019-01-01T12:00:00.000Z","last_modified_by_id":"last_modified_by_id","operation":"create","resources":[{"target":{"type":"Account","id":"id"},"role":{"resource_created":{"id":"id"},"error_message":{"name":"name","errorCode":"errorCode","message":"message","code":"code","errors":[{"code":"insufficent_permissions","message":"message","details":{"conflicts_with":{"etag":"etag","role":"role","policy":"policy"}},"more_info":"more_info"}]}}}],"template":{"id":"id","version":"version"},"target":{"type":"Account","id":"id"},"status":"accepted"}],"total_count":2,"limit":1}'; + + beforeEach(() => { + unmock_createRequest(); + const scope = nock(serviceUrl) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse1) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse2); + }); + + afterEach(() => { + nock.cleanAll(); + mock_createRequest(); + }); + + test('getNext()', async () => { + const params = { + accountId: 'testString', + acceptLanguage: 'default', + templateId: 'testString', + templateVersion: 'testString', + limit: 10, + }; + const allResults = []; + const pager = new IamPolicyManagementV1.RoleAssignmentsPager(iamPolicyManagementService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + + test('getAll()', async () => { + const params = { + accountId: 'testString', + acceptLanguage: 'default', + templateId: 'testString', + templateVersion: 'testString', + limit: 10, + }; + const pager = new IamPolicyManagementV1.RoleAssignmentsPager(iamPolicyManagementService, params); + const allResults = await pager.getAll(); + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + }); + }); + + describe('createRoleTemplateAssignment', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // AssignmentTargetDetails + const assignmentTargetDetailsModel = { + type: 'Account', + id: 'testString', + }; + + // RoleAssignmentTemplate + const roleAssignmentTemplateModel = { + id: 'testString', + version: 'testString', + }; + + function __createRoleTemplateAssignmentTest() { + // Construct the params object for operation createRoleTemplateAssignment + const target = assignmentTargetDetailsModel; + const templates = [roleAssignmentTemplateModel]; + const acceptLanguage = 'default'; + const createRoleTemplateAssignmentParams = { + target, + templates, + acceptLanguage, + }; + + const createRoleTemplateAssignmentResult = iamPolicyManagementService.createRoleTemplateAssignment(createRoleTemplateAssignmentParams); + + // all methods should return a Promise + expectToBePromise(createRoleTemplateAssignmentResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_assignments', 'POST'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + checkUserHeader(createRequestMock, 'Accept-Language', acceptLanguage); + expect(mockRequestOptions.body.target).toEqual(target); + expect(mockRequestOptions.body.templates).toEqual(templates); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createRoleTemplateAssignmentTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __createRoleTemplateAssignmentTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __createRoleTemplateAssignmentTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const target = assignmentTargetDetailsModel; + const templates = [roleAssignmentTemplateModel]; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createRoleTemplateAssignmentParams = { + target, + templates, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.createRoleTemplateAssignment(createRoleTemplateAssignmentParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.createRoleTemplateAssignment({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.createRoleTemplateAssignment(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('getRoleAssignment', () => { + describe('positive tests', () => { + function __getRoleAssignmentTest() { + // Construct the params object for operation getRoleAssignment + const assignmentId = 'testString'; + const getRoleAssignmentParams = { + assignmentId, + }; + + const getRoleAssignmentResult = iamPolicyManagementService.getRoleAssignment(getRoleAssignmentParams); + + // all methods should return a Promise + expectToBePromise(getRoleAssignmentResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_assignments/{assignment_id}', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.assignment_id).toEqual(assignmentId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getRoleAssignmentTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __getRoleAssignmentTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __getRoleAssignmentTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const assignmentId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getRoleAssignmentParams = { + assignmentId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.getRoleAssignment(getRoleAssignmentParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.getRoleAssignment({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.getRoleAssignment(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('updateRoleAssignment', () => { + describe('positive tests', () => { + function __updateRoleAssignmentTest() { + // Construct the params object for operation updateRoleAssignment + const assignmentId = 'testString'; + const ifMatch = 'testString'; + const templateVersion = 'testString'; + const updateRoleAssignmentParams = { + assignmentId, + ifMatch, + templateVersion, + }; + + const updateRoleAssignmentResult = iamPolicyManagementService.updateRoleAssignment(updateRoleAssignmentParams); + + // all methods should return a Promise + expectToBePromise(updateRoleAssignmentResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_assignments/{assignment_id}', 'PATCH'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + checkUserHeader(createRequestMock, 'If-Match', ifMatch); + expect(mockRequestOptions.body.template_version).toEqual(templateVersion); + expect(mockRequestOptions.path.assignment_id).toEqual(assignmentId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __updateRoleAssignmentTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __updateRoleAssignmentTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __updateRoleAssignmentTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const assignmentId = 'testString'; + const ifMatch = 'testString'; + const templateVersion = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const updateRoleAssignmentParams = { + assignmentId, + ifMatch, + templateVersion, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.updateRoleAssignment(updateRoleAssignmentParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.updateRoleAssignment({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.updateRoleAssignment(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('deleteRoleAssignment', () => { + describe('positive tests', () => { + function __deleteRoleAssignmentTest() { + // Construct the params object for operation deleteRoleAssignment + const assignmentId = 'testString'; + const deleteRoleAssignmentParams = { + assignmentId, + }; + + const deleteRoleAssignmentResult = iamPolicyManagementService.deleteRoleAssignment(deleteRoleAssignmentParams); + + // all methods should return a Promise + expectToBePromise(deleteRoleAssignmentResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/role_assignments/{assignment_id}', 'DELETE'); + const expectedAccept = undefined; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.assignment_id).toEqual(assignmentId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteRoleAssignmentTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.enableRetries(); + __deleteRoleAssignmentTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamPolicyManagementService.disableRetries(); + __deleteRoleAssignmentTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const assignmentId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteRoleAssignmentParams = { + assignmentId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamPolicyManagementService.deleteRoleAssignment(deleteRoleAssignmentParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamPolicyManagementService.deleteRoleAssignment({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamPolicyManagementService.deleteRoleAssignment(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); });