Skip to content

Commit

Permalink
feat: support access style override (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
bingliang-zh authored Nov 24, 2020
1 parent fdbc801 commit 6888347
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
16 changes: 15 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +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)|

|`pathStyle` | _bool_ |Set this value to override default access behavior (path) for non AWS endpoints. Default is true. (Optional)|

__Example__

Expand Down Expand Up @@ -96,6 +96,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',
pathStyle: false,
region: 'oss-cn-hangzhou'
})
```

## 2. Bucket operations
<a name="makeBucket"></a>
Expand Down
21 changes: 18 additions & 3 deletions docs/zh_CN/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ 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'
})
```

| 操作存储桶 | 操作对象 | Presigned操作 | 存储桶策略/通知 |
| ------------- |-------------| -----| ----- |
| [`makeBucket`](#makeBucket) | [`getObject`](#getObject) | [`presignedUrl`](#presignedUrl) | [`getBucketNotification`](#getBucketNotification) |
Expand Down Expand Up @@ -64,7 +65,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|

| `pathStyle` | _bool_ | 对于非 AWS 的 Endpoint,设置该值以覆盖默认访问方式 (path)。默认值为 true。(可选) |

__示例__

Expand Down Expand Up @@ -95,6 +96,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',
pathStyle: false,
region: 'oss-cn-hangzhou'
})
```

## 2. 操作存储桶
<a name="makeBucket"></a>
Expand Down
4 changes: 2 additions & 2 deletions src/main/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ 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, pathStyle) {
if (protocol === 'https:' && bucket.indexOf('.') > -1) {
return false
}
return isAmazonEndpoint(endpoint)
return isAmazonEndpoint(endpoint) || !pathStyle
}

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

// Default path style is true
if (params.pathStyle === undefined) {
this.pathStyle = true
} else {
this.pathStyle = params.pathStyle
}

if (!this.accessKey) this.accessKey = ''
if (!this.secretKey) this.secretKey = ''
this.anonymous = !this.accessKey || !this.secretKey
Expand Down Expand Up @@ -178,9 +185,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.pathStyle)
}

if (this.port) reqOptions.port = this.port
Expand Down Expand Up @@ -489,7 +494,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 = this.pathStyle && typeof window === 'undefined'

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 6888347

Please sign in to comment.