Skip to content

Commit ec3b666

Browse files
authored
feat(internal/config): add discovery LRO polling configuration for Rust (#3111)
Add RustDiscovery and RustPoller types to support LRO polling for discovery-based APIs (e.g., Compute Engine), which use different polling endpoints based on resource scope.
1 parent 9f278bf commit ec3b666

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

internal/config/language.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ type RustCrate struct {
9595

9696
// NameOverrides contains codec-level overrides for type and service names.
9797
NameOverrides string `yaml:"name_overrides,omitempty"`
98+
99+
// Discovery contains discovery-specific configuration for LRO polling.
100+
Discovery *RustDiscovery `yaml:"discovery,omitempty"`
98101
}
99102

100103
// RustPackageDependency represents a package dependency configuration.
@@ -144,3 +147,21 @@ type RustPaginationOverride struct {
144147
// ItemField is the name of the field used for items.
145148
ItemField string `yaml:"item_field"`
146149
}
150+
151+
// RustDiscovery contains discovery-specific configuration for LRO polling.
152+
type RustDiscovery struct {
153+
// OperationID is the ID of the LRO operation type (e.g., ".google.cloud.compute.v1.Operation").
154+
OperationID string `yaml:"operation_id"`
155+
156+
// Pollers is a list of LRO polling configurations.
157+
Pollers []RustPoller `yaml:"pollers,omitempty"`
158+
}
159+
160+
// RustPoller defines how to find a suitable poller RPC for discovery APIs.
161+
type RustPoller struct {
162+
// Prefix is an acceptable prefix for the URL path (e.g., "compute/v1/projects/{project}/zones/{zone}").
163+
Prefix string `yaml:"prefix"`
164+
165+
// MethodID is the corresponding method ID (e.g., ".google.cloud.compute.v1.zoneOperations.get").
166+
MethodID string `yaml:"method_id"`
167+
}

internal/librarian/internal/rust/codec.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ func toSidekickConfig(library *config.Library, channel *config.Channel, googleap
7272
}
7373
}
7474
}
75+
if library.Rust.Discovery != nil {
76+
pollers := make([]*sidekickconfig.Poller, len(library.Rust.Discovery.Pollers))
77+
for i, poller := range library.Rust.Discovery.Pollers {
78+
pollers[i] = &sidekickconfig.Poller{
79+
Prefix: poller.Prefix,
80+
MethodID: poller.MethodID,
81+
}
82+
}
83+
sidekickCfg.Discovery = &sidekickconfig.Discovery{
84+
OperationID: library.Rust.Discovery.OperationID,
85+
Pollers: pollers,
86+
}
87+
}
7588
}
7689
return sidekickCfg
7790
}

internal/librarian/internal/rust/codec_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,71 @@ func TestToSidekickConfig(t *testing.T) {
460460
},
461461
},
462462
},
463+
{
464+
name: "with discovery LRO polling config",
465+
library: &config.Library{
466+
Name: "google-cloud-compute-v1",
467+
SpecificationFormat: "discovery",
468+
Rust: &config.RustCrate{
469+
Discovery: &config.RustDiscovery{
470+
OperationID: ".google.cloud.compute.v1.Operation",
471+
Pollers: []config.RustPoller{
472+
{
473+
Prefix: "compute/v1/projects/{project}/zones/{zone}",
474+
MethodID: ".google.cloud.compute.v1.zoneOperations.get",
475+
},
476+
{
477+
Prefix: "compute/v1/projects/{project}/regions/{region}",
478+
MethodID: ".google.cloud.compute.v1.regionOperations.get",
479+
},
480+
{
481+
Prefix: "compute/v1/projects/{project}",
482+
MethodID: ".google.cloud.compute.v1.globalOperations.get",
483+
},
484+
},
485+
},
486+
},
487+
},
488+
channel: &config.Channel{
489+
Path: "discoveries/compute.v1.json",
490+
ServiceConfig: "google/cloud/compute/v1/compute_v1.yaml",
491+
},
492+
googleapisDir: "/tmp/googleapis",
493+
discoveryDir: "/tmp/discovery-artifact-manager",
494+
want: &sidekickconfig.Config{
495+
General: sidekickconfig.GeneralConfig{
496+
Language: "rust",
497+
SpecificationFormat: "disco",
498+
ServiceConfig: "google/cloud/compute/v1/compute_v1.yaml",
499+
SpecificationSource: "discoveries/compute.v1.json",
500+
},
501+
Source: map[string]string{
502+
"googleapis-root": "/tmp/googleapis",
503+
"discovery-root": "/tmp/discovery-artifact-manager",
504+
"roots": "discovery,googleapis",
505+
},
506+
Codec: map[string]string{
507+
"package-name-override": "google-cloud-compute-v1",
508+
},
509+
Discovery: &sidekickconfig.Discovery{
510+
OperationID: ".google.cloud.compute.v1.Operation",
511+
Pollers: []*sidekickconfig.Poller{
512+
{
513+
Prefix: "compute/v1/projects/{project}/zones/{zone}",
514+
MethodID: ".google.cloud.compute.v1.zoneOperations.get",
515+
},
516+
{
517+
Prefix: "compute/v1/projects/{project}/regions/{region}",
518+
MethodID: ".google.cloud.compute.v1.regionOperations.get",
519+
},
520+
{
521+
Prefix: "compute/v1/projects/{project}",
522+
MethodID: ".google.cloud.compute.v1.globalOperations.get",
523+
},
524+
},
525+
},
526+
},
527+
},
463528
} {
464529
t.Run(test.name, func(t *testing.T) {
465530
got := toSidekickConfig(test.library, test.channel, test.googleapisDir, test.discoveryDir)

0 commit comments

Comments
 (0)