Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ branches:
before_script:
- composer install --prefer-source
- vendor/bin/parallel-lint --exclude vendor .
- vendor/bin/php-cs-fixer fix --dry-run --level psr2 .
- vendor/bin/php-cs-fixer fix --dry-run --diff --level psr2 .

after_script:
- php vendor/bin/coveralls -v
Expand Down
41 changes: 41 additions & 0 deletions samples/Identity/add_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;

// You can replace {authUrl} with Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// Set up Identity service
$service = $client->identityService();

// Create user
$user = $service->createUser(array(
'username' => '{username}', // replace username
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'{username}' should be replaced by something like getenv('RS_IDENTITY_USER_NAME') so the user needs only use one mechanism (environment variables) to pass in information needed to execute these scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not a big fan of asking users to set a whole bunch of environment variables. For me, that's more work than tweaking an inline variable. Plus on DRC we use inline placeholders rather than env vars, so there's added inconsistency if we do something different.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with using inline placeholders instead of environment variables but three considerations come to mind:

  1. There are several existing samples (in the samples/ directory) that would need updating,
  2. I would rather go inline placeholders all the way than having some values specified via environment variables and others via inline placeholdes,
  3. Will inline placeholders work for @maxlinc's scripts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'm fine with that. That's a good point about @maxlinc's scripts, though - I'll ping Max and ask what his requirements are to make it work. If inline placeholders are fine, I'll go ahead and change all the other samples and submit in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If inline placeholders are fine, I'll go ahead and change all the other samples and submit in another PR.

@jamiehannaford I've created #467 to track progress with changing all the other code samples so we are out of our current inconsistent state (some samples use getenv(...) while others use {...}).

'email' => '{email}', // replace email address
'enabled' => true,
));

// If you do not provide a "password" key in the createUser operation, the API
// will automatically generate you one. If that's the case, you will need to
// retrieve the new password and save it somewhere.
echo $user->getPassword();
32 changes: 32 additions & 0 deletions samples/Identity/authenticate_token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;

// You can replace {authUrl} with Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// Authenticate with the above credentials
$client->authenticate();

// Retrieve token ID
echo $client->getToken();
36 changes: 36 additions & 0 deletions samples/Identity/delete_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;
use OpenCloud\Identity\Constants\User as UserConst;

// You can replace {authUrl} with Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// Set up Identity service
$service = $client->identityService();

// Retrieve existing user
$user = $service->getUser('{username}');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of these samples is to let a user of the SDK download any of them and execute them with the least amount of work. To that end, I would split off each of these three cases (either by username, ID or email) into their own sample files such as delete_user_using_username.php, delete_user_using_id.php, and delete_user_using_email.php.

Alternatively, you could introduce a set of three sample files on retrieving a user such as get_user_using_username.php, get_user_using_id.php, and get_user_using_email.php showing the three methods to retrieve a user. Then in this sample file (delete_user.php), just use one of those three methods, as you have done in reset_api_key.php.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a separate file for retrieving a user by ID? IMHO it's a fairly simple edit that's documented with comments... I don't think users will be confused by this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original goal, when I first started adding these samples, was to make it dead simple for the user to run any of these samples. Specifically, I have been creating these samples such that the user has to perform the least number of changes possible to run them.

Lets consider this sample in it's current form (i.e. one sample showing all three methods of retrieving a user). It would take a user 3 edits to run it with, say, username:

  1. replace {username} with the desired value, and
  2. comment out the line using {userId}, and
  3. comment out the line using {email}.

Contrast that with providing three distinct sample files. It would take the user only one edit to make one of those files (say the one that uses username) run:

  1. replace {username} with the desired value

I know that sounds like a small delta but I think we should do whatever we can so the user doesn't have to. Also, what is the downside of having multiple files?

Another benefit I've found to having multiple sample files is that I can usually link to one of them without providing any additional explanation, when a user requires support for a particular use case of execution path for a service.


// And delete them...
$user->delete();
33 changes: 33 additions & 0 deletions samples/Identity/get_user_by_email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;
use OpenCloud\Identity\Constants\User as UserConst;

// You can replace {authUrl} with Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// Set up Identity service
$service = $client->identityService();

// Retrieve existing user
$user = $service->getUser('{email}', UserConst::MODE_EMAIL);
33 changes: 33 additions & 0 deletions samples/Identity/get_user_by_id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;
use OpenCloud\Identity\Constants\User as UserConst;

// You can replace {authUrl} with Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// Set up Identity service
$service = $client->identityService();

// Retrieve existing user
$user = $service->getUser('{userId}', UserConst::MODE_ID);
33 changes: 33 additions & 0 deletions samples/Identity/get_user_by_name.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;
use OpenCloud\Identity\Constants\User as UserConst;

// You can replace {authUrl} with Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// Set up Identity service
$service = $client->identityService();

// Retrieve existing user
$user = $service->getUser('{username}');
38 changes: 38 additions & 0 deletions samples/Identity/list_users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;
use OpenCloud\Identity\Constants\User as UserConst;

// You can replace {authUrl} with Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// Set up Identity service
$service = $client->identityService();

// Get a collection of users
$users = $service->getUsers();

// Traverse the collection
foreach ($users as $user) {
printf("User ID: %s, Name: %s\n", $user->getId(), $user->getUsername());
}
39 changes: 39 additions & 0 deletions samples/Identity/reset_api_key.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;
use OpenCloud\Identity\Constants\User as UserConst;

// You can replace {authUrl} with Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// Set up Identity service
$service = $client->identityService();

// Get user by their ID
$user = $service->getUser('{userId}');

// Reset
$user->resetApiKey();

// Show the new API key
echo $user->getApiKey();