get ( $credential_name )

Retrieves the requested credentials from the internal credential store.

Access

public static

Parameters

Parameter

Type

Required

Description

$credential_name

Optional

Returns

Type

Description

stdClass

A stdClass object where the properties represent the keys that were provided.

Examples

Set the credential sets that should be available to the application, and read back the values.

// Dependencies
require_once dirname(__FILE__) . '/../../sdk.class.php';
require_once dirname(__FILE__) . '/../testutil.inc.php';

/**
 * Create a group of credential sets. This would normally go inside the config.inc.php file.
 *
 * Each credential set is assigned a name. Any name that PHP allows as an array key may be used.
 * `@inherit` is a keyword that will tell the class to use the inherited credential set as a base,
 * then apply changes on top of it. The "default" credential set can be its own credential set,
 * or can reference another credential set by name.
 */
CFCredentials::set(array(

	// Credentials for the production environment
	'production' => array(
		'key' => 'production-key',
		'secret' => 'production-secret',
		'cache' => 'apc',
		'something_else' => 'abc123',
		'aardvark' => 'applesauce'
	),

	// Credentials for the staging environment. Inherits from "production".
	'staging' => array(
		'@inherit' => 'production',
		'key' => 'staging-key',
		'secret' => 'staging-secret',
	),

	// Credentials for the development environment. Inherits from "staging", and in-turn, "production".
	'development' => array(
		'@inherit' => 'staging',
		'key' => 'development-key',
		'secret' => 'development-secret',
	),

	// Any name can be used for a credential set.
	'my-own-personal-credential-set' => array(
		'@inherit' => 'staging'
	),

	// Set a default credential set for ambiguous cases.
	'@default' => 'development'
));

/**
 * Requesting data back from the credential sets.
 */
echo CFCredentials::get('production')->key . PHP_EOL;
echo CFCredentials::get('production')->aardvark . PHP_EOL;

echo PHP_EOL;

echo CFCredentials::get('staging')->key . PHP_EOL;
echo CFCredentials::get('staging')->aardvark . PHP_EOL;

echo PHP_EOL;

echo CFCredentials::get('development')->key . PHP_EOL;
echo CFCredentials::get('development')->aardvark . PHP_EOL;

echo PHP_EOL;

echo CFCredentials::get('my-own-personal-credential-set')->key . PHP_EOL;

echo PHP_EOL;

echo CFCredentials::get()->key . PHP_EOL;
Result:
production-key
applesauce

staging-key
applesauce

development-key
applesauce

staging-key

development-key

Source

Method defined in utilities/credentials.class.php | Toggle source view (11 lines) | View on GitHub

public static function get($credential_name = self::DEFAULT_KEY)
{
    // Make sure the credential set exists
    if (!isset(self::$credentials[$credential_name]))
    {
        throw new CFCredentials_Exception('The credential set, "' . $credential_name . '", does not exist and cannot be retrieved.');
    }

    // Return the credential set as an object
    return new CFCredential(self::$credentials[$credential_name]);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback