UNPKG

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