diff --git a/apikeys/apiv2/api_keys_client.go b/apikeys/apiv2/api_keys_client.go index 9d578a566747..1e8f8de51499 100644 --- a/apikeys/apiv2/api_keys_client.go +++ b/apikeys/apiv2/api_keys_client.go @@ -25,6 +25,7 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" + emptypb "github.com/golang/protobuf/ptypes/empty" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -35,7 +36,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" - emptypb "google.golang.org/protobuf/types/known/emptypb" ) var newClientHook clientHook diff --git a/apikeys/go.mod b/apikeys/go.mod index 699bd88dd8b1..25e960995b90 100644 --- a/apikeys/go.mod +++ b/apikeys/go.mod @@ -4,9 +4,10 @@ go 1.19 require ( cloud.google.com/go v0.103.0 + github.com/golang/protobuf v1.5.2 github.com/googleapis/gax-go/v2 v2.5.1 google.golang.org/api v0.93.0 - google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 + google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.1 ) @@ -14,7 +15,6 @@ require ( require ( cloud.google.com/go/compute v1.7.0 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect - github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect go.opencensus.io v0.23.0 // indirect diff --git a/apikeys/go.sum b/apikeys/go.sum index 90ccd595bb7f..df62d3ff3c07 100644 --- a/apikeys/go.sum +++ b/apikeys/go.sum @@ -597,8 +597,8 @@ google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220628213854-d9e0b6570c03/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 h1:hw4Y42zL1VyVKxPgRHHh191fpVBGV8sNVmcow5Z8VXY= -google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 h1:iw8luj804hqA2C43tq4SXb4OQNgaJU0KzSZHOHfdA4U= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/bigquery/go.mod b/bigquery/go.mod index 28066cf1b630..fe45c005af7f 100644 --- a/bigquery/go.mod +++ b/bigquery/go.mod @@ -14,7 +14,7 @@ require ( golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f google.golang.org/api v0.93.0 - google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 + google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.1 ) diff --git a/bigquery/go.sum b/bigquery/go.sum index 2de4c52fe50e..e24a91aab0ed 100644 --- a/bigquery/go.sum +++ b/bigquery/go.sum @@ -607,8 +607,8 @@ google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220722212130-b98a9ff5e252/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= -google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 h1:hw4Y42zL1VyVKxPgRHHh191fpVBGV8sNVmcow5Z8VXY= -google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 h1:iw8luj804hqA2C43tq4SXb4OQNgaJU0KzSZHOHfdA4U= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/compute/go.mod b/compute/go.mod index 830d212778c1..3d4203be11f7 100644 --- a/compute/go.mod +++ b/compute/go.mod @@ -7,7 +7,7 @@ require ( github.com/google/go-cmp v0.5.8 github.com/googleapis/gax-go/v2 v2.4.0 google.golang.org/api v0.93.0 - google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 + google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.1 ) diff --git a/compute/go.sum b/compute/go.sum index 620c742f0c50..b2d668a58dd4 100644 --- a/compute/go.sum +++ b/compute/go.sum @@ -588,8 +588,8 @@ google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 h1:hw4Y42zL1VyVKxPgRHHh191fpVBGV8sNVmcow5Z8VXY= -google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 h1:iw8luj804hqA2C43tq4SXb4OQNgaJU0KzSZHOHfdA4U= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/go.mod b/go.mod index 5f6155225c62..263724a34b78 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f google.golang.org/api v0.93.0 - google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 + google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.1 ) diff --git a/go.sum b/go.sum index 4e45d7f64535..4d558d5879a3 100644 --- a/go.sum +++ b/go.sum @@ -600,8 +600,8 @@ google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 h1:C2UVWqrgLYKrT5nh5oU6hLRm1AeEklCK5eloQA1NtFY= -google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 h1:iw8luj804hqA2C43tq4SXb4OQNgaJU0KzSZHOHfdA4U= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/internal/generated/snippets/aiplatform/apiv1/snippet_metadata.google.cloud.aiplatform.v1.json b/internal/generated/snippets/aiplatform/apiv1/snippet_metadata.google.cloud.aiplatform.v1.json index 1ecad61593de..2bf3a7324bf0 100644 --- a/internal/generated/snippets/aiplatform/apiv1/snippet_metadata.google.cloud.aiplatform.v1.json +++ b/internal/generated/snippets/aiplatform/apiv1/snippet_metadata.google.cloud.aiplatform.v1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "cloud.google.com/go/aiplatform/apiv1", - "version": "1.16.0", + "version": "1.17.0", "language": "GO", "apis": [ { diff --git a/internal/generated/snippets/aiplatform/apiv1beta1/snippet_metadata.google.cloud.aiplatform.v1beta1.json b/internal/generated/snippets/aiplatform/apiv1beta1/snippet_metadata.google.cloud.aiplatform.v1beta1.json index 72e9113b71bd..e1def79fba98 100644 --- a/internal/generated/snippets/aiplatform/apiv1beta1/snippet_metadata.google.cloud.aiplatform.v1beta1.json +++ b/internal/generated/snippets/aiplatform/apiv1beta1/snippet_metadata.google.cloud.aiplatform.v1beta1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "cloud.google.com/go/aiplatform/apiv1beta1", - "version": "1.16.0", + "version": "1.17.0", "language": "GO", "apis": [ { diff --git a/internal/generated/snippets/apikeys/apiv2/Client/CreateKey/main.go b/internal/generated/snippets/apikeys/apiv2/Client/CreateKey/main.go new file mode 100644 index 000000000000..b130d1e83513 --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/CreateKey/main.go @@ -0,0 +1,53 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_CreateKey_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + apikeyspb "google.golang.org/genproto/googleapis/api/apikeys/v2" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &apikeyspb.CreateKeyRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/apikeys/v2#CreateKeyRequest. + } + op, err := c.CreateKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END apikeys_v2_generated_ApiKeys_CreateKey_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/Client/DeleteKey/main.go b/internal/generated/snippets/apikeys/apiv2/Client/DeleteKey/main.go new file mode 100644 index 000000000000..f9d87331fe88 --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/DeleteKey/main.go @@ -0,0 +1,53 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_DeleteKey_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + apikeyspb "google.golang.org/genproto/googleapis/api/apikeys/v2" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &apikeyspb.DeleteKeyRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/apikeys/v2#DeleteKeyRequest. + } + op, err := c.DeleteKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END apikeys_v2_generated_ApiKeys_DeleteKey_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/Client/GetKey/main.go b/internal/generated/snippets/apikeys/apiv2/Client/GetKey/main.go new file mode 100644 index 000000000000..deda7c13f70a --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/GetKey/main.go @@ -0,0 +1,48 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_GetKey_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + apikeyspb "google.golang.org/genproto/googleapis/api/apikeys/v2" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &apikeyspb.GetKeyRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/apikeys/v2#GetKeyRequest. + } + resp, err := c.GetKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END apikeys_v2_generated_ApiKeys_GetKey_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/Client/GetKeyString/main.go b/internal/generated/snippets/apikeys/apiv2/Client/GetKeyString/main.go new file mode 100644 index 000000000000..5b3fbd26d33b --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/GetKeyString/main.go @@ -0,0 +1,48 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_GetKeyString_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + apikeyspb "google.golang.org/genproto/googleapis/api/apikeys/v2" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &apikeyspb.GetKeyStringRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/apikeys/v2#GetKeyStringRequest. + } + resp, err := c.GetKeyString(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END apikeys_v2_generated_ApiKeys_GetKeyString_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/Client/GetOperation/main.go b/internal/generated/snippets/apikeys/apiv2/Client/GetOperation/main.go new file mode 100644 index 000000000000..14709eef1863 --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/GetOperation/main.go @@ -0,0 +1,48 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_GetOperation_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END apikeys_v2_generated_ApiKeys_GetOperation_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/Client/ListKeys/main.go b/internal/generated/snippets/apikeys/apiv2/Client/ListKeys/main.go new file mode 100644 index 000000000000..088b77016280 --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/ListKeys/main.go @@ -0,0 +1,55 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_ListKeys_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + "google.golang.org/api/iterator" + apikeyspb "google.golang.org/genproto/googleapis/api/apikeys/v2" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &apikeyspb.ListKeysRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/apikeys/v2#ListKeysRequest. + } + it := c.ListKeys(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END apikeys_v2_generated_ApiKeys_ListKeys_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/Client/LookupKey/main.go b/internal/generated/snippets/apikeys/apiv2/Client/LookupKey/main.go new file mode 100644 index 000000000000..c7bad45cba22 --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/LookupKey/main.go @@ -0,0 +1,48 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_LookupKey_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + apikeyspb "google.golang.org/genproto/googleapis/api/apikeys/v2" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &apikeyspb.LookupKeyRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/apikeys/v2#LookupKeyRequest. + } + resp, err := c.LookupKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END apikeys_v2_generated_ApiKeys_LookupKey_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/Client/UndeleteKey/main.go b/internal/generated/snippets/apikeys/apiv2/Client/UndeleteKey/main.go new file mode 100644 index 000000000000..670fcae80ad2 --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/UndeleteKey/main.go @@ -0,0 +1,53 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_UndeleteKey_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + apikeyspb "google.golang.org/genproto/googleapis/api/apikeys/v2" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &apikeyspb.UndeleteKeyRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/apikeys/v2#UndeleteKeyRequest. + } + op, err := c.UndeleteKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END apikeys_v2_generated_ApiKeys_UndeleteKey_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/Client/UpdateKey/main.go b/internal/generated/snippets/apikeys/apiv2/Client/UpdateKey/main.go new file mode 100644 index 000000000000..b7722fb2cc50 --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/Client/UpdateKey/main.go @@ -0,0 +1,53 @@ +// 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 +// +// 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. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START apikeys_v2_generated_ApiKeys_UpdateKey_sync] + +package main + +import ( + "context" + + apikeys "cloud.google.com/go/apikeys/apiv2" + apikeyspb "google.golang.org/genproto/googleapis/api/apikeys/v2" +) + +func main() { + ctx := context.Background() + c, err := apikeys.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &apikeyspb.UpdateKeyRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/apikeys/v2#UpdateKeyRequest. + } + op, err := c.UpdateKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END apikeys_v2_generated_ApiKeys_UpdateKey_sync] diff --git a/internal/generated/snippets/apikeys/apiv2/snippet_metadata.google.api.apikeys.v2.json b/internal/generated/snippets/apikeys/apiv2/snippet_metadata.google.api.apikeys.v2.json new file mode 100644 index 000000000000..b8b20fffd1c2 --- /dev/null +++ b/internal/generated/snippets/apikeys/apiv2/snippet_metadata.google.api.apikeys.v2.json @@ -0,0 +1,429 @@ +{ + "clientLibrary": { + "name": "cloud.google.com/go/apikeys/apiv2", + "version": "0.1.0", + "language": "GO", + "apis": [ + { + "id": "google.api.apikeys.v2", + "version": "v2" + } + ] + }, + "snippets": [ + { + "regionTag": "apikeys_v2_generated_ApiKeys_CreateKey_sync", + "title": "apikeys CreateKey Sample", + "description": "CreateKey creates a new API key.\n\nNOTE: Key is a global resource; hence the only supported value for\nlocation is global.", + "file": "Client/CreateKey/main.go", + "language": "GO", + "clientMethod": { + "shortName": "CreateKey", + "fullName": "google.api.apikeys.v2.Client.CreateKey", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "apikeyspb.CreateKeyRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "CreateKeyOperation", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "CreateKey", + "fullName": "google.api.apikeys.v2.ApiKeys.CreateKey", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 52, + "type": "FULL" + } + ] + }, + { + "regionTag": "apikeys_v2_generated_ApiKeys_DeleteKey_sync", + "title": "apikeys DeleteKey Sample", + "description": "DeleteKey deletes an API key. Deleted key can be retrieved within 30 days of\ndeletion. Afterward, key will be purged from the project.\n\nNOTE: Key is a global resource; hence the only supported value for\nlocation is global.", + "file": "Client/DeleteKey/main.go", + "language": "GO", + "clientMethod": { + "shortName": "DeleteKey", + "fullName": "google.api.apikeys.v2.Client.DeleteKey", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "apikeyspb.DeleteKeyRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "DeleteKeyOperation", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "DeleteKey", + "fullName": "google.api.apikeys.v2.ApiKeys.DeleteKey", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 52, + "type": "FULL" + } + ] + }, + { + "regionTag": "apikeys_v2_generated_ApiKeys_GetKey_sync", + "title": "apikeys GetKey Sample", + "description": "GetKey gets the metadata for an API key. The key string of the API key\nisn’t included in the response.\n\nNOTE: Key is a global resource; hence the only supported value for\nlocation is global.", + "file": "Client/GetKey/main.go", + "language": "GO", + "clientMethod": { + "shortName": "GetKey", + "fullName": "google.api.apikeys.v2.Client.GetKey", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "apikeyspb.GetKeyRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "apikeyspb.Key", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "GetKey", + "fullName": "google.api.apikeys.v2.ApiKeys.GetKey", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 47, + "type": "FULL" + } + ] + }, + { + "regionTag": "apikeys_v2_generated_ApiKeys_GetKeyString_sync", + "title": "apikeys GetKeyString Sample", + "description": "GetKeyString get the key string for an API key.\n\nNOTE: Key is a global resource; hence the only supported value for\nlocation is global.", + "file": "Client/GetKeyString/main.go", + "language": "GO", + "clientMethod": { + "shortName": "GetKeyString", + "fullName": "google.api.apikeys.v2.Client.GetKeyString", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "apikeyspb.GetKeyStringRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "apikeyspb.GetKeyStringResponse", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "GetKeyString", + "fullName": "google.api.apikeys.v2.ApiKeys.GetKeyString", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 47, + "type": "FULL" + } + ] + }, + { + "regionTag": "apikeys_v2_generated_ApiKeys_GetOperation_sync", + "title": "apikeys GetOperation Sample", + "description": "GetOperation is a utility method from google.longrunning.Operations.", + "file": "Client/GetOperation/main.go", + "language": "GO", + "clientMethod": { + "shortName": "GetOperation", + "fullName": "google.api.apikeys.v2.Client.GetOperation", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "longrunningpb.GetOperationRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "longrunningpb.Operation", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "GetOperation", + "fullName": "google.api.apikeys.v2.ApiKeys.GetOperation", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 47, + "type": "FULL" + } + ] + }, + { + "regionTag": "apikeys_v2_generated_ApiKeys_ListKeys_sync", + "title": "apikeys ListKeys Sample", + "description": "ListKeys lists the API keys owned by a project. The key string of the API key\nisn’t included in the response.\n\nNOTE: Key is a global resource; hence the only supported value for\nlocation is global.", + "file": "Client/ListKeys/main.go", + "language": "GO", + "clientMethod": { + "shortName": "ListKeys", + "fullName": "google.api.apikeys.v2.Client.ListKeys", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "apikeyspb.ListKeysRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "KeyIterator", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "ListKeys", + "fullName": "google.api.apikeys.v2.ApiKeys.ListKeys", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 54, + "type": "FULL" + } + ] + }, + { + "regionTag": "apikeys_v2_generated_ApiKeys_LookupKey_sync", + "title": "apikeys LookupKey Sample", + "description": "LookupKey find the parent project and resource name of the API\nkey that matches the key string in the request. If the API key has been\npurged, resource name will not be set.\nThe service account must have the apikeys.keys.lookup permission\non the parent project.", + "file": "Client/LookupKey/main.go", + "language": "GO", + "clientMethod": { + "shortName": "LookupKey", + "fullName": "google.api.apikeys.v2.Client.LookupKey", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "apikeyspb.LookupKeyRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "apikeyspb.LookupKeyResponse", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "LookupKey", + "fullName": "google.api.apikeys.v2.ApiKeys.LookupKey", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 47, + "type": "FULL" + } + ] + }, + { + "regionTag": "apikeys_v2_generated_ApiKeys_UndeleteKey_sync", + "title": "apikeys UndeleteKey Sample", + "description": "UndeleteKey undeletes an API key which was deleted within 30 days.\n\nNOTE: Key is a global resource; hence the only supported value for\nlocation is global.", + "file": "Client/UndeleteKey/main.go", + "language": "GO", + "clientMethod": { + "shortName": "UndeleteKey", + "fullName": "google.api.apikeys.v2.Client.UndeleteKey", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "apikeyspb.UndeleteKeyRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "UndeleteKeyOperation", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "UndeleteKey", + "fullName": "google.api.apikeys.v2.ApiKeys.UndeleteKey", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 52, + "type": "FULL" + } + ] + }, + { + "regionTag": "apikeys_v2_generated_ApiKeys_UpdateKey_sync", + "title": "apikeys UpdateKey Sample", + "description": "UpdateKey patches the modifiable fields of an API key.\nThe key string of the API key isn’t included in the response.\n\nNOTE: Key is a global resource; hence the only supported value for\nlocation is global.", + "file": "Client/UpdateKey/main.go", + "language": "GO", + "clientMethod": { + "shortName": "UpdateKey", + "fullName": "google.api.apikeys.v2.Client.UpdateKey", + "parameters": [ + { + "type": "context.Context", + "name": "ctx" + }, + { + "type": "apikeyspb.UpdateKeyRequest", + "name": "req" + }, + { + "type": "...gax.CallOption", + "name": "opts" + } + ], + "resultType": "UpdateKeyOperation", + "client": { + "shortName": "Client", + "fullName": "google.api.apikeys.v2.Client" + }, + "method": { + "shortName": "UpdateKey", + "fullName": "google.api.apikeys.v2.ApiKeys.UpdateKey", + "service": { + "shortName": "ApiKeys", + "fullName": "google.api.apikeys.v2.ApiKeys" + } + } + }, + "origin": "API_DEFINITION", + "segments": [ + { + "start": 18, + "end": 52, + "type": "FULL" + } + ] + } + ] +} \ No newline at end of file diff --git a/internal/generated/snippets/asset/apiv1/snippet_metadata.google.cloud.asset.v1.json b/internal/generated/snippets/asset/apiv1/snippet_metadata.google.cloud.asset.v1.json index cc67d4e10837..f4b4366a93ed 100644 --- a/internal/generated/snippets/asset/apiv1/snippet_metadata.google.cloud.asset.v1.json +++ b/internal/generated/snippets/asset/apiv1/snippet_metadata.google.cloud.asset.v1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "cloud.google.com/go/asset/apiv1", - "version": "1.3.0", + "version": "1.4.0", "language": "GO", "apis": [ { diff --git a/internal/generated/snippets/asset/apiv1p2beta1/snippet_metadata.google.cloud.asset.v1p2beta1.json b/internal/generated/snippets/asset/apiv1p2beta1/snippet_metadata.google.cloud.asset.v1p2beta1.json index 615ded181537..bd25d78c1cb3 100644 --- a/internal/generated/snippets/asset/apiv1p2beta1/snippet_metadata.google.cloud.asset.v1p2beta1.json +++ b/internal/generated/snippets/asset/apiv1p2beta1/snippet_metadata.google.cloud.asset.v1p2beta1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "cloud.google.com/go/asset/apiv1p2beta1", - "version": "1.3.0", + "version": "1.4.0", "language": "GO", "apis": [ { diff --git a/internal/generated/snippets/asset/apiv1p5beta1/snippet_metadata.google.cloud.asset.v1p5beta1.json b/internal/generated/snippets/asset/apiv1p5beta1/snippet_metadata.google.cloud.asset.v1p5beta1.json index 6858b3205f02..6ea3c14d9565 100644 --- a/internal/generated/snippets/asset/apiv1p5beta1/snippet_metadata.google.cloud.asset.v1p5beta1.json +++ b/internal/generated/snippets/asset/apiv1p5beta1/snippet_metadata.google.cloud.asset.v1p5beta1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "cloud.google.com/go/asset/apiv1p5beta1", - "version": "1.3.0", + "version": "1.4.0", "language": "GO", "apis": [ { diff --git a/internal/generated/snippets/compute/apiv1/snippet_metadata.google.cloud.compute.v1.json b/internal/generated/snippets/compute/apiv1/snippet_metadata.google.cloud.compute.v1.json index 8cd1d2977cf1..5f1774c4b82f 100644 --- a/internal/generated/snippets/compute/apiv1/snippet_metadata.google.cloud.compute.v1.json +++ b/internal/generated/snippets/compute/apiv1/snippet_metadata.google.cloud.compute.v1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "cloud.google.com/go/compute/apiv1", - "version": "1.8.0", + "version": "1.9.0", "language": "GO", "apis": [ { diff --git a/internal/generated/snippets/documentai/apiv1/snippet_metadata.google.cloud.documentai.v1.json b/internal/generated/snippets/documentai/apiv1/snippet_metadata.google.cloud.documentai.v1.json index 13e4a2b85282..0dd0d44890be 100644 --- a/internal/generated/snippets/documentai/apiv1/snippet_metadata.google.cloud.documentai.v1.json +++ b/internal/generated/snippets/documentai/apiv1/snippet_metadata.google.cloud.documentai.v1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "cloud.google.com/go/documentai/apiv1", - "version": "1.4.0", + "version": "1.5.0", "language": "GO", "apis": [ { diff --git a/internal/generated/snippets/documentai/apiv1beta3/snippet_metadata.google.cloud.documentai.v1beta3.json b/internal/generated/snippets/documentai/apiv1beta3/snippet_metadata.google.cloud.documentai.v1beta3.json index 725e1530df46..2440f5516bdb 100644 --- a/internal/generated/snippets/documentai/apiv1beta3/snippet_metadata.google.cloud.documentai.v1beta3.json +++ b/internal/generated/snippets/documentai/apiv1beta3/snippet_metadata.google.cloud.documentai.v1beta3.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "cloud.google.com/go/documentai/apiv1beta3", - "version": "1.4.0", + "version": "1.5.0", "language": "GO", "apis": [ { diff --git a/internal/generated/snippets/go.mod b/internal/generated/snippets/go.mod index 7b3627458dad..b7408aedf24d 100644 --- a/internal/generated/snippets/go.mod +++ b/internal/generated/snippets/go.mod @@ -120,10 +120,13 @@ require ( cloud.google.com/go/workflows v1.1.0 github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect google.golang.org/api v0.93.0 - google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 + google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 ) -require cloud.google.com/go/apigeeregistry v0.0.0-00010101000000-000000000000 +require ( + cloud.google.com/go/apigeeregistry v0.0.0-00010101000000-000000000000 + cloud.google.com/go/apikeys v0.0.0-00010101000000-000000000000 +) require ( github.com/golang/protobuf v1.5.2 // indirect @@ -383,3 +386,5 @@ replace cloud.google.com/go/dataform => ../../../dataform replace cloud.google.com/go/beyondcorp => ../../../beyondcorp replace cloud.google.com/go/apigeeregistry => ../../../apigeeregistry + +replace cloud.google.com/go/apikeys => ../../../apikeys diff --git a/internal/generated/snippets/go.sum b/internal/generated/snippets/go.sum index 9d27b09ebe60..3a1c2d78996e 100644 --- a/internal/generated/snippets/go.sum +++ b/internal/generated/snippets/go.sum @@ -229,8 +229,9 @@ google.golang.org/genproto v0.0.0-20220722212130-b98a9ff5e252/go.mod h1:GkXuJDJ6 google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= -google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 h1:C2UVWqrgLYKrT5nh5oU6hLRm1AeEklCK5eloQA1NtFY= google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 h1:iw8luj804hqA2C43tq4SXb4OQNgaJU0KzSZHOHfdA4U= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/internal/godocfx/go.mod b/internal/godocfx/go.mod index 7a2283b230de..ed24dc162c22 100644 --- a/internal/godocfx/go.mod +++ b/internal/godocfx/go.mod @@ -32,7 +32,7 @@ require ( golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect google.golang.org/api v0.93.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 // indirect + google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 // indirect google.golang.org/grpc v1.48.0 // indirect google.golang.org/protobuf v1.28.1 // indirect ) diff --git a/internal/godocfx/go.sum b/internal/godocfx/go.sum index bada8cc5c75e..c5019a41cf14 100644 --- a/internal/godocfx/go.sum +++ b/internal/godocfx/go.sum @@ -272,8 +272,8 @@ google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220622131801-db39fadba55f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 h1:C2UVWqrgLYKrT5nh5oU6hLRm1AeEklCK5eloQA1NtFY= -google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 h1:iw8luj804hqA2C43tq4SXb4OQNgaJU0KzSZHOHfdA4U= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/pubsublite/apiv1/admin_client.go b/pubsublite/apiv1/admin_client.go index 6c1d3e143b43..62639fb10429 100644 --- a/pubsublite/apiv1/admin_client.go +++ b/pubsublite/apiv1/admin_client.go @@ -61,6 +61,10 @@ type AdminCallOptions struct { UpdateReservation []gax.CallOption DeleteReservation []gax.CallOption ListReservationTopics []gax.CallOption + CancelOperation []gax.CallOption + DeleteOperation []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultAdminGRPCClientOptions() []option.ClientOption { @@ -362,6 +366,38 @@ func defaultAdminCallOptions() *AdminCallOptions { }) }), }, + CancelOperation: []gax.CallOption{}, + DeleteOperation: []gax.CallOption{}, + GetOperation: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -390,6 +426,10 @@ type internalAdminClient interface { UpdateReservation(context.Context, *pubsublitepb.UpdateReservationRequest, ...gax.CallOption) (*pubsublitepb.Reservation, error) DeleteReservation(context.Context, *pubsublitepb.DeleteReservationRequest, ...gax.CallOption) error ListReservationTopics(context.Context, *pubsublitepb.ListReservationTopicsRequest, ...gax.CallOption) *StringIterator + CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error + DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // AdminClient is a client for interacting with Pub/Sub Lite API. @@ -553,6 +593,26 @@ func (c *AdminClient) ListReservationTopics(ctx context.Context, req *pubsublite return c.internalClient.ListReservationTopics(ctx, req, opts...) } +// CancelOperation is a utility method from google.longrunning.Operations. +func (c *AdminClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.CancelOperation(ctx, req, opts...) +} + +// DeleteOperation is a utility method from google.longrunning.Operations. +func (c *AdminClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteOperation(ctx, req, opts...) +} + +// GetOperation is a utility method from google.longrunning.Operations. +func (c *AdminClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *AdminClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // adminGRPCClient is a client for interacting with Pub/Sub Lite API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -574,6 +634,8 @@ type adminGRPCClient struct { // Users should not Close this client. LROClient **lroauto.OperationsClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -609,6 +671,7 @@ func NewAdminClient(ctx context.Context, opts ...option.ClientOption) (*AdminCli disableDeadlines: disableDeadlines, adminClient: pubsublitepb.NewAdminServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -1173,6 +1236,99 @@ func (c *adminGRPCClient) ListReservationTopics(ctx context.Context, req *pubsub return it } +func (c *adminGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *adminGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *adminGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *adminGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // SeekSubscriptionOperation manages a long-running operation from SeekSubscription. type SeekSubscriptionOperation struct { lro *longrunning.Operation @@ -1242,6 +1398,53 @@ func (op *SeekSubscriptionOperation) Name() string { return op.lro.Name() } +// OperationIterator manages a stream of *longrunningpb.Operation. +type OperationIterator struct { + items []*longrunningpb.Operation + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *OperationIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *OperationIterator) Next() (*longrunningpb.Operation, error) { + var item *longrunningpb.Operation + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *OperationIterator) bufLen() int { + return len(it.items) +} + +func (it *OperationIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + // ReservationIterator manages a stream of *pubsublitepb.Reservation. type ReservationIterator struct { items []*pubsublitepb.Reservation diff --git a/pubsublite/apiv1/admin_client_example_test.go b/pubsublite/apiv1/admin_client_example_test.go index 040a87c891ee..7576ddb32801 100644 --- a/pubsublite/apiv1/admin_client_example_test.go +++ b/pubsublite/apiv1/admin_client_example_test.go @@ -22,6 +22,7 @@ import ( pubsublite "cloud.google.com/go/pubsublite/apiv1" "google.golang.org/api/iterator" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewAdminClient() { @@ -444,3 +445,85 @@ func ExampleAdminClient_ListReservationTopics() { _ = resp } } + +func ExampleAdminClient_CancelOperation() { + ctx := context.Background() + c, err := pubsublite.NewAdminClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.CancelOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#CancelOperationRequest. + } + err = c.CancelOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleAdminClient_DeleteOperation() { + ctx := context.Background() + c, err := pubsublite.NewAdminClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.DeleteOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#DeleteOperationRequest. + } + err = c.DeleteOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleAdminClient_GetOperation() { + ctx := context.Background() + c, err := pubsublite.NewAdminClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAdminClient_ListOperations() { + ctx := context.Background() + c, err := pubsublite.NewAdminClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/pubsublite/apiv1/cursor_client.go b/pubsublite/apiv1/cursor_client.go index be9771e695db..c3c3b30dd661 100644 --- a/pubsublite/apiv1/cursor_client.go +++ b/pubsublite/apiv1/cursor_client.go @@ -29,6 +29,7 @@ import ( "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -42,6 +43,10 @@ type CursorCallOptions struct { StreamingCommitCursor []gax.CallOption CommitCursor []gax.CallOption ListPartitionCursors []gax.CallOption + CancelOperation []gax.CallOption + DeleteOperation []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultCursorGRPCClientOptions() []option.ClientOption { @@ -89,6 +94,38 @@ func defaultCursorCallOptions() *CursorCallOptions { }) }), }, + CancelOperation: []gax.CallOption{}, + DeleteOperation: []gax.CallOption{}, + GetOperation: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -100,6 +137,10 @@ type internalCursorClient interface { StreamingCommitCursor(context.Context, ...gax.CallOption) (pubsublitepb.CursorService_StreamingCommitCursorClient, error) CommitCursor(context.Context, *pubsublitepb.CommitCursorRequest, ...gax.CallOption) (*pubsublitepb.CommitCursorResponse, error) ListPartitionCursors(context.Context, *pubsublitepb.ListPartitionCursorsRequest, ...gax.CallOption) *PartitionCursorIterator + CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error + DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // CursorClient is a client for interacting with Pub/Sub Lite API. @@ -153,6 +194,26 @@ func (c *CursorClient) ListPartitionCursors(ctx context.Context, req *pubsublite return c.internalClient.ListPartitionCursors(ctx, req, opts...) } +// CancelOperation is a utility method from google.longrunning.Operations. +func (c *CursorClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.CancelOperation(ctx, req, opts...) +} + +// DeleteOperation is a utility method from google.longrunning.Operations. +func (c *CursorClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteOperation(ctx, req, opts...) +} + +// GetOperation is a utility method from google.longrunning.Operations. +func (c *CursorClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *CursorClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // cursorGRPCClient is a client for interacting with Pub/Sub Lite API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -169,6 +230,8 @@ type cursorGRPCClient struct { // The gRPC API client. cursorClient pubsublitepb.CursorServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -205,6 +268,7 @@ func NewCursorClient(ctx context.Context, opts ...option.ClientOption) (*CursorC disableDeadlines: disableDeadlines, cursorClient: pubsublitepb.NewCursorServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -317,6 +381,99 @@ func (c *cursorGRPCClient) ListPartitionCursors(ctx context.Context, req *pubsub return it } +func (c *cursorGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *cursorGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *cursorGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *cursorGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // PartitionCursorIterator manages a stream of *pubsublitepb.PartitionCursor. type PartitionCursorIterator struct { items []*pubsublitepb.PartitionCursor diff --git a/pubsublite/apiv1/cursor_client_example_test.go b/pubsublite/apiv1/cursor_client_example_test.go index db461b77b47c..8e0b257191de 100644 --- a/pubsublite/apiv1/cursor_client_example_test.go +++ b/pubsublite/apiv1/cursor_client_example_test.go @@ -23,6 +23,7 @@ import ( pubsublite "cloud.google.com/go/pubsublite/apiv1" "google.golang.org/api/iterator" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewCursorClient() { @@ -117,3 +118,85 @@ func ExampleCursorClient_ListPartitionCursors() { _ = resp } } + +func ExampleCursorClient_CancelOperation() { + ctx := context.Background() + c, err := pubsublite.NewCursorClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.CancelOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#CancelOperationRequest. + } + err = c.CancelOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleCursorClient_DeleteOperation() { + ctx := context.Background() + c, err := pubsublite.NewCursorClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.DeleteOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#DeleteOperationRequest. + } + err = c.DeleteOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleCursorClient_GetOperation() { + ctx := context.Background() + c, err := pubsublite.NewCursorClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCursorClient_ListOperations() { + ctx := context.Background() + c, err := pubsublite.NewCursorClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/pubsublite/apiv1/gapic_metadata.json b/pubsublite/apiv1/gapic_metadata.json index 4d82bdaf696f..f74883fbd51a 100644 --- a/pubsublite/apiv1/gapic_metadata.json +++ b/pubsublite/apiv1/gapic_metadata.json @@ -10,6 +10,11 @@ "grpc": { "libraryClient": "AdminClient", "rpcs": { + "CancelOperation": { + "methods": [ + "CancelOperation" + ] + }, "CreateReservation": { "methods": [ "CreateReservation" @@ -25,6 +30,11 @@ "CreateTopic" ] }, + "DeleteOperation": { + "methods": [ + "DeleteOperation" + ] + }, "DeleteReservation": { "methods": [ "DeleteReservation" @@ -40,6 +50,11 @@ "DeleteTopic" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "GetReservation": { "methods": [ "GetReservation" @@ -60,6 +75,11 @@ "GetTopicPartitions" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "ListReservationTopics": { "methods": [ "ListReservationTopics" @@ -114,11 +134,31 @@ "grpc": { "libraryClient": "CursorClient", "rpcs": { + "CancelOperation": { + "methods": [ + "CancelOperation" + ] + }, "CommitCursor": { "methods": [ "CommitCursor" ] }, + "DeleteOperation": { + "methods": [ + "DeleteOperation" + ] + }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "ListPartitionCursors": { "methods": [ "ListPartitionCursors" @@ -142,6 +182,26 @@ "methods": [ "AssignPartitions" ] + }, + "CancelOperation": { + "methods": [ + "CancelOperation" + ] + }, + "DeleteOperation": { + "methods": [ + "DeleteOperation" + ] + }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] } } } @@ -152,6 +212,26 @@ "grpc": { "libraryClient": "PublisherClient", "rpcs": { + "CancelOperation": { + "methods": [ + "CancelOperation" + ] + }, + "DeleteOperation": { + "methods": [ + "DeleteOperation" + ] + }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "Publish": { "methods": [ "Publish" @@ -166,6 +246,26 @@ "grpc": { "libraryClient": "SubscriberClient", "rpcs": { + "CancelOperation": { + "methods": [ + "CancelOperation" + ] + }, + "DeleteOperation": { + "methods": [ + "DeleteOperation" + ] + }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "Subscribe": { "methods": [ "Subscribe" @@ -180,6 +280,11 @@ "grpc": { "libraryClient": "TopicStatsClient", "rpcs": { + "CancelOperation": { + "methods": [ + "CancelOperation" + ] + }, "ComputeHeadCursor": { "methods": [ "ComputeHeadCursor" @@ -194,6 +299,21 @@ "methods": [ "ComputeTimeCursor" ] + }, + "DeleteOperation": { + "methods": [ + "DeleteOperation" + ] + }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] } } } diff --git a/pubsublite/apiv1/partition_assignment_client.go b/pubsublite/apiv1/partition_assignment_client.go index 4244ae8ff82f..ba2d36df395c 100644 --- a/pubsublite/apiv1/partition_assignment_client.go +++ b/pubsublite/apiv1/partition_assignment_client.go @@ -18,15 +18,22 @@ package pubsublite import ( "context" + "fmt" "math" + "net/url" + "time" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPartitionAssignmentClientHook clientHook @@ -34,6 +41,10 @@ var newPartitionAssignmentClientHook clientHook // PartitionAssignmentCallOptions contains the retry settings for each method of PartitionAssignmentClient. type PartitionAssignmentCallOptions struct { AssignPartitions []gax.CallOption + CancelOperation []gax.CallOption + DeleteOperation []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultPartitionAssignmentGRPCClientOptions() []option.ClientOption { @@ -51,6 +62,38 @@ func defaultPartitionAssignmentGRPCClientOptions() []option.ClientOption { func defaultPartitionAssignmentCallOptions() *PartitionAssignmentCallOptions { return &PartitionAssignmentCallOptions{ AssignPartitions: []gax.CallOption{}, + CancelOperation: []gax.CallOption{}, + DeleteOperation: []gax.CallOption{}, + GetOperation: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -60,6 +103,10 @@ type internalPartitionAssignmentClient interface { setGoogleClientInfo(...string) Connection() *grpc.ClientConn AssignPartitions(context.Context, ...gax.CallOption) (pubsublitepb.PartitionAssignmentService_AssignPartitionsClient, error) + CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error + DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // PartitionAssignmentClient is a client for interacting with Pub/Sub Lite API. @@ -108,6 +155,26 @@ func (c *PartitionAssignmentClient) AssignPartitions(ctx context.Context, opts . return c.internalClient.AssignPartitions(ctx, opts...) } +// CancelOperation is a utility method from google.longrunning.Operations. +func (c *PartitionAssignmentClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.CancelOperation(ctx, req, opts...) +} + +// DeleteOperation is a utility method from google.longrunning.Operations. +func (c *PartitionAssignmentClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteOperation(ctx, req, opts...) +} + +// GetOperation is a utility method from google.longrunning.Operations. +func (c *PartitionAssignmentClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *PartitionAssignmentClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // partitionAssignmentGRPCClient is a client for interacting with Pub/Sub Lite API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -124,6 +191,8 @@ type partitionAssignmentGRPCClient struct { // The gRPC API client. partitionAssignmentClient pubsublitepb.PartitionAssignmentServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -159,6 +228,7 @@ func NewPartitionAssignmentClient(ctx context.Context, opts ...option.ClientOpti disableDeadlines: disableDeadlines, partitionAssignmentClient: pubsublitepb.NewPartitionAssignmentServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -203,3 +273,96 @@ func (c *partitionAssignmentGRPCClient) AssignPartitions(ctx context.Context, op } return resp, nil } + +func (c *partitionAssignmentGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *partitionAssignmentGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *partitionAssignmentGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *partitionAssignmentGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} diff --git a/pubsublite/apiv1/partition_assignment_client_example_test.go b/pubsublite/apiv1/partition_assignment_client_example_test.go index e1e574031a70..36214d544380 100644 --- a/pubsublite/apiv1/partition_assignment_client_example_test.go +++ b/pubsublite/apiv1/partition_assignment_client_example_test.go @@ -21,7 +21,9 @@ import ( "io" pubsublite "cloud.google.com/go/pubsublite/apiv1" + "google.golang.org/api/iterator" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewPartitionAssignmentClient() { @@ -70,3 +72,85 @@ func ExamplePartitionAssignmentClient_AssignPartitions() { _ = resp } } + +func ExamplePartitionAssignmentClient_CancelOperation() { + ctx := context.Background() + c, err := pubsublite.NewPartitionAssignmentClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.CancelOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#CancelOperationRequest. + } + err = c.CancelOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExamplePartitionAssignmentClient_DeleteOperation() { + ctx := context.Background() + c, err := pubsublite.NewPartitionAssignmentClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.DeleteOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#DeleteOperationRequest. + } + err = c.DeleteOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExamplePartitionAssignmentClient_GetOperation() { + ctx := context.Background() + c, err := pubsublite.NewPartitionAssignmentClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePartitionAssignmentClient_ListOperations() { + ctx := context.Background() + c, err := pubsublite.NewPartitionAssignmentClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/pubsublite/apiv1/publisher_client.go b/pubsublite/apiv1/publisher_client.go index 7564b8953678..18eeca043b7e 100644 --- a/pubsublite/apiv1/publisher_client.go +++ b/pubsublite/apiv1/publisher_client.go @@ -18,22 +18,33 @@ package pubsublite import ( "context" + "fmt" "math" + "net/url" + "time" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPublisherClientHook clientHook // PublisherCallOptions contains the retry settings for each method of PublisherClient. type PublisherCallOptions struct { - Publish []gax.CallOption + Publish []gax.CallOption + CancelOperation []gax.CallOption + DeleteOperation []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultPublisherGRPCClientOptions() []option.ClientOption { @@ -50,7 +61,39 @@ func defaultPublisherGRPCClientOptions() []option.ClientOption { func defaultPublisherCallOptions() *PublisherCallOptions { return &PublisherCallOptions{ - Publish: []gax.CallOption{}, + Publish: []gax.CallOption{}, + CancelOperation: []gax.CallOption{}, + DeleteOperation: []gax.CallOption{}, + GetOperation: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -60,6 +103,10 @@ type internalPublisherClient interface { setGoogleClientInfo(...string) Connection() *grpc.ClientConn Publish(context.Context, ...gax.CallOption) (pubsublitepb.PublisherService_PublishClient, error) + CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error + DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // PublisherClient is a client for interacting with Pub/Sub Lite API. @@ -110,6 +157,26 @@ func (c *PublisherClient) Publish(ctx context.Context, opts ...gax.CallOption) ( return c.internalClient.Publish(ctx, opts...) } +// CancelOperation is a utility method from google.longrunning.Operations. +func (c *PublisherClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.CancelOperation(ctx, req, opts...) +} + +// DeleteOperation is a utility method from google.longrunning.Operations. +func (c *PublisherClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteOperation(ctx, req, opts...) +} + +// GetOperation is a utility method from google.longrunning.Operations. +func (c *PublisherClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *PublisherClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // publisherGRPCClient is a client for interacting with Pub/Sub Lite API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -126,6 +193,8 @@ type publisherGRPCClient struct { // The gRPC API client. publisherClient pubsublitepb.PublisherServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -163,6 +232,7 @@ func NewPublisherClient(ctx context.Context, opts ...option.ClientOption) (*Publ disableDeadlines: disableDeadlines, publisherClient: pubsublitepb.NewPublisherServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -207,3 +277,96 @@ func (c *publisherGRPCClient) Publish(ctx context.Context, opts ...gax.CallOptio } return resp, nil } + +func (c *publisherGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *publisherGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *publisherGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *publisherGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} diff --git a/pubsublite/apiv1/publisher_client_example_test.go b/pubsublite/apiv1/publisher_client_example_test.go index fa2116517fa0..0fd4f7b14f16 100644 --- a/pubsublite/apiv1/publisher_client_example_test.go +++ b/pubsublite/apiv1/publisher_client_example_test.go @@ -21,7 +21,9 @@ import ( "io" pubsublite "cloud.google.com/go/pubsublite/apiv1" + "google.golang.org/api/iterator" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewPublisherClient() { @@ -70,3 +72,85 @@ func ExamplePublisherClient_Publish() { _ = resp } } + +func ExamplePublisherClient_CancelOperation() { + ctx := context.Background() + c, err := pubsublite.NewPublisherClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.CancelOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#CancelOperationRequest. + } + err = c.CancelOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExamplePublisherClient_DeleteOperation() { + ctx := context.Background() + c, err := pubsublite.NewPublisherClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.DeleteOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#DeleteOperationRequest. + } + err = c.DeleteOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExamplePublisherClient_GetOperation() { + ctx := context.Background() + c, err := pubsublite.NewPublisherClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublisherClient_ListOperations() { + ctx := context.Background() + c, err := pubsublite.NewPublisherClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/pubsublite/apiv1/subscriber_client.go b/pubsublite/apiv1/subscriber_client.go index 2020df9ca388..4a0c2bcc7e1d 100644 --- a/pubsublite/apiv1/subscriber_client.go +++ b/pubsublite/apiv1/subscriber_client.go @@ -18,22 +18,33 @@ package pubsublite import ( "context" + "fmt" "math" + "net/url" + "time" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSubscriberClientHook clientHook // SubscriberCallOptions contains the retry settings for each method of SubscriberClient. type SubscriberCallOptions struct { - Subscribe []gax.CallOption + Subscribe []gax.CallOption + CancelOperation []gax.CallOption + DeleteOperation []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultSubscriberGRPCClientOptions() []option.ClientOption { @@ -50,7 +61,39 @@ func defaultSubscriberGRPCClientOptions() []option.ClientOption { func defaultSubscriberCallOptions() *SubscriberCallOptions { return &SubscriberCallOptions{ - Subscribe: []gax.CallOption{}, + Subscribe: []gax.CallOption{}, + CancelOperation: []gax.CallOption{}, + DeleteOperation: []gax.CallOption{}, + GetOperation: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -60,6 +103,10 @@ type internalSubscriberClient interface { setGoogleClientInfo(...string) Connection() *grpc.ClientConn Subscribe(context.Context, ...gax.CallOption) (pubsublitepb.SubscriberService_SubscribeClient, error) + CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error + DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // SubscriberClient is a client for interacting with Pub/Sub Lite API. @@ -102,6 +149,26 @@ func (c *SubscriberClient) Subscribe(ctx context.Context, opts ...gax.CallOption return c.internalClient.Subscribe(ctx, opts...) } +// CancelOperation is a utility method from google.longrunning.Operations. +func (c *SubscriberClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.CancelOperation(ctx, req, opts...) +} + +// DeleteOperation is a utility method from google.longrunning.Operations. +func (c *SubscriberClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteOperation(ctx, req, opts...) +} + +// GetOperation is a utility method from google.longrunning.Operations. +func (c *SubscriberClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *SubscriberClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // subscriberGRPCClient is a client for interacting with Pub/Sub Lite API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -118,6 +185,8 @@ type subscriberGRPCClient struct { // The gRPC API client. subscriberClient pubsublitepb.SubscriberServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -153,6 +222,7 @@ func NewSubscriberClient(ctx context.Context, opts ...option.ClientOption) (*Sub disableDeadlines: disableDeadlines, subscriberClient: pubsublitepb.NewSubscriberServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -197,3 +267,96 @@ func (c *subscriberGRPCClient) Subscribe(ctx context.Context, opts ...gax.CallOp } return resp, nil } + +func (c *subscriberGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *subscriberGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *subscriberGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *subscriberGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} diff --git a/pubsublite/apiv1/subscriber_client_example_test.go b/pubsublite/apiv1/subscriber_client_example_test.go index 292f55f540ed..de92fb7bc3a5 100644 --- a/pubsublite/apiv1/subscriber_client_example_test.go +++ b/pubsublite/apiv1/subscriber_client_example_test.go @@ -21,7 +21,9 @@ import ( "io" pubsublite "cloud.google.com/go/pubsublite/apiv1" + "google.golang.org/api/iterator" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewSubscriberClient() { @@ -70,3 +72,85 @@ func ExampleSubscriberClient_Subscribe() { _ = resp } } + +func ExampleSubscriberClient_CancelOperation() { + ctx := context.Background() + c, err := pubsublite.NewSubscriberClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.CancelOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#CancelOperationRequest. + } + err = c.CancelOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleSubscriberClient_DeleteOperation() { + ctx := context.Background() + c, err := pubsublite.NewSubscriberClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.DeleteOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#DeleteOperationRequest. + } + err = c.DeleteOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleSubscriberClient_GetOperation() { + ctx := context.Background() + c, err := pubsublite.NewSubscriberClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubscriberClient_ListOperations() { + ctx := context.Background() + c, err := pubsublite.NewSubscriberClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/pubsublite/apiv1/topic_stats_client.go b/pubsublite/apiv1/topic_stats_client.go index 7cb67894683c..05fd8d2c903b 100644 --- a/pubsublite/apiv1/topic_stats_client.go +++ b/pubsublite/apiv1/topic_stats_client.go @@ -24,13 +24,16 @@ import ( "time" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newTopicStatsClientHook clientHook @@ -40,6 +43,10 @@ type TopicStatsCallOptions struct { ComputeMessageStats []gax.CallOption ComputeHeadCursor []gax.CallOption ComputeTimeCursor []gax.CallOption + CancelOperation []gax.CallOption + DeleteOperation []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultTopicStatsGRPCClientOptions() []option.ClientOption { @@ -101,6 +108,38 @@ func defaultTopicStatsCallOptions() *TopicStatsCallOptions { }) }), }, + CancelOperation: []gax.CallOption{}, + DeleteOperation: []gax.CallOption{}, + GetOperation: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -112,6 +151,10 @@ type internalTopicStatsClient interface { ComputeMessageStats(context.Context, *pubsublitepb.ComputeMessageStatsRequest, ...gax.CallOption) (*pubsublitepb.ComputeMessageStatsResponse, error) ComputeHeadCursor(context.Context, *pubsublitepb.ComputeHeadCursorRequest, ...gax.CallOption) (*pubsublitepb.ComputeHeadCursorResponse, error) ComputeTimeCursor(context.Context, *pubsublitepb.ComputeTimeCursorRequest, ...gax.CallOption) (*pubsublitepb.ComputeTimeCursorResponse, error) + CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error + DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // TopicStatsClient is a client for interacting with Pub/Sub Lite API. @@ -170,6 +213,26 @@ func (c *TopicStatsClient) ComputeTimeCursor(ctx context.Context, req *pubsublit return c.internalClient.ComputeTimeCursor(ctx, req, opts...) } +// CancelOperation is a utility method from google.longrunning.Operations. +func (c *TopicStatsClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.CancelOperation(ctx, req, opts...) +} + +// DeleteOperation is a utility method from google.longrunning.Operations. +func (c *TopicStatsClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteOperation(ctx, req, opts...) +} + +// GetOperation is a utility method from google.longrunning.Operations. +func (c *TopicStatsClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *TopicStatsClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // topicStatsGRPCClient is a client for interacting with Pub/Sub Lite API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -186,6 +249,8 @@ type topicStatsGRPCClient struct { // The gRPC API client. topicStatsClient pubsublitepb.TopicStatsServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -220,6 +285,7 @@ func NewTopicStatsClient(ctx context.Context, opts ...option.ClientOption) (*Top disableDeadlines: disableDeadlines, topicStatsClient: pubsublitepb.NewTopicStatsServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -315,3 +381,96 @@ func (c *topicStatsGRPCClient) ComputeTimeCursor(ctx context.Context, req *pubsu } return resp, nil } + +func (c *topicStatsGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *topicStatsGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *topicStatsGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *topicStatsGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} diff --git a/pubsublite/apiv1/topic_stats_client_example_test.go b/pubsublite/apiv1/topic_stats_client_example_test.go index 5527ef747364..6d84debff9f8 100644 --- a/pubsublite/apiv1/topic_stats_client_example_test.go +++ b/pubsublite/apiv1/topic_stats_client_example_test.go @@ -20,7 +20,9 @@ import ( "context" pubsublite "cloud.google.com/go/pubsublite/apiv1" + "google.golang.org/api/iterator" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewTopicStatsClient() { @@ -94,3 +96,85 @@ func ExampleTopicStatsClient_ComputeTimeCursor() { // TODO: Use resp. _ = resp } + +func ExampleTopicStatsClient_CancelOperation() { + ctx := context.Background() + c, err := pubsublite.NewTopicStatsClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.CancelOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#CancelOperationRequest. + } + err = c.CancelOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleTopicStatsClient_DeleteOperation() { + ctx := context.Background() + c, err := pubsublite.NewTopicStatsClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.DeleteOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#DeleteOperationRequest. + } + err = c.DeleteOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleTopicStatsClient_GetOperation() { + ctx := context.Background() + c, err := pubsublite.NewTopicStatsClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTopicStatsClient_ListOperations() { + ctx := context.Background() + c, err := pubsublite.NewTopicStatsClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/pubsublite/go.mod b/pubsublite/go.mod index 146314dab1f2..19d8708db2df 100644 --- a/pubsublite/go.mod +++ b/pubsublite/go.mod @@ -11,7 +11,7 @@ require ( github.com/googleapis/gax-go/v2 v2.4.0 golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f google.golang.org/api v0.93.0 - google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 + google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.1 ) diff --git a/pubsublite/go.sum b/pubsublite/go.sum index 5e779ebf9983..f6e3907a8051 100644 --- a/pubsublite/go.sum +++ b/pubsublite/go.sum @@ -600,8 +600,8 @@ google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 h1:hw4Y42zL1VyVKxPgRHHh191fpVBGV8sNVmcow5Z8VXY= -google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09 h1:iw8luj804hqA2C43tq4SXb4OQNgaJU0KzSZHOHfdA4U= +google.golang.org/genproto v0.0.0-20220819153447-c7cd466b0e09/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=