npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

client-swift-sda

v0.1.2

Published

A fork of matsune's official Object Storage OpenStack Swift client for Node.js

Downloads

8

Readme

Swift

Swift is a client library for connecting Object Storage OpenStack Swift, supporting all Identity API versions (v1.0, v2.0, v3).
This library is inspired by golang's swift client library ncw/swift.

Installation

$ npm install --save client-swift

Usage

let data =  {
  authUrl: "http://127.0.0.1/v3",
  userName: "admin",
  apiKey: "password",
  tenant: "admin",
  domain: "Default",
  tenantDomain: "Default"
}

// authenticate and create client instance
let client = await new Swift(data).authenticate()
// get containers list
let containers = await client.list()
// container instance
let container = client.Container(containers[0].name)
// get objects list
let objects = await container.list()
// object instance
let object = container.Object(objects[0].name)
// download file
let dst = fs.createWriteStream("a.txt")
object.write(dst)

Documentation

- Swift class

const Swift = require("client-swift")

let client = new Swift({
  authUrl: "http://127.0.0.1/v3",
  userName: "admin",
  apiKey: "password",
  tenant: "admin",
  domain: "Default",
  tenantDomain: "Default",
  endpointType: "public"
})

|key|Environment Variable| |---|---| |authUrl|$OS_AUTH_URL| |userName|$OS_USERNAME| |apiKey|$OS_PASSWORD| |userId|$OS_USER_ID| |domain|$OS_USER_DOMAIN_NAME| |domainId|$OS_USER_DOMAIN_ID| |tenant|$OS_TENANT_NAME (v2)| |tenant|$OS_PROJECT_NAME (v3)| |tenantId|$OS_TENANT_ID| |tenantDomain|$OS_PROJECT_DOMAIN_NAME| |tenantDomainId|$OS_PROJECT_DOMAIN_ID| |region|$OS_REGION_NAME (v2)| |trustId|$OS_TRUST_ID (v3)| |endpointType|$OS_ENDPOINT_TYPE|

Swift#authenticate()

let client = new Swift(data)
await client.authenticate()
//  or
//  let client = await new Swift(data).authenticate()

console.log(client.authenticated()) // `true` if success
// await client.unauthenticate()

Swift#list()

Get containers list

let containers = await client.list()
// containers
[
  { count: 1,
    last_modified: '2018-11-16T01:36:13.378500',
    bytes: 3,
    name: 'container1'
  },
  { count: 2,
    last_modified: '2018-11-17T08:01:24.877880',
    bytes: 25,
    name: 'container2'
  }
]

Swift#create(containerName, headers)

Create container

let container1 = await client.create("container1") // returns `SwiftContainer` instance

Swift#delete(containerName)

Delete container

await client.delete("container1")

Swift#metadata()

Get account metadata

let metadata = await client.metadata()
// metadata
{ 'content-length': '0',
  'x-account-object-count': '3',
  'x-account-storage-policy-policy-0-bytes-used': '28',
  'x-account-storage-policy-policy-0-container-count': '2',
  'x-timestamp': '1542330348.41749',
  ...

Swift#updateMetadata(headers)

Update account metadata

await client.updateMetadata({'X-Account-Meta-Subject': 'Literature'})

- SwiftContainer class

let container1 = client.Container("container1")

SwiftContainer#list()

Get objects list in container

let objects = await container1.list()
// objects
[
  { hash: 'd8198139ca62b0333ead15afbb50f99d',
    last_modified: '2018-11-17T08:51:34.103090',
    bytes: 22,
    name: 'a.txt',
    content_type: 'text/plain'
  },
  { hash: 'd41d8cd98f00b204e9800998ecf8427e',
    last_modified: '2018-11-17T08:51:34.160090',
    bytes: 30,
    name: 'b.txt',
    content_type: 'text/plain'
  }
]

SwiftContainer#create(objectName, stream)

Put object

const src = fs.createReadStream("src.txt", "utf8")
let object = await container1.create("dst.txt", src)
console.log(object); // `SwiftObject` instance

SwiftContainer#delete(objectName)

Delete object

await container1.delete("b.txt")

SwiftContainer#metadata()

let metadata = await container1.metadata()

SwiftContainer#updateMetadata()

await container1.updateMetadata({"X-Container-Meta-Century": "Nineteenth"})

- SwiftObject class

let object = container1.Object("sample.txt")

SwiftObject#write(stream)

let object = container1.Object("sample.txt")
let dstStream = fs.createWriteStream("a.txt")
object.write(dstStream)

SwiftObject#copy(dstContainer, dstObjectName, headers)

let object = client.Container("container1").Object("a.txt")
await object.copy("container2", "b.txt")

SwiftObject#metadata()

let metadata = await object.metadata()

SwiftObject#updateMetadata()

await object.updateMetadata({"X-Object-Meta-Book": "GoodbyeColumbus"})