Skip to content

Commit

Permalink
feat: Add IAM management methods. (#2298)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and jdpedrie committed Sep 4, 2019
1 parent d0c7656 commit 8858563
Show file tree
Hide file tree
Showing 7 changed files with 542 additions and 15 deletions.
40 changes: 30 additions & 10 deletions Bigtable/metadata/Admin/V2/BigtableTableAdmin.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions Bigtable/src/Admin/V2/BigtableTableAdminGrpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,48 @@ public function DeleteSnapshot(\Google\Cloud\Bigtable\Admin\V2\DeleteSnapshotReq
$metadata, $options);
}

/**
* Gets the access control policy for an instance resource. Returns an empty
* policy if an table exists but does not have a policy set.
* @param \Google\Cloud\Iam\V1\GetIamPolicyRequest $argument input argument
* @param array $metadata metadata
* @param array $options call options
*/
public function GetIamPolicy(\Google\Cloud\Iam\V1\GetIamPolicyRequest $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/google.bigtable.admin.v2.BigtableTableAdmin/GetIamPolicy',
$argument,
['\Google\Cloud\Iam\V1\Policy', 'decode'],
$metadata, $options);
}

/**
* Sets the access control policy on a table resource. Replaces any existing
* policy.
* @param \Google\Cloud\Iam\V1\SetIamPolicyRequest $argument input argument
* @param array $metadata metadata
* @param array $options call options
*/
public function SetIamPolicy(\Google\Cloud\Iam\V1\SetIamPolicyRequest $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/google.bigtable.admin.v2.BigtableTableAdmin/SetIamPolicy',
$argument,
['\Google\Cloud\Iam\V1\Policy', 'decode'],
$metadata, $options);
}

/**
* Returns permissions that the caller has on the specified table resource.
* @param \Google\Cloud\Iam\V1\TestIamPermissionsRequest $argument input argument
* @param array $metadata metadata
* @param array $options call options
*/
public function TestIamPermissions(\Google\Cloud\Iam\V1\TestIamPermissionsRequest $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/google.bigtable.admin.v2.BigtableTableAdmin/TestIamPermissions',
$argument,
['\Google\Cloud\Iam\V1\TestIamPermissionsResponse', 'decode'],
$metadata, $options);
}

}
179 changes: 179 additions & 0 deletions Bigtable/src/Admin/V2/Gapic/BigtableTableAdminGapicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
use Google\Cloud\Bigtable\Admin\V2\SnapshotTableRequest;
use Google\Cloud\Bigtable\Admin\V2\Table;
use Google\Cloud\Bigtable\Admin\V2\Table\View;
use Google\Cloud\Iam\V1\GetIamPolicyRequest;
use Google\Cloud\Iam\V1\GetPolicyOptions;
use Google\Cloud\Iam\V1\Policy;
use Google\Cloud\Iam\V1\SetIamPolicyRequest;
use Google\Cloud\Iam\V1\TestIamPermissionsRequest;
use Google\Cloud\Iam\V1\TestIamPermissionsResponse;
use Google\LongRunning\Operation;
use Google\Protobuf\Duration;
use Google\Protobuf\GPBEmpty;
Expand Down Expand Up @@ -1036,6 +1042,179 @@ public function checkConsistency($name, $consistencyToken, array $optionalArgs =
)->wait();
}

/**
* Gets the access control policy for an instance resource. Returns an empty
* policy if an table exists but does not have a policy set.
*
* Sample code:
* ```
* $bigtableTableAdminClient = new Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient();
* try {
* $formattedResource = $bigtableTableAdminClient->tableName('[PROJECT]', '[INSTANCE]', '[TABLE]');
* $response = $bigtableTableAdminClient->getIamPolicy($formattedResource);
* } finally {
* $bigtableTableAdminClient->close();
* }
* ```
*
* @param string $resource REQUIRED: The resource for which the policy is being requested.
* See the operation documentation for the appropriate value for this field.
* @param array $optionalArgs {
* Optional.
*
* @type GetPolicyOptions $options
* OPTIONAL: A `GetPolicyOptions` object for specifying options to
* `GetIamPolicy`. This field is only used by Cloud IAM.
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a
* {@see Google\ApiCore\RetrySettings} object, or an associative array
* of retry settings parameters. See the documentation on
* {@see Google\ApiCore\RetrySettings} for example usage.
* }
*
* @return \Google\Cloud\Iam\V1\Policy
*
* @throws ApiException if the remote call fails
* @experimental
*/
public function getIamPolicy($resource, array $optionalArgs = [])
{
$request = new GetIamPolicyRequest();
$request->setResource($resource);
if (isset($optionalArgs['options'])) {
$request->setOptions($optionalArgs['options']);
}

$requestParams = new RequestParamsHeaderDescriptor([
'resource' => $request->getResource(),
]);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();

return $this->startCall(
'GetIamPolicy',
Policy::class,
$optionalArgs,
$request
)->wait();
}

/**
* Sets the access control policy on a table resource. Replaces any existing
* policy.
*
* Sample code:
* ```
* $bigtableTableAdminClient = new Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient();
* try {
* $formattedResource = $bigtableTableAdminClient->tableName('[PROJECT]', '[INSTANCE]', '[TABLE]');
* $policy = new Google\Cloud\Iam\V1\Policy();
* $response = $bigtableTableAdminClient->setIamPolicy($formattedResource, $policy);
* } finally {
* $bigtableTableAdminClient->close();
* }
* ```
*
* @param string $resource REQUIRED: The resource for which the policy is being specified.
* See the operation documentation for the appropriate value for this field.
* @param Policy $policy REQUIRED: The complete policy to be applied to the `resource`. The size of
* the policy is limited to a few 10s of KB. An empty policy is a
* valid policy but certain Cloud Platform services (such as Projects)
* might reject them.
* @param array $optionalArgs {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a
* {@see Google\ApiCore\RetrySettings} object, or an associative array
* of retry settings parameters. See the documentation on
* {@see Google\ApiCore\RetrySettings} for example usage.
* }
*
* @return \Google\Cloud\Iam\V1\Policy
*
* @throws ApiException if the remote call fails
* @experimental
*/
public function setIamPolicy($resource, $policy, array $optionalArgs = [])
{
$request = new SetIamPolicyRequest();
$request->setResource($resource);
$request->setPolicy($policy);

$requestParams = new RequestParamsHeaderDescriptor([
'resource' => $request->getResource(),
]);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();

return $this->startCall(
'SetIamPolicy',
Policy::class,
$optionalArgs,
$request
)->wait();
}

/**
* Returns permissions that the caller has on the specified table resource.
*
* Sample code:
* ```
* $bigtableTableAdminClient = new Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient();
* try {
* $formattedResource = $bigtableTableAdminClient->tableName('[PROJECT]', '[INSTANCE]', '[TABLE]');
* $permissions = [];
* $response = $bigtableTableAdminClient->testIamPermissions($formattedResource, $permissions);
* } finally {
* $bigtableTableAdminClient->close();
* }
* ```
*
* @param string $resource REQUIRED: The resource for which the policy detail is being requested.
* See the operation documentation for the appropriate value for this field.
* @param string[] $permissions The set of permissions to check for the `resource`. Permissions with
* wildcards (such as '*' or 'storage.*') are not allowed. For more
* information see
* [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
* @param array $optionalArgs {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a
* {@see Google\ApiCore\RetrySettings} object, or an associative array
* of retry settings parameters. See the documentation on
* {@see Google\ApiCore\RetrySettings} for example usage.
* }
*
* @return \Google\Cloud\Iam\V1\TestIamPermissionsResponse
*
* @throws ApiException if the remote call fails
* @experimental
*/
public function testIamPermissions($resource, $permissions, array $optionalArgs = [])
{
$request = new TestIamPermissionsRequest();
$request->setResource($resource);
$request->setPermissions($permissions);

$requestParams = new RequestParamsHeaderDescriptor([
'resource' => $request->getResource(),
]);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();

return $this->startCall(
'TestIamPermissions',
TestIamPermissionsResponse::class,
$optionalArgs,
$request
)->wait();
}

/**
* Creates a new snapshot in the specified cluster from the specified
* source table. The cluster and the table must be in the same instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@
"retry_codes_name": "idempotent",
"retry_params_name": "idempotent_params"
},
"GetIamPolicy": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "idempotent_params"
},
"SetIamPolicy": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "non_idempotent_params"
},
"TestIamPermissions": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "idempotent_params"
},
"SnapshotTable": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,42 @@
],
],
],
'GetIamPolicy' => [
'method' => 'post',
'uriTemplate' => '/v2/{resource=projects/*/instances/*/tables/*}:getIamPolicy',
'body' => '*',
'placeholders' => [
'resource' => [
'getters' => [
'getResource',
],
],
],
],
'SetIamPolicy' => [
'method' => 'post',
'uriTemplate' => '/v2/{resource=projects/*/instances/*/tables/*}:setIamPolicy',
'body' => '*',
'placeholders' => [
'resource' => [
'getters' => [
'getResource',
],
],
],
],
'TestIamPermissions' => [
'method' => 'post',
'uriTemplate' => '/v2/{resource=projects/*/instances/*/tables/*}:testIamPermissions',
'body' => '*',
'placeholders' => [
'resource' => [
'getters' => [
'getResource',
],
],
],
],
'SnapshotTable' => [
'method' => 'post',
'uriTemplate' => '/v2/{name=projects/*/instances/*/tables/*}:snapshot',
Expand Down
Loading

0 comments on commit 8858563

Please sign in to comment.