Skip to content

Commit ad5bfce

Browse files
committed
Add adapter for Backblaze B2
1 parent 01b7b1c commit ad5bfce

21 files changed

+365
-49
lines changed

.github/workflows/docs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Documentation
22

33
on:
44
push:
5+
branches:
6+
- main
57
paths:
68
- docs/**
79

@@ -35,11 +37,11 @@ jobs:
3537
npm install
3638
npm run build
3739
- name: Upload artifact
38-
uses: actions/upload-pages-artifact@v1
40+
uses: actions/upload-pages-artifact@v3
3941
with:
4042
path: 'docs/build'
4143
- name: Setup Pages
42-
uses: actions/configure-pages@v2
44+
uses: actions/configure-pages@v5
4345
deploy:
4446
environment:
4547
name: github-pages
@@ -49,4 +51,4 @@ jobs:
4951
steps:
5052
- name: Deploy to GitHub Pages
5153
id: deployment
52-
uses: actions/deploy-pages@v1
54+
uses: actions/deploy-pages@v4

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
rm -f .gitignore
8080
8181
- name: Archive Add-on
82-
uses: actions/upload-artifact@v2
82+
uses: actions/upload-artifact@v4
8383
with:
8484
name: cloud_files
8585
path: cloud_files

.github/workflows/tests.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
working-directory: ee/build-tools
5353
run: |
5454
content=`node -pe 'JSON.parse(process.argv[1]).tag' "$(cat build.json)"`
55-
echo "::set-output name=BUILD_VERSION::$content"
55+
echo "BUILD_VERSION=$content" >> $GITHUB_OUTPUT
5656
5757
- name: Run build process
5858
working-directory: ee/build-tools
@@ -98,7 +98,7 @@ jobs:
9898
strategy:
9999
fail-fast: false
100100
matrix:
101-
php: [7.4, 8.0, 8.1, 8.2]
101+
php: [7.4, 8.0, 8.1, 8.2, 8.3]
102102
os: [ubuntu-latest]
103103

104104
name: Cypress Tests, PHP${{ matrix.php }} - ${{ matrix.os }}
@@ -175,13 +175,12 @@ jobs:
175175
run: php tests/serve.php &
176176

177177
- name: Run Cypress Tests
178-
uses: cypress-io/github-action@v3
178+
uses: cypress-io/github-action@v6
179179
with:
180180
spec: cypress/integration/addon_cloud_files/**
181181
browser: chrome
182-
headless: true
183182
working-directory: tests/cypress
184-
config-file: cypress.json
183+
config-file: cypress.config.js
185184
env:
186185
CYPRESS_AWS_S3_KEY: ${{secrets.AWS_S3_KEY}}
187186
CYPRESS_AWS_S3_SECRET: ${{secrets.AWS_S3_SECRET}}
@@ -196,18 +195,22 @@ jobs:
196195
CYPRESS_CF_R2_SECRET: ${{secrets.CF_R2_SECRET}}
197196
CYPRESS_CF_R2_BUCKET: ${{secrets.CF_R2_BUCKET}}
198197
CYPRESS_CF_R2_URL: ${{secrets.CF_R2_URL}}
198+
CYPRESS_BB_B2_KEY: ${{secrets.BB_B2_KEY}}
199+
CYPRESS_BB_B2_SECRET: ${{secrets.BB_B2_SECRET}}
200+
CYPRESS_BB_B2_REGION: ${{secrets.BB_B2_REGION}}
201+
CYPRESS_BB_B2_BUCKET: ${{secrets.BB_B2_BUCKET}}
199202
CYPRESS_CF_TEST_FOLDER: ${{ matrix.php }}_${{ github.sha }}
200203
CYPRESS_KEEP_DEBUG: ${{vars.KEEP_DEBUG != 'false'}}
201204

202205
- name: Archive screenshots
203-
uses: actions/upload-artifact@v2
206+
uses: actions/upload-artifact@v4
204207
if: vars.KEEP_DEBUG != 'false' && failure()
205208
with:
206209
name: cypress-tests-PHP${{ matrix.php }}
207210
path: tests/cypress/cypress/screenshots/
208211

209212
- name: Archive server errors
210-
uses: actions/upload-artifact@v2
213+
uses: actions/upload-artifact@v4
211214
if: vars.KEEP_DEBUG != 'false' && failure()
212215
with:
213216
name: error.PHP${{ matrix.php }}.log

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
/vendor/
3-
/vendor-bin/*/vendor
3+
/vendor-bin/*/vendor
4+
node_modules/

Adapter/BackblazeB2.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
namespace CloudFiles\Adapter;
4+
5+
use ExpressionEngine\Dependency\Aws\S3\S3Client;
6+
use ExpressionEngine\Dependency\League\Flysystem;
7+
use ExpressionEngine\Library\Filesystem\Adapter\AdapterInterface;
8+
use ExpressionEngine\Library\Filesystem\Adapter\AdapterTrait;
9+
use ExpressionEngine\Service\Validation\ValidationAware;
10+
11+
class BackblazeB2 extends Flysystem\AwsS3v3\AwsS3Adapter implements AdapterInterface, ValidationAware
12+
{
13+
use AdapterTrait;
14+
15+
protected $_validation_rules = [
16+
'key' => 'required',
17+
'secret' => 'required',
18+
'region' => 'required',
19+
'bucket' => 'required',
20+
];
21+
22+
public function __construct($settings = [])
23+
{
24+
$this->settings = $settings;
25+
$client = new S3Client([
26+
'credentials' => [
27+
'key' => $settings['key'],
28+
'secret' => $settings['secret']
29+
],
30+
'region' => $settings['region'],
31+
'version' => 'latest',
32+
'endpoint' => "https://s3.{$settings['region']}.backblazeb2.com",
33+
'exception_class' => \ExpressionEngine\Dependency\Aws\S3\Exception\S3Exception::class
34+
]);
35+
36+
parent::__construct($client, $settings['bucket']);
37+
}
38+
39+
public static function getSettingsForm($settings)
40+
{
41+
return [
42+
[
43+
'title' => 'Application Key ID',
44+
'desc' => 'Enter your Backblaze B2 Key ID',
45+
'fields' => [
46+
'adapter_settings[key]' => [
47+
'type' => 'text',
48+
'value' => $settings['key'] ?? '',
49+
'required' => true
50+
]
51+
]
52+
],
53+
[
54+
'title' => 'Application Key',
55+
'desc' => 'Enter your Backblaze B2 Key',
56+
'fields' => [
57+
'adapter_settings[secret]' => [
58+
'type' => 'text',
59+
'value' => $settings['secret'] ?? '',
60+
'required' => true
61+
]
62+
]
63+
],
64+
[
65+
'title' => 'Region',
66+
'desc' => 'Enter the region for your Backblaze B2 Bucket',
67+
'fields' => [
68+
'adapter_settings[region]' => [
69+
'type' => 'text',
70+
'value' => $settings['region'] ?? '',
71+
'required' => true
72+
]
73+
]
74+
],
75+
[
76+
'title' => 'Bucket Name',
77+
'desc' => 'Enter the name of your Backblaze B2 Bucket',
78+
'fields' => [
79+
'adapter_settings[bucket]' => [
80+
'type' => 'text',
81+
'value' => $settings['bucket'] ?? '',
82+
'required' => true
83+
]
84+
]
85+
],
86+
[
87+
'title' => 'Path',
88+
'desc' => 'Enter the path inside your Backblaze B2 Bucket',
89+
'fields' => [
90+
'server_path' => [
91+
'type' => 'text',
92+
'value' => $settings['server_path'] ?? '',
93+
'required' => false
94+
]
95+
]
96+
],
97+
[
98+
'title' => 'Url',
99+
'desc' => 'Enter the url used to access your Backblaze B2 Bucket',
100+
'fields' => [
101+
'url' => [
102+
'type' => 'text',
103+
'value' => $settings['url'] ?? '',
104+
'required' => false
105+
]
106+
]
107+
]
108+
];
109+
}
110+
111+
public function getBaseUrl()
112+
{
113+
return implode('/', array_filter([
114+
'https://s3.'.$this->settings['region'].'.backblazeb2.com',
115+
$this->getBucket(),
116+
$this->getPathPrefix()
117+
]));
118+
}
119+
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Filesystem Adapter for integrating with Backblaze B2 service
8+
59
## [1.1.0] - 2023-07-28
610

711
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cloud Files
22

3-
For installation and usage please [read the documentation](docs/index.md)
3+
For installation and usage please [read the documentation](docs/docs/index.md)
44

55
## Contributing
66

addon.setup.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
'settings_exist' => false,
1313
'filesystem_adapters' => [
1414
\CloudFiles\Adapter\AwsS3::class,
15-
\CloudFiles\Adapter\DigitalOcean::class,
15+
\CloudFiles\Adapter\BackblazeB2::class,
1616
\CloudFiles\Adapter\CloudflareR2::class,
17+
\CloudFiles\Adapter\DigitalOcean::class,
1718
]
1819
);

docs/docs/adapter-bb-b2.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Backblaze B2 Adapter
2+
3+
## Step 1: Create a B2 Bucket
4+
5+
1. Log in to the Backblaze account.
6+
2. Select Create bucket.
7+
8+
![Create a new Bucket](./images/adapter-bb-step1-create.png "Create a new Bucket")
9+
10+
3. Enter a name for the bucket
11+
4. Make sure "Files in Bucket are:" is toggled to "Public"
12+
![New Bucket Details](./images/adapter-bb-step1-create-detail.png "New Bucket Details")
13+
5. Click Create a Bucket.
14+
6. Take note of the "Endpoint" and the region which is encoded like this `s3.{region}.backblazeb2.com`. Your region might look something like this: `us-east-001`
15+
16+
17+
## Step 2: Create an Application Key
18+
19+
1. Under B2 Cloud Storage click "Application Keys" in the sidebar.
20+
2. Now click "Add a New Application Key"
21+
3. Give this token a name to help you remember what it is used for and make sure to assign "Read and Write" permissions. You may also wish to restrict this key to the bucket you created in Step 1.
22+
![Create Application Key](./images/adapter-bb-step2-create-key.png "Create Application Key")
23+
4. Now you will see the credentials and be able to copy the "Key ID" and "Key" which will be necessary for configuring ExpressionEngine
24+
25+
26+
## Step 3: Configure ExpressionEngine
27+
28+
1. [Create a new Upload Directory](https://docs.expressionengine.com/v7/control-panel/file-manager/upload-directories.html#createedit-upload-directory)
29+
2. Enter a name and choose "Backblaze B2" for the **Adapter**
30+
3. Enter the "Application Key ID" from Step 2.4 into the **Key** field
31+
4. Enter the "Application Key" from Step 2.4 into the **Secret** field
32+
5. Enter the **Region** given to your bucket in Step 1.6
33+
6. Enter the **Bucket Name** which was chosen during Step 1.3
34+
7. Optionally you can specify a **Path** inside your bucket where the directory should store files and folders. Please note this path is only used for file storage and manipulation, you may need to add this path to your **Url** as well depending on your configuration.
35+
8. Optionally you can specify a **Url** to use as the base when generating links to files in the bucket. This can be useful for having a CDN handle requests to your files. (Cloud Files will auto-generate a "path-style" url from your bucket configuration but if you need or prefer a "virtual-hosted style" url you can enter that instead)
36+
9. Continue to configure the directory how you normally would and click "Save".
37+
38+
![Create Upload Directory](./images/adapter-bb-step3-configure-ee.png "Create Upload Directory")
188 KB
Loading

0 commit comments

Comments
 (0)