From dba159ced53d0dcb11a2f633500d46efad3f0b4d Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 16 Feb 2021 10:56:06 +0300 Subject: [PATCH 1/5] PMM-5194 Tunnels --- Gopkg.lock | 7 +- Gopkg.toml | 3 +- .../client/agent_local/status2_responses.go | 34 +- .../client/agent_local/status_responses.go | 75 ++++- .../json/client/pmm_inventory_client.go | 5 + .../client/tunnels/add_tunnel_parameters.go | 131 ++++++++ .../client/tunnels/add_tunnel_responses.go | 302 ++++++++++++++++++ .../client/tunnels/list_tunnels_parameters.go | 133 ++++++++ .../client/tunnels/list_tunnels_responses.go | 300 +++++++++++++++++ .../tunnels/remove_tunnel_parameters.go | 131 ++++++++ .../client/tunnels/remove_tunnel_responses.go | 223 +++++++++++++ .../json/client/tunnels/tunnels_client.go | 139 ++++++++ 12 files changed, 1477 insertions(+), 6 deletions(-) create mode 100644 vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/add_tunnel_parameters.go create mode 100644 vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/add_tunnel_responses.go create mode 100644 vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_parameters.go create mode 100644 vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go create mode 100644 vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/remove_tunnel_parameters.go create mode 100644 vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/remove_tunnel_responses.go create mode 100644 vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/tunnels_client.go diff --git a/Gopkg.lock b/Gopkg.lock index 1498f6e7..a26413f4 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -240,8 +240,8 @@ version = "v1.1.2" [[projects]] - branch = "PMM-2.0" - digest = "1:0b55cc70802a3d417bc8cabe030255107001bfd4e32408bfdcb3503e23e83781" + branch = "PMM-5194-tunnels" + digest = "1:7f25af86aa84a21f7be1a18c3e05f5b1ef819ae8beacf4883b848f977e492fb1" name = "github.com/percona/pmm" packages = [ "api/agentlocalpb/json/client", @@ -250,6 +250,7 @@ "api/inventorypb/json/client/agents", "api/inventorypb/json/client/nodes", "api/inventorypb/json/client/services", + "api/inventorypb/json/client/tunnels", "api/inventorypb/types", "api/managementpb/json/client", "api/managementpb/json/client/actions", @@ -271,7 +272,7 @@ "version", ] pruneopts = "NUT" - revision = "4559713b8bc01ab2538bd183bca387cebe624966" + revision = "94cf2834063285cf7f27a63b448e75180ed3c289" [[projects]] digest = "1:14715f705ff5dfe0ffd6571d7d201dd8e921030f8070321a79380d8ca4ec1a24" diff --git a/Gopkg.toml b/Gopkg.toml index f3410dea..74736a8e 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -11,7 +11,8 @@ required = [ [[constraint]] name = "github.com/percona/pmm" - branch = "PMM-2.0" + # branch = "PMM-2.0" + branch = "PMM-5194-tunnels" # https://jira.percona.com/browse/PMM-4081 # https://jira.percona.com/browse/PMM-4042 diff --git a/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status2_responses.go b/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status2_responses.go index f04ef8fd..191d3777 100644 --- a/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status2_responses.go +++ b/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status2_responses.go @@ -203,7 +203,7 @@ type Status2OKBody struct { // runs on node id RunsOnNodeID string `json:"runs_on_node_id,omitempty"` - // agents info + // Agents information. AgentsInfo []*AgentsInfoItems0 `json:"agents_info"` // Config file path if pmm-agent was started with one. @@ -212,6 +212,9 @@ type Status2OKBody struct { // PMM Agent version. AgentVersion string `json:"agent_version,omitempty"` + // Tunnels information. + TunnelsInfo []*TunnelsInfoItems0 `json:"tunnels_info"` + // server info ServerInfo *Status2OKBodyServerInfo `json:"server_info,omitempty"` } @@ -224,6 +227,10 @@ func (o *Status2OKBody) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := o.validateTunnelsInfo(formats); err != nil { + res = append(res, err) + } + if err := o.validateServerInfo(formats); err != nil { res = append(res, err) } @@ -259,6 +266,31 @@ func (o *Status2OKBody) validateAgentsInfo(formats strfmt.Registry) error { return nil } +func (o *Status2OKBody) validateTunnelsInfo(formats strfmt.Registry) error { + + if swag.IsZero(o.TunnelsInfo) { // not required + return nil + } + + for i := 0; i < len(o.TunnelsInfo); i++ { + if swag.IsZero(o.TunnelsInfo[i]) { // not required + continue + } + + if o.TunnelsInfo[i] != nil { + if err := o.TunnelsInfo[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("status2Ok" + "." + "tunnels_info" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (o *Status2OKBody) validateServerInfo(formats strfmt.Registry) error { if swag.IsZero(o.ServerInfo) { // not required diff --git a/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status_responses.go b/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status_responses.go index b4a8ebc9..35e018d8 100644 --- a/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status_responses.go +++ b/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status_responses.go @@ -437,7 +437,7 @@ type StatusOKBody struct { // runs on node id RunsOnNodeID string `json:"runs_on_node_id,omitempty"` - // agents info + // Agents information. AgentsInfo []*AgentsInfoItems0 `json:"agents_info"` // Config file path if pmm-agent was started with one. @@ -446,6 +446,9 @@ type StatusOKBody struct { // PMM Agent version. AgentVersion string `json:"agent_version,omitempty"` + // Tunnels information. + TunnelsInfo []*TunnelsInfoItems0 `json:"tunnels_info"` + // server info ServerInfo *StatusOKBodyServerInfo `json:"server_info,omitempty"` } @@ -458,6 +461,10 @@ func (o *StatusOKBody) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := o.validateTunnelsInfo(formats); err != nil { + res = append(res, err) + } + if err := o.validateServerInfo(formats); err != nil { res = append(res, err) } @@ -493,6 +500,31 @@ func (o *StatusOKBody) validateAgentsInfo(formats strfmt.Registry) error { return nil } +func (o *StatusOKBody) validateTunnelsInfo(formats strfmt.Registry) error { + + if swag.IsZero(o.TunnelsInfo) { // not required + return nil + } + + for i := 0; i < len(o.TunnelsInfo); i++ { + if swag.IsZero(o.TunnelsInfo[i]) { // not required + continue + } + + if o.TunnelsInfo[i] != nil { + if err := o.TunnelsInfo[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("statusOk" + "." + "tunnels_info" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (o *StatusOKBody) validateServerInfo(formats strfmt.Registry) error { if swag.IsZero(o.ServerInfo) { // not required @@ -575,3 +607,44 @@ func (o *StatusOKBodyServerInfo) UnmarshalBinary(b []byte) error { *o = res return nil } + +/*TunnelsInfoItems0 TunnelInfo contains information about Tunnel managed by pmm-agent. +swagger:model TunnelsInfoItems0 +*/ +type TunnelsInfoItems0 struct { + + // Tunnel ID. + TunnelID string `json:"tunnel_id,omitempty"` + + // Listen port of the listening pmm-agent. + ListenPort int64 `json:"listen_port,omitempty"` + + // Target port of the connecting pmm-agent. + ConnectPort int64 `json:"connect_port,omitempty"` + + // The current number of established connections. + CurrentConnection int64 `json:"current_connection,omitempty"` +} + +// Validate validates this tunnels info items0 +func (o *TunnelsInfoItems0) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *TunnelsInfoItems0) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *TunnelsInfoItems0) UnmarshalBinary(b []byte) error { + var res TunnelsInfoItems0 + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/pmm_inventory_client.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/pmm_inventory_client.go index 97cf7546..c1163472 100644 --- a/vendor/github.com/percona/pmm/api/inventorypb/json/client/pmm_inventory_client.go +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/pmm_inventory_client.go @@ -13,6 +13,7 @@ import ( "github.com/percona/pmm/api/inventorypb/json/client/agents" "github.com/percona/pmm/api/inventorypb/json/client/nodes" "github.com/percona/pmm/api/inventorypb/json/client/services" + "github.com/percona/pmm/api/inventorypb/json/client/tunnels" ) // Default PMM inventory HTTP client. @@ -60,6 +61,7 @@ func New(transport runtime.ClientTransport, formats strfmt.Registry) *PMMInvento cli.Agents = agents.New(transport, formats) cli.Nodes = nodes.New(transport, formats) cli.Services = services.New(transport, formats) + cli.Tunnels = tunnels.New(transport, formats) return cli } @@ -110,6 +112,8 @@ type PMMInventory struct { Services services.ClientService + Tunnels tunnels.ClientService + Transport runtime.ClientTransport } @@ -119,4 +123,5 @@ func (c *PMMInventory) SetTransport(transport runtime.ClientTransport) { c.Agents.SetTransport(transport) c.Nodes.SetTransport(transport) c.Services.SetTransport(transport) + c.Tunnels.SetTransport(transport) } diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/add_tunnel_parameters.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/add_tunnel_parameters.go new file mode 100644 index 00000000..d622f547 --- /dev/null +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/add_tunnel_parameters.go @@ -0,0 +1,131 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tunnels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewAddTunnelParams creates a new AddTunnelParams object +// with the default values initialized. +func NewAddTunnelParams() *AddTunnelParams { + var () + return &AddTunnelParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewAddTunnelParamsWithTimeout creates a new AddTunnelParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewAddTunnelParamsWithTimeout(timeout time.Duration) *AddTunnelParams { + var () + return &AddTunnelParams{ + + timeout: timeout, + } +} + +// NewAddTunnelParamsWithContext creates a new AddTunnelParams object +// with the default values initialized, and the ability to set a context for a request +func NewAddTunnelParamsWithContext(ctx context.Context) *AddTunnelParams { + var () + return &AddTunnelParams{ + + Context: ctx, + } +} + +// NewAddTunnelParamsWithHTTPClient creates a new AddTunnelParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewAddTunnelParamsWithHTTPClient(client *http.Client) *AddTunnelParams { + var () + return &AddTunnelParams{ + HTTPClient: client, + } +} + +/*AddTunnelParams contains all the parameters to send to the API endpoint +for the add tunnel operation typically these are written to a http.Request +*/ +type AddTunnelParams struct { + + /*Body*/ + Body AddTunnelBody + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the add tunnel params +func (o *AddTunnelParams) WithTimeout(timeout time.Duration) *AddTunnelParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the add tunnel params +func (o *AddTunnelParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the add tunnel params +func (o *AddTunnelParams) WithContext(ctx context.Context) *AddTunnelParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the add tunnel params +func (o *AddTunnelParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the add tunnel params +func (o *AddTunnelParams) WithHTTPClient(client *http.Client) *AddTunnelParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the add tunnel params +func (o *AddTunnelParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the add tunnel params +func (o *AddTunnelParams) WithBody(body AddTunnelBody) *AddTunnelParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the add tunnel params +func (o *AddTunnelParams) SetBody(body AddTunnelBody) { + o.Body = body +} + +// WriteToRequest writes these params to a swagger request +func (o *AddTunnelParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/add_tunnel_responses.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/add_tunnel_responses.go new file mode 100644 index 00000000..7ff9ec6f --- /dev/null +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/add_tunnel_responses.go @@ -0,0 +1,302 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tunnels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// AddTunnelReader is a Reader for the AddTunnel structure. +type AddTunnelReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *AddTunnelReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewAddTunnelOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewAddTunnelDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewAddTunnelOK creates a AddTunnelOK with default headers values +func NewAddTunnelOK() *AddTunnelOK { + return &AddTunnelOK{} +} + +/*AddTunnelOK handles this case with default header values. + +A successful response. +*/ +type AddTunnelOK struct { + Payload *AddTunnelOKBody +} + +func (o *AddTunnelOK) Error() string { + return fmt.Sprintf("[POST /v1/inventory/Tunnels/Add][%d] addTunnelOk %+v", 200, o.Payload) +} + +func (o *AddTunnelOK) GetPayload() *AddTunnelOKBody { + return o.Payload +} + +func (o *AddTunnelOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(AddTunnelOKBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewAddTunnelDefault creates a AddTunnelDefault with default headers values +func NewAddTunnelDefault(code int) *AddTunnelDefault { + return &AddTunnelDefault{ + _statusCode: code, + } +} + +/*AddTunnelDefault handles this case with default header values. + +An unexpected error response. +*/ +type AddTunnelDefault struct { + _statusCode int + + Payload *AddTunnelDefaultBody +} + +// Code gets the status code for the add tunnel default response +func (o *AddTunnelDefault) Code() int { + return o._statusCode +} + +func (o *AddTunnelDefault) Error() string { + return fmt.Sprintf("[POST /v1/inventory/Tunnels/Add][%d] AddTunnel default %+v", o._statusCode, o.Payload) +} + +func (o *AddTunnelDefault) GetPayload() *AddTunnelDefaultBody { + return o.Payload +} + +func (o *AddTunnelDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(AddTunnelDefaultBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +/*AddTunnelBody add tunnel body +swagger:model AddTunnelBody +*/ +type AddTunnelBody struct { + + // Agent ID of the listening pmm-agent. + ListenAgentID string `json:"listen_agent_id,omitempty"` + + // Listen port of the listening pmm-agent. + ListenPort int64 `json:"listen_port,omitempty"` + + // Agent ID of the connecting pmm-agent. + ConnectAgentID string `json:"connect_agent_id,omitempty"` + + // Target port of the connecting pmm-agent. + ConnectPort int64 `json:"connect_port,omitempty"` +} + +// Validate validates this add tunnel body +func (o *AddTunnelBody) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *AddTunnelBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *AddTunnelBody) UnmarshalBinary(b []byte) error { + var res AddTunnelBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} + +/*AddTunnelDefaultBody add tunnel default body +swagger:model AddTunnelDefaultBody +*/ +type AddTunnelDefaultBody struct { + + // error + Error string `json:"error,omitempty"` + + // code + Code int32 `json:"code,omitempty"` + + // message + Message string `json:"message,omitempty"` + + // details + Details []*DetailsItems0 `json:"details"` +} + +// Validate validates this add tunnel default body +func (o *AddTunnelDefaultBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateDetails(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *AddTunnelDefaultBody) validateDetails(formats strfmt.Registry) error { + + if swag.IsZero(o.Details) { // not required + return nil + } + + for i := 0; i < len(o.Details); i++ { + if swag.IsZero(o.Details[i]) { // not required + continue + } + + if o.Details[i] != nil { + if err := o.Details[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("AddTunnel default" + "." + "details" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (o *AddTunnelDefaultBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *AddTunnelDefaultBody) UnmarshalBinary(b []byte) error { + var res AddTunnelDefaultBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} + +/*AddTunnelOKBody add tunnel OK body +swagger:model AddTunnelOKBody +*/ +type AddTunnelOKBody struct { + + // Tunnel ID. + TunnelID string `json:"tunnel_id,omitempty"` +} + +// Validate validates this add tunnel OK body +func (o *AddTunnelOKBody) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *AddTunnelOKBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *AddTunnelOKBody) UnmarshalBinary(b []byte) error { + var res AddTunnelOKBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} + +/*DetailsItems0 details items0 +swagger:model DetailsItems0 +*/ +type DetailsItems0 struct { + + // type url + TypeURL string `json:"type_url,omitempty"` + + // value + // Format: byte + Value strfmt.Base64 `json:"value,omitempty"` +} + +// Validate validates this details items0 +func (o *DetailsItems0) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *DetailsItems0) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *DetailsItems0) UnmarshalBinary(b []byte) error { + var res DetailsItems0 + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_parameters.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_parameters.go new file mode 100644 index 00000000..f338ec7f --- /dev/null +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_parameters.go @@ -0,0 +1,133 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tunnels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewListTunnelsParams creates a new ListTunnelsParams object +// with the default values initialized. +func NewListTunnelsParams() *ListTunnelsParams { + var () + return &ListTunnelsParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewListTunnelsParamsWithTimeout creates a new ListTunnelsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewListTunnelsParamsWithTimeout(timeout time.Duration) *ListTunnelsParams { + var () + return &ListTunnelsParams{ + + timeout: timeout, + } +} + +// NewListTunnelsParamsWithContext creates a new ListTunnelsParams object +// with the default values initialized, and the ability to set a context for a request +func NewListTunnelsParamsWithContext(ctx context.Context) *ListTunnelsParams { + var () + return &ListTunnelsParams{ + + Context: ctx, + } +} + +// NewListTunnelsParamsWithHTTPClient creates a new ListTunnelsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewListTunnelsParamsWithHTTPClient(client *http.Client) *ListTunnelsParams { + var () + return &ListTunnelsParams{ + HTTPClient: client, + } +} + +/*ListTunnelsParams contains all the parameters to send to the API endpoint +for the list tunnels operation typically these are written to a http.Request +*/ +type ListTunnelsParams struct { + + /*Body*/ + Body interface{} + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the list tunnels params +func (o *ListTunnelsParams) WithTimeout(timeout time.Duration) *ListTunnelsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the list tunnels params +func (o *ListTunnelsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the list tunnels params +func (o *ListTunnelsParams) WithContext(ctx context.Context) *ListTunnelsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the list tunnels params +func (o *ListTunnelsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the list tunnels params +func (o *ListTunnelsParams) WithHTTPClient(client *http.Client) *ListTunnelsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the list tunnels params +func (o *ListTunnelsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the list tunnels params +func (o *ListTunnelsParams) WithBody(body interface{}) *ListTunnelsParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the list tunnels params +func (o *ListTunnelsParams) SetBody(body interface{}) { + o.Body = body +} + +// WriteToRequest writes these params to a swagger request +func (o *ListTunnelsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.Body != nil { + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go new file mode 100644 index 00000000..ff7fb9c9 --- /dev/null +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go @@ -0,0 +1,300 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tunnels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// ListTunnelsReader is a Reader for the ListTunnels structure. +type ListTunnelsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *ListTunnelsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewListTunnelsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewListTunnelsDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewListTunnelsOK creates a ListTunnelsOK with default headers values +func NewListTunnelsOK() *ListTunnelsOK { + return &ListTunnelsOK{} +} + +/*ListTunnelsOK handles this case with default header values. + +A successful response. +*/ +type ListTunnelsOK struct { + Payload *ListTunnelsOKBody +} + +func (o *ListTunnelsOK) Error() string { + return fmt.Sprintf("[POST /v1/inventory/Tunnels/List][%d] listTunnelsOk %+v", 200, o.Payload) +} + +func (o *ListTunnelsOK) GetPayload() *ListTunnelsOKBody { + return o.Payload +} + +func (o *ListTunnelsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(ListTunnelsOKBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewListTunnelsDefault creates a ListTunnelsDefault with default headers values +func NewListTunnelsDefault(code int) *ListTunnelsDefault { + return &ListTunnelsDefault{ + _statusCode: code, + } +} + +/*ListTunnelsDefault handles this case with default header values. + +An unexpected error response. +*/ +type ListTunnelsDefault struct { + _statusCode int + + Payload *ListTunnelsDefaultBody +} + +// Code gets the status code for the list tunnels default response +func (o *ListTunnelsDefault) Code() int { + return o._statusCode +} + +func (o *ListTunnelsDefault) Error() string { + return fmt.Sprintf("[POST /v1/inventory/Tunnels/List][%d] ListTunnels default %+v", o._statusCode, o.Payload) +} + +func (o *ListTunnelsDefault) GetPayload() *ListTunnelsDefaultBody { + return o.Payload +} + +func (o *ListTunnelsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(ListTunnelsDefaultBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +/*ListTunnelsDefaultBody list tunnels default body +swagger:model ListTunnelsDefaultBody +*/ +type ListTunnelsDefaultBody struct { + + // error + Error string `json:"error,omitempty"` + + // code + Code int32 `json:"code,omitempty"` + + // message + Message string `json:"message,omitempty"` + + // details + Details []*DetailsItems0 `json:"details"` +} + +// Validate validates this list tunnels default body +func (o *ListTunnelsDefaultBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateDetails(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *ListTunnelsDefaultBody) validateDetails(formats strfmt.Registry) error { + + if swag.IsZero(o.Details) { // not required + return nil + } + + for i := 0; i < len(o.Details); i++ { + if swag.IsZero(o.Details[i]) { // not required + continue + } + + if o.Details[i] != nil { + if err := o.Details[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("ListTunnels default" + "." + "details" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (o *ListTunnelsDefaultBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *ListTunnelsDefaultBody) UnmarshalBinary(b []byte) error { + var res ListTunnelsDefaultBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} + +/*ListTunnelsOKBody list tunnels OK body +swagger:model ListTunnelsOKBody +*/ +type ListTunnelsOKBody struct { + + // tunnel + Tunnel []*TunnelItems0 `json:"tunnel"` +} + +// Validate validates this list tunnels OK body +func (o *ListTunnelsOKBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateTunnel(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *ListTunnelsOKBody) validateTunnel(formats strfmt.Registry) error { + + if swag.IsZero(o.Tunnel) { // not required + return nil + } + + for i := 0; i < len(o.Tunnel); i++ { + if swag.IsZero(o.Tunnel[i]) { // not required + continue + } + + if o.Tunnel[i] != nil { + if err := o.Tunnel[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("listTunnelsOk" + "." + "tunnel" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (o *ListTunnelsOKBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *ListTunnelsOKBody) UnmarshalBinary(b []byte) error { + var res ListTunnelsOKBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} + +/*TunnelItems0 Tunnel represents a single Tunnel configuration. +swagger:model TunnelItems0 +*/ +type TunnelItems0 struct { + + // Agent ID of the listening pmm-agent. + ListenAgentID string `json:"listen_agent_id,omitempty"` + + // Listen port of the listening pmm-agent. + ListenPort int64 `json:"listen_port,omitempty"` + + // Agent ID of the connecting pmm-agent. + ConnectAgentID string `json:"connect_agent_id,omitempty"` + + // Target port of the connecting pmm-agent. + ConnectPort int64 `json:"connect_port,omitempty"` +} + +// Validate validates this tunnel items0 +func (o *TunnelItems0) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *TunnelItems0) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *TunnelItems0) UnmarshalBinary(b []byte) error { + var res TunnelItems0 + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/remove_tunnel_parameters.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/remove_tunnel_parameters.go new file mode 100644 index 00000000..8d400487 --- /dev/null +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/remove_tunnel_parameters.go @@ -0,0 +1,131 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tunnels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewRemoveTunnelParams creates a new RemoveTunnelParams object +// with the default values initialized. +func NewRemoveTunnelParams() *RemoveTunnelParams { + var () + return &RemoveTunnelParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewRemoveTunnelParamsWithTimeout creates a new RemoveTunnelParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewRemoveTunnelParamsWithTimeout(timeout time.Duration) *RemoveTunnelParams { + var () + return &RemoveTunnelParams{ + + timeout: timeout, + } +} + +// NewRemoveTunnelParamsWithContext creates a new RemoveTunnelParams object +// with the default values initialized, and the ability to set a context for a request +func NewRemoveTunnelParamsWithContext(ctx context.Context) *RemoveTunnelParams { + var () + return &RemoveTunnelParams{ + + Context: ctx, + } +} + +// NewRemoveTunnelParamsWithHTTPClient creates a new RemoveTunnelParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewRemoveTunnelParamsWithHTTPClient(client *http.Client) *RemoveTunnelParams { + var () + return &RemoveTunnelParams{ + HTTPClient: client, + } +} + +/*RemoveTunnelParams contains all the parameters to send to the API endpoint +for the remove tunnel operation typically these are written to a http.Request +*/ +type RemoveTunnelParams struct { + + /*Body*/ + Body RemoveTunnelBody + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the remove tunnel params +func (o *RemoveTunnelParams) WithTimeout(timeout time.Duration) *RemoveTunnelParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the remove tunnel params +func (o *RemoveTunnelParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the remove tunnel params +func (o *RemoveTunnelParams) WithContext(ctx context.Context) *RemoveTunnelParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the remove tunnel params +func (o *RemoveTunnelParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the remove tunnel params +func (o *RemoveTunnelParams) WithHTTPClient(client *http.Client) *RemoveTunnelParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the remove tunnel params +func (o *RemoveTunnelParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the remove tunnel params +func (o *RemoveTunnelParams) WithBody(body RemoveTunnelBody) *RemoveTunnelParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the remove tunnel params +func (o *RemoveTunnelParams) SetBody(body RemoveTunnelBody) { + o.Body = body +} + +// WriteToRequest writes these params to a swagger request +func (o *RemoveTunnelParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/remove_tunnel_responses.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/remove_tunnel_responses.go new file mode 100644 index 00000000..e5aa0216 --- /dev/null +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/remove_tunnel_responses.go @@ -0,0 +1,223 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tunnels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// RemoveTunnelReader is a Reader for the RemoveTunnel structure. +type RemoveTunnelReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *RemoveTunnelReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewRemoveTunnelOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewRemoveTunnelDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewRemoveTunnelOK creates a RemoveTunnelOK with default headers values +func NewRemoveTunnelOK() *RemoveTunnelOK { + return &RemoveTunnelOK{} +} + +/*RemoveTunnelOK handles this case with default header values. + +A successful response. +*/ +type RemoveTunnelOK struct { + Payload interface{} +} + +func (o *RemoveTunnelOK) Error() string { + return fmt.Sprintf("[POST /v1/inventory/Tunnels/Remove][%d] removeTunnelOk %+v", 200, o.Payload) +} + +func (o *RemoveTunnelOK) GetPayload() interface{} { + return o.Payload +} + +func (o *RemoveTunnelOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewRemoveTunnelDefault creates a RemoveTunnelDefault with default headers values +func NewRemoveTunnelDefault(code int) *RemoveTunnelDefault { + return &RemoveTunnelDefault{ + _statusCode: code, + } +} + +/*RemoveTunnelDefault handles this case with default header values. + +An unexpected error response. +*/ +type RemoveTunnelDefault struct { + _statusCode int + + Payload *RemoveTunnelDefaultBody +} + +// Code gets the status code for the remove tunnel default response +func (o *RemoveTunnelDefault) Code() int { + return o._statusCode +} + +func (o *RemoveTunnelDefault) Error() string { + return fmt.Sprintf("[POST /v1/inventory/Tunnels/Remove][%d] RemoveTunnel default %+v", o._statusCode, o.Payload) +} + +func (o *RemoveTunnelDefault) GetPayload() *RemoveTunnelDefaultBody { + return o.Payload +} + +func (o *RemoveTunnelDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(RemoveTunnelDefaultBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +/*RemoveTunnelBody remove tunnel body +swagger:model RemoveTunnelBody +*/ +type RemoveTunnelBody struct { + + // tunnel id + TunnelID string `json:"tunnel_id,omitempty"` +} + +// Validate validates this remove tunnel body +func (o *RemoveTunnelBody) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *RemoveTunnelBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *RemoveTunnelBody) UnmarshalBinary(b []byte) error { + var res RemoveTunnelBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} + +/*RemoveTunnelDefaultBody remove tunnel default body +swagger:model RemoveTunnelDefaultBody +*/ +type RemoveTunnelDefaultBody struct { + + // error + Error string `json:"error,omitempty"` + + // code + Code int32 `json:"code,omitempty"` + + // message + Message string `json:"message,omitempty"` + + // details + Details []*DetailsItems0 `json:"details"` +} + +// Validate validates this remove tunnel default body +func (o *RemoveTunnelDefaultBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateDetails(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *RemoveTunnelDefaultBody) validateDetails(formats strfmt.Registry) error { + + if swag.IsZero(o.Details) { // not required + return nil + } + + for i := 0; i < len(o.Details); i++ { + if swag.IsZero(o.Details[i]) { // not required + continue + } + + if o.Details[i] != nil { + if err := o.Details[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("RemoveTunnel default" + "." + "details" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (o *RemoveTunnelDefaultBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *RemoveTunnelDefaultBody) UnmarshalBinary(b []byte) error { + var res RemoveTunnelDefaultBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/tunnels_client.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/tunnels_client.go new file mode 100644 index 00000000..58991482 --- /dev/null +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/tunnels_client.go @@ -0,0 +1,139 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tunnels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" +) + +// New creates a new tunnels API client. +func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService { + return &Client{transport: transport, formats: formats} +} + +/* +Client for tunnels API +*/ +type Client struct { + transport runtime.ClientTransport + formats strfmt.Registry +} + +// ClientService is the interface for Client methods +type ClientService interface { + AddTunnel(params *AddTunnelParams) (*AddTunnelOK, error) + + ListTunnels(params *ListTunnelsParams) (*ListTunnelsOK, error) + + RemoveTunnel(params *RemoveTunnelParams) (*RemoveTunnelOK, error) + + SetTransport(transport runtime.ClientTransport) +} + +/* + AddTunnel adds tunnel adds a tunnel +*/ +func (a *Client) AddTunnel(params *AddTunnelParams) (*AddTunnelOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewAddTunnelParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "AddTunnel", + Method: "POST", + PathPattern: "/v1/inventory/Tunnels/Add", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http", "https"}, + Params: params, + Reader: &AddTunnelReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*AddTunnelOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*AddTunnelDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + +/* + ListTunnels lists tunnels returns a list of all tunnels +*/ +func (a *Client) ListTunnels(params *ListTunnelsParams) (*ListTunnelsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewListTunnelsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "ListTunnels", + Method: "POST", + PathPattern: "/v1/inventory/Tunnels/List", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http", "https"}, + Params: params, + Reader: &ListTunnelsReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*ListTunnelsOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*ListTunnelsDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + +/* + RemoveTunnel removes tunnel removes a tunnel +*/ +func (a *Client) RemoveTunnel(params *RemoveTunnelParams) (*RemoveTunnelOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewRemoveTunnelParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "RemoveTunnel", + Method: "POST", + PathPattern: "/v1/inventory/Tunnels/Remove", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http", "https"}, + Params: params, + Reader: &RemoveTunnelReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*RemoveTunnelOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*RemoveTunnelDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + +// SetTransport changes the transport on the client +func (a *Client) SetTransport(transport runtime.ClientTransport) { + a.transport = transport +} From 790aa3f6db04dd24a49aaf9115f3e21c096fef52 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 16 Feb 2021 12:26:33 +0300 Subject: [PATCH 2/5] WIP --- Gopkg.lock | 4 +- commands/inventory/list_tunnels.go | 88 +++++++++++++++++++ main.go | 2 + .../client/tunnels/list_tunnels_parameters.go | 12 ++- .../client/tunnels/list_tunnels_responses.go | 32 +++++++ 5 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 commands/inventory/list_tunnels.go diff --git a/Gopkg.lock b/Gopkg.lock index a26413f4..941517e7 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -241,7 +241,7 @@ [[projects]] branch = "PMM-5194-tunnels" - digest = "1:7f25af86aa84a21f7be1a18c3e05f5b1ef819ae8beacf4883b848f977e492fb1" + digest = "1:1a3ba45c64fbce713016027a2ea66b0e7b1618281628747aa29e027190e80310" name = "github.com/percona/pmm" packages = [ "api/agentlocalpb/json/client", @@ -272,7 +272,7 @@ "version", ] pruneopts = "NUT" - revision = "94cf2834063285cf7f27a63b448e75180ed3c289" + revision = "2d1598848a2de465e700e1d1cda39d4999402b76" [[projects]] digest = "1:14715f705ff5dfe0ffd6571d7d201dd8e921030f8070321a79380d8ca4ec1a24" diff --git a/commands/inventory/list_tunnels.go b/commands/inventory/list_tunnels.go new file mode 100644 index 00000000..acdf3b76 --- /dev/null +++ b/commands/inventory/list_tunnels.go @@ -0,0 +1,88 @@ +// pmm-admin +// Copyright 2019 Percona LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package inventory + +import ( + "github.com/percona/pmm/api/inventorypb/json/client" + "github.com/percona/pmm/api/inventorypb/json/client/tunnels" + + "github.com/percona/pmm-admin/commands" +) + +var listTunnelsResultT = commands.ParseTemplate(` +Agents list. + +{{ printf "%-27s" "Agent type" }} {{ printf "%-15s" "Status" }} {{ printf "%-47s" "Agent ID" }} {{ printf "%-47s" "PMM-Agent ID" }} {{ printf "%-47s" "Service ID" }} +{{ range .Agents }} +{{- printf "%-27s" .HumanReadableAgentType }} {{ printf "%-15s" .NiceAgentStatus }} {{ .AgentID }} {{ .PMMAgentID }} {{ .ServiceID }} +{{ end }} +`) + +type listResultTunnel struct { + ListenAgentID string `json:"listen_agent_id"` + ListenPort uint16 `json:"listen_port"` + ConnectAgentID string `json:"connect_agent_id"` + ConnectPort uint16 `json:"connect_port"` +} + +type listTunnelsResult struct { + Tunnels []listResultTunnel `json:"tunnels"` +} + +func (res *listTunnelsResult) Result() {} + +func (res *listTunnelsResult) String() string { + return commands.RenderTemplate(listTunnelsResultT, res) +} + +type listTunnelsCommand struct { + filters tunnels.ListTunnelsBody +} + +func (cmd *listTunnelsCommand) Run() (commands.Result, error) { + params := &tunnels.ListTunnelsParams{ + Body: cmd.filters, + Context: commands.Ctx, + } + tunnelsRes, err := client.Default.Tunnels.ListTunnels(params) + if err != nil { + return nil, err + } + + tunnelsList := make([]listResultTunnel, len(tunnelsRes.Payload.Tunnel)) + for i, t := range tunnelsRes.Payload.Tunnel { + tunnelsList[i] = listResultTunnel{ + ListenAgentID: t.ListenAgentID, + ListenPort: uint16(t.ListenPort), + ConnectAgentID: t.ConnectAgentID, + ConnectPort: uint16(t.ConnectPort), + } + } + + return &listTunnelsResult{ + Tunnels: tunnelsList, + }, nil +} + +// register command +var ( + ListTunnels = new(listTunnelsCommand) + ListTunnelsC = inventoryListC.Command("tunnels", "Show tunnels in inventory").Hide(hide) +) + +func init() { + ListTunnelsC.Flag("pmm-agent-id", "Filter by pmm-agent identifier").StringVar(&ListTunnels.filters.AgentID) +} diff --git a/main.go b/main.go index a8d4ac8b..da1b12e3 100644 --- a/main.go +++ b/main.go @@ -122,6 +122,8 @@ func main() { inventory.RemoveAgentC.FullCommand(): inventory.RemoveAgent, + inventory.ListTunnelsC.FullCommand(): inventory.ListTunnels, + commands.ListC.FullCommand(): commands.List, commands.AnnotationC.FullCommand(): commands.Annotation, commands.StatusC.FullCommand(): commands.Status, diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_parameters.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_parameters.go index f338ec7f..3145ec02 100644 --- a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_parameters.go +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_parameters.go @@ -61,7 +61,7 @@ for the list tunnels operation typically these are written to a http.Request type ListTunnelsParams struct { /*Body*/ - Body interface{} + Body ListTunnelsBody timeout time.Duration Context context.Context @@ -102,13 +102,13 @@ func (o *ListTunnelsParams) SetHTTPClient(client *http.Client) { } // WithBody adds the body to the list tunnels params -func (o *ListTunnelsParams) WithBody(body interface{}) *ListTunnelsParams { +func (o *ListTunnelsParams) WithBody(body ListTunnelsBody) *ListTunnelsParams { o.SetBody(body) return o } // SetBody adds the body to the list tunnels params -func (o *ListTunnelsParams) SetBody(body interface{}) { +func (o *ListTunnelsParams) SetBody(body ListTunnelsBody) { o.Body = body } @@ -120,10 +120,8 @@ func (o *ListTunnelsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.R } var res []error - if o.Body != nil { - if err := r.SetBodyParam(o.Body); err != nil { - return err - } + if err := r.SetBodyParam(o.Body); err != nil { + return err } if len(res) > 0 { diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go index ff7fb9c9..689d231a 100644 --- a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go @@ -117,6 +117,38 @@ func (o *ListTunnelsDefault) readResponse(response runtime.ClientResponse, consu return nil } +/*ListTunnelsBody list tunnels body +swagger:model ListTunnelsBody +*/ +type ListTunnelsBody struct { + + // Return only Tunnels where one (or both) pmm-agent has this ID. + AgentID string `json:"agent_id,omitempty"` +} + +// Validate validates this list tunnels body +func (o *ListTunnelsBody) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *ListTunnelsBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *ListTunnelsBody) UnmarshalBinary(b []byte) error { + var res ListTunnelsBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} + /*ListTunnelsDefaultBody list tunnels default body swagger:model ListTunnelsDefaultBody */ From 1858a4eb17aab90d1ef8924eb3c1e5c98ae176b2 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 16 Feb 2021 19:08:24 +0300 Subject: [PATCH 3/5] WIP --- Gopkg.lock | 5 +++-- commands/inventory/list_tunnels.go | 21 ++++++++++++++++++- .../client/tunnels/list_tunnels_responses.go | 3 +++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 941517e7..a673581b 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -241,7 +241,7 @@ [[projects]] branch = "PMM-5194-tunnels" - digest = "1:1a3ba45c64fbce713016027a2ea66b0e7b1618281628747aa29e027190e80310" + digest = "1:93a415f64d72a40206397a167c36f1d50f903b17e2df61eb0b3603f67618186a" name = "github.com/percona/pmm" packages = [ "api/agentlocalpb/json/client", @@ -272,7 +272,7 @@ "version", ] pruneopts = "NUT" - revision = "2d1598848a2de465e700e1d1cda39d4999402b76" + revision = "5066f213ed715ea82bf2a5f1757c0ac0c2a9a94e" [[projects]] digest = "1:14715f705ff5dfe0ffd6571d7d201dd8e921030f8070321a79380d8ca4ec1a24" @@ -427,6 +427,7 @@ "github.com/percona/pmm/api/inventorypb/json/client/agents", "github.com/percona/pmm/api/inventorypb/json/client/nodes", "github.com/percona/pmm/api/inventorypb/json/client/services", + "github.com/percona/pmm/api/inventorypb/json/client/tunnels", "github.com/percona/pmm/api/inventorypb/types", "github.com/percona/pmm/api/managementpb/json/client", "github.com/percona/pmm/api/managementpb/json/client/annotation", diff --git a/commands/inventory/list_tunnels.go b/commands/inventory/list_tunnels.go index acdf3b76..f60da703 100644 --- a/commands/inventory/list_tunnels.go +++ b/commands/inventory/list_tunnels.go @@ -16,6 +16,10 @@ package inventory import ( + "bytes" + "fmt" + "text/tabwriter" + "github.com/percona/pmm/api/inventorypb/json/client" "github.com/percona/pmm/api/inventorypb/json/client/tunnels" @@ -32,6 +36,7 @@ Agents list. `) type listResultTunnel struct { + TunnelID string `json:"tunnel_id"` ListenAgentID string `json:"listen_agent_id"` ListenPort uint16 `json:"listen_port"` ConnectAgentID string `json:"connect_agent_id"` @@ -45,7 +50,20 @@ type listTunnelsResult struct { func (res *listTunnelsResult) Result() {} func (res *listTunnelsResult) String() string { - return commands.RenderTemplate(listTunnelsResultT, res) + if len(res.Tunnels) == 0 { + return "No tunnels." + } + + var buf bytes.Buffer + buf.WriteString("Tunnels list.\n") + + w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', 0) + fmt.Fprintf(w, "ID\tInfo\n") + for _, t := range res.Tunnels { + fmt.Fprintf(w, "%s\tlala\n", t.TunnelID) + } + w.Flush() + return buf.String() } type listTunnelsCommand struct { @@ -65,6 +83,7 @@ func (cmd *listTunnelsCommand) Run() (commands.Result, error) { tunnelsList := make([]listResultTunnel, len(tunnelsRes.Payload.Tunnel)) for i, t := range tunnelsRes.Payload.Tunnel { tunnelsList[i] = listResultTunnel{ + TunnelID: t.TunnelID, ListenAgentID: t.ListenAgentID, ListenPort: uint16(t.ListenPort), ConnectAgentID: t.ConnectAgentID, diff --git a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go index 689d231a..2c45f614 100644 --- a/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go +++ b/vendor/github.com/percona/pmm/api/inventorypb/json/client/tunnels/list_tunnels_responses.go @@ -295,6 +295,9 @@ swagger:model TunnelItems0 */ type TunnelItems0 struct { + // Tunnel ID. + TunnelID string `json:"tunnel_id,omitempty"` + // Agent ID of the listening pmm-agent. ListenAgentID string `json:"listen_agent_id,omitempty"` From 9b52351f906deec84673a11f5802bde2b4129f9f Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 16 Feb 2021 19:57:14 +0300 Subject: [PATCH 4/5] WIP --- commands/inventory/list_tunnels.go | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/commands/inventory/list_tunnels.go b/commands/inventory/list_tunnels.go index f60da703..e56c3712 100644 --- a/commands/inventory/list_tunnels.go +++ b/commands/inventory/list_tunnels.go @@ -18,6 +18,8 @@ package inventory import ( "bytes" "fmt" + "strconv" + "strings" "text/tabwriter" "github.com/percona/pmm/api/inventorypb/json/client" @@ -26,15 +28,6 @@ import ( "github.com/percona/pmm-admin/commands" ) -var listTunnelsResultT = commands.ParseTemplate(` -Agents list. - -{{ printf "%-27s" "Agent type" }} {{ printf "%-15s" "Status" }} {{ printf "%-47s" "Agent ID" }} {{ printf "%-47s" "PMM-Agent ID" }} {{ printf "%-47s" "Service ID" }} -{{ range .Agents }} -{{- printf "%-27s" .HumanReadableAgentType }} {{ printf "%-15s" .NiceAgentStatus }} {{ .AgentID }} {{ .PMMAgentID }} {{ .ServiceID }} -{{ end }} -`) - type listResultTunnel struct { TunnelID string `json:"tunnel_id"` ListenAgentID string `json:"listen_agent_id"` @@ -55,12 +48,24 @@ func (res *listTunnelsResult) String() string { } var buf bytes.Buffer - buf.WriteString("Tunnels list.\n") - - w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', 0) - fmt.Fprintf(w, "ID\tInfo\n") + w := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0) + header := strings.Join([]string{ + "ID", + "Listen Agent ID", + "Listen port", + "Connect Agent ID", + "Connect port", + }, "\t") + fmt.Fprintln(w, header) for _, t := range res.Tunnels { - fmt.Fprintf(w, "%s\tlala\n", t.TunnelID) + line := strings.Join([]string{ + t.TunnelID, + t.ListenAgentID, + strconv.Itoa(int(t.ListenPort)), + t.ConnectAgentID, + strconv.Itoa(int(t.ConnectPort)), + }, "\t") + fmt.Fprintln(w, line) } w.Flush() return buf.String() From 53f6551ac2acdcb72ad7a5dd92569b1f58e454b5 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Thu, 18 Feb 2021 00:10:51 +0300 Subject: [PATCH 5/5] WIP --- .travis.yml | 10 +++-- Gopkg.lock | 4 +- agentlocal/agentlocal.go | 38 +++++++++++++++---- commands/inventory/list_tunnels.go | 3 +- commands/status.go | 32 +++++++++++++++- .../client/agent_local/status_responses.go | 2 +- 6 files changed, 72 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index e81072a9..5c320b39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,9 @@ services: go: - 1.15.x - - 1.14.x - - tip + - 1.16.x + # TODO enable when 1.15.x is removed + # - tip matrix: fast_finish: true @@ -16,10 +17,11 @@ matrix: go_import_path: github.com/percona/pmm-admin -# skip non-trunk PMM-XXXX branch builds, but still build pull requests +# skip non-trunk PMM-XXXX/SAAS-XXXX branch builds, but still build pull requests branches: except: - - /^PMM\-\d{4}/ + - /^PMM\-\d{3,5}/ + - /^SAAS\-\d{2,5}/ cache: directories: diff --git a/Gopkg.lock b/Gopkg.lock index a673581b..a610f059 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -241,7 +241,7 @@ [[projects]] branch = "PMM-5194-tunnels" - digest = "1:93a415f64d72a40206397a167c36f1d50f903b17e2df61eb0b3603f67618186a" + digest = "1:bee170dc6d3de5a79b2b0aafb1536d71b9d27d60b13149f76de7fa88916c44f7" name = "github.com/percona/pmm" packages = [ "api/agentlocalpb/json/client", @@ -272,7 +272,7 @@ "version", ] pruneopts = "NUT" - revision = "5066f213ed715ea82bf2a5f1757c0ac0c2a9a94e" + revision = "1eec7892ea9512975689f358a1a392ee05e6cb45" [[projects]] digest = "1:14715f705ff5dfe0ffd6571d7d201dd8e921030f8070321a79380d8ca4ec1a24" diff --git a/agentlocal/agentlocal.go b/agentlocal/agentlocal.go index 7d89a318..09d843e4 100644 --- a/agentlocal/agentlocal.go +++ b/agentlocal/agentlocal.go @@ -69,7 +69,8 @@ type Status struct { ServerVersion string `json:"server_version"` AgentVersion string `json:"agent_version"` - Agents []AgentStatus `json:"agents"` + Agents []AgentStatus `json:"agents"` + Tunnels []TunnelStatus `json:"tunnels"` Connected bool `json:"connected"` ServerClockDrift time.Duration `json:"server_clock_drift,omitempty"` @@ -77,9 +78,17 @@ type Status struct { } type AgentStatus struct { - AgentID string `json:"agent_id"` - AgentType string `json:"agent_type"` - Status string `json:"status"` + AgentID string `json:"agent_id"` + AgentType string `json:"agent_type"` + Status string `json:"status"` + ListenPort uint16 `json:"listen_port"` +} + +type TunnelStatus struct { + TunnelID string `json:"tunnel_id"` + ListenPort uint16 `json:"listen_port"` + ConnectPort uint16 `json:"connect_port"` + CurrentConnections uint `json:"current_connections"` } // GetRawStatus returns raw local pmm-agent status. No special cases. @@ -123,11 +132,23 @@ func GetStatus(requestNetworkInfo NetworkInfo) (*Status, error) { agents := make([]AgentStatus, len(p.AgentsInfo)) for i, a := range p.AgentsInfo { agents[i] = AgentStatus{ - AgentID: a.AgentID, - AgentType: pointer.GetString(a.AgentType), - Status: pointer.GetString(a.Status), + AgentID: a.AgentID, + AgentType: pointer.GetString(a.AgentType), + Status: pointer.GetString(a.Status), + ListenPort: uint16(a.ListenPort), + } + } + + tunnels := make([]TunnelStatus, len(p.TunnelsInfo)) + for i, t := range p.TunnelsInfo { + tunnels[i] = TunnelStatus{ + TunnelID: t.TunnelID, + ListenPort: uint16(t.ListenPort), + ConnectPort: uint16(t.ConnectPort), + CurrentConnections: uint(t.CurrentConnections), } } + var clockDrift time.Duration var latency time.Duration if bool(requestNetworkInfo) && p.ServerInfo.Connected { @@ -155,7 +176,8 @@ func GetStatus(requestNetworkInfo NetworkInfo) (*Status, error) { ServerVersion: p.ServerInfo.Version, AgentVersion: agentVersion, - Agents: agents, + Agents: agents, + Tunnels: tunnels, Connected: p.ServerInfo.Connected, ServerClockDrift: clockDrift, diff --git a/commands/inventory/list_tunnels.go b/commands/inventory/list_tunnels.go index e56c3712..6aa869aa 100644 --- a/commands/inventory/list_tunnels.go +++ b/commands/inventory/list_tunnels.go @@ -67,7 +67,8 @@ func (res *listTunnelsResult) String() string { }, "\t") fmt.Fprintln(w, line) } - w.Flush() + _ = w.Flush() + return buf.String() } diff --git a/commands/status.go b/commands/status.go index 7e88f329..8a0a11bb 100644 --- a/commands/status.go +++ b/commands/status.go @@ -16,9 +16,13 @@ package commands import ( + "bytes" "context" + "fmt" "net/url" + "strconv" "strings" + "text/tabwriter" "time" "github.com/percona/pmm/api/inventorypb/types" @@ -64,7 +68,33 @@ func (res *statusResult) NiceAgentStatus(status string) string { func (res *statusResult) Result() {} func (res *statusResult) String() string { - return RenderTemplate(statusResultT, res) + s := RenderTemplate(statusResultT, res) + + if len(res.PMMAgentStatus.Tunnels) == 0 { + return s + "\n" + "No tunnels." + } + + var buf bytes.Buffer + w := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0) + header := strings.Join([]string{ + "ID", + "Listen port", + "Connect port", + "Current connections", + }, "\t") + fmt.Fprintln(w, header) + for _, t := range res.PMMAgentStatus.Tunnels { + line := strings.Join([]string{ + t.TunnelID, + strconv.Itoa(int(t.ListenPort)), + strconv.Itoa(int(t.ConnectPort)), + strconv.Itoa(int(t.CurrentConnections)), + }, "\t") + fmt.Fprintln(w, line) + } + _ = w.Flush() + + return s + "\n" + buf.String() } func newStatusResult(status *agentlocal.Status) *statusResult { diff --git a/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status_responses.go b/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status_responses.go index 35e018d8..14e8dcb9 100644 --- a/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status_responses.go +++ b/vendor/github.com/percona/pmm/api/agentlocalpb/json/client/agent_local/status_responses.go @@ -623,7 +623,7 @@ type TunnelsInfoItems0 struct { ConnectPort int64 `json:"connect_port,omitempty"` // The current number of established connections. - CurrentConnection int64 `json:"current_connection,omitempty"` + CurrentConnections int64 `json:"current_connections,omitempty"` } // Validate validates this tunnels info items0