From d3baee33f237d02fb27ab121bc408d36f88c6091 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Mon, 14 Aug 2017 14:50:33 -0400 Subject: [PATCH] @google-cloud/storage - Added IAM typings (#18892) --- .../google-cloud__storage-tests.ts | 17 ++++++++++++++ types/google-cloud__storage/index.d.ts | 23 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/types/google-cloud__storage/google-cloud__storage-tests.ts b/types/google-cloud__storage/google-cloud__storage-tests.ts index b46b4766a1..590953fa6a 100644 --- a/types/google-cloud__storage/google-cloud__storage-tests.ts +++ b/types/google-cloud__storage/google-cloud__storage-tests.ts @@ -396,3 +396,20 @@ export class TestFile { return this.file.setMetadata(metadata); } } + +const testStorage = new TestStorage().bucket("examplebucketname"); + +testStorage.iam.getPolicy(); + +testStorage.iam.setPolicy({ + bindings: [ + { + role: "roles/storage.admin", + members: ['serviceAccount:myotherproject@appspot.gserviceaccount.com'] + } + ] + }); + +testStorage.iam.testPermissions('storage.buckets.delete'); + +testStorage.iam.testPermissions(['storage.buckets.delete', 'storage.buckets.get']); diff --git a/types/google-cloud__storage/index.d.ts b/types/google-cloud__storage/index.d.ts index dcea17e5d4..bee7c5de87 100644 --- a/types/google-cloud__storage/index.d.ts +++ b/types/google-cloud__storage/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for @google-cloud/storage 1.1 // Project: https://github.com/GoogleCloudPlatform/google-cloud-node/tree/master/packages/storage // Definitions by: Brian Love +// Nathan Brooker Perry // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -28,6 +29,7 @@ declare namespace Storage { getFilesStream(query?: BucketQuery): ReadStream; getMetadata(): Promise<[BucketMetadata, Storage.ApiResponse]>; id: string; + iam: Iam; makePrivate(options?: BucketPrivacyOptions): Promise<[File[]]>; makePublic(options?: BucketPrivacyOptions): Promise<[File[]]>; metadata: BucketMetadata; @@ -337,6 +339,27 @@ declare namespace Storage { interface ChannelConfig { address: string; } + + /** + * This class allows you to get Identity Access Management information. + */ + class Iam { + getPolicy(): Promise; + setPolicy(policy: IamPolicy): Promise<[IamPolicy, ApiResponse]>; + testPermissions(permission: string | string[]): Promise<[{[key: string]: boolean}, ApiResponse]>; + } + + /** + * IAM policy + */ + interface IamPolicy { + bindings: IamBinding[]; + } + + interface IamBinding { + role: string; + members: string[]; + } } declare function Storage(config?: Storage.ConfigurationObject): Storage.Storage;