Skip to content

Commit

Permalink
feat: support access style override
Browse files Browse the repository at this point in the history
  • Loading branch information
bingliang committed Nov 14, 2020
1 parent fdbc801 commit f34483e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
15 changes: 15 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ __Parameters__
|`transport` | _string_ |Set this value to pass in a custom transport. (Optional)|
|`sessionToken` | _string_ |Set this value to provide x-amz-security-token (AWS S3 specific). (Optional)|
|`partSize` | _number_ |Set this value to override default part size of 64MB for multipart uploads. (Optional)|
|`accessStyle` | _string_ |Set this value to override default access behavior. Supported styles are 'path' and 'virtual-hosted'. (Optional)|


__Example__
Expand Down Expand Up @@ -96,6 +97,20 @@ var s3Client = new Minio.Client({
})
```

## Ali OSS

```js
var Minio = require('minio')

var s3Client = new Minio.Client({
endPoint: 'oss-cn-hangzhou.aliyuncs.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY',
bucket: 'YOUR-BUCKET',
accessStyle: 'virtual-hosted',
region: 'oss-cn-hangzhou'
})
```

## 2. Bucket operations
<a name="makeBucket"></a>
Expand Down
22 changes: 19 additions & 3 deletions docs/zh_CN/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,26 @@ var Minio = require('minio')

var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
})
```

## Ali OSS

```js
var Minio = require('minio')

var s3Client = new Minio.Client({
endPoint: 'oss-cn-hangzhou.aliyuncs.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY',
bucket: 'YOUR-BUCKET',
accessStyle: 'virtual-hosted',
region: 'oss-cn-hangzhou'
})
```

| 操作存储桶 | 操作对象 | Presigned操作 | 存储桶策略/通知 |
| ------------- |-------------| -----| ----- |
| [`makeBucket`](#makeBucket) | [`getObject`](#getObject) | [`presignedUrl`](#presignedUrl) | [`getBucketNotification`](#getBucketNotification) |
Expand Down Expand Up @@ -64,7 +80,7 @@ __参数__
|`transport` | _string_ |Set this value to pass in a custom transport. (Optional) - To be translated |
|`sessionToken` | _string_ |Set this value to provide x-amz-security-token (AWS S3 specific). (Optional) - To be translated|
|`partSize` | _number_ |Set this value to override default part size of 64MB for multipart uploads. (Optional) - To be translated|

|`accessStyle` | _string_ |设置该值以覆盖默认访问方式。支持方式有 'path' 与 'virtual-hosted'。(可选)|

__示例__

Expand Down
11 changes: 9 additions & 2 deletions src/main/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,18 @@ export function isAmazonEndpoint(endpoint) {
// style if the protocol is 'https:', this is due to SSL wildcard
// limitation. For all other buckets and Amazon S3 endpoint we will
// default to virtual host style.
export function isVirtualHostStyle(endpoint, protocol, bucket) {
export function isVirtualHostStyle(endpoint, protocol, bucket, accessStyle) {
if (protocol === 'https:' && bucket.indexOf('.') > -1) {
if (accessStyle !== undefined && accessStyle !== 'path') {
console.log("Protocol is https and bucket contains a dot, ignoring override, force path style.")
}
return false
}
return isAmazonEndpoint(endpoint)
switch (accessStyle) {
case 'path': return false
case 'virtual-hosted': return true
default: return isAmazonEndpoint(endpoint)
}
}

var ipv4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/
Expand Down
8 changes: 4 additions & 4 deletions src/main/minio.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class Client {
this.accessKey = params.accessKey
this.secretKey = params.secretKey
this.sessionToken = params.sessionToken
this.accessStyle = params.accessStyle
this.userAgent = `${libraryAgent}`

if (!this.accessKey) this.accessKey = ''
Expand Down Expand Up @@ -178,9 +179,7 @@ export class Client {
// Verify if virtual host supported.
var virtualHostStyle
if (bucketName) {
virtualHostStyle = isVirtualHostStyle(this.host,
this.protocol,
bucketName)
virtualHostStyle = isVirtualHostStyle(this.host, this.protocol, bucketName, this.accessStyle)
}

if (this.port) reqOptions.port = this.port
Expand Down Expand Up @@ -489,7 +488,8 @@ export class Client {
// the error XML also provides Region of the bucket. To validate
// this region is proper we retry the same request with the newly
// obtained region.
var pathStyle = typeof window === 'undefined'
var pathStyle = typeof window === 'undefined' && this.accessStyle !== 'virtual-hosted'

this.makeRequest({method, bucketName, query, pathStyle}, '', 200, 'us-east-1', true, (e, response) => {
if (e) {
if (e.name === 'AuthorizationHeaderMalformed') {
Expand Down

0 comments on commit f34483e

Please sign in to comment.