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

feat: bucket controller #33

Draft
wants to merge 18 commits into
base: 2-dev
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ Then in your `kuzzlerc` file, you can change the following configuration variabl
}
}
```
If needed, you can override `bucketName` by adding `bucketName` arg to the request:
```javascript
{
// Kuzzle API params
"controller": "s3/file",
"action": "getFilesKeys",
"bucketName": "your-other-bucket-name"
}
```

In addition to Amazon aws s3, this plugin allows you to use any S3-Api compatible service accesible
through the [AWS-S3 sdk](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html).
Expand All @@ -237,6 +246,7 @@ can be added to the `s3ClientOptions` configuration attribute.
Please note that the parameters are translated directly,
so refer to the sdk documentation to available options.


### AWS S3 Bucket

First you must configure your bucket to allow public access to uploaded files.
Expand Down
3 changes: 2 additions & 1 deletion config/kuzzlerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"bucketName": "your-s3-bucket",
"endpoint": "https://s3.eu-west-3.amazonaws.com",
"s3ClientOptions": {
"s3ForcePathStyle": false
"s3ForcePathStyle": false,
"region" : "eu-west-3"
},
"signedUrlTTL": "20min",
"redisPrefix": "s3Plugin/uploads",
Expand Down
90 changes: 90 additions & 0 deletions doc/2/controllers/bucket/create/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
code: true
type: page
title: create
---

# create

Creates a S3 bucket

## Query Syntax

### HTTP

```http
URL: http://kuzzle:7512/_plugin/s3/bucket/:bucketName/:bucketRegion
Method: POST
Body:
```

```js
{
"bucketOptions":{ <OptionsList> },
"bucketPolicy":{ <PolicyList> },
"bucketCORS":{ <CORS> }
"disableDotsInName":"false"
}
```

### Other protocols

```js
{
"controller": "s3",
"action": "create",
"bucketName": "<bucketname>",
"bucketRegion": "<bucketRegion>",
"body": {
"bucketOptions": { <OptionsList> },
"bucketPolicy":{ <PolicyList> },
"bucketCORS":{ <CORS> }
"disableDotsInName": false
}
}
```

## Arguments

- `bucketName`: the name of the bucket, bucket will need to follow the [AWS Bucket Name Guidelines](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).
- `bucketRegion` (optional): the region where you want to create the bucket, see [AWS Documentation](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html) for available regions. Otherwise it will default to the region configured globally.
- `bucketOptions` (optional): Specify options like a custom ACL, otherwise it will default to :

```js
{
ACL: 'public-read'
}
```

- `bucketPolicy` (optional): Specify a custom policy for your bucket.
- `bucketCORS` (optional): Specify a custom CORS policy to add to your bucket, otherwise it will default to :

```js
{
AllowedHeaders: ['*'],
AllowedMethods: ['GET', 'POST', 'PUT'],
AllowedOrigins: ['*'],
}
```

- `disableDotsInName` (optional): changes the name checks on the `bucketName` variable to check for dots, which would prevent [S3 Transfer Acceleration](https://aws.amazon.com/fr/s3/transfer-acceleration/) from working.

## Response

Returns an object with the following properties:

```js
{
"status": 200,
"error": null,
"action": "create",
"controller": "s3/bucket",
"result": {
"bucketName: "<bucketname>",
"bucketRegion":"<bucketregion>",
"bucketOptions": { <OptionsList> },
"bucketPolicy":{ <PolicyList> },
"bucketCORS": { <CORS> }
}
}
```
50 changes: 50 additions & 0 deletions doc/2/controllers/bucket/delete/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
code: true
type: page
title: create
---

# delete

Deletes an existing empty S3 bucket

## Query Syntax

### HTTP

```http
URL: http://kuzzle:7512/_plugin/s3/bucket/<bucketName>/<bucketRegion>
Method: DELETE
```

### Other protocols

```js
{
"controller": "s3",
"action": "delete",
"bucketName": "mybucket"
"bucketRegion": "eu-west-3"
}
```

## Arguments

- `bucketName`: the name of the bucket to delete
- `bucketRegion`: the AWS region where the bucket is located

## Response

Returns an object with the following properties:

```js
{
"status": 200,
"error": null,
"action": "delete",
"controller": "s3/bucket",
"result": {
"result": "ok"
}
}
```
50 changes: 50 additions & 0 deletions doc/2/controllers/bucket/exists/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
code: true
type: page
title: exists
---

# exists

Check if a S3 bucket exists.

## Query Syntax

### HTTP

```http
URL: http://kuzzle:7512/_plugin/s3/bucket/exists/<bucketName>
Method: GET
```

### Other protocols

```js
{
"controller": "s3",
"action": "exists",
"bucketName": "mybucket",
"bucketRegion": "eu-east-1"
}
```

## Arguments

- `bucketName`: the name of the bucket to delete
- `bucketRegion`: the AWS region where the bucket is located

## Response

Returns an object with the following properties:

```js
{
"status": 200,
"error": null,
"action": "exists",
"controller": "s3/bucket",
"result": {
"result": "true"
}
}
```
5 changes: 5 additions & 0 deletions doc/2/controllers/bucket/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
code: true
type: branch
title: file
---
2 changes: 1 addition & 1 deletion doc/2/controllers/file/delete/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Method: DELETE
## Arguments

- `fileKey`: [file key](https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-keys) in S3 bucket

- `bucketName` : Override config bucketName
---

## Response
Expand Down
9 changes: 7 additions & 2 deletions doc/2/controllers/file/get-url/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Method: GET
{
"controller": "s3/file",
"action": "getUrl",

"bucketName":"<bucketname>",
"bucketRegion":"<bucketregion>",
"signedUrl":"true"
"fileKey": "xen/<uuid>-headcrab.png"
}
```
Expand All @@ -35,7 +37,10 @@ Method: GET
## Arguments

- `fileKey`: [file key](https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-keys) in S3 bucket

- `bucketName` (optional): the name of the bucket
- `bucketRegion` (optional): the region where the specified bucket is located,
- `signedUrl` (optional): flag to use a signed url,

---

## Response
Expand Down
2 changes: 1 addition & 1 deletion doc/2/controllers/file/getFilesKeys/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Method: GET

## Arguments

None
- `bucketName` : Override config bucketName

---

Expand Down
2 changes: 1 addition & 1 deletion doc/2/controllers/upload/get-url/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Method: GET

- `filename`: Uploaded file name
- `uploadDir`: Upload directory (see [s3 file key](https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-keys))

- `bucketName` : Override config bucketName
---

## Response
Expand Down
2 changes: 1 addition & 1 deletion doc/2/controllers/upload/validate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Method: PUT
## Arguments

- `fileKey`: [file key](https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-keys) in S3 bucket

- `bucketName` : [string] Override config bucketName
---

## Response
Expand Down
Loading
Loading