Skip to content

Commit a28d914

Browse files
authored
feat(secret): add endpoint to list tags (#708)
1 parent 6606908 commit a28d914

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

packages/clients/src/api/secret/v1alpha1/api.gen.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
unmarshalAccessSecretVersionResponse,
1818
unmarshalListSecretVersionsResponse,
1919
unmarshalListSecretsResponse,
20+
unmarshalListTagsResponse,
2021
unmarshalSecret,
2122
unmarshalSecretVersion,
2223
} from './marshalling.gen'
@@ -41,6 +42,8 @@ import type {
4142
ListSecretVersionsResponse,
4243
ListSecretsRequest,
4344
ListSecretsResponse,
45+
ListTagsRequest,
46+
ListTagsResponse,
4447
Secret,
4548
SecretVersion,
4649
UpdateSecretRequest,
@@ -537,4 +540,33 @@ export class API extends ParentAPI {
537540
},
538541
unmarshalSecretVersion,
539542
)
543+
544+
protected pageOfListTags = (request: Readonly<ListTagsRequest> = {}) =>
545+
this.client.fetch<ListTagsResponse>(
546+
{
547+
method: 'GET',
548+
path: `/secret-manager/v1alpha1/regions/${validatePathParam(
549+
'region',
550+
request.region ?? this.client.settings.defaultRegion,
551+
)}/tags`,
552+
urlParams: urlParams(
553+
['page', request.page],
554+
[
555+
'page_size',
556+
request.pageSize ?? this.client.settings.defaultPageSize,
557+
],
558+
['project_id', request.projectId],
559+
),
560+
},
561+
unmarshalListTagsResponse,
562+
)
563+
564+
/**
565+
* List tags. List all tags associated to secrets in one or several Projects.
566+
*
567+
* @param request - The request {@link ListTagsRequest}
568+
* @returns A Promise of ListTagsResponse
569+
*/
570+
listTags = (request: Readonly<ListTagsRequest> = {}) =>
571+
enrichForPagination('tags', this.pageOfListTags, request)
540572
}

packages/clients/src/api/secret/v1alpha1/index.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export type {
2323
ListSecretsRequest,
2424
ListSecretsRequestOrderBy,
2525
ListSecretsResponse,
26+
ListTagsRequest,
27+
ListTagsResponse,
2628
PasswordGenerationParams,
2729
Product,
2830
Secret,

packages/clients/src/api/secret/v1alpha1/marshalling.gen.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
GeneratePasswordRequest,
1616
ListSecretVersionsResponse,
1717
ListSecretsResponse,
18+
ListTagsResponse,
1819
PasswordGenerationParams,
1920
Secret,
2021
SecretVersion,
@@ -103,6 +104,16 @@ export const unmarshalListSecretsResponse = (data: unknown) => {
103104
} as ListSecretsResponse
104105
}
105106

107+
export const unmarshalListTagsResponse = (data: unknown) => {
108+
if (!isJSONObject(data)) {
109+
throw new TypeError(
110+
`Unmarshalling the type 'ListTagsResponse' failed as data isn't a dictionary.`,
111+
)
112+
}
113+
114+
return { tags: data.tags, totalCount: data.total_count } as ListTagsResponse
115+
}
116+
106117
const marshalPasswordGenerationParams = (
107118
request: PasswordGenerationParams,
108119
defaults: DefaultValues,

packages/clients/src/api/secret/v1alpha1/types.gen.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ export interface ListSecretsResponse {
5454
totalCount: number
5555
}
5656

57+
/** List tags response. */
58+
export interface ListTagsResponse {
59+
/** List of tags. */
60+
tags: string[]
61+
/** Count of all tags matching the requested criteria. */
62+
totalCount: number
63+
}
64+
5765
/** Password generation params. */
5866
export interface PasswordGenerationParams {
5967
/** Length of the password to generate (between 1 and 1024). */
@@ -467,3 +475,18 @@ export type DestroySecretVersionRequest = {
467475
*/
468476
revision: string
469477
}
478+
479+
export type ListTagsRequest = {
480+
/**
481+
* Region to target. If none is passed will use default region from the
482+
* config.
483+
*/
484+
region?: Region
485+
/**
486+
* ID of the Project to target. (Optional.) If not specified, Secret Manager
487+
* will look for tags in all Projects.
488+
*/
489+
projectId?: string
490+
page?: number
491+
pageSize?: number
492+
}

0 commit comments

Comments
 (0)