Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: honour the set region config #1039

Merged
merged 6 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,5 @@ export class SelectResults {
}

}

export const DEFAULT_REGION = 'us-east-1'
Fixed Show fixed Hide fixed
27 changes: 11 additions & 16 deletions src/main/minio.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
LEGAL_HOLD_STATUS, CopySourceOptions, CopyDestinationOptions, getSourceVersionId,
PART_CONSTRAINTS,
partsRequired,
calculateEvenSplits
calculateEvenSplits,
DEFAULT_REGION
} from './helpers.js'

import { signV4, presignSignatureV4, postPresignSignatureV4 } from './signing.js'
Expand All @@ -62,6 +63,7 @@ import { parseSelectObjectContentResponse} from "./xml-parsers"

var Package = require('../../package.json')


prakashsvmx marked this conversation as resolved.
Show resolved Hide resolved
export class Client {
constructor(params) {
if (typeof params.secure !== 'undefined') throw new Error('"secure" option deprecated, "useSSL" should be used instead')
Expand Down Expand Up @@ -132,6 +134,7 @@ export class Client {
this.secretKey = params.secretKey
this.sessionToken = params.sessionToken
this.userAgent = `${libraryAgent}`
this.region = DEFAULT_REGION

// Default path style is true
if (params.pathStyle === undefined) {
Expand Down Expand Up @@ -517,7 +520,7 @@ export class Client {
if (this.regionMap[bucketName]) return cb(null, this.regionMap[bucketName])
var extractRegion = (response) => {
var transformer = transformers.getBucketRegionTransformer()
var region = 'us-east-1'
var region = DEFAULT_REGION
pipesetup(response, transformer)
.on('error', cb)
.on('data', data => {
Expand Down Expand Up @@ -545,7 +548,7 @@ export class Client {
// obtained region.
var pathStyle = this.pathStyle && typeof window === 'undefined'

this.makeRequest({method, bucketName, query, pathStyle}, '', [200], 'us-east-1', true, (e, response) => {
this.makeRequest({method, bucketName, query, pathStyle}, '', [200], this.region, true, (e, response) => {
if (e) {
if (e.name === 'AuthorizationHeaderMalformed') {
var region = e.Region
Expand All @@ -569,7 +572,7 @@ export class Client {
// * `region` _string_ - region valid values are _us-west-1_, _us-west-2_, _eu-west-1_, _eu-central-1_, _ap-southeast-1_, _ap-northeast-1_, _ap-southeast-2_, _sa-east-1_.
// * `makeOpts` _object_ - Options to create a bucket. e.g {ObjectLocking:true} (Optional)
// * `callback(err)` _function_ - callback function with `err` as the error argument. `err` is null if the bucket is successfully created.
makeBucket(bucketName, region, makeOpts={}, cb) {
makeBucket(bucketName, region="", makeOpts={}, cb) {
prakashsvmx marked this conversation as resolved.
Show resolved Hide resolved
if (!isValidBucketName(bucketName)) {
throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName)
}
Expand Down Expand Up @@ -602,17 +605,9 @@ export class Client {

var payload = ''

// Region already set in constructor, validate if
// caller requested bucket location is same.
if (region && this.region) {
if (region !== this.region) {
throw new errors.InvalidArgumentError(`Configured region ${this.region}, requested ${region}`)
}
}

// sending makeBucket request with XML containing 'us-east-1' fails. For
// default region server expects the request without body
if (region && region !== 'us-east-1') {
if (region && region !== DEFAULT_REGION) {
var createBucketConfiguration = []
createBucketConfiguration.push({
_attr: {
Expand All @@ -634,7 +629,7 @@ export class Client {
headers["x-amz-bucket-object-lock-enabled"]=true
}

if (!region) region = 'us-east-1'
if (!region) region = this.region
this.makeRequest({method, bucketName, headers}, payload, [200], region, false, cb)
}

Expand All @@ -651,7 +646,7 @@ export class Client {
throw new TypeError('callback should be of type "function"')
}
var method = 'GET'
this.makeRequest({method}, '', [200], 'us-east-1', true, (e, response) => {
this.makeRequest({method}, '', [200], this.region, true, (e, response) => {
if (e) return cb(e)
var transformer = transformers.getListBucketTransformer()
var buckets
Expand Down Expand Up @@ -763,7 +758,7 @@ export class Client {
throw new TypeError('callback should be of type "function"')
}
var method = 'DELETE'
this.makeRequest({method, bucketName}, '', [204], '', false, (e) => {
this.makeRequest({method, bucketName}, '', [204], this.region, false, (e) => {
// If the bucket was successfully removed, remove the region map entry.
if (!e) delete(this.regionMap[bucketName])
cb(e)
Expand Down
4 changes: 2 additions & 2 deletions src/main/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { EventEmitter } from 'events'
import * as transformers from './transformers'
import { pipesetup, uriEscape } from './helpers'
import {DEFAULT_REGION, pipesetup, uriEscape} from './helpers'

// Notification config - array of target configs.
// Target configs can be
Expand Down Expand Up @@ -151,7 +151,7 @@ export class NotificationPoller extends EventEmitter {
if (queries.length > 0) {
query = `${queries.join('&')}`
}
const region = this.client.region || 'us-east-1'
const region = this.client.region || DEFAULT_REGION
this.client.makeRequest({ method, bucketName: this.bucketName, query }, '', [200], region, true, (e, response) => {
if (e) return this.emit('error', e)

Expand Down