Skip to content

Commit 6888347

Browse files
authoredNov 24, 2020
feat: support access style override (#872)
1 parent fdbc801 commit 6888347

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed
 

‎docs/API.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ __Parameters__
6565
|`transport` | _string_ |Set this value to pass in a custom transport. (Optional)|
6666
|`sessionToken` | _string_ |Set this value to provide x-amz-security-token (AWS S3 specific). (Optional)|
6767
|`partSize` | _number_ |Set this value to override default part size of 64MB for multipart uploads. (Optional)|
68-
68+
|`pathStyle` | _bool_ |Set this value to override default access behavior (path) for non AWS endpoints. Default is true. (Optional)|
6969

7070
__Example__
7171

@@ -96,6 +96,20 @@ var s3Client = new Minio.Client({
9696
})
9797
```
9898

99+
## Ali OSS
100+
101+
```js
102+
var Minio = require('minio')
103+
104+
var s3Client = new Minio.Client({
105+
endPoint: 'oss-cn-hangzhou.aliyuncs.com',
106+
accessKey: 'YOUR-ACCESSKEYID',
107+
secretKey: 'YOUR-SECRETACCESSKEY',
108+
bucket: 'YOUR-BUCKET',
109+
pathStyle: false,
110+
region: 'oss-cn-hangzhou'
111+
})
112+
```
99113

100114
## 2. Bucket operations
101115
<a name="makeBucket"></a>

‎docs/zh_CN/API.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ var Minio = require('minio')
2323

2424
var s3Client = new Minio.Client({
2525
endPoint: 's3.amazonaws.com',
26-
accessKey: 'YOUR-ACCESSKEYID',
27-
secretKey: 'YOUR-SECRETACCESSKEY'
26+
accessKey: 'YOUR-ACCESSKEYID',
27+
secretKey: 'YOUR-SECRETACCESSKEY'
2828
})
2929
```
30+
3031
| 操作存储桶 | 操作对象 | Presigned操作 | 存储桶策略/通知 |
3132
| ------------- |-------------| -----| ----- |
3233
| [`makeBucket`](#makeBucket) | [`getObject`](#getObject) | [`presignedUrl`](#presignedUrl) | [`getBucketNotification`](#getBucketNotification) |
@@ -64,7 +65,7 @@ __参数__
6465
|`transport` | _string_ |Set this value to pass in a custom transport. (Optional) - To be translated |
6566
|`sessionToken` | _string_ |Set this value to provide x-amz-security-token (AWS S3 specific). (Optional) - To be translated|
6667
|`partSize` | _number_ |Set this value to override default part size of 64MB for multipart uploads. (Optional) - To be translated|
67-
68+
| `pathStyle` | _bool_ | 对于非 AWS 的 Endpoint,设置该值以覆盖默认访问方式 (path)。默认值为 true。(可选) |
6869

6970
__示例__
7071

@@ -95,6 +96,20 @@ var s3Client = new Minio.Client({
9596
})
9697
```
9798

99+
## Ali OSS
100+
101+
```js
102+
var Minio = require('minio')
103+
104+
var s3Client = new Minio.Client({
105+
endPoint: 'oss-cn-hangzhou.aliyuncs.com',
106+
accessKey: 'YOUR-ACCESSKEYID',
107+
secretKey: 'YOUR-SECRETACCESSKEY',
108+
bucket: 'YOUR-BUCKET',
109+
pathStyle: false,
110+
region: 'oss-cn-hangzhou'
111+
})
112+
```
98113

99114
## 2. 操作存储桶
100115
<a name="makeBucket"></a>

‎src/main/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ export function isAmazonEndpoint(endpoint) {
9494
// style if the protocol is 'https:', this is due to SSL wildcard
9595
// limitation. For all other buckets and Amazon S3 endpoint we will
9696
// default to virtual host style.
97-
export function isVirtualHostStyle(endpoint, protocol, bucket) {
97+
export function isVirtualHostStyle(endpoint, protocol, bucket, pathStyle) {
9898
if (protocol === 'https:' && bucket.indexOf('.') > -1) {
9999
return false
100100
}
101-
return isAmazonEndpoint(endpoint)
101+
return isAmazonEndpoint(endpoint) || !pathStyle
102102
}
103103

104104
var ipv4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/

‎src/main/minio.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ export class Client {
123123
this.sessionToken = params.sessionToken
124124
this.userAgent = `${libraryAgent}`
125125

126+
// Default path style is true
127+
if (params.pathStyle === undefined) {
128+
this.pathStyle = true
129+
} else {
130+
this.pathStyle = params.pathStyle
131+
}
132+
126133
if (!this.accessKey) this.accessKey = ''
127134
if (!this.secretKey) this.secretKey = ''
128135
this.anonymous = !this.accessKey || !this.secretKey
@@ -178,9 +185,7 @@ export class Client {
178185
// Verify if virtual host supported.
179186
var virtualHostStyle
180187
if (bucketName) {
181-
virtualHostStyle = isVirtualHostStyle(this.host,
182-
this.protocol,
183-
bucketName)
188+
virtualHostStyle = isVirtualHostStyle(this.host, this.protocol, bucketName, this.pathStyle)
184189
}
185190

186191
if (this.port) reqOptions.port = this.port
@@ -489,7 +494,8 @@ export class Client {
489494
// the error XML also provides Region of the bucket. To validate
490495
// this region is proper we retry the same request with the newly
491496
// obtained region.
492-
var pathStyle = typeof window === 'undefined'
497+
var pathStyle = this.pathStyle && typeof window === 'undefined'
498+
493499
this.makeRequest({method, bucketName, query, pathStyle}, '', 200, 'us-east-1', true, (e, response) => {
494500
if (e) {
495501
if (e.name === 'AuthorizationHeaderMalformed') {

0 commit comments

Comments
 (0)
Please sign in to comment.