Skip to content

Commit 62b4338

Browse files
feat: [KmsInventory] Add support for project level key usage tracking (#8927)
* feat: Add support for project level key usage tracking docs: Add support for project level key usage tracking PiperOrigin-RevId: 871667322 Source-Link: googleapis/googleapis@1133adb Source-Link: googleapis/googleapis-gen@d0121e3 Copy-Tag: eyJwIjoiS21zSW52ZW50b3J5Ly5Pd2xCb3QueWFtbCIsImgiOiJkMDEyMWUzN2JhNWZhOTlmMTJhYjE5Njc1OTI2MzVjMjg5NzIwZDFjIn0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 82fdb00 commit 62b4338

14 files changed

Lines changed: 418 additions & 31 deletions

KmsInventory/metadata/V1/KeyDashboardService.php

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
692 Bytes
Binary file not shown.

KmsInventory/samples/V1/KeyTrackingServiceClient/get_protected_resources_summary.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@
3030

3131
/**
3232
* Returns aggregate information about the resources protected by the given
33-
* Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. Only resources within
34-
* the same Cloud organization as the key will be returned. The project that
35-
* holds the key must be part of an organization in order for this call to
36-
* succeed.
33+
* Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. By default,
34+
* summary of resources within the same Cloud organization as the key will be
35+
* returned, which requires the KMS organization service account to be
36+
* configured(refer
37+
* https://docs.cloud.google.com/kms/docs/view-key-usage#required-roles).
38+
* If the KMS organization service account is not configured or key's project
39+
* is not part of an organization, set
40+
* [fallback_scope][google.cloud.kms.inventory.v1.GetProtectedResourcesSummaryRequest.fallback_scope]
41+
* to `FALLBACK_SCOPE_PROJECT` to retrieve a summary of protected resources
42+
* within the key's project.
3743
*
3844
* @param string $formattedName The resource name of the
3945
* [CryptoKey][google.cloud.kms.v1.CryptoKey]. Please see

KmsInventory/samples/V1/KeyTrackingServiceClient/search_protected_resources.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@
3131

3232
/**
3333
* Returns metadata about the resources protected by the given Cloud KMS
34-
* [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud organization.
34+
* [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud
35+
* organization/project.
3536
*
36-
* @param string $formattedScope Resource name of the organization.
37-
* Example: organizations/123
38-
* Please see {@see KeyTrackingServiceClient::organizationName()} for help formatting this field.
37+
* @param string $formattedScope A scope can be an organization or a project. Resources protected
38+
* by the crypto key in provided scope will be returned.
39+
*
40+
* The following values are allowed:
41+
*
42+
* * organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/12345678")
43+
* * projects/{PROJECT_ID} (e.g., "projects/foo-bar")
44+
* * projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
45+
* Please see {@see KeyTrackingServiceClient::projectName()} for help formatting this field.
3946
* @param string $cryptoKey The resource name of the
4047
* [CryptoKey][google.cloud.kms.v1.CryptoKey].
4148
*/
@@ -74,7 +81,7 @@ function search_protected_resources_sample(string $formattedScope, string $crypt
7481
*/
7582
function callSample(): void
7683
{
77-
$formattedScope = KeyTrackingServiceClient::organizationName('[ORGANIZATION]');
84+
$formattedScope = KeyTrackingServiceClient::projectName('[PROJECT]');
7885
$cryptoKey = '[CRYPTO_KEY]';
7986

8087
search_protected_resources_sample($formattedScope, $cryptoKey);

KmsInventory/src/V1/Client/KeyTrackingServiceClient.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ public static function organizationName(string $organization): string
116116
]);
117117
}
118118

119+
/**
120+
* Formats a string containing the fully-qualified path to represent a project
121+
* resource.
122+
*
123+
* @param string $project
124+
*
125+
* @return string The formatted project resource.
126+
*/
127+
public static function projectName(string $project): string
128+
{
129+
return self::getPathTemplate('project')->render([
130+
'project' => $project,
131+
]);
132+
}
133+
119134
/**
120135
* Formats a string containing the fully-qualified path to represent a
121136
* project_location_key_ring_crypto_key_crypto_key_version_protectedResourcesSummary
@@ -202,6 +217,7 @@ public static function protectedResourcesSummaryName(
202217
* The following name formats are supported:
203218
* Template: Pattern
204219
* - organization: organizations/{organization}
220+
* - project: projects/{project}
205221
* - projectLocationKeyRingCryptoKeyCryptoKeyVersionProtectedResourcesSummary: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}/protectedResourcesSummary
206222
* - projectLocationKeyRingCryptoKeyProtectedResourcesSummary: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/protectedResourcesSummary
207223
* - protectedResourcesSummary: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/protectedResourcesSummary
@@ -311,10 +327,16 @@ public function __call($method, $args)
311327

312328
/**
313329
* Returns aggregate information about the resources protected by the given
314-
* Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. Only resources within
315-
* the same Cloud organization as the key will be returned. The project that
316-
* holds the key must be part of an organization in order for this call to
317-
* succeed.
330+
* Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. By default,
331+
* summary of resources within the same Cloud organization as the key will be
332+
* returned, which requires the KMS organization service account to be
333+
* configured(refer
334+
* https://docs.cloud.google.com/kms/docs/view-key-usage#required-roles).
335+
* If the KMS organization service account is not configured or key's project
336+
* is not part of an organization, set
337+
* [fallback_scope][google.cloud.kms.inventory.v1.GetProtectedResourcesSummaryRequest.fallback_scope]
338+
* to `FALLBACK_SCOPE_PROJECT` to retrieve a summary of protected resources
339+
* within the key's project.
318340
*
319341
* The async variant is
320342
* {@see KeyTrackingServiceClient::getProtectedResourcesSummaryAsync()} .
@@ -344,7 +366,8 @@ public function getProtectedResourcesSummary(
344366

345367
/**
346368
* Returns metadata about the resources protected by the given Cloud KMS
347-
* [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud organization.
369+
* [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud
370+
* organization/project.
348371
*
349372
* The async variant is
350373
* {@see KeyTrackingServiceClient::searchProtectedResourcesAsync()} .

KmsInventory/src/V1/FallbackScope.php

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

KmsInventory/src/V1/GetProtectedResourcesSummaryRequest.php

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

KmsInventory/src/V1/ProtectedResourcesSummary.php

Lines changed: 47 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)