...

Source file src/cloud.google.com/go/debugger/apiv2/controller2_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 newController2ClientHook clientHook
    43  
    44  // Controller2CallOptions contains the retry settings for each method of Controller2Client.
    45  type Controller2CallOptions struct {
    46  	RegisterDebuggee       []gax.CallOption
    47  	ListActiveBreakpoints  []gax.CallOption
    48  	UpdateActiveBreakpoint []gax.CallOption
    49  }
    50  
    51  func defaultController2GRPCClientOptions() []option.ClientOption {
    52  	return []option.ClientOption{
    53  		internaloption.WithDefaultEndpoint("clouddebugger.googleapis.com:443"),
    54  		internaloption.WithDefaultEndpointTemplate("clouddebugger.UNIVERSE_DOMAIN:443"),
    55  		internaloption.WithDefaultMTLSEndpoint("clouddebugger.mtls.googleapis.com:443"),
    56  		internaloption.WithDefaultAudience("https://clouddebugger.googleapis.com/"),
    57  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    58  		internaloption.EnableJwtWithScope(),
    59  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    60  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    61  	}
    62  }
    63  
    64  func defaultController2CallOptions() *Controller2CallOptions {
    65  	return &Controller2CallOptions{
    66  		RegisterDebuggee: []gax.CallOption{},
    67  		ListActiveBreakpoints: []gax.CallOption{
    68  			gax.WithRetry(func() gax.Retryer {
    69  				return gax.OnCodes([]codes.Code{
    70  					codes.Unavailable,
    71  					codes.DeadlineExceeded,
    72  				}, gax.Backoff{
    73  					Initial:    100 * time.Millisecond,
    74  					Max:        60000 * time.Millisecond,
    75  					Multiplier: 1.30,
    76  				})
    77  			}),
    78  		},
    79  		UpdateActiveBreakpoint: []gax.CallOption{
    80  			gax.WithRetry(func() gax.Retryer {
    81  				return gax.OnCodes([]codes.Code{
    82  					codes.Unavailable,
    83  					codes.DeadlineExceeded,
    84  				}, gax.Backoff{
    85  					Initial:    100 * time.Millisecond,
    86  					Max:        60000 * time.Millisecond,
    87  					Multiplier: 1.30,
    88  				})
    89  			}),
    90  		},
    91  	}
    92  }
    93  
    94  func defaultController2RESTCallOptions() *Controller2CallOptions {
    95  	return &Controller2CallOptions{
    96  		RegisterDebuggee: []gax.CallOption{},
    97  		ListActiveBreakpoints: []gax.CallOption{
    98  			gax.WithRetry(func() gax.Retryer {
    99  				return gax.OnHTTPCodes(gax.Backoff{
   100  					Initial:    100 * time.Millisecond,
   101  					Max:        60000 * time.Millisecond,
   102  					Multiplier: 1.30,
   103  				},
   104  					http.StatusServiceUnavailable,
   105  					http.StatusGatewayTimeout)
   106  			}),
   107  		},
   108  		UpdateActiveBreakpoint: []gax.CallOption{
   109  			gax.WithRetry(func() gax.Retryer {
   110  				return gax.OnHTTPCodes(gax.Backoff{
   111  					Initial:    100 * time.Millisecond,
   112  					Max:        60000 * time.Millisecond,
   113  					Multiplier: 1.30,
   114  				},
   115  					http.StatusServiceUnavailable,
   116  					http.StatusGatewayTimeout)
   117  			}),
   118  		},
   119  	}
   120  }
   121  
   122  // internalController2Client is an interface that defines the methods available from Stackdriver Debugger API.
   123  type internalController2Client interface {
   124  	Close() error
   125  	setGoogleClientInfo(...string)
   126  	Connection() *grpc.ClientConn
   127  	RegisterDebuggee(context.Context, *debuggerpb.RegisterDebuggeeRequest, ...gax.CallOption) (*debuggerpb.RegisterDebuggeeResponse, error)
   128  	ListActiveBreakpoints(context.Context, *debuggerpb.ListActiveBreakpointsRequest, ...gax.CallOption) (*debuggerpb.ListActiveBreakpointsResponse, error)
   129  	UpdateActiveBreakpoint(context.Context, *debuggerpb.UpdateActiveBreakpointRequest, ...gax.CallOption) (*debuggerpb.UpdateActiveBreakpointResponse, error)
   130  }
   131  
   132  // Controller2Client is a client for interacting with Stackdriver Debugger API.
   133  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   134  //
   135  // The Controller service provides the API for orchestrating a collection of
   136  // debugger agents to perform debugging tasks. These agents are each attached
   137  // to a process of an application which may include one or more replicas.
   138  //
   139  // The debugger agents register with the Controller to identify the application
   140  // being debugged, the Debuggee. All agents that register with the same data,
   141  // represent the same Debuggee, and are assigned the same debuggee_id.
   142  //
   143  // The debugger agents call the Controller to retrieve  the list of active
   144  // Breakpoints. Agents with the same debuggee_id get the same breakpoints
   145  // list. An agent that can fulfill the breakpoint request updates the
   146  // Controller with the breakpoint result. The controller selects the first
   147  // result received and discards the rest of the results.
   148  // Agents that poll again for active breakpoints will no longer have
   149  // the completed breakpoint in the list and should remove that breakpoint from
   150  // their attached process.
   151  //
   152  // The Controller service does not provide a way to retrieve the results of
   153  // a completed breakpoint. This functionality is available using the Debugger
   154  // service.
   155  type Controller2Client struct {
   156  	// The internal transport-dependent client.
   157  	internalClient internalController2Client
   158  
   159  	// The call options for this service.
   160  	CallOptions *Controller2CallOptions
   161  }
   162  
   163  // Wrapper methods routed to the internal client.
   164  
   165  // Close closes the connection to the API service. The user should invoke this when
   166  // the client is no longer required.
   167  func (c *Controller2Client) Close() error {
   168  	return c.internalClient.Close()
   169  }
   170  
   171  // setGoogleClientInfo sets the name and version of the application in
   172  // the `x-goog-api-client` header passed on each request. Intended for
   173  // use by Google-written clients.
   174  func (c *Controller2Client) setGoogleClientInfo(keyval ...string) {
   175  	c.internalClient.setGoogleClientInfo(keyval...)
   176  }
   177  
   178  // Connection returns a connection to the API service.
   179  //
   180  // Deprecated: Connections are now pooled so this method does not always
   181  // return the same resource.
   182  func (c *Controller2Client) Connection() *grpc.ClientConn {
   183  	return c.internalClient.Connection()
   184  }
   185  
   186  // RegisterDebuggee registers the debuggee with the controller service.
   187  //
   188  // All agents attached to the same application must call this method with
   189  // exactly the same request content to get back the same stable debuggee_id.
   190  // Agents should call this method again whenever google.rpc.Code.NOT_FOUND
   191  // is returned from any controller method.
   192  //
   193  // This protocol allows the controller service to disable debuggees, recover
   194  // from data loss, or change the debuggee_id format. Agents must handle
   195  // debuggee_id value changing upon re-registration.
   196  func (c *Controller2Client) RegisterDebuggee(ctx context.Context, req *debuggerpb.RegisterDebuggeeRequest, opts ...gax.CallOption) (*debuggerpb.RegisterDebuggeeResponse, error) {
   197  	return c.internalClient.RegisterDebuggee(ctx, req, opts...)
   198  }
   199  
   200  // ListActiveBreakpoints returns the list of all active breakpoints for the debuggee.
   201  //
   202  // The breakpoint specification (location, condition, and expressions
   203  // fields) is semantically immutable, although the field values may
   204  // change. For example, an agent may update the location line number
   205  // to reflect the actual line where the breakpoint was set, but this
   206  // doesn’t change the breakpoint semantics.
   207  //
   208  // This means that an agent does not need to check if a breakpoint has changed
   209  // when it encounters the same breakpoint on a successive call.
   210  // Moreover, an agent should remember the breakpoints that are completed
   211  // until the controller removes them from the active list to avoid
   212  // setting those breakpoints again.
   213  func (c *Controller2Client) ListActiveBreakpoints(ctx context.Context, req *debuggerpb.ListActiveBreakpointsRequest, opts ...gax.CallOption) (*debuggerpb.ListActiveBreakpointsResponse, error) {
   214  	return c.internalClient.ListActiveBreakpoints(ctx, req, opts...)
   215  }
   216  
   217  // UpdateActiveBreakpoint updates the breakpoint state or mutable fields.
   218  // The entire Breakpoint message must be sent back to the controller service.
   219  //
   220  // Updates to active breakpoint fields are only allowed if the new value
   221  // does not change the breakpoint specification. Updates to the location,
   222  // condition and expressions fields should not alter the breakpoint
   223  // semantics. These may only make changes such as canonicalizing a value
   224  // or snapping the location to the correct line of code.
   225  func (c *Controller2Client) UpdateActiveBreakpoint(ctx context.Context, req *debuggerpb.UpdateActiveBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.UpdateActiveBreakpointResponse, error) {
   226  	return c.internalClient.UpdateActiveBreakpoint(ctx, req, opts...)
   227  }
   228  
   229  // controller2GRPCClient is a client for interacting with Stackdriver Debugger API over gRPC transport.
   230  //
   231  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   232  type controller2GRPCClient struct {
   233  	// Connection pool of gRPC connections to the service.
   234  	connPool gtransport.ConnPool
   235  
   236  	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
   237  	disableDeadlines bool
   238  
   239  	// Points back to the CallOptions field of the containing Controller2Client
   240  	CallOptions **Controller2CallOptions
   241  
   242  	// The gRPC API client.
   243  	controller2Client debuggerpb.Controller2Client
   244  
   245  	// The x-goog-* metadata to be sent with each request.
   246  	xGoogMetadata metadata.MD
   247  }
   248  
   249  // NewController2Client creates a new controller2 client based on gRPC.
   250  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   251  //
   252  // The Controller service provides the API for orchestrating a collection of
   253  // debugger agents to perform debugging tasks. These agents are each attached
   254  // to a process of an application which may include one or more replicas.
   255  //
   256  // The debugger agents register with the Controller to identify the application
   257  // being debugged, the Debuggee. All agents that register with the same data,
   258  // represent the same Debuggee, and are assigned the same debuggee_id.
   259  //
   260  // The debugger agents call the Controller to retrieve  the list of active
   261  // Breakpoints. Agents with the same debuggee_id get the same breakpoints
   262  // list. An agent that can fulfill the breakpoint request updates the
   263  // Controller with the breakpoint result. The controller selects the first
   264  // result received and discards the rest of the results.
   265  // Agents that poll again for active breakpoints will no longer have
   266  // the completed breakpoint in the list and should remove that breakpoint from
   267  // their attached process.
   268  //
   269  // The Controller service does not provide a way to retrieve the results of
   270  // a completed breakpoint. This functionality is available using the Debugger
   271  // service.
   272  func NewController2Client(ctx context.Context, opts ...option.ClientOption) (*Controller2Client, error) {
   273  	clientOpts := defaultController2GRPCClientOptions()
   274  	if newController2ClientHook != nil {
   275  		hookOpts, err := newController2ClientHook(ctx, clientHookParams{})
   276  		if err != nil {
   277  			return nil, err
   278  		}
   279  		clientOpts = append(clientOpts, hookOpts...)
   280  	}
   281  
   282  	disableDeadlines, err := checkDisableDeadlines()
   283  	if err != nil {
   284  		return nil, err
   285  	}
   286  
   287  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   288  	if err != nil {
   289  		return nil, err
   290  	}
   291  	client := Controller2Client{CallOptions: defaultController2CallOptions()}
   292  
   293  	c := &controller2GRPCClient{
   294  		connPool:          connPool,
   295  		disableDeadlines:  disableDeadlines,
   296  		controller2Client: debuggerpb.NewController2Client(connPool),
   297  		CallOptions:       &client.CallOptions,
   298  	}
   299  	c.setGoogleClientInfo()
   300  
   301  	client.internalClient = c
   302  
   303  	return &client, nil
   304  }
   305  
   306  // Connection returns a connection to the API service.
   307  //
   308  // Deprecated: Connections are now pooled so this method does not always
   309  // return the same resource.
   310  func (c *controller2GRPCClient) Connection() *grpc.ClientConn {
   311  	return c.connPool.Conn()
   312  }
   313  
   314  // setGoogleClientInfo sets the name and version of the application in
   315  // the `x-goog-api-client` header passed on each request. Intended for
   316  // use by Google-written clients.
   317  func (c *controller2GRPCClient) setGoogleClientInfo(keyval ...string) {
   318  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   319  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   320  	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
   321  }
   322  
   323  // Close closes the connection to the API service. The user should invoke this when
   324  // the client is no longer required.
   325  func (c *controller2GRPCClient) Close() error {
   326  	return c.connPool.Close()
   327  }
   328  
   329  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   330  type controller2RESTClient struct {
   331  	// The http endpoint to connect to.
   332  	endpoint string
   333  
   334  	// The http client.
   335  	httpClient *http.Client
   336  
   337  	// The x-goog-* metadata to be sent with each request.
   338  	xGoogMetadata metadata.MD
   339  
   340  	// Points back to the CallOptions field of the containing Controller2Client
   341  	CallOptions **Controller2CallOptions
   342  }
   343  
   344  // NewController2RESTClient creates a new controller2 rest client.
   345  //
   346  // The Controller service provides the API for orchestrating a collection of
   347  // debugger agents to perform debugging tasks. These agents are each attached
   348  // to a process of an application which may include one or more replicas.
   349  //
   350  // The debugger agents register with the Controller to identify the application
   351  // being debugged, the Debuggee. All agents that register with the same data,
   352  // represent the same Debuggee, and are assigned the same debuggee_id.
   353  //
   354  // The debugger agents call the Controller to retrieve  the list of active
   355  // Breakpoints. Agents with the same debuggee_id get the same breakpoints
   356  // list. An agent that can fulfill the breakpoint request updates the
   357  // Controller with the breakpoint result. The controller selects the first
   358  // result received and discards the rest of the results.
   359  // Agents that poll again for active breakpoints will no longer have
   360  // the completed breakpoint in the list and should remove that breakpoint from
   361  // their attached process.
   362  //
   363  // The Controller service does not provide a way to retrieve the results of
   364  // a completed breakpoint. This functionality is available using the Debugger
   365  // service.
   366  func NewController2RESTClient(ctx context.Context, opts ...option.ClientOption) (*Controller2Client, error) {
   367  	clientOpts := append(defaultController2RESTClientOptions(), opts...)
   368  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   369  	if err != nil {
   370  		return nil, err
   371  	}
   372  
   373  	callOpts := defaultController2RESTCallOptions()
   374  	c := &controller2RESTClient{
   375  		endpoint:    endpoint,
   376  		httpClient:  httpClient,
   377  		CallOptions: &callOpts,
   378  	}
   379  	c.setGoogleClientInfo()
   380  
   381  	return &Controller2Client{internalClient: c, CallOptions: callOpts}, nil
   382  }
   383  
   384  func defaultController2RESTClientOptions() []option.ClientOption {
   385  	return []option.ClientOption{
   386  		internaloption.WithDefaultEndpoint("https://clouddebugger.googleapis.com"),
   387  		internaloption.WithDefaultEndpointTemplate("https://clouddebugger.UNIVERSE_DOMAIN"),
   388  		internaloption.WithDefaultMTLSEndpoint("https://clouddebugger.mtls.googleapis.com"),
   389  		internaloption.WithDefaultAudience("https://clouddebugger.googleapis.com/"),
   390  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   391  	}
   392  }
   393  
   394  // setGoogleClientInfo sets the name and version of the application in
   395  // the `x-goog-api-client` header passed on each request. Intended for
   396  // use by Google-written clients.
   397  func (c *controller2RESTClient) setGoogleClientInfo(keyval ...string) {
   398  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   399  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
   400  	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
   401  }
   402  
   403  // Close closes the connection to the API service. The user should invoke this when
   404  // the client is no longer required.
   405  func (c *controller2RESTClient) Close() error {
   406  	// Replace httpClient with nil to force cleanup.
   407  	c.httpClient = nil
   408  	return nil
   409  }
   410  
   411  // Connection returns a connection to the API service.
   412  //
   413  // Deprecated: This method always returns nil.
   414  func (c *controller2RESTClient) Connection() *grpc.ClientConn {
   415  	return nil
   416  }
   417  func (c *controller2GRPCClient) RegisterDebuggee(ctx context.Context, req *debuggerpb.RegisterDebuggeeRequest, opts ...gax.CallOption) (*debuggerpb.RegisterDebuggeeResponse, error) {
   418  	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
   419  		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
   420  		defer cancel()
   421  		ctx = cctx
   422  	}
   423  	ctx = insertMetadata(ctx, c.xGoogMetadata)
   424  	opts = append((*c.CallOptions).RegisterDebuggee[0:len((*c.CallOptions).RegisterDebuggee):len((*c.CallOptions).RegisterDebuggee)], opts...)
   425  	var resp *debuggerpb.RegisterDebuggeeResponse
   426  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   427  		var err error
   428  		resp, err = c.controller2Client.RegisterDebuggee(ctx, req, settings.GRPC...)
   429  		return err
   430  	}, opts...)
   431  	if err != nil {
   432  		return nil, err
   433  	}
   434  	return resp, nil
   435  }
   436  
   437  func (c *controller2GRPCClient) ListActiveBreakpoints(ctx context.Context, req *debuggerpb.ListActiveBreakpointsRequest, opts ...gax.CallOption) (*debuggerpb.ListActiveBreakpointsResponse, error) {
   438  	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
   439  		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
   440  		defer cancel()
   441  		ctx = cctx
   442  	}
   443  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId())))
   444  
   445  	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
   446  	opts = append((*c.CallOptions).ListActiveBreakpoints[0:len((*c.CallOptions).ListActiveBreakpoints):len((*c.CallOptions).ListActiveBreakpoints)], opts...)
   447  	var resp *debuggerpb.ListActiveBreakpointsResponse
   448  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   449  		var err error
   450  		resp, err = c.controller2Client.ListActiveBreakpoints(ctx, req, settings.GRPC...)
   451  		return err
   452  	}, opts...)
   453  	if err != nil {
   454  		return nil, err
   455  	}
   456  	return resp, nil
   457  }
   458  
   459  func (c *controller2GRPCClient) UpdateActiveBreakpoint(ctx context.Context, req *debuggerpb.UpdateActiveBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.UpdateActiveBreakpointResponse, error) {
   460  	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
   461  		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
   462  		defer cancel()
   463  		ctx = cctx
   464  	}
   465  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId()), "breakpoint.id", url.QueryEscape(req.GetBreakpoint().GetId())))
   466  
   467  	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
   468  	opts = append((*c.CallOptions).UpdateActiveBreakpoint[0:len((*c.CallOptions).UpdateActiveBreakpoint):len((*c.CallOptions).UpdateActiveBreakpoint)], opts...)
   469  	var resp *debuggerpb.UpdateActiveBreakpointResponse
   470  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   471  		var err error
   472  		resp, err = c.controller2Client.UpdateActiveBreakpoint(ctx, req, settings.GRPC...)
   473  		return err
   474  	}, opts...)
   475  	if err != nil {
   476  		return nil, err
   477  	}
   478  	return resp, nil
   479  }
   480  
   481  // RegisterDebuggee registers the debuggee with the controller service.
   482  //
   483  // All agents attached to the same application must call this method with
   484  // exactly the same request content to get back the same stable debuggee_id.
   485  // Agents should call this method again whenever google.rpc.Code.NOT_FOUND
   486  // is returned from any controller method.
   487  //
   488  // This protocol allows the controller service to disable debuggees, recover
   489  // from data loss, or change the debuggee_id format. Agents must handle
   490  // debuggee_id value changing upon re-registration.
   491  func (c *controller2RESTClient) RegisterDebuggee(ctx context.Context, req *debuggerpb.RegisterDebuggeeRequest, opts ...gax.CallOption) (*debuggerpb.RegisterDebuggeeResponse, error) {
   492  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   493  	jsonReq, err := m.Marshal(req)
   494  	if err != nil {
   495  		return nil, err
   496  	}
   497  
   498  	baseUrl, err := url.Parse(c.endpoint)
   499  	if err != nil {
   500  		return nil, err
   501  	}
   502  	baseUrl.Path += fmt.Sprintf("/v2/controller/debuggees/register")
   503  
   504  	params := url.Values{}
   505  	params.Add("$alt", "json;enum-encoding=int")
   506  
   507  	baseUrl.RawQuery = params.Encode()
   508  
   509  	// Build HTTP headers from client and context metadata.
   510  	headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json"))
   511  	opts = append((*c.CallOptions).RegisterDebuggee[0:len((*c.CallOptions).RegisterDebuggee):len((*c.CallOptions).RegisterDebuggee)], opts...)
   512  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   513  	resp := &debuggerpb.RegisterDebuggeeResponse{}
   514  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   515  		if settings.Path != "" {
   516  			baseUrl.Path = settings.Path
   517  		}
   518  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   519  		if err != nil {
   520  			return err
   521  		}
   522  		httpReq = httpReq.WithContext(ctx)
   523  		httpReq.Header = headers
   524  
   525  		httpRsp, err := c.httpClient.Do(httpReq)
   526  		if err != nil {
   527  			return err
   528  		}
   529  		defer httpRsp.Body.Close()
   530  
   531  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   532  			return err
   533  		}
   534  
   535  		buf, err := ioutil.ReadAll(httpRsp.Body)
   536  		if err != nil {
   537  			return err
   538  		}
   539  
   540  		if err := unm.Unmarshal(buf, resp); err != nil {
   541  			return err
   542  		}
   543  
   544  		return nil
   545  	}, opts...)
   546  	if e != nil {
   547  		return nil, e
   548  	}
   549  	return resp, nil
   550  }
   551  
   552  // ListActiveBreakpoints returns the list of all active breakpoints for the debuggee.
   553  //
   554  // The breakpoint specification (location, condition, and expressions
   555  // fields) is semantically immutable, although the field values may
   556  // change. For example, an agent may update the location line number
   557  // to reflect the actual line where the breakpoint was set, but this
   558  // doesn’t change the breakpoint semantics.
   559  //
   560  // This means that an agent does not need to check if a breakpoint has changed
   561  // when it encounters the same breakpoint on a successive call.
   562  // Moreover, an agent should remember the breakpoints that are completed
   563  // until the controller removes them from the active list to avoid
   564  // setting those breakpoints again.
   565  func (c *controller2RESTClient) ListActiveBreakpoints(ctx context.Context, req *debuggerpb.ListActiveBreakpointsRequest, opts ...gax.CallOption) (*debuggerpb.ListActiveBreakpointsResponse, error) {
   566  	baseUrl, err := url.Parse(c.endpoint)
   567  	if err != nil {
   568  		return nil, err
   569  	}
   570  	baseUrl.Path += fmt.Sprintf("/v2/controller/debuggees/%v/breakpoints", req.GetDebuggeeId())
   571  
   572  	params := url.Values{}
   573  	params.Add("$alt", "json;enum-encoding=int")
   574  	if req.GetSuccessOnTimeout() {
   575  		params.Add("successOnTimeout", fmt.Sprintf("%v", req.GetSuccessOnTimeout()))
   576  	}
   577  	if req.GetWaitToken() != "" {
   578  		params.Add("waitToken", fmt.Sprintf("%v", req.GetWaitToken()))
   579  	}
   580  
   581  	baseUrl.RawQuery = params.Encode()
   582  
   583  	// Build HTTP headers from client and context metadata.
   584  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId())))
   585  
   586  	headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
   587  	opts = append((*c.CallOptions).ListActiveBreakpoints[0:len((*c.CallOptions).ListActiveBreakpoints):len((*c.CallOptions).ListActiveBreakpoints)], opts...)
   588  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   589  	resp := &debuggerpb.ListActiveBreakpointsResponse{}
   590  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   591  		if settings.Path != "" {
   592  			baseUrl.Path = settings.Path
   593  		}
   594  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   595  		if err != nil {
   596  			return err
   597  		}
   598  		httpReq = httpReq.WithContext(ctx)
   599  		httpReq.Header = headers
   600  
   601  		httpRsp, err := c.httpClient.Do(httpReq)
   602  		if err != nil {
   603  			return err
   604  		}
   605  		defer httpRsp.Body.Close()
   606  
   607  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   608  			return err
   609  		}
   610  
   611  		buf, err := ioutil.ReadAll(httpRsp.Body)
   612  		if err != nil {
   613  			return err
   614  		}
   615  
   616  		if err := unm.Unmarshal(buf, resp); err != nil {
   617  			return err
   618  		}
   619  
   620  		return nil
   621  	}, opts...)
   622  	if e != nil {
   623  		return nil, e
   624  	}
   625  	return resp, nil
   626  }
   627  
   628  // UpdateActiveBreakpoint updates the breakpoint state or mutable fields.
   629  // The entire Breakpoint message must be sent back to the controller service.
   630  //
   631  // Updates to active breakpoint fields are only allowed if the new value
   632  // does not change the breakpoint specification. Updates to the location,
   633  // condition and expressions fields should not alter the breakpoint
   634  // semantics. These may only make changes such as canonicalizing a value
   635  // or snapping the location to the correct line of code.
   636  func (c *controller2RESTClient) UpdateActiveBreakpoint(ctx context.Context, req *debuggerpb.UpdateActiveBreakpointRequest, opts ...gax.CallOption) (*debuggerpb.UpdateActiveBreakpointResponse, error) {
   637  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   638  	jsonReq, err := m.Marshal(req)
   639  	if err != nil {
   640  		return nil, err
   641  	}
   642  
   643  	baseUrl, err := url.Parse(c.endpoint)
   644  	if err != nil {
   645  		return nil, err
   646  	}
   647  	baseUrl.Path += fmt.Sprintf("/v2/controller/debuggees/%v/breakpoints/%v", req.GetDebuggeeId(), req.GetBreakpoint().GetId())
   648  
   649  	params := url.Values{}
   650  	params.Add("$alt", "json;enum-encoding=int")
   651  
   652  	baseUrl.RawQuery = params.Encode()
   653  
   654  	// Build HTTP headers from client and context metadata.
   655  	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId()), "breakpoint.id", url.QueryEscape(req.GetBreakpoint().GetId())))
   656  
   657  	headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
   658  	opts = append((*c.CallOptions).UpdateActiveBreakpoint[0:len((*c.CallOptions).UpdateActiveBreakpoint):len((*c.CallOptions).UpdateActiveBreakpoint)], opts...)
   659  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   660  	resp := &debuggerpb.UpdateActiveBreakpointResponse{}
   661  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   662  		if settings.Path != "" {
   663  			baseUrl.Path = settings.Path
   664  		}
   665  		httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
   666  		if err != nil {
   667  			return err
   668  		}
   669  		httpReq = httpReq.WithContext(ctx)
   670  		httpReq.Header = headers
   671  
   672  		httpRsp, err := c.httpClient.Do(httpReq)
   673  		if err != nil {
   674  			return err
   675  		}
   676  		defer httpRsp.Body.Close()
   677  
   678  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   679  			return err
   680  		}
   681  
   682  		buf, err := ioutil.ReadAll(httpRsp.Body)
   683  		if err != nil {
   684  			return err
   685  		}
   686  
   687  		if err := unm.Unmarshal(buf, resp); err != nil {
   688  			return err
   689  		}
   690  
   691  		return nil
   692  	}, opts...)
   693  	if e != nil {
   694  		return nil, e
   695  	}
   696  	return resp, nil
   697  }
   698  

View as plain text