UNPKG

@webda/aws

Version:

Webda AWS Services implementation

255 lines (254 loc) 6.83 kB
import { CertificateDetail } from "@aws-sdk/client-acm"; import { HostedZone, RRType } from "@aws-sdk/client-route-53"; import { GetCallerIdentityResponse } from "@aws-sdk/client-sts"; import { DeployerResources } from "@webda/core"; import { Deployer, DeploymentManager } from "@webda/shell"; export type TagsDefinition = { Key: string; Value: string; }[] | { [key: string]: string; }; /** * Common resources for all AWS Deployers */ export interface AWSDeployerResources extends DeployerResources { /** * AWS_ACCESS_KEY_ID to use * * Using static key is not recommended */ accessKeyId?: string; /** * AWS_SECRET_ACCESS_KEY to use * * Using static key is not recommended */ secretAccessKey?: string; /** * AWS_REGION to use * * @default "us-east-1" */ region?: string; /** * AWS_SESSION_TOKEN Token * * Even if it is possible to add it here * It is not sustainable as this token at its best will * have a lifetime of 12 hours */ sessionToken?: string; /** * AWS Account Id */ AWSAccountId?: string; /** * Endpoints to use by differents services * Usefull to test with localstack or other AWS emulations */ endpoints?: { ACM?: string; S3?: string; STS?: string; EC2?: string; Route53?: string; }; /** * Default Tags to use with resources created by deployers */ Tags?: TagsDefinition; /** * SSL certificates to create * * Sample * ``` * Certificates: { * "test.webda.io": { * SubjectAlternativeNames: ["test2.webda.io"] * } * } * ``` */ Certificates?: { [key: string]: { /** * Any alternative names to add to the certificate */ SubjectAlternativeNames?: string[]; Tags?: TagsDefinition; }; }; } /** * Abstract AWS Deployer * * It includes some basic utilities methods to be used by * final deployers */ export declare abstract class AWSDeployer<T extends AWSDeployerResources> extends Deployer<T> { constructor(manager: DeploymentManager, resources: any); /** * Return AWS region */ getRegion(): string; /** * Return the current AWS Identity used */ getAWSIdentity(): Promise<GetCallerIdentityResponse>; /** * Return the default VPC for the current region */ getDefaultVpc(): Promise<{ Id: string; Subnets: any[]; }>; /** * Generate a MD5 in hex * @param str to hash */ protected md5(str: string): string; /** * Hash the string * * @param str to hash * @param type of hash * @param format hex or b64 */ protected hash(str: string, type?: string, format?: "hex" | "base64"): string; /** * Replace / by _ as theses ID are not allowed in AWS * * @param id */ _replaceForAWS(id: string): string; /** * Get a certificate or create it * * @param domain to get certificate for * @param region */ getCertificate(domain: string, region?: string): Promise<any>; /** * Get the closest zone to the domain * * @param domain to get zone for */ getZoneForDomainName(domain: any): Promise<HostedZone>; /** * Transform a tag map into a tag array * * @param tags */ transformMapTagsToArray(tags: TagsDefinition): { Key: string; Value: string; }[]; /** * Transform a tag array into a tag map * * @param tags */ transformArrayTagsToMap(tags: TagsDefinition): { [key: string]: string; }; /** * Take this.resources[key].Tags and add all remaining Tags from this.resources.Tags * * @param key of the resources to add */ getDefaultTags(key?: string | TagsDefinition): { Key: string; Value: string; }[]; /** * Take this.resources[key].Tags and add all remaining Tags from this.resources.Tags * * @param key of the resources to add */ getDefaultTagsAsMap(key?: string | TagsDefinition): { [key: string]: string; }; /** * Return the S3 Tagging string * @param key of the resources to add */ getDefaultTagsAsS3Tagging(key?: string | TagsDefinition): string; waitFor(callback: (resolve?: (value?: any) => void, reject?: (reason?: any) => void) => Promise<boolean>, retries: number, title: string, delay: number): Promise<any>; /** * Create a certificate for a domain * Will use Route 53 to do the validation * * @param domain to create the certificate for * @param zone */ doCreateCertificate(domain: string, zone: HostedZone): Promise<CertificateDetail>; /** * Create DNS entry * * @param domain to create * @param type of DNS * @param value the value of the record * @param targetZone */ createDNSEntry(domain: string, type: RRType, value: string, targetZone?: HostedZone): Promise<void>; getARNPolicy(accountId: any, region: any): { Sid: string; Effect: string; Action: string[]; Resource: string[]; }[]; /** * Generate the `PolicyDocument` * * It will browse all services for a method `getARNPolicy` * Allowing you to write some specific Service or Bean that * requires specific AWS permissions */ getPolicyDocument(additionalStatements?: any[]): Promise<any>; /** * Create a bucket if it does not exist * * @param bucket to create */ createBucket(Bucket: string): Promise<void>; /** * Send a full folder (recursive) on bucket * * @param bucket to send data to * @param folder path to local folder to send * @param prefix prefix on the bucket */ putFolderOnBucket(bucket: string, folder: string, prefix?: string): Promise<void>; /** * Find the common prefix between two strings * * Example * ``` * commonPrefix("/test/plop1", "/templates/") => "/te" * ``` * * * @param str1 to compare * @param str2 to compare */ commonPrefix(str1: string, str2: string): string; /** * Add files to a bucket * * It uses hash and ETag to avoid uploading files already present * * * The files src can be either: * - a string representing the local path * - a Buffer with the dynamic content * * @param bucket to send bucket * @param files to send */ putFilesOnBucket(bucket: string, files: { key?: string; src: any; mimetype?: string; }[]): Promise<void>; }