Skip to content

Commit 16da348

Browse files
committed
fix: various issues in OBS connection
1 parent fd46a4b commit 16da348

40 files changed

+2824
-6524
lines changed

README.md

Lines changed: 151 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This package now supports multiple versions of both Flysystem and Guzzle:
2727

2828
-**Complete Flysystem v3 Compatibility**: Full implementation of all required and optional Flysystem methods
2929
-**Laravel Integration**: Seamless integration with Laravel's Storage facade
30-
-**Huawei OBS SDK Integration**: Uses the official `obs/esdk-obs-php` SDK
30+
-**Huawei OBS SDK Integration**: Uses `mubbi/esdk-obs-php` (Huawei OBS SDK compatible fork)
3131
-**Temporary Credentials**: Support for session tokens (`securityToken`)
3232
-**Signed URLs**: Generate pre-signed URLs for temporary object access
3333
-**Public URLs**: Generate public URLs for objects with public read access
@@ -93,19 +93,46 @@ composer require mubbi/laravel-flysystem-huawei-obs
9393
2. Publish the configuration (optional):
9494

9595
```bash
96-
php artisan vendor:publish --provider="LaravelFlysystemHuaweiObs\HuaweiObsServiceProvider"
96+
php artisan vendor:publish --provider="LaravelFlysystemHuaweiObs\HuaweiObsServiceProvider" --tag=huawei-obs-config
9797
```
9898

9999
3. Add your Huawei OBS credentials to your `.env` file:
100100

101101
```env
102+
# Required Configuration
102103
HUAWEI_OBS_ACCESS_KEY_ID=your_access_key_id
103104
HUAWEI_OBS_SECRET_ACCESS_KEY=your_secret_access_key
104105
HUAWEI_OBS_BUCKET=your_bucket_name
105106
HUAWEI_OBS_ENDPOINT=https://obs.cn-north-1.myhuaweicloud.com
106-
HUAWEI_OBS_REGION=cn-north-1
107+
108+
# Optional Configuration
107109
HUAWEI_OBS_PREFIX=optional_prefix
108110
HUAWEI_OBS_SECURITY_TOKEN=your_security_token_for_temporary_credentials
111+
112+
# Advanced OBSClient Configuration
113+
HUAWEI_OBS_SIGNATURE=v4
114+
HUAWEI_OBS_PATH_STYLE=false
115+
HUAWEI_OBS_REGION=cn-north-1
116+
HUAWEI_OBS_SSL_CERTIFICATE_AUTHORITY=
117+
HUAWEI_OBS_MAX_RETRY_COUNT=3
118+
HUAWEI_OBS_SOCKET_TIMEOUT=60
119+
HUAWEI_OBS_CHUNK_SIZE=8192
120+
HUAWEI_OBS_EXCEPTION_RESPONSE_MODE=exception
121+
HUAWEI_OBS_IS_CNAME=false
122+
123+
# HTTP Client Configuration
124+
HUAWEI_OBS_TIMEOUT=120
125+
HUAWEI_OBS_CONNECT_TIMEOUT=30
126+
HUAWEI_OBS_VERIFY_SSL=true
127+
128+
# Retry Configuration
129+
HUAWEI_OBS_RETRY_ATTEMPTS=3
130+
HUAWEI_OBS_RETRY_DELAY=1
131+
132+
# Logging Configuration
133+
HUAWEI_OBS_LOGGING_ENABLED=false
134+
HUAWEI_OBS_LOG_OPERATIONS=false
135+
HUAWEI_OBS_LOG_ERRORS=true
109136
```
110137

111138
4. Configure your filesystem in `config/filesystems.php`:
@@ -114,27 +141,52 @@ HUAWEI_OBS_SECURITY_TOKEN=your_security_token_for_temporary_credentials
114141
'disks' => [
115142
'huawei-obs' => [
116143
'driver' => 'huawei-obs',
144+
145+
// Required Configuration
117146
'key' => env('HUAWEI_OBS_ACCESS_KEY_ID'),
118147
'secret' => env('HUAWEI_OBS_SECRET_ACCESS_KEY'),
119148
'bucket' => env('HUAWEI_OBS_BUCKET'),
120149
'endpoint' => env('HUAWEI_OBS_ENDPOINT'),
121-
'region' => env('HUAWEI_OBS_REGION'),
150+
151+
// Optional Configuration
122152
'prefix' => env('HUAWEI_OBS_PREFIX'),
123153
'security_token' => env('HUAWEI_OBS_SECURITY_TOKEN'),
124-
'visibility' => 'private',
125-
'throw' => false,
154+
155+
// Advanced OBSClient Configuration
156+
'signature' => env('HUAWEI_OBS_SIGNATURE', 'v4'),
157+
'path_style' => env('HUAWEI_OBS_PATH_STYLE', false),
158+
'region' => env('HUAWEI_OBS_REGION'),
159+
'ssl_verify' => env('HUAWEI_OBS_VERIFY_SSL', true),
160+
'ssl.certificate_authority' => env('HUAWEI_OBS_SSL_CERTIFICATE_AUTHORITY'),
161+
'max_retry_count' => env('HUAWEI_OBS_MAX_RETRY_COUNT', 3),
162+
'timeout' => env('HUAWEI_OBS_TIMEOUT', 120),
163+
'socket_timeout' => env('HUAWEI_OBS_SOCKET_TIMEOUT', 60),
164+
'connect_timeout' => env('HUAWEI_OBS_CONNECT_TIMEOUT', 30),
165+
'chunk_size' => env('HUAWEI_OBS_CHUNK_SIZE', 8192),
166+
'exception_response_mode' => env('HUAWEI_OBS_EXCEPTION_RESPONSE_MODE', 'exception'),
167+
'is_cname' => env('HUAWEI_OBS_IS_CNAME', false),
168+
169+
// HTTP Client Configuration
126170
'http_client' => [
127-
'timeout' => 30,
128-
'connect_timeout' => 10,
129-
'verify' => true,
171+
'timeout' => env('HUAWEI_OBS_TIMEOUT', 120),
172+
'connect_timeout' => env('HUAWEI_OBS_CONNECT_TIMEOUT', 30),
173+
'verify' => env('HUAWEI_OBS_VERIFY_SSL', true),
130174
'proxy' => null,
131175
'headers' => [],
132176
],
133-
'retry_attempts' => 3,
134-
'retry_delay' => 1,
135-
'logging_enabled' => false,
136-
'log_operations' => false,
137-
'log_errors' => true,
177+
178+
// Retry Configuration
179+
'retry_attempts' => env('HUAWEI_OBS_RETRY_ATTEMPTS', 3),
180+
'retry_delay' => env('HUAWEI_OBS_RETRY_DELAY', 1),
181+
182+
// Logging Configuration
183+
'logging_enabled' => env('HUAWEI_OBS_LOGGING_ENABLED', false),
184+
'log_operations' => env('HUAWEI_OBS_LOG_OPERATIONS', false),
185+
'log_errors' => env('HUAWEI_OBS_LOG_ERRORS', true),
186+
187+
// Flysystem Configuration
188+
'visibility' => 'private',
189+
'throw' => false,
138190
],
139191
],
140192
```
@@ -169,23 +221,89 @@ $tempUrl = Storage::disk('huawei-obs')->temporaryUrl('file.txt', now()->addHour(
169221

170222
### Direct Adapter Usage
171223

172-
You can also use the adapter directly:
224+
You can also use the adapter directly (Flysystem v3 interface):
173225

174226
```php
175-
use LaravelFlysystemHuaweiObs\HuaweiObsAdapter;
176-
177-
$adapter = new HuaweiObsAdapter(
178-
'your_access_key_id',
179-
'your_secret_access_key',
180-
'your_bucket_name',
181-
'https://obs.cn-north-1.myhuaweicloud.com'
227+
use LaravelFlysystemHuaweiObs\LaravelHuaweiObsAdapter;
228+
use League\Flysystem\Filesystem;
229+
use League\Flysystem\Config;
230+
231+
$adapter = new LaravelHuaweiObsAdapter(
232+
env('HUAWEI_OBS_ACCESS_KEY_ID'),
233+
env('HUAWEI_OBS_SECRET_ACCESS_KEY'),
234+
env('HUAWEI_OBS_BUCKET'),
235+
env('HUAWEI_OBS_ENDPOINT'),
236+
env('HUAWEI_OBS_PREFIX'),
182237
);
183238

184-
// Use Flysystem methods directly
185-
$adapter->write('file.txt', 'Hello World', new \League\Flysystem\Config());
186-
$contents = $adapter->read('file.txt');
239+
$filesystem = new Filesystem($adapter);
240+
241+
$filesystem->write('file.txt', 'Hello World', new Config());
242+
$contents = $filesystem->read('file.txt');
187243
```
188244

245+
## Configuration Options
246+
247+
### Required Configuration
248+
249+
These options are required for the adapter to function:
250+
251+
- `key` - Your Huawei OBS Access Key ID
252+
- `secret` - Your Huawei OBS Secret Access Key
253+
- `bucket` - The OBS bucket name
254+
- `endpoint` - The OBS endpoint URL (e.g., `https://obs.cn-north-1.myhuaweicloud.com`)
255+
256+
### Optional Configuration
257+
258+
- `prefix` - Optional path prefix for all operations
259+
- `security_token` - Security token for temporary credentials
260+
261+
### Advanced OBSClient Configuration
262+
263+
The adapter supports all OBSClient configuration options:
264+
265+
- `signature` - Signature version (`v2`, `v4`, `obs`) - Default: `v4`
266+
- `path_style` - Use path-style URLs instead of virtual-hosted-style - Default: `false`
267+
- `region` - OBS region (e.g., `cn-north-1`) - Optional
268+
- `ssl_verify` - Enable/disable SSL certificate verification - Default: `true`
269+
- `ssl.certificate_authority` - Path to custom CA certificate bundle - Optional
270+
- `max_retry_count` - Maximum number of retry attempts - Default: `3`
271+
- `timeout` - Request timeout in seconds - Default: `120`
272+
- `socket_timeout` - Socket timeout in seconds - Default: `60`
273+
- `connect_timeout` - Connection timeout in seconds - Default: `30`
274+
- `chunk_size` - Chunk size for multipart uploads in bytes - Default: `8192`
275+
- `exception_response_mode` - Exception response mode (`exception`, `response`) - Default: `exception`
276+
- `is_cname` - Whether the endpoint is a CNAME - Default: `false`
277+
278+
### HTTP Client Configuration
279+
280+
- `http_client.timeout` - Request timeout in seconds - Default: `120`
281+
- `http_client.connect_timeout` - Connection timeout in seconds - Default: `30`
282+
- `http_client.verify` - SSL certificate verification - Default: `true`
283+
- `http_client.proxy` - HTTP proxy configuration - Optional
284+
- `http_client.headers` - Additional HTTP headers - Optional
285+
286+
### Retry Configuration
287+
288+
- `retry_attempts` - Number of retry attempts for transient errors - Default: `3`
289+
- `retry_delay` - Base delay between retries in seconds - Default: `1`
290+
291+
### Logging Configuration
292+
293+
- `logging_enabled` - Enable/disable logging - Default: `false`
294+
- `log_operations` - Log successful operations - Default: `false`
295+
- `log_errors` - Log errors - Default: `true`
296+
297+
### Examples
298+
299+
See the `examples/` directory for concise, copy-pasteable snippets:
300+
301+
- `examples/usage.php`: basic write/read with Flysystem
302+
- `examples/url-usage.php`: URL and temporary URL usage
303+
- `examples/advanced-usage.php`: signed URLs, post signatures, tags, restore, optimized listing
304+
- `examples/controller-compatibility.php`: controller-style listing example
305+
- `examples/laravel-compatibility-demo.php`: Storage facade compatibility helpers
306+
189307
## Advanced Features
190308

191309
### Optimized Methods for Large Datasets
@@ -387,7 +505,7 @@ $adapter->refreshCredentials('new_access_key', 'new_secret_key', 'new_security_t
387505

388506
### URL Handling
389507

390-
The adapter supports both public URLs and signed URLs, with full Laravel compatibility:
508+
The adapter supports both public URLs and signed URLs. For Laravel's `Storage` facade:
391509

392510
#### Public and Private URLs
393511

@@ -477,17 +595,16 @@ Storage::disk('huawei-obs')->restoreObject('archived-file.txt', 7);
477595

478596
### Artisan Command
479597

480-
The package includes an Artisan command for testing connectivity:
598+
The package includes an Artisan command for testing connectivity and features:
481599

482600
```bash
483601
php artisan huawei-obs:test
484602
```
485603

486604
This command will:
487-
- Test authentication with your configured credentials
488-
- Verify bucket access
489-
- Test basic file operations
490-
- Display detailed results
605+
- Validate credentials and bucket access
606+
- Test reads/writes, signed URLs, post signatures, and tagging
607+
- Output a concise pass/fail report
491608

492609
### Manual Testing
493610

@@ -538,7 +655,7 @@ try {
538655

539656
### Custom Exceptions
540657

541-
The package provides specific exceptions for different error types:
658+
The package provides specific exceptions for different error types used by advanced features:
542659

543660
```php
544661
use LaravelFlysystemHuaweiObs\Exceptions\UnableToCreateSignedUrl;
@@ -641,7 +758,8 @@ Contributions are welcome! Please feel free to submit a Pull Request. For major
641758
1. Clone the repository
642759
2. Install dependencies: `composer install`
643760
3. Run tests: `composer test`
644-
4. Run code quality checks: `composer check`
761+
4. Static analysis: `composer phpstan`
762+
5. Lint/format: `composer pint`
645763

646764
### Code Quality
647765

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
3131
"phpunit/phpunit": "^9.0|^10.0",
3232
"phpstan/phpstan": "^1.10",
33+
"phpstan/phpstan-mockery": "^1.1",
34+
"phpstan/phpstan-phpunit": "^1.4",
3335
"laravel/pint": "^1.0",
3436
"mockery/mockery": "^1.6",
3537
"fakerphp/faker": "^1.23"

config/filesystems.php

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)