diff --git a/examples/usage-reports.v4.test.js b/examples/usage-reports.v4.test.js index 242b635b..4d1f2881 100644 --- a/examples/usage-reports.v4.test.js +++ b/examples/usage-reports.v4.test.js @@ -34,6 +34,10 @@ const authHelper = require('../test/resources/auth-helper.js'); // USAGE_REPORTS_RESOURCE_GROUP_ID= // USAGE_REPORTS_ORG_ID= // USAGE_REPORTS_BILLING_MONTH= +// USAGE_REPORTS_COS_BUCKET= +// USAGE_REPORTS_COS_LOCATION= +// USAGE_REPORTS_DATE_FROM= +// USAGE_REPORTS_DATE_TO= // // These configuration properties can be exported as environment variables, or stored // in a configuration file and then: @@ -66,6 +70,10 @@ describe('UsageReportsV4', () => { let resourceGroupId = config.resourceGroupId; let orgId = config.orgId; let billingMonth = config.billingMonth; + let cosBucket = config.cosBucket; + let cosLocation = config.cosLocation; + let snapshotDateFrom = config.snapshotDateFrom; + let snapshotDateTo = config.snapshotDateTo; test('getAccountSummary request example', async () => { @@ -267,4 +275,146 @@ describe('UsageReportsV4', () => { // end-get_resource_usage_org }); + test('createReportsSnapshotConfig 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('createReportsSnapshotConfig() result:'); + // begin-create_reports_snapshot_config + + const params = { + accountId, + interval: 'daily', + cosBucket, + cosLocation, + }; + + let res; + try { + res = await usageReportsService.createReportsSnapshotConfig(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-create_reports_snapshot_config + }); + + test('getReportsSnapshotConfig 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('getReportsSnapshotConfig() result:'); + // begin-get_reports_snapshot_config + + const params = { + accountId, + }; + + let res; + try { + res = await usageReportsService.getReportsSnapshotConfig(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-get_reports_snapshot_config + }); + + test('updateReportsSnapshotConfig 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('updateReportsSnapshotConfig() result:'); + // begin-update_reports_snapshot_config + + const params = { + accountId, + }; + + let res; + try { + res = await usageReportsService.updateReportsSnapshotConfig(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-update_reports_snapshot_config + }); + + test('getReportsSnapshot 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('getReportsSnapshot() result:'); + // begin-get_reports_snapshot + + const params = { + accountId, + month: billingMonth, + dateFrom: snapshotDateFrom, + dateTo: snapshotDateTo, + }; + + let res; + try { + res = await usageReportsService.getReportsSnapshot(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-get_reports_snapshot + }); + + test('deleteReportsSnapshotConfig 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_reports_snapshot_config + + const params = { + accountId, + }; + + try { + await usageReportsService.deleteReportsSnapshotConfig(params); + } catch (err) { + console.warn(err); + } + + // end-delete_reports_snapshot_config + }); }); diff --git a/test/integration/usage-reports.v4.test.js b/test/integration/usage-reports.v4.test.js index 07598124..1c9fd4ea 100644 --- a/test/integration/usage-reports.v4.test.js +++ b/test/integration/usage-reports.v4.test.js @@ -33,6 +33,10 @@ let accountId; let resourceGroupId; let orgId; let billingMonth; +let cosBucket; +let cosLocation; +let snapshotDateFrom; +let snapshotDateTo; describe('UsageReportsV4_integration', () => { jest.setTimeout(timeout); @@ -49,10 +53,18 @@ describe('UsageReportsV4_integration', () => { resourceGroupId = config.resourceGroupId; orgId = config.orgId; billingMonth = config.billingMonth; + cosBucket = config.cosBucket; + cosLocation = config.cosLocation; + snapshotDateFrom = config.snapshotDateFrom; + snapshotDateTo = config.snapshotDateTo; expect(accountId).not.toBeNull(); expect(resourceGroupId).not.toBeNull(); expect(orgId).not.toBeNull(); expect(billingMonth).not.toBeNull(); + expect(cosBucket).not.toBeNull(); + expect(cosLocation).not.toBeNull(); + expect(snapshotDateFrom).not.toBeNull(); + expect(snapshotDateTo).not.toBeNull(); // console.log('Finished setup.'); }); @@ -293,4 +305,74 @@ describe('UsageReportsV4_integration', () => { // console.log(`getResourceUsageOrg() response contained ${numResources} total resources`); expect(numResources).toBeGreaterThan(0); }); + + test('createReportsSnapshotConfig()', async () => { + const params = { + accountId, + interval: 'daily', + cosBucket, + cosLocation, + cosReportsFolder: 'IBMCloud-Billing-Reports', + reportTypes: ['account_summary', 'enterprise_summary', 'account_resource_instance_usage'], + versioning: 'new', + }; + + const res = await usageReportsService.createReportsSnapshotConfig(params); + expect(res).toBeDefined(); + expect(res.status).toBe(201); + expect(res.result).toBeDefined(); + }); + + test('getReportsSnapshotConfig()', async () => { + const params = { + accountId, + }; + + const res = await usageReportsService.getReportsSnapshotConfig(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('updateReportsSnapshotConfig()', async () => { + const params = { + accountId, + interval: 'daily', + cosBucket, + cosLocation, + cosReportsFolder: 'IBMCloud-Billing-Reports', + reportTypes: ['account_summary', 'enterprise_summary'], + versioning: 'new', + }; + + const res = await usageReportsService.updateReportsSnapshotConfig(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('getReportsSnapshot()', async () => { + const params = { + accountId, + month: billingMonth, + dateFrom: snapshotDateFrom, + dateTo: snapshotDateTo, + }; + + const res = await usageReportsService.getReportsSnapshot(params); + expect(res).toBeDefined(); + expect(res.status).toBe(200); + expect(res.result).toBeDefined(); + }); + + test('deleteReportsSnapshotConfig()', async () => { + const params = { + accountId, + }; + + const res = await usageReportsService.deleteReportsSnapshotConfig(params); + expect(res).toBeDefined(); + expect(res.status).toBe(204); + expect(res.result).toBeDefined(); + }); }); diff --git a/test/unit/usage-reports.v4.test.js b/test/unit/usage-reports.v4.test.js index 8e9591fd..7101851e 100644 --- a/test/unit/usage-reports.v4.test.js +++ b/test/unit/usage-reports.v4.test.js @@ -15,9 +15,9 @@ */ // need to import the whole package to mock getAuthenticatorFromEnvironment -const core = require('ibm-cloud-sdk-core'); +const sdkCorePackage = require('ibm-cloud-sdk-core'); -const { NoAuthAuthenticator, unitTestUtils } = core; +const { NoAuthAuthenticator, unitTestUtils } = sdkCorePackage; const UsageReportsV4 = require('../../dist/usage-reports/v4'); const nock = require('nock'); @@ -54,7 +54,7 @@ function unmock_createRequest() { } // dont actually construct an authenticator -const getAuthenticatorMock = jest.spyOn(core, 'getAuthenticatorFromEnvironment'); +const getAuthenticatorMock = jest.spyOn(sdkCorePackage, 'getAuthenticatorFromEnvironment'); getAuthenticatorMock.mockImplementation(() => new NoAuthAuthenticator()); describe('UsageReportsV4', () => { @@ -1059,4 +1059,477 @@ describe('UsageReportsV4', () => { }); }); }); + + describe('createReportsSnapshotConfig', () => { + describe('positive tests', () => { + function __createReportsSnapshotConfigTest() { + // Construct the params object for operation createReportsSnapshotConfig + const accountId = 'abc'; + const interval = 'daily'; + const cosBucket = 'bucket_name'; + const cosLocation = 'us-south'; + const cosReportsFolder = 'IBMCloud-Billing-Reports'; + const reportTypes = ['account_summary', 'enterprise_summary', 'account_resource_instance_usage']; + const versioning = 'new'; + const createReportsSnapshotConfigParams = { + accountId, + interval, + cosBucket, + cosLocation, + cosReportsFolder, + reportTypes, + versioning, + }; + + const createReportsSnapshotConfigResult = usageReportsService.createReportsSnapshotConfig(createReportsSnapshotConfigParams); + + // all methods should return a Promise + expectToBePromise(createReportsSnapshotConfigResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/billing-reports-snapshot-config', 'POST'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.account_id).toEqual(accountId); + expect(mockRequestOptions.body.interval).toEqual(interval); + expect(mockRequestOptions.body.cos_bucket).toEqual(cosBucket); + expect(mockRequestOptions.body.cos_location).toEqual(cosLocation); + expect(mockRequestOptions.body.cos_reports_folder).toEqual(cosReportsFolder); + expect(mockRequestOptions.body.report_types).toEqual(reportTypes); + expect(mockRequestOptions.body.versioning).toEqual(versioning); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createReportsSnapshotConfigTest(); + + // enable retries and test again + createRequestMock.mockClear(); + usageReportsService.enableRetries(); + __createReportsSnapshotConfigTest(); + + // disable retries and test again + createRequestMock.mockClear(); + usageReportsService.disableRetries(); + __createReportsSnapshotConfigTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'abc'; + const interval = 'daily'; + const cosBucket = 'bucket_name'; + const cosLocation = 'us-south'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createReportsSnapshotConfigParams = { + accountId, + interval, + cosBucket, + cosLocation, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + usageReportsService.createReportsSnapshotConfig(createReportsSnapshotConfigParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await usageReportsService.createReportsSnapshotConfig({}); + } 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 usageReportsService.createReportsSnapshotConfig(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('getReportsSnapshotConfig', () => { + describe('positive tests', () => { + function __getReportsSnapshotConfigTest() { + // Construct the params object for operation getReportsSnapshotConfig + const accountId = 'abc'; + const getReportsSnapshotConfigParams = { + accountId, + }; + + const getReportsSnapshotConfigResult = usageReportsService.getReportsSnapshotConfig(getReportsSnapshotConfigParams); + + // all methods should return a Promise + expectToBePromise(getReportsSnapshotConfigResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/billing-reports-snapshot-config', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.account_id).toEqual(accountId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getReportsSnapshotConfigTest(); + + // enable retries and test again + createRequestMock.mockClear(); + usageReportsService.enableRetries(); + __getReportsSnapshotConfigTest(); + + // disable retries and test again + createRequestMock.mockClear(); + usageReportsService.disableRetries(); + __getReportsSnapshotConfigTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'abc'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getReportsSnapshotConfigParams = { + accountId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + usageReportsService.getReportsSnapshotConfig(getReportsSnapshotConfigParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await usageReportsService.getReportsSnapshotConfig({}); + } 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 usageReportsService.getReportsSnapshotConfig(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('updateReportsSnapshotConfig', () => { + describe('positive tests', () => { + function __updateReportsSnapshotConfigTest() { + // Construct the params object for operation updateReportsSnapshotConfig + const accountId = 'abc'; + const interval = 'daily'; + const cosBucket = 'bucket_name'; + const cosLocation = 'us-south'; + const cosReportsFolder = 'IBMCloud-Billing-Reports'; + const reportTypes = ['account_summary', 'enterprise_summary', 'account_resource_instance_usage']; + const versioning = 'new'; + const updateReportsSnapshotConfigParams = { + accountId, + interval, + cosBucket, + cosLocation, + cosReportsFolder, + reportTypes, + versioning, + }; + + const updateReportsSnapshotConfigResult = usageReportsService.updateReportsSnapshotConfig(updateReportsSnapshotConfigParams); + + // all methods should return a Promise + expectToBePromise(updateReportsSnapshotConfigResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/billing-reports-snapshot-config', 'PATCH'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.account_id).toEqual(accountId); + expect(mockRequestOptions.body.interval).toEqual(interval); + expect(mockRequestOptions.body.cos_bucket).toEqual(cosBucket); + expect(mockRequestOptions.body.cos_location).toEqual(cosLocation); + expect(mockRequestOptions.body.cos_reports_folder).toEqual(cosReportsFolder); + expect(mockRequestOptions.body.report_types).toEqual(reportTypes); + expect(mockRequestOptions.body.versioning).toEqual(versioning); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __updateReportsSnapshotConfigTest(); + + // enable retries and test again + createRequestMock.mockClear(); + usageReportsService.enableRetries(); + __updateReportsSnapshotConfigTest(); + + // disable retries and test again + createRequestMock.mockClear(); + usageReportsService.disableRetries(); + __updateReportsSnapshotConfigTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'abc'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const updateReportsSnapshotConfigParams = { + accountId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + usageReportsService.updateReportsSnapshotConfig(updateReportsSnapshotConfigParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await usageReportsService.updateReportsSnapshotConfig({}); + } 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 usageReportsService.updateReportsSnapshotConfig(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('deleteReportsSnapshotConfig', () => { + describe('positive tests', () => { + function __deleteReportsSnapshotConfigTest() { + // Construct the params object for operation deleteReportsSnapshotConfig + const accountId = 'abc'; + const deleteReportsSnapshotConfigParams = { + accountId, + }; + + const deleteReportsSnapshotConfigResult = usageReportsService.deleteReportsSnapshotConfig(deleteReportsSnapshotConfigParams); + + // all methods should return a Promise + expectToBePromise(deleteReportsSnapshotConfigResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/billing-reports-snapshot-config', 'DELETE'); + const expectedAccept = undefined; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.account_id).toEqual(accountId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteReportsSnapshotConfigTest(); + + // enable retries and test again + createRequestMock.mockClear(); + usageReportsService.enableRetries(); + __deleteReportsSnapshotConfigTest(); + + // disable retries and test again + createRequestMock.mockClear(); + usageReportsService.disableRetries(); + __deleteReportsSnapshotConfigTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'abc'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteReportsSnapshotConfigParams = { + accountId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + usageReportsService.deleteReportsSnapshotConfig(deleteReportsSnapshotConfigParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await usageReportsService.deleteReportsSnapshotConfig({}); + } 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 usageReportsService.deleteReportsSnapshotConfig(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('getReportsSnapshot', () => { + describe('positive tests', () => { + function __getReportsSnapshotTest() { + // Construct the params object for operation getReportsSnapshot + const accountId = 'abc'; + const month = '2023-02'; + const dateFrom = 1675209600000; + const dateTo = 1675987200000; + const getReportsSnapshotParams = { + accountId, + month, + dateFrom, + dateTo, + }; + + const getReportsSnapshotResult = usageReportsService.getReportsSnapshot(getReportsSnapshotParams); + + // all methods should return a Promise + expectToBePromise(getReportsSnapshotResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/billing-reports-snapshots', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.account_id).toEqual(accountId); + expect(mockRequestOptions.qs.month).toEqual(month); + expect(mockRequestOptions.qs.date_from).toEqual(dateFrom); + expect(mockRequestOptions.qs.date_to).toEqual(dateTo); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getReportsSnapshotTest(); + + // enable retries and test again + createRequestMock.mockClear(); + usageReportsService.enableRetries(); + __getReportsSnapshotTest(); + + // disable retries and test again + createRequestMock.mockClear(); + usageReportsService.disableRetries(); + __getReportsSnapshotTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'abc'; + const month = '2023-02'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getReportsSnapshotParams = { + accountId, + month, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + usageReportsService.getReportsSnapshot(getReportsSnapshotParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await usageReportsService.getReportsSnapshot({}); + } 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 usageReportsService.getReportsSnapshot(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); }); diff --git a/usage-reports/v4.ts b/usage-reports/v4.ts index f2a9fe86..5c11f03e 100644 --- a/usage-reports/v4.ts +++ b/usage-reports/v4.ts @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.64.1-cee95189-20230124-211647 + * IBM OpenAPI SDK Code Generator Version: 3.75.0-726bc7e3-20230713-221716 */ /* eslint-disable max-classes-per-file */ @@ -652,6 +652,318 @@ class UsageReportsV4 extends BaseService { }), }; + return this.createRequest(parameters); + } + /************************* + * billingReportsSnapshot + ************************/ + + /** + * Setup the snapshot configuration. + * + * Snapshots of the billing reports would be taken on a periodic interval and stored based on the configuration setup + * by the customer for the given Account Id. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - Account ID for which billing report snapshot is configured. + * @param {string} params.interval - Frequency of taking the snapshot of the billing reports. + * @param {string} params.cosBucket - The name of the COS bucket to store the snapshot of the billing reports. + * @param {string} params.cosLocation - Region of the COS instance. + * @param {string} [params.cosReportsFolder] - The billing reports root folder to store the billing reports snapshots. + * Defaults to "IBMCloud-Billing-Reports". + * @param {string[]} [params.reportTypes] - The type of billing reports to take snapshot of. Possible values are + * [account_summary, enterprise_summary, account_resource_instance_usage]. + * @param {string} [params.versioning] - A new version of report is created or the existing report version is + * overwritten with every update. Defaults to "new". + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createReportsSnapshotConfig( + params: UsageReportsV4.CreateReportsSnapshotConfigParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId', 'interval', 'cosBucket', 'cosLocation']; + const _validParams = [ + 'accountId', + 'interval', + 'cosBucket', + 'cosLocation', + 'cosReportsFolder', + 'reportTypes', + 'versioning', + 'headers', + ]; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'account_id': _params.accountId, + 'interval': _params.interval, + 'cos_bucket': _params.cosBucket, + 'cos_location': _params.cosLocation, + 'cos_reports_folder': _params.cosReportsFolder, + 'report_types': _params.reportTypes, + 'versioning': _params.versioning, + }; + + const sdkHeaders = getSdkHeaders( + UsageReportsV4.DEFAULT_SERVICE_NAME, + 'v4', + 'createReportsSnapshotConfig' + ); + + const parameters = { + options: { + url: '/v1/billing-reports-snapshot-config', + method: 'POST', + body, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Fetch the snapshot configuration. + * + * Returns the configuration of snapshot of the billing reports setup by the customer for the given Account Id. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - Account ID for which the billing report snapshot is configured. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getReportsSnapshotConfig( + params: UsageReportsV4.GetReportsSnapshotConfigParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId']; + const _validParams = ['accountId', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'account_id': _params.accountId, + }; + + const sdkHeaders = getSdkHeaders( + UsageReportsV4.DEFAULT_SERVICE_NAME, + 'v4', + 'getReportsSnapshotConfig' + ); + + const parameters = { + options: { + url: '/v1/billing-reports-snapshot-config', + method: 'GET', + qs: query, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Update the snapshot configuration. + * + * Updates the configuration of snapshot of the billing reports setup by the customer for the given Account Id. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - Account ID for which billing report snapshot is configured. + * @param {string} [params.interval] - Frequency of taking the snapshot of the billing reports. + * @param {string} [params.cosBucket] - The name of the COS bucket to store the snapshot of the billing reports. + * @param {string} [params.cosLocation] - Region of the COS instance. + * @param {string} [params.cosReportsFolder] - The billing reports root folder to store the billing reports snapshots. + * @param {string[]} [params.reportTypes] - The type of billing reports to take snapshot of. Possible values are + * [account_summary, enterprise_summary, account_resource_instance_usage]. + * @param {string} [params.versioning] - A new version of report is created or the existing report version is + * overwritten with every update. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public updateReportsSnapshotConfig( + params: UsageReportsV4.UpdateReportsSnapshotConfigParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId']; + const _validParams = [ + 'accountId', + 'interval', + 'cosBucket', + 'cosLocation', + 'cosReportsFolder', + 'reportTypes', + 'versioning', + 'headers', + ]; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'account_id': _params.accountId, + 'interval': _params.interval, + 'cos_bucket': _params.cosBucket, + 'cos_location': _params.cosLocation, + 'cos_reports_folder': _params.cosReportsFolder, + 'report_types': _params.reportTypes, + 'versioning': _params.versioning, + }; + + const sdkHeaders = getSdkHeaders( + UsageReportsV4.DEFAULT_SERVICE_NAME, + 'v4', + 'updateReportsSnapshotConfig' + ); + + const parameters = { + options: { + url: '/v1/billing-reports-snapshot-config', + method: 'PATCH', + body, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Delete the snapshot configuration. + * + * Delete the configuration of snapshot of the billing reports setup by the customer for the given Account Id. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - Account ID for which the billing report snapshot is configured. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteReportsSnapshotConfig( + params: UsageReportsV4.DeleteReportsSnapshotConfigParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId']; + const _validParams = ['accountId', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'account_id': _params.accountId, + }; + + const sdkHeaders = getSdkHeaders( + UsageReportsV4.DEFAULT_SERVICE_NAME, + 'v4', + 'deleteReportsSnapshotConfig' + ); + + const parameters = { + options: { + url: '/v1/billing-reports-snapshot-config', + method: 'DELETE', + qs: query, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend(true, sdkHeaders, {}, _params.headers), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Fetch the current or past snapshots. + * + * Returns the billing reports snapshots captured for the given Account Id in the specific time period. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - Account ID for which the billing report snapshot is requested. + * @param {string} params.month - The month for which billing report snapshot is requested. Format is yyyy-mm. + * @param {number} [params.dateFrom] - Timestamp in milliseconds for which billing report snapshot is requested. + * @param {number} [params.dateTo] - Timestamp in milliseconds for which billing report snapshot is requested. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getReportsSnapshot( + params: UsageReportsV4.GetReportsSnapshotParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId', 'month']; + const _validParams = ['accountId', 'month', 'dateFrom', 'dateTo', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'account_id': _params.accountId, + 'month': _params.month, + 'date_from': _params.dateFrom, + 'date_to': _params.dateTo, + }; + + const sdkHeaders = getSdkHeaders( + UsageReportsV4.DEFAULT_SERVICE_NAME, + 'v4', + 'getReportsSnapshot' + ); + + const parameters = { + options: { + url: '/v1/billing-reports-snapshots', + method: 'GET', + qs: query, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + return this.createRequest(parameters); } } @@ -819,6 +1131,117 @@ namespace UsageReportsV4 { headers?: OutgoingHttpHeaders; } + /** Parameters for the `createReportsSnapshotConfig` operation. */ + export interface CreateReportsSnapshotConfigParams { + /** Account ID for which billing report snapshot is configured. */ + accountId: string; + /** Frequency of taking the snapshot of the billing reports. */ + interval: CreateReportsSnapshotConfigConstants.Interval | string; + /** The name of the COS bucket to store the snapshot of the billing reports. */ + cosBucket: string; + /** Region of the COS instance. */ + cosLocation: string; + /** The billing reports root folder to store the billing reports snapshots. Defaults to + * "IBMCloud-Billing-Reports". + */ + cosReportsFolder?: string; + /** The type of billing reports to take snapshot of. Possible values are [account_summary, enterprise_summary, + * account_resource_instance_usage]. + */ + reportTypes?: CreateReportsSnapshotConfigConstants.ReportTypes | string[]; + /** A new version of report is created or the existing report version is overwritten with every update. Defaults + * to "new". + */ + versioning?: CreateReportsSnapshotConfigConstants.Versioning | string; + headers?: OutgoingHttpHeaders; + } + + /** Constants for the `createReportsSnapshotConfig` operation. */ + export namespace CreateReportsSnapshotConfigConstants { + /** Frequency of taking the snapshot of the billing reports. */ + export enum Interval { + DAILY = 'daily', + } + /** ReportTypes */ + export enum ReportTypes { + ACCOUNT_SUMMARY = 'account_summary', + ENTERPRISE_SUMMARY = 'enterprise_summary', + ACCOUNT_RESOURCE_INSTANCE_USAGE = 'account_resource_instance_usage', + } + /** A new version of report is created or the existing report version is overwritten with every update. Defaults to "new". */ + export enum Versioning { + NEW = 'new', + OVERWRITE = 'overwrite', + } + } + + /** Parameters for the `getReportsSnapshotConfig` operation. */ + export interface GetReportsSnapshotConfigParams { + /** Account ID for which the billing report snapshot is configured. */ + accountId: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `updateReportsSnapshotConfig` operation. */ + export interface UpdateReportsSnapshotConfigParams { + /** Account ID for which billing report snapshot is configured. */ + accountId: string; + /** Frequency of taking the snapshot of the billing reports. */ + interval?: UpdateReportsSnapshotConfigConstants.Interval | string; + /** The name of the COS bucket to store the snapshot of the billing reports. */ + cosBucket?: string; + /** Region of the COS instance. */ + cosLocation?: string; + /** The billing reports root folder to store the billing reports snapshots. */ + cosReportsFolder?: string; + /** The type of billing reports to take snapshot of. Possible values are [account_summary, enterprise_summary, + * account_resource_instance_usage]. + */ + reportTypes?: UpdateReportsSnapshotConfigConstants.ReportTypes | string[]; + /** A new version of report is created or the existing report version is overwritten with every update. */ + versioning?: UpdateReportsSnapshotConfigConstants.Versioning | string; + headers?: OutgoingHttpHeaders; + } + + /** Constants for the `updateReportsSnapshotConfig` operation. */ + export namespace UpdateReportsSnapshotConfigConstants { + /** Frequency of taking the snapshot of the billing reports. */ + export enum Interval { + DAILY = 'daily', + } + /** ReportTypes */ + export enum ReportTypes { + ACCOUNT_SUMMARY = 'account_summary', + ENTERPRISE_SUMMARY = 'enterprise_summary', + ACCOUNT_RESOURCE_INSTANCE_USAGE = 'account_resource_instance_usage', + } + /** A new version of report is created or the existing report version is overwritten with every update. */ + export enum Versioning { + NEW = 'new', + OVERWRITE = 'overwrite', + } + } + + /** Parameters for the `deleteReportsSnapshotConfig` operation. */ + export interface DeleteReportsSnapshotConfigParams { + /** Account ID for which the billing report snapshot is configured. */ + accountId: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `getReportsSnapshot` operation. */ + export interface GetReportsSnapshotParams { + /** Account ID for which the billing report snapshot is requested. */ + accountId: string; + /** The month for which billing report snapshot is requested. Format is yyyy-mm. */ + month: string; + /** Timestamp in milliseconds for which billing report snapshot is requested. */ + dateFrom?: number; + /** Timestamp in milliseconds for which billing report snapshot is requested. */ + dateTo?: number; + headers?: OutgoingHttpHeaders; + } + /************************* * model interfaces ************************/ @@ -1098,6 +1521,169 @@ namespace UsageReportsV4 { non_billable_cost: number; } + /** SnapshotConfigHistoryItem. */ + export interface SnapshotConfigHistoryItem { + /** Timestamp in milliseconds when the snapshot configuration was created. */ + start_time?: number; + /** Timestamp in milliseconds when the snapshot configuration ends. */ + end_time?: number; + /** Account that updated the billing snapshot configuration. */ + updated_by?: string; + /** Account ID for which billing report snapshot is configured. */ + account_id?: string; + /** Status of the billing snapshot configuration. Possible values are [enabled, disabled]. */ + state?: string; + /** Type of account. Possible values [enterprise, account]. */ + account_type?: string; + /** Frequency of taking the snapshot of the billing reports. */ + interval?: string; + /** A new version of report is created or the existing report version is overwritten with every update. */ + versioning?: string; + /** The type of billing reports to take snapshot of. Possible values are [account_summary, enterprise_summary, + * account_resource_instance_usage]. + */ + report_types?: string[]; + /** Compression format of the snapshot report. */ + compression?: string; + /** Type of content stored in snapshot report. */ + content_type?: string; + /** The billing reports root folder to store the billing reports snapshots. Defaults to + * "IBMCloud-Billing-Reports". + */ + cos_reports_folder?: string; + /** The name of the COS bucket to store the snapshot of the billing reports. */ + cos_bucket?: string; + /** Region of the COS instance. */ + cos_location?: string; + /** The endpoint of the COS instance. */ + cos_endpoint?: string; + } + + /** List of billing reports snapshots. */ + export interface SnapshotList { + /** Number of total snapshots. */ + count?: number; + /** Reference to the first page of the search query. */ + first?: SnapshotListFirst; + /** Reference to the next page of the search query if any. */ + next?: SnapshotListNext; + snapshots?: SnapshotListSnapshotsItem[]; + } + + /** Reference to the first page of the search query. */ + export interface SnapshotListFirst { + href?: string; + } + + /** Reference to the next page of the search query if any. */ + export interface SnapshotListNext { + href?: string; + } + + /** Snapshot Schema. */ + export interface SnapshotListSnapshotsItem { + /** Account ID for which billing report snapshot is configured. */ + account_id?: string; + /** Month of captured snapshot. */ + month?: string; + /** Type of account. Possible values are [enterprise, account]. */ + account_type?: string; + /** Timestamp of snapshot processed. */ + expected_processed_at?: number; + /** Status of the billing snapshot configuration. Possible values are [enabled, disabled]. */ + state?: string; + /** Period of billing in snapshot. */ + billing_period?: SnapshotListSnapshotsItemBillingPeriod; + /** Id of the snapshot captured. */ + snapshot_id?: string; + /** Character encoding used. */ + charset?: string; + /** Compression format of the snapshot report. */ + compression?: string; + /** Type of content stored in snapshot report. */ + content_type?: string; + /** The name of the COS bucket to store the snapshot of the billing reports. */ + bucket?: string; + /** Version of the snapshot. */ + version?: string; + /** Date and time of creation of snapshot. */ + created_on?: string; + /** List of report types configured for the snapshot. */ + report_types?: SnapshotListSnapshotsItemReportTypesItem[]; + /** List of location of reports. */ + files?: SnapshotListSnapshotsItemFilesItem[]; + /** Timestamp at which snapshot is captured. */ + processed_at?: number; + } + + /** Period of billing in snapshot. */ + export interface SnapshotListSnapshotsItemBillingPeriod { + /** Date and time of start of billing in the respective snapshot. */ + start?: string; + /** Date and time of end of billing in the respective snapshot. */ + end?: string; + } + + /** SnapshotListSnapshotsItemFilesItem. */ + export interface SnapshotListSnapshotsItemFilesItem { + /** The type of billing report stored. Possible values are [account_summary, enterprise_summary, + * account_resource_instance_usage]. + */ + report_types?: string; + /** Absolute path of the billing report in the COS instance. */ + location?: string; + /** Account ID for which billing report is captured. */ + account_id?: string; + } + + /** SnapshotListSnapshotsItemReportTypesItem. */ + export interface SnapshotListSnapshotsItemReportTypesItem { + /** The type of billing report of the snapshot. Possible values are [account_summary, enterprise_summary, + * account_resource_instance_usage]. + */ + type?: string; + /** Version of the snapshot. */ + version?: string; + } + + /** Billing reports snapshot configuration. */ + export interface SnapshotConfig { + /** Account ID for which billing report snapshot is configured. */ + account_id?: string; + /** Status of the billing snapshot configuration. Possible values are [enabled, disabled]. */ + state?: string; + /** Type of account. Possible values are [enterprise, account]. */ + account_type?: string; + /** Frequency of taking the snapshot of the billing reports. */ + interval?: string; + /** A new version of report is created or the existing report version is overwritten with every update. */ + versioning?: string; + /** The type of billing reports to take snapshot of. Possible values are [account_summary, enterprise_summary, + * account_resource_instance_usage]. + */ + report_types?: string[]; + /** Compression format of the snapshot report. */ + compression?: string; + /** Type of content stored in snapshot report. */ + content_type?: string; + /** The billing reports root folder to store the billing reports snapshots. Defaults to + * "IBMCloud-Billing-Reports". + */ + cos_reports_folder?: string; + /** The name of the COS bucket to store the snapshot of the billing reports. */ + cos_bucket?: string; + /** Region of the COS instance. */ + cos_location?: string; + /** The endpoint of the COS instance. */ + cos_endpoint?: string; + /** Timestamp in milliseconds when the snapshot configuration was created. */ + created_at?: number; + /** Timestamp in milliseconds when the snapshot configuration was last updated. */ + last_updated_at?: number; + /** List of previous versions of the snapshot configurations. */ + history?: SnapshotConfigHistoryItem[]; + } + /** Subscription. */ export interface Subscription { /** The ID of the subscription. */