Skip to content

Commit

Permalink
feat(IAM Policy Management): re-gen service after fix the template st…
Browse files Browse the repository at this point in the history
…ate parameter (#238)

Signed-off-by: Rajesh K Pirati <[email protected]>
  • Loading branch information
Rajesh-Pirati authored Jan 12, 2024
1 parent 9b04b37 commit 66ef839
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 10 deletions.
167 changes: 158 additions & 9 deletions iam-policy-management/v1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

/**
* IBM OpenAPI SDK Code Generator Version: 3.81.0-c73a091c-20231026-215706
* IBM OpenAPI SDK Code Generator Version: 3.84.0-a4533f12-20240103-170852
*/

import * as extend from 'extend';
Expand Down Expand Up @@ -50,7 +50,7 @@ class IamPolicyManagementV1 extends BaseService {
* @param {UserOptions} [options] - The parameters to send to the service.
* @param {string} [options.serviceName] - The name of the service to configure
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service
* @param {string} [options.serviceUrl] - The URL for the service
* @param {string} [options.serviceUrl] - The base URL for the service
* @returns {IamPolicyManagementV1}
*/

Expand All @@ -75,7 +75,7 @@ class IamPolicyManagementV1 extends BaseService {
* Construct a IamPolicyManagementV1 object.
*
* @param {Object} options - Options for the service.
* @param {string} [options.serviceUrl] - The base url to use when contacting the service. The base url may differ between IBM Cloud regions.
* @param {string} [options.serviceUrl] - The base URL for the service
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
* @param {Authenticator} options.authenticator - The Authenticator object used to authenticate requests to the service
* @constructor
Expand Down Expand Up @@ -341,7 +341,87 @@ class IamPolicyManagementV1 extends BaseService {
* actions](/docs/account?topic=account-iam-service-roles-actions). Use only the resource attributes supported by the
* service. To view a service's or the platform's supported attributes, check the [documentation](/docs?tab=all-docs).
* The policy resource must include either the **`serviceType`**, **`serviceName`**, or **`resourceGroupId`**
* attribute and the **`accountId`** attribute.` If the subject is a locked service-id, the request will fail.
* attribute and the **`accountId`** attribute.`
*
* In the rule field, you can specify a single condition by using **`key`**, **`value`**, and condition
* **`operator`**, or a set of **`conditions`** with a combination **`operator`**. The possible combination operators
* are **`and`** and **`or`**.
*
* Currently, we support two types of patterns:
*
* 1. `time-based`: Used to specify a time-based restriction
*
* Combine conditions to specify a time-based restriction (e.g., access only during business hours, during the
* Monday-Friday work week). For example, a policy can grant access Monday-Friday, 9:00am-5:00pm using the following
* rule:
* ```json
* "rule": {
* "operator": "and",
* "conditions": [{
* "key": "{{environment.attributes.day_of_week}}",
* "operator": "dayOfWeekAnyOf",
* "value": ["1+00:00", "2+00:00", "3+00:00", "4+00:00", "5+00:00"]
* },
* "key": "{{environment.attributes.current_time}}",
* "operator": "timeGreaterThanOrEquals",
* "value": "09:00:00+00:00"
* },
* "key": "{{environment.attributes.current_time}}",
* "operator": "timeLessThanOrEquals",
* "value": "17:00:00+00:00"
* }]
* }
* ``` You can use the following operators in the **`key`** and **`value`** pair:
* ```
* 'timeLessThan', 'timeLessThanOrEquals', 'timeGreaterThan', 'timeGreaterThanOrEquals',
* 'dateTimeLessThan', 'dateTimeLessThanOrEquals', 'dateTimeGreaterThan', 'dateTimeGreaterThanOrEquals',
* 'dayOfWeekEquals', 'dayOfWeekAnyOf',
* ``` The pattern field that matches the rule is required when rule is provided. For the business hour rule example
* above, the **`pattern`** is **`"time-based-conditions:weekly"`**. For more information, see [Time-based conditions
* operators](/docs/account?topic=account-iam-condition-properties&interface=ui#policy-condition-properties) and
* [Limiting access with time-based conditions](/docs/account?topic=account-iam-time-based&interface=ui). If the
* subject is a locked service-id, the request will fail.
*
* 2. `attribute-based`: Used to specify a combination of OR/AND based conditions applied on resource attributes.
*
* Combine conditions to specify an attribute-based condition using AN/OR-based operators.
*
* For example, a policy can grant access based on multiple conditions applied on the resource attributes below:
* ```json
* "pattern": "attribute-based-condition:resource:literal-and-wildcard"
* "rule": {
* "operator": "or",
* "conditions": [
* {
* "operator": "and",
* "conditions": [
* {
* "key": "{{resource.attributes.prefix}}",
* "operator": "stringEquals",
* "value": "home/test"
* },
* {
* "key": "{{environment.attributes.delimiter}}",
* "operator": "stringEquals",
* "value": "/"
* }
* ]
* },
* {
* "key": "{{resource.attributes.path}}",
* "operator": "stringMatch",
* "value": "home/David/_*"
* }
* ]
* }
* ```
*
* In addition to satisfying the `resources` section, the policy grants permission only if either the `path` begins
* with `home/David/` **OR** the `prefix` is `home/test` and the `delimiter` is `/`. This mechanism helps you
* consolidate multiple policies in to a single policy, making policies easier to administer and stay within the
* policy limit for an account. View the list of operators that can be used in the condition
* [here](/docs/account?topic=account-wildcard#string-comparisons).
*
*
* ### Authorization
*
Expand Down Expand Up @@ -1512,6 +1592,7 @@ class IamPolicyManagementV1 extends BaseService {
* * `pt-br` - Portuguese (Brazil)
* * `zh-cn` - Chinese (Simplified, PRC)
* * `zh-tw` - (Chinese, Taiwan).
* @param {string} [params.state] - The policy template state.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<IamPolicyManagementV1.Response<IamPolicyManagementV1.PolicyTemplateCollection>>}
*/
Expand All @@ -1520,14 +1601,15 @@ class IamPolicyManagementV1 extends BaseService {
): Promise<IamPolicyManagementV1.Response<IamPolicyManagementV1.PolicyTemplateCollection>> {
const _params = { ...params };
const _requiredParams = ['accountId'];
const _validParams = ['accountId', 'acceptLanguage', 'headers'];
const _validParams = ['accountId', 'acceptLanguage', 'state', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const query = {
'account_id': _params.accountId,
'state': _params.state,
};

const sdkHeaders = getSdkHeaders(
Expand Down Expand Up @@ -1650,6 +1732,7 @@ class IamPolicyManagementV1 extends BaseService {
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.policyTemplateId - The policy template ID.
* @param {string} [params.state] - The policy template state.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<IamPolicyManagementV1.Response<IamPolicyManagementV1.PolicyTemplate>>}
*/
Expand All @@ -1658,12 +1741,16 @@ class IamPolicyManagementV1 extends BaseService {
): Promise<IamPolicyManagementV1.Response<IamPolicyManagementV1.PolicyTemplate>> {
const _params = { ...params };
const _requiredParams = ['policyTemplateId'];
const _validParams = ['policyTemplateId', 'headers'];
const _validParams = ['policyTemplateId', 'state', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const query = {
'state': _params.state,
};

const path = {
'policy_template_id': _params.policyTemplateId,
};
Expand All @@ -1678,6 +1765,7 @@ class IamPolicyManagementV1 extends BaseService {
options: {
url: '/v1/policy_templates/{policy_template_id}',
method: 'GET',
qs: query,
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
Expand Down Expand Up @@ -1824,6 +1912,7 @@ class IamPolicyManagementV1 extends BaseService {
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.policyTemplateId - The policy template ID.
* @param {string} [params.state] - The policy template state.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<IamPolicyManagementV1.Response<IamPolicyManagementV1.PolicyTemplateVersionsCollection>>}
*/
Expand All @@ -1834,12 +1923,16 @@ class IamPolicyManagementV1 extends BaseService {
> {
const _params = { ...params };
const _requiredParams = ['policyTemplateId'];
const _validParams = ['policyTemplateId', 'headers'];
const _validParams = ['policyTemplateId', 'state', 'headers'];
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}

const query = {
'state': _params.state,
};

const path = {
'policy_template_id': _params.policyTemplateId,
};
Expand All @@ -1854,6 +1947,7 @@ class IamPolicyManagementV1 extends BaseService {
options: {
url: '/v1/policy_templates/{policy_template_id}/versions',
method: 'GET',
qs: query,
path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
Expand Down Expand Up @@ -2740,9 +2834,20 @@ namespace IamPolicyManagementV1 {
* * `zh-tw` - (Chinese, Taiwan).
*/
acceptLanguage?: string;
/** The policy template state. */
state?: ListPolicyTemplatesConstants.State | string;
headers?: OutgoingHttpHeaders;
}

/** Constants for the `listPolicyTemplates` operation. */
export namespace ListPolicyTemplatesConstants {
/** The policy template state. */
export enum State {
ACTIVE = 'active',
DELETED = 'deleted',
}
}

/** Parameters for the `createPolicyTemplate` operation. */
export interface CreatePolicyTemplateParams {
/** Required field when creating a new template. Otherwise this field is optional. If the field is included it
Expand Down Expand Up @@ -2780,9 +2885,20 @@ namespace IamPolicyManagementV1 {
export interface GetPolicyTemplateParams {
/** The policy template ID. */
policyTemplateId: string;
/** The policy template state. */
state?: GetPolicyTemplateConstants.State | string;
headers?: OutgoingHttpHeaders;
}

/** Constants for the `getPolicyTemplate` operation. */
export namespace GetPolicyTemplateConstants {
/** The policy template state. */
export enum State {
ACTIVE = 'active',
DELETED = 'deleted',
}
}

/** Parameters for the `deletePolicyTemplate` operation. */
export interface DeletePolicyTemplateParams {
/** The policy template ID. */
Expand Down Expand Up @@ -2813,9 +2929,20 @@ namespace IamPolicyManagementV1 {
export interface ListPolicyTemplateVersionsParams {
/** The policy template ID. */
policyTemplateId: string;
/** The policy template state. */
state?: ListPolicyTemplateVersionsConstants.State | string;
headers?: OutgoingHttpHeaders;
}

/** Constants for the `listPolicyTemplateVersions` operation. */
export namespace ListPolicyTemplateVersionsConstants {
/** The policy template state. */
export enum State {
ACTIVE = 'active',
DELETED = 'deleted',
}
}

/** Parameters for the `replacePolicyTemplate` operation. */
export interface ReplacePolicyTemplateParams {
/** The policy template ID. */
Expand Down Expand Up @@ -3052,7 +3179,7 @@ namespace IamPolicyManagementV1 {
limit?: number;
}

/** Condition that specifies additional conditions or RuleAttribute to grant access.s. */
/** Condition that specifies additional conditions or RuleAttribute to grant access. */
export interface NestedCondition {}

/** The core set of properties associated with a policy. */
Expand Down Expand Up @@ -3232,6 +3359,8 @@ namespace IamPolicyManagementV1 {
committed?: boolean;
/** The core set of properties associated with the template's policy objet. */
policy: TemplatePolicy;
/** State of policy template. */
state?: PolicyTemplate.Constants.State | string;
/** The policy template ID. */
id?: string;
/** The href URL that links to the policy templates API by policy template ID. */
Expand All @@ -3245,6 +3374,15 @@ namespace IamPolicyManagementV1 {
/** The iam ID of the entity that last modified the policy template. */
last_modified_by_id?: string;
}
export namespace PolicyTemplate {
export namespace Constants {
/** State of policy template. */
export enum State {
ACTIVE = 'active',
DELETED = 'deleted',
}
}
}

/** A collection of policies assignments. */
export interface PolicyTemplateAssignmentCollection {
Expand Down Expand Up @@ -3276,6 +3414,8 @@ namespace IamPolicyManagementV1 {
committed?: boolean;
/** The core set of properties associated with the template's policy objet. */
policy: TemplatePolicy;
/** State of policy template. */
state?: PolicyTemplateLimitData.Constants.State | string;
/** The policy template ID. */
id?: string;
/** The href URL that links to the policy templates API by policy template ID. */
Expand All @@ -3291,6 +3431,15 @@ namespace IamPolicyManagementV1 {
/** policy template count details. */
counts?: TemplateCountData;
}
export namespace PolicyTemplateLimitData {
export namespace Constants {
/** State of policy template. */
export enum State {
ACTIVE = 'active',
DELETED = 'deleted',
}
}
}

/** The core set of properties associated with a policy. */
export interface PolicyTemplateMetaData {
Expand Down
6 changes: 6 additions & 0 deletions test/integration/iam-policy-management.v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ describe('IamPolicyManagementV1_integration', () => {
expect(result.policy).toEqual(testTemplatePolicy);
expect(result.name).toEqual(testTemplateName);
expect(result.description).toEqual(testTemplateDescription);
expect(result.state).toEqual('active');
testTemplateId = result.id;
testTemplateVersion = result.version;
});
Expand All @@ -811,6 +812,7 @@ describe('IamPolicyManagementV1_integration', () => {
expect(response.status).toEqual(200);
const { result } = response || {};
expect(result).toBeDefined();
expect(result.state).toEqual('active');
testTemplateETag = response.headers.etag;
});
test('Replace a policy template', async () => {
Expand All @@ -835,6 +837,7 @@ describe('IamPolicyManagementV1_integration', () => {
expect(result.policy.control.grant.roles[0].role_id).toEqual(testEditorRoleCrn);
expect(result.name).toEqual(testTemplateName);
expect(result.description).toEqual(testTemplateDescription);
expect(result.state).toEqual('active');
});
test('List policy templates', async () => {
const params = {
Expand Down Expand Up @@ -873,6 +876,7 @@ describe('IamPolicyManagementV1_integration', () => {
const { result } = response || {};
expect(result).toBeDefined();
expect(Number(result.version)).toBeGreaterThan(Number(testTemplateVersion));
expect(result.state).toEqual('active');
});
test('Get a policy template version', async () => {
expect(testTemplateId).toBeDefined();
Expand All @@ -888,6 +892,7 @@ describe('IamPolicyManagementV1_integration', () => {
const { result } = response || {};
expect(result).toBeDefined();
expect(result.version).toEqual(testTemplateVersion);
expect(result.state).toEqual('active');
testTemplateETag = response.headers.etag;
});
test('Commit a policy template version', async () => {
Expand Down Expand Up @@ -953,6 +958,7 @@ describe('IamPolicyManagementV1_integration', () => {
const { versions: templates } = result || [];
expect(templates).toHaveLength(1);
expect(templates[0].version).not.toEqual(testTemplateVersion);
expect(templates[0].state).toEqual('active');
});
test('Clean up all test policy templates', async () => {
// List all policy templates in the account
Expand Down
Loading

0 comments on commit 66ef839

Please sign in to comment.