Skip to content

Commit

Permalink
Fix swift client + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steevepay committed Jul 26, 2023
1 parent e948f61 commit 0657e8d
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 156 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### v2.2.5
- SWIFT updated:
- The authentication object does not require the `tenantName` attribute anymore, it is now optional.
- `swift.uploadFile`: The 3rd argument accepts a function returning a ReadStream, in addition to the Buffer and the absolute path of the file
- Updated dev npm packages:
- `eslint` to `8.45.0`
- `nock` to `=13.3.2`

### v2.2.4
- Patched `s3.deleteFiles`: the XML body includes object names without encoding. Previously, objects with special character was encoded (encodeURIComponent), and S3 did not delete them.

Expand Down
26 changes: 17 additions & 9 deletions USAGE-SWIFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ Initialise the SDK with one or multiple storage, if something goes wrong, the ne
const storageClient = require('tiny-storage-client');
let storage = storageClient([{
authUrl : 'https://auth.cloud.ovh.net/v3',
username : 'username-1',
password : 'password-1',
tenantName : 'tenantName-1',
region : 'region-1'
authUrl : 'https://auth.cloud.ovh.net/v3', // REQUIRED
username : 'username-1', // REQUIRED
password : 'password-1', // REQUIRED
region : 'region-1', // REQUIRED
tenantName : 'tenantName-1' // OPTIONAL
},
{
authUrl : 'https://auth.cloud.ovh.net/v3',
username : 'username-2',
password : 'password-2',
tenantName : 'tenantName-2',
region : 'region-2'
region : 'region-2',
tenantName : 'tenantName-2'
}]);
storage.connection((err) => {
Expand All @@ -111,15 +111,23 @@ storage.uploadFile('container', 'filename.jpg', path.join(__dirname, './assets/f
// success
});
/** SOLUTION 2: A buffer can be passed for the file content **/
/** SOLUTION 2: A Buffer can be passed for the file content **/
storage.uploadFile('container', 'filename.jpg', Buffer.from("File content"), (err) => {
if (err) {
// handle error
}
// success
});
/** SOLUTION 3: the function accepts a optionnal fourth argument `option` including query parameters and headers. List of query parameters and headers: https://docs.openstack.org/api-ref/object-store/?expanded=create-or-replace-object-detail#create-or-replace-object **/
/** SOLUTION 3: Pass a function returning a ReadStream **/
storage.uploadFile('container', 'filename.jpg', () => fs.createReadStream(path.join(__dirname, './assets/file.txt')), (err) => {
if (err) {
// handle error
}
// success
});
/** SOLUTION 4: the function accepts a optionnal fourth argument `option` including query parameters and headers. List of query parameters and headers: https://docs.openstack.org/api-ref/object-store/?expanded=create-or-replace-object-detail#create-or-replace-object **/
storage.uploadFile('container', 'filename.jpg', Buffer.from("File content"), { queries: { temp_url_expires: '1440619048' }, headers: { 'X-Object-Meta-LocationOrigin': 'Paris/France' }}, (err) => {
if (err) {
// handle error
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = (config) => {
const _auth = Array.isArray(config) && config.length > 0 ? config[0] : config;
if (_auth?.accessKeyId && _auth?.secretAccessKey && _auth?.url && _auth?.region) {
return s3(config);
} else if (_auth?.username && _auth?.password && _auth?.authUrl && _auth?.tenantName && _auth?.region) {
} else if (_auth?.username && _auth?.password && _auth?.authUrl && _auth?.region) {
return swift(config);
} else {
throw new Error("Storage connexion not recognised - did you provide correct credentials for a S3 or Swift storage?")
Expand Down
Loading

0 comments on commit 0657e8d

Please sign in to comment.