Merge pull request #124 from getmaxun/minio-screenshot-access

feat: apply public-read policy to minio bucket
This commit is contained in:
Karishma Shukla
2024-11-04 22:12:37 +05:30
committed by GitHub
2 changed files with 22 additions and 20 deletions

View File

@@ -32,9 +32,10 @@ services:
environment: environment:
MINIO_ROOT_USER: ${MINIO_ACCESS_KEY} MINIO_ROOT_USER: ${MINIO_ACCESS_KEY}
MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY} MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY}
command: server /data command: server /data --console-address :9001
ports: ports:
- "9000:9000" - "9000:9000" # API port
- "9001:9001" # WebUI port
volumes: volumes:
- minio_data:/data - minio_data:/data

View File

@@ -21,21 +21,24 @@ minioClient.bucketExists('maxun-test')
console.error('Error connecting to MinIO:', err); console.error('Error connecting to MinIO:', err);
}) })
async function createBucketWithPolicy(bucketName: string, policy?: 'public-read' | 'private') { async function createBucketWithPolicy(bucketName: string, policy = 'public-read') {
try { try {
const bucketExists = await minioClient.bucketExists(bucketName); const bucketExists = await minioClient.bucketExists(bucketName);
if (!bucketExists) { if (!bucketExists) {
await minioClient.makeBucket(bucketName); await minioClient.makeBucket(bucketName);
console.log(`Bucket ${bucketName} created successfully.`); console.log(`Bucket ${bucketName} created successfully.`);
} else {
console.log(`Bucket ${bucketName} already exists.`);
}
if (policy === 'public-read') { if (policy === 'public-read') {
// Define a public-read policy // Apply public-read policy after confirming the bucket exists
const policyJSON = { const policyJSON = {
Version: "2012-10-17", Version: "2012-10-17",
Statement: [ Statement: [
{ {
Effect: "Allow", Effect: "Allow",
Principal: "", Principal: "*",
Action: ["s3:GetObject"], Action: ["s3:GetObject"],
Resource: [`arn:aws:s3:::${bucketName}/*`] Resource: [`arn:aws:s3:::${bucketName}/*`]
} }
@@ -44,15 +47,13 @@ async function createBucketWithPolicy(bucketName: string, policy?: 'public-read'
await minioClient.setBucketPolicy(bucketName, JSON.stringify(policyJSON)); await minioClient.setBucketPolicy(bucketName, JSON.stringify(policyJSON));
console.log(`Public-read policy applied to bucket ${bucketName}.`); console.log(`Public-read policy applied to bucket ${bucketName}.`);
} }
} else {
console.log(`Bucket ${bucketName} already exists.`);
}
} catch (error) { } catch (error) {
console.error('Error in bucket creation or policy application:', error); console.error('Error in bucket creation or policy application:', error);
} }
} }
class BinaryOutputService { class BinaryOutputService {
private bucketName: string; private bucketName: string;