...

Source file src/cloud.google.com/go/debugger/apiv2/debugger2_client.go

Documentation: cloud.google.com/go/debugger/apiv2

     1  // Copyright 2023 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 debugger
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"io/ioutil"
    24  	"math"
    25  	"net/http"
    26  	"net/url"
    27  	"time"
    28  
    29  	debuggerpb "cloud.google.com/go/debugger/apiv2/debuggerpb"
    30  	gax "github.com/googleapis/gax-go/v2"
    31  	"google.golang.org/api/googleapi"
    32  	"google.golang.org/api/option"
    33  	"google.golang.org/api/option/internaloption"
    34  	gtransport "google.golang.org/api/transport/grpc"
    35  	httptransport "google.golang.org/api/transport/http"
    36  	"google.golang.org/grpc"
    37  	"google.golang.org/grpc/codes"
    38  	"google.golang.org/grpc/metadata"
    39  	"google.golang.org/protobuf/encoding/protojson"
    40  )
    41  
    42  var newDebugger2ClientHook clientHook
    43  
    44  // Debugger2CallOptions contains the retry settings for each method of Debugger2Client.
    45  type Debugger2CallOptions struct {
    46  	SetBreakpoint    []gax.CallOption
    47  	GetBreakpoint    []gax.CallOption
    48  	DeleteBreakpoint []gax.CallOption
    49  	ListBreakpoints  []gax.CallOption
    50  	ListDebuggees    []gax.CallOption
    51  }
    52  
    53  func defaultDebugger2GRPCClientOptions() []option.ClientOption {
    54  	return []option.ClientOption{
    55  		internaloption.WithDefaultEndpoint("clouddebugger.googleapis.com:443"),
    56  		internaloption.WithDefaultEndpointTemplate("clouddebugger.UNIVERSE_DOMAIN:443"),
    57  		internaloption.WithDefaultMTLSEndpoint("clouddebugger.mtls.googleapis.com:443"),
    58  		internaloption.WithDefaultAudience("https://clouddebugger.googleapis.com/"),
    59  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    60  		internaloption.EnableJwtWithScope(),
    61  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    62  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    63  	}
    64  }
    65  
    66  func defaultDebugger2CallOptions() *Debugger2CallOptions {
    67  	return &Debugger2CallOptions{
    68  		SetBreakpoint: []gax.CallOption{},
    69  		GetBreakpoint: []gax.CallOption{
    70  			gax.WithRetry(func() gax.Retryer {
    71  				return gax.OnCodes([]codes.Code{
    72  					codes.Unavailable,
    73  					codes.DeadlineExceeded,
    74  				}, gax.Backoff{
    75  					Initial:    100 * time.Millisecond,
    76  					Max:        60000 * time.Millisecond,
    77  					Multiplier: 1.30,
    78  				})
    79  			}),
    80  		},
    81  		DeleteBreakpoint: []gax.CallOption{
    82  			gax.WithRetry(func() gax.Retryer {
    83  				return gax.OnCodes([]codes.Code{
    84  					codes.Unavailable,
    85  					codes.DeadlineExceeded,
    86  				}, gax.Backoff{
    87  					Initial:    100 * time.Millisecond,
    88  					Max:        60000 * time.Millisecond,
    89  					Multiplier: 1.30,
    90  				})
    91  			}),
    92  		},
    93  		ListBreakpoints: []gax.CallOption{
    94  			gax.WithRetry(func() gax.Retryer {
    95  				return gax.OnCodes([]codes.Code{
    96  					codes.Unavailable,
    97  					codes.DeadlineExceeded,
    98  				}, gax.Backoff{
    99  					Initial:    100 * time.Millisecond,
   100  					Max:        60000 * time.Millisecond,
   101  					Multiplier: 1.30,
   102  				})
   103  			}),
   104  		},
   105  		ListDebuggees: []gax.CallOption{
   106  			gax.WithRetry(func() gax.Retryer {
   107  				return gax.OnCodes([]codes.Code{
   108  					codes.Unavailable,
   109  					codes.DeadlineExceeded,
   110  				}, gax.Backoff{
   111  					Initial:    100 * time.Millisecond,
   112  					Max:        60000 * time.Millisecond,
   113  					Multiplier: 1.30,
   114  				})
   115  			}),
   116  		},
   117  	}
   118  }
   119  
   120  func defaultDebugger2RESTCallOptions() *Debugger2CallOptions {
   121  	return &Debugger2CallOptions{
   122  		SetBreakpoint: []gax.CallOption{},
   123  		GetBreakpoint: []gax.CallOption{
   124  			gax.WithRetry(func() gax.Retryer {
   125  				return gax.OnHTTPCodes(gax.Backoff{
   126  					Initial:    100 * time.Millisecond,
   127  					Max:        60000 * time.Millisecond,
   128  					Multiplier: 1.30,
   129  				},
   130  					http.StatusServiceUnavailable,
   131  					http.StatusGatewayTimeout)
   132  			}),
   133  		},
   134  		DeleteBreakpoint: []gax.CallOption{
   135  			gax.WithRetry(func() gax.Retryer {
   136  				return gax.OnHTTPCodes(gax.Backoff{
   137  					Initial:    100 * time.Millisecond,
   138  					Max:        60000 * time.Millisecond,
   139  					Multiplier: 1.30,
   140  				},
   141  					http.StatusServiceUnavailable,
   142  					http.StatusGatewayTimeout)
   143  			}),
   144  		},
   145  		ListBreakpoints: []gax.CallOption{
   146  			gax.WithRetry(func() gax.Retryer {
   147  				return gax.OnHTTPCodes(gax.Backoff{
   148  					Initial:    100 * time.Millisecond,
   149  					Max:        60000 * time.Millisecond,
   150  					Multiplier: 1.30,
   151  				},
   152  					http.StatusServiceUnavailable,
   153  					http.StatusGatewayTimeout)
   154  			}),
   155  		},
   156  		ListDebuggees: []gax.CallOption{
   157  			gax.WithRetry(func() gax.Retryer {
   158  				return gax.OnHTTPCodes(gax.Backoff{
   159  					Initial:    100 * time.Millisecond,
   160  					Max:        60000 * time.Millisecond,
   161  					Multiplier: 1.30,
   162  				},
   163  					http.StatusServiceUnavailable,
   164  					http.StatusGatewayTimeout)
   165  			}),
   166  		},
   167  	}
   168  }
   169  
   170  // internalDebugger2Client is an interface that defines the methods available from Stackdriver Debugger API.
   171  type internalDebugger2Client interface {
   172  	Close() error
   173  	setGoogleClientInfo(...string)
   174  	Connection() *grpc.ClientConn
   175  	SetBreakpoint(context.Context, *debuggerpb.SetBreakpointRequest, ...gax.CallOption) (*debuggerpb.SetBreakpointResponse, error)
   176  	GetBreakpoint(context.Context, *debuggerpb.GetBreakpointRequest, ...gax.CallOption) (*debuggerpb.GetBreakpointResponse, error)
   177  	DeleteBreakpoint(context.Context, *debuggerpb.DeleteBreakpointRequest, ...gax.CallOption) error
   178  	ListBreakpoints(context.Context, *debuggerpb.ListBreakpointsRequest, ...gax.CallOption) (*debuggerpb.ListBreakpointsResponse, error)
   179  	ListDebuggees(context.Context, *debuggerpb.ListDebuggeesRequest, ...gax.CallOption) (*debuggerpb.ListDebuggeesResponse, error)
   180  }
   181  
   182  // Debugger2Client is a client for interacting with Stackdriver Debugger API.
   183  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   184  //
   185  // The Debugger service provides the API that allows users to collect run-time
   186  // information from a running application, without stopping or slowing it down
   187  // and without modifying its state.  An application may include one or
   188  // more replicated processes performing the same work.
   189  //
   190  // A debugged application is represented using the Debuggee concept. The
   191  // Debugger service provides a way to query for available debuggees, but does
   192  // not provide a way to create one.  A debuggee is created using the Controller
   193  // service, usually by running a debugger agent with the application.
   194  //
   195  // The Debugger service enables the client to set one or more Breakpoints on a
   196  // Debuggee and collect the results of the set Breakpoints.
   197  type Debugger2Client struct {
   198  	// The internal transport-dependent client.
   199  	internalClient internalDebugger2Client
   200  
   201  	// The call options for this service.
   202  	CallOptions *Debugger2CallOptions
   203  }
   204  
   205  // Wrapper methods routed to the internal client.
   206  
   207  // Close closes the connection to the API service. The user should invoke this when
   208  // the client is no longer required.
   209  func (c *Debugger2Client) Close() error {
   210  	return c.internalClient.Close()
   211  }
   212  
   213  // setGoogleClientInfo sets the name and version of the application in
   214  // the `x-goog-api-client` header passed on each request. Intended for
   215  // use by Google-written clients.
   216  func (c *Debugger2Client) setGoogleClientInfo(keyval ...string) {
   217  	c.internalClient.setGoogleClientInfo(keyval...)
   218  }
   219  
   220  // Connection returns a connection to the API service.
   221  //
   222  // Deprecated: Connections are now pooled so this method does not always
   223  // return the same resource.
   224  func (c *Debugger2Client) Connection() *grpc.ClientConn {
   225  	return c.internalClient.Connection()
   226  }
   227  
   228  // SetBreakpoint sets the breakpoint to the debuggee.
   229  func (c *Debugger2Client) SetBreakpoint(ctx context.Context, req *debuggerpb.SetBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.SetBreakpointResponse, error) {
   230  	return c.internalClient.SetBreakpoint(ctx, req, opts...)
   231  }
   232  
   233  // GetBreakpoint gets breakpoint information.
   234  func (c *Debugger2Client) GetBreakpoint(ctx context.Context, req *debuggerpb.GetBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.GetBreakpointResponse, error) {
   235  	return c.internalClient.GetBreakpoint(ctx, req, opts...)
   236  }
   237  
   238  // DeleteBreakpoint deletes the breakpoint from the debuggee.
   239  func (c *Debugger2Client) DeleteBreakpoint(ctx context.Context, req *debuggerpb.DeleteBreakpointRequest, opts ...gax.CallOption) error {
   240  	return c.internalClient.DeleteBreakpoint(ctx, req, opts...)
   241  }
   242  
   243  // ListBreakpoints lists all breakpoints for the debuggee.
   244  func (c *Debugger2Client) ListBreakpoints(ctx context.Context, req *debuggerpb.ListBreakpointsRequest, opts ...gax.CallOption) (*debuggerpb.ListBreakpointsResponse, error) {
   245  	return c.internalClient.ListBreakpoints(ctx, req, opts...)
   246  }
   247  
   248  // ListDebuggees lists all the debuggees that the user has access to.
   249  func (c *Debugger2Client) ListDebuggees(ctx context.Context, req *debuggerpb.ListDebuggeesRequest, opts ...gax.CallOption) (*debuggerpb.ListDebuggeesResponse, error) {
   250  	return c.internalClient.ListDebuggees(ctx, req, opts...)
   251  }
   252  
   253  // debugger2GRPCClient is a client for interacting with Stackdriver Debugger API over gRPC transport.
   254  //
   255  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   256  type debugger2GRPCClient struct {
   257  	// Connection pool of gRPC connections to the service.
   258  	connPool gtransport.ConnPool
   259  
   260  	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
   261  	disableDeadlines bool
   262  
   263  	// Points back to the CallOptions field of the containing Debugger2Client
   264  	CallOptions **Debugger2CallOptions
   265  
   266  	// The gRPC API client.
   267  	debugger2Client debuggerpb.Debugger2Client
   268  
   269  	// The x-goog-* metadata to be sent with each request.
   270  	xGoogMetadata metadata.MD
   271  }
   272  
   273  // NewDebugger2Client creates a new debugger2 client based on gRPC.
   274  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   275  //
   276  // The Debugger service provides the API that allows users to collect run-time
   277  // information from a running application, without stopping or slowing it down
   278  // and without modifying its state.  An application may include one or
   279  // more replicated processes performing the same work.
   280  //
   281  // A debugged application is represented using the Debuggee concept. The
   282  // Debugger service provides a way to query for available debuggees, but does
   283  // not provide a way to create one.  A debuggee is created using the Controller
   284  // service, usually by running a debugger agent with the application.
   285  //
   286  // The Debugger service enables the client to set one or more Breakpoints on a
   287  // Debuggee and collect the results of the set Breakpoints.
   288  func NewDebugger2Client(ctx context.Context, opts ...option.ClientOption) (*Debugger2Client, error) {
   289  	clientOpts := defaultDebugger2GRPCClientOptions()
   290  	if newDebugger2ClientHook != nil {
   291  		hookOpts, err := newDebugger2ClientHook(ctx, clientHookParams{})
   292  		if err != nil {
   293  			return nil, err
   294  		}
   295  		clientOpts = append(clientOpts, hookOpts...)
   296  	}
   297  
   298  	disableDeadlines, err := checkDisableDeadlines()
   299  	if err != nil {
   300  		return nil, err
   301  	}
   302  
   303  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   304  	if err != nil {
   305  		return nil, err
   306  	}
   307  	client := Debugger2Client{CallOptions: defaultDebugger2CallOptions()}
   308  
   309  	c := &debugger2GRPCClient{
   310  		connPool:         connPool,
   311  		disableDeadlines: disableDeadlines,
   312  		debugger2Client:  debuggerpb.NewDebugger2Client(connPool),
   313  		CallOptions:      &client.CallOptions,
   314  	}
   315  	c.setGoogleClientInfo()
   316  
   317  	client.internalClient = c
   318  
   319  	return &client, nil
   320  }
   321  
   322  // Connection returns a connection to the API service.
   323  //
   324  // Deprecated: Connections are now pooled so this method does not always
   325  // return the same resource.
   326  func (c *debugger2GRPCClient) Connection() *grpc.ClientConn {
   327  	return c.connPool.Conn()
   328  }
   329  
   330  // setGoogleClientInfo sets the name and version of the application in
   331  // the `x-goog-api-client` header passed on each request. Intended for
   332  // use by Google-written clients.
   333  func (c *debugger2GRPCClient) setGoogleClientInfo(keyval ...string) {
   334  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   335  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   336  	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
   337  }
   338  
   339  // Close closes the connection to the API service. The user should invoke this when
   340  // the client is no longer required.
   341  func (c *debugger2GRPCClient) Close() error {
   342  	return c.connPool.Close()
   343  }
   344  
   345  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   346  type debugger2RESTClient struct {
   347  	// The http endpoint to connect to.
   348  	endpoint string
   349  
   350  	// The http client.
   351  	httpClient *http.Client
   352  
   353  	// The x-goog-* metadata to be sent with each request.
   354  	xGoogMetadata metadata.MD
   355  
   356  	// Points back to the CallOptions field of the containing Debugger2Client
   357  	CallOptions **Debugger2CallOptions
   358  }
   359  
   360  // NewDebugger2RESTClient creates a new debugger2 rest client.
   361  //
   362  // The Debugger service provides the API that allows users to collect run-time
   363  // information from a running application, without stopping or slowing it down
   364  // and without modifying its state.  An application may include one or
   365  // more replicated processes performing the same work.
   366  //
   367  // A debugged application is represented using the Debuggee concept. The
   368  // Debugger service provides a way to query for available debuggees, but does
   369  // not provide a way to create one.  A debuggee is created using the Controller
   370  // service, usually by running a debugger agent with the application.
   371  //
   372  // The Debugger service enables the client to set one or more Breakpoints on a
   373  // Debuggee and collect the results of the set Breakpoints.
   374  func NewDebugger2RESTClient(ctx context.Context, opts ...option.ClientOption) (*Debugger2Client, error) {
   375  	clientOpts := append(defaultDebugger2RESTClientOptions(), opts...)
   376  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   377  	if err != nil {
   378  		return nil, err
   379  	}
   380  
   381  	callOpts := defaultDebugger2RESTCallOptions()
   382  	c := &debugger2RESTClient{
   383  		endpoint:    endpoint,
   384  		httpClient:  httpClient,
   385  		CallOptions: &callOpts,
   386  	}
   387  	c.setGoogleClientInfo()
   388  
   389  	return &Debugger2Client{internalClient: c, CallOptions: callOpts}, nil
   390  }
   391  
   392  func defaultDebugger2RESTClientOptions() []option.ClientOption {
   393  	return []option.ClientOption{
   394  		internaloption.WithDefaultEndpoint("https://clouddebugger.googleapis.com"),
   395  		internaloption.WithDefaultEndpointTemplate("https://clouddebugger.UNIVERSE_DOMAIN"),
   396  		internaloption.WithDefaultMTLSEndpoint("https://clouddebugger.mtls.googleapis.com"),
   397  		internaloption.WithDefaultAudience("https://clouddebugger.googleapis.com/"),
   398  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   399  	}
   400  }
   401  
   402  // setGoogleClientInfo sets the name and version of the application in
   403  // the `x-goog-api-client` header passed on each request. Intended for
   404  // use by Google-written clients.
   405  func (c *debugger2RESTClient) setGoogleClientInfo(keyval ...string) {
   406  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   407  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
   408  	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
   409  }
   410  
   411  // Close closes the connection to the API service. The user should invoke this when
   412  // the client is no longer required.
   413  func (c *debugger2RESTClient) Close() error {
   414  	// Replace httpClient with nil to force cleanup.
   415  	c.httpClient = nil
   416  	return nil
   417  }
   418  
   419  // Connection returns a connection to the API service.
   420  //
   421  // Deprecated: This method always returns nil.
   422  func (c *debugger2RESTClient) Connection() *grpc.ClientConn {
   423  	return nil
   424  }
   425  func (c *debugger2GRPCClient) SetBreakpoint(ctx context.Context, req *debuggerpb.SetBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.SetBreakpointResponse, error) {
   426  	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
   427  		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
   428  		defer cancel()
   429  		ctx = cctx
   430  	}
   431  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId())))
   432  
   433  	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
   434  	opts = append((*c.CallOptions).SetBreakpoint[0:len((*c.CallOptions).SetBreakpoint):len((*c.CallOptions).SetBreakpoint)], opts...)
   435  	var resp *debuggerpb.SetBreakpointResponse
   436  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   437  		var err error
   438  		resp, err = c.debugger2Client.SetBreakpoint(ctx, req, settings.GRPC...)
   439  		return err
   440  	}, opts...)
   441  	if err != nil {
   442  		return nil, err
   443  	}
   444  	return resp, nil
   445  }
   446  
   447  func (c *debugger2GRPCClient) GetBreakpoint(ctx context.Context, req *debuggerpb.GetBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.GetBreakpointResponse, error) {
   448  	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
   449  		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
   450  		defer cancel()
   451  		ctx = cctx
   452  	}
   453  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId()), "breakpoint_id", url.QueryEscape(req.GetBreakpointId())))
   454  
   455  	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
   456  	opts = append((*c.CallOptions).GetBreakpoint[0:len((*c.CallOptions).GetBreakpoint):len((*c.CallOptions).GetBreakpoint)], opts...)
   457  	var resp *debuggerpb.GetBreakpointResponse
   458  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   459  		var err error
   460  		resp, err = c.debugger2Client.GetBreakpoint(ctx, req, settings.GRPC...)
   461  		return err
   462  	}, opts...)
   463  	if err != nil {
   464  		return nil, err
   465  	}
   466  	return resp, nil
   467  }
   468  
   469  func (c *debugger2GRPCClient) DeleteBreakpoint(ctx context.Context, req *debuggerpb.DeleteBreakpointRequest, opts ...gax.CallOption) error {
   470  	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
   471  		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
   472  		defer cancel()
   473  		ctx = cctx
   474  	}
   475  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId()), "breakpoint_id", url.QueryEscape(req.GetBreakpointId())))
   476  
   477  	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
   478  	opts = append((*c.CallOptions).DeleteBreakpoint[0:len((*c.CallOptions).DeleteBreakpoint):len((*c.CallOptions).DeleteBreakpoint)], opts...)
   479  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   480  		var err error
   481  		_, err = c.debugger2Client.DeleteBreakpoint(ctx, req, settings.GRPC...)
   482  		return err
   483  	}, opts...)
   484  	return err
   485  }
   486  
   487  func (c *debugger2GRPCClient) ListBreakpoints(ctx context.Context, req *debuggerpb.ListBreakpointsRequest, opts ...gax.CallOption) (*debuggerpb.ListBreakpointsResponse, error) {
   488  	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
   489  		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
   490  		defer cancel()
   491  		ctx = cctx
   492  	}
   493  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId())))
   494  
   495  	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
   496  	opts = append((*c.CallOptions).ListBreakpoints[0:len((*c.CallOptions).ListBreakpoints):len((*c.CallOptions).ListBreakpoints)], opts...)
   497  	var resp *debuggerpb.ListBreakpointsResponse
   498  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   499  		var err error
   500  		resp, err = c.debugger2Client.ListBreakpoints(ctx, req, settings.GRPC...)
   501  		return err
   502  	}, opts...)
   503  	if err != nil {
   504  		return nil, err
   505  	}
   506  	return resp, nil
   507  }
   508  
   509  func (c *debugger2GRPCClient) ListDebuggees(ctx context.Context, req *debuggerpb.ListDebuggeesRequest, opts ...gax.CallOption) (*debuggerpb.ListDebuggeesResponse, error) {
   510  	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
   511  		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
   512  		defer cancel()
   513  		ctx = cctx
   514  	}
   515  	ctx = insertMetadata(ctx, c.xGoogMetadata)
   516  	opts = append((*c.CallOptions).ListDebuggees[0:len((*c.CallOptions).ListDebuggees):len((*c.CallOptions).ListDebuggees)], opts...)
   517  	var resp *debuggerpb.ListDebuggeesResponse
   518  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   519  		var err error
   520  		resp, err = c.debugger2Client.ListDebuggees(ctx, req, settings.GRPC...)
   521  		return err
   522  	}, opts...)
   523  	if err != nil {
   524  		return nil, err
   525  	}
   526  	return resp, nil
   527  }
   528  
   529  // SetBreakpoint sets the breakpoint to the debuggee.
   530  func (c *debugger2RESTClient) SetBreakpoint(ctx context.Context, req *debuggerpb.SetBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.SetBreakpointResponse, error) {
   531  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   532  	body := req.GetBreakpoint()
   533  	jsonReq, err := m.Marshal(body)
   534  	if err != nil {
   535  		return nil, err
   536  	}
   537  
   538  	baseUrl, err := url.Parse(c.endpoint)
   539  	if err != nil {
   540  		return nil, err
   541  	}
   542  	baseUrl.Path += fmt.Sprintf("/v2/debugger/debuggees/%v/breakpoints/set", req.GetDebuggeeId())
   543  
   544  	params := url.Values{}
   545  	params.Add("$alt", "json;enum-encoding=int")
   546  	params.Add("clientVersion", fmt.Sprintf("%v", req.GetClientVersion()))
   547  
   548  	baseUrl.RawQuery = params.Encode()
   549  
   550  	// Build HTTP headers from client and context metadata.
   551  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId())))
   552  
   553  	headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
   554  	opts = append((*c.CallOptions).SetBreakpoint[0:len((*c.CallOptions).SetBreakpoint):len((*c.CallOptions).SetBreakpoint)], opts...)
   555  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   556  	resp := &debuggerpb.SetBreakpointResponse{}
   557  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   558  		if settings.Path != "" {
   559  			baseUrl.Path = settings.Path
   560  		}
   561  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   562  		if err != nil {
   563  			return err
   564  		}
   565  		httpReq = httpReq.WithContext(ctx)
   566  		httpReq.Header = headers
   567  
   568  		httpRsp, err := c.httpClient.Do(httpReq)
   569  		if err != nil {
   570  			return err
   571  		}
   572  		defer httpRsp.Body.Close()
   573  
   574  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   575  			return err
   576  		}
   577  
   578  		buf, err := ioutil.ReadAll(httpRsp.Body)
   579  		if err != nil {
   580  			return err
   581  		}
   582  
   583  		if err := unm.Unmarshal(buf, resp); err != nil {
   584  			return err
   585  		}
   586  
   587  		return nil
   588  	}, opts...)
   589  	if e != nil {
   590  		return nil, e
   591  	}
   592  	return resp, nil
   593  }
   594  
   595  // GetBreakpoint gets breakpoint information.
   596  func (c *debugger2RESTClient) GetBreakpoint(ctx context.Context, req *debuggerpb.GetBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.GetBreakpointResponse, error) {
   597  	baseUrl, err := url.Parse(c.endpoint)
   598  	if err != nil {
   599  		return nil, err
   600  	}
   601  	baseUrl.Path += fmt.Sprintf("/v2/debugger/debuggees/%v/breakpoints/%v", req.GetDebuggeeId(), req.GetBreakpointId())
   602  
   603  	params := url.Values{}
   604  	params.Add("$alt", "json;enum-encoding=int")
   605  	params.Add("clientVersion", fmt.Sprintf("%v", req.GetClientVersion()))
   606  
   607  	baseUrl.RawQuery = params.Encode()
   608  
   609  	// Build HTTP headers from client and context metadata.
   610  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId()), "breakpoint_id", url.QueryEscape(req.GetBreakpointId())))
   611  
   612  	headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
   613  	opts = append((*c.CallOptions).GetBreakpoint[0:len((*c.CallOptions).GetBreakpoint):len((*c.CallOptions).GetBreakpoint)], opts...)
   614  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   615  	resp := &debuggerpb.GetBreakpointResponse{}
   616  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   617  		if settings.Path != "" {
   618  			baseUrl.Path = settings.Path
   619  		}
   620  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   621  		if err != nil {
   622  			return err
   623  		}
   624  		httpReq = httpReq.WithContext(ctx)
   625  		httpReq.Header = headers
   626  
   627  		httpRsp, err := c.httpClient.Do(httpReq)
   628  		if err != nil {
   629  			return err
   630  		}
   631  		defer httpRsp.Body.Close()
   632  
   633  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   634  			return err
   635  		}
   636  
   637  		buf, err := ioutil.ReadAll(httpRsp.Body)
   638  		if err != nil {
   639  			return err
   640  		}
   641  
   642  		if err := unm.Unmarshal(buf, resp); err != nil {
   643  			return err
   644  		}
   645  
   646  		return nil
   647  	}, opts...)
   648  	if e != nil {
   649  		return nil, e
   650  	}
   651  	return resp, nil
   652  }
   653  
   654  // DeleteBreakpoint deletes the breakpoint from the debuggee.
   655  func (c *debugger2RESTClient) DeleteBreakpoint(ctx context.Context, req *debuggerpb.DeleteBreakpointRequest, opts ...gax.CallOption) error {
   656  	baseUrl, err := url.Parse(c.endpoint)
   657  	if err != nil {
   658  		return err
   659  	}
   660  	baseUrl.Path += fmt.Sprintf("/v2/debugger/debuggees/%v/breakpoints/%v", req.GetDebuggeeId(), req.GetBreakpointId())
   661  
   662  	params := url.Values{}
   663  	params.Add("$alt", "json;enum-encoding=int")
   664  	params.Add("clientVersion", fmt.Sprintf("%v", req.GetClientVersion()))
   665  
   666  	baseUrl.RawQuery = params.Encode()
   667  
   668  	// Build HTTP headers from client and context metadata.
   669  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId()), "breakpoint_id", url.QueryEscape(req.GetBreakpointId())))
   670  
   671  	headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
   672  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   673  		if settings.Path != "" {
   674  			baseUrl.Path = settings.Path
   675  		}
   676  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
   677  		if err != nil {
   678  			return err
   679  		}
   680  		httpReq = httpReq.WithContext(ctx)
   681  		httpReq.Header = headers
   682  
   683  		httpRsp, err := c.httpClient.Do(httpReq)
   684  		if err != nil {
   685  			return err
   686  		}
   687  		defer httpRsp.Body.Close()
   688  
   689  		// Returns nil if there is no error, otherwise wraps
   690  		// the response code and body into a non-nil error
   691  		return googleapi.CheckResponse(httpRsp)
   692  	}, opts...)
   693  }
   694  
   695  // ListBreakpoints lists all breakpoints for the debuggee.
   696  func (c *debugger2RESTClient) ListBreakpoints(ctx context.Context, req *debuggerpb.ListBreakpointsRequest, opts ...gax.CallOption) (*debuggerpb.ListBreakpointsResponse, error) {
   697  	baseUrl, err := url.Parse(c.endpoint)
   698  	if err != nil {
   699  		return nil, err
   700  	}
   701  	baseUrl.Path += fmt.Sprintf("/v2/debugger/debuggees/%v/breakpoints", req.GetDebuggeeId())
   702  
   703  	params := url.Values{}
   704  	params.Add("$alt", "json;enum-encoding=int")
   705  	if req.GetAction().GetValue() != 0 {
   706  		params.Add("action.value", fmt.Sprintf("%v", req.GetAction().GetValue()))
   707  	}
   708  	params.Add("clientVersion", fmt.Sprintf("%v", req.GetClientVersion()))
   709  	if req.GetIncludeAllUsers() {
   710  		params.Add("includeAllUsers", fmt.Sprintf("%v", req.GetIncludeAllUsers()))
   711  	}
   712  	if req.GetIncludeInactive() {
   713  		params.Add("includeInactive", fmt.Sprintf("%v", req.GetIncludeInactive()))
   714  	}
   715  	if req.GetStripResults() {
   716  		params.Add("stripResults", fmt.Sprintf("%v", req.GetStripResults()))
   717  	}
   718  	if req.GetWaitToken() != "" {
   719  		params.Add("waitToken", fmt.Sprintf("%v", req.GetWaitToken()))
   720  	}
   721  
   722  	baseUrl.RawQuery = params.Encode()
   723  
   724  	// Build HTTP headers from client and context metadata.
   725  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId())))
   726  
   727  	headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
   728  	opts = append((*c.CallOptions).ListBreakpoints[0:len((*c.CallOptions).ListBreakpoints):len((*c.CallOptions).ListBreakpoints)], opts...)
   729  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   730  	resp := &debuggerpb.ListBreakpointsResponse{}
   731  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   732  		if settings.Path != "" {
   733  			baseUrl.Path = settings.Path
   734  		}
   735  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   736  		if err != nil {
   737  			return err
   738  		}
   739  		httpReq = httpReq.WithContext(ctx)
   740  		httpReq.Header = headers
   741  
   742  		httpRsp, err := c.httpClient.Do(httpReq)
   743  		if err != nil {
   744  			return err
   745  		}
   746  		defer httpRsp.Body.Close()
   747  
   748  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   749  			return err
   750  		}
   751  
   752  		buf, err := ioutil.ReadAll(httpRsp.Body)
   753  		if err != nil {
   754  			return err
   755  		}
   756  
   757  		if err := unm.Unmarshal(buf, resp); err != nil {
   758  			return err
   759  		}
   760  
   761  		return nil
   762  	}, opts...)
   763  	if e != nil {
   764  		return nil, e
   765  	}
   766  	return resp, nil
   767  }
   768  
   769  // ListDebuggees lists all the debuggees that the user has access to.
   770  func (c *debugger2RESTClient) ListDebuggees(ctx context.Context, req *debuggerpb.ListDebuggeesRequest, opts ...gax.CallOption) (*debuggerpb.ListDebuggeesResponse, error) {
   771  	baseUrl, err := url.Parse(c.endpoint)
   772  	if err != nil {
   773  		return nil, err
   774  	}
   775  	baseUrl.Path += fmt.Sprintf("/v2/debugger/debuggees")
   776  
   777  	params := url.Values{}
   778  	params.Add("$alt", "json;enum-encoding=int")
   779  	params.Add("clientVersion", fmt.Sprintf("%v", req.GetClientVersion()))
   780  	if req.GetIncludeInactive() {
   781  		params.Add("includeInactive", fmt.Sprintf("%v", req.GetIncludeInactive()))
   782  	}
   783  	params.Add("project", fmt.Sprintf("%v", req.GetProject()))
   784  
   785  	baseUrl.RawQuery = params.Encode()
   786  
   787  	// Build HTTP headers from client and context metadata.
   788  	headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json"))
   789  	opts = append((*c.CallOptions).ListDebuggees[0:len((*c.CallOptions).ListDebuggees):len((*c.CallOptions).ListDebuggees)], opts...)
   790  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   791  	resp := &debuggerpb.ListDebuggeesResponse{}
   792  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   793  		if settings.Path != "" {
   794  			baseUrl.Path = settings.Path
   795  		}
   796  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   797  		if err != nil {
   798  			return err
   799  		}
   800  		httpReq = httpReq.WithContext(ctx)
   801  		httpReq.Header = headers
   802  
   803  		httpRsp, err := c.httpClient.Do(httpReq)
   804  		if err != nil {
   805  			return err
   806  		}
   807  		defer httpRsp.Body.Close()
   808  
   809  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   810  			return err
   811  		}
   812  
   813  		buf, err := ioutil.ReadAll(httpRsp.Body)
   814  		if err != nil {
   815  			return err
   816  		}
   817  
   818  		if err := unm.Unmarshal(buf, resp); err != nil {
   819  			return err
   820  		}
   821  
   822  		return nil
   823  	}, opts...)
   824  	if e != nil {
   825  		return nil, e
   826  	}
   827  	return resp, nil
   828  }
   829  

View as plain text