From 9b2782a9373d39ae3d67182b791cefd1a7ffc7f0 Mon Sep 17 00:00:00 2001 From: Dylan Yu Date: Fri, 15 Sep 2023 09:55:21 -0500 Subject: [PATCH] feat(Context-Based Restrictions): add service group support to operations (#224) Signed-off-by: Dylan --- context-based-restrictions/v1.ts | 207 +++++++++-------- .../context-based-restrictions.v1.test.js | 2 +- .../context-based-restrictions.v1.test.js | 53 ++++- .../context-based-restrictions.v1.test.js | 217 +++++++++--------- 4 files changed, 270 insertions(+), 209 deletions(-) diff --git a/context-based-restrictions/v1.ts b/context-based-restrictions/v1.ts index f7617e5e..c99429e9 100644 --- a/context-based-restrictions/v1.ts +++ b/context-based-restrictions/v1.ts @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2022. + * (C) Copyright IBM Corp. 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.57.1-4c556507-20220928-143422 + * IBM OpenAPI SDK Code Generator Version: 3.79.0-2eb6af3d-20230905-174838 */ import * as extend from 'extend'; @@ -23,9 +23,9 @@ import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'; import { Authenticator, BaseService, + UserOptions, getAuthenticatorFromEnvironment, validateParams, - UserOptions, } from 'ibm-cloud-sdk-core'; import { getSdkHeaders } from '../lib/common'; @@ -115,10 +115,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -191,10 +191,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {string} [params.name] - The name of the zone. * @param {string} [params.sort] - Sorts results by using a valid sort field. To learn more, see * [Sorting](https://cloud.ibm.com/docs/api-handbook?topic=api-handbook-sorting). @@ -265,10 +265,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -336,10 +336,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -420,16 +420,16 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers - * @returns {Promise>} + * @returns {Promise>} */ public deleteZone( params: ContextBasedRestrictionsV1.DeleteZoneParams - ): Promise> { + ): Promise> { const _params = { ...params }; const _requiredParams = ['zoneId']; const _validParams = ['zoneId', 'xCorrelationId', 'transactionId', 'headers']; @@ -480,10 +480,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {string} [params.type] - Specifies the types of services to retrieve. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} @@ -553,10 +553,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -629,10 +629,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {string} [params.region] - The `region` resource attribute. * @param {string} [params.resource] - The `resource` resource attribute. * @param {string} [params.resourceType] - The `resourceType` resource attribute. @@ -727,10 +727,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -800,10 +800,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -884,16 +884,16 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers - * @returns {Promise>} + * @returns {Promise>} */ public deleteRule( params: ContextBasedRestrictionsV1.DeleteRuleParams - ): Promise> { + ): Promise> { const _params = { ...params }; const _requiredParams = ['ruleId']; const _validParams = ['ruleId', 'xCorrelationId', 'transactionId', 'headers']; @@ -948,10 +948,10 @@ class ContextBasedRestrictionsV1 extends BaseService { * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -1007,25 +1007,34 @@ class ContextBasedRestrictionsV1 extends BaseService { * * This operation lists all available service operations. * - * @param {Object} params - The parameters to send to the service. - * @param {string} params.serviceName - The name of the service. + * @param {Object} [params] - The parameters to send to the service. * @param {string} [params.xCorrelationId] - The supplied or generated value of this header is logged for a request * and repeated in a response header for the corresponding response. The same value is used for downstream requests * and retries of those requests. If a value of this headers is not supplied in a request, the service generates a * random (version 4) UUID. - * @param {string} [params.transactionId] - The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It - * is supported for backward compatibility with other IBM platform services that support the `Transaction-Id` header - * only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over - * `Transaction-Id`. + * @param {string} [params.transactionId] - Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` + * header. It is supported for backward compatibility with other IBM platform services that support the + * `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has + * the precedence over `Transaction-Id`. + * @param {string} [params.serviceName] - The name of the service. + * @param {string} [params.serviceGroupId] - The id of the service group. + * @param {string} [params.resourceType] - The type of resource. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ public listAvailableServiceOperations( - params: ContextBasedRestrictionsV1.ListAvailableServiceOperationsParams + params?: ContextBasedRestrictionsV1.ListAvailableServiceOperationsParams ): Promise> { const _params = { ...params }; - const _requiredParams = ['serviceName']; - const _validParams = ['serviceName', 'xCorrelationId', 'transactionId', 'headers']; + const _requiredParams = []; + const _validParams = [ + 'xCorrelationId', + 'transactionId', + 'serviceName', + 'serviceGroupId', + 'resourceType', + 'headers', + ]; const _validationErrors = validateParams(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); @@ -1033,6 +1042,8 @@ class ContextBasedRestrictionsV1 extends BaseService { const query = { 'service_name': _params.serviceName, + 'service_group_id': _params.serviceGroupId, + 'resource_type': _params.resourceType, }; const sdkHeaders = getSdkHeaders( @@ -1082,7 +1093,7 @@ namespace ContextBasedRestrictionsV1 { export type Callback = (error: any, response?: Response) => void; /** The body of a service request that returns no response data. */ - export interface Empty {} + export interface EmptyObject {} /** A standard JS object, defined to avoid the limitations of `Object` and `object` */ export interface JsonObject { @@ -1112,8 +1123,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1130,8 +1141,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1154,8 +1165,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1188,8 +1199,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1206,8 +1217,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1222,8 +1233,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1263,8 +1274,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1291,8 +1302,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1341,8 +1352,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1377,8 +1388,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1405,8 +1416,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1423,8 +1434,8 @@ namespace ContextBasedRestrictionsV1 { * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ @@ -1434,19 +1445,23 @@ namespace ContextBasedRestrictionsV1 { /** Parameters for the `listAvailableServiceOperations` operation. */ export interface ListAvailableServiceOperationsParams { - /** The name of the service. */ - serviceName: string; /** The supplied or generated value of this header is logged for a request and repeated in a response header for * the corresponding response. The same value is used for downstream requests and retries of those requests. If a * value of this headers is not supplied in a request, the service generates a random (version 4) UUID. */ xCorrelationId?: string; - /** The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward - * compatibility with other IBM platform services that support the `Transaction-Id` header only. If both + /** Deprecated: The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for + * backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both * `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over * `Transaction-Id`. */ transactionId?: string; + /** The name of the service. */ + serviceName?: string; + /** The id of the service group. */ + serviceGroupId?: string; + /** The type of resource. */ + resourceType?: string; headers?: OutgoingHttpHeaders; } @@ -1462,6 +1477,8 @@ namespace ContextBasedRestrictionsV1 { display_name: string; /** The description of the API type. */ description: string; + /** The type of the API type. */ + type: string; /** The actions available for the API type. */ actions: Action[]; } @@ -1713,7 +1730,7 @@ namespace ContextBasedRestrictionsV1 { last_modified_by_id: string; } - /** A single IP address. */ + /** A single IP address. IPv4 and IPv6 are supported. */ export interface AddressIPAddress extends Address { /** The type of address. */ type: string; @@ -1721,7 +1738,7 @@ namespace ContextBasedRestrictionsV1 { value: string; } - /** An IP address range. */ + /** An IP address range. IPv4 and IPv6 are supported. */ export interface AddressIPAddressRange extends Address { /** The type of address. */ type: string; diff --git a/examples/context-based-restrictions.v1.test.js b/examples/context-based-restrictions.v1.test.js index e32d9e04..51c82775 100644 --- a/examples/context-based-restrictions.v1.test.js +++ b/examples/context-based-restrictions.v1.test.js @@ -2,7 +2,7 @@ * @jest-environment node */ /** - * (C) Copyright IBM Corp. 2022. + * (C) Copyright IBM Corp. 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test/integration/context-based-restrictions.v1.test.js b/test/integration/context-based-restrictions.v1.test.js index f84181d2..59affe27 100644 --- a/test/integration/context-based-restrictions.v1.test.js +++ b/test/integration/context-based-restrictions.v1.test.js @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2022. + * (C) Copyright IBM Corp. 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -919,7 +919,7 @@ describe('ContextBasedRestrictionsV1_integration', () => { }); }); - test('listAvailableServiceOperations()', async () => { + test('listAvailableServiceOperations() with Service Name', async () => { const params = { serviceName: 'containers-kubernetes', transactionId: uuidv4(), @@ -929,6 +929,55 @@ describe('ContextBasedRestrictionsV1_integration', () => { expect(res).toBeDefined(); expect(res.status).toBe(200); expect(res.result).toBeDefined(); + res.result.api_types.forEach((apiType) => { + expect(apiType.type).not.toEqual(''); + }); + }); + + test('listAvailableServiceOperations() with Service Group', async () => { + const params = { + serviceGroupId: 'IAM', + transactionId: uuidv4(), + }; + + const res = await contextBasedRestrictionsService.listAvailableServiceOperations(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + res.result.api_types.forEach((apiType) => { + expect(apiType.type).not.toEqual(''); + }); + }); + + test('listAvailableServiceOperations() with Resource Type', async () => { + const params = { + serviceName: 'iam-access-management', + resourceType: 'customRole', + transactionId: uuidv4(), + }; + + const res = await contextBasedRestrictionsService.listAvailableServiceOperations(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + res.result.api_types.forEach((apiType) => { + expect(apiType.type).not.toEqual(''); + }); + }); + + test('listAvailableServiceOperations() with mutual exclusion error', async () => { + const params = { + serviceName: 'iam-access-management', + serviceGroupId: 'IAM', + transactionId: uuidv4(), + }; + + await expect( + contextBasedRestrictionsService.listAvailableServiceOperations(params) + ).rejects.toMatchObject({ + 'message': + "The following query parameters are mutually exclusive: 'service_group_id, service_name'. Specify exactly one of the mutually exclusive parameters and try your request again.", + }); }); test('deleteRule() - Delete rule with "Missing required parameters: ruleId" error', async () => { diff --git a/test/unit/context-based-restrictions.v1.test.js b/test/unit/context-based-restrictions.v1.test.js index 803f5505..f82f4251 100644 --- a/test/unit/context-based-restrictions.v1.test.js +++ b/test/unit/context-based-restrictions.v1.test.js @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2022. + * (C) Copyright IBM Corp. 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,9 @@ */ // need to import the whole package to mock getAuthenticatorFromEnvironment -const core = require('ibm-cloud-sdk-core'); - -const { NoAuthAuthenticator, unitTestUtils } = core; +const sdkCorePackage = require('ibm-cloud-sdk-core'); +const { NoAuthAuthenticator, unitTestUtils } = sdkCorePackage; const ContextBasedRestrictionsV1 = require('../../dist/context-based-restrictions/v1'); const { @@ -37,20 +36,30 @@ const contextBasedRestrictionsServiceOptions = { const contextBasedRestrictionsService = new ContextBasedRestrictionsV1(contextBasedRestrictionsServiceOptions); -// dont actually create a request -const createRequestMock = jest.spyOn(contextBasedRestrictionsService, 'createRequest'); -createRequestMock.mockImplementation(() => Promise.resolve()); +let createRequestMock = null; +function mock_createRequest() { + if (!createRequestMock) { + createRequestMock = jest.spyOn(contextBasedRestrictionsService, 'createRequest'); + createRequestMock.mockImplementation(() => Promise.resolve()); + } +} // dont actually construct an authenticator -const getAuthenticatorMock = jest.spyOn(core, 'getAuthenticatorFromEnvironment'); +const getAuthenticatorMock = jest.spyOn(sdkCorePackage, 'getAuthenticatorFromEnvironment'); getAuthenticatorMock.mockImplementation(() => new NoAuthAuthenticator()); -afterEach(() => { - createRequestMock.mockClear(); - getAuthenticatorMock.mockClear(); -}); - describe('ContextBasedRestrictionsV1', () => { + beforeEach(() => { + mock_createRequest(); + }); + + afterEach(() => { + if (createRequestMock) { + createRequestMock.mockClear(); + } + getAuthenticatorMock.mockClear(); + }); + describe('the newInstance method', () => { test('should use defaults when options not provided', () => { const testInstance = ContextBasedRestrictionsV1.newInstance(); @@ -109,7 +118,7 @@ describe('ContextBasedRestrictionsV1', () => { // AddressIPAddress const addressModel = { type: 'ipAddress', - value: '169.23.56.234', + value: '169.23.56.234, 3ffe:1900:fe21:4545::', }; function __createZoneTest() { @@ -122,13 +131,13 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const createZoneParams = { - name: name, - accountId: accountId, - addresses: addresses, - description: description, - excluded: excluded, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + name, + accountId, + addresses, + description, + excluded, + xCorrelationId, + transactionId, }; const createZoneResult = contextBasedRestrictionsService.createZone(createZoneParams); @@ -202,11 +211,11 @@ describe('ContextBasedRestrictionsV1', () => { const name = 'testString'; const sort = 'testString'; const listZonesParams = { - accountId: accountId, - xCorrelationId: xCorrelationId, - transactionId: transactionId, - name: name, - sort: sort, + accountId, + xCorrelationId, + transactionId, + name, + sort, }; const listZonesResult = contextBasedRestrictionsService.listZones(listZonesParams); @@ -296,9 +305,9 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const getZoneParams = { - zoneId: zoneId, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + zoneId, + xCorrelationId, + transactionId, }; const getZoneResult = contextBasedRestrictionsService.getZone(getZoneParams); @@ -385,7 +394,7 @@ describe('ContextBasedRestrictionsV1', () => { // AddressIPAddress const addressModel = { type: 'ipAddress', - value: '169.23.56.234', + value: '169.23.56.234, 3ffe:1900:fe21:4545::', }; function __replaceZoneTest() { @@ -400,15 +409,15 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const replaceZoneParams = { - zoneId: zoneId, - ifMatch: ifMatch, - name: name, - accountId: accountId, - addresses: addresses, - description: description, - excluded: excluded, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + zoneId, + ifMatch, + name, + accountId, + addresses, + description, + excluded, + xCorrelationId, + transactionId, }; const replaceZoneResult = contextBasedRestrictionsService.replaceZone(replaceZoneParams); @@ -504,9 +513,9 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const deleteZoneParams = { - zoneId: zoneId, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + zoneId, + xCorrelationId, + transactionId, }; const deleteZoneResult = contextBasedRestrictionsService.deleteZone(deleteZoneParams); @@ -594,9 +603,9 @@ describe('ContextBasedRestrictionsV1', () => { const transactionId = 'testString'; const type = 'all'; const listAvailableServicerefTargetsParams = { - xCorrelationId: xCorrelationId, - transactionId: transactionId, - type: type, + xCorrelationId, + transactionId, + type, }; const listAvailableServicerefTargetsResult = contextBasedRestrictionsService.listAvailableServicerefTargets(listAvailableServicerefTargetsParams); @@ -711,13 +720,13 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const createRuleParams = { - contexts: contexts, - resources: resources, - description: description, - operations: operations, - enforcementMode: enforcementMode, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + contexts, + resources, + description, + operations, + enforcementMode, + xCorrelationId, + transactionId, }; const createRuleResult = contextBasedRestrictionsService.createRule(createRuleParams); @@ -799,19 +808,19 @@ describe('ContextBasedRestrictionsV1', () => { const sort = 'testString'; const enforcementMode = 'enabled'; const listRulesParams = { - accountId: accountId, - xCorrelationId: xCorrelationId, - transactionId: transactionId, - region: region, - resource: resource, - resourceType: resourceType, - serviceInstance: serviceInstance, - serviceName: serviceName, - serviceType: serviceType, - serviceGroupId: serviceGroupId, - zoneId: zoneId, - sort: sort, - enforcementMode: enforcementMode, + accountId, + xCorrelationId, + transactionId, + region, + resource, + resourceType, + serviceInstance, + serviceName, + serviceType, + serviceGroupId, + zoneId, + sort, + enforcementMode, }; const listRulesResult = contextBasedRestrictionsService.listRules(listRulesParams); @@ -909,9 +918,9 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const getRuleParams = { - ruleId: ruleId, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + ruleId, + xCorrelationId, + transactionId, }; const getRuleResult = contextBasedRestrictionsService.getRule(getRuleParams); @@ -1048,15 +1057,15 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const replaceRuleParams = { - ruleId: ruleId, - ifMatch: ifMatch, - contexts: contexts, - resources: resources, - description: description, - operations: operations, - enforcementMode: enforcementMode, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + ruleId, + ifMatch, + contexts, + resources, + description, + operations, + enforcementMode, + xCorrelationId, + transactionId, }; const replaceRuleResult = contextBasedRestrictionsService.replaceRule(replaceRuleParams); @@ -1152,9 +1161,9 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const deleteRuleParams = { - ruleId: ruleId, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + ruleId, + xCorrelationId, + transactionId, }; const deleteRuleResult = contextBasedRestrictionsService.deleteRule(deleteRuleParams); @@ -1242,9 +1251,9 @@ describe('ContextBasedRestrictionsV1', () => { const xCorrelationId = 'testString'; const transactionId = 'testString'; const getAccountSettingsParams = { - accountId: accountId, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + accountId, + xCorrelationId, + transactionId, }; const getAccountSettingsResult = contextBasedRestrictionsService.getAccountSettings(getAccountSettingsParams); @@ -1328,13 +1337,17 @@ describe('ContextBasedRestrictionsV1', () => { describe('positive tests', () => { function __listAvailableServiceOperationsTest() { // Construct the params object for operation listAvailableServiceOperations - const serviceName = 'testString'; const xCorrelationId = 'testString'; const transactionId = 'testString'; + const serviceName = 'testString'; + const serviceGroupId = 'testString'; + const resourceType = 'testString'; const listAvailableServiceOperationsParams = { - serviceName: serviceName, - xCorrelationId: xCorrelationId, - transactionId: transactionId, + xCorrelationId, + transactionId, + serviceName, + serviceGroupId, + resourceType, }; const listAvailableServiceOperationsResult = contextBasedRestrictionsService.listAvailableServiceOperations(listAvailableServiceOperationsParams); @@ -1354,6 +1367,8 @@ describe('ContextBasedRestrictionsV1', () => { checkUserHeader(createRequestMock, 'X-Correlation-Id', xCorrelationId); checkUserHeader(createRequestMock, 'Transaction-Id', transactionId); expect(mockRequestOptions.qs.service_name).toEqual(serviceName); + expect(mockRequestOptions.qs.service_group_id).toEqual(serviceGroupId); + expect(mockRequestOptions.qs.resource_type).toEqual(resourceType); } test('should pass the right params to createRequest with enable and disable retries', () => { @@ -1373,11 +1388,9 @@ describe('ContextBasedRestrictionsV1', () => { test('should prioritize user-given headers', () => { // parameters - const serviceName = 'testString'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; const listAvailableServiceOperationsParams = { - serviceName, headers: { Accept: userAccept, 'Content-Type': userContentType, @@ -1387,29 +1400,11 @@ describe('ContextBasedRestrictionsV1', () => { contextBasedRestrictionsService.listAvailableServiceOperations(listAvailableServiceOperationsParams); checkMediaHeaders(createRequestMock, userAccept, userContentType); }); - }); - - describe('negative tests', () => { - test('should enforce required parameters', async () => { - let err; - try { - await contextBasedRestrictionsService.listAvailableServiceOperations({}); - } 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 contextBasedRestrictionsService.listAvailableServiceOperations(); - } catch (e) { - err = e; - } - - expect(err.message).toMatch(/Missing required parameters/); + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + contextBasedRestrictionsService.listAvailableServiceOperations({}); + checkForSuccessfulExecution(createRequestMock); }); }); });