UNPKG

4.14 kBTypeScriptView Raw
1import { Metadata } from './nodejs-common';
2import { Bucket } from './bucket';
3export interface GetPolicyOptions {
4 userProject?: string;
5 requestedPolicyVersion?: number;
6}
7export type GetPolicyResponse = [Policy, Metadata];
8/**
9 * @callback GetPolicyCallback
10 * @param {?Error} err Request error, if any.
11 * @param {object} acl The policy.
12 * @param {object} apiResponse The full API response.
13 */
14export interface GetPolicyCallback {
15 (err?: Error | null, acl?: Policy, apiResponse?: Metadata): void;
16}
17/**
18 * @typedef {object} SetPolicyOptions
19 * @param {string} [userProject] The ID of the project which will be
20 * billed for the request.
21 */
22export interface SetPolicyOptions {
23 userProject?: string;
24}
25/**
26 * @typedef {array} SetPolicyResponse
27 * @property {object} 0 The policy.
28 * @property {object} 1 The full API response.
29 */
30export type SetPolicyResponse = [Policy, Metadata];
31/**
32 * @callback SetPolicyCallback
33 * @param {?Error} err Request error, if any.
34 * @param {object} acl The policy.
35 * @param {object} apiResponse The full API response.
36 */
37export interface SetPolicyCallback {
38 (err?: Error | null, acl?: Policy, apiResponse?: object): void;
39}
40export interface Policy {
41 bindings: PolicyBinding[];
42 version?: number;
43 etag?: string;
44}
45export interface PolicyBinding {
46 role: string;
47 members: string[];
48 condition?: Expr;
49}
50export interface Expr {
51 title?: string;
52 description?: string;
53 expression: string;
54}
55/**
56 * @typedef {array} TestIamPermissionsResponse
57 * @property {object} 0 A subset of permissions that the caller is allowed.
58 * @property {object} 1 The full API response.
59 */
60export type TestIamPermissionsResponse = [{
61 [key: string]: boolean;
62}, Metadata];
63/**
64 * @callback TestIamPermissionsCallback
65 * @param {?Error} err Request error, if any.
66 * @param {object} acl A subset of permissions that the caller is allowed.
67 * @param {object} apiResponse The full API response.
68 */
69export interface TestIamPermissionsCallback {
70 (err?: Error | null, acl?: {
71 [key: string]: boolean;
72 } | null, apiResponse?: Metadata): void;
73}
74/**
75 * @typedef {object} TestIamPermissionsOptions Configuration options for Iam#testPermissions().
76 * @param {string} [userProject] The ID of the project which will be
77 * billed for the request.
78 */
79export interface TestIamPermissionsOptions {
80 userProject?: string;
81}
82export declare enum IAMExceptionMessages {
83 POLICY_OBJECT_REQUIRED = "A policy object is required.",
84 PERMISSIONS_REQUIRED = "Permissions are required."
85}
86/**
87 * Get and set IAM policies for your Cloud Storage bucket.
88 *
89 * See {@link https://cloud.google.com/storage/docs/access-control/iam#short_title_iam_management| Cloud Storage IAM Management}
90 * See {@link https://cloud.google.com/iam/docs/granting-changing-revoking-access| Granting, Changing, and Revoking Access}
91 * See {@link https://cloud.google.com/iam/docs/understanding-roles| IAM Roles}
92 *
93 * @constructor Iam
94 *
95 * @param {Bucket} bucket The parent instance.
96 * @example
97 * ```
98 * const {Storage} = require('@google-cloud/storage');
99 * const storage = new Storage();
100 * const bucket = storage.bucket('my-bucket');
101 * // bucket.iam
102 * ```
103 */
104declare class Iam {
105 private request_;
106 private resourceId_;
107 constructor(bucket: Bucket);
108 getPolicy(options?: GetPolicyOptions): Promise<GetPolicyResponse>;
109 getPolicy(options: GetPolicyOptions, callback: GetPolicyCallback): void;
110 getPolicy(callback: GetPolicyCallback): void;
111 setPolicy(policy: Policy, options?: SetPolicyOptions): Promise<SetPolicyResponse>;
112 setPolicy(policy: Policy, callback: SetPolicyCallback): void;
113 setPolicy(policy: Policy, options: SetPolicyOptions, callback: SetPolicyCallback): void;
114 testPermissions(permissions: string | string[], options?: TestIamPermissionsOptions): Promise<TestIamPermissionsResponse>;
115 testPermissions(permissions: string | string[], callback: TestIamPermissionsCallback): void;
116 testPermissions(permissions: string | string[], options: TestIamPermissionsOptions, callback: TestIamPermissionsCallback): void;
117}
118export { Iam };