diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b60918..7154ef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ +## v6.1.0 +* Added support for Cloud Endpoints (currently in private beta). + ## v6.0.0 ### Breaking Changes * Renamed the Policy Module to the Traffic Policy Module on HTTP Edge Routes, TCP Edges, and TLS Edges, which allows you to configure rules that can be used to influence and control traffic to and from your upstream service. The Traffic Policy itself is now specified as either a JSON or YAML string. diff --git a/datatypes.go b/datatypes.go index 0a5a0eb..0ed4ea4 100644 --- a/datatypes.go +++ b/datatypes.go @@ -3999,14 +3999,19 @@ type Endpoint struct { // URL of the hostport served by this endpoint PublicURL string `json:"public_url,omitempty"` // protocol served by this endpoint. one of http, https, tcp, or tls - Proto string `json:"proto,omitempty"` - // hostport served by this endpoint (hostname:port) + Proto string `json:"proto,omitempty"` + Scheme string `json:"scheme,omitempty"` + // hostport served by this endpoint (hostname:port) -> soon to be deprecated Hostport string `json:"hostport,omitempty"` + Host string `json:"host,omitempty"` + Port int64 `json:"port,omitempty"` // whether the endpoint is ephemeral (served directly by an agent-initiated tunnel) - // or edge (served by an edge) + // or edge (served by an edge) or cloud (represents a cloud endpoint) Type string `json:"type,omitempty"` // user-supplied metadata of the associated tunnel or edge object Metadata string `json:"metadata,omitempty"` + // user-supplied description of the associated tunnel + Description string `json:"description,omitempty"` // the domain reserved for this endpoint Domain *Ref `json:"domain,omitempty"` // the address reserved for this endpoint @@ -4015,6 +4020,26 @@ type Endpoint struct { Tunnel *Ref `json:"tunnel,omitempty"` // the edge serving requests to this endpoint, if this is an edge endpoint Edge *Ref `json:"edge,omitempty"` + // the local address the tunnel forwards to + UpstreamURL string `json:"upstream_url,omitempty"` + // the protocol the agent uses to forward with + UpstreamProto string `json:"upstream_proto,omitempty"` + // the url of the endpoint + URL string `json:"url,omitempty"` + // The ID of the owner (bot or user) that owns this endpoint + Principal *Ref `json:"principal,omitempty"` + // TODO: deprecate me! + PrincipalID *Ref `json:"principal_id,omitempty"` + // The traffic policy attached to this endpoint + TrafficPolicy string `json:"traffic_policy,omitempty"` + // the bindings associated with this endpoint + Bindings []string `json:"bindings,omitempty"` + // The tunnel session of the agent for this endpoint + TunnelSession *Ref `json:"tunnel_session,omitempty"` + // URI of the clep API resource + URI string `json:"uri,omitempty"` + // user supplied name for the endpoint + Name string `json:"name,omitempty"` } func (x *Endpoint) String() string { @@ -4032,13 +4057,27 @@ func (x *Endpoint) GoString() string { fmt.Fprintf(tw, "\tUpdatedAt\t%v\n", x.UpdatedAt) fmt.Fprintf(tw, "\tPublicURL\t%v\n", x.PublicURL) fmt.Fprintf(tw, "\tProto\t%v\n", x.Proto) + fmt.Fprintf(tw, "\tScheme\t%v\n", x.Scheme) fmt.Fprintf(tw, "\tHostport\t%v\n", x.Hostport) + fmt.Fprintf(tw, "\tHost\t%v\n", x.Host) + fmt.Fprintf(tw, "\tPort\t%v\n", x.Port) fmt.Fprintf(tw, "\tType\t%v\n", x.Type) fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) fmt.Fprintf(tw, "\tDomain\t%v\n", x.Domain) fmt.Fprintf(tw, "\tTCPAddr\t%v\n", x.TCPAddr) fmt.Fprintf(tw, "\tTunnel\t%v\n", x.Tunnel) fmt.Fprintf(tw, "\tEdge\t%v\n", x.Edge) + fmt.Fprintf(tw, "\tUpstreamURL\t%v\n", x.UpstreamURL) + fmt.Fprintf(tw, "\tUpstreamProto\t%v\n", x.UpstreamProto) + fmt.Fprintf(tw, "\tURL\t%v\n", x.URL) + fmt.Fprintf(tw, "\tPrincipal\t%v\n", x.Principal) + fmt.Fprintf(tw, "\tPrincipalID\t%v\n", x.PrincipalID) + fmt.Fprintf(tw, "\tTrafficPolicy\t%v\n", x.TrafficPolicy) + fmt.Fprintf(tw, "\tBindings\t%v\n", x.Bindings) + fmt.Fprintf(tw, "\tTunnelSession\t%v\n", x.TunnelSession) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tName\t%v\n", x.Name) tw.Flush() fmt.Fprintf(&b, "}\n") return b.String() @@ -4069,6 +4108,76 @@ func (x *EndpointList) GoString() string { return b.String() } +type EndpointCreate struct { + // the url of the endpoint + URL string `json:"url,omitempty"` + // whether the endpoint is ephemeral (served directly by an agent-initiated tunnel) + // or edge (served by an edge) or cloud (represents a cloud endpoint) + Type string `json:"type,omitempty"` + // The traffic policy attached to this endpoint + TrafficPolicy string `json:"traffic_policy,omitempty"` + // user-supplied description of the associated tunnel + Description *string `json:"description,omitempty"` + // user-supplied metadata of the associated tunnel or edge object + Metadata *string `json:"metadata,omitempty"` + // the bindings associated with this endpoint + Bindings []string `json:"bindings,omitempty"` +} + +func (x *EndpointCreate) String() string { + return x.GoString() +} + +func (x *EndpointCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tURL\t%v\n", x.URL) + fmt.Fprintf(tw, "\tType\t%v\n", x.Type) + fmt.Fprintf(tw, "\tTrafficPolicy\t%v\n", x.TrafficPolicy) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tBindings\t%v\n", x.Bindings) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + +type EndpointUpdate struct { + // unique endpoint resource identifier + ID string `json:"id,omitempty"` + // the url of the endpoint + Url *string `json:"url,omitempty"` + // The traffic policy attached to this endpoint + TrafficPolicy *string `json:"traffic_policy,omitempty"` + // user-supplied description of the associated tunnel + Description *string `json:"description,omitempty"` + // user-supplied metadata of the associated tunnel or edge object + Metadata *string `json:"metadata,omitempty"` + // the bindings associated with this endpoint + Bindings []string `json:"bindings,omitempty"` +} + +func (x *EndpointUpdate) String() string { + return fmt.Sprintf("EndpointUpdate{ID: %v}", x.ID) + +} + +func (x *EndpointUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tUrl\t%v\n", x.Url) + fmt.Fprintf(tw, "\tTrafficPolicy\t%v\n", x.TrafficPolicy) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tBindings\t%v\n", x.Bindings) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventDestinationCreate struct { // Arbitrary user-defined machine-readable data of this Event Destination. // Optional, max 4096 bytes. @@ -4344,7 +4453,7 @@ type EventTargetAzureLogsIngestion struct { LogsIngestionURI string `json:"logs_ingestion_uri,omitempty"` // Data collection rule immutable ID DataCollectionRuleId string `json:"data_collection_rule_id,omitempty"` - // Data collection stream name to use as destination, located instide the DCR + // Data collection stream name to use as destination, located inside the DCR DataCollectionStreamName string `json:"data_collection_stream_name,omitempty"` } @@ -5385,8 +5494,8 @@ type ReservedDomainCertPolicy struct { // certificate authority to request certificates from. The only supported value is // letsencrypt. Authority string `json:"authority,omitempty"` - // type of private key to use when requesting certificates. Defaults to rsa, can be - // either rsa or ecdsa. + // type of private key to use when requesting certificates. Defaults to ecdsa, can + // be either rsa or ecdsa. PrivateKeyType string `json:"private_key_type,omitempty"` } diff --git a/endpoints/client.go b/endpoints/client.go index dc6945e..a374190 100644 --- a/endpoints/client.go +++ b/endpoints/client.go @@ -24,6 +24,31 @@ func NewClient(cfg *ngrok.ClientConfig) *Client { return &Client{apiClient: api.NewClient(cfg)} } +// Create an endpoint, currently available only for cloud endpoints +// +// https://ngrok.com/docs/api#api-endpoints-create +func (c *Client) Create(ctx context.Context, arg *ngrok.EndpointCreate) (*ngrok.Endpoint, error) { + if arg == nil { + arg = new(ngrok.EndpointCreate) + } + var res ngrok.Endpoint + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/endpoints")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg + + if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + // List all active endpoints on the account // // https://ngrok.com/docs/api#api-endpoints-list @@ -148,3 +173,52 @@ func (c *Client) Get(ctx context.Context, id string) (*ngrok.Endpoint, error) { } return &res, nil } + +// Update an Endpoint by ID, currently available only for cloud endpoints +// +// https://ngrok.com/docs/api#api-endpoints-update +func (c *Client) Update(ctx context.Context, arg *ngrok.EndpointUpdate) (*ngrok.Endpoint, error) { + if arg == nil { + arg = new(ngrok.EndpointUpdate) + } + var res ngrok.Endpoint + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/endpoints/{{ .ID }}")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg + + if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// Delete an Endpoint by ID, currently available only for cloud endpoints +// +// https://ngrok.com/docs/api#api-endpoints-delete +func (c *Client) Delete(ctx context.Context, id string) error { + arg := &ngrok.Item{ID: id} + + var path bytes.Buffer + if err := template.Must(template.New("delete_path").Parse("/endpoints/{{ .ID }}")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + + if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil { + return err + } + return nil +}