public function Lockr::createSecretValue in Lockr 7.3
Creates a secret value by name.
Parameters
string $name:
string $value:
string|null $label:
string|null $sovereignty:
Return value
string
File
- vendor/
lockr/ lockr/ src/ Lockr.php, line 161
Class
Namespace
LockrCode
public function createSecretValue($name, $value, $label = null, $sovereignty = null) {
$info = $this->info
->getSecretInfo($name);
if (isset($info['wrapping_key'])) {
$ret = MultiKeyWrapper::reencrypt($value, $info['wrapping_key']);
}
else {
$ret = MultiKeyWrapper::encrypt($value);
}
$info['wrapping_key'] = $ret['encoded'];
$value = $ret['ciphertext'];
$query = <<<'EOQ'
mutation EnsureSecret($input: EnsureSecretValue!) {
ensureSecretValue(input: $input) {
id
}
}
EOQ;
if (is_null($label)) {
$label = '';
}
$input = [
'name' => $name,
'label' => $label,
'value' => base64_encode($value),
];
if (!is_null($sovereignty)) {
$input['sovereignty'] = $sovereignty;
}
$t0 = microtime(true);
$data = $this->client
->query([
'query' => $query,
'variables' => [
'input' => $input,
],
]);
$t1 = microtime(true);
$this->client
->getStats()
->lockrCallCompleted('create_secret_value', $t1 - $t0);
$this->info
->setSecretInfo($name, $info);
return $data['ensureSecretValue']['id'];
}