1. Go to this page and download the library: Download akeyless/grpc 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/ */
akeyless / grpc example snippets
keyless\gRPC\AkeylessV2ServiceClient;
use Akeyless\gRPC\Auth;
use Akeyless\gRPC\AuthRequest;
use Akeyless\gRPC\GetSecretValue;
use Akeyless\gRPC\GetSecretValueRequest;
use Akeyless\gRPC\ListItems;
use Akeyless\gRPC\ListItemsRequest;
// Replace with your actual hostname, options, and channel if needed
$hostname = "localhost:8085";
// Specify your channel options as needed
$opts = [
"credentials" => Grpc\ChannelCredentials::createInsecure(),
];
// Create an client of AkeylessV2ServiceClient
$client = new AkeylessV2ServiceClient($hostname, $opts);
// Authenticate
$auth = new Auth([
"access_id" => "********",
"access_key" => "********",
"access_type" => "access_key",
]);
$authRequest = new AuthRequest();
$authRequest->setBody($auth);
// Auth
list($authResponse, $status) = $client->Auth($authRequest)->wait();
$token = $authResponse->getToken();
$listItems = new ListItems();
$listItems->setToken($token);
$listItemsRequest = new ListItemsRequest();
$listItemsRequest->setBody($listItems);
//List items
list($listItemsResponse, $status) = $client
->ListItems($listItemsRequest)
->wait();
foreach ($listItemsResponse->getItems() as $item) {
echo $item->getItemName() . PHP_EOL;
}
$getSecretValue = new GetSecretValue();
$getSecretValue->setToken($token);
$getSecretValue->setNames(["/MyFirstSecret"]);
$getSecretValueRequest = new GetSecretValueRequest();
$getSecretValueRequest->setBody($getSecretValue);
//Get secret value
list($getSecretValueResponse, $status) = $client
->GetSecretValue($getSecretValueRequest)
->wait();
$fields = $getSecretValueResponse->getData()->getFields();
// Iterate over each field
foreach ($fields as $key => $value) {
$stringValue = $value->getStringValue();
// Use the values as needed
echo "Field: $key, Value: $stringValue" . PHP_EOL;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.