https://github.com/131/swift
Openstack swift API
https://github.com/131/swift
Last synced: about 1 year ago
JSON representation
Openstack swift API
- Host: GitHub
- URL: https://github.com/131/swift
- Owner: 131
- License: other
- Created: 2018-09-26T20:21:40.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-15T16:09:13.000Z (almost 5 years ago)
- Last Synced: 2025-05-14T08:49:40.888Z (about 1 year ago)
- Language: JavaScript
- Size: 48.8 KB
- Stars: 4
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Openstack *swift* client API with ES7 async/await design.
[](https://github.com/131/swift/actions/workflows/test.yml)
[](https://www.npmjs.org/package/swift)
[](https://coveralls.io/r/131/swift?branch=master)
[](http://opensource.org/licenses/MIT)
[](https://www.npmjs.com/package/eslint-plugin-ivs)
# Installation
```bash
$ npm install swift
```
# API/services (auth3)
Auth3 API will login to your openstack and use a X-Auth-Token in all operations.
Make sure to renew (setInterval) the auth token periodicaly.
## credentials
```js
"use strict";
module.exports = {
authUrl : "https://auth.cloud.ovh.net/v3", // default
username : "OpenstackUsername", // required
password : "OpenstackPassword", // required
tenantId : "OpenstackProjectId", // one of tenantId or tenantName is required
tenantName : "OpenstackProjectName", // one of tenantId or tenantName is required
region: "WAW", // default "GRA3"
};
```
## object-store
```js
"use strict";
const fs = require('fs');
const Context = require('swift/context');
const storage = require('swift/storage');
const pipe = require('nyks/stream/pipe');
const creds = require('./credentials');
class foo {
async run(){
// init token
let container = 'mediaprivate';
var ctx = await Context.build(creds);
var files = await storage.toggleMode(ctx, container, ".r:*,.rlistings");
var headers = await storage.showContainer(ctx, container);
var remote = await storage.putFile(ctx, 'boucs.jpg', container, 'bouc.jpg');
var local = fs.createWriteStream('tmp.jpg');
var remote = storage.download(ctx, container, 'bouc.jpg');
await pipe(remote, local);
var remote = await storage.deleteFile(ctx, container, 'bouc.jpg');
var files = await storage.getFileList(ctx, container);
console.log({files, remote});
}
}
module.exports = foo;
```
# API/services (meta-temp-url-key)
Using a container meta-temp key, you can upload, retrieve or delete specific files in your container.
On a CAS designed container, this should be considered as a best practice against a full container access.
## object-store
```js
"use strict";
const fs = require('fs');
const Context = require('swift/context');
const storage = require('swift/storage');
const pipe = require('nyks/stream/pipe');
const creds = {
"containers" : {
"mediaprivate" : {
"endpoint" : "https://someopenstackswifthost/v1/AUTH_PROJECTID/mediaprivate",
"temp-url-key" : "somesecret",
}
}
};
class foo {
async run(){
let container = 'mediaprivate';
// does not init token, as no username is provided
var ctx = await Context.build(creds);
//please note that container level API won't work
//var files = await storage.toggleMode(ctx, container, ".r:*,.rlistings");
//var headers = await storage.showContainer(ctx, container);
var remote = await storage.putFile(ctx, 'boucs.jpg', container, 'bouc.jpg');
var local = fs.createWriteStream('tmp.jpg');
//download through tempURL
var remote = storage.download(ctx, container, 'bouc.jpg');
await pipe(remote, local);
var remote = await storage.deleteFile(ctx, container, 'bouc.jpg');
var files = await storage.getFileList(ctx, container);
console.log({files, remote});
}
}
module.exports = foo;
```
# Credits
* [131](https://github.com/131)