-
Notifications
You must be signed in to change notification settings - Fork 248
Adding identity samples #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
'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(); |
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(); |
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}'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Alternatively, you could introduce a set of three sample files on retrieving a user such as There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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:
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(); |
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); |
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); |
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}'); |
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()); | ||
} |
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(); |
There was a problem hiding this comment.
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 likegetenv('RS_IDENTITY_USER_NAME')
so the user needs only use one mechanism (environment variables) to pass in information needed to execute these scripts.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
samples/
directory) that would need updating,There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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{...}
).