Skip to content

Commit

Permalink
Merge pull request grpc#4487 from stanley-cheung/php_insecure_channel…
Browse files Browse the repository at this point in the history
…_creds

PHP: make ChannelCredentials::createInsecure explicit
  • Loading branch information
jboeuf committed Dec 16, 2015
2 parents 416000f + 6bd3180 commit 62ae50d
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/php/ext/grpc/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,20 @@ PHP_METHOD(Channel, __construct) {
array_hash = Z_ARRVAL_P(args_array);
if (zend_hash_find(array_hash, "credentials", sizeof("credentials"),
(void **)&creds_obj) == SUCCESS) {
if (zend_get_class_entry(*creds_obj TSRMLS_CC) !=
if (Z_TYPE_P(*creds_obj) == IS_NULL) {
creds = NULL;
zend_hash_del(array_hash, "credentials", 12);
} else if (zend_get_class_entry(*creds_obj TSRMLS_CC) !=
grpc_ce_channel_credentials) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"credentials must be a ChannelCredentials object",
1 TSRMLS_CC);
return;
} else {
creds = (wrapped_grpc_channel_credentials *)zend_object_store_get_object(
*creds_obj TSRMLS_CC);
zend_hash_del(array_hash, "credentials", 12);
}
creds = (wrapped_grpc_channel_credentials *)zend_object_store_get_object(
*creds_obj TSRMLS_CC);
zend_hash_del(array_hash, "credentials", 12);
}
php_grpc_read_args_array(args_array, &args);
if (creds == NULL) {
Expand Down
10 changes: 10 additions & 0 deletions src/php/ext/grpc/channel_credentials.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,23 @@ PHP_METHOD(ChannelCredentials, createComposite) {
RETURN_DESTROY_ZVAL(creds_object);
}

/**
* Create insecure channel credentials
* @return null
*/
PHP_METHOD(ChannelCredentials, createInsecure) {
RETURN_NULL();
}

static zend_function_entry channel_credentials_methods[] = {
PHP_ME(ChannelCredentials, createDefault, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(ChannelCredentials, createSsl, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(ChannelCredentials, createComposite, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(ChannelCredentials, createInsecure, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END};

void grpc_init_channel_credentials(TSRMLS_D) {
Expand Down
12 changes: 7 additions & 5 deletions src/php/ext/grpc/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<email>grpc-packages@google.com</email>
<active>yes</active>
</lead>
<date>2015-12-15</date>
<time>13:49:29</time>
<date>2015-12-16</date>
<time>12:56:11</time>
<version>
<release>0.7.0</release>
<api>0.7.0</api>
Expand All @@ -25,6 +25,7 @@
- Breaking change to Credentials class (removed) #3765
- Replaced by ChannelCredentials and CallCredentials class #3765
- New plugin based metadata auth API #4394
- Explicit ChannelCredentials::createInsecure() call
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand All @@ -34,9 +35,9 @@
<file baseinstalldir="/" md5sum="44c56bd9912d2538cbd6059e3e0452b6" name="call.h" role="src" />
<file baseinstalldir="/" md5sum="ff90f6c03ed44b5f4170bf3259a6704e" name="call_credentials.c" role="src" />
<file baseinstalldir="/" md5sum="3c3860e1d84f43cb6b2fbaa8d2ae1ab7" name="call_credentials.h" role="src" />
<file baseinstalldir="/" md5sum="00b44de389fbafa68afe8173045940af" name="channel.c" role="src" />
<file baseinstalldir="/" md5sum="aee9b63f790522aec2c682055240cc61" name="channel.c" role="src" />
<file baseinstalldir="/" md5sum="ed4b00c0cf3702b115d0cfa87450dc09" name="channel.h" role="src" />
<file baseinstalldir="/" md5sum="d6e32503492b22bca1baf119d6c5e373" name="channel_credentials.c" role="src" />
<file baseinstalldir="/" md5sum="1a51c76d0b7b7d3ab570ed7d60c2ea46" name="channel_credentials.c" role="src" />
<file baseinstalldir="/" md5sum="a86250e03f610ce6c2c7595a84e08821" name="channel_credentials.h" role="src" />
<file baseinstalldir="/" md5sum="55ab7a42f9dd9bfc7e28a61cfc5fca63" name="completion_queue.c" role="src" />
<file baseinstalldir="/" md5sum="f10b5bb232d74a6878e829e2e76cdaa2" name="completion_queue.h" role="src" />
Expand Down Expand Up @@ -141,12 +142,13 @@ Update to wrap gRPC C Core version 0.10.0
<release>beta</release>
<api>beta</api>
</stability>
<date>2015-12-15</date>
<date>2015-12-16</date>
<license>BSD</license>
<notes>
- Breaking change to Credentials class (removed) #3765
- Replaced by ChannelCredentials and CallCredentials class #3765
- New plugin based metadata auth API #4394
- Explicit ChannelCredentials::createInsecure() call
</notes>
</release>
</changelog>
Expand Down
11 changes: 11 additions & 0 deletions src/php/lib/Grpc/AbstractCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,15 @@ protected function deserializeResponse($value)

return call_user_func($this->deserialize, $value);
}

/**
* Set the CallCredentials for the underlying Call.
*
* @param CallCredentials $call_credentials The CallCredentials
* object
*/
public function setCallCredentials($call_credentials)
{
$this->call->setCredentials($call_credentials);
}
}
5 changes: 5 additions & 0 deletions src/php/lib/Grpc/BaseStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public function __construct($hostname, $opts)
}
$opts['grpc.primary_user_agent'] .=
'grpc-php/'.$package_config['version'];
if (!array_key_exists('credentials', $opts)) {
throw new \Exception("The opts['credentials'] key is now ".
'required. Please see one of the '.
'ChannelCredentials::create methods');
}
$this->channel = new Channel($hostname, $opts);
}

Expand Down
4 changes: 3 additions & 1 deletion src/php/tests/generated_code/AbstractGeneratedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public function testCancel()
*/
public function testInvalidMethodName()
{
$invalid_client = new DummyInvalidClient('host', []);
$invalid_client = new DummyInvalidClient('host', [
'credentials' => Grpc\ChannelCredentials::createInsecure(),
]);
$div_arg = new math\DivArgs();
$invalid_client->InvalidUnaryCall($div_arg);
}
Expand Down
6 changes: 4 additions & 2 deletions src/php/tests/generated_code/GeneratedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ class GeneratedCodeTest extends AbstractGeneratedCodeTest
public function setUp()
{
self::$client = new math\MathClient(
getenv('GRPC_TEST_HOST'), []);
getenv('GRPC_TEST_HOST'), [
'credentials' => Grpc\ChannelCredentials::createInsecure(),
]);
}

public static function tearDownAfterClass()
public function tearDown()
{
self::$client->close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function setUp()
{
self::$client = new math\MathClient(
getenv('GRPC_TEST_HOST'),
['update_metadata' => function ($a_hash,
['credentials' => Grpc\ChannelCredentials::createInsecure(),
'update_metadata' => function ($a_hash,
$client = []) {
$a_copy = $a_hash;
$a_copy['foo'] = ['bar'];
Expand All @@ -48,7 +49,7 @@ public function setUp()
}]);
}

public static function tearDownAfterClass()
public function tearDown()
{
self::$client->close();
}
Expand Down
2 changes: 2 additions & 0 deletions src/php/tests/interop/interop_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ function timeoutOnSleepingServer($stub)
}
$opts['credentials'] = $ssl_credentials;
$opts['grpc.ssl_target_name_override'] = $host_override;
} else {
$opts['credentials'] = Grpc\ChannelCredentials::createInsecure();
}

if (in_array($test_case, ['service_account_creds',
Expand Down

0 comments on commit 62ae50d

Please sign in to comment.