diff --git a/src/iam.ts b/src/iam.ts index 6d440b260..a605434aa 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -18,12 +18,13 @@ * @module pubsub/iam */ -import * as arrify from 'arrify'; import {promisifyAll} from '@google-cloud/promisify'; -import * as r from 'request'; +import * as arrify from 'arrify'; +import {CallOptions} from 'google-gax'; import * as is from 'is'; -import { PubSub } from '.'; -import { CallOptions } from 'google-gax'; +import * as r from 'request'; + +import {PubSub} from '.'; /** * @callback GetPolicyCallback @@ -108,10 +109,11 @@ export interface Policy { } /** - * [IAM (Identity and Access Management)](https://cloud.google.com/pubsub/access_control) - * allows you to set permissions on invidual resources and offers a wider range - * of roles: editor, owner, publisher, subscriber, and viewer. This gives you - * greater flexibility and allows you to set more fine-grained access control. + * [IAM (Identity and Access + * Management)](https://cloud.google.com/pubsub/access_control) allows you to + * set permissions on invidual resources and offers a wider range of roles: + * editor, owner, publisher, subscriber, and viewer. This gives you greater + * flexibility and allows you to set more fine-grained access control. * * For example: * * Grant access on a per-topic or per-subscription basis, rather than for @@ -146,6 +148,7 @@ export interface Policy { * // subscription.iam */ export class IAM { + // tslint:disable-next-line variable-name Promise?: PromiseConstructor; pubsub: PubSub; request: typeof PubSub.prototype.request; @@ -193,23 +196,26 @@ export class IAM { getPolicy(gaxOpts?: CallOptions): Promise; getPolicy(callback: GetPolicyCallback): void; getPolicy(gaxOpts: CallOptions, callback: GetPolicyCallback): void; - getPolicy(gaxOptsOrCallback?: CallOptions|GetPolicyCallback, callback?: GetPolicyCallback): Promise|void { - let gaxOpts = typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + getPolicy( + gaxOptsOrCallback?: CallOptions|GetPolicyCallback, + callback?: GetPolicyCallback): Promise|void { + const gaxOpts = + typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; + callback = + typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; const reqOpts = { resource: this.id, }; this.request( - { - client: 'SubscriberClient', - method: 'getIamPolicy', - reqOpts: reqOpts, - gaxOpts: gaxOpts, - }, - callback! - ); + { + client: 'SubscriberClient', + method: 'getIamPolicy', + reqOpts, + gaxOpts, + }, + callback!); } /** @@ -241,14 +247,16 @@ export class IAM { * bindings: [ * { * role: 'roles/pubsub.subscriber', - * members: ['serviceAccount:myotherproject@appspot.gserviceaccount.com'] + * members: + * ['serviceAccount:myotherproject@appspot.gserviceaccount.com'] * } * ] * }; * * topic.iam.setPolicy(myPolicy, function(err, policy, apiResponse) {}); * - * subscription.iam.setPolicy(myPolicy, function(err, policy, apiResponse) {}); + * subscription.iam.setPolicy(myPolicy, function(err, policy, apiResponse) + * {}); * * //- * // If the callback is omitted, we'll return a Promise. @@ -259,15 +267,20 @@ export class IAM { * }); */ setPolicy(policy: Policy, gaxOpts?: CallOptions): Promise; - setPolicy(policy: Policy, gaxOpts: CallOptions, callback: SetPolicyCallback): void; + setPolicy(policy: Policy, gaxOpts: CallOptions, callback: SetPolicyCallback): + void; setPolicy(policy: Policy, callback: SetPolicyCallback): void; - setPolicy(policy: Policy, gaxOptsOrCallback?: CallOptions|SetPolicyCallback, callback?: SetPolicyCallback): Promise|void { + setPolicy( + policy: Policy, gaxOptsOrCallback?: CallOptions|SetPolicyCallback, + callback?: SetPolicyCallback): Promise|void { if (!(typeof policy === 'object')) { throw new Error('A policy object is required.'); } - let gaxOpts = typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = + typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; + callback = + typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; const reqOpts = { resource: this.id, @@ -275,14 +288,13 @@ export class IAM { }; this.request( - { - client: 'SubscriberClient', - method: 'setIamPolicy', - reqOpts: reqOpts, - gaxOpts: gaxOpts, - }, - callback! - ); + { + client: 'SubscriberClient', + method: 'setIamPolicy', + reqOpts, + gaxOpts, + }, + callback!); } /** @@ -345,16 +357,26 @@ export class IAM { * const apiResponse = data[1]; * }); */ - testPermissions(permissions: string|string[], gaxOpts?: CallOptions): Promise; - testPermissions(permissions: string|string[], gaxOpts: CallOptions, callback: TestIamPermissionsCallback): void; - testPermissions(permissions: string|string[], callback: TestIamPermissionsCallback): void; - testPermissions(permissions: string|string[], gaxOptsOrCallback?: CallOptions|TestIamPermissionsCallback, callback?: TestIamPermissionsCallback): Promise|void { + testPermissions(permissions: string|string[], gaxOpts?: CallOptions): + Promise; + testPermissions( + permissions: string|string[], gaxOpts: CallOptions, + callback: TestIamPermissionsCallback): void; + testPermissions( + permissions: string|string[], callback: TestIamPermissionsCallback): void; + testPermissions( + permissions: string|string[], + gaxOptsOrCallback?: CallOptions|TestIamPermissionsCallback, + callback?: TestIamPermissionsCallback): + Promise|void { if (!Array.isArray(permissions) && !(typeof permissions === 'string')) { throw new Error('Permissions are required.'); } - let gaxOpts = typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = + typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; + callback = + typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; const reqOpts = { resource: this.id, @@ -362,25 +384,25 @@ export class IAM { }; this.request( - { - client: 'SubscriberClient', - method: 'testIamPermissions', - reqOpts: reqOpts, - gaxOpts: gaxOpts, - }, - function(err, resp) { - if (err) { - callback!(err, null, resp); - return; - } - const availablePermissions = arrify(resp.permissions); - const permissionHash = (permissions as string[]).reduce(function(acc, permission) { - acc[permission] = availablePermissions.indexOf(permission) > -1; - return acc; - }, {} as {[key: string]: boolean}); - callback!(null, permissionHash, resp); - } - ); + { + client: 'SubscriberClient', + method: 'testIamPermissions', + reqOpts, + gaxOpts, + }, + (err, resp) => { + if (err) { + callback!(err, null, resp); + return; + } + const availablePermissions = arrify(resp.permissions); + const permissionHash = + (permissions as string[]).reduce((acc, permission) => { + acc[permission] = availablePermissions.indexOf(permission) > -1; + return acc; + }, {} as {[key: string]: boolean}); + callback!(null, permissionHash, resp); + }); } }