Skip to content

Commit 154520c

Browse files
committed
feat(securitycenter): Add Resource SCC Management API Org SHA Custom Module code samples
1 parent d7fb7e2 commit 154520c

File tree

6 files changed

+409
-7
lines changed

6 files changed

+409
-7
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* Create security health analytics custom module
18+
*/
19+
function main(organizationId, customModuleDisplayName, locationId = 'global') {
20+
// [START securitycenter_create_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const { SecurityCenterManagementClient, protos } = require('@google-cloud/securitycentermanagement');
23+
24+
const client = new SecurityCenterManagementClient();
25+
26+
const EnablementState = protos.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule.EnablementState;
27+
const Severity = protos.google.cloud.securitycentermanagement.v1.CustomConfig.Severity;
28+
29+
/*
30+
* Required. The name of the parent resource of security health analytics module.
31+
* Its format is
32+
* `organizations/[organization_id]/locations/[location_id]`
33+
* `folders/[folder_id]/locations/[location_id]`
34+
* `projects/[project_id]/locations/[location_id]`
35+
*/
36+
const parent = `organizations/${organizationId}/locations/${locationId}`;
37+
38+
/*
39+
* Required. Resource name of security health analytics module.
40+
* Its format is
41+
* `organizations/[organization_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
42+
* `folders/[folder_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
43+
* `projects/[project_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
44+
*/
45+
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/custom_module`;
46+
47+
// define the CEL expression here and this will scans for keys that have not been rotated in
48+
// the last 30 days, change it according to the your requirements
49+
const expr = {
50+
expression: `has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))`
51+
};
52+
53+
// define the resource selector
54+
const resourceSelector = {
55+
resourceTypes: [
56+
'cloudkms.googleapis.com/CryptoKey'
57+
]
58+
};
59+
60+
// define the custom module configuration, update the severity, description,
61+
// recommendation below
62+
const customConfig = {
63+
predicate: expr,
64+
resourceSelector: resourceSelector,
65+
severity: Severity.MEDIUM,
66+
description: 'add your description here',
67+
recommendation: 'add your recommendation here'
68+
};
69+
70+
// define the security health analytics custom module configuration, update the
71+
// EnablementState below
72+
const securityHealthAnalyticsCustomModule = {
73+
name: name,
74+
displayName: customModuleDisplayName,
75+
enablementState: EnablementState.ENABLED,
76+
customConfig: customConfig
77+
};
78+
79+
async function createSecurityHealthAnalyticsCustomModule() {
80+
const [response] = await client.createSecurityHealthAnalyticsCustomModule({
81+
parent: parent,
82+
securityHealthAnalyticsCustomModule: securityHealthAnalyticsCustomModule
83+
});
84+
console.log('Security Health Analytics Custom Module creation succeeded: ', response);
85+
}
86+
87+
createSecurityHealthAnalyticsCustomModule();
88+
// [END securitycenter_create_security_health_analytics_custom_module]
89+
}
90+
91+
main(...process.argv.slice(2));
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* Retrieve an existing effective security health analytics custom module
18+
*/
19+
function main(organizationId, customModuleId, locationId = 'global') {
20+
// [START securitycenter_get_effective_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const { SecurityCenterManagementClient } = require('@google-cloud/securitycentermanagement');
23+
24+
const client = new SecurityCenterManagementClient();
25+
26+
/*
27+
* Required. Resource name of security health analytics module.
28+
* Its format is
29+
* `organizations/[organization_id]/locations/[location_id]/effectiveSecurityHealthAnalyticsCustomModules/[custom_module]`
30+
* `folders/[folder_id]/locations/[location_id]/effectiveSecurityHealthAnalyticsCustomModules/[custom_module]`
31+
* `projects/[project_id]/locations/[location_id]/effectiveSecurityHealthAnalyticsCustomModules/[custom_module]`
32+
*/
33+
const name = `organizations/${organizationId}/locations/${locationId}/effectiveSecurityHealthAnalyticsCustomModules/${customModuleId}`;
34+
35+
async function getEffectiveSecurityHealthAnalyticsCustomModule() {
36+
const [response] = await client.getEffectiveSecurityHealthAnalyticsCustomModule({
37+
name: name
38+
});
39+
console.log('Security Health Analytics Custom Module get effective succeeded: ', response);
40+
}
41+
42+
getEffectiveSecurityHealthAnalyticsCustomModule();
43+
// [END securitycenter_get_effective_security_health_analytics_custom_module]
44+
}
45+
46+
main(...process.argv.slice(2));
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* Retrieve an existing security health analytics custom module
18+
*/
19+
function main(organizationId, customModuleId, locationId = 'global') {
20+
// [START securitycenter_get_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const { SecurityCenterManagementClient } = require('@google-cloud/securitycentermanagement');
23+
24+
const client = new SecurityCenterManagementClient();
25+
26+
/*
27+
* Required. Resource name of security health analytics module.
28+
* Its format is
29+
* `organizations/[organization_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
30+
* `folders/[folder_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
31+
* `projects/[project_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
32+
*/
33+
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/${customModuleId}`;
34+
35+
async function getSecurityHealthAnalyticsCustomModule() {
36+
const [response] = await client.getSecurityHealthAnalyticsCustomModule({
37+
name: name
38+
});
39+
console.log('Security Health Analytics Custom Module get succeeded: ', response);
40+
}
41+
42+
getSecurityHealthAnalyticsCustomModule();
43+
// [END securitycenter_get_security_health_analytics_custom_module]
44+
}
45+
46+
main(...process.argv.slice(2));
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* Update an existing security health analytics custom module
18+
*/
19+
function main(organizationId, customModuleId, locationId = 'global') {
20+
// [START securitycenter_update_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const { SecurityCenterManagementClient, protos } = require('@google-cloud/securitycentermanagement');
23+
24+
const client = new SecurityCenterManagementClient();
25+
26+
const EnablementState = protos.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule.EnablementState;
27+
28+
/*
29+
* Required. Resource name of security health analytics module.
30+
* Its format is
31+
* `organizations/[organization_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
32+
* `folders/[folder_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
33+
* `projects/[project_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
34+
*/
35+
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/${customModuleId}`;
36+
37+
// define the security health analytics custom module configuration, update the
38+
// EnablementState below
39+
const securityHealthAnalyticsCustomModule = {
40+
name: name,
41+
enablementState: EnablementState.DISABLED
42+
};
43+
44+
// Set the field mask to specify which properties should be updated.
45+
const fieldMask = {
46+
paths: [
47+
'enablement_state'
48+
]
49+
}
50+
51+
async function updateSecurityHealthAnalyticsCustomModule() {
52+
const [response] = await client.updateSecurityHealthAnalyticsCustomModule({
53+
updateMask: fieldMask,
54+
securityHealthAnalyticsCustomModule: securityHealthAnalyticsCustomModule
55+
});
56+
console.log('Security Health Analytics Custom Module update succeeded: ', response);
57+
}
58+
59+
updateSecurityHealthAnalyticsCustomModule();
60+
// [END securitycenter_update_security_health_analytics_custom_module]
61+
}
62+
63+
main(...process.argv.slice(2));

security-center/snippets/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
},
1414
"license": "Apache-2.0",
1515
"dependencies": {
16-
"@google-cloud/pubsub": "^4.0.0",
17-
"@google-cloud/security-center": "^8.7.0"
16+
"@google-cloud/pubsub": "^4.9.0",
17+
"@google-cloud/security-center": "^8.12.0",
18+
"@google-cloud/securitycentermanagement": "^0.5.0"
1819
},
1920
"devDependencies": {
20-
"c8": "^10.0.0",
21-
"chai": "^4.5.0",
22-
"mocha": "^10.4.0",
23-
"uuid": "^10.0.0",
24-
"@google-cloud/bigquery": "^7.0.0"
21+
"@google-cloud/bigquery": "^7.9.1",
22+
"c8": "^10.1.3",
23+
"chai": "^5.1.2",
24+
"mocha": "^11.0.1",
25+
"uuid": "^11.0.3"
2526
}
2627
}

0 commit comments

Comments
 (0)