-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new surface custom LROs (#712)
- Loading branch information
Showing
29 changed files
with
1,864 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
tests/Unit/ProtoTests/CustomLroNew/custom_lro_new.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
syntax = "proto3"; | ||
|
||
import "google/api/annotations.proto"; | ||
import "google/api/client.proto"; | ||
import "google/api/field_behavior.proto"; | ||
import "google/cloud/extended_operations.proto"; | ||
import "google/protobuf/empty.proto"; | ||
|
||
package testing.customlronew; | ||
|
||
option php_namespace = "Testing\\CustomLroNew"; | ||
|
||
service CustomLro { | ||
option (google.api.default_host) = "customlro.example.com"; | ||
option (google.api.oauth_scopes) = "scope1,scope2"; | ||
rpc CreateFoo(CreateFooRequest) returns (CustomOperationResponse) { | ||
option (google.api.http) = { | ||
post: "/foo" | ||
body: "*" | ||
}; | ||
option (google.cloud.operation_service) = "CustomLroOperations"; | ||
} | ||
} | ||
|
||
service CustomLroOperations { | ||
option (google.api.default_host) = "customlro.example.com"; | ||
option (google.api.oauth_scopes) = "scope1,scope2"; | ||
rpc Get(GetOperationRequest) returns (CustomOperationResponse) { | ||
option (google.api.http) = { | ||
get: "/operation" | ||
}; | ||
option (google.cloud.operation_polling_method) = true; | ||
option (google.api.method_signature) = 'operation,project,region,foo'; | ||
} | ||
|
||
rpc Cancel(CancelOperationRequest) returns (google.protobuf.Empty) { | ||
option (google.api.http) = { | ||
patch: "/operation" | ||
}; | ||
} | ||
|
||
rpc Delete(DeleteOperationRequest) returns (google.protobuf.Empty) { | ||
option (google.api.http) = { | ||
delete: "/operation" | ||
}; | ||
} | ||
} | ||
|
||
message CustomOperationResponse { | ||
optional string name = 1 [(google.cloud.operation_field) = NAME]; | ||
|
||
optional string http_error_message = 2 [(google.cloud.operation_field) = ERROR_MESSAGE]; | ||
|
||
optional int32 http_error_status_code = 3 [(google.cloud.operation_field) = ERROR_CODE]; | ||
|
||
enum Status { | ||
// A value indicating that the enum field is not set. | ||
UNDEFINED_STATUS = 0; | ||
|
||
DONE = 1; | ||
|
||
PENDING = 2; | ||
|
||
RUNNING = 3; | ||
} | ||
|
||
optional Status status = 4 [(google.cloud.operation_field) = STATUS]; | ||
} | ||
|
||
message CreateFooRequest { | ||
string foo = 1 [(google.cloud.operation_request_field) = "foo"]; | ||
|
||
string project = 2 [ | ||
(google.cloud.operation_request_field) = "project", | ||
(google.api.field_behavior) = REQUIRED]; | ||
|
||
string region = 3 [ | ||
(google.cloud.operation_request_field) = "region", | ||
(google.api.field_behavior) = REQUIRED]; | ||
} | ||
|
||
message GetOperationRequest { | ||
// Name of the Operations resource to return. | ||
string operation = 1 [ | ||
(google.cloud.operation_response_field) = "name", | ||
(google.api.field_behavior) = REQUIRED]; | ||
|
||
// Project ID for this request. | ||
string project = 2 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
// Name of the region for this request. | ||
string region = 3 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
// The foo from the initial request. | ||
string foo = 4 [(google.api.field_behavior) = REQUIRED]; | ||
} | ||
|
||
message CancelOperationRequest { | ||
// Name of th Operations resource to cancel. | ||
string operation = 1 [(google.api.field_behavior) = REQUIRED]; | ||
} | ||
|
||
message DeleteOperationRequest { | ||
// Name of th Operations resource to delete. | ||
string operation = 1 [(google.api.field_behavior) = REQUIRED]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
type: google.api.Service | ||
config_version: 1 | ||
name: customlro.example.com | ||
title: Custom LRO Example API | ||
|
||
# Included protobuf APIs | ||
apis: | ||
- name: testing.customlro.CustomLro | ||
- name: testing.customlro.CustomLroOperations | ||
|
||
# Documentation section | ||
documentation: | ||
summary: | ||
A simple Custom LRO Example API. | ||
|
||
# Auth section | ||
authentication: | ||
rules: | ||
- selector: '*' | ||
oauth: | ||
canonical_scopes: scope1, | ||
scope2 | ||
|
||
# Backend section | ||
backend: | ||
rules: | ||
- selector: testing.customlro.CustomLro.CreateFoo | ||
deadline: 1.0 |
19 changes: 19 additions & 0 deletions
19
.../ProtoTests/CustomLroNew/out/fragments/Testing/CustomLroNew/GetOperationRequest.build.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
/** | ||
* @param string $operation Name of the Operations resource to return. | ||
* @param string $project Project ID for this request. | ||
* @param string $region Name of the region for this request. | ||
* @param string $foo The foo from the initial request. | ||
* | ||
* @return \Testing\CustomLroNew\GetOperationRequest | ||
* | ||
* @experimental | ||
*/ | ||
public static function build(string $operation, string $project, string $region, string $foo): self | ||
{ | ||
return (new self()) | ||
->setOperation($operation) | ||
->setProject($project) | ||
->setRegion($region) | ||
->setFoo($foo); | ||
} |
80 changes: 80 additions & 0 deletions
80
tests/Unit/ProtoTests/CustomLroNew/out/samples/CustomLroClient/create_foo.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
/* | ||
* GENERATED CODE WARNING | ||
* This file was automatically generated - do not edit! | ||
*/ | ||
|
||
require_once __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
// [START customlro_generated_CustomLro_CreateFoo_sync] | ||
use Google\ApiCore\ApiException; | ||
use Google\ApiCore\OperationResponse; | ||
use Google\Rpc\Status; | ||
use Testing\CustomLroNew\Client\CustomLroClient; | ||
use Testing\CustomLroNew\CreateFooRequest; | ||
|
||
/** | ||
* @param string $project | ||
* @param string $region | ||
*/ | ||
function create_foo_sample(string $project, string $region): void | ||
{ | ||
// Create a client. | ||
$customLroClient = new CustomLroClient(); | ||
|
||
// Prepare the request message. | ||
$request = (new CreateFooRequest()) | ||
->setProject($project) | ||
->setRegion($region); | ||
|
||
// Call the API and handle any network failures. | ||
try { | ||
/** @var OperationResponse $response */ | ||
$response = $customLroClient->createFoo($request); | ||
$response->pollUntilComplete(); | ||
|
||
if ($response->operationSucceeded()) { | ||
printf('Operation completed successfully.' . PHP_EOL); | ||
} else { | ||
/** @var Status $error */ | ||
$error = $response->getError(); | ||
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString()); | ||
} | ||
} catch (ApiException $ex) { | ||
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Helper to execute the sample. | ||
* | ||
* This sample has been automatically generated and should be regarded as a code | ||
* template only. It will require modifications to work: | ||
* - It may require correct/in-range values for request initialization. | ||
* - It may require specifying regional endpoints when creating the service client, | ||
* please see the apiEndpoint client configuration option for more details. | ||
*/ | ||
function callSample(): void | ||
{ | ||
$project = '[PROJECT]'; | ||
$region = '[REGION]'; | ||
|
||
create_foo_sample($project, $region); | ||
} | ||
// [END customlro_generated_CustomLro_CreateFoo_sync] |
Oops, something went wrong.