Skip to content

Commit

Permalink
added ts style fix for src/iam.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
vijay-qlogic committed Nov 24, 2018
1 parent fd2dd12 commit 5183fb3
Showing 1 changed file with 80 additions and 58 deletions.
138 changes: 80 additions & 58 deletions src/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -193,23 +196,26 @@ export class IAM {
getPolicy(gaxOpts?: CallOptions): Promise<GetPolicyCallback>;
getPolicy(callback: GetPolicyCallback): void;
getPolicy(gaxOpts: CallOptions, callback: GetPolicyCallback): void;
getPolicy(gaxOptsOrCallback?: CallOptions|GetPolicyCallback, callback?: GetPolicyCallback): Promise<GetPolicyCallback>|void {
let gaxOpts = typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {};
callback = typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback;
getPolicy(
gaxOptsOrCallback?: CallOptions|GetPolicyCallback,
callback?: GetPolicyCallback): Promise<GetPolicyCallback>|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!);
}

/**
Expand Down Expand Up @@ -241,14 +247,16 @@ export class IAM {
* bindings: [
* {
* role: 'roles/pubsub.subscriber',
* members: ['serviceAccount:[email protected]']
* members:
* ['serviceAccount:[email protected]']
* }
* ]
* };
*
* 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.
Expand All @@ -259,30 +267,34 @@ export class IAM {
* });
*/
setPolicy(policy: Policy, gaxOpts?: CallOptions): Promise<SetPolicyResponse>;
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<SetPolicyResponse>|void {
setPolicy(
policy: Policy, gaxOptsOrCallback?: CallOptions|SetPolicyCallback,
callback?: SetPolicyCallback): Promise<SetPolicyResponse>|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,
policy,
};

this.request(
{
client: 'SubscriberClient',
method: 'setIamPolicy',
reqOpts: reqOpts,
gaxOpts: gaxOpts,
},
callback!
);
{
client: 'SubscriberClient',
method: 'setIamPolicy',
reqOpts,
gaxOpts,
},
callback!);
}

/**
Expand Down Expand Up @@ -345,42 +357,52 @@ export class IAM {
* const apiResponse = data[1];
* });
*/
testPermissions(permissions: string|string[], gaxOpts?: CallOptions): Promise<TestIamPermissionsResponse>;
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<TestIamPermissionsResponse>|void {
testPermissions(permissions: string|string[], gaxOpts?: CallOptions):
Promise<TestIamPermissionsResponse>;
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<TestIamPermissionsResponse>|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,
permissions: arrify(permissions),
};

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);
});
}
}

Expand Down

0 comments on commit 5183fb3

Please sign in to comment.