UNPKG

@webda/aws

Version:

Webda AWS Services implementation

163 lines (162 loc) 4.61 kB
import { HeadObjectCommandOutput, S3 } from "@aws-sdk/client-s3"; import { BinaryFile, BinaryMap, BinaryParameters, CloudBinary, CoreModel, OperationContext, WebContext } from "@webda/core"; import { Readable } from "stream"; import CloudFormationDeployer from "../deployers/cloudformation.js"; import { CloudFormationContributor } from "./index.js"; declare const S3BinaryParameters_base: { new (...args: any[]): { endpoint?: string; credentials?: { accessKeyId: string; secretAccessKey: string; sessionToken?: string; }; region?: string; type: string; url?: string; openapi?: import("@webda/core/lib/router").OpenAPIWebdaDefinition; }; } & typeof BinaryParameters; export declare class S3BinaryParameters extends S3BinaryParameters_base { forcePathStyle?: boolean; bucket: string; prefix?: string; CloudFormation: any; CloudFormationSkip: boolean; constructor(params: any, service: S3Binary); } /** * S3Binary handles the storage of binary on a S3 bucket * * The structure used for now is * /{hash}/data * /{hash}/{targetStore}_{uuid} * The challenge is stored on the metadata of the data object * * It takes parameters * bucket: "bucketName" * accessKeyId: "" * secretAccessKey: "" * region: "" * * See Binary the general interface * * We can register on S3 Event to get info when /data is pushed * * @WebdaModda */ export default class S3Binary<T extends S3BinaryParameters = S3BinaryParameters> extends CloudBinary<T> implements CloudFormationContributor { _s3: S3; /** * Load the parameters * * @param params */ loadParameters(params: any): S3BinaryParameters; /** * @inheritdoc */ computeParameters(): void; /** * @inheritdoc */ putRedirectUrl(ctx: WebContext): Promise<{ url: string; method: string; headers: { [key: string]: string; }; }>; /** * @inheritdoc */ putMarker(hash: string, suffix: string, storeName: string): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>; /** * Return a signed url to an object * * @param key to the object * @param action to perform * @param params * @returns */ getSignedUrl(key: string, action?: "getObject" | "putObject", params?: any): Promise<string>; /** * @override */ getSignedUrlFromMap(binaryMap: BinaryMap, expire: number, _context: OperationContext): Promise<string>; /** * @override */ _get(info: BinaryMap): Promise<Readable>; /** * Check if an object exists on S3 * @param key * @param bucket */ exists(Key: string, Bucket?: string): Promise<HeadObjectCommandOutput | null>; /** * @inheritdoc */ getUsageCount(hash: string): Promise<number>; /** * @inheritdoc */ _cleanHash(hash: string): Promise<void>; /** * @inheritdoc */ _cleanUsage(hash: string, uuid: string, attribute?: string): Promise<void>; /** * @inheritdoc */ _exists(hash: string): Promise<boolean>; /** * Get a head object * @param hash * @returns */ _getS3(hash: string): Promise<HeadObjectCommandOutput>; /** * Get an object from s3 bucket * * @param key to get * @param bucket to retrieve from or default bucket * @returns */ getObject(key: string, bucket?: string): Promise<Readable>; /** * * @param Bucket to iterate on * @param Prefix to use * @param callback to execute with each key * @param filter regexp to execute on the key */ forEachFile(Bucket: string, callback: (Key: string, page: number) => Promise<void>, Prefix?: string, filter?: RegExp): Promise<void>; /** * Add an object to S3 bucket * * @param key to add to * @param body content of the object * @param metadatas to put along the object * @param bucket to use */ putObject(key: string, body: Buffer | Blob | string | ReadableStream, metadatas?: {}, bucket?: string): Promise<void>; /** * @inheritdoc */ store(object: CoreModel, property: string, file: BinaryFile): Promise<void>; /** * @inheritdoc */ getARNPolicy(_accountId: string): { Sid: string; Effect: string; Action: string[]; Resource: string[]; }; /** * @inheritdoc */ getCloudFormation(deployer: CloudFormationDeployer): {}; } export { S3Binary };