Skip to content

Commit

Permalink
fix(Resource Manager): update service after recent API changes and ge…
Browse files Browse the repository at this point in the history
…nerate examples (#84)


Co-authored-by: Norbert Biczo <[email protected]>
Co-authored-by: András Csányi <[email protected]>
  • Loading branch information
3 people authored Mar 18, 2021
1 parent d284dfc commit 4d63345
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 60 deletions.
258 changes: 258 additions & 0 deletions examples/resource-manager.v2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
/**
* @jest-environment node
*/
/**
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';

const ResourceManagerV2 = require('../dist/resource-manager/v2');
const { readExternalSources } = require('ibm-cloud-sdk-core');
const authHelper = require('../test/resources/auth-helper.js');

//
// This file provides an example of how to use the Resource Manager service.
//
// The following configuration properties are assumed to be defined:
// The following configuration properties are assumed to be defined:
// RESOURCE_MANAGER_URL=<service base url>
// RESOURCE_MANAGER_AUTH_TYPE=iam
// RESOURCE_MANAGER_APIKEY=<IAM apikey of the service>
// RESOURCE_MANAGER_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
// RESOURCE_MANAGER_QUOTA_ID=<quota ID>
// RESOURCE_MANAGER_USER_ACCOUNT_ID=<account ID of the user with delete permission>
//
// ALT_RESOURCE_MANAGER_URL=<service base url>
// ALT_RESOURCE_MANAGER_AUTH_TYPE=iam
// ALT_RESOURCE_MANAGER_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
// ALT_RESOURCE_MANAGER_APIKEY=<IAM apikey of the user with delete permission>
//
// These configuration properties can be exported as environment variables, or stored
// in a configuration file and then:
// export IBM_CREDENTIALS_FILE=<name of configuration file>
//
const configFile = 'resource_manager.env';

const describe = authHelper.prepareTests(configFile);

// Save original console.log and console.warn
const originalLog = console.log;
const originalWarn = console.warn;

// Mocks for console.log and console.warn
const consoleLogMock = jest.spyOn(console, 'log');
const consoleWarnMock = jest.spyOn(console, 'warn');

describe('ResourceManagerV2', () => {

// begin-common

const resourceManagerService = ResourceManagerV2.newInstance({ serviceName: ResourceManagerV2.DEFAULT_SERVICE_NAME});
const deleteResourceManagerService = ResourceManagerV2.newInstance(
{serviceName: 'ALT_RESOURCE_MANAGER'}
);

// end-common

const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME);
const exampleUserAccountId = config.userAccountId;
const exampleQuotaId = config.quotaId;
let resourceGroupId = null;

test('createResourceGroup request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-create_resource_group
const params = {
accountId: exampleUserAccountId,
name: "ExampleGroup"
};

resourceManagerService.createResourceGroup(params)
.then(res => {
resourceGroupId = res.result.id;
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-create_resource_group
});
test('getResourceGroup request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-get_resource_group

const params = {
id: resourceGroupId,
};

resourceManagerService.getResourceGroup(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-get_resource_group
});
test('updateResourceGroup request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-update_resource_group

const params = {
id: resourceGroupId,
state: 'ACTIVE',
name: 'RenamedExampleGroup'
};

resourceManagerService.updateResourceGroup(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-update_resource_group
});

test('listResourceGroups request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-list_resource_groups
const params = {
accountId: exampleUserAccountId,
includeDeleted: true,
}

resourceManagerService.listResourceGroups(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-list_resource_groups
});
test('deleteResourceGroup request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-delete_resource_group

const params = {
id: resourceGroupId,
};

deleteResourceManagerService.deleteResourceGroup(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-delete_resource_group
});

test('listQuotaDefinitions request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-list_quota_definitions

resourceManagerService.listQuotaDefinitions({})
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-list_quota_definitions
});
test('getQuotaDefinition request example', done => {

consoleLogMock.mockImplementation(output => {
originalLog(output);
done();
});
consoleWarnMock.mockImplementation(output => {
done(output);
});

// begin-get_quota_definition

const params = {
id: exampleQuotaId,
};

resourceManagerService.getQuotaDefinition(params)
.then(res => {
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-get_quota_definition
});

});
32 changes: 22 additions & 10 deletions resource-manager/v2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2020.
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

/**
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-d753183b-20201209-163011
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-4883cbcd-20210301-143711
*/


Expand Down Expand Up @@ -97,8 +97,11 @@ class ResourceManagerV2 extends BaseService {
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.accountId] - The ID of the account that contains the resource groups that you want to get.
* @param {string} [params.date] - The date would be in a format of YYYY-MM which returns resource groups exclude the
* deleted ones before this month.
* @param {string} [params.date] - The date in the format of YYYY-MM which returns resource groups. Deleted resource
* groups will be excluded before this month.
* @param {string} [params.name] - The name of the resource group.
* @param {boolean} [params._default] - Boolean value to specify whether or not to list default resource groups.
* @param {boolean} [params.includeDeleted] - Boolean value to specify whether or not to list default resource groups.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<ResourceManagerV2.Response<ResourceManagerV2.ResourceGroupList>>}
*/
Expand All @@ -107,7 +110,10 @@ class ResourceManagerV2 extends BaseService {

const query = {
'account_id': _params.accountId,
'date': _params.date
'date': _params.date,
'name': _params.name,
'default': _params._default,
'include_deleted': _params.includeDeleted
};

const sdkHeaders = getSdkHeaders(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'listResourceGroups');
Expand Down Expand Up @@ -406,10 +412,16 @@ namespace ResourceManagerV2 {
export interface ListResourceGroupsParams {
/** The ID of the account that contains the resource groups that you want to get. */
accountId?: string;
/** The date would be in a format of YYYY-MM which returns resource groups exclude the deleted ones before this
* month.
/** The date in the format of YYYY-MM which returns resource groups. Deleted resource groups will be excluded
* before this month.
*/
date?: string;
/** The name of the resource group. */
name?: string;
/** Boolean value to specify whether or not to list default resource groups. */
_default?: boolean;
/** Boolean value to specify whether or not to list default resource groups. */
includeDeleted?: boolean;
headers?: OutgoingHttpHeaders;
}

Expand Down Expand Up @@ -504,7 +516,7 @@ namespace ResourceManagerV2 {
/** An alpha-numeric value identifying the resource group. */
id?: string;
/** The full CRN (cloud resource name) associated with the resource group. For more on this format, see [Cloud
* Resource Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
* Resource Names](https://cloud.ibm.com/docs/account?topic=account-crn).
*/
crn?: string;
}
Expand All @@ -514,7 +526,7 @@ namespace ResourceManagerV2 {
/** An alpha-numeric value identifying the resource group. */
id?: string;
/** The full CRN (cloud resource name) associated with the resource group. For more on this format, see [Cloud
* Resource Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
* Resource Names](https://cloud.ibm.com/docs/account?topic=account-crn).
*/
crn?: string;
/** An alpha-numeric value identifying the account ID. */
Expand Down Expand Up @@ -554,7 +566,7 @@ namespace ResourceManagerV2 {
/** The human-readable name of the quota. */
resource_id?: string;
/** The full CRN (cloud resource name) associated with the quota. For more on this format, see
* https://cloud.ibm.com/docs/resources?topic=resources-crn#crn.
* https://cloud.ibm.com/docs/account?topic=account-crn.
*/
crn?: string;
/** The limit number of this resource. */
Expand Down
Loading

0 comments on commit 4d63345

Please sign in to comment.