Skip to content

Commit

Permalink
fix: add InsecureCredentials to address issue in Cloud Spanner emulat…
Browse files Browse the repository at this point in the history
…or (#5224)
  • Loading branch information
HannahShiSFB committed May 2, 2022
1 parent aac8a23 commit e4caaa7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Core/src/EmulatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ private function emulatorGapicConfig($emulatorHost)
'credentials' => \Grpc\ChannelCredentials::createInsecure()
]
]
]
],
'credentials' => new InsecureCredentialsWrapper(),
];
}
/**
Expand Down
36 changes: 36 additions & 0 deletions Core/src/InsecureCredentialsWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* Copyright 2022 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Core;

use Google\ApiCore\CredentialsWrapper;

/**
* For connect to emulator.
*/
class InsecureCredentialsWrapper extends CredentialsWrapper
{
public function __construct()
{
}

public function getAuthorizationHeaderCallback($audience = null)
{
return null;
}
}
13 changes: 7 additions & 6 deletions Spanner/src/Connection/Grpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ public function __construct(array $config = [])
'queryOptions' => []
];
if ((bool) $config['emulatorHost']) {
$grpcConfig += $this->emulatorGapicConfig($config['emulatorHost']);
} else {
$this->credentialsWrapper = $grpcConfig['credentials'];
if (isset($config['apiEndpoint'])) {
$grpcConfig['apiEndpoint'] = $config['apiEndpoint'];
}
$grpcConfig = array_merge(
$grpcConfig,
$this->emulatorGapicConfig($config['emulatorHost'])
);
} elseif (isset($config['apiEndpoint'])) {
$grpcConfig['apiEndpoint'] = $config['apiEndpoint'];
}
$this->credentialsWrapper = $grpcConfig['credentials'];

$this->defaultQueryOptions = $config['queryOptions'];

Expand Down

0 comments on commit e4caaa7

Please sign in to comment.