Debian Codegraph @

osconfig/agentendpoint/apiv1/agent_endpoint_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package agentendpoint
18
19 import (
20 "context"
21 "log/slog"
22 "math"
23 "time"
24
25 agentendpointpb "cloud.google.com/go/osconfig/agentendpoint/apiv1/agentendpointpb"
26 gax "github.com/googleapis/gax-go/v2"
27 "google.golang.org/api/option"
28 "google.golang.org/api/option/internaloption"
29 gtransport "google.golang.org/api/transport/grpc"
30 "google.golang.org/grpc"
31 "google.golang.org/grpc/codes"
32 )
33
34 var newClientHook clientHook
35
36 // CallOptions contains the retry settings for each method of Client.
37 type CallOptions struct {
38 ReceiveTaskNotification []gax.CallOption
39 StartNextTask []gax.CallOption
40 ReportTaskProgress []gax.CallOption
41 ReportTaskComplete []gax.CallOption
42 RegisterAgent []gax.CallOption
43 ReportInventory []gax.CallOption
44 }
45
46 func defaultGRPCClientOptions() []option.ClientOption {
47 return []option.ClientOption{
48 internaloption.WithDefaultEndpoint("osconfig.googleapis.com:443"),
49 internaloption.WithDefaultEndpointTemplate("osconfig.UNIVERSE_DOMAIN:443"),
50 internaloption.WithDefaultMTLSEndpoint("osconfig.mtls.googleapis.com:443"),
51 internaloption.WithDefaultUniverseDomain("googleapis.com"),
52 internaloption.WithDefaultAudience("https://osconfig.googleapis.com/"),
53 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
54 internaloption.EnableJwtWithScope(),
55 internaloption.EnableNewAuthLibrary(),
56 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
57 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
58 }
59 }
60
61 func defaultCallOptions() *CallOptions {
62 return &CallOptions{
63 ReceiveTaskNotification: []gax.CallOption{
64 gax.WithRetry(func() gax.Retryer {
65 return gax.OnCodes([]codes.Code{
66 codes.DeadlineExceeded,
67 codes.Canceled,
68 codes.Aborted,
69 codes.Internal,
70 codes.Unavailable,
71 }, gax.Backoff{
72 Initial: 1000 * time.Millisecond,
73 Max: 60000 * time.Millisecond,
74 Multiplier: 1.30,
75 })
76 }),
77 },
78 StartNextTask: []gax.CallOption{
79 gax.WithTimeout(60000 * time.Millisecond),
80 gax.WithRetry(func() gax.Retryer {
81 return gax.OnCodes([]codes.Code{
82 codes.Unavailable,
83 }, gax.Backoff{
84 Initial: 1000 * time.Millisecond,
85 Max: 60000 * time.Millisecond,
86 Multiplier: 1.30,
87 })
88 }),
89 },
90 ReportTaskProgress: []gax.CallOption{
91 gax.WithTimeout(60000 * time.Millisecond),
92 gax.WithRetry(func() gax.Retryer {
93 return gax.OnCodes([]codes.Code{
94 codes.Unavailable,
95 }, gax.Backoff{
96 Initial: 1000 * time.Millisecond,
97 Max: 60000 * time.Millisecond,
98 Multiplier: 1.30,
99 })
100 }),
101 },
102 ReportTaskComplete: []gax.CallOption{
103 gax.WithTimeout(60000 * time.Millisecond),
104 gax.WithRetry(func() gax.Retryer {
105 return gax.OnCodes([]codes.Code{
106 codes.Unavailable,
107 }, gax.Backoff{
108 Initial: 1000 * time.Millisecond,
109 Max: 60000 * time.Millisecond,
110 Multiplier: 1.30,
111 })
112 }),
113 },
114 RegisterAgent: []gax.CallOption{
115 gax.WithTimeout(60000 * time.Millisecond),
116 gax.WithRetry(func() gax.Retryer {
117 return gax.OnCodes([]codes.Code{
118 codes.Unavailable,
119 }, gax.Backoff{
120 Initial: 1000 * time.Millisecond,
121 Max: 60000 * time.Millisecond,
122 Multiplier: 1.30,
123 })
124 }),
125 },
126 ReportInventory: []gax.CallOption{
127 gax.WithTimeout(60000 * time.Millisecond),
128 gax.WithRetry(func() gax.Retryer {
129 return gax.OnCodes([]codes.Code{
130 codes.Unavailable,
131 }, gax.Backoff{
132 Initial: 1000 * time.Millisecond,
133 Max: 60000 * time.Millisecond,
134 Multiplier: 1.30,
135 })
136 }),
137 },
138 }
139 }
140
141 // internalClient is an interface that defines the methods available from OS Config API.
142 type internalClient interface {
143 Close() error
144 setGoogleClientInfo(...string)
145 Connection() *grpc.ClientConn
146 ReceiveTaskNotification(context.Context, *agentendpointpb.ReceiveTaskNotificationRequest, ...gax.CallOption) (agentendpointpb.AgentEndpointService_ReceiveTaskNotificationClient, error)
147 StartNextTask(context.Context, *agentendpointpb.StartNextTaskRequest, ...gax.CallOption) (*agentendpointpb.StartNextTaskResponse, error)
148 ReportTaskProgress(context.Context, *agentendpointpb.ReportTaskProgressRequest, ...gax.CallOption) (*agentendpointpb.ReportTaskProgressResponse, error)
149 ReportTaskComplete(context.Context, *agentendpointpb.ReportTaskCompleteRequest, ...gax.CallOption) (*agentendpointpb.ReportTaskCompleteResponse, error)
150 RegisterAgent(context.Context, *agentendpointpb.RegisterAgentRequest, ...gax.CallOption) (*agentendpointpb.RegisterAgentResponse, error)
151 ReportInventory(context.Context, *agentendpointpb.ReportInventoryRequest, ...gax.CallOption) (*agentendpointpb.ReportInventoryResponse, error)
152 }
153
154 // Client is a client for interacting with OS Config API.
155 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
156 //
157 // OS Config agent endpoint API.
158 type Client struct {
159 // The internal transport-dependent client.
160 internalClient internalClient
161
162 // The call options for this service.
163 CallOptions *CallOptions
164 }
165
166 // Wrapper methods routed to the internal client.
167
168 // Close closes the connection to the API service. The user should invoke this when
169 // the client is no longer required.
170 func (c *Client) Close() error {
171 return c.internalClient.Close()
172 }
173
174 // setGoogleClientInfo sets the name and version of the application in
175 // the `x-goog-api-client` header passed on each request. Intended for
176 // use by Google-written clients.
177 func (c *Client) setGoogleClientInfo(keyval ...string) {
178 c.internalClient.setGoogleClientInfo(keyval...)
179 }
180
181 // Connection returns a connection to the API service.
182 //
183 // Deprecated: Connections are now pooled so this method does not always
184 // return the same resource.
185 func (c *Client) Connection() *grpc.ClientConn {
186 return c.internalClient.Connection()
187 }
188
189 // ReceiveTaskNotification stream established by client to receive Task notifications.
190 func (c *Client) ReceiveTaskNotification(ctx context.Context, req *agentendpointpb.ReceiveTaskNotificationRequest, opts ...gax.CallOption) (agentendpointpb.AgentEndpointService_ReceiveTaskNotificationClient, error) {
191 return c.internalClient.ReceiveTaskNotification(ctx, req, opts...)
192 }
193
194 // StartNextTask signals the start of a task execution and returns the task info.
195 func (c *Client) StartNextTask(ctx context.Context, req *agentendpointpb.StartNextTaskRequest, opts ...gax.CallOption) (*agentendpointpb.StartNextTaskResponse, error) {
196 return c.internalClient.StartNextTask(ctx, req, opts...)
197 }
198
199 // ReportTaskProgress signals an intermediary progress checkpoint in task execution.
200 func (c *Client) ReportTaskProgress(ctx context.Context, req *agentendpointpb.ReportTaskProgressRequest, opts ...gax.CallOption) (*agentendpointpb.ReportTaskProgressResponse, error) {
201 return c.internalClient.ReportTaskProgress(ctx, req, opts...)
202 }
203
204 // ReportTaskComplete signals that the task execution is complete and optionally returns the next
205 // task.
206 func (c *Client) ReportTaskComplete(ctx context.Context, req *agentendpointpb.ReportTaskCompleteRequest, opts ...gax.CallOption) (*agentendpointpb.ReportTaskCompleteResponse, error) {
207 return c.internalClient.ReportTaskComplete(ctx, req, opts...)
208 }
209
210 // RegisterAgent registers the agent running on the VM.
211 func (c *Client) RegisterAgent(ctx context.Context, req *agentendpointpb.RegisterAgentRequest, opts ...gax.CallOption) (*agentendpointpb.RegisterAgentResponse, error) {
212 return c.internalClient.RegisterAgent(ctx, req, opts...)
213 }
214
215 // ReportInventory reports the VMs current inventory.
216 func (c *Client) ReportInventory(ctx context.Context, req *agentendpointpb.ReportInventoryRequest, opts ...gax.CallOption) (*agentendpointpb.ReportInventoryResponse, error) {
217 return c.internalClient.ReportInventory(ctx, req, opts...)
218 }
219
220 // gRPCClient is a client for interacting with OS Config API over gRPC transport.
221 //
222 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
223 type gRPCClient struct {
224 // Connection pool of gRPC connections to the service.
225 connPool gtransport.ConnPool
226
227 // Points back to the CallOptions field of the containing Client
228 CallOptions **CallOptions
229
230 // The gRPC API client.
231 client agentendpointpb.AgentEndpointServiceClient
232
233 // The x-goog-* metadata to be sent with each request.
234 xGoogHeaders []string
235
236 logger *slog.Logger
237 }
238
239 // NewClient creates a new agent endpoint service client based on gRPC.
240 // The returned client must be Closed when it is done being used to clean up its underlying connections.
241 //
242 // OS Config agent endpoint API.
243 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
244 clientOpts := defaultGRPCClientOptions()
245 if newClientHook != nil {
246 hookOpts, err := newClientHook(ctx, clientHookParams{})
247 if err != nil {
248 return nil, err
249 }
250 clientOpts = append(clientOpts, hookOpts...)
251 }
252
253 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
254 if err != nil {
255 return nil, err
256 }
257 client := Client{CallOptions: defaultCallOptions()}
258
259 c := &gRPCClient{
260 connPool: connPool,
261 client: agentendpointpb.NewAgentEndpointServiceClient(connPool),
262 CallOptions: &client.CallOptions,
263 logger: internaloption.GetLogger(opts),
264 }
265 c.setGoogleClientInfo()
266
267 client.internalClient = c
268
269 return &client, nil
270 }
271
272 // Connection returns a connection to the API service.
273 //
274 // Deprecated: Connections are now pooled so this method does not always
275 // return the same resource.
276 func (c *gRPCClient) Connection() *grpc.ClientConn {
277 return c.connPool.Conn()
278 }
279
280 // setGoogleClientInfo sets the name and version of the application in
281 // the `x-goog-api-client` header passed on each request. Intended for
282 // use by Google-written clients.
283 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
284 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
285 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
286 c.xGoogHeaders = []string{
287 "x-goog-api-client", gax.XGoogHeader(kv...),
288 }
289 }
290
291 // Close closes the connection to the API service. The user should invoke this when
292 // the client is no longer required.
293 func (c *gRPCClient) Close() error {
294 return c.connPool.Close()
295 }
296
297 func (c *gRPCClient) ReceiveTaskNotification(ctx context.Context, req *agentendpointpb.ReceiveTaskNotificationRequest, opts ...gax.CallOption) (agentendpointpb.AgentEndpointService_ReceiveTaskNotificationClient, error) {
298 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
299 opts = append((*c.CallOptions).ReceiveTaskNotification[0:len((*c.CallOptions).ReceiveTaskNotification):len((*c.CallOptions).ReceiveTaskNotification)], opts...)
300 var resp agentendpointpb.AgentEndpointService_ReceiveTaskNotificationClient
301 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
302 var err error
303 c.logger.DebugContext(ctx, "api streaming client request", "serviceName", serviceName, "rpcName", "ReceiveTaskNotification")
304 resp, err = c.client.ReceiveTaskNotification(ctx, req, settings.GRPC...)
305 c.logger.DebugContext(ctx, "api streaming client response", "serviceName", serviceName, "rpcName", "ReceiveTaskNotification")
306 return err
307 }, opts...)
308 if err != nil {
309 return nil, err
310 }
311 return resp, nil
312 }
313
314 func (c *gRPCClient) StartNextTask(ctx context.Context, req *agentendpointpb.StartNextTaskRequest, opts ...gax.CallOption) (*agentendpointpb.StartNextTaskResponse, error) {
315 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
316 opts = append((*c.CallOptions).StartNextTask[0:len((*c.CallOptions).StartNextTask):len((*c.CallOptions).StartNextTask)], opts...)
317 var resp *agentendpointpb.StartNextTaskResponse
318 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
319 var err error
320 resp, err = executeRPC(ctx, c.client.StartNextTask, req, settings.GRPC, c.logger, "StartNextTask")
321 return err
322 }, opts...)
323 if err != nil {
324 return nil, err
325 }
326 return resp, nil
327 }
328
329 func (c *gRPCClient) ReportTaskProgress(ctx context.Context, req *agentendpointpb.ReportTaskProgressRequest, opts ...gax.CallOption) (*agentendpointpb.ReportTaskProgressResponse, error) {
330 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
331 opts = append((*c.CallOptions).ReportTaskProgress[0:len((*c.CallOptions).ReportTaskProgress):len((*c.CallOptions).ReportTaskProgress)], opts...)
332 var resp *agentendpointpb.ReportTaskProgressResponse
333 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
334 var err error
335 resp, err = executeRPC(ctx, c.client.ReportTaskProgress, req, settings.GRPC, c.logger, "ReportTaskProgress")
336 return err
337 }, opts...)
338 if err != nil {
339 return nil, err
340 }
341 return resp, nil
342 }
343
344 func (c *gRPCClient) ReportTaskComplete(ctx context.Context, req *agentendpointpb.ReportTaskCompleteRequest, opts ...gax.CallOption) (*agentendpointpb.ReportTaskCompleteResponse, error) {
345 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
346 opts = append((*c.CallOptions).ReportTaskComplete[0:len((*c.CallOptions).ReportTaskComplete):len((*c.CallOptions).ReportTaskComplete)], opts...)
347 var resp *agentendpointpb.ReportTaskCompleteResponse
348 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
349 var err error
350 resp, err = executeRPC(ctx, c.client.ReportTaskComplete, req, settings.GRPC, c.logger, "ReportTaskComplete")
351 return err
352 }, opts...)
353 if err != nil {
354 return nil, err
355 }
356 return resp, nil
357 }
358
359 func (c *gRPCClient) RegisterAgent(ctx context.Context, req *agentendpointpb.RegisterAgentRequest, opts ...gax.CallOption) (*agentendpointpb.RegisterAgentResponse, error) {
360 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
361 opts = append((*c.CallOptions).RegisterAgent[0:len((*c.CallOptions).RegisterAgent):len((*c.CallOptions).RegisterAgent)], opts...)
362 var resp *agentendpointpb.RegisterAgentResponse
363 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
364 var err error
365 resp, err = executeRPC(ctx, c.client.RegisterAgent, req, settings.GRPC, c.logger, "RegisterAgent")
366 return err
367 }, opts...)
368 if err != nil {
369 return nil, err
370 }
371 return resp, nil
372 }
373
374 func (c *gRPCClient) ReportInventory(ctx context.Context, req *agentendpointpb.ReportInventoryRequest, opts ...gax.CallOption) (*agentendpointpb.ReportInventoryResponse, error) {
375 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
376 opts = append((*c.CallOptions).ReportInventory[0:len((*c.CallOptions).ReportInventory):len((*c.CallOptions).ReportInventory)], opts...)
377 var resp *agentendpointpb.ReportInventoryResponse
378 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
379 var err error
380 resp, err = executeRPC(ctx, c.client.ReportInventory, req, settings.GRPC, c.logger, "ReportInventory")
381 return err
382 }, opts...)
383 if err != nil {
384 return nil, err
385 }
386 return resp, nil
387 }