Esempio n. 1
0
$key = $argv[2 + $offset];
$uri = $argv[3 + $offset];
$tenantId = NULL;
if (!empty($argv[4 + $offset])) {
    $tenantId = $argv[4 + $offset];
}
/*
$store = ObjectStorage::newFromSwiftAuth($user, $key, $uri);

$token = $store->token();
*/
$cs = new IdentityServices($uri);
if ($asUser) {
    $token = $cs->authenticateAsUser($user, $key, $tenantId);
} else {
    $token = $cs->authenticateAsAccount($user, $key, $tenantId);
}
if (empty($token)) {
    print "Authentication seemed to succeed, but no token was returned." . PHP_EOL;
    exit(1);
}
$t = "You are logged in as %s with token %s (good until %s)." . PHP_EOL;
$tokenDetails = $cs->tokenDetails();
$user = $cs->user();
printf($t, $user['name'], $cs->token(), $tokenDetails['expires']);
print "The following services are available on this account:" . PHP_EOL;
$services = $cs->serviceCatalog();
foreach ($services as $service) {
    print "\t" . $service['name'] . PHP_EOL;
}
//print_r($services);
 /**
  * @group tenant
  * @depends testTenants
  */
 function testRescopeByTenantName()
 {
     $service = new IdentityServices(self::conf('hpcloud.identity.url'));
     $user = self::conf('hpcloud.identity.username');
     $pass = self::conf('hpcloud.identity.password');
     $tenantName = self::conf('hpcloud.identity.tenantName');
     // Authenticate without a tenant ID.
     $token = $service->authenticateAsUser($user, $pass);
     $this->assertNotEmpty($token);
     $details = $service->tokenDetails();
     $this->assertFalse(isset($details['tenant']));
     $service->rescopeUsingTenantName($tenantName);
     $details = $service->tokenDetails();
     $this->assertEquals($tenantName, $details['tenant']['name']);
     $catalog = $service->serviceCatalog();
     $this->assertGreaterThan(1, count($catalog));
     // Test unscoping
     $service->rescope('');
     $details = $service->tokenDetails();
     $this->assertFalse(isset($details['tenant']));
     $catalog = $service->serviceCatalog();
 }
Esempio n. 3
0
<?php

require_once __DIR__ . '/../src/HPCloud/Bootstrap.php';
use HPCloud\Bootstrap;
use HPCloud\Services\IdentityServices;
use HPCloud\Storage\ObjectStorage;
use HPCloud\Storage\ObjectStorage\Object;
Bootstrap::useAutoloader();
// Load these from an ini file.
$ini = parse_ini_file(getenv('HOME') . '/.hpcloud.ini');
$username = $ini['username'];
$password = $ini['password'];
$tenantId = $ini['tenantId'];
$endpoint = $ini['url'];
$idService = new IdentityServices($endpoint);
$token = $idService->authenticateAsAccount($username, $password, $tenantId);
$catalog = $idService->serviceCatalog();
$store = ObjectStorage::newFromServiceCatalog($catalog, $token);
$store->createContainer('Example');
$container = $store->container('Example');
$name = 'hello.txt';
$content = 'Hello World';
$mime = 'text/plain';
$localObject = new Object($name, $content, $mime);
$container->save($localObject);
$object = $container->object('hello.txt');
printf("Name: %s \n", $object->name());
printf("Size: %d \n", $object->contentLength());
printf("Type: %s \n", $object->contentType());
print $object->content() . PHP_EOL;