Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Posture Management): Add posture management service sdk #86

Merged
merged 20 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
201fb53
feat(Posture Management): add generated SDK of Posture Management ser…
Andras-Csanyi Mar 9, 2021
72aa385
feat(Posture Management): add generated examples of Posture Managemen…
Andras-Csanyi Mar 9, 2021
ff067eb
feat(Posture Management): update README.md
Andras-Csanyi Mar 9, 2021
afa5dfe
Merge branch 'main' into add-posture-management-service-sdk
Andras-Csanyi Mar 14, 2021
a5da58c
feat(posture management): add configuration values to integration tests.
Andras-Csanyi Mar 14, 2021
41e988d
feat(posture management): align examples
Andras-Csanyi Mar 14, 2021
2a35cc5
feat(posture management): fix README.md link to Posture Management do…
Andras-Csanyi Mar 14, 2021
1dfff9e
Merge branch 'main' into add-posture-management-service-sdk
Andras-Csanyi Mar 18, 2021
0eadf6a
fix: update .secrets-baseline
Andras-Csanyi Mar 18, 2021
7a555f9
Merge branch 'main' into add-posture-management-service-sdk
Andras-Csanyi Mar 25, 2021
47e1301
Merge branch 'main' into add-posture-management-service-sdk
padamstx Mar 25, 2021
d5ed3e7
fix(posture management): update service and unit test
Andras-Csanyi Mar 25, 2021
3122f1e
fix(posture management): update integration test
Andras-Csanyi Mar 25, 2021
3a43d33
fix(posture management): update example
Andras-Csanyi Mar 25, 2021
7b627d8
fix(posture management): update integration test
Andras-Csanyi Mar 25, 2021
48dd2cd
fix(posture management): update examples
Andras-Csanyi Mar 25, 2021
0fe02ba
Merge branch 'add-posture-management-service-sdk' of github.com:IBM/p…
Andras-Csanyi Mar 25, 2021
c5359cf
fix(posture management) update .secrets.baseline
Andras-Csanyi Mar 25, 2021
19b81ac
fix(posture management): add labels to examples
Andras-Csanyi Mar 25, 2021
1673957
fix(posture management): fix examples
Andras-Csanyi Mar 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "package-lock.json|^.secrets.baseline$",
"lines": null
},
"generated_at": "2021-03-11T23:34:28Z",
"generated_at": "2021-03-25T18:02:01Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -190,16 +190,6 @@
"verified_result": null
}
],
"test/integration/resource-manager.v2.test.js": [
{
"hashed_secret": "1f7f6b3a6bee3796ba250ac4379ea6743d51ed53",
"is_secret": false,
"is_verified": false,
"line_number": 37,
"type": "Hex High Entropy String",
"verified_result": null
}
],
"test/unit/catalog-management.v1.test.js": [
{
"hashed_secret": "b8473b86d4c2072ca9b08bd28e373e8253e865c4",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Service Name | Import Path
[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
[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
[Resource Manager](https://cloud.ibm.com/apidocs/resource-controller/resource-manager) | ibm-platform-services/resource-manager/v2
[Usage Metering](https://cloud.ibm.com/apidocs/usage-metering) | ibm-platform-services/usage-metering/v4
Expand Down
158 changes: 158 additions & 0 deletions examples/posture-management.v1.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**
* @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 PostureManagementV1 = require('../dist/posture-management/v1');
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 Posture Management service.
//
// The following configuration properties are assumed to be defined:
// POSTURE_MANAGEMENT_URL=<service base url>
// POSTURE_MANAGEMENT_AUTH_TYPE=iam
// POSTURE_MANAGEMENT_APIKEY=<IAM apikey>
// POSTURE_MANAGEMENT_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
// POSTURE_MANAGEMENT_PROFILE_NAME=<Profile Name>
// POSTURE_MANAGEMENT_SCOPES_NAME=<Scope Name>
//
// 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 = 'posture_management.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('PostureManagementV1', () => {

// begin-common

const postureManagementService = PostureManagementV1.newInstance({});

// end-common

const config = readExternalSources(PostureManagementV1.DEFAULT_SERVICE_NAME);
const accountId = config.accountId;
const profileName = config.profileName;
const scopesName = config.scopesName;

expect(accountId).toBeDefined();
expect(profileName).toBeDefined();
expect(scopesName).toBeDefined();

let profileId;
let scopeId;
const groupProfileId = '0';

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

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

// begin-list_profiles

const params = {
accountId: accountId,
name: profileName,
};

postureManagementService.listProfiles(params)
.then(res => {
profileId = res.result.profiles[0].profile_id;
console.log('listProfiles() result:\n' + JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

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

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

// begin-list_scopes

const params = {
accountId: accountId,
name: scopesName,
};

postureManagementService.listScopes(params)
.then(res => {
scopeId = res.result.scopes[0].scope_id;
console.log('listScopes() result:\n' + JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

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

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

// begin-create_validation

const params = {
accountId: accountId,
scopeId: scopeId,
profileId: profileId,
groupProfileId: groupProfileId,
};

postureManagementService.createValidation(params)
.then(res => {
console.log('createValidation() result:\n' + JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});

// end-create_validation
});
});
Loading