Skip to content

Commit 6398a9a

Browse files
agggaurav2024iennaecode-review-assist[bot]
authored
feat(securitycenter): Add Resource SCC Management API Org SHA Custom … (#3952)
* feat(securitycenter): Add Resource SCC Management API Org SHA Custom Modules * fix: adjust comment to remove extra word Co-authored-by: code-review-assist[bot] <182814678+code-review-assist[bot]@users.noreply.github.com> * fix: lint issue * updated test * refactor cleanup code * updated test * fix lint issue * update test case --------- Co-authored-by: Jennifer Davis <[email protected]> Co-authored-by: code-review-assist[bot] <182814678+code-review-assist[bot]@users.noreply.github.com>
1 parent 102eaed commit 6398a9a

7 files changed

+453
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2025 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 {
23+
SecurityCenterManagementClient,
24+
protos,
25+
} = require('@google-cloud/securitycentermanagement');
26+
27+
const client = new SecurityCenterManagementClient();
28+
29+
const EnablementState =
30+
protos.google.cloud.securitycentermanagement.v1
31+
.SecurityHealthAnalyticsCustomModule.EnablementState;
32+
33+
const Severity =
34+
protos.google.cloud.securitycentermanagement.v1.CustomConfig.Severity;
35+
36+
/*
37+
* Required. The name of the parent resource of security health analytics module
38+
* Its format is
39+
* `organizations/[organization_id]/locations/[location_id]`
40+
* `folders/[folder_id]/locations/[location_id]`
41+
* `projects/[project_id]/locations/[location_id]`
42+
*/
43+
const parent = `organizations/${organizationId}/locations/${locationId}`;
44+
45+
/*
46+
* Required. Resource name of security health analytics module.
47+
* Its format is
48+
* `organizations/[organization_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
49+
* `folders/[folder_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
50+
* `projects/[project_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
51+
*/
52+
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/custom_module`;
53+
54+
// define the CEL expression here and this will scans for keys that have not been rotated in
55+
// the last 30 days, change it according to your requirements
56+
const expr = {
57+
expression: `has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))`,
58+
};
59+
60+
// define the resource selector
61+
const resourceSelector = {
62+
resourceTypes: ['cloudkms.googleapis.com/CryptoKey'],
63+
};
64+
65+
// define the custom module configuration, update the severity, description,
66+
// recommendation below
67+
const customConfig = {
68+
predicate: expr,
69+
resourceSelector: resourceSelector,
70+
severity: Severity.MEDIUM,
71+
description: 'add your description here',
72+
recommendation: 'add your recommendation here',
73+
};
74+
75+
// define the security health analytics custom module configuration, update the
76+
// EnablementState below
77+
const securityHealthAnalyticsCustomModule = {
78+
name: name,
79+
displayName: customModuleDisplayName,
80+
enablementState: EnablementState.ENABLED,
81+
customConfig: customConfig,
82+
};
83+
84+
async function createSecurityHealthAnalyticsCustomModule() {
85+
const [response] = await client.createSecurityHealthAnalyticsCustomModule({
86+
parent: parent,
87+
securityHealthAnalyticsCustomModule: securityHealthAnalyticsCustomModule,
88+
});
89+
console.log(
90+
'Security Health Analytics Custom Module creation succeeded: ',
91+
response
92+
);
93+
}
94+
95+
createSecurityHealthAnalyticsCustomModule();
96+
// [END securitycenter_create_security_health_analytics_custom_module]
97+
}
98+
99+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2025 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 {
23+
SecurityCenterManagementClient,
24+
} = require('@google-cloud/securitycentermanagement');
25+
26+
const client = new SecurityCenterManagementClient();
27+
28+
/*
29+
* Required. Resource name of security health analytics module.
30+
* Its format is
31+
* `organizations/[organization_id]/locations/[location_id]/effectiveSecurityHealthAnalyticsCustomModules/[custom_module]`
32+
* `folders/[folder_id]/locations/[location_id]/effectiveSecurityHealthAnalyticsCustomModules/[custom_module]`
33+
* `projects/[project_id]/locations/[location_id]/effectiveSecurityHealthAnalyticsCustomModules/[custom_module]`
34+
*/
35+
const name = `organizations/${organizationId}/locations/${locationId}/effectiveSecurityHealthAnalyticsCustomModules/${customModuleId}`;
36+
37+
async function getEffectiveSecurityHealthAnalyticsCustomModule() {
38+
const [response] =
39+
await client.getEffectiveSecurityHealthAnalyticsCustomModule({
40+
name: name,
41+
});
42+
console.log(
43+
'Security Health Analytics Custom Module get effective succeeded: ',
44+
response
45+
);
46+
}
47+
48+
getEffectiveSecurityHealthAnalyticsCustomModule();
49+
// [END securitycenter_get_effective_security_health_analytics_custom_module]
50+
}
51+
52+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 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 {
23+
SecurityCenterManagementClient,
24+
} = require('@google-cloud/securitycentermanagement');
25+
26+
const client = new SecurityCenterManagementClient();
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+
async function getSecurityHealthAnalyticsCustomModule() {
38+
const [response] = await client.getSecurityHealthAnalyticsCustomModule({
39+
name: name,
40+
});
41+
console.log(
42+
'Security Health Analytics Custom Module get succeeded: ',
43+
response
44+
);
45+
}
46+
47+
getSecurityHealthAnalyticsCustomModule();
48+
// [END securitycenter_get_security_health_analytics_custom_module]
49+
}
50+
51+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2025 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 {
23+
SecurityCenterManagementClient,
24+
protos,
25+
} = require('@google-cloud/securitycentermanagement');
26+
27+
const client = new SecurityCenterManagementClient();
28+
29+
const EnablementState =
30+
protos.google.cloud.securitycentermanagement.v1
31+
.SecurityHealthAnalyticsCustomModule.EnablementState;
32+
33+
/*
34+
* Required. Resource name of security health analytics module.
35+
* Its format is
36+
* `organizations/[organization_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
37+
* `folders/[folder_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
38+
* `projects/[project_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
39+
*/
40+
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/${customModuleId}`;
41+
42+
// define the security health analytics custom module configuration, update the
43+
// EnablementState below
44+
const securityHealthAnalyticsCustomModule = {
45+
name: name,
46+
enablementState: EnablementState.DISABLED,
47+
};
48+
49+
// Set the field mask to specify which properties should be updated.
50+
const fieldMask = {
51+
paths: ['enablement_state'],
52+
};
53+
54+
async function updateSecurityHealthAnalyticsCustomModule() {
55+
const [response] = await client.updateSecurityHealthAnalyticsCustomModule({
56+
updateMask: fieldMask,
57+
securityHealthAnalyticsCustomModule: securityHealthAnalyticsCustomModule,
58+
});
59+
console.log(
60+
'Security Health Analytics Custom Module update succeeded: ',
61+
response
62+
);
63+
}
64+
65+
updateSecurityHealthAnalyticsCustomModule();
66+
// [END securitycenter_update_security_health_analytics_custom_module]
67+
}
68+
69+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)