| 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/apiv1beta/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 |
LookupEffectiveGuestPolicy []gax.CallOption |
| 43 |
RegisterAgent []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 |
LookupEffectiveGuestPolicy: []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 |
RegisterAgent: []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 |
LookupEffectiveGuestPolicy(context.Context, *agentendpointpb.LookupEffectiveGuestPolicyRequest, ...gax.CallOption) (*agentendpointpb.EffectiveGuestPolicy, error) |
| 151 |
RegisterAgent(context.Context, *agentendpointpb.RegisterAgentRequest, ...gax.CallOption) (*agentendpointpb.RegisterAgentResponse, 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 |
// LookupEffectiveGuestPolicy lookup the effective guest policy that applies to a VM instance. This |
| 211 |
// lookup merges all policies that are assigned to the instance ancestry. |
| 212 |
func (c *Client) LookupEffectiveGuestPolicy(ctx context.Context, req *agentendpointpb.LookupEffectiveGuestPolicyRequest, opts ...gax.CallOption) (*agentendpointpb.EffectiveGuestPolicy, error) { |
| 213 |
return c.internalClient.LookupEffectiveGuestPolicy(ctx, req, opts...) |
| 214 |
} |
| 215 |
|
| 216 |
// RegisterAgent registers the agent running on the VM. |
| 217 |
func (c *Client) RegisterAgent(ctx context.Context, req *agentendpointpb.RegisterAgentRequest, opts ...gax.CallOption) (*agentendpointpb.RegisterAgentResponse, error) { |
| 218 |
return c.internalClient.RegisterAgent(ctx, req, opts...) |
| 219 |
} |
| 220 |
|
| 221 |
// gRPCClient is a client for interacting with OS Config API over gRPC transport. |
| 222 |
// |
| 223 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 224 |
type gRPCClient struct { |
| 225 |
// Connection pool of gRPC connections to the service. |
| 226 |
connPool gtransport.ConnPool |
| 227 |
|
| 228 |
// Points back to the CallOptions field of the containing Client |
| 229 |
CallOptions **CallOptions |
| 230 |
|
| 231 |
// The gRPC API client. |
| 232 |
client agentendpointpb.AgentEndpointServiceClient |
| 233 |
|
| 234 |
// The x-goog-* metadata to be sent with each request. |
| 235 |
xGoogHeaders []string |
| 236 |
|
| 237 |
logger *slog.Logger |
| 238 |
} |
| 239 |
|
| 240 |
// NewClient creates a new agent endpoint service client based on gRPC. |
| 241 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 242 |
// |
| 243 |
// OS Config agent endpoint API. |
| 244 |
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 245 |
clientOpts := defaultGRPCClientOptions() |
| 246 |
if newClientHook != nil { |
| 247 |
hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| 248 |
if err != nil { |
| 249 |
return nil, err |
| 250 |
} |
| 251 |
clientOpts = append(clientOpts, hookOpts...) |
| 252 |
} |
| 253 |
|
| 254 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 255 |
if err != nil { |
| 256 |
return nil, err |
| 257 |
} |
| 258 |
client := Client{CallOptions: defaultCallOptions()} |
| 259 |
|
| 260 |
c := &gRPCClient{ |
| 261 |
connPool: connPool, |
| 262 |
client: agentendpointpb.NewAgentEndpointServiceClient(connPool), |
| 263 |
CallOptions: &client.CallOptions, |
| 264 |
logger: internaloption.GetLogger(opts), |
| 265 |
} |
| 266 |
c.setGoogleClientInfo() |
| 267 |
|
| 268 |
client.internalClient = c |
| 269 |
|
| 270 |
return &client, nil |
| 271 |
} |
| 272 |
|
| 273 |
// Connection returns a connection to the API service. |
| 274 |
// |
| 275 |
// Deprecated: Connections are now pooled so this method does not always |
| 276 |
// return the same resource. |
| 277 |
func (c *gRPCClient) Connection() *grpc.ClientConn { |
| 278 |
return c.connPool.Conn() |
| 279 |
} |
| 280 |
|
| 281 |
// setGoogleClientInfo sets the name and version of the application in |
| 282 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 283 |
// use by Google-written clients. |
| 284 |
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| 285 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 286 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 287 |
c.xGoogHeaders = []string{ |
| 288 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
// Close closes the connection to the API service. The user should invoke this when |
| 293 |
// the client is no longer required. |
| 294 |
func (c *gRPCClient) Close() error { |
| 295 |
return c.connPool.Close() |
| 296 |
} |
| 297 |
|
| 298 |
func (c *gRPCClient) ReceiveTaskNotification(ctx context.Context, req *agentendpointpb.ReceiveTaskNotificationRequest, opts ...gax.CallOption) (agentendpointpb.AgentEndpointService_ReceiveTaskNotificationClient, error) { |
| 299 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 300 |
opts = append((*c.CallOptions).ReceiveTaskNotification[0:len((*c.CallOptions).ReceiveTaskNotification):len((*c.CallOptions).ReceiveTaskNotification)], opts...) |
| 301 |
var resp agentendpointpb.AgentEndpointService_ReceiveTaskNotificationClient |
| 302 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 303 |
var err error |
| 304 |
c.logger.DebugContext(ctx, "api streaming client request", "serviceName", serviceName, "rpcName", "ReceiveTaskNotification") |
| 305 |
resp, err = c.client.ReceiveTaskNotification(ctx, req, settings.GRPC...) |
| 306 |
c.logger.DebugContext(ctx, "api streaming client response", "serviceName", serviceName, "rpcName", "ReceiveTaskNotification") |
| 307 |
return err |
| 308 |
}, opts...) |
| 309 |
if err != nil { |
| 310 |
return nil, err |
| 311 |
} |
| 312 |
return resp, nil |
| 313 |
} |
| 314 |
|
| 315 |
func (c *gRPCClient) StartNextTask(ctx context.Context, req *agentendpointpb.StartNextTaskRequest, opts ...gax.CallOption) (*agentendpointpb.StartNextTaskResponse, error) { |
| 316 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 317 |
opts = append((*c.CallOptions).StartNextTask[0:len((*c.CallOptions).StartNextTask):len((*c.CallOptions).StartNextTask)], opts...) |
| 318 |
var resp *agentendpointpb.StartNextTaskResponse |
| 319 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 320 |
var err error |
| 321 |
resp, err = executeRPC(ctx, c.client.StartNextTask, req, settings.GRPC, c.logger, "StartNextTask") |
| 322 |
return err |
| 323 |
}, opts...) |
| 324 |
if err != nil { |
| 325 |
return nil, err |
| 326 |
} |
| 327 |
return resp, nil |
| 328 |
} |
| 329 |
|
| 330 |
func (c *gRPCClient) ReportTaskProgress(ctx context.Context, req *agentendpointpb.ReportTaskProgressRequest, opts ...gax.CallOption) (*agentendpointpb.ReportTaskProgressResponse, error) { |
| 331 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 332 |
opts = append((*c.CallOptions).ReportTaskProgress[0:len((*c.CallOptions).ReportTaskProgress):len((*c.CallOptions).ReportTaskProgress)], opts...) |
| 333 |
var resp *agentendpointpb.ReportTaskProgressResponse |
| 334 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 335 |
var err error |
| 336 |
resp, err = executeRPC(ctx, c.client.ReportTaskProgress, req, settings.GRPC, c.logger, "ReportTaskProgress") |
| 337 |
return err |
| 338 |
}, opts...) |
| 339 |
if err != nil { |
| 340 |
return nil, err |
| 341 |
} |
| 342 |
return resp, nil |
| 343 |
} |
| 344 |
|
| 345 |
func (c *gRPCClient) ReportTaskComplete(ctx context.Context, req *agentendpointpb.ReportTaskCompleteRequest, opts ...gax.CallOption) (*agentendpointpb.ReportTaskCompleteResponse, error) { |
| 346 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 347 |
opts = append((*c.CallOptions).ReportTaskComplete[0:len((*c.CallOptions).ReportTaskComplete):len((*c.CallOptions).ReportTaskComplete)], opts...) |
| 348 |
var resp *agentendpointpb.ReportTaskCompleteResponse |
| 349 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 350 |
var err error |
| 351 |
resp, err = executeRPC(ctx, c.client.ReportTaskComplete, req, settings.GRPC, c.logger, "ReportTaskComplete") |
| 352 |
return err |
| 353 |
}, opts...) |
| 354 |
if err != nil { |
| 355 |
return nil, err |
| 356 |
} |
| 357 |
return resp, nil |
| 358 |
} |
| 359 |
|
| 360 |
func (c *gRPCClient) LookupEffectiveGuestPolicy(ctx context.Context, req *agentendpointpb.LookupEffectiveGuestPolicyRequest, opts ...gax.CallOption) (*agentendpointpb.EffectiveGuestPolicy, error) { |
| 361 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 362 |
opts = append((*c.CallOptions).LookupEffectiveGuestPolicy[0:len((*c.CallOptions).LookupEffectiveGuestPolicy):len((*c.CallOptions).LookupEffectiveGuestPolicy)], opts...) |
| 363 |
var resp *agentendpointpb.EffectiveGuestPolicy |
| 364 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 365 |
var err error |
| 366 |
resp, err = executeRPC(ctx, c.client.LookupEffectiveGuestPolicy, req, settings.GRPC, c.logger, "LookupEffectiveGuestPolicy") |
| 367 |
return err |
| 368 |
}, opts...) |
| 369 |
if err != nil { |
| 370 |
return nil, err |
| 371 |
} |
| 372 |
return resp, nil |
| 373 |
} |
| 374 |
|
| 375 |
func (c *gRPCClient) RegisterAgent(ctx context.Context, req *agentendpointpb.RegisterAgentRequest, opts ...gax.CallOption) (*agentendpointpb.RegisterAgentResponse, error) { |
| 376 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 377 |
opts = append((*c.CallOptions).RegisterAgent[0:len((*c.CallOptions).RegisterAgent):len((*c.CallOptions).RegisterAgent)], opts...) |
| 378 |
var resp *agentendpointpb.RegisterAgentResponse |
| 379 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 380 |
var err error |
| 381 |
resp, err = executeRPC(ctx, c.client.RegisterAgent, req, settings.GRPC, c.logger, "RegisterAgent") |
| 382 |
return err |
| 383 |
}, opts...) |
| 384 |
if err != nil { |
| 385 |
return nil, err |
| 386 |
} |
| 387 |
return resp, nil |
| 388 |
} |