diff --git a/README.md b/README.md index dee059b..a47ea0c 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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 diff --git a/action.yml b/action.yml index 545418c..309a2f9 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/dist/index.js b/dist/index.js index 620675e..640c0a7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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"), })) @@ -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, }) } diff --git a/src/index.js b/src/index.js index 3fbfc3d..e8363e5 100644 --- a/src/index.js +++ b/src/index.js @@ -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"), })) diff --git a/src/providers.js b/src/providers.js index 675968e..51ab06e 100644 --- a/src/providers.js +++ b/src/providers.js @@ -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, }) } diff --git a/src/test.js b/src/test.js index 860b968..33709b6 100644 --- a/src/test.js +++ b/src/test.js @@ -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"); +}