PHP code example of pmg / cred-commands

1. Go to this page and download the library: Download pmg/cred-commands 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/ */

    

pmg / cred-commands example snippets


#!/usr/bin/env php


use Aws\Ssm\SsmClient;
use PMG\CredCommands\Application;
use PMG\CredCommands\CredentialClient;

$ssm = SsmClient::factory([
  'version' => 'latest',
  'region' => 'us-east-1',
]);
$client = new CredentialClient($ssm);

$app = new Application($client, 'App Name', 'App Version');

$app->run();

#!/usr/bin/env php


use Aws\Ssm\SsmClient;
use Symfony\Component\Console\Application;
use PMG\CredCommands\CredentialClient;
use PMG\CredCommands\Command\GetCommand;
use PMG\CredCommands\Command\PutCommand;
use PMG\CredCommands\Command\RemoveCommand;

$app = new Application();

// other command added here or something...

$ssm = SsmClient::factory([
  'version' => 'latest',
  'region' => 'us-east-1',
]);
$client = new CredentialClient($ssm);

$app->add(new GetCommand($client));
$app->add(new PutCommand($client));
$app->add(new RemoveCommand($client));

$app->run();

use PMG\CredCommands\Formatter\NullFormatter;

$formatter = new NullFormatter();

$formater->format('someCredential'); // 'someCredential'

use PMG\CredCommands\Formatter\TemplateFormatter;

$formatter = new TemplateFormater('prefix_{cred}');

$formater->format('someCredential'); // 'prefix_someCredential'

use PMG\CredCommands\Formatter\AppEnvFormatter;

$formatter = new AppEnvFormater('appName', 'prod');

$formater->format('someCredential'); // '/appName/prod/someCredential'



use Aws\Ssm\SsmClient;
use PMG\CredCommands\Application;
use PMG\CredCommands\CredentialClient;
use PMG\CredCommands\Command\GetCommand;
use PMG\CredCommands\Formatter\AppEnvFormatter;

$ssm = SsmClient::factory([
  // ...
]);
$client = new CredentialClient(
    $ssm,
    new AppEnvFormatter('example', 'dev')
);

// new GetCommand($client);
// new Application($client, 'name', 'version');
// etc.



use Aws\Ssm\SsmClient;
use PMG\CredCommands\CredentialClient;
use PMG\CredCommands\Formatter\AppEnvFormatter;

$ssm = SsmClient::factory([
  // ...
]);

// with a key ID (example, not a real key ID)
$client = new CredentialClient(
    $ssm,
    new AppEnvFormatter('example', 'dev'),
    'df502ce0-49e1-4579-a682-395274de6eb4',
);

// with a key alias (example, not a real key alias)
$client = new CredentialClient(
    $ssm,
    new AppEnvFormatter('example', 'dev'),
    'alias/some-alias-here'
);