Skip to content

Commit

Permalink
allow cert and key to return separately
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Aug 18, 2021
1 parent 96becc4 commit 013ebcc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/GapicClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,12 @@ private function buildClientOptions(array $options)
// mTLS: detect and load the default clientCertSource if the environment variable
// "GOOGLE_API_USE_CLIENT_CERTIFICATE" is true, and the cert source is available
if (empty($options['clientCertSource']) && CredentialsLoader::shouldLoadClientCertSource()) {
$options['clientCertSource'] = CredentialsLoader::getDefaultClientCertSource();
$options['clientCertSource'] = function () {
$cert = call_user_func(CredentialsLoader::getDefaultClientCertSource());

// the key and the cert are returned in one string
return [$cert, $cert];
};
}

// mTLS: If no apiEndpoint has been supplied by the user, and either
Expand Down
5 changes: 1 addition & 4 deletions src/Transport/GrpcTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ private function getCallOptions(array $options)

private static function loadClientCertSource(callable $clientCertSource)
{
$cert = call_user_func($clientCertSource);

// the key and the cert are returned in one string
return [$cert, $cert];
return call_user_func($clientCertSource);
}
}
9 changes: 6 additions & 3 deletions src/Transport/HttpUnaryTransportTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ private function throwUnsupportedException()

private static function loadClientCertSource(callable $clientCertSource)
{
$f = tempnam(sys_get_temp_dir(), 'cert');
file_put_contents($f, call_user_func($this->clientCertSource));
$certFile = tempnam(sys_get_temp_dir(), 'cert');
$keyFile = tempnam(sys_get_temp_dir(), 'key');
list($cert, $key) = call_user_func($this->clientCertSource);
file_put_contents($certFile, $cert);
file_put_contents($keyFile, $key);

// the key and the cert are returned in one temporary file
return [$f, $f];
return [$certFile, $keyFile];
}
}

0 comments on commit 013ebcc

Please sign in to comment.