1// Copyright 2021 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
17package appengine
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24	"time"
25
26	"cloud.google.com/go/longrunning"
27	lroauto "cloud.google.com/go/longrunning/autogen"
28	gax "github.com/googleapis/gax-go/v2"
29	"google.golang.org/api/option"
30	"google.golang.org/api/option/internaloption"
31	gtransport "google.golang.org/api/transport/grpc"
32	appenginepb "google.golang.org/genproto/googleapis/appengine/v1"
33	longrunningpb "google.golang.org/genproto/googleapis/longrunning"
34	"google.golang.org/grpc"
35	"google.golang.org/grpc/metadata"
36)
37
38var newApplicationsClientHook clientHook
39
40// ApplicationsCallOptions contains the retry settings for each method of ApplicationsClient.
41type ApplicationsCallOptions struct {
42	GetApplication    []gax.CallOption
43	CreateApplication []gax.CallOption
44	UpdateApplication []gax.CallOption
45	RepairApplication []gax.CallOption
46}
47
48func defaultApplicationsClientOptions() []option.ClientOption {
49	return []option.ClientOption{
50		internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"),
51		internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"),
52		internaloption.WithDefaultAudience("https://appengine.googleapis.com/"),
53		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
54		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
55		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
56			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
57	}
58}
59
60func defaultApplicationsCallOptions() *ApplicationsCallOptions {
61	return &ApplicationsCallOptions{
62		GetApplication:    []gax.CallOption{},
63		CreateApplication: []gax.CallOption{},
64		UpdateApplication: []gax.CallOption{},
65		RepairApplication: []gax.CallOption{},
66	}
67}
68
69// ApplicationsClient is a client for interacting with App Engine Audit Data.
70//
71// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
72type ApplicationsClient struct {
73	// Connection pool of gRPC connections to the service.
74	connPool gtransport.ConnPool
75
76	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
77	disableDeadlines bool
78
79	// The gRPC API client.
80	applicationsClient appenginepb.ApplicationsClient
81
82	// LROClient is used internally to handle longrunning operations.
83	// It is exposed so that its CallOptions can be modified if required.
84	// Users should not Close this client.
85	LROClient *lroauto.OperationsClient
86
87	// The call options for this service.
88	CallOptions *ApplicationsCallOptions
89
90	// The x-goog-* metadata to be sent with each request.
91	xGoogMetadata metadata.MD
92}
93
94// NewApplicationsClient creates a new applications client.
95//
96// Manages App Engine applications.
97func NewApplicationsClient(ctx context.Context, opts ...option.ClientOption) (*ApplicationsClient, error) {
98	clientOpts := defaultApplicationsClientOptions()
99
100	if newApplicationsClientHook != nil {
101		hookOpts, err := newApplicationsClientHook(ctx, clientHookParams{})
102		if err != nil {
103			return nil, err
104		}
105		clientOpts = append(clientOpts, hookOpts...)
106	}
107
108	disableDeadlines, err := checkDisableDeadlines()
109	if err != nil {
110		return nil, err
111	}
112
113	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
114	if err != nil {
115		return nil, err
116	}
117	c := &ApplicationsClient{
118		connPool:         connPool,
119		disableDeadlines: disableDeadlines,
120		CallOptions:      defaultApplicationsCallOptions(),
121
122		applicationsClient: appenginepb.NewApplicationsClient(connPool),
123	}
124	c.setGoogleClientInfo()
125
126	c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
127	if err != nil {
128		// This error "should not happen", since we are just reusing old connection pool
129		// and never actually need to dial.
130		// If this does happen, we could leak connp. However, we cannot close conn:
131		// If the user invoked the constructor with option.WithGRPCConn,
132		// we would close a connection that's still in use.
133		// TODO: investigate error conditions.
134		return nil, err
135	}
136	return c, nil
137}
138
139// Connection returns a connection to the API service.
140//
141// Deprecated.
142func (c *ApplicationsClient) Connection() *grpc.ClientConn {
143	return c.connPool.Conn()
144}
145
146// Close closes the connection to the API service. The user should invoke this when
147// the client is no longer required.
148func (c *ApplicationsClient) Close() error {
149	return c.connPool.Close()
150}
151
152// setGoogleClientInfo sets the name and version of the application in
153// the `x-goog-api-client` header passed on each request. Intended for
154// use by Google-written clients.
155func (c *ApplicationsClient) setGoogleClientInfo(keyval ...string) {
156	kv := append([]string{"gl-go", versionGo()}, keyval...)
157	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
158	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
159}
160
161// GetApplication gets information about an application.
162func (c *ApplicationsClient) GetApplication(ctx context.Context, req *appenginepb.GetApplicationRequest, opts ...gax.CallOption) (*appenginepb.Application, error) {
163	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
164	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
165	opts = append(c.CallOptions.GetApplication[0:len(c.CallOptions.GetApplication):len(c.CallOptions.GetApplication)], opts...)
166	var resp *appenginepb.Application
167	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
168		var err error
169		resp, err = c.applicationsClient.GetApplication(ctx, req, settings.GRPC...)
170		return err
171	}, opts...)
172	if err != nil {
173		return nil, err
174	}
175	return resp, nil
176}
177
178// CreateApplication creates an App Engine application for a Google Cloud Platform project.
179// Required fields:
180//
181//   id - The ID of the target Cloud Platform project.
182//
183//   location - The region (at https://cloud.google.com/appengine/docs/locations) where you want the App Engine application located.
184//
185// For more information about App Engine applications, see Managing Projects, Applications, and Billing (at https://cloud.google.com/appengine/docs/standard/python/console/).
186func (c *ApplicationsClient) CreateApplication(ctx context.Context, req *appenginepb.CreateApplicationRequest, opts ...gax.CallOption) (*CreateApplicationOperation, error) {
187	ctx = insertMetadata(ctx, c.xGoogMetadata)
188	opts = append(c.CallOptions.CreateApplication[0:len(c.CallOptions.CreateApplication):len(c.CallOptions.CreateApplication)], opts...)
189	var resp *longrunningpb.Operation
190	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
191		var err error
192		resp, err = c.applicationsClient.CreateApplication(ctx, req, settings.GRPC...)
193		return err
194	}, opts...)
195	if err != nil {
196		return nil, err
197	}
198	return &CreateApplicationOperation{
199		lro: longrunning.InternalNewOperation(c.LROClient, resp),
200	}, nil
201}
202
203// UpdateApplication updates the specified Application resource.
204// You can update the following fields:
205//
206//   auth_domain - Google authentication domain for controlling user access to the application.
207//
208//   default_cookie_expiration - Cookie expiration policy for the application.
209func (c *ApplicationsClient) UpdateApplication(ctx context.Context, req *appenginepb.UpdateApplicationRequest, opts ...gax.CallOption) (*UpdateApplicationOperation, error) {
210	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
211	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
212	opts = append(c.CallOptions.UpdateApplication[0:len(c.CallOptions.UpdateApplication):len(c.CallOptions.UpdateApplication)], opts...)
213	var resp *longrunningpb.Operation
214	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
215		var err error
216		resp, err = c.applicationsClient.UpdateApplication(ctx, req, settings.GRPC...)
217		return err
218	}, opts...)
219	if err != nil {
220		return nil, err
221	}
222	return &UpdateApplicationOperation{
223		lro: longrunning.InternalNewOperation(c.LROClient, resp),
224	}, nil
225}
226
227// RepairApplication recreates the required App Engine features for the specified App Engine
228// application, for example a Cloud Storage bucket or App Engine service
229// account.
230// Use this method if you receive an error message about a missing feature,
231// for example, Error retrieving the App Engine service account.
232// If you have deleted your App Engine service account, this will
233// not be able to recreate it. Instead, you should attempt to use the
234// IAM undelete API if possible at https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/undelete?apix_params={ (at https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/undelete?apix_params=%7B)“name”%3A"projects%2F-%2FserviceAccounts%2Funique_id"%2C"resource"%3A%7B%7D%7D .
235// If the deletion was recent, the numeric ID can be found in the Cloud
236// Console Activity Log.
237func (c *ApplicationsClient) RepairApplication(ctx context.Context, req *appenginepb.RepairApplicationRequest, opts ...gax.CallOption) (*RepairApplicationOperation, error) {
238	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
239	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
240	opts = append(c.CallOptions.RepairApplication[0:len(c.CallOptions.RepairApplication):len(c.CallOptions.RepairApplication)], opts...)
241	var resp *longrunningpb.Operation
242	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
243		var err error
244		resp, err = c.applicationsClient.RepairApplication(ctx, req, settings.GRPC...)
245		return err
246	}, opts...)
247	if err != nil {
248		return nil, err
249	}
250	return &RepairApplicationOperation{
251		lro: longrunning.InternalNewOperation(c.LROClient, resp),
252	}, nil
253}
254
255// CreateApplicationOperation manages a long-running operation from CreateApplication.
256type CreateApplicationOperation struct {
257	lro *longrunning.Operation
258}
259
260// CreateApplicationOperation returns a new CreateApplicationOperation from a given name.
261// The name must be that of a previously created CreateApplicationOperation, possibly from a different process.
262func (c *ApplicationsClient) CreateApplicationOperation(name string) *CreateApplicationOperation {
263	return &CreateApplicationOperation{
264		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
265	}
266}
267
268// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
269//
270// See documentation of Poll for error-handling information.
271func (op *CreateApplicationOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) {
272	var resp appenginepb.Application
273	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
274		return nil, err
275	}
276	return &resp, nil
277}
278
279// Poll fetches the latest state of the long-running operation.
280//
281// Poll also fetches the latest metadata, which can be retrieved by Metadata.
282//
283// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
284// the operation has completed with failure, the error is returned and op.Done will return true.
285// If Poll succeeds and the operation has completed successfully,
286// op.Done will return true, and the response of the operation is returned.
287// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
288func (op *CreateApplicationOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) {
289	var resp appenginepb.Application
290	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
291		return nil, err
292	}
293	if !op.Done() {
294		return nil, nil
295	}
296	return &resp, nil
297}
298
299// Metadata returns metadata associated with the long-running operation.
300// Metadata itself does not contact the server, but Poll does.
301// To get the latest metadata, call this method after a successful call to Poll.
302// If the metadata is not available, the returned metadata and error are both nil.
303func (op *CreateApplicationOperation) Metadata() (*appenginepb.OperationMetadataV1, error) {
304	var meta appenginepb.OperationMetadataV1
305	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
306		return nil, nil
307	} else if err != nil {
308		return nil, err
309	}
310	return &meta, nil
311}
312
313// Done reports whether the long-running operation has completed.
314func (op *CreateApplicationOperation) Done() bool {
315	return op.lro.Done()
316}
317
318// Name returns the name of the long-running operation.
319// The name is assigned by the server and is unique within the service from which the operation is created.
320func (op *CreateApplicationOperation) Name() string {
321	return op.lro.Name()
322}
323
324// RepairApplicationOperation manages a long-running operation from RepairApplication.
325type RepairApplicationOperation struct {
326	lro *longrunning.Operation
327}
328
329// RepairApplicationOperation returns a new RepairApplicationOperation from a given name.
330// The name must be that of a previously created RepairApplicationOperation, possibly from a different process.
331func (c *ApplicationsClient) RepairApplicationOperation(name string) *RepairApplicationOperation {
332	return &RepairApplicationOperation{
333		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
334	}
335}
336
337// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
338//
339// See documentation of Poll for error-handling information.
340func (op *RepairApplicationOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) {
341	var resp appenginepb.Application
342	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
343		return nil, err
344	}
345	return &resp, nil
346}
347
348// Poll fetches the latest state of the long-running operation.
349//
350// Poll also fetches the latest metadata, which can be retrieved by Metadata.
351//
352// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
353// the operation has completed with failure, the error is returned and op.Done will return true.
354// If Poll succeeds and the operation has completed successfully,
355// op.Done will return true, and the response of the operation is returned.
356// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
357func (op *RepairApplicationOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) {
358	var resp appenginepb.Application
359	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
360		return nil, err
361	}
362	if !op.Done() {
363		return nil, nil
364	}
365	return &resp, nil
366}
367
368// Metadata returns metadata associated with the long-running operation.
369// Metadata itself does not contact the server, but Poll does.
370// To get the latest metadata, call this method after a successful call to Poll.
371// If the metadata is not available, the returned metadata and error are both nil.
372func (op *RepairApplicationOperation) Metadata() (*appenginepb.OperationMetadataV1, error) {
373	var meta appenginepb.OperationMetadataV1
374	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
375		return nil, nil
376	} else if err != nil {
377		return nil, err
378	}
379	return &meta, nil
380}
381
382// Done reports whether the long-running operation has completed.
383func (op *RepairApplicationOperation) Done() bool {
384	return op.lro.Done()
385}
386
387// Name returns the name of the long-running operation.
388// The name is assigned by the server and is unique within the service from which the operation is created.
389func (op *RepairApplicationOperation) Name() string {
390	return op.lro.Name()
391}
392
393// UpdateApplicationOperation manages a long-running operation from UpdateApplication.
394type UpdateApplicationOperation struct {
395	lro *longrunning.Operation
396}
397
398// UpdateApplicationOperation returns a new UpdateApplicationOperation from a given name.
399// The name must be that of a previously created UpdateApplicationOperation, possibly from a different process.
400func (c *ApplicationsClient) UpdateApplicationOperation(name string) *UpdateApplicationOperation {
401	return &UpdateApplicationOperation{
402		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
403	}
404}
405
406// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
407//
408// See documentation of Poll for error-handling information.
409func (op *UpdateApplicationOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) {
410	var resp appenginepb.Application
411	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
412		return nil, err
413	}
414	return &resp, nil
415}
416
417// Poll fetches the latest state of the long-running operation.
418//
419// Poll also fetches the latest metadata, which can be retrieved by Metadata.
420//
421// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
422// the operation has completed with failure, the error is returned and op.Done will return true.
423// If Poll succeeds and the operation has completed successfully,
424// op.Done will return true, and the response of the operation is returned.
425// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
426func (op *UpdateApplicationOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) {
427	var resp appenginepb.Application
428	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
429		return nil, err
430	}
431	if !op.Done() {
432		return nil, nil
433	}
434	return &resp, nil
435}
436
437// Metadata returns metadata associated with the long-running operation.
438// Metadata itself does not contact the server, but Poll does.
439// To get the latest metadata, call this method after a successful call to Poll.
440// If the metadata is not available, the returned metadata and error are both nil.
441func (op *UpdateApplicationOperation) Metadata() (*appenginepb.OperationMetadataV1, error) {
442	var meta appenginepb.OperationMetadataV1
443	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
444		return nil, nil
445	} else if err != nil {
446		return nil, err
447	}
448	return &meta, nil
449}
450
451// Done reports whether the long-running operation has completed.
452func (op *UpdateApplicationOperation) Done() bool {
453	return op.lro.Done()
454}
455
456// Name returns the name of the long-running operation.
457// The name is assigned by the server and is unique within the service from which the operation is created.
458func (op *UpdateApplicationOperation) Name() string {
459	return op.lro.Name()
460}
461