UNPKG

4.84 kBTypeScriptView Raw
1import * as cdk from '@aws-cdk/core';
2import { IConstruct } from '@aws-cdk/core';
3import { PolicyStatement } from './policy-statement';
4/**
5 * Properties for a new PolicyDocument
6 */
7export interface PolicyDocumentProps {
8 /**
9 * Automatically assign Statement Ids to all statements
10 *
11 * @default false
12 */
13 readonly assignSids?: boolean;
14 /**
15 * Initial statements to add to the policy document
16 *
17 * @default - No statements
18 */
19 readonly statements?: PolicyStatement[];
20 /**
21 * Try to minimize the policy by merging statements
22 *
23 * To avoid overrunning the maximum policy size, combine statements if they produce
24 * the same result. Merging happens according to the following rules:
25 *
26 * - The Effect of both statements is the same
27 * - Neither of the statements have a 'Sid'
28 * - Combine Principals if the rest of the statement is exactly the same.
29 * - Combine Resources if the rest of the statement is exactly the same.
30 * - Combine Actions if the rest of the statement is exactly the same.
31 * - We will never combine NotPrincipals, NotResources or NotActions, because doing
32 * so would change the meaning of the policy document.
33 *
34 * @default - false, unless the feature flag `@aws-cdk/aws-iam:minimizePolicies` is set
35 */
36 readonly minimize?: boolean;
37}
38/**
39 * A PolicyDocument is a collection of statements
40 */
41export declare class PolicyDocument implements cdk.IResolvable {
42 /**
43 * Creates a new PolicyDocument based on the object provided.
44 * This will accept an object created from the `.toJSON()` call
45 * @param obj the PolicyDocument in object form.
46 */
47 static fromJson(obj: any): PolicyDocument;
48 readonly creationStack: string[];
49 private readonly statements;
50 private readonly autoAssignSids;
51 private readonly minimize?;
52 constructor(props?: PolicyDocumentProps);
53 resolve(context: cdk.IResolveContext): any;
54 /**
55 * Whether the policy document contains any statements.
56 */
57 get isEmpty(): boolean;
58 /**
59 * The number of statements already added to this policy.
60 * Can be used, for example, to generate unique "sid"s within the policy.
61 */
62 get statementCount(): number;
63 /**
64 * Adds a statement to the policy document.
65 *
66 * @param statement the statement to add.
67 */
68 addStatements(...statement: PolicyStatement[]): void;
69 /**
70 * Encode the policy document as a string
71 */
72 toString(): string;
73 /**
74 * JSON-ify the document
75 *
76 * Used when JSON.stringify() is called
77 */
78 toJSON(): any;
79 /**
80 * Validate that all policy statements in the policy document satisfies the
81 * requirements for any policy.
82 *
83 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#access_policies-json
84 *
85 * @returns An array of validation error messages, or an empty array if the document is valid.
86 */
87 validateForAnyPolicy(): string[];
88 /**
89 * Validate that all policy statements in the policy document satisfies the
90 * requirements for a resource-based policy.
91 *
92 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#access_policies-json
93 *
94 * @returns An array of validation error messages, or an empty array if the document is valid.
95 */
96 validateForResourcePolicy(): string[];
97 /**
98 * Validate that all policy statements in the policy document satisfies the
99 * requirements for an identity-based policy.
100 *
101 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#access_policies-json
102 *
103 * @returns An array of validation error messages, or an empty array if the document is valid.
104 */
105 validateForIdentityPolicy(): string[];
106 /**
107 * Perform statement merging (if enabled and not done yet)
108 *
109 * @internal
110 */
111 _maybeMergeStatements(scope: cdk.IConstruct): void;
112 /**
113 * Split the statements of the PolicyDocument into multiple groups, limited by their size
114 *
115 * We do a round of size-limited merging first (making sure to not produce statements too
116 * large to fit into standalone policies), so that we can most accurately estimate total
117 * policy size. Another final round of minimization will be done just before rendering to
118 * end up with minimal policies that look nice to humans.
119 *
120 * Return a map of the final set of policy documents, mapped to the ORIGINAL (pre-merge)
121 * PolicyStatements that ended up in the given PolicyDocument.
122 *
123 * @internal
124 */
125 _splitDocument(scope: IConstruct, selfMaximumSize: number, splitMaximumSize: number): Map<PolicyDocument, PolicyStatement[]>;
126 private render;
127 private shouldMerge;
128}