Skip to content

Commit

Permalink
feat: allow passing region to adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Apr 29, 2024
1 parent 881aaea commit 27c7488
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const checkName = (name) => {
return resultToAsync(
Result.Err([])
.alt(
includes('..', name) ? Result.Err(['name cannot contain \'..\'']) : Result.Err([]),
includes('..', name) ? Result.Err(["name cannot contain '..'"]) : Result.Err([]),
)
.bichain(
(errs) => errs.length ? Result.Err(errs) : Result.Ok(name),
Expand Down
6 changes: 4 additions & 2 deletions mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { Either } = crocks
const { Left, Right, of } = Either
const { identity, defaultTo, over, lensProp, mergeRight } = R

export default ({ url, bucketPrefix, useNamespacedBucket }) => {
export default ({ url, region, bucketPrefix, useNamespacedBucket }) => {
const checkBucketPrefix = (config) =>
config.bucketPrefix && config.bucketPrefix.length <= 32 ? Right(config) : Left({
message: 'Prefix name: must be a string 1-32 alphanumeric characters',
Expand All @@ -16,6 +16,7 @@ export default ({ url, bucketPrefix, useNamespacedBucket }) => {
const setFromEnv = (config) =>
mergeRight({
url: Deno.env.get('MINIO_URL'),
region: Deno.env.get('MINIO_REGION'),
// optional. Credentials in MINIO_URL take precedent
accessKey: Deno.env.get('MINIO_ROOT_USER'),
secretKey: Deno.env.get('MINIO_ROOT_PASSWORD'),
Expand All @@ -30,6 +31,7 @@ export default ({ url, bucketPrefix, useNamespacedBucket }) => {
const minioConfig = new URL(config.url)
return new Minio.Client({
endPoint: minioConfig.hostname,
region: config.region,
// Fallback to credentials pulled from env, if none in MINIO_URL
accessKey: minioConfig.username || config.accessKey,
secretKey: minioConfig.password || config.secretKey,
Expand All @@ -46,7 +48,7 @@ export default ({ url, bucketPrefix, useNamespacedBucket }) => {
load: (prevLoad) =>
of(prevLoad) // credentials can be received from a composed plugin
.map(defaultTo({}))
.map((prevLoad) => mergeRight(prevLoad, { url, bucketPrefix, useNamespacedBucket }))
.map((prevLoad) => mergeRight(prevLoad, { url, region, bucketPrefix, useNamespacedBucket }))
.chain(checkBucketPrefix)
.map(setFromEnv)
.map(setUseNamespacedBucket)
Expand Down

0 comments on commit 27c7488

Please sign in to comment.