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(provider): Cloudflare R2 #9

Merged
merged 2 commits into from
May 18, 2023
Merged
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ Currently the below providers are supported, but it could be used with other pro
- Linode
- DigitalOcean
- Scaleway
- Cloudflare

## Inputs

### `provider`

**Not Required** The s3 provider to use. Defaults to Linode. AWS, Linode, DigitalOcean, Scaleway are supported.
**Not Required** The s3 provider to use. Defaults to Linode. AWS, Linode, DigitalOcean, Scaleway, Cloudflare are supported.

### `secret_key`

Expand All @@ -29,6 +30,10 @@ Currently the below providers are supported, but it could be used with other pro

**Not Required** The default region to use. The default depends on the provider.

### `account_id`

**Not Required** Cloudflare account ID. Only required when using Cloudflare R2.

## Example usage

```yml
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
region:
description: "s3 region (default region depends on the provider)"
required: false
account_id:
description: "account id (only used with Cloudflare R2)"
required: false
access_key:
description: "s3 access key"
required: true
Expand Down
9 changes: 9 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ execSync("/bin/bash -c 'pip3 install s3cmd --no-cache'")

const conf = makeConf(providers[core.getInput('provider')]({
region: core.getInput("region"),
account_id: core.getInput("account_id"),
access_key: core.getInput("access_key"),
secret_key: core.getInput("secret_key"),
}))
Expand Down Expand Up @@ -461,6 +462,14 @@ const providers = {
website_endpoint: `https://%(bucket)s.s3-website.${region}.scw.cloud/`,
access_key,
secret_key,
}),
cloudflare: ({ account_id = '', region='auto', access_key = '', secret_key = '' }) => ({
bucket_location: region,
host_base: `${account_id}.r2.cloudflarestorage.com`,
host_bucket: '',
website_endpoint: '',
access_key,
secret_key,
})
}

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ execSync("/bin/bash -c 'pip3 install s3cmd --no-cache'")

const conf = makeConf(providers[core.getInput('provider')]({
region: core.getInput("region"),
account_id: core.getInput("account_id"),
access_key: core.getInput("access_key"),
secret_key: core.getInput("secret_key"),
}))
Expand Down
8 changes: 8 additions & 0 deletions src/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const providers = {
website_endpoint: `https://%(bucket)s.s3-website.${region}.scw.cloud/`,
access_key,
secret_key,
}),
cloudflare: ({ account_id = '', region='auto', access_key = '', secret_key = '' }) => ({
bucket_location: region,
host_base: `${account_id}.r2.cloudflarestorage.com`,
host_bucket: '',
website_endpoint: '',
access_key,
secret_key,
})
}

Expand Down
14 changes: 14 additions & 0 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ const digitaloceanWriter = createWriteStream('assets/test-results/digitalocean')
for (const line of digitaloceanConf) {
digitaloceanWriter.write(line + '\r\n')
}

const cloudflareConf = makeConf(
providers.cloudflare({
account_id: "123abc",
access_key: "top-secret",
secret_key: "more secret",
})
);

const cloudflareWriter = createWriteStream("assets/test-results/cloudflare");

for (const line of cloudflareConf) {
cloudflareWriter.write(line + "\r\n");
}