PHP code example of lockerpm / locker-secrets

1. Go to this page and download the library: Download lockerpm/locker-secrets library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lockerpm / locker-secrets example snippets


use Locker\ClientOptions;
use Locker\Locker;

$locker = new Locker(
    accessKeyId: $accessKeyId,
    secretAccessKey: $secretAccessKey,
    options: new ClientOptions(cliPath: '/opt/locker/bin/locker'),
);



use Locker\Locker;

$locker = Locker::fromEnvironment();
$databasePassword = $locker->getRequired('DATABASE_PASSWORD');

$secrets = $locker->secrets();

$secret = $secrets->get('DATABASE_PASSWORD', 'production');
$all = $secrets->list('production');

$page = $secrets->listPage(
    environment: 'production',
    pageSize: 100,
);
while ($page->nextCursor !== null) {
    $page = $secrets->listPage(
        environment: 'production',
        pageSize: 100,
        cursor: $page->nextCursor,
    );
}

$created = $secrets->create(
    key: 'API_TOKEN',
    value: $token,
    environment: 'production',
    description: 'Token used by the worker',
);

$updated = $secrets->update(
    key: 'API_TOKEN',
    changes: [
        'value' => $rotatedToken,
        'description' => '',
        'environment' => null,
    ],
    environment: 'production',
);

$token = $locker->getRequired('API_TOKEN', 'production');

$region = $locker->getOrDefault('REGION', 'us-east-1');

$environments = $locker->environments();

$production = $environments->get('production');
$all = $environments->list();
$page = $environments->listPage(pageSize: 100);

$created = $environments->create(
    name: 'staging',
    externalUrl: 'https://staging.example.com',
    description: '',
);

$updated = $environments->update(
    name: 'staging',
    changes: [
        'name' => 'staging-eu',
        'external_url' => 'https://eu.staging.example.com',
    ],
);

use Locker\ClientOptions;
use Locker\Locker;

$options = new ClientOptions(
    cliPath: '/opt/locker/bin/locker',
    timeoutSeconds: 15.0,
    apiBase: 'https://api.locker.io/locker_secrets',
    headers: ['CF-Access-Client-Id' => $clientId],
    forceRefresh: false,
    cacheMaxAgeSeconds: 120,
);

$locker = new Locker($accessKeyId, $secretAccessKey, $options);

use Locker\Exception\AlreadyExistsException;
use Locker\Exception\ConflictException;

try {
    $locker->secrets()->create(
        key: 'PAYMENT_API_KEY',
        value: 'value',
    );
} catch (AlreadyExistsException $error) {
    // The secret or environment already exists.
    // AlreadyExistsException is also a ConflictException.
}

use Locker\Distribution\CliInstaller;

$path = (new CliInstaller())->installLatest();