import { Injectable } from '@nestjs/common'; import * as Joi from 'joi'; import { AbstractActionHandler, Format } from '../abstract-action.handler'; import { Action } from '../action.enum'; import { RequestContext } from '../_context/request.context'; import { S3Service } from './s3.service'; type QueryParams = { Bucket: string; }; @Injectable() export class GetBucketAclHandler extends AbstractActionHandler { constructor(private readonly s3Service: S3Service) { super(); } format = Format.Xml; action = Action.S3GetBucketAcl; validator = Joi.object({ Bucket: Joi.string().required(), }); protected async handle({ Bucket }: QueryParams, { awsProperties }: RequestContext) { const acl = await this.s3Service.getBucketAcl(Bucket); return { Owner: acl.Owner, AccessControlList: { Grant: acl.Grants.length > 0 ? acl.Grants : undefined, }, }; } }