Skip to content

Commit

Permalink
feat: add s3 with required envs
Browse files Browse the repository at this point in the history
  • Loading branch information
frytg committed Dec 17, 2024
1 parent 35da008 commit 0a72ba5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
25 changes: 25 additions & 0 deletions storage-s3/s3.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// load packages
import process from 'node:process'
import { test } from '@cross/test'
import { assertInstanceOf } from '@std/assert'
// @deno-types="minio/dist/esm/minio.d.mts"
import { Client } from 'minio'
import sinon from 'sinon'

test('s3 - exports a Minio.Client instance', async () => {
// Setup
const envStub = sinon.stub(process, 'env').value({
S3_ENDPOINT: 'test-endpoint',
MY_SCW_ACCESS_KEY: 'test-access-key',
MY_SCW_SECRET_KEY: 'test-secret-key',
})

// load module with stubbed env
const { minioClient } = await import('./s3.ts')

// Verify
assertInstanceOf(minioClient, Client, 'Should export a Minio.Client instance')

// Cleanup
envStub.restore()
})
20 changes: 8 additions & 12 deletions storage-s3/s3.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// load packages
import process from 'node:process'
import { checkRequiredEnv } from '@frytg/check-required-env'
import * as Minio from 'minio'
import { getRequiredEnv } from '@frytg/check-required-env/get'
// @deno-types="minio/dist/esm/minio.d.mts"
import { Client } from 'minio'

// check for env
checkRequiredEnv('S3_ENDPOINT')
checkRequiredEnv('MY_SCW_ACCESS_KEY')
checkRequiredEnv('MY_SCW_SECRET_KEY')

export const minioClient = new Minio.Client({
// create a minio client
export const minioClient = new Client({
useSSL: true,
endPoint: process.env.S3_ENDPOINT,
accessKey: process.env.MY_SCW_ACCESS_KEY,
secretKey: process.env.MY_SCW_SECRET_KEY,
endPoint: getRequiredEnv('S3_ENDPOINT', false),
accessKey: getRequiredEnv('MY_SCW_ACCESS_KEY', false),
secretKey: getRequiredEnv('MY_SCW_SECRET_KEY', false),
})

0 comments on commit 0a72ba5

Please sign in to comment.