Skip to content

Commit 062bf8b

Browse files
author
Jamie Hannaford
committed
Merge pull request rackspace#622 from rackspace/working
Move working commits into master
2 parents 46745a4 + d6b71fe commit 062bf8b

File tree

16 files changed

+315
-48
lines changed

16 files changed

+315
-48
lines changed

CODE_OF_CONDUCT.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project, and in the interest of
4+
fostering an open and welcoming community, we pledge to respect all people who
5+
contribute through reporting issues, posting feature requests, updating
6+
documentation, submitting pull requests or patches, and other activities.
7+
8+
We are committed to making participation in this project a harassment-free
9+
experience for everyone, regardless of level of experience, gender, gender
10+
identity and expression, sexual orientation, disability, personal appearance,
11+
body size, race, ethnicity, age, religion, or nationality.
12+
13+
Examples of unacceptable behavior by participants include:
14+
15+
* The use of sexualized language or imagery
16+
* Personal attacks
17+
* Trolling or insulting/derogatory comments
18+
* Public or private harassment
19+
* Publishing other's private information, such as physical or electronic
20+
addresses, without explicit permission
21+
* Other unethical or unprofessional conduct
22+
23+
Project maintainers have the right and responsibility to remove, edit, or
24+
reject comments, commits, code, wiki edits, issues, and other contributions
25+
that are not aligned to this Code of Conduct, or to ban temporarily or
26+
permanently any contributor for other behaviors that they deem inappropriate,
27+
threatening, offensive, or harmful.
28+
29+
By adopting this Code of Conduct, project maintainers commit themselves to
30+
fairly and consistently applying these principles to every aspect of managing
31+
this project. Project maintainers who do not follow or enforce the Code of
32+
Conduct may be permanently removed from the project team.
33+
34+
This Code of Conduct applies both within project spaces and in public spaces
35+
when an individual is representing the project or its community.
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
38+
reported by contacting a project maintainer at [email protected]. All
39+
complaints will be reviewed and investigated and will result in a response that
40+
is deemed necessary and appropriate to the circumstances. Maintainers are
41+
obligated to maintain confidentiality with regard to the reporter of an
42+
incident.
43+
44+
45+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
46+
version 1.3.0, available at
47+
[http://contributor-covenant.org/version/1/3/0/][version]
48+
49+
[homepage]: http://contributor-covenant.org
50+
[version]: http://contributor-covenant.org/version/1/3/0/

composer.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99
"name": "Jamie Hannaford",
1010
"email": "[email protected]",
1111
"homepage" : "https://github.com/jamiehannaford"
12-
},
13-
{
14-
"name": "Glen Campbell",
15-
"email": "[email protected]"
16-
},
17-
{
18-
"name": "Shaunak Kashyap",
19-
"email": "[email protected]",
20-
"homepage": "https://github.com/ycombinator"
2112
}
2213
],
2314
"autoload": {
2415
"psr-0": {
25-
"OpenCloud": ["lib/", "tests/"]
16+
"OpenCloud": ["lib/"]
17+
}
18+
},
19+
"autoload-dev": {
20+
"psr-0": {
21+
"OpenCloud": ["tests/"]
2622
}
2723
},
2824
"require": {

doc/services/object-store/access.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ To allow PUT access for 1 hour:
4949
`Get the executable PHP script for this example <https://raw.githubusercontent.com/rackspace/php-opencloud/master/samples/ObjectStore/create-object-temporary-url.php>`_
5050

5151

52+
Override TempURL file names
53+
---------------------------
54+
55+
Override tempURL file names simply by adding the filename parameter to the url:
56+
57+
.. code-block:: php
58+
59+
$tempUrl = $object->getTemporaryUrl(60, 'GET');
60+
$url = $tempUrl.'&filename='.$label;
61+
62+
5263
Hosting HTML sites on CDN
5364
=========================
5465

doc/services/object-store/objects.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,19 @@ filenames inside the archive.
495495

496496
`Get the executable PHP script for this example <https://raw.githubusercontent.com/rackspace/php-opencloud/master/samples/ObjectStore/auto-extract-archive-files.php>`_
497497

498-
499498
Delete object
500-
-------------
499+
---------------------------------
500+
501+
.. code-block:: php
502+
503+
$container->deleteObject('{objectName}');
504+
505+
506+
`Get the executable PHP script for this example <https://raw.githubusercontent.com/rackspace/php-opencloud/master/samples/ObjectStore/delete-object-without-download.php>`_
507+
508+
509+
Delete already downloaded object
510+
---------------------------------
501511

502512
.. code-block:: php
503513
@@ -518,3 +528,13 @@ Bulk delete a set of paths:
518528
$service->bulkDelete($pathsToBeDeleted);
519529
520530
`Get the executable PHP script for this example <https://raw.githubusercontent.com/rackspace/php-opencloud/master/samples/ObjectStore/bulk-delete.php>`_
531+
532+
Check an object exists
533+
----------------------
534+
535+
To check whether an object exists:
536+
537+
.. code-block:: php
538+
539+
/** @var bool $exists */
540+
$exists = $container->objectExists('{objectName}');

lib/OpenCloud/Common/Http/Client.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,13 @@
1919

2020
use Guzzle\Http\Client as GuzzleClient;
2121
use OpenCloud\Version;
22-
use OpenCloud\Common\Exceptions\UnsupportedVersionError;
2322

2423
/**
2524
* Base client object which handles HTTP transactions. Each service is based off of a Client which acts as a
2625
* centralized parent.
2726
*/
2827
class Client extends GuzzleClient
2928
{
30-
const MINIMUM_PHP_VERSION = '5.3.0';
31-
32-
public function __construct($baseUrl = '', $config = null)
33-
{
34-
// @codeCoverageIgnoreStart
35-
if (PHP_VERSION < self::MINIMUM_PHP_VERSION) {
36-
throw new UnsupportedVersionError(sprintf(
37-
'You must have PHP version >= %s installed.',
38-
self::MINIMUM_PHP_VERSION
39-
));
40-
}
41-
// @codeCoverageIgnoreEnd
42-
43-
parent::__construct($baseUrl, $config);
44-
}
45-
4629
public function getDefaultUserAgent()
4730
{
4831
return 'OpenCloud/' . Version::getVersion()

lib/OpenCloud/Compute/Resource/Server.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use OpenCloud\DNS\Resource\HasPtrRecordsInterface;
2222
use OpenCloud\Image\Resource\ImageInterface;
2323
use OpenCloud\Networking\Resource\NetworkInterface;
24+
use OpenCloud\Networking\Resource\SecurityGroup;
25+
use OpenCloud\Networking\Resource\Port;
2426
use OpenCloud\Volume\Resource\Volume;
2527
use OpenCloud\Common\Exceptions;
2628
use OpenCloud\Common\Http\Message\Formatter;
@@ -103,6 +105,12 @@ class Server extends NovaResource implements HasPtrRecordsInterface
103105
*/
104106
public $networks = array();
105107

108+
/**
109+
* Security groups for this server. An array of either the names or SecurityGroup objects.
110+
* @var (string|SecurityGroup)[]
111+
*/
112+
public $security_groups = array();
113+
106114
/**
107115
* @var string The server ID.
108116
*/
@@ -689,22 +697,39 @@ protected function createJson()
689697
$server->networks = array();
690698

691699
foreach ($this->networks as $network) {
692-
if (!$network instanceof NetworkInterface) {
700+
if ($network instanceof NetworkInterface) {
701+
$server->networks[] = (object) array('uuid' => $network->getId());
702+
} elseif ($network instanceof Port) {
703+
$server->networks[] = (object) array('port' => $network->getId());
704+
} else {
693705
throw new Exceptions\InvalidParameterError(sprintf(
694706
'When creating a server, the "networks" key must be an ' .
695-
'array of objects which implement OpenCloud\Networking\Resource\NetworkInterface;' .
696-
'variable passed in was a [%s]',
707+
'array of objects which implement either OpenCloud\Networking\Resource\NetworkInterface ' .
708+
'or OpenCloud\Networking\Resource\Port. The variable you passed in was a [%s]',
697709
gettype($network)
698710
));
699711
}
700-
if (!($networkId = $network->getId())) {
701-
$this->getLogger()->warning('When creating a server, the '
702-
. 'network objects passed in must have an ID'
703-
);
704-
continue;
712+
}
713+
}
714+
715+
// Security groups
716+
if (is_array($this->security_groups) && count($this->security_groups)) {
717+
$server->security_groups = array();
718+
719+
foreach ($this->security_groups as $security_group) {
720+
if ($security_group instanceof SecurityGroup) {
721+
$securityGroupName = $security_group->name();
722+
} elseif (is_string($security_group)) {
723+
$securityGroupName = $security_group;
724+
} else {
725+
throw new Exceptions\InvalidParameterError(sprintf(
726+
'When creating a server, the "security_groups" key must be an ' .
727+
'array of strings or objects of type OpenCloud\Networking\Resource\SecurityGroup;' .
728+
'variable passed in was a [%s]',
729+
gettype($security_group)
730+
));
705731
}
706-
// Stock networks array
707-
$server->networks[] = (object) array('uuid' => $networkId);
732+
$server->security_groups[] = (object) array('name' => $securityGroupName);
708733
}
709734
}
710735

lib/OpenCloud/Compute/Resource/ServerMetadata.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ private function getMetadataJson()
179179
if ($name = $this->key) {
180180
$object->meta->$name = $this->$name;
181181
} else {
182-
$object->metadata = new \stdClass();
183-
foreach ($this->keylist() as $key) {
184-
$object->metadata->$key = (string) $this->$key;
185-
}
182+
$object->metadata = $this->keylist();
186183
}
187184

188185
$json = json_encode($object);

lib/OpenCloud/LoadBalancer/Resource/LoadBalancer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,20 @@ public function addNodes()
255255
);
256256
}
257257

258-
$requests = array();
258+
$requestData = array('nodes' => array());
259259

260+
/** @var Node $node */
260261
foreach ($this->nodes as $node) {
261262
// Only add the node if it is new
262263
if (null === $node->getId()) {
263-
$json = json_encode($node->createJson());
264-
$requests[] = $this->getClient()->post($node->getUrl(), self::getJsonHeader(), $json);
264+
$nodeJson = $node->createJson();
265+
$requestData['nodes'][] = $nodeJson['nodes'][0];
265266
}
266267
}
267268

268-
return $this->getClient()->send($requests);
269+
$request = $this->getClient()->post($node->getUrl(), self::getJsonHeader(), json_encode($requestData));
270+
271+
return $this->getClient()->send($request);
269272
}
270273

271274
/**

lib/OpenCloud/ObjectStore/Resource/Container.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,19 @@ public function deleteAllObjects()
235235
return $this->getService()->batchDelete($paths);
236236
}
237237

238+
/**
239+
* Delete an object from the API.
240+
*
241+
* @param string $name The name of object you want to delete
242+
* @throws \Guzzle\Http\Exception\BadResponseException When an error occurred
243+
*/
244+
public function deleteObject($name)
245+
{
246+
$this->getClient()
247+
->delete($this->getUrl($name))
248+
->send();
249+
}
250+
238251
/**
239252
* Creates a Collection of objects in the container
240253
*

lib/OpenCloud/ObjectStore/Resource/DataObject.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,11 @@ public function getTemporaryUrl($expires, $method, $forcePublicUrl = false)
481481
}
482482
// @codeCoverageIgnoreEnd
483483

484-
$url = ($forcePublicUrl === true) ? $this->getService()->getEndpoint()->getPublicUrl() : $this->getUrl();
484+
$url = $this->getUrl();
485+
if ($forcePublicUrl === true) {
486+
$url->setHost($this->getService()->getEndpoint()->getPublicUrl()->getHost());
487+
}
488+
485489
$urlPath = urldecode($url->getPath());
486490
$body = sprintf("%s\n%d\n%s", $method, $expiry, $urlPath);
487491
$hash = hash_hmac('sha1', $body, $secret);

lib/OpenCloud/ObjectStore/Service.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public function listContainers(array $filter = array())
9292
*/
9393
public function getContainer($data = null)
9494
{
95+
if (is_string($data) || is_numeric($data)) {
96+
$this->checkContainerName($data);
97+
}
98+
9599
return new Container($this, $data);
96100
}
97101

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright 2012-2014 Rackspace US, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
require dirname(__DIR__) . '/../vendor/autoload.php';
19+
20+
use OpenCloud\Rackspace;
21+
22+
// 1. Instantiate a Rackspace client. You can replace {authUrl} with
23+
// Rackspace::US_IDENTITY_ENDPOINT or similar
24+
$client = new Rackspace('{authUrl}', array(
25+
'username' => '{username}',
26+
'apiKey' => '{apiKey}',
27+
));
28+
29+
// 2. Obtain an Object Store service object from the client.
30+
$objectStoreService = $client->objectStoreService(null, '{region}');
31+
32+
// 3. Get container.
33+
$container = $objectStoreService->getContainer('{containerName}');
34+
35+
// 4. Delete object.
36+
$container->deleteObject('{objectName}');

0 commit comments

Comments
 (0)