Ejemplo n.º 1
0
 public function testIsPublic()
 {
     $acl = new ACL();
     $this->assertFalse($acl->isPublic());
     $acl->allowListings();
     $acl->addReferrer(ACL::READ, '*');
     $this->assertTrue($acl->isPublic());
     $acl->addAccount(ACL::WRITE, 'foo', 'bar');
     $this->assertTrue($acl->isPublic());
     $acl = ACL::makePublic();
     $this->assertTrue($acl->isPublic());
 }
Ejemplo n.º 2
0
 /**
  * @group public
  */
 public function testAcl()
 {
     $store = $this->objectStore();
     $cname = self::$settings['hpcloud.swift.container'] . 'PUBLIC';
     if ($store->hasContainer($cname)) {
         $store->deleteContainer($cname);
     }
     $store->createContainer($cname, ACL::makePublic());
     $store->containers();
     $container = $store->container($cname);
     $acl = $container->acl();
     $this->assertInstanceOf('\\HPCloud\\Storage\\ObjectStorage\\ACL', $acl);
     $this->assertTrue($acl->isPublic());
     $store->deleteContainer($cname);
 }
Ejemplo n.º 3
0
 /**
  * Create a container with the given name.
  *
  * This creates a new container on the ObjectStorage
  * server with the name provided in $name.
  *
  * A boolean is returned when the operation did not generate an error
  * condition.
  *
  * - TRUE means that the container was created.
  * - FALSE means that the container was not created because it already
  * exists.
  *
  * Any actual error will cause an exception to be thrown. These will
  * be the HTTP-level exceptions.
  *
  * ACLs
  *
  * Swift supports an ACL stream that allows for specifying (with
  * certain caveats) various levels of read and write access. However,
  * there are two standard settings that cover the vast majority of
  * cases.
  *
  * - Make the resource private: This grants read and write access to
  *   ONLY the creating account. This is the default; it can also be
  *   specified with ACL::makeNonPublic().
  * - Make the resource public: This grants READ permission to any
  *   requesting host, yet only allows the creator to WRITE to the
  *   object. This level can be granted by ACL::makePublic().
  *
  * Note that ACLs operate at a container level. Thus, marking a
  * container public will allow access to ALL objects inside of the
  * container.
  *
  * To find out whether an existing container is public, you can
  * write something like this:
  *
  * @code
  * <?php
  * // Get the container.
  * $container = $objectStorage->container('my_container');
  *
  * //Check the permission on the ACL:
  * $boolean = $container->acl()->isPublic();
  * ?>
  * @endcode
  *
  * For details on ACLs, see HPCloud::Storage::ObjectStorage::ACL.
  *
  * @param string $name
  *   The name of the container.
  * @param object $acl HPCloud::Storage::ObjectStorage::ACL
  *   An access control list object. By default, a container is
  *   non-public (private). To change this behavior, you can add a
  *   custom ACL. To make the container publically readable, you can
  *   use this: HPCloud::Storage::ObjectStorage::ACL::makePublic().
  * @param array $metadata
  *   An associative array of metadata to attach to the container.
  * @retval boolean
  * @return boolean
  *   TRUE if the container was created, FALSE if the container was not
  *   created because it already exists.
  */
 public function createContainer($name, ACL $acl = NULL, $metadata = array())
 {
     $url = $this->url() . '/' . rawurlencode($name);
     $headers = array('X-Auth-Token' => $this->token());
     if (!empty($metadata)) {
         $prefix = Container::CONTAINER_METADATA_HEADER_PREFIX;
         $headers += Container::generateMetadataHeaders($metadata, $prefix);
     }
     $client = \HPCloud\Transport::instance();
     // Add ACLs to header.
     if (!empty($acl)) {
         $headers += $acl->headers();
     }
     $data = $client->doRequest($url, 'PUT', $headers);
     //syslog(LOG_WARNING, print_r($data, TRUE));
     $status = $data->status();
     if ($status == 201) {
         return TRUE;
     } elseif ($status == 202) {
         return FALSE;
     } else {
         throw new \HPCloud\Exception('Server returned unexpected code: ' . $status);
     }
 }
Ejemplo n.º 4
0
 /**
  * @depends testCreateContainerPublic
  */
 public function testChangeContainerACL()
 {
     $testCollection = self::$settings['hpcloud.swift.container'] . 'PUBLIC';
     $store = $this->objectStore();
     if ($store->hasContainer($testCollection)) {
         $store->deleteContainer($testCollection);
     }
     $ret = $store->createContainer($testCollection);
     $acl = \HPCloud\Storage\ObjectStorage\ACL::makePublic();
     $ret = $store->changeContainerACL($testCollection, $acl);
     $this->assertFalse($ret);
     $container = $store->container($testCollection);
     $url = $container->url() . '?format=xml';
     $data = file_get_contents($url);
     $this->assertNotEmpty($data, $url);
     $store->deleteContainer($testCollection);
 }