/** * Get missing fields. * * Not all containers come fully instantiated. This method is sometimes * called to "fill in" missing fields. * * @return \OpenStack\ObjectStore\v1\Resource\Container */ protected function loadExtraData() { // If URL and token are empty, we are dealing with a local item that // has not been saved, and was not created with Container::createContainer(). // We treat this as an error condition. if (empty($this->url) || empty($this->token)) { throw new Exception('Remote data cannot be fetched. A Token and endpoint URL are required.'); } // Do a GET on $url to fetch headers. $headers = ['X-Auth-Token' => $this->token]; $response = $this->client->get($this->url, ['headers' => $headers]); $headers = self::reformatHeaders($response->getHeaders()); // Get ACL. $this->acl = ACL::newFromHeaders($headers); // Update size and count. $this->bytes = $response->getHeader('X-Container-Bytes-Used', 0); $this->count = $response->getHeader('X-Container-Object-Count', 0); // Get metadata. $prefix = Container::CONTAINER_METADATA_HEADER_PREFIX; $this->setMetadata(Container::extractHeaderAttributes($headers, $prefix)); return $this; }
public function testNewFromHeaders() { $headers = [ACL::HEADER_READ => '.r:.example.com,.rlistings,.r:-*.evil.net', ACL::HEADER_WRITE => 'testact2, testact3:earnie, .rlistings ']; $acl = ACL::newFromHeaders($headers); $rules = $acl->rules(); $this->assertEquals(6, count($rules)); // Yay, now we get to test each one. $this->assertEquals(ACL::READ, $rules[0]['mask']); $this->assertEquals('.example.com', $rules[0]['host']); $this->assertTrue($rules[1]['rlistings']); $this->assertEquals('-*.evil.net', $rules[2]['host']); $this->assertEquals(ACL::WRITE, $rules[3]['mask']); $this->assertEquals('testact2', $rules[3]['account']); $this->assertEquals('testact3', $rules[4]['account']); $this->assertEquals('earnie', $rules[4]['user']); $this->assertTrue($rules[5]['rlistings']); // Final canary: $headers = $acl->headers(); $read = $headers[ACL::HEADER_READ]; $write = $headers[ACL::HEADER_WRITE]; $this->assertEquals('.r:.example.com,.rlistings,.r:-*.evil.net', $read); // Note that the spurious .rlistings was removed. $this->assertEquals('testact2,testact3:earnie', $write); }