diff --git a/cis/zones-settings/v1.ts b/cis/zones-settings/v1.ts index addb7f5..84e291c 100644 --- a/cis/zones-settings/v1.ts +++ b/cis/zones-settings/v1.ts @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.112.0-f88e9264-20260220-115155 + * IBM OpenAPI SDK Code Generator Version: 3.114.0-a902401e-20260427-192904 */ import * as extend from 'extend'; @@ -4463,6 +4463,117 @@ class ZonesSettingsV1 extends BaseService { return this.createRequest(parameters); } + + /** + * Get security level setting. + * + * Get security level for a zone. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getSecurityLevel( + params?: ZonesSettingsV1.GetSecurityLevelParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'crn': this.crn, + 'zone_identifier': this.zoneIdentifier, + }; + + const sdkHeaders = getSdkHeaders(ZonesSettingsV1.DEFAULT_SERVICE_NAME, 'v1', 'getSecurityLevel'); + + const parameters = { + options: { + url: '/v1/{crn}/zones/{zone_identifier}/settings/security_level', + 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 security level setting. + * + * Update security level setting for a zone. + * + * @param {Object} [params] - The parameters to send to the service. + * @param {string} [params.value] - Value. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public updateSecurityLevel( + params?: ZonesSettingsV1.UpdateSecurityLevelParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = []; + const _validParams = ['value', 'signal', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'value': _params.value, + }; + + const path = { + 'crn': this.crn, + 'zone_identifier': this.zoneIdentifier, + }; + + const sdkHeaders = getSdkHeaders(ZonesSettingsV1.DEFAULT_SERVICE_NAME, 'v1', 'updateSecurityLevel'); + + const parameters = { + options: { + url: '/v1/{crn}/zones/{zone_identifier}/settings/security_level', + method: 'PATCH', + 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); + } } /************************* @@ -5214,6 +5325,28 @@ namespace ZonesSettingsV1 { } } + /** Parameters for the `getSecurityLevel` operation. */ + export interface GetSecurityLevelParams extends DefaultParams { + } + + /** Parameters for the `updateSecurityLevel` operation. */ + export interface UpdateSecurityLevelParams extends DefaultParams { + /** Value. */ + value?: UpdateSecurityLevelConstants.Value | string; + } + + /** Constants for the `updateSecurityLevel` operation. */ + export namespace UpdateSecurityLevelConstants { + /** Value. */ + export enum Value { + ESSENTIALLY_OFF = 'essentially_off', + LOW = 'low', + MEDIUM = 'medium', + HIGH = 'high', + UNDER_ATTACK = 'under_attack', + } + } + /************************* * model interfaces ************************/ @@ -5313,7 +5446,7 @@ namespace ZonesSettingsV1 { /** Editable. */ editable: boolean; /** Modified date. */ - modified_on: string; + modified_on?: string; } /** @@ -5691,7 +5824,7 @@ namespace ZonesSettingsV1 { /** Editable. */ editable: boolean; /** Modified date. */ - modified_on: string; + modified_on?: string; } /** @@ -5784,6 +5917,20 @@ namespace ZonesSettingsV1 { nosniff: boolean; } + /** + * Container for response information. + */ + export interface SecurityLevelRespResult { + /** ID. */ + id: string; + /** Value. */ + value: string; + /** Editable. */ + editable: boolean; + /** Modified date. */ + modified_on?: string; + } + /** * Container for response information. */ @@ -6042,6 +6189,8 @@ namespace ZonesSettingsV1 { export interface EmailObfuscationResp { /** Container for response information. */ result: EmailObfuscationRespResult; + /** Result information. */ + result_info?: JsonObject; /** Was the get successful. */ success: boolean; /** Array of errors encountered. */ @@ -6335,6 +6484,8 @@ namespace ZonesSettingsV1 { export interface ReplaceInsecureJsResp { /** Container for response information. */ result: ReplaceInsecureJsRespResult; + /** Result information. */ + result_info?: JsonObject; /** Was the get successful. */ success: boolean; /** Array of errors encountered. */ @@ -6385,6 +6536,20 @@ namespace ZonesSettingsV1 { messages: string[][]; } + /** + * Security level response. + */ + export interface SecurityLevelResp { + /** Container for response information. */ + result: SecurityLevelRespResult; + /** Was the get successful. */ + success: boolean; + /** Array of errors encountered. */ + errors: string[][]; + /** Array of messages returned. */ + messages: string[][]; + } + /** * Response of server side exclude. */ diff --git a/test/integration/cis/zones-settings.v1.test.js b/test/integration/cis/zones-settings.v1.test.js index 32d00eb..58f62a1 100644 --- a/test/integration/cis/zones-settings.v1.test.js +++ b/test/integration/cis/zones-settings.v1.test.js @@ -2077,4 +2077,49 @@ describe.skip('Zones Settings', () => { }); }); }); -}); + + describe('Security Level', () => { + let securityLevelInstance; + beforeAll(() => { + securityLevelInstance = ZoneSettingsApi.newInstance({ + authenticator: new IamAuthenticator({ + apikey: config.CIS_SERVICES_APIKEY, + url: config.CIS_SERVICES_AUTH_URL, + }), + crn: config.CIS_SERVICES_CRN, + serviceUrl: config.CIS_SERVICES_URL, + version: config.CIS_SERVICES_API_VERSION, + zoneIdentifier: config.CIS_SERVICES_ZONE_ID, + }); + }); + + test('should successfully get security level setting', async () => { + const response = await securityLevelInstance.getSecurityLevel(); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + + expect(result).toBeDefined(); + if (result && result.result) { + expect(result.result).toBeDefined(); + } + }); + + test('should successfully update security level setting', async () => { + const params = { + value: 'medium', + }; + const response = await securityLevelInstance.updateSecurityLevel(params); + expect(response).toBeDefined(); + expect(response.status).toEqual(200); + + const { result } = response || {}; + + expect(result).toBeDefined(); + if (result && result.result) { + expect(result.result).toBeDefined(); + } + }); + }); +}); \ No newline at end of file diff --git a/test/unit/cis/zones-settings.v1.test.js b/test/unit/cis/zones-settings.v1.test.js index d8fa350..d9bc95c 100644 --- a/test/unit/cis/zones-settings.v1.test.js +++ b/test/unit/cis/zones-settings.v1.test.js @@ -5224,4 +5224,132 @@ describe('ZonesSettingsV1', () => { }); }); }); + + describe('getSecurityLevel', () => { + describe('positive tests', () => { + function __getSecurityLevelTest() { + // Construct the params object for operation getSecurityLevel + const getSecurityLevelParams = {}; + + const getSecurityLevelResult = zonesSettingsService.getSecurityLevel(getSecurityLevelParams); + + // all methods should return a Promise + expectToBePromise(getSecurityLevelResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/zones/{zone_identifier}/settings/security_level', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.crn).toEqual(zonesSettingsServiceOptions.crn); + expect(mockRequestOptions.path.zone_identifier).toEqual(zonesSettingsServiceOptions.zoneIdentifier); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getSecurityLevelTest(); + + // enable retries and test again + createRequestMock.mockClear(); + zonesSettingsService.enableRetries(); + __getSecurityLevelTest(); + + // disable retries and test again + createRequestMock.mockClear(); + zonesSettingsService.disableRetries(); + __getSecurityLevelTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getSecurityLevelParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + zonesSettingsService.getSecurityLevel(getSecurityLevelParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + zonesSettingsService.getSecurityLevel({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); + + describe('updateSecurityLevel', () => { + describe('positive tests', () => { + function __updateSecurityLevelTest() { + // Construct the params object for operation updateSecurityLevel + const value = 'medium'; + const updateSecurityLevelParams = { + value, + }; + + const updateSecurityLevelResult = zonesSettingsService.updateSecurityLevel(updateSecurityLevelParams); + + // all methods should return a Promise + expectToBePromise(updateSecurityLevelResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/{crn}/zones/{zone_identifier}/settings/security_level', 'PATCH'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.value).toEqual(value); + expect(mockRequestOptions.path.crn).toEqual(zonesSettingsServiceOptions.crn); + expect(mockRequestOptions.path.zone_identifier).toEqual(zonesSettingsServiceOptions.zoneIdentifier); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __updateSecurityLevelTest(); + + // enable retries and test again + createRequestMock.mockClear(); + zonesSettingsService.enableRetries(); + __updateSecurityLevelTest(); + + // disable retries and test again + createRequestMock.mockClear(); + zonesSettingsService.disableRetries(); + __updateSecurityLevelTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const updateSecurityLevelParams = { + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + zonesSettingsService.updateSecurityLevel(updateSecurityLevelParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + + test('should not have any problems when no parameters are passed in', () => { + // invoke the method with no parameters + zonesSettingsService.updateSecurityLevel({}); + checkForSuccessfulExecution(createRequestMock); + }); + }); + }); });