-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAKeylessTest.php
executable file
·65 lines (57 loc) · 2.25 KB
/
AKeylessTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
function FetchKeylessStatic_old($arrNames)
{
# $arrNames is an array of the secret names to be fetched
# Returns an associated array with the secret name as key and the secret as the value
# Requires AccessID and Accesskey as environment variables
$AccessID = getenv("KEYLESSID");
$AccessKey = getenv("KEYLESSKEY");
$APIEndpoint = "https://api.akeyless.io";
$PostData = array();
$PostData["access-type"] = "access_key";
$PostData["access-id"] = "$AccessID";
$PostData["access-key"] = "$AccessKey";
$jsonPostData = json_encode($PostData);
$Service = "/auth";
$url = $APIEndpoint.$Service;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonPostData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("accept: application/json","Content-Type: application/json"));
$response = curl_exec($curl);
curl_close($curl);
$arrResponse = json_decode($response, TRUE);
$token = $arrResponse["token"];
$PostData = array();
$PostData["token"] = $token;
$PostData["names"] = $arrNames;
$jsonPostData = json_encode($PostData);
$Service = "/get-secret-value";
$url = $APIEndpoint.$Service;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonPostData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("accept: application/json","Content-Type: application/json"));
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response, TRUE);
}
require_once("header.php");
$arrname = array();
$arrname[] = "MySecret1";
$arrname[] = "MyFirstSecret";
$arrname[] = "/TSC/AnotherTest2";
$arrname[] = "/Test/MyPathTest";
print "<h1>Fetching secret from AKEYLESS secret management system at akeyless.io</h1>\n";
$arrSecretValues = FetchKeylessStatic($arrname);
print "<p>Here are the secret names and corrensponding values</p>\n";
foreach($arrSecretValues as $key => $value)
{
print "$key: $value <br>\n";
}
require_once("footer.php");
?>