HPCloud-JS

API Docs for: 1.0.0
Show:

ACL Class

Module: hpcloud

Construct a new ACL.

By default, an ACL is set to "private."

EXPERIMENTAL: This is bassed on a feature of Swift that is likely to change. Most of this is based on undocmented features of the API discovered both in the Python docs and in discussions by various members of the OpenStack community.

Swift access control rules are broken into two permissions: READ and WRITE. Read permissions grant the user the ability to access the file (using verbs like GET and HEAD), while WRITE permissions allow any modification operation. WRITE does not imply READ.

In the current implementation of Swift, access can be assigned based on two different factors:

  • Accounts: Access can be granted to specific accounts, and within those accounts, can be further specified to specific users. See the addAccount() method for details on this.
  • Referrers: Access can be granted based on host names or host name patterns. For example, only subdomains of *.example.com may be granted READ access to a particular object.

ACLs are transmitted within the HTTP headers for an object or container. Two headers are used: X-Container-Read for READ rules, and X-Container-Write for WRITE rules. Each header may have a chain of rules.

For a detailed description of the rules for ACL creation, see http://swift.openstack.org/misc.html#acls

Constructor

ACL

()

Methods

addAccount

(
  • perm
  • account
  • user
)

Grant ACL access to an account.

Optionally, a user may be given to further limit access.

This is used to restrict access to a particular account and, if so specified, a specific user on that account.

If just an account is given, any user on that account will be automatically granted access.

If an account and a user is given, only that user of the account is granted access.

If $user is an array, every user in the array will be granted access under the provided account. That is, for each user in the array, an entry of the form \c account:user will be generated in the final ACL.

At this time there does not seem to be a way to grant global write access to an object.

Parameters:

  • perm Number

    ACL.READ, ACL.WRITE or ACL.READ_WRITE

  • account String

    The name of the account.

  • user String | Array

    The name of the user, or optionally an indexed array of user names.

addReferrer

(
  • perm
  • host
)
ACL chainable

Allow (or deny) a hostname or host pattern.

In current Swift implementations, only READ rules can have host patterns. WRITE permissions cannot be granted to hostnames.

Formats: - Allow any host: '*' - Allow exact host: 'www.example.com' - Allow hosts in domain: '.example.com' - Disallow exact host: '-www.example.com' - Disallow hosts in domain: '-.example.com'

Note that a simple minus sign ('-') is illegal, though it seems it should be "disallow all hosts."

Parameters:

  • perm Object

    The permission. One of ACL.READ, ACL.WRITE, ACL.READ_WRITE.

  • host String

    A host string, as described above.

Returns:

ACL: this

addRule

(
  • perm
  • rule
)
ACL chainable

Add a rule to the rule set.

This adds a rule with the given permission to the rule set.

Parameters:

  • perm Object

    A permission object.

  • rule Object

    A rule.

Returns:

ACL: this

allowListings

() ACL chainable

Allow hosts with READ permissions to list a container's content.

By default, granting READ permission on a container does not grant permission to list the contents of a container. Setting the ACL.allowListings() permission will allow matching hosts to also list the contents of a container.

In the current Swift implementation, there is no mechanism for allowing some hosts to get listings, while denying others.

Returns:

ACL: this

headers

() Array

Transform the rule set into HTTP headers.

Returns:

Array: headers.

isPrivate

() Boolean

Check if the ACL marks this private.

This returns TRUE only if this ACL does not grant any permissions at all.

Returns:

Boolean: TRUE if this is private (non-public), FALSE if any permissions are granted via this ACL.

isPublic

() Boolean

Check whether this object allows public reading.

This will return TRUE the ACL allows (a) any host to access the item, and (b) it allows container listings.

This checks whether the object allows public reading, not whether it is ONLY allowing public reads.

See ACL.makePublic().

Returns:

Boolean: TRUE if the ACL allows (a) any host to access the item, and (b) it allows container listings.

makePrivate

() ACL static

A factory to create an ACL object with private permissions

Returns:

ACL: An ACL object configured with private access.

makePublic

() ACL static

A factory to create an ACL object with public permissions.

Returns:

ACL: An ACL object configured with public access.

newFromHeaders

(
  • headers
)
ACL static

Build a new ACL object from a header array.

This will scan headers for expected rules, and parse out the results. If no headers are found, the returned ACL will be private.

Parameters:

  • headers Array

    The headers array.

Returns:

ACL: The ACL object.

parseRule

(
  • perm
  • rule
)
Object static

Parse an ACL rule into a rule object.

Parameters:

  • perm Number

    One of ACL.READ or ACL.WRITE.

  • rule String

    A string representation of a rule.

Returns:

Object: A rule object.

rules

() Array

Get the rules set.

Returns:

Array: An array of rule objects.

ruleToString

(
  • perm
  • rule
)
String

Convert a rule to a string.

Parameters:

  • perm Number

    The permission type (ACL.WRITE, ACL.READ).

  • rule Object

    The rule object.

Returns:

String: A rule as a string.

toString

() String

Convert the ACL (headers) to a string. This is useful for debugging.

Returns:

String: The ACL as a string

Properties

HEADER_READ

String

Header for read permissions.

HEADER_WRITE

String

Header for write permissions.

READ

Number

Read flag.

READ_WRITE

Number

Read/write flag (shorthand for READ | WRITE).

WRITE

Number

Write flag.