export interface APIOptions { region?: string; restApiId?: string; stage?: string; } export interface AuthPolicyMethod { resourceArn?: string; conditions?: string[]; } export interface AuthPolicyStatement { Action?: string; Effect?: string; Resource?: any[]; Condition?: string; } export interface AuthPolicyDocument { Version?: string; Statement?: AuthPolicyStatement[]; } export interface AuthPolicyResponse { principalId: string; policyDocument: any; context?: any; } /** * AuthPolicy receives a set of allowed and denied methods and generates a valid * AWS policy for the API Gateway authorizer. The constructor receives the calling * user principal, the AWS account ID of the API owner, and an apiOptions object. * The apiOptions can contain an API Gateway RestApi Id, a region for the RestApi, and a * stage that calls should be allowed/denied for. For example * { * restApiId: "xxxxxxxxxx", * region: "us-east-1", * stage: "dev" * } * * let testPolicy = new AuthPolicy("[principal user identifier]", "[AWS account id]", apiOptions); * testPolicy.allowMethod(AuthPolicy.HttpVerb.GET, "/users/username"); * testPolicy.denyMethod(AuthPolicy.HttpVerb.POST, "/pets"); * context.succeed(testPolicy.build()); * * @class AuthPolicy * @constructor */ export declare class AuthPolicy { awsAccountId: string; principalId: string; version: string; pathRegex: RegExp; restApiId: string; region: string; stage: string; allowMethods: AuthPolicyMethod[]; denyMethods: AuthPolicyMethod[]; constructor(principalId: string, methodArn: string); /** * A set of existing HTTP verbs supported by API Gateway. This property is here * only to avoid spelling mistakes in the policy. * * @property HttpVerb * @type {Object} */ static get HttpVerb(): { GET: string; POST: string; PUT: string; PATCH: string; HEAD: string; DELETE: string; OPTIONS: string; ALL: string; }; /** * Adds a method to the internal lists of allowed or denied methods. Each object in * the internal list contains a resource ARN and a condition statement. The condition * statement can be null. * * @method addMethod * @param {String} The effect for the policy. This can only be "Allow" or "Deny". * @param {String} he HTTP verb for the method, this should ideally come from the * AuthPolicy.HttpVerb object to avoid spelling mistakes * @param {String} The resource path. For example "/pets" * @param {Object} The conditions object in the format specified by the AWS docs. * @return {void} */ private addMethod; /** * Returns an empty statement object prepopulated with the correct action and the * desired effect. * * @method getEmptyStatement * @param {String} The effect of the statement, this can be "Allow" or "Deny" * @return {Object} An empty statement object with the Action, Effect, and Resource * properties prepopulated. */ static getEmptyStatement(effect: any): AuthPolicyStatement; /** * This function loops over an array of objects containing a resourceArn and * conditions statement and generates the array of statements for the policy. * * @method getStatementsForEffect * @param {String} The desired effect. This can be "Allow" or "Deny" * @param {Array} An array of method objects containing the ARN of the resource * and the conditions for the policy * @return {Array} an array of formatted statements for the policy. */ private getStatementsForEffect; /** * Adds an allow "*" statement to the policy. * * @method allowAllMethods */ allowAllMethods(): void; /** * Adds a deny "*" statement to the policy. * * @method denyAllMethods */ denyAllMethods(): void; /** * Adds an API Gateway method (Http verb + Resource path) to the list of allowed * methods for the policy * * @method allowMethod * @param {String} The HTTP verb for the method, this should ideally come from the * AuthPolicy.HttpVerb object to avoid spelling mistakes * @param {string} The resource path. For example "/pets" * @return {void} */ allowMethod(verb: any, resource: any): void; /** * Adds an API Gateway method (Http verb + Resource path) to the list of denied * methods for the policy * * @method denyMethod * @param {String} The HTTP verb for the method, this should ideally come from the * AuthPolicy.HttpVerb object to avoid spelling mistakes * @param {string} The resource path. For example "/pets" * @return {void} */ denyMethod(verb: any, resource: any): void; /** * Adds an API Gateway method (Http verb + Resource path) to the list of allowed * methods and includes a condition for the policy statement. More on AWS policy * conditions here: http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#Condition * * @method allowMethodWithConditions * @param {String} The HTTP verb for the method, this should ideally come from the * AuthPolicy.HttpVerb object to avoid spelling mistakes * @param {string} The resource path. For example "/pets" * @param {Object} The conditions object in the format specified by the AWS docs * @return {void} */ allowMethodWithConditions(verb: any, resource: any, conditions: any): void; /** * Adds an API Gateway method (Http verb + Resource path) to the list of denied * methods and includes a condition for the policy statement. More on AWS policy * conditions here: http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#Condition * * @method denyMethodWithConditions * @param {String} The HTTP verb for the method, this should ideally come from the * AuthPolicy.HttpVerb object to avoid spelling mistakes * @param {string} The resource path. For example "/pets" * @param {Object} The conditions object in the format specified by the AWS docs * @return {void} */ denyMethodWithConditions(verb: any, resource: any, conditions: any): void; /** * Generates the policy document based on the internal lists of allowed and denied * conditions. This will generate a policy with two main statements for the effect: * one statement for Allow and one statement for Deny. * Methods that includes conditions will have their own statement in the policy. * * @method build * @return {Object} The policy object that can be serialized to JSON. */ build(): AuthPolicyResponse; }