2.8.0 • Published 3 years ago

swift v2.8.0

Weekly downloads
213
License
MIT
Repository
github
Last release
3 years ago

Openstack swift client API with ES7 async/await design.

Build Status NPM Version Coverage Status License Code style

Installation

$ 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

"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

"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

"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

2.8.0

3 years ago

2.7.3

3 years ago

3.1.3

4 years ago

2.7.2

4 years ago

3.1.1

4 years ago

2.7.1

4 years ago

2.7.0

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.6.2

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.3

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.4

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago

0.9.1

6 years ago

0.1.8

12 years ago

0.1.7

13 years ago

0.1.6

13 years ago

0.1.5

13 years ago

0.1.4

13 years ago

0.1.3

13 years ago

0.0.3

13 years ago

0.0.2

13 years ago

0.0.1

13 years ago