Merge pull request #4534 from stanley-cheung/php_insecure_channel_creds_0_12

PHP: make ChannelCredentials::createInsecure explicit
pull/4539/head
Stanley Cheung 9 years ago
commit 08ae945aac
  1. 12
      src/php/ext/grpc/channel.c
  2. 10
      src/php/ext/grpc/channel_credentials.c
  3. 43
      src/php/ext/grpc/package.xml
  4. 11
      src/php/lib/Grpc/AbstractCall.php
  5. 5
      src/php/lib/Grpc/BaseStub.php
  6. 4
      src/php/tests/generated_code/AbstractGeneratedCodeTest.php
  7. 6
      src/php/tests/generated_code/GeneratedCodeTest.php
  8. 5
      src/php/tests/generated_code/GeneratedCodeWithCallbackTest.php
  9. 2
      src/php/tests/interop/interop_client.php

@ -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) {

@ -169,6 +169,14 @@ 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)
@ -176,6 +184,8 @@ static zend_function_entry channel_credentials_methods[] = {
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) {

@ -10,11 +10,11 @@
<email>grpc-packages@google.com</email>
<active>yes</active>
</lead>
<date>2015-10-21</date>
<time>17:04:32</time>
<date>2015-12-16</date>
<time>12:56:11</time>
<version>
<release>0.6.1</release>
<api>0.6.0</api>
<release>0.7.0</release>
<api>0.7.0</api>
</version>
<stability>
<release>beta</release>
@ -22,19 +22,22 @@
</stability>
<license>BSD</license>
<notes>
- fixed undefined constant fatal error when run with apache/nginx #2275
- 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="/">
<file baseinstalldir="/" md5sum="6f19828fb869b7b8a590cbb76b4f996d" name="byte_buffer.c" role="src" />
<file baseinstalldir="/" md5sum="c8de0f819499c48adfc8d7f472c0196b" name="byte_buffer.h" role="src" />
<file baseinstalldir="/" md5sum="d64c9005993de02abac55664b0b9e0b2" name="call.c" role="src" />
<file baseinstalldir="/" md5sum="26acbf04c30162c2d2aca4688bb2aec8" name="call.h" role="src" />
<file baseinstalldir="/" md5sum="6fa13d260dfde216f795225644f04e7a" name="call_credentials.c" role="src" />
<file baseinstalldir="/" md5sum="e45269975f9a30fd349a90daf6b31aa2" name="call_credentials.h" role="src" />
<file baseinstalldir="/" md5sum="0779db3b196c98081b2260ceec22cd4d" name="channel.c" role="src" />
<file baseinstalldir="/" md5sum="ee7eb7757f9e6f0e36f8f616b6bd0af5" name="call.c" role="src" />
<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="aee9b63f790522aec2c682055240cc61" name="channel.c" role="src" />
<file baseinstalldir="/" md5sum="ed4b00c0cf3702b115d0cfa87450dc09" name="channel.h" role="src" />
<file baseinstalldir="/" md5sum="1b40f50fa6184ad7d24a961ac76151ff" 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" />
@ -130,5 +133,23 @@ Update to wrap gRPC C Core version 0.10.0
- fixed undefined constant fatal error when run with apache/nginx #2275
</notes>
</release>
<release>
<version>
<release>0.7.0</release>
<api>0.7.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<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>
</package>

@ -114,4 +114,15 @@ abstract class AbstractCall
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);
}
}

@ -72,6 +72,11 @@ class BaseStub
}
$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);
}

@ -111,7 +111,9 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase
*/
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);
}

@ -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();
}

@ -39,7 +39,8 @@ class GeneratedCodeWithCallbackTest extends AbstractGeneratedCodeTest
{
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'];
@ -48,7 +49,7 @@ class GeneratedCodeWithCallbackTest extends AbstractGeneratedCodeTest
}]);
}
public static function tearDownAfterClass()
public function tearDown()
{
self::$client->close();
}

@ -438,6 +438,8 @@ if ($use_tls) {
}
$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',

Loading…
Cancel
Save