static ImmutableList<ListAssetsResult> listAssetsWithQueryMarks(
OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to list all assets filtered by a specific security mark.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
ListAssetsRequest request =
ListAssetsRequest.newBuilder()
.setParent(organizationName.toString())
.setFilter("security_marks.marks.key_a = \"value_a\"")
.build();
// Call the API.
ListAssetsPagedResponse response = client.listAssets(request);
// This creates one list for all assets. If your organization has a large number of assets
// this can cause out of memory issues. You can process them batches by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<ListAssetsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Assets with security mark - key_a=value_a:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
// Imports the Google Cloud client library.
const {SecurityCenterClient} = require('@google-cloud/security-center');
// Creates a new client.
const client = new SecurityCenterClient();
// organizationId is the numeric ID of the organization.
/*
* TODO(developer): Uncomment the following lines
*/
// const organizationId = "1234567777";
const orgName = client.organizationPath(organizationId);
// Call the API with automatic pagination.
async function listAssetsWithSecurityMarks() {
const [response] = await client.listAssets({
parent: orgName,
filter: 'security_marks.marks.key_a="value_a"',
});
let count = 0;
Array.from(response).forEach(result =>
console.log(
`${++count} ${result.asset.name} ${
result.asset.securityCenterProperties.resourceName
}`
)
);
}
listAssetsWithSecurityMarks();
from google.cloud import securitycenter
client = securitycenter.SecurityCenterClient()
# organization_id is the numeric ID of the organization.
# organization_id=1234567777
org_name = "organizations/{org_id}".format(org_id=organization_id)
marks_filter = 'security_marks.marks.key_a = "value_a"'
# Call the API and print results.
asset_iterator = client.list_assets(
request={"parent": org_name, "filter": marks_filter}
)
# Call the API and print results.
asset_iterator = client.list_assets(
request={"parent": org_name, "filter": marks_filter}
)
for i, asset_result in enumerate(asset_iterator):
print(i, asset_result)