Skip to content

Instantly share code, notes, and snippets.

@maximevalette
Last active June 28, 2022 11:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maximevalette/0958ad9fd2ff1c2747731459ec34ba8c to your computer and use it in GitHub Desktop.
Save maximevalette/0958ad9fd2ff1c2747731459ec34ba8c to your computer and use it in GitHub Desktop.
Sample PHP script to use Keystone v3 with OVH credentials (username + password)

OVH + PHP + Keystone v3

Install PHP OpenCloud

composer require php-opencloud/openstack ^3.0

Sample token authentication with OVH credentials

<?php

require 'vendor/autoload.php';

// Don't forget the trailing slash
$client = new \GuzzleHttp\Client(['base_uri' => 'https://auth.cloud.ovh.net/v3/']);

$token = new \OpenStack\Identity\v3\Models\Token($client, new \OpenStack\Identity\v3\Api());

$token->create([
  'user' => [
    'name' => 'USERNAME',
    'domain' => [
      'name' => 'Default',
    ],
    'password' => 'PASSWORD',
  ],
]);

// You should save the token for later use
file_put_contents('openstack.json', json_encode($token->export()));

Sample usage of token

<?php

require 'vendor/autoload.php';

$cachedToken = json_decode(file_get_contents('openstack.json'), true);

$openstack = new \OpenStack\OpenStack([
  'authUrl' => 'https://auth.cloud.ovh.net/v3/',
  'region' => 'REGION',
  'tenantName' => 'TENANT',
  'cachedToken' => $cachedToken,
]);

$service = $openstack->objectStoreV1();
$container = $service->getContainer('CONTAINER');

$container->createObject([
  'name' => 'FILENAME',
  'content' => 'CONTENT',
]);
@benbrahimHamza
Copy link

Very useful ! Thanks, the doc is very poor and often outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment