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

Add Ceph RGW S3 compatibility. #21

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/aws.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/aws.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/kms.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/kms.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/s3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/s3.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/secrets-manager.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/secrets-manager.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/ssm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/ssm.min.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/internal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class AWSClient {
* the specific AWS service the child class implements the functionalities of.
*/
public get host() {
if (this._host == undefined) {
if (this.awsConfig.forcePathStyle) {
return this.awsConfig.endpoint
} else if (this._host == undefined) {
return `${this.serviceName}.${this.awsConfig.region}.${this.awsConfig.endpoint}`
}
return this._host
Expand Down
18 changes: 18 additions & 0 deletions src/internal/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export class AWSConfig {
*/
endpoint: string = 'amazonaws.com'

/**
* Path-style bucket.
*
* @type {boolean}
*/
forcePathStyle: boolean = false

/**
* Create an AWSConfig.
*
Expand Down Expand Up @@ -98,6 +105,10 @@ export class AWSConfig {
if (options.endpoint !== undefined) {
this.endpoint = options.endpoint
}

if (options.forcePathStyle !== undefined) {
this.forcePathStyle = options.forcePathStyle
}
}
}

Expand Down Expand Up @@ -146,6 +157,13 @@ export interface AWSConfigOptions {
* @type {string}
*/
endpoint?: string

/**
* Path-Style bucket.
*
* @type {boolean}
*/
forcePathStyle?: boolean
}

/** Class representing an invalid AWS configuration */
Expand Down
62 changes: 47 additions & 15 deletions src/internal/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class S3Client extends AWSClient {
service: this.serviceName,
region: this.awsConfig.region,
credentials: {
accessKeyId: this.awsConfig.accessKeyID,
accessKeyId: this.awsConfig.accessKeyId,
secretAccessKey: this.awsConfig.secretAccessKey,
sessionToken: this.awsConfig.sessionToken,
},
Expand All @@ -47,8 +47,8 @@ export class S3Client extends AWSClient {

const signedRequest: SignedHTTPRequest = this.signature.sign(
{
method: 'GET',
protocol: 'https',
method: method,
protocol: this.awsConfig.scheme,
hostname: this.host,
path: '/',
headers: {},
Expand Down Expand Up @@ -101,14 +101,22 @@ export class S3Client extends AWSClient {
listObjects(bucketName: string, prefix?: string): Array<S3Object> {
// Prepare request
const method = 'GET'
const host = `${bucketName}.${this.host}`
let host
let path
if (this.awsConfig.forcePathStyle) {
host = `${this.host}`
path = `/${bucketName}/`
} else {
host = `${bucketName}.${this.host}`
path = `/`
}

const signedRequest: SignedHTTPRequest = this.signature.sign(
{
method: 'GET',
protocol: 'https',
protocol: this.awsConfig.scheme,
hostname: host,
path: '/',
path: path,
query: {
'list-type': '2',
prefix: prefix || '',
Expand Down Expand Up @@ -170,14 +178,22 @@ export class S3Client extends AWSClient {
getObject(bucketName: string, objectKey: string): S3Object {
// Prepare request
const method = 'GET'
const host = `${bucketName}.${this.host}`
let host
let path
if (this.awsConfig.forcePathStyle) {
host = `${this.host}`
path = `/${bucketName}/${objectKey}`
} else {
host = `${bucketName}.${this.host}`
path = `/${objectKey}`
}

const signedRequest = this.signature.sign(
{
method: 'GET',
protocol: 'https',
protocol: this.awsConfig.scheme,
hostname: host,
path: `/${objectKey}`,
path: path,
headers: {},
},
{}
Expand Down Expand Up @@ -215,14 +231,22 @@ export class S3Client extends AWSClient {
putObject(bucketName: string, objectKey: string, data: string | ArrayBuffer) {
// Prepare request
const method = 'PUT'
const host = `${bucketName}.${this.host}`
let host
let path
if (this.awsConfig.forcePathStyle) {
host = `${this.host}`
path = `/${bucketName}/${objectKey}`
} else {
host = `${bucketName}.${this.host}`
path = `/${objectKey}`
}

const signedRequest = this.signature.sign(
{
method: method,
protocol: 'https',
protocol: this.awsConfig.scheme,
hostname: host,
path: `/${objectKey}`,
path: path,
headers: {},
body: data,
},
Expand All @@ -247,14 +271,22 @@ export class S3Client extends AWSClient {
deleteObject(bucketName: string, objectKey: string): void {
// Prepare request
const method = 'DELETE'
const host = `${bucketName}.${this.host}`
let host
let path
if (this.awsConfig.forcePathStyle) {
host = `${this.host}`
path = `/${bucketName}/${objectKey}`
} else {
host = `${bucketName}.${this.host}`
path = `/${objectKey}`
}

const signedRequest = this.signature.sign(
{
method: method,
protocol: 'https',
protocol: this.awsConfig.scheme,
hostname: host,
path: `/${objectKey}`,
path: path,
headers: {},
},
{}
Expand Down