Skip to content

Commit

Permalink
feat(cloudshell): add service, tests and examples to project
Browse files Browse the repository at this point in the history
  • Loading branch information
hartyt authored Jun 29, 2021
1 parent 786254c commit dcce91f
Show file tree
Hide file tree
Showing 7 changed files with 893 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ global-tagging/*.js
iam-access-groups/*.js
iam-identity/*.js
iam-policy-management/*.js
ibm-cloud-shell/*.js
open-service-broker/*.js
resource-manager/*.js
resource-controller/*.js
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Service Name | Import Path
[IAM Access Groups](https://cloud.ibm.com/apidocs/iam-access-groups) | ibm-platform-services/iam-access-groups/v2
[IAM Identity Service](https://cloud.ibm.com/apidocs/iam-identity-token-api) | ibm-platform-services/iam-identity/v1
[IAM Policy Management](https://cloud.ibm.com/apidocs/iam-policy-management) | ibm-platform-services/iam-policy-management/v1
[IBM Cloud Shell](https://cloud.ibm.com/apidocs/cloudshell) | ibm-platform-services/ibm-cloud-shell/v1
[Open Service Broker](https://cloud.ibm.com/apidocs/resource-controller/ibm-cloud-osb-api) | ibm-platform-services/open-service-broker/v1
[Posture Management](https://cloud.ibm.com/apidocs/security-compliance/posture) | ibm-platform-services/posture-management/v1
[Resource Controller](https://cloud.ibm.com/apidocs/resource-controller/resource-controller) | ibm-platform-services/resource-controller/v2
Expand Down
155 changes: 155 additions & 0 deletions examples/ibm-cloud-shell.v1.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/**
* @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';

/* eslint-disable no-console */

const IbmCloudShellV1 = require('../dist/ibm-cloud-shell/v1');
// eslint-disable-next-line node/no-unpublished-require
const authHelper = require('../test/resources/auth-helper.js');
// You can use the readExternalSources method to access additional configuration values
// const { readExternalSources } = require('ibm-cloud-sdk-core');

//
// This file provides an example of how to use the IBM Cloud Shell service.
//
// The following configuration properties are assumed to be defined:
// IBM_CLOUD_SHELL_URL=<service base url>
// IBM_CLOUD_SHELL_AUTH_TYPE=iam
// IBM_CLOUD_SHELL_APIKEY=<IAM apikey>
// IBM_CLOUD_SHELL_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
// IBM_CLOUD_SHELL_ACCOUNT_ID=<IBM Cloud account ID>
//
// 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 = 'ibm_cloud_shell_v1.env';

const describe = authHelper.prepareTests(configFile);

// Save original console.log
const originalLog = console.log;

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

describe('IbmCloudShellV1', () => {

// begin-common

const ibmCloudShellService = IbmCloudShellV1.newInstance({});

// end-common

// To access additional configuration values, uncomment this line and extract the values from config
const config = readExternalSources(IbmCloudShellV1.DEFAULT_SERVICE_NAME);
let accountId = config.accountId;
expect(accountId).not.toBeNull();

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

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

originalLog('getAccountSettings() result:');
// begin-get_account_settings

const params = {
accountId: accountId,
};

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

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

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

originalLog('updateAccountSettings() result:');
// begin-update_account_settings

// Feature
const featureModel = [
{
enabled: true,
key: 'server.file_manager',
},
{
enabled: true,
key: 'server.web_preview',
},
];

// RegionSetting
const regionSettingModel = [
{
enabled: true,
key: 'eu-de',
},
{
enabled: true,
key: 'jp-tok',
},
{
enabled: true,
key: 'us-south',
},
];

const params = {
accountId: accountId,
rev: '130-${accountId}',
defaultEnableNewFeatures: true,
defaultEnableNewRegions: true,
enabled: true,
features: featureModel,
regions: regionSettingModel,
};

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

// end-update_account_settings
});
});
Loading

0 comments on commit dcce91f

Please sign in to comment.