From 7d8bf2fec54c9b88a5d51b1531dbfcd1e3dff731 Mon Sep 17 00:00:00 2001 From: ngrok-release-bot Date: Fri, 14 May 2021 22:17:22 +0000 Subject: [PATCH] cut new release --- abuse_reports/client.go | 70 + api_keys/client.go | 206 ++ certificate_authorities/client.go | 205 ++ client.go | 125 + config.go | 65 + credentials/client.go | 208 ++ datatypes.go | 2277 ++++++++++++++++++ debug.go | 153 ++ endpoint_backend_module/client.go | 92 + endpoint_basic_auth_module/client.go | 92 + endpoint_circuit_breaker_module/client.go | 90 + endpoint_compression_module/client.go | 90 + endpoint_configurations/client.go | 214 ++ endpoint_ip_policy_module/client.go | 90 + endpoint_logging_module/client.go | 90 + endpoint_mutual_tls_module/client.go | 90 + endpoint_o_auth_module/client.go | 90 + endpoint_oidc_module/client.go | 90 + endpoint_request_headers_module/client.go | 90 + endpoint_response_headers_module/client.go | 90 + endpoint_saml_module/client.go | 90 + endpoint_tls_termination_module/client.go | 90 + endpoint_webhook_validation_module/client.go | 90 + error.go | 41 + event_destinations/client.go | 235 ++ event_sources/client.go | 141 ++ event_streams/client.go | 206 ++ event_subscriptions/client.go | 205 ++ go.mod | 9 + ip_policies/client.go | 208 ++ ip_policy_rules/client.go | 205 ++ ip_restrictions/client.go | 205 ++ ip_whitelist/client.go | 206 ++ main_test.go | 64 + priority_backends/client.go | 205 ++ reserved_addrs/client.go | 229 ++ reserved_domains/client.go | 301 +++ root/client.go | 41 + ssh_certificate_authorities/client.go | 205 ++ ssh_credentials/client.go | 206 ++ ssh_host_certificates/client.go | 205 ++ ssh_user_certificates/client.go | 205 ++ static_backends/client.go | 205 ++ tls_certificates/client.go | 205 ++ tunnel_group_backends/client.go | 205 ++ tunnel_sessions/client.go | 224 ++ tunnels/client.go | 109 + type_helpers.go | 15 + weighted_backends/client.go | 205 ++ 49 files changed, 9277 insertions(+) create mode 100644 abuse_reports/client.go create mode 100644 api_keys/client.go create mode 100644 certificate_authorities/client.go create mode 100644 client.go create mode 100644 config.go create mode 100644 credentials/client.go create mode 100644 datatypes.go create mode 100644 debug.go create mode 100644 endpoint_backend_module/client.go create mode 100644 endpoint_basic_auth_module/client.go create mode 100644 endpoint_circuit_breaker_module/client.go create mode 100644 endpoint_compression_module/client.go create mode 100644 endpoint_configurations/client.go create mode 100644 endpoint_ip_policy_module/client.go create mode 100644 endpoint_logging_module/client.go create mode 100644 endpoint_mutual_tls_module/client.go create mode 100644 endpoint_o_auth_module/client.go create mode 100644 endpoint_oidc_module/client.go create mode 100644 endpoint_request_headers_module/client.go create mode 100644 endpoint_response_headers_module/client.go create mode 100644 endpoint_saml_module/client.go create mode 100644 endpoint_tls_termination_module/client.go create mode 100644 endpoint_webhook_validation_module/client.go create mode 100644 error.go create mode 100644 event_destinations/client.go create mode 100644 event_sources/client.go create mode 100644 event_streams/client.go create mode 100644 event_subscriptions/client.go create mode 100644 go.mod create mode 100644 ip_policies/client.go create mode 100644 ip_policy_rules/client.go create mode 100644 ip_restrictions/client.go create mode 100644 ip_whitelist/client.go create mode 100644 main_test.go create mode 100644 priority_backends/client.go create mode 100644 reserved_addrs/client.go create mode 100644 reserved_domains/client.go create mode 100644 root/client.go create mode 100644 ssh_certificate_authorities/client.go create mode 100644 ssh_credentials/client.go create mode 100644 ssh_host_certificates/client.go create mode 100644 ssh_user_certificates/client.go create mode 100644 static_backends/client.go create mode 100644 tls_certificates/client.go create mode 100644 tunnel_group_backends/client.go create mode 100644 tunnel_sessions/client.go create mode 100644 tunnels/client.go create mode 100644 type_helpers.go create mode 100644 weighted_backends/client.go diff --git a/abuse_reports/client.go b/abuse_reports/client.go new file mode 100644 index 0000000..88bcd9e --- /dev/null +++ b/abuse_reports/client.go @@ -0,0 +1,70 @@ +// Code generated by apic. DO NOT EDIT. + +package abuse_reports + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Creates a new abuse report which will be reviewed by our system and abuse +// response team. This API is only available to authorized accounts. Contact +// abuse@ngrok.com to request access +func (c *Client) Create( + ctx context.Context, + arg *ngrok.AbuseReportCreate, +) (*ngrok.AbuseReport, error) { + var res ngrok.AbuseReport + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/abuse_reports")).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 +} + +// Get the detailed status of abuse report by ID. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.AbuseReport, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.AbuseReport + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/abuse_reports/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} diff --git a/api_keys/client.go b/api_keys/client.go new file mode 100644 index 0000000..f79c34a --- /dev/null +++ b/api_keys/client.go @@ -0,0 +1,206 @@ +// Code generated by apic. DO NOT EDIT. + +package api_keys + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new API key. The generated API key can be used to authenticate to the +// ngrok API. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.APIKeyCreate, +) (*ngrok.APIKey, error) { + var res ngrok.APIKey + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/api_keys")).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 +} + +// Delete an API key by ID +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("/api_keys/{{ .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 +} + +// Get the details of an API key by ID. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.APIKey, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.APIKey + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/api_keys/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all API keys owned by this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.APIKeyList, error) { + var res ngrok.APIKeyList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/api_keys")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.APIKey + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.Keys + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.APIKey { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an API key by ID. +func (c *Client) Update( + ctx context.Context, + arg *ngrok.APIKeyUpdate, +) (*ngrok.APIKey, error) { + var res ngrok.APIKey + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/api_keys/{{ .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 +} diff --git a/certificate_authorities/client.go b/certificate_authorities/client.go new file mode 100644 index 0000000..16ad424 --- /dev/null +++ b/certificate_authorities/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package certificate_authorities + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Upload a new Certificate Authority +func (c *Client) Create( + ctx context.Context, + arg *ngrok.CertificateAuthorityCreate, +) (*ngrok.CertificateAuthority, error) { + var res ngrok.CertificateAuthority + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/certificate_authorities")).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 +} + +// Delete a Certificate Authority +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("/certificate_authorities/{{ .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 +} + +// Get detailed information about a certficate authority +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.CertificateAuthority, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.CertificateAuthority + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/certificate_authorities/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all Certificate Authority on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.CertificateAuthorityList, error) { + var res ngrok.CertificateAuthorityList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/certificate_authorities")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.CertificateAuthority + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.CertificateAuthorities + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.CertificateAuthority { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of a Certificate Authority by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.CertificateAuthorityUpdate, +) (*ngrok.CertificateAuthority, error) { + var res ngrok.CertificateAuthority + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/certificate_authorities/{{ .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 +} diff --git a/client.go b/client.go new file mode 100644 index 0000000..08d54f4 --- /dev/null +++ b/client.go @@ -0,0 +1,125 @@ +// Code generated by apic. DO NOT EDIT. + +package ngrok + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "net/http" + "net/url" +) + +const ( + apiVersion = "2" +) + +type Client struct { + cfg *clientConfig +} + +func NewClient(opts ...ClientOption) (*Client, error) { + var cfg clientConfig + if err := cfg.parseOptions(opts); err != nil { + return nil, err + } + return &Client{cfg: &cfg}, nil +} + +func (c *Client) Do(ctx context.Context, method string, reqURL *url.URL, reqBody interface{}, respBody interface{}) error { + req, err := c.buildRequest(ctx, method, reqURL, reqBody) + if err != nil { + return err + } + resp, err := c.cfg.httpClient.Do(req) + if err != nil { + return err + } + if err = c.readResponse(resp, respBody); err != nil { + return err + } + return nil +} + +func (c *Client) buildRequest(ctx context.Context, method string, reqURL *url.URL, reqBody interface{}) (*http.Request, error) { + body, err := c.buildRequestBody(reqBody) + if err != nil { + return nil, err + } + reqURLString := c.cfg.baseURL.ResolveReference(reqURL).String() + r, err := http.NewRequestWithContext(ctx, method, reqURLString, body) + if err != nil { + return nil, err + } + + r.Header.Set("authorization", fmt.Sprintf("Bearer %s", c.cfg.apiKey)) + //r.Header.Set("user-agent", "github.com/ngrok/ngrok-api-go") + r.Header.Set("ngrok-version", apiVersion) + if body != nil { + r.Header.Set("content-type", "application/json") + } + return r, nil +} + +func (c *Client) buildRequestBody(reqBody interface{}) (io.Reader, error) { + if reqBody == nil { + return nil, nil + } + jsonBytes, err := json.Marshal(reqBody) + if err != nil { + return nil, err + } + return bytes.NewReader(jsonBytes), nil +} + +func (c *Client) readResponse(resp *http.Response, out interface{}) error { + if resp.Body != nil { + defer resp.Body.Close() + } + if resp.StatusCode >= 400 { + return c.readErrorResponse(resp) + } + return c.readResponseBody(resp, out) +} + +// read an error response body +func (c *Client) readErrorResponse(resp *http.Response) error { + var out Error + err := c.readResponseBody(resp, &out) + if err != nil { + return err + } + return &out +} + +// unmarshal a response body +func (c *Client) readResponseBody(resp *http.Response, out interface{}) error { + if out == nil { + return nil + } + bodyBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + return c.buildUnmarshalError(resp, bodyBytes, err) + } + if err := json.Unmarshal(bodyBytes, out); err != nil { + return c.buildUnmarshalError(resp, bodyBytes, err) + } + return nil +} + +// if an error occurs while trying to read a response body, construct a new +// error explaining the unmarshalling failure +func (c *Client) buildUnmarshalError(resp *http.Response, bodyBytes []byte, err error) error { + return &Error{ + Msg: fmt.Sprintf("failed to unmarshal response body: %s. body: %s", err, bodyBytes), + StatusCode: int32(resp.StatusCode), + Details: map[string]string{ + "unmarshal_error": err.Error(), + "invalid_body": string(bodyBytes), + "operation_id": resp.Header.Get("ngrok-operation-id"), + }, + } +} diff --git a/config.go b/config.go new file mode 100644 index 0000000..cae2566 --- /dev/null +++ b/config.go @@ -0,0 +1,65 @@ +package ngrok + +import ( + "net/http" + "net/url" + "os" +) + +var ( + defaultBaseURL, _ = url.Parse("https://api.ngrok.com") +) + +type clientConfig struct { + apiKey string + baseURL *url.URL + debug Debug + httpClient *http.Client + err error +} + +type ClientOption func(cc *clientConfig) + +func (cc *clientConfig) parseOptions(opts []ClientOption) error { + for _, o := range opts { + o(cc) + } + cc.setDefaults() + return cc.err +} + +func (c *clientConfig) setDefaults() { + if c.httpClient == nil { + c.httpClient = http.DefaultClient + } + if c.baseURL == nil { + c.baseURL = defaultBaseURL + } + if c.apiKey == "" { + c.apiKey = os.Getenv("NGROK_API_KEY") + } +} + +func WithAPIKey(apiKey string) ClientOption { + return func(cc *clientConfig) { + cc.apiKey = apiKey + } +} + +func WithBaseURL(baseURL string) ClientOption { + return func(cc *clientConfig) { + cc.baseURL, cc.err = url.Parse(baseURL) + } +} + +func WithDebug(debug Debug) ClientOption { + return func(cc *clientConfig) { + cc.debug = debug + } +} + +func WithHTTPClient(httpClient *http.Client) ClientOption { + return func(cc *clientConfig) { + cc.httpClient = httpClient + } +} diff --git a/credentials/client.go b/credentials/client.go new file mode 100644 index 0000000..f619ec1 --- /dev/null +++ b/credentials/client.go @@ -0,0 +1,208 @@ +// Code generated by apic. DO NOT EDIT. + +package credentials + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new tunnel authtoken credential. This authtoken credential can be used +// to start a new tunnel session. The response to this API call is the only time +// the generated token is available. If you need it for future use, you must save +// it securely yourself. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.CredentialCreate, +) (*ngrok.Credential, error) { + var res ngrok.Credential + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/credentials")).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 +} + +// Delete a tunnel authtoken credential by ID +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("/credentials/{{ .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 +} + +// Get detailed information about a tunnel authtoken credential +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.Credential, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.Credential + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/credentials/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all tunnel authtoken credentials on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.CredentialList, error) { + var res ngrok.CredentialList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/credentials")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.Credential + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.Credentials + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.Credential { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an tunnel authtoken credential by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.CredentialUpdate, +) (*ngrok.Credential, error) { + var res ngrok.Credential + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/credentials/{{ .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 +} diff --git a/datatypes.go b/datatypes.go new file mode 100644 index 0000000..28d9003 --- /dev/null +++ b/datatypes.go @@ -0,0 +1,2277 @@ +// Code generated by apic. DO NOT EDIT. + +package ngrok + +type Empty struct { +} + +type Item struct { + // a resource identifier + ID string `json:"id,omitempty"` +} + +type Page struct { + BeforeID *string `json:"before_id,omitempty"` + Limit *string `json:"limit,omitempty"` +} + +type Error struct { + ErrorCode string `json:"error_code,omitempty"` + StatusCode int32 `json:"status_code,omitempty"` + Msg string `json:"msg,omitempty"` + Details map[string]string `json:"details,omitempty"` +} + +type Ref struct { + // a resource identifier + ID string `json:"id,omitempty"` + // a uri for locating a resource + URI string `json:"uri,omitempty"` +} + +type AbuseReport struct { + // ID of the abuse report + ID string `json:"id,omitempty"` + // URI of the abuse report API resource + URI string `json:"uri,omitempty"` + // timestamp that the abuse report record was created in RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // a list of URLs containing suspected abusive content + URLs []string `json:"urls,omitempty"` + // arbitrary user-defined data about this abuse report. Optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // Indicates whether ngrok has processed the abuse report. one of PENDING, + // PROCESSED, or PARTIALLY_PROCESSED + Status string `json:"status,omitempty"` + // an array of hostname statuses related to the report + Hostnames []AbuseReportHostname `json:"hostnames,omitempty"` +} + +type AbuseReportHostname struct { + // the hostname ngrok has parsed out of one of the reported URLs in this abuse + // report + Hostname string `json:"hostname,omitempty"` + // indicates what action ngrok has taken against the hostname. one of PENDING, + // BANNED, UNBANNED, or IGNORE + Status string `json:"status,omitempty"` +} + +type AbuseReportCreate struct { + // a list of URLs containing suspected abusive content + URLs []string `json:"urls,omitempty"` + // arbitrary user-defined data about this abuse report. Optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` +} + +type APIKeyCreate struct { + // human-readable description of what uses the API key to authenticate. optional, + // max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined data of this API key. optional, max 4096 bytes + Metadata string `json:"metadata,omitempty"` +} + +type APIKeyUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of what uses the API key to authenticate. optional, + // max 255 bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined data of this API key. optional, max 4096 bytes + Metadata *string `json:"metadata,omitempty"` +} + +type APIKey struct { + // unique API key resource identifier + ID string `json:"id,omitempty"` + // URI to the API resource of this API key + URI string `json:"uri,omitempty"` + // human-readable description of what uses the API key to authenticate. optional, + // max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined data of this API key. optional, max 4096 bytes + Metadata string `json:"metadata,omitempty"` + // timestamp when the api key was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // the bearer token that can be placed into the Authorization header to + // authenticate request to the ngrok API. This value is only available one time, on + // the API response from key creation. Otherwise it is null. + Token *string `json:"token,omitempty"` +} + +type APIKeyList struct { + // the list of API keys for this account + Keys []APIKey `json:"keys,omitempty"` + // URI of the API keys list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type PriorityBackend struct { + // unique identifier for this Priority backend + ID string `json:"id,omitempty"` + // timestamp when the backend was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this backend. Optional + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata string `json:"metadata,omitempty"` + // the ids of the child backends in order + Backends []string `json:"backends,omitempty"` +} + +type PriorityBackendCreate struct { + // human-readable description of this backend. Optional + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata string `json:"metadata,omitempty"` + // the ids of the child backends in order + Backends []string `json:"backends,omitempty"` +} + +type PriorityBackendUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this backend. Optional + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata *string `json:"metadata,omitempty"` + // the ids of the child backends in order + Backends []string `json:"backends,omitempty"` +} + +type PriorityBackendList struct { + // the list of all Priority backends on this account + Backends []PriorityBackend `json:"backends,omitempty"` + // URI of the Priority backends list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type StaticBackend struct { + // unique identifier for this static backend + ID string `json:"id,omitempty"` + // timestamp when the backend was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this backend. Optional + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata string `json:"metadata,omitempty"` + // the address to forward to + Address string `json:"address,omitempty"` + // tls configuration to use + TLS StaticBackendTLS `json:"tls,omitempty"` +} + +type StaticBackendTLS struct { + // if tls is checked + Enabled bool `json:"enabled,omitempty"` +} + +type StaticBackendCreate struct { + // human-readable description of this backend. Optional + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata string `json:"metadata,omitempty"` + // the address to forward to + Address string `json:"address,omitempty"` + // tls configuration to use + TLS StaticBackendTLS `json:"tls,omitempty"` +} + +type StaticBackendUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this backend. Optional + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata *string `json:"metadata,omitempty"` + // the address to forward to + Address string `json:"address,omitempty"` + // tls configuration to use + TLS StaticBackendTLS `json:"tls,omitempty"` +} + +type StaticBackendList struct { + // the list of all static backends on this account + Backends []StaticBackend `json:"backends,omitempty"` + // URI of the static backends list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type TunnelGroupBackend struct { + // unique identifier for this TunnelGroup backend + ID string `json:"id,omitempty"` + // timestamp when the backend was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this backend. Optional + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata string `json:"metadata,omitempty"` + // labels to watch for tunnels on, e.g. app->foo, dc->bar + Labels map[string]string `json:"labels,omitempty"` +} + +type TunnelGroupBackendCreate struct { + // human-readable description of this backend. Optional + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata string `json:"metadata,omitempty"` + // labels to watch for tunnels on, e.g. app->foo, dc->bar + Labels map[string]string `json:"labels,omitempty"` +} + +type TunnelGroupBackendUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this backend. Optional + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata *string `json:"metadata,omitempty"` + // labels to watch for tunnels on, e.g. app->foo, dc->bar + Labels map[string]string `json:"labels,omitempty"` +} + +type TunnelGroupBackendList struct { + // the list of all TunnelGroup backends on this account + Backends []TunnelGroupBackend `json:"backends,omitempty"` + // URI of the TunnelGroup backends list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type WeightedBackend struct { + // unique identifier for this Weighted backend + ID string `json:"id,omitempty"` + // timestamp when the backend was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this backend. Optional + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata string `json:"metadata,omitempty"` + // the ids of the child backends to their weights (0-10000) + Backends map[string]int64 `json:"backends,omitempty"` +} + +type WeightedBackendCreate struct { + // human-readable description of this backend. Optional + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata string `json:"metadata,omitempty"` + // the ids of the child backends to their weights (0-10000) + Backends map[string]int64 `json:"backends,omitempty"` +} + +type WeightedBackendUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this backend. Optional + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this backend. Optional + Metadata *string `json:"metadata,omitempty"` + // the ids of the child backends to their weights (0-10000) + Backends map[string]int64 `json:"backends,omitempty"` +} + +type WeightedBackendList struct { + // the list of all Weighted backends on this account + Backends []WeightedBackend `json:"backends,omitempty"` + // URI of the Weighted backends list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type CertificateAuthorityCreate struct { + // human-readable description of this Certificate Authority. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this Certificate Authority. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // raw PEM of the Certificate Authority + CAPEM string `json:"ca_pem,omitempty"` +} + +type CertificateAuthorityUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this Certificate Authority. optional, max 255 + // bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this Certificate Authority. + // optional, max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` +} + +type CertificateAuthority struct { + // unique identifier for this Certificate Authority + ID string `json:"id,omitempty"` + // URI of the Certificate Authority API resource + URI string `json:"uri,omitempty"` + // timestamp when the Certificate Authority was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this Certificate Authority. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this Certificate Authority. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // raw PEM of the Certificate Authority + CAPEM string `json:"ca_pem,omitempty"` + // subject common name of the Certificate Authority + SubjectCommonName string `json:"subject_common_name,omitempty"` + // timestamp when this Certificate Authority becomes valid, RFC 3339 format + NotBefore string `json:"not_before,omitempty"` + // timestamp when this Certificate Authority becomes invalid, RFC 3339 format + NotAfter string `json:"not_after,omitempty"` + // set of actions the private key of this Certificate Authority can be used for + KeyUsages []string `json:"key_usages,omitempty"` + // extended set of actions the private key of this Certificate Authority can be + // used for + ExtendedKeyUsages []string `json:"extended_key_usages,omitempty"` +} + +type CertificateAuthorityList struct { + // the list of all certificate authorities on this account + CertificateAuthorities []CertificateAuthority `json:"certificate_authorities,omitempty"` + // URI of the certificates authorities list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type CredentialCreate struct { + // human-readable description of who or what will use the credential to + // authenticate. Optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this credential. Optional, max + // 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // optional list of ACL rules. If unspecified, the credential will have no + // restrictions. The only allowed ACL rule at this time is the bind rule. The bind + // rule allows the caller to restrict what domains and addresses the token is + // allowed to bind. For example, to allow the token to open a tunnel on + // example.ngrok.io your ACL would include the rule bind:example.ngrok.io. Bind + // rules may specify a leading wildcard to match multiple domains with a common + // suffix. For example, you may specify a rule of bind:*.example.com which will + // allow x.example.com, y.example.com, *.example.com, etc. A rule of '*' is + // equivalent to no acl at all and will explicitly permit all actions. + ACL []string `json:"acl,omitempty"` +} + +type CredentialUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of who or what will use the credential to + // authenticate. Optional, max 255 bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this credential. Optional, max + // 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // optional list of ACL rules. If unspecified, the credential will have no + // restrictions. The only allowed ACL rule at this time is the bind rule. The bind + // rule allows the caller to restrict what domains and addresses the token is + // allowed to bind. For example, to allow the token to open a tunnel on + // example.ngrok.io your ACL would include the rule bind:example.ngrok.io. Bind + // rules may specify a leading wildcard to match multiple domains with a common + // suffix. For example, you may specify a rule of bind:*.example.com which will + // allow x.example.com, y.example.com, *.example.com, etc. A rule of '*' is + // equivalent to no acl at all and will explicitly permit all actions. + ACL *[]string `json:"acl,omitempty"` +} + +type Credential struct { + // unique tunnel credential resource identifier + ID string `json:"id,omitempty"` + // URI of the tunnel credential API resource + URI string `json:"uri,omitempty"` + // timestamp when the tunnel credential was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of who or what will use the credential to + // authenticate. Optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this credential. Optional, max + // 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // the credential's authtoken that can be used to authenticate an ngrok client. + // This value is only available one time, on the API response from credential + // creation, otherwise it is null. + Token *string `json:"token,omitempty"` + // optional list of ACL rules. If unspecified, the credential will have no + // restrictions. The only allowed ACL rule at this time is the bind rule. The bind + // rule allows the caller to restrict what domains and addresses the token is + // allowed to bind. For example, to allow the token to open a tunnel on + // example.ngrok.io your ACL would include the rule bind:example.ngrok.io. Bind + // rules may specify a leading wildcard to match multiple domains with a common + // suffix. For example, you may specify a rule of bind:*.example.com which will + // allow x.example.com, y.example.com, *.example.com, etc. A rule of '*' is + // equivalent to no acl at all and will explicitly permit all actions. + ACL []string `json:"acl,omitempty"` +} + +type CredentialList struct { + // the list of all tunnel credentials on this account + Credentials []Credential `json:"credentials,omitempty"` + // URI of the tunnel credential list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type EventStreamCreate struct { + // Arbitrary user-defined machine-readable data of this Event Stream. Optional, max + // 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // Human-readable description of the Event Stream. Optional, max 255 bytes. + Description string `json:"description,omitempty"` + // A list of protocol-specific fields you want to collect on each event. + Fields []string `json:"fields,omitempty"` + // The protocol that determines which events will be collected. Supported values + // are tcp_connection_closed and http_request_complete. + EventType string `json:"event_type,omitempty"` + // A list of Event Destination IDs which should be used for this Event Stream. + // Event Streams are required to have at least one Event Destination. + DestinationIDs []string `json:"destination_ids,omitempty"` + // The percentage of all events you would like to capture. Valid values range from + // 0.01, representing 1% of all events to 1.00, representing 100% of all events. + SamplingRate float64 `json:"sampling_rate,omitempty"` +} + +type EventStreamUpdate struct { + // Unique identifier for this Event Stream. + ID string `json:"id,omitempty"` + // Arbitrary user-defined machine-readable data of this Event Stream. Optional, max + // 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // Human-readable description of the Event Stream. Optional, max 255 bytes. + Description *string `json:"description,omitempty"` + // A list of protocol-specific fields you want to collect on each event. + Fields *[]string `json:"fields,omitempty"` + // A list of Event Destination IDs which should be used for this Event Stream. + // Event Streams are required to have at least one Event Destination. + DestinationIDs *[]string `json:"destination_ids,omitempty"` + // The percentage of all events you would like to capture. Valid values range from + // 0.01, representing 1% of all events to 1.00, representing 100% of all events. + SamplingRate *float64 `json:"sampling_rate,omitempty"` +} + +type EventStreamList struct { + // The list of all Event Streams on this account. + EventStreams []EventStream `json:"event_streams,omitempty"` + // URI of the Event Stream list API resource. + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page. + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type EventStream struct { + // Unique identifier for this Event Stream. + ID string `json:"id,omitempty"` + // URI of the Event Stream API resource. + URI string `json:"uri,omitempty"` + // Timestamp when the Event Stream was created, RFC 3339 format. + CreatedAt string `json:"created_at,omitempty"` + // Arbitrary user-defined machine-readable data of this Event Stream. Optional, max + // 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // Human-readable description of the Event Stream. Optional, max 255 bytes. + Description string `json:"description,omitempty"` + // A list of protocol-specific fields you want to collect on each event. + Fields []string `json:"fields,omitempty"` + // The protocol that determines which events will be collected. Supported values + // are tcp_connection_closed and http_request_complete. + EventType string `json:"event_type,omitempty"` + // A list of Event Destination IDs which should be used for this Event Stream. + // Event Streams are required to have at least one Event Destination. + DestinationIDs []string `json:"destination_ids,omitempty"` + // The percentage of all events you would like to capture. Valid values range from + // 0.01, representing 1% of all events to 1.00, representing 100% of all events. + SamplingRate float64 `json:"sampling_rate,omitempty"` +} + +type EventDestinationCreate struct { + // Arbitrary user-defined machine-readable data of this Event Destination. + // Optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // Human-readable description of the Event Destination. Optional, max 255 bytes. + Description string `json:"description,omitempty"` + // The output format you would like to serialize events into when sending to their + // target. Currently the only accepted value is JSON. + Format string `json:"format,omitempty"` + // An object that encapsulates where and how to send your events. An event + // destination must contain exactly one of the following objects, leaving the rest + // null: kinesis, firehose, cloudwatch_logs, or s3. + Target EventTarget `json:"target,omitempty"` + VerifyWithTestEvent *bool `json:"verify_with_test_event,omitempty"` +} + +type EventDestinationUpdate struct { + // Unique identifier for this Event Destination. + ID string `json:"id,omitempty"` + // Arbitrary user-defined machine-readable data of this Event Destination. + // Optional, max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // Human-readable description of the Event Destination. Optional, max 255 bytes. + Description *string `json:"description,omitempty"` + // The output format you would like to serialize events into when sending to their + // target. Currently the only accepted value is JSON. + Format *string `json:"format,omitempty"` + // An object that encapsulates where and how to send your events. An event + // destination must contain exactly one of the following objects, leaving the rest + // null: kinesis, firehose, cloudwatch_logs, or s3. + Target *EventTarget `json:"target,omitempty"` + VerifyWithTestEvent *bool `json:"verify_with_test_event,omitempty"` +} + +type EventDestination struct { + // Unique identifier for this Event Destination. + ID string `json:"id,omitempty"` + // Arbitrary user-defined machine-readable data of this Event Destination. + // Optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // Timestamp when the Event Destination was created, RFC 3339 format. + CreatedAt string `json:"created_at,omitempty"` + // Human-readable description of the Event Destination. Optional, max 255 bytes. + Description string `json:"description,omitempty"` + // The output format you would like to serialize events into when sending to their + // target. Currently the only accepted value is JSON. + Format string `json:"format,omitempty"` + // An object that encapsulates where and how to send your events. An event + // destination must contain exactly one of the following objects, leaving the rest + // null: kinesis, firehose, cloudwatch_logs, or s3. + Target EventTarget `json:"target,omitempty"` + // URI of the Event Destination API resource. + URI string `json:"uri,omitempty"` +} + +type EventDestinationList struct { + // The list of all Event Destinations on this account. + EventDestinations []EventDestination `json:"event_destinations,omitempty"` + // URI of the Event Destinations list API resource. + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page. + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type EventTarget struct { + // Configuration used to send events to Amazon Kinesis Data Firehose. + Firehose *EventTargetFirehose `json:"firehose,omitempty"` + // Configuration used to send events to Amazon Kinesis. + Kinesis *EventTargetKinesis `json:"kinesis,omitempty"` + // Configuration used to send events to Amazon CloudWatch Logs. + CloudwatchLogs *EventTargetCloudwatchLogs `json:"cloudwatch_logs,omitempty"` + // Configuration used for internal debugging. + Debug *EventTargetDebug `json:"debug,omitempty"` +} + +type EventTargetFirehose struct { + // Configuration for how to authenticate into your AWS account. Exactly one of role + // or creds should be configured. + Auth AWSAuth `json:"auth,omitempty"` + // An Amazon Resource Name specifying the Firehose delivery stream to deposit + // events into. + DeliveryStreamARN string `json:"delivery_stream_arn,omitempty"` +} + +type EventTargetKinesis struct { + // Configuration for how to authenticate into your AWS account. Exactly one of role + // or creds should be configured. + Auth AWSAuth `json:"auth,omitempty"` + // An Amazon Resource Name specifying the Kinesis stream to deposit events into. + StreamARN string `json:"stream_arn,omitempty"` +} + +type EventTargetCloudwatchLogs struct { + // Configuration for how to authenticate into your AWS account. Exactly one of role + // or creds should be configured. + Auth AWSAuth `json:"auth,omitempty"` + // An Amazon Resource Name specifying the CloudWatch Logs group to deposit events + // into. + LogGroupARN string `json:"log_group_arn,omitempty"` +} + +type EventTargetS3 struct { + // Configuration for how to authenticate into your AWS account. Exactly one of role + // or creds should be configured. + Auth AWSAuth `json:"auth,omitempty"` + // An Amazon Resource Name specifying the S3 bucket to deposit events into. + BucketARN string `json:"bucket_arn,omitempty"` + // An optional prefix to prepend to S3 object keys. + ObjectPrefix string `json:"object_prefix,omitempty"` + // Whether or not to compress files with gzip. + Compression bool `json:"compression,omitempty"` + // How many bytes we should accumulate into a single file before sending to S3. + MaxFileSize int64 `json:"max_file_size,omitempty"` + // How many seconds we should batch up events before sending them to S3. + MaxFileAge int64 `json:"max_file_age,omitempty"` +} + +type EventTargetDebug struct { + // Whether or not to output to publisher service logs. + Log bool `json:"log,omitempty"` + // URL to send events to. + CallbackURL string `json:"callback_url,omitempty"` +} + +type AWSAuth struct { + // A role for ngrok to assume on your behalf to deposit events into your AWS + // account. + Role *AWSRole `json:"role,omitempty"` + // Credentials to your AWS account if you prefer ngrok to sign in with long-term + // access keys. + Creds *AWSCredentials `json:"creds,omitempty"` +} + +type AWSRole struct { + // An ARN that specifies the role that ngrok should use to deliver to the + // configured target. + RoleARN string `json:"role_arn,omitempty"` +} + +type AWSCredentials struct { + // The ID portion of an AWS access key. + AWSAccessKeyID string `json:"aws_access_key_id,omitempty"` + // The secret portion of an AWS access key. + AWSSecretAccessKey *string `json:"aws_secret_access_key,omitempty"` +} + +type SentEvent struct { + EventID string `json:"event_id,omitempty"` +} + +type EventSubscriptionCreate struct { + // Arbitrary customer supplied information intended to be machine readable. + // Optional, max 4096 chars. + Metadata string `json:"metadata,omitempty"` + // Arbitrary customer supplied information intended to be human readable. Optional, + // max 255 chars. + Description string `json:"description,omitempty"` + // TODO + Sources []EventSourceReplace `json:"sources,omitempty"` + // TODO + DestinationIDs []string `json:"destination_ids,omitempty"` +} + +type EventSubscriptionUpdate struct { + // Unique identifier for this Event Subscription. + ID string `json:"id,omitempty"` + // Arbitrary customer supplied information intended to be machine readable. + // Optional, max 4096 chars. + Metadata *string `json:"metadata,omitempty"` + // Arbitrary customer supplied information intended to be human readable. Optional, + // max 255 chars. + Description *string `json:"description,omitempty"` + // TODO + Sources *[]EventSourceReplace `json:"sources,omitempty"` + // TODO + DestinationIDs *[]string `json:"destination_ids,omitempty"` +} + +type EventSubscriptionList struct { + // The list of all Event Subscriptions on this account. + EventSubscriptions []EventSubscription `json:"event_subscriptions,omitempty"` + // URI of the Event Subscriptions list API resource. + URI string `json:"uri,omitempty"` + // URI of next page, or null if there is no next page. + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type EventSubscription struct { + // Unique identifier for this Event Subscription. + ID string `json:"id,omitempty"` + // URI of the Event Subscription API resource. + URI string `json:"uri,omitempty"` + // When the Event Subscription was created (RFC 3339 format). + CreatedAt string `json:"created_at,omitempty"` + // Arbitrary customer supplied information intended to be machine readable. + // Optional, max 4096 chars. + Metadata string `json:"metadata,omitempty"` + // Arbitrary customer supplied information intended to be human readable. Optional, + // max 255 chars. + Description string `json:"description,omitempty"` + // TODO + Sources []EventSource `json:"sources,omitempty"` + // TODO + Destinations []Ref `json:"destinations,omitempty"` +} + +type EventSourceReplace struct { + // TODO + Type string `json:"type,omitempty"` + // TODO + Filter string `json:"filter,omitempty"` + // TODO + Fields []string `json:"fields,omitempty"` +} + +type EventSource struct { + // TODO + Type string `json:"type,omitempty"` + // TODO + Filter string `json:"filter,omitempty"` + // TODO + Fields []string `json:"fields,omitempty"` + // TODO + URI string `json:"uri,omitempty"` +} + +type EventSourceList struct { + // TODO + Sources []EventSource `json:"sources,omitempty"` + // TODO + URI string `json:"uri,omitempty"` +} + +type EventSourceCreate struct { + // TODO + SubscriptionID string `json:"subscription_id,omitempty"` + // TODO + Type string `json:"type,omitempty"` + // TODO + Filter string `json:"filter,omitempty"` + // TODO + Fields []string `json:"fields,omitempty"` +} + +type EventSourceUpdate struct { + // TODO + SubscriptionID string `json:"subscription_id,omitempty"` + // TODO + Type string `json:"type,omitempty"` + // TODO + Filter *string `json:"filter,omitempty"` + // TODO + Fields *[]string `json:"fields,omitempty"` +} + +// This is needed instead of Item because the parameters are different. +type EventSourceItem struct { + // TODO + SubscriptionID string `json:"subscription_id,omitempty"` + // TODO + Type string `json:"type,omitempty"` +} + +// This is needed instead of Page because the parameters are different. We also don't need the typical pagination params because pagination of this isn't necessary or supported. +type EventSourcePage struct { + // TODO + SubscriptionID string `json:"subscription_id,omitempty"` +} + +type IPPolicyCreate struct { + // human-readable description of the source IPs of this IP policy. optional, max + // 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP policy. optional, max + // 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // the IP policy action. Supported values are allow or deny + Action string `json:"action,omitempty"` +} + +type IPPolicyUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of the source IPs of this IP policy. optional, max + // 255 bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP policy. optional, max + // 4096 bytes. + Metadata *string `json:"metadata,omitempty"` +} + +type IPPolicy struct { + // unique identifier for this IP policy + ID string `json:"id,omitempty"` + // URI of the IP Policy API resource + URI string `json:"uri,omitempty"` + // timestamp when the IP policy was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of the source IPs of this IP policy. optional, max + // 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP policy. optional, max + // 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // the IP policy action. Supported values are allow or deny + Action string `json:"action,omitempty"` +} + +type IPPolicyList struct { + // the list of all IP policies on this account + IPPolicies []IPPolicy `json:"ip_policies,omitempty"` + // URI of the IP policy list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type IPPolicyRuleCreate struct { + // human-readable description of the source IPs of this IP rule. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP policy rule. optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // an IP or IP range specified in CIDR notation. IPv4 and IPv6 are both supported. + CIDR string `json:"cidr,omitempty"` + // ID of the IP policy this IP policy rule will be attached to + IPPolicyID string `json:"ip_policy_id,omitempty"` +} + +type IPPolicyRuleUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of the source IPs of this IP rule. optional, max 255 + // bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP policy rule. optional, + // max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // an IP or IP range specified in CIDR notation. IPv4 and IPv6 are both supported. + CIDR *string `json:"cidr,omitempty"` +} + +type IPPolicyRule struct { + // unique identifier for this IP policy rule + ID string `json:"id,omitempty"` + // URI of the IP policy rule API resource + URI string `json:"uri,omitempty"` + // timestamp when the IP policy rule was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of the source IPs of this IP rule. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP policy rule. optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // an IP or IP range specified in CIDR notation. IPv4 and IPv6 are both supported. + CIDR string `json:"cidr,omitempty"` + // object describing the IP policy this IP Policy Rule belongs to + IPPolicy Ref `json:"ip_policy,omitempty"` +} + +type IPPolicyRuleList struct { + // the list of all IP policy rules on this account + IPPolicyRules []IPPolicyRule `json:"ip_policy_rules,omitempty"` + // URI of the IP policy rule list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type IPRestrictionCreate struct { + // human-readable description of this IP restriction. optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP restriction. optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // true if the IP restriction will be enforce. if false, only warnings will be + // issued + Enforced bool `json:"enforced,omitempty"` + // the type of IP restriction. this defines what traffic will be restricted with + // the attached policies. four values are currently supported: dashboard, api, + // agent, and endpoints + Type string `json:"type,omitempty"` + // the set of IP policy identifiers that are used to enforce the restriction + IPPolicyIDs []string `json:"ip_policy_ids,omitempty"` +} + +type IPRestrictionUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this IP restriction. optional, max 255 bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP restriction. optional, + // max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // true if the IP restriction will be enforce. if false, only warnings will be + // issued + Enforced *bool `json:"enforced,omitempty"` + // the set of IP policy identifiers that are used to enforce the restriction + IPPolicyIDs []string `json:"ip_policy_ids,omitempty"` +} + +type IPRestriction struct { + // unique identifier for this IP restriction + ID string `json:"id,omitempty"` + // URI of the IP restriction API resource + URI string `json:"uri,omitempty"` + // timestamp when the IP restriction was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this IP restriction. optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP restriction. optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // true if the IP restriction will be enforce. if false, only warnings will be + // issued + Enforced bool `json:"enforced,omitempty"` + // the type of IP restriction. this defines what traffic will be restricted with + // the attached policies. four values are currently supported: dashboard, api, + // agent, and endpoints + Type string `json:"type,omitempty"` + // the set of IP policies that are used to enforce the restriction + IPPolicies []Ref `json:"ip_policies,omitempty"` +} + +type IPRestrictionList struct { + // the list of all IP restrictions on this account + IPRestrictions []IPRestriction `json:"ip_restrictions,omitempty"` + // URI of the IP resrtrictions list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type IPWhitelistEntryCreate struct { + // human-readable description of the source IPs for this IP whitelist entry. + // optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP whitelist entry. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // an IP address or IP network range in CIDR notation (e.g. 10.1.1.1 or + // 10.1.0.0/16) of addresses that will be whitelisted to communicate with your + // tunnel endpoints + IPNet string `json:"ip_net,omitempty"` +} + +type IPWhitelistEntryUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of the source IPs for this IP whitelist entry. + // optional, max 255 bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP whitelist entry. + // optional, max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` +} + +type IPWhitelistEntry struct { + // unique identifier for this IP whitelist entry + ID string `json:"id,omitempty"` + // URI of the IP whitelist entry API resource + URI string `json:"uri,omitempty"` + // timestamp when the IP whitelist entry was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of the source IPs for this IP whitelist entry. + // optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this IP whitelist entry. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // an IP address or IP network range in CIDR notation (e.g. 10.1.1.1 or + // 10.1.0.0/16) of addresses that will be whitelisted to communicate with your + // tunnel endpoints + IPNet string `json:"ip_net,omitempty"` +} + +type IPWhitelistEntryList struct { + // the list of all IP whitelist entries on this account + Whitelist []IPWhitelistEntry `json:"whitelist,omitempty"` + // URI of the IP whitelist API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type EndpointConfiguration struct { + // unique identifier of this endpoint configuration + ID string `json:"id,omitempty"` + // they type of traffic this endpoint configuration can be applied to. one of: + // http, https, tcp + Type string `json:"type,omitempty"` + // human-readable description of what this endpoint configuration will be do when + // applied or what traffic it will be applied to. Optional, max 255 bytes + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this endpoint configuration. + // Optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // timestamp when the endpoint configuration was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // URI of the endpoint configuration API resource + URI string `json:"uri,omitempty"` + // basic auth module configuration or null + BasicAuth *EndpointBasicAuth `json:"basic_auth,omitempty"` + // circuit breaker module configuration or null + CircuitBreaker *EndpointCircuitBreaker `json:"circuit_breaker,omitempty"` + // compression module configuration or null + Compression *EndpointCompression `json:"compression,omitempty"` + // request headers module configuration or null + RequestHeaders *EndpointRequestHeaders `json:"request_headers,omitempty"` + // response headers module configuration or null + ResponseHeaders *EndpointResponseHeaders `json:"response_headers,omitempty"` + // ip policy module configuration or null + IPPolicy *EndpointIPPolicy `json:"ip_policy,omitempty"` + // mutual TLS module configuration or null + MutualTLS *EndpointMutualTLS `json:"mutual_tls,omitempty"` + // TLS termination module configuration or null + TLSTermination *EndpointTLSTermination `json:"tls_termination,omitempty"` + // webhook validation module configuration or null + WebhookValidation *EndpointWebhookValidation `json:"webhook_validation,omitempty"` + // oauth module configuration or null + OAuth *EndpointOAuth `json:"oauth,omitempty"` + // logging module configuration or null + Logging *EndpointLogging `json:"logging,omitempty"` + // saml module configuration or null + SAML *EndpointSAML `json:"saml,omitempty"` + // oidc module configuration or null + OIDC *EndpointOIDC `json:"oidc,omitempty"` + // backend module configuration or null + Backend *EndpointBackend `json:"backend,omitempty"` +} + +type EndpointConfigurationList struct { + // the list of all endpoint configurations on this account + EndpointConfigurations []EndpointConfiguration `json:"endpoint_configurations,omitempty"` + // URI of the endpoint configurations list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type EndpointConfigurationUpdate struct { + // unique identifier of this endpoint configuration + ID string `json:"id,omitempty"` + // human-readable description of what this endpoint configuration will be do when + // applied or what traffic it will be applied to. Optional, max 255 bytes + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this endpoint configuration. + // Optional, max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // basic auth module configuration or null + BasicAuth *EndpointBasicAuth `json:"basic_auth,omitempty"` + // circuit breaker module configuration or null + CircuitBreaker *EndpointCircuitBreaker `json:"circuit_breaker,omitempty"` + // compression module configuration or null + Compression *EndpointCompression `json:"compression,omitempty"` + // request headers module configuration or null + RequestHeaders *EndpointRequestHeaders `json:"request_headers,omitempty"` + // response headers module configuration or null + ResponseHeaders *EndpointResponseHeaders `json:"response_headers,omitempty"` + // ip policy module configuration or null + IPPolicy *EndpointIPPolicyMutate `json:"ip_policy,omitempty"` + // mutual TLS module configuration or null + MutualTLS *EndpointMutualTLSMutate `json:"mutual_tls,omitempty"` + // TLS termination module configuration or null + TLSTermination *EndpointTLSTermination `json:"tls_termination,omitempty"` + // webhook validation module configuration or null + WebhookValidation *EndpointWebhookValidation `json:"webhook_validation,omitempty"` + // oauth module configuration or null + OAuth *EndpointOAuth `json:"oauth,omitempty"` + // logging module configuration or null + Logging *EndpointLoggingMutate `json:"logging,omitempty"` + // saml module configuration or null + SAML *EndpointSAMLMutate `json:"saml,omitempty"` + // oidc module configuration or null + OIDC *EndpointOIDC `json:"oidc,omitempty"` + // backend module configuration or null + Backend *EndpointBackendMutate `json:"backend,omitempty"` +} + +type EndpointConfigurationCreate struct { + // they type of traffic this endpoint configuration can be applied to. one of: + // http, https, tcp + Type string `json:"type,omitempty"` + // human-readable description of what this endpoint configuration will be do when + // applied or what traffic it will be applied to. Optional, max 255 bytes + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this endpoint configuration. + // Optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // basic auth module configuration or null + BasicAuth *EndpointBasicAuth `json:"basic_auth,omitempty"` + // circuit breaker module configuration or null + CircuitBreaker *EndpointCircuitBreaker `json:"circuit_breaker,omitempty"` + // compression module configuration or null + Compression *EndpointCompression `json:"compression,omitempty"` + // request headers module configuration or null + RequestHeaders *EndpointRequestHeaders `json:"request_headers,omitempty"` + // response headers module configuration or null + ResponseHeaders *EndpointResponseHeaders `json:"response_headers,omitempty"` + // ip policy module configuration or null + IPPolicy *EndpointIPPolicyMutate `json:"ip_policy,omitempty"` + // mutual TLS module configuration or null + MutualTLS *EndpointMutualTLSMutate `json:"mutual_tls,omitempty"` + // TLS termination module configuration or null + TLSTermination *EndpointTLSTermination `json:"tls_termination,omitempty"` + // webhook validation module configuration or null + WebhookValidation *EndpointWebhookValidation `json:"webhook_validation,omitempty"` + // oauth module configuration or null + OAuth *EndpointOAuth `json:"oauth,omitempty"` + // logging module configuration or null + Logging *EndpointLoggingMutate `json:"logging,omitempty"` + // saml module configuration or null + SAML *EndpointSAMLMutate `json:"saml,omitempty"` + // oidc module configuration or null + OIDC *EndpointOIDC `json:"oidc,omitempty"` + // backend module configuration or null + Backend *EndpointBackendMutate `json:"backend,omitempty"` +} + +type EndpointWebhookValidation struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // a string indicating which webhook provider will be sending webhooks to this + // endpoint. Value must be one of the supported providers: SLACK, SNS, STRIPE, + // GITHUB, TWILIO, SHOPIFY, GITLAB, INTERCOM. + Provider string `json:"provider,omitempty"` + // a string secret used to validate requests from the given provider. All providers + // except AWS SNS require a secret + Secret string `json:"secret,omitempty"` +} + +type EndpointCompression struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` +} + +type EndpointMutualTLS struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // PEM-encoded CA certificates that will be used to validate. Multiple CAs may be + // provided by concatenating them together. + CertificateAuthorities []Ref `json:"certificate_authorities,omitempty"` +} + +type EndpointMutualTLSMutate struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // list of certificate authorities that will be used to validate the TLS client + // certificate presnted by the initiatiator of the TLS connection + CertificateAuthorityIDs []string `json:"certificate_authority_ids,omitempty"` +} + +type EndpointTLSTermination struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // edge if the ngrok edge should terminate TLS traffic, upstream if TLS traffic + // should be passed through to the upstream ngrok agent / application server for + // termination. if upstream is chosen, most other modules will be disallowed + // because they rely on the ngrok edge being able to access the underlying traffic. + TerminateAt string `json:"terminate_at,omitempty"` + // The minimum TLS version used for termination and advertised to the client during + // the TLS handshake. if unspecified, ngrok will choose an industry-safe default. + // This value must be null if terminate_at is set to upstream. + MinVersion *string `json:"min_version,omitempty"` +} + +type EndpointBasicAuth struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // determines how the basic auth credentials are validated. Currently only the + // value agent is supported which means that credentials will be validated against + // the username and password specified by the ngrok agent's -auth flag, if any. + AuthProviderID string `json:"auth_provider_id,omitempty"` + // an arbitrary string to be specified in as the 'realm' value in the + // WWW-Authenticate header. default is ngrok + Realm string `json:"realm,omitempty"` + // true or false indicating whether to allow OPTIONS requests through without + // authentication which is necessary for CORS. default is false + AllowOptions bool `json:"allow_options,omitempty"` +} + +type EndpointLogging struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // list of all EventStreams that will be used to configure and export this + // endpoint's logs + EventStreams []Ref `json:"event_streams,omitempty"` +} + +type EndpointLoggingMutate struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // list of all EventStreams that will be used to configure and export this + // endpoint's logs + EventStreamIDs []string `json:"event_stream_ids,omitempty"` +} + +type EndpointRequestHeaders struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // a map of header key to header value that will be injected into the HTTP Request + // before being sent to the upstream application server + Add map[string]string `json:"add,omitempty"` + // a list of header names that will be removed from the HTTP Request before being + // sent to the upstream application server + Remove []string `json:"remove,omitempty"` +} + +type EndpointResponseHeaders struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // a map of header key to header value that will be injected into the HTTP Response + // returned to the HTTP client + Add map[string]string `json:"add,omitempty"` + // a list of header names that will be removed from the HTTP Response returned to + // the HTTP client + Remove []string `json:"remove,omitempty"` +} + +type EndpointIPPolicy struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + IPPolicies []Ref `json:"ip_policies,omitempty"` +} + +type EndpointIPPolicyMutate struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // list of all IP policies that will be used to check if a source IP is allowed + // access to the endpoint + IPPolicyIDs []string `json:"ip_policy_ids,omitempty"` +} + +type EndpointCircuitBreaker struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // Integer number of seconds after which the circuit is tripped to wait before + // re-evaluating upstream health + TrippedDuration uint32 `json:"tripped_duration,omitempty"` + // Integer number of seconds in the statistical rolling window that metrics are + // retained for. + RollingWindow uint32 `json:"rolling_window,omitempty"` + // Integer number of buckets into which metrics are retained. Max 128. + NumBuckets uint32 `json:"num_buckets,omitempty"` + // Integer number of requests in a rolling window that will trip the circuit. + // Helpful if traffic volume is low. + VolumeThreshold uint32 `json:"volume_threshold,omitempty"` + // Error threshold percentage should be between 0 - 1.0, not 0-100.0 + ErrorThresholdPercentage float64 `json:"error_threshold_percentage,omitempty"` +} + +type EndpointOAuth struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // an object which defines the identity provider to use for authentication and + // configuration for who may access the endpoint + Provider EndpointOAuthProvider `json:"provider,omitempty"` + // Do not enforce authentication on HTTP OPTIONS requests. necessary if you are + // supporting CORS. + OptionsPassthrough bool `json:"options_passthrough,omitempty"` + // the prefix of the session cookie that ngrok sets on the http client to cache + // authentication. default is 'ngrok.' + CookiePrefix string `json:"cookie_prefix,omitempty"` + // Integer number of seconds of inactivity after which if the user has not accessed + // the endpoint, their session will time out and they will be forced to + // reauthenticate. + InactivityTimeout uint32 `json:"inactivity_timeout,omitempty"` + // Integer number of seconds of the maximum duration of an authenticated session. + // After this period is exceeded, a user must reauthenticate. + MaximumDuration uint32 `json:"maximum_duration,omitempty"` + // Integer number of seconds after which ngrok guarantees it will refresh user + // state from the identity provider and recheck whether the user is still + // authorized to access the endpoint. This is the preferred tunable to use to + // enforce a minimum amount of time after which a revoked user will no longer be + // able to access the resource. + AuthCheckInterval uint32 `json:"auth_check_interval,omitempty"` +} + +type EndpointOAuthProvider struct { + // configuration for using github as the identity provider + Github *EndpointOAuthGitHub `json:"github,omitempty"` + // configuration for using facebook as the identity provider + Facebook *EndpointOAuthFacebook `json:"facebook,omitempty"` + // configuration for using microsoft as the identity provider + Microsoft *EndpointOAuthMicrosoft `json:"microsoft,omitempty"` + // configuration for using google as the identity provider + Google *EndpointOAuthGoogle `json:"google,omitempty"` +} + +type EndpointOAuthGitHub struct { + // the OAuth app client ID. retrieve it from the identity provider's dashboard + // where you created your own OAuth app. optional. if unspecified, ngrok will use + // its own managed oauth application which has additional restrictions. see the + // OAuth module docs for more details. if present, client_secret must be present as + // well. + ClientID *string `json:"client_id,omitempty"` + // the OAuth app client secret. retrieve if from the identity provider's dashboard + // where you created your own OAuth app. optional, see all of the caveats in the + // docs for client_id. + ClientSecret *string `json:"client_secret,omitempty"` + // a list of provider-specific OAuth scopes with the permissions your OAuth app + // would like to ask for. these may not be set if you are using the ngrok-managed + // oauth app (i.e. you must pass both client_id and client_secret to set scopes) + Scopes []string `json:"scopes,omitempty"` + // a list of email addresses of users authenticated by identity provider who are + // allowed access to the endpoint + EmailAddresses []string `json:"email_addresses,omitempty"` + // a list of email domains of users authenticated by identity provider who are + // allowed access to the endpoint + EmailDomains []string `json:"email_domains,omitempty"` + // a list of github teams identifiers. users will be allowed access to the endpoint + // if they are a member of any of these teams. identifiers should be in the 'slug' + // format qualified with the org name, e.g. org-name/team-name + Teams []string `json:"teams,omitempty"` + // a list of github org identifiers. users who are members of any of the listed + // organizations will be allowed access. identifiers should be the organization's + // 'slug' + Organizations []string `json:"organizations,omitempty"` +} + +type EndpointOAuthFacebook struct { + // the OAuth app client ID. retrieve it from the identity provider's dashboard + // where you created your own OAuth app. optional. if unspecified, ngrok will use + // its own managed oauth application which has additional restrictions. see the + // OAuth module docs for more details. if present, client_secret must be present as + // well. + ClientID *string `json:"client_id,omitempty"` + // the OAuth app client secret. retrieve if from the identity provider's dashboard + // where you created your own OAuth app. optional, see all of the caveats in the + // docs for client_id. + ClientSecret *string `json:"client_secret,omitempty"` + // a list of provider-specific OAuth scopes with the permissions your OAuth app + // would like to ask for. these may not be set if you are using the ngrok-managed + // oauth app (i.e. you must pass both client_id and client_secret to set scopes) + Scopes []string `json:"scopes,omitempty"` + // a list of email addresses of users authenticated by identity provider who are + // allowed access to the endpoint + EmailAddresses []string `json:"email_addresses,omitempty"` + // a list of email domains of users authenticated by identity provider who are + // allowed access to the endpoint + EmailDomains []string `json:"email_domains,omitempty"` +} + +type EndpointOAuthMicrosoft struct { + // the OAuth app client ID. retrieve it from the identity provider's dashboard + // where you created your own OAuth app. optional. if unspecified, ngrok will use + // its own managed oauth application which has additional restrictions. see the + // OAuth module docs for more details. if present, client_secret must be present as + // well. + ClientID *string `json:"client_id,omitempty"` + // the OAuth app client secret. retrieve if from the identity provider's dashboard + // where you created your own OAuth app. optional, see all of the caveats in the + // docs for client_id. + ClientSecret *string `json:"client_secret,omitempty"` + // a list of provider-specific OAuth scopes with the permissions your OAuth app + // would like to ask for. these may not be set if you are using the ngrok-managed + // oauth app (i.e. you must pass both client_id and client_secret to set scopes) + Scopes []string `json:"scopes,omitempty"` + // a list of email addresses of users authenticated by identity provider who are + // allowed access to the endpoint + EmailAddresses []string `json:"email_addresses,omitempty"` + // a list of email domains of users authenticated by identity provider who are + // allowed access to the endpoint + EmailDomains []string `json:"email_domains,omitempty"` +} + +type EndpointOAuthGoogle struct { + // the OAuth app client ID. retrieve it from the identity provider's dashboard + // where you created your own OAuth app. optional. if unspecified, ngrok will use + // its own managed oauth application which has additional restrictions. see the + // OAuth module docs for more details. if present, client_secret must be present as + // well. + ClientID *string `json:"client_id,omitempty"` + // the OAuth app client secret. retrieve if from the identity provider's dashboard + // where you created your own OAuth app. optional, see all of the caveats in the + // docs for client_id. + ClientSecret *string `json:"client_secret,omitempty"` + // a list of provider-specific OAuth scopes with the permissions your OAuth app + // would like to ask for. these may not be set if you are using the ngrok-managed + // oauth app (i.e. you must pass both client_id and client_secret to set scopes) + Scopes []string `json:"scopes,omitempty"` + // a list of email addresses of users authenticated by identity provider who are + // allowed access to the endpoint + EmailAddresses []string `json:"email_addresses,omitempty"` + // a list of email domains of users authenticated by identity provider who are + // allowed access to the endpoint + EmailDomains []string `json:"email_domains,omitempty"` +} + +type EndpointSAML struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // Do not enforce authentication on HTTP OPTIONS requests. necessary if you are + // supporting CORS. + OptionsPassthrough bool `json:"options_passthrough,omitempty"` + // the prefix of the session cookie that ngrok sets on the http client to cache + // authentication. default is 'ngrok.' + CookiePrefix string `json:"cookie_prefix,omitempty"` + // Integer number of seconds of inactivity after which if the user has not accessed + // the endpoint, their session will time out and they will be forced to + // reauthenticate. + InactivityTimeout uint32 `json:"inactivity_timeout,omitempty"` + // Integer number of seconds of the maximum duration of an authenticated session. + // After this period is exceeded, a user must reauthenticate. + MaximumDuration uint32 `json:"maximum_duration,omitempty"` + // The IdP's metadata URL which returns the XML IdP EntityDescriptor. The IdP's + // metadata URL specifies how to connect to the IdP as well as its public key which + // is then used to validate the signature on incoming SAML assertions to the ACS + // endpoint. + IdPMetadataURL string `json:"idp_metadata_url,omitempty"` + // The full XML IdP EntityDescriptor. Your IdP may provide this to you as a a file + // to download or as a URL. + IdPMetadata string `json:"idp_metadata,omitempty"` + // If true, indicates that whenever we redirect a user to the IdP for + // authentication that the IdP must prompt the user for authentication credentials + // even if the user already has a valid session with the IdP. + ForceAuthn bool `json:"force_authn,omitempty"` + // If true, the IdP may initiate a login directly (e.g. the user does not need to + // visit the endpoint first and then be redirected). The IdP should set the + // RelayState parameter to the target URL of the resource they want the user to be + // redirected to after the SAML login assertion has been processed. + AllowIdPInitiated *bool `json:"allow_idp_initiated,omitempty"` + // If present, only users who are a member of one of the listed groups may access + // the target endpoint. + AuthorizedGroups []string `json:"authorized_groups,omitempty"` + // The SP Entity's unique ID. This always takes the form of a URL. In ngrok's + // implementation, this URL is the same as the metadata URL. This will need to be + // specified to the IdP as configuration. + EntityID string `json:"entity_id,omitempty"` + // The public URL of the SP's Assertion Consumer Service. This is where the IdP + // will redirect to during an authentication flow. This will need to be specified + // to the IdP as configuration. + AssertionConsumerServiceURL string `json:"assertion_consumer_service_url,omitempty"` + // The public URL of the SP's Single Logout Service. This is where the IdP will + // redirect to during a single logout flow. This will optionally need to be + // specified to the IdP as configuration. + SingleLogoutURL string `json:"single_logout_url,omitempty"` + // PEM-encoded x.509 certificate of the key pair that is used to sign all SAML + // requests that the ngrok SP makes to the IdP. Many IdPs do not support request + // signing verification, but we highly recommend specifying this in the IdP's + // configuration if it is supported. + RequestSigningCertificatePEM string `json:"request_signing_certificate_pem,omitempty"` + // A public URL where the SP's metadata is hosted. If an IdP supports dynamic + // configuration, this is the URL it can use to retrieve the SP metadata. + MetadataURL string `json:"metadata_url,omitempty"` +} + +type EndpointSAMLMutate struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // Do not enforce authentication on HTTP OPTIONS requests. necessary if you are + // supporting CORS. + OptionsPassthrough bool `json:"options_passthrough,omitempty"` + // the prefix of the session cookie that ngrok sets on the http client to cache + // authentication. default is 'ngrok.' + CookiePrefix string `json:"cookie_prefix,omitempty"` + // Integer number of seconds of inactivity after which if the user has not accessed + // the endpoint, their session will time out and they will be forced to + // reauthenticate. + InactivityTimeout uint32 `json:"inactivity_timeout,omitempty"` + // Integer number of seconds of the maximum duration of an authenticated session. + // After this period is exceeded, a user must reauthenticate. + MaximumDuration uint32 `json:"maximum_duration,omitempty"` + // The IdP's metadata URL which returns the XML IdP EntityDescriptor. The IdP's + // metadata URL specifies how to connect to the IdP as well as its public key which + // is then used to validate the signature on incoming SAML assertions to the ACS + // endpoint. + IdPMetadataURL string `json:"idp_metadata_url,omitempty"` + // The full XML IdP EntityDescriptor. Your IdP may provide this to you as a a file + // to download or as a URL. + IdPMetadata string `json:"idp_metadata,omitempty"` + // If true, indicates that whenever we redirect a user to the IdP for + // authentication that the IdP must prompt the user for authentication credentials + // even if the user already has a valid session with the IdP. + ForceAuthn bool `json:"force_authn,omitempty"` + // If true, the IdP may initiate a login directly (e.g. the user does not need to + // visit the endpoint first and then be redirected). The IdP should set the + // RelayState parameter to the target URL of the resource they want the user to be + // redirected to after the SAML login assertion has been processed. + AllowIdPInitiated *bool `json:"allow_idp_initiated,omitempty"` + // If present, only users who are a member of one of the listed groups may access + // the target endpoint. + AuthorizedGroups []string `json:"authorized_groups,omitempty"` +} + +type EndpointOIDC struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // Do not enforce authentication on HTTP OPTIONS requests. necessary if you are + // supporting CORS. + OptionsPassthrough bool `json:"options_passthrough,omitempty"` + // the prefix of the session cookie that ngrok sets on the http client to cache + // authentication. default is 'ngrok.' + CookiePrefix string `json:"cookie_prefix,omitempty"` + // Integer number of seconds of inactivity after which if the user has not accessed + // the endpoint, their session will time out and they will be forced to + // reauthenticate. + InactivityTimeout uint32 `json:"inactivity_timeout,omitempty"` + // Integer number of seconds of the maximum duration of an authenticated session. + // After this period is exceeded, a user must reauthenticate. + MaximumDuration uint32 `json:"maximum_duration,omitempty"` + // URL of the OIDC "OpenID provider". This is the base URL used for discovery. + Issuer string `json:"issuer,omitempty"` + // The OIDC app's client ID and OIDC audience. + ClientID string `json:"client_id,omitempty"` + // The OIDC app's client secret. + ClientSecret string `json:"client_secret,omitempty"` + // The set of scopes to request from the OIDC identity provider. + Scopes []string `json:"scopes,omitempty"` +} + +type EndpointBackend struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // backend to be used to back this endpoint + Backend Ref `json:"backend,omitempty"` +} + +type EndpointBackendMutate struct { + // true if the module will be applied to traffic, false to disable. default true if + // unspecified + Enabled *bool `json:"enabled,omitempty"` + // backend to be used to back this endpoint + BackendID string `json:"backend_id,omitempty"` +} + +type EndpointLoggingReplace struct { + ID string `json:"id,omitempty"` + Module EndpointLoggingMutate `json:"module,omitempty"` +} + +type EndpointBasicAuthReplace struct { + ID string `json:"id,omitempty"` + Module EndpointBasicAuth `json:"module,omitempty"` +} + +type EndpointCircuitBreakerReplace struct { + ID string `json:"id,omitempty"` + Module EndpointCircuitBreaker `json:"module,omitempty"` +} + +type EndpointCompressionReplace struct { + ID string `json:"id,omitempty"` + Module EndpointCompression `json:"module,omitempty"` +} + +type EndpointTLSTerminationReplace struct { + ID string `json:"id,omitempty"` + Module EndpointTLSTermination `json:"module,omitempty"` +} + +type EndpointIPPolicyReplace struct { + ID string `json:"id,omitempty"` + Module EndpointIPPolicyMutate `json:"module,omitempty"` +} + +type EndpointMutualTLSReplace struct { + ID string `json:"id,omitempty"` + Module EndpointMutualTLSMutate `json:"module,omitempty"` +} + +type EndpointRequestHeadersReplace struct { + ID string `json:"id,omitempty"` + Module EndpointRequestHeaders `json:"module,omitempty"` +} + +type EndpointResponseHeadersReplace struct { + ID string `json:"id,omitempty"` + Module EndpointResponseHeaders `json:"module,omitempty"` +} + +type EndpointOAuthReplace struct { + ID string `json:"id,omitempty"` + Module EndpointOAuth `json:"module,omitempty"` +} + +type EndpointWebhookValidationReplace struct { + ID string `json:"id,omitempty"` + Module EndpointWebhookValidation `json:"module,omitempty"` +} + +type EndpointSAMLReplace struct { + ID string `json:"id,omitempty"` + Module EndpointSAMLMutate `json:"module,omitempty"` +} + +type EndpointOIDCReplace struct { + ID string `json:"id,omitempty"` + Module EndpointOIDC `json:"module,omitempty"` +} + +type EndpointBackendReplace struct { + ID string `json:"id,omitempty"` + Module EndpointBackendMutate `json:"module,omitempty"` +} + +type ReservedAddrCreate struct { + // human-readable description of what this reserved address will be used for + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this reserved address. Optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // reserve the address in this geographic ngrok datacenter. Optional, default is + // us. (au, eu, ap, us, jp, in, sa) + Region string `json:"region,omitempty"` + // ID of an endpoint configuration of type tcp that will be used to handle inbound + // traffic to this address + EndpointConfigurationID string `json:"endpoint_configuration_id,omitempty"` +} + +type ReservedAddrUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of what this reserved address will be used for + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this reserved address. Optional, + // max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // ID of an endpoint configuration of type tcp that will be used to handle inbound + // traffic to this address + EndpointConfigurationID *string `json:"endpoint_configuration_id,omitempty"` +} + +type ReservedAddr struct { + // unique reserved address resource identifier + ID string `json:"id,omitempty"` + // URI of the reserved address API resource + URI string `json:"uri,omitempty"` + // timestamp when the reserved address was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of what this reserved address will be used for + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this reserved address. Optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // hostname:port of the reserved address that was assigned at creation time + Addr string `json:"addr,omitempty"` + // reserve the address in this geographic ngrok datacenter. Optional, default is + // us. (au, eu, ap, us, jp, in, sa) + Region string `json:"region,omitempty"` + // object reference to the endpoint configuration that will be applied to traffic + // to this address + EndpointConfiguration *Ref `json:"endpoint_configuration,omitempty"` +} + +type ReservedAddrList struct { + // the list of all reserved addresses on this account + ReservedAddrs []ReservedAddr `json:"reserved_addrs,omitempty"` + // URI of the reserved address list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type ReservedDomainCreate struct { + // the domain name to reserve. It may be a full domain name like app.example.com. + // If the name does not contain a '.' it will reserve that subdomain on ngrok.io. + Name string `json:"name,omitempty"` + // reserve the domain in this geographic ngrok datacenter. Optional, default is us. + // (au, eu, ap, us, jp, in, sa) + Region string `json:"region,omitempty"` + // human-readable description of what this reserved domain will be used for + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this reserved domain. Optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // ID of an endpoint configuration of type http that will be used to handle inbound + // http traffic to this domain + HTTPEndpointConfigurationID string `json:"http_endpoint_configuration_id,omitempty"` + // ID of an endpoint configuration of type https that will be used to handle + // inbound https traffic to this domain + HTTPSEndpointConfigurationID string `json:"https_endpoint_configuration_id,omitempty"` + // ID of a user-uploaded TLS certificate to use for connections to targeting this + // domain. Optional, mutually exclusive with certificate_management_policy. + CertificateID *string `json:"certificate_id,omitempty"` + // configuration for automatic management of TLS certificates for this domain, or + // null if automatic management is disabled. Optional, mutually exclusive with + // certificate_id. + CertificateManagementPolicy *ReservedDomainCertPolicy `json:"certificate_management_policy,omitempty"` +} + +type ReservedDomainUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of what this reserved domain will be used for + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this reserved domain. Optional, + // max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // ID of an endpoint configuration of type http that will be used to handle inbound + // http traffic to this domain + HTTPEndpointConfigurationID *string `json:"http_endpoint_configuration_id,omitempty"` + // ID of an endpoint configuration of type https that will be used to handle + // inbound https traffic to this domain + HTTPSEndpointConfigurationID *string `json:"https_endpoint_configuration_id,omitempty"` + // ID of a user-uploaded TLS certificate to use for connections to targeting this + // domain. Optional, mutually exclusive with certificate_management_policy. + CertificateID *string `json:"certificate_id,omitempty"` + // configuration for automatic management of TLS certificates for this domain, or + // null if automatic management is disabled. Optional, mutually exclusive with + // certificate_id. + CertificateManagementPolicy *ReservedDomainCertPolicy `json:"certificate_management_policy,omitempty"` +} + +type ReservedDomain struct { + // unique reserved domain resource identifier + ID string `json:"id,omitempty"` + // URI of the reserved domain API resource + URI string `json:"uri,omitempty"` + // timestamp when the reserved domain was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of what this reserved domain will be used for + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this reserved domain. Optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // hostname of the reserved domain + Domain string `json:"domain,omitempty"` + // reserve the domain in this geographic ngrok datacenter. Optional, default is us. + // (au, eu, ap, us, jp, in, sa) + Region string `json:"region,omitempty"` + // DNS CNAME target for a custom hostname, or null if the reserved domain is a + // subdomain of *.ngrok.io + CNAMETarget *string `json:"cname_target,omitempty"` + // object referencing the endpoint configuration applied to http traffic on this + // domain + HTTPEndpointConfiguration *Ref `json:"http_endpoint_configuration,omitempty"` + // object referencing the endpoint configuration applied to https traffic on this + // domain + HTTPSEndpointConfiguration *Ref `json:"https_endpoint_configuration,omitempty"` + // object referencing the TLS certificate used for connections to this domain. This + // can be either a user-uploaded certificate, the most recently issued automatic + // one, or null otherwise. + Certificate *Ref `json:"certificate,omitempty"` + // configuration for automatic management of TLS certificates for this domain, or + // null if automatic management is disabled + CertificateManagementPolicy *ReservedDomainCertPolicy `json:"certificate_management_policy,omitempty"` + // status of the automatic certificate management for this domain, or null if + // automatic management is disabled + CertificateManagementStatus *ReservedDomainCertStatus `json:"certificate_management_status,omitempty"` +} + +type ReservedDomainList struct { + // the list of all reserved domains on this account + ReservedDomains []ReservedDomain `json:"reserved_domains,omitempty"` + // URI of the reserved domain list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +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. + PrivateKeyType string `json:"private_key_type,omitempty"` +} + +type ReservedDomainCertStatus struct { + // timestamp when the next renewal will be requested, RFC 3339 format + RenewsAt *string `json:"renews_at,omitempty"` + // status of the certificate provisioning job, or null if the certificiate isn't + // being provisioned or renewed + ProvisioningJob *ReservedDomainCertJob `json:"provisioning_job,omitempty"` +} + +type ReservedDomainCertNSTarget struct { + // the zone that the nameservers need to be applied to + Zone string `json:"zone,omitempty"` + // the nameservers the user must add + Nameservers []string `json:"nameservers,omitempty"` +} + +type ReservedDomainCertJob struct { + // if present, an error code indicating why provisioning is failing. It may be + // either a temporary condition (INTERNAL_ERROR), or a permanent one the user must + // correct (DNS_ERROR). + ErrorCode *string `json:"error_code,omitempty"` + // a message describing the current status or error + Msg string `json:"msg,omitempty"` + // timestamp when the provisioning job started, RFC 3339 format + StartedAt string `json:"started_at,omitempty"` + // timestamp when the provisioning job will be retried + RetriesAt *string `json:"retries_at,omitempty"` + // if present, indicates the dns nameservers that the user must configure to + // complete the provisioning process of a wildcard certificate + NSTargets []ReservedDomainCertNSTarget `json:"ns_targets,omitempty"` +} + +type RootResponse struct { + URI string `json:"uri,omitempty"` + SubresourceURIs map[string]string `json:"subresource_uris,omitempty"` +} + +type SSHCertificateAuthorityCreate struct { + // human-readable description of this SSH Certificate Authority. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH Certificate Authority. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // the type of private key to generate. one of rsa, ecdsa, ed25519 + PrivateKeyType string `json:"private_key_type,omitempty"` + // the type of elliptic curve to use when creating an ECDSA key + EllipticCurve string `json:"elliptic_curve,omitempty"` + // the key size to use when creating an RSA key. one of 2048 or 4096 + KeySize int64 `json:"key_size,omitempty"` +} + +type SSHCertificateAuthorityUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this SSH Certificate Authority. optional, max 255 + // bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH Certificate Authority. + // optional, max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` +} + +type SSHCertificateAuthority struct { + // unique identifier for this SSH Certificate Authority + ID string `json:"id,omitempty"` + // URI of the SSH Certificate Authority API resource + URI string `json:"uri,omitempty"` + // timestamp when the SSH Certificate Authority API resource was created, RFC 3339 + // format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this SSH Certificate Authority. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH Certificate Authority. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // raw public key for this SSH Certificate Authority + PublicKey string `json:"public_key,omitempty"` + // the type of private key for this SSH Certificate Authority + KeyType string `json:"key_type,omitempty"` +} + +type SSHCertificateAuthorityList struct { + // the list of all certificate authorities on this account + SSHCertificateAuthorities []SSHCertificateAuthority `json:"ssh_certificate_authorities,omitempty"` + // URI of the certificates authorities list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type SSHCredentialCreate struct { + // human-readable description of who or what will use the ssh credential to + // authenticate. Optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this ssh credential. Optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // optional list of ACL rules. If unspecified, the credential will have no + // restrictions. The only allowed ACL rule at this time is the bind rule. The bind + // rule allows the caller to restrict what domains and addresses the token is + // allowed to bind. For example, to allow the token to open a tunnel on + // example.ngrok.io your ACL would include the rule bind:example.ngrok.io. Bind + // rules may specify a leading wildcard to match multiple domains with a common + // suffix. For example, you may specify a rule of bind:*.example.com which will + // allow x.example.com, y.example.com, *.example.com, etc. A rule of '*' is + // equivalent to no acl at all and will explicitly permit all actions. + ACL []string `json:"acl,omitempty"` + // the PEM-encoded public key of the SSH keypair that will be used to authenticate + PublicKey string `json:"public_key,omitempty"` +} + +type SSHCredentialUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of who or what will use the ssh credential to + // authenticate. Optional, max 255 bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this ssh credential. Optional, + // max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` + // optional list of ACL rules. If unspecified, the credential will have no + // restrictions. The only allowed ACL rule at this time is the bind rule. The bind + // rule allows the caller to restrict what domains and addresses the token is + // allowed to bind. For example, to allow the token to open a tunnel on + // example.ngrok.io your ACL would include the rule bind:example.ngrok.io. Bind + // rules may specify a leading wildcard to match multiple domains with a common + // suffix. For example, you may specify a rule of bind:*.example.com which will + // allow x.example.com, y.example.com, *.example.com, etc. A rule of '*' is + // equivalent to no acl at all and will explicitly permit all actions. + ACL *[]string `json:"acl,omitempty"` +} + +type SSHCredential struct { + // unique ssh credential resource identifier + ID string `json:"id,omitempty"` + // URI of the ssh credential API resource + URI string `json:"uri,omitempty"` + // timestamp when the ssh credential was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of who or what will use the ssh credential to + // authenticate. Optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this ssh credential. Optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // the PEM-encoded public key of the SSH keypair that will be used to authenticate + PublicKey string `json:"public_key,omitempty"` + // optional list of ACL rules. If unspecified, the credential will have no + // restrictions. The only allowed ACL rule at this time is the bind rule. The bind + // rule allows the caller to restrict what domains and addresses the token is + // allowed to bind. For example, to allow the token to open a tunnel on + // example.ngrok.io your ACL would include the rule bind:example.ngrok.io. Bind + // rules may specify a leading wildcard to match multiple domains with a common + // suffix. For example, you may specify a rule of bind:*.example.com which will + // allow x.example.com, y.example.com, *.example.com, etc. A rule of '*' is + // equivalent to no acl at all and will explicitly permit all actions. + ACL []string `json:"acl,omitempty"` +} + +type SSHCredentialList struct { + // the list of all ssh credentials on this account + SSHCredentials []SSHCredential `json:"ssh_credentials,omitempty"` + // URI of the ssh credential list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type SSHHostCertificateCreate struct { + // the ssh certificate authority that is used to sign this ssh host certificate + SSHCertificateAuthorityID string `json:"ssh_certificate_authority_id,omitempty"` + // a public key in OpenSSH Authorized Keys format that this certificate signs + PublicKey string `json:"public_key,omitempty"` + // the list of principals included in the ssh host certificate. This is the list of + // hostnames and/or IP addresses that are authorized to serve SSH traffic with this + // certificate. Dangerously, if no principals are specified, this certificate is + // considered valid for all hosts. + Principals []string `json:"principals,omitempty"` + // The time when the host certificate becomes valid, in RFC 3339 format. Defaults + // to the current time if unspecified. + ValidAfter string `json:"valid_after,omitempty"` + // The time when this host certificate becomes invalid, in RFC 3339 format. If + // unspecified, a default value of one year in the future will be used. The OpenSSH + // certificates RFC calls this valid_before. + ValidUntil string `json:"valid_until,omitempty"` + // human-readable description of this SSH Host Certificate. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH Host Certificate. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` +} + +type SSHHostCertificateUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this SSH Host Certificate. optional, max 255 + // bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH Host Certificate. + // optional, max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` +} + +type SSHHostCertificate struct { + // unique identifier for this SSH Host Certificate + ID string `json:"id,omitempty"` + // URI of the SSH Host Certificate API resource + URI string `json:"uri,omitempty"` + // timestamp when the SSH Host Certificate API resource was created, RFC 3339 + // format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this SSH Host Certificate. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH Host Certificate. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // a public key in OpenSSH Authorized Keys format that this certificate signs + PublicKey string `json:"public_key,omitempty"` + // the key type of the public_key, one of rsa, ecdsa or ed25519 + KeyType string `json:"key_type,omitempty"` + // the ssh certificate authority that is used to sign this ssh host certificate + SSHCertificateAuthorityID string `json:"ssh_certificate_authority_id,omitempty"` + // the list of principals included in the ssh host certificate. This is the list of + // hostnames and/or IP addresses that are authorized to serve SSH traffic with this + // certificate. Dangerously, if no principals are specified, this certificate is + // considered valid for all hosts. + Principals []string `json:"principals,omitempty"` + // the time when the ssh host certificate becomes valid, in RFC 3339 format. + ValidAfter string `json:"valid_after,omitempty"` + // the time after which the ssh host certificate becomes invalid, in RFC 3339 + // format. the OpenSSH certificates RFC calls this valid_before. + ValidUntil string `json:"valid_until,omitempty"` + // the signed SSH certificate in OpenSSH Authorized Keys format. this value should + // be placed in a -cert.pub certificate file on disk that should be referenced in + // your sshd_config configuration file with a HostCertificate directive + Certificate string `json:"certificate,omitempty"` +} + +type SSHHostCertificateList struct { + // the list of all ssh host certificates on this account + SSHHostCertificates []SSHHostCertificate `json:"ssh_host_certificates,omitempty"` + // URI of the ssh host certificates list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type SSHUserCertificateCreate struct { + // the ssh certificate authority that is used to sign this ssh user certificate + SSHCertificateAuthorityID string `json:"ssh_certificate_authority_id,omitempty"` + // a public key in OpenSSH Authorized Keys format that this certificate signs + PublicKey string `json:"public_key,omitempty"` + // the list of principals included in the ssh user certificate. This is the list of + // usernames that the certificate holder may sign in as on a machine authorizinig + // the signing certificate authority. Dangerously, if no principals are specified, + // this certificate may be used to log in as any user. + Principals []string `json:"principals,omitempty"` + // A map of critical options included in the certificate. Only two critical options + // are currently defined by OpenSSH: force-command and source-address. See + // (https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.certkeys)the + // OpenSSH certificate protocol spec for additional details. + CriticalOptions map[string]string `json:"critical_options,omitempty"` + // A map of extensions included in the certificate. Extensions are additional + // metadata that can be interpreted by the SSH server for any purpose. These can be + // used to permit or deny the ability to open a terminal, do port forwarding, x11 + // forwarding, and more. If unspecified, the certificate will include limited + // permissions with the following extension map: {"permit-pty": "", + // "permit-user-rc": ""} OpenSSH understands a number of predefined extensions. See + // (https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.certkeys)the + // OpenSSH certificate protocol spec for additional details. + Extensions map[string]string `json:"extensions,omitempty"` + // The time when the user certificate becomes valid, in RFC 3339 format. Defaults + // to the current time if unspecified. + ValidAfter string `json:"valid_after,omitempty"` + // The time when this host certificate becomes invalid, in RFC 3339 format. If + // unspecified, a default value of 24 hours will be used. The OpenSSH certificates + // RFC calls this valid_before. + ValidUntil string `json:"valid_until,omitempty"` + // human-readable description of this SSH User Certificate. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH User Certificate. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` +} + +type SSHUserCertificateUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this SSH User Certificate. optional, max 255 + // bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH User Certificate. + // optional, max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` +} + +type SSHUserCertificate struct { + // unique identifier for this SSH User Certificate + ID string `json:"id,omitempty"` + // URI of the SSH User Certificate API resource + URI string `json:"uri,omitempty"` + // timestamp when the SSH User Certificate API resource was created, RFC 3339 + // format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this SSH User Certificate. optional, max 255 + // bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this SSH User Certificate. + // optional, max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // a public key in OpenSSH Authorized Keys format that this certificate signs + PublicKey string `json:"public_key,omitempty"` + // the key type of the public_key, one of rsa, ecdsa or ed25519 + KeyType string `json:"key_type,omitempty"` + // the ssh certificate authority that is used to sign this ssh user certificate + SSHCertificateAuthorityID string `json:"ssh_certificate_authority_id,omitempty"` + // the list of principals included in the ssh user certificate. This is the list of + // usernames that the certificate holder may sign in as on a machine authorizinig + // the signing certificate authority. Dangerously, if no principals are specified, + // this certificate may be used to log in as any user. + Principals []string `json:"principals,omitempty"` + // A map of critical options included in the certificate. Only two critical options + // are currently defined by OpenSSH: force-command and source-address. See + // (https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.certkeys)the + // OpenSSH certificate protocol spec for additional details. + CriticalOptions map[string]string `json:"critical_options,omitempty"` + // A map of extensions included in the certificate. Extensions are additional + // metadata that can be interpreted by the SSH server for any purpose. These can be + // used to permit or deny the ability to open a terminal, do port forwarding, x11 + // forwarding, and more. If unspecified, the certificate will include limited + // permissions with the following extension map: {"permit-pty": "", + // "permit-user-rc": ""} OpenSSH understands a number of predefined extensions. See + // (https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.certkeys)the + // OpenSSH certificate protocol spec for additional details. + Extensions map[string]string `json:"extensions,omitempty"` + // the time when the ssh host certificate becomes valid, in RFC 3339 format. + ValidAfter string `json:"valid_after,omitempty"` + // the time after which the ssh host certificate becomes invalid, in RFC 3339 + // format. the OpenSSH certificates RFC calls this valid_before. + ValidUntil string `json:"valid_until,omitempty"` + // the signed SSH certificate in OpenSSH Authorized Keys Format. this value should + // be placed in a -cert.pub certificate file on disk that should be referenced in + // your sshd_config configuration file with a HostCertificate directive + Certificate string `json:"certificate,omitempty"` +} + +type SSHUserCertificateList struct { + // the list of all ssh user certificates on this account + SSHUserCertificates []SSHUserCertificate `json:"ssh_user_certificates,omitempty"` + // URI of the ssh user certificates list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type TLSCertificateCreate struct { + // human-readable description of this TLS certificate. optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this TLS certificate. optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // chain of PEM-encoded certificates, leaf first. See + // (https://ngrok.com/docs/api#tls-certificates-pem)Certificate Bundles. + CertificatePEM string `json:"certificate_pem,omitempty"` + // private key for the TLS certificate, PEM-encoded. See + // (https://ngrok.com/docs/ngrok-link#tls-certificates-key)Private Keys. + PrivateKeyPEM string `json:"private_key_pem,omitempty"` +} + +type TLSCertificateUpdate struct { + ID string `json:"id,omitempty"` + // human-readable description of this TLS certificate. optional, max 255 bytes. + Description *string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this TLS certificate. optional, + // max 4096 bytes. + Metadata *string `json:"metadata,omitempty"` +} + +type TLSCertificate struct { + // unique identifier for this TLS certificate + ID string `json:"id,omitempty"` + // URI of the TLS certificate API resource + URI string `json:"uri,omitempty"` + // timestamp when the TLS certificate was created, RFC 3339 format + CreatedAt string `json:"created_at,omitempty"` + // human-readable description of this TLS certificate. optional, max 255 bytes. + Description string `json:"description,omitempty"` + // arbitrary user-defined machine-readable data of this TLS certificate. optional, + // max 4096 bytes. + Metadata string `json:"metadata,omitempty"` + // chain of PEM-encoded certificates, leaf first. See + // (https://ngrok.com/docs/api#tls-certificates-pem)Certificate Bundles. + CertificatePEM string `json:"certificate_pem,omitempty"` + // subject common name from the leaf of this TLS certificate + SubjectCommonName string `json:"subject_common_name,omitempty"` + // subject alternative names (SANs) from the leaf of this TLS certificate + SubjectAlternativeNames TLSCertificateSANs `json:"subject_alternative_names,omitempty"` + // timestamp (in RFC 3339 format) when this TLS certificate was issued + // automatically, or null if this certificate was user-uploaded + IssuedAt *string `json:"issued_at,omitempty"` + // timestamp when this TLS certificate becomes valid, RFC 3339 format + NotBefore string `json:"not_before,omitempty"` + // timestamp when this TLS certificate becomes invalid, RFC 3339 format + NotAfter string `json:"not_after,omitempty"` + // set of actions the private key of this TLS certificate can be used for + KeyUsages []string `json:"key_usages,omitempty"` + // extended set of actions the private key of this TLS certificate can be used for + ExtendedKeyUsages []string `json:"extended_key_usages,omitempty"` + // type of the private key of this TLS certificate. One of rsa, ecdsa, or ed25519. + PrivateKeyType string `json:"private_key_type,omitempty"` + // issuer common name from the leaf of this TLS certificate + IssuerCommonName string `json:"issuer_common_name,omitempty"` + // serial number of the leaf of this TLS certificate + SerialNumber string `json:"serial_number,omitempty"` + // subject organization from the leaf of this TLS certificate + SubjectOrganization string `json:"subject_organization,omitempty"` + // subject organizational unit from the leaf of this TLS certificate + SubjectOrganizationalUnit string `json:"subject_organizational_unit,omitempty"` + // subject locality from the leaf of this TLS certificate + SubjectLocality string `json:"subject_locality,omitempty"` + // subject province from the leaf of this TLS certificate + SubjectProvince string `json:"subject_province,omitempty"` + // subject country from the leaf of this TLS certificate + SubjectCountry string `json:"subject_country,omitempty"` +} + +type TLSCertificateList struct { + // the list of all TLS certificates on this account + TLSCertificates []TLSCertificate `json:"tls_certificates,omitempty"` + // URI of the TLS certificates list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type TLSCertificateSANs struct { + // set of additional domains (including wildcards) this TLS certificate is valid + // for + DNSNames []string `json:"dns_names,omitempty"` + // set of IP addresses this TLS certificate is also valid for + IPs []string `json:"ips,omitempty"` +} + +type TunnelSession struct { + // version of the ngrok agent that started this ngrok tunnel session + AgentVersion string `json:"agent_version,omitempty"` + // reference to the tunnel credential or ssh credential used by the ngrok agent to + // start this tunnel session + Credential Ref `json:"credential,omitempty"` + // unique tunnel session resource identifier + ID string `json:"id,omitempty"` + // source ip address of the tunnel session + IP string `json:"ip,omitempty"` + // arbitrary user-defined data specified in the metadata property in the ngrok + // configuration file. See the metadata configuration option + Metadata string `json:"metadata,omitempty"` + // operating system of the host the ngrok agent is running on + OS string `json:"os,omitempty"` + // the ngrok region identifier in which this tunnel session was started + Region string `json:"region,omitempty"` + // time when the tunnel session first connected to the ngrok servers + StartedAt string `json:"started_at,omitempty"` + // the transport protocol used to start the tunnel session. Either ngrok/v2 or ssh + Transport string `json:"transport,omitempty"` + // URI to the API resource of the tunnel session + URI string `json:"uri,omitempty"` +} + +type TunnelSessionList struct { + // list of all tunnel sessions on this account + TunnelSessions []TunnelSession `json:"tunnel_sessions,omitempty"` + // URI to the API resource of the tunnel session list + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} + +type TunnelSessionsUpdate struct { + ID string `json:"id,omitempty"` + // request that the ngrok agent update to this specific version instead of the + // latest available version + Version string `json:"version,omitempty"` +} + +type Tunnel struct { + // unique tunnel resource identifier + ID string `json:"id,omitempty"` + // URL of the tunnel's public endpoint + PublicURL string `json:"public_url,omitempty"` + // timestamp when the tunnel was initiated in RFC 3339 format + StartedAt string `json:"started_at,omitempty"` + // user-supplied metadata for the tunnel defined in the ngrok configuration file. + // See the tunnel (https://ngrok.com/docs#tunnel-definitions-metadata)metadata + // configuration option In API version 0, this value was instead pulled from the + // top-level (https://ngrok.com/docs#config_metadata)metadata configuration + // option. + Metadata string `json:"metadata,omitempty"` + // tunnel protocol. one of http, https, tcp or tls + Proto string `json:"proto,omitempty"` + // identifier of tune region where the tunnel is running + Region string `json:"region,omitempty"` + // reference object pointing to the tunnel session on which this tunnel was started + TunnelSession Ref `json:"tunnel_session,omitempty"` +} + +type TunnelList struct { + // the list of all online tunnels on this account + Tunnels []Tunnel `json:"tunnels,omitempty"` + // URI of the tunnels list API resource + URI string `json:"uri,omitempty"` + // URI of the next page, or null if there is no next page + NextPageURI *string `json:"next_page_uri,omitempty"` +} diff --git a/debug.go b/debug.go new file mode 100644 index 0000000..d8c10c5 --- /dev/null +++ b/debug.go @@ -0,0 +1,153 @@ +package ngrok + +import ( + "bytes" + "context" + "encoding/json" + "errors" + "fmt" + "io" + "io/ioutil" + "net/http" + "net/http/httptrace" + "strings" +) + +type Debug struct { + Stdout, Stderr io.Writer + Verbose bool + Include bool + DryRun bool +} + +// implements the io.TeeReader logic, but closes the writer when the reader +// completes +type teeReaderCloser struct { + r io.Reader + w io.WriteCloser + done <-chan struct{} +} + +func (r teeReaderCloser) Read(p []byte) (n int, err error) { + n, err = r.r.Read(p) + if n > 0 { + if n, err := r.w.Write(p[:n]); err != nil { + return n, err + } + } + if errors.Is(err, io.EOF) { + r.w.Close() + <-r.done + } + return n, err +} + +func (d Debug) makeRequest(ctx context.Context, body io.Reader) (context.Context, io.Reader) { + if (!d.Verbose && !d.DryRun) || d.Stderr == nil { + return ctx, body + } + + ctx = httptrace.WithClientTrace(ctx, &httptrace.ClientTrace{ + WroteHeaderField: func(key string, value []string) { + fmt.Fprintf(d.Stderr, "> %s: %s\n", key, value) + }, + WroteHeaders: func() { + fmt.Fprintln(d.Stderr) + }, + }) + + if body != nil { + ch := make(chan struct{}) + + pr, pw := io.Pipe() + body = teeReaderCloser{ + r: body, + w: pw, + done: ch, + } + + go func() { + defer close(ch) + decoder := json.NewDecoder(pr) + for decoder.More() { + var i interface{} + if err := decoder.Decode(&i); err == nil { + enc := json.NewEncoder(d.Stderr) + enc.SetIndent("", " ") + enc.Encode(i) + } + } + fmt.Fprintln(d.Stderr) + }() + } + + return ctx, body +} + +func (d Debug) printResponse(r *http.Response) { + if d.Stderr != nil { + // status + if d.Verbose { + fmt.Fprintf(d.Stderr, "Status: %s\n", r.Status) + } else { + fmt.Fprintln(d.Stderr, r.Status) + } + + // headers + if d.Verbose || d.Include { + fmt.Fprintln(d.Stderr) + for k, v := range r.Header { + fmt.Fprintf(d.Stderr, "< %s: %v\n", k, v) + } + fmt.Fprintln(d.Stderr) + } + } + + if d.Stdout != nil && (r.StatusCode < 400 || d.Verbose) { + body, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + r.Body = ioutil.NopCloser(bytes.NewReader(body)) + + var i interface{} + if err := json.Unmarshal(body, &i); err == nil { + enc := json.NewEncoder(d.Stdout) + enc.SetIndent("", " ") + enc.Encode(i) + } else { + fmt.Fprint(d.Stdout, string(body)) + } + } +} + +type eofReader struct{} + +func (eofReader) Read([]byte) (int, error) { + return 0, io.EOF +} + +func emptyHTTPResponse(req *http.Request) *http.Response { + return &http.Response{ + Body: ioutil.NopCloser(eofReader{}), + Header: http.Header{}, + Trailer: http.Header{}, + Request: req, + } +} + +func (d Debug) dryRunResponse(req *http.Request) (*http.Response, error) { + if d.Verbose && d.Stderr != nil { + fmt.Fprintf(d.Stderr, "> :authority: [%s]\n", req.URL.Hostname()) + fmt.Fprintf(d.Stderr, "> :method: [%s]\n", req.Method) + fmt.Fprintf(d.Stderr, "> :path: [%s]\n", req.URL.Path) + fmt.Fprintf(d.Stderr, "> :scheme: [%s]\n", req.URL.Scheme) + for k, v := range req.Header { + fmt.Fprintf(d.Stderr, "> %s: %s\n", strings.ToLower(k), v) + } + fmt.Fprintln(d.Stderr) + } + if req.Body != nil { + // if Verbose this causes the request to be printed to stderr + ioutil.ReadAll(req.Body) + } + return emptyHTTPResponse(req), nil +} diff --git a/endpoint_backend_module/client.go b/endpoint_backend_module/client.go new file mode 100644 index 0000000..e10e512 --- /dev/null +++ b/endpoint_backend_module/client.go @@ -0,0 +1,92 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_backend_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + id string, + +) (*ngrok.EndpointBackend, error) { + arg := &ngrok.EndpointBackendReplace{ID: id} + var res ngrok.EndpointBackend + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/backend")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointBackend, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointBackend + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/backend")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/backend")).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 +} diff --git a/endpoint_basic_auth_module/client.go b/endpoint_basic_auth_module/client.go new file mode 100644 index 0000000..3883c2d --- /dev/null +++ b/endpoint_basic_auth_module/client.go @@ -0,0 +1,92 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_basic_auth_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + id string, + +) (*ngrok.EndpointBasicAuth, error) { + arg := &ngrok.EndpointBasicAuthReplace{ID: id} + var res ngrok.EndpointBasicAuth + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/basic_auth")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointBasicAuth, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointBasicAuth + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/basic_auth")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/basic_auth")).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 +} diff --git a/endpoint_circuit_breaker_module/client.go b/endpoint_circuit_breaker_module/client.go new file mode 100644 index 0000000..26e105a --- /dev/null +++ b/endpoint_circuit_breaker_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_circuit_breaker_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointCircuitBreakerReplace, +) (*ngrok.EndpointCircuitBreaker, error) { + var res ngrok.EndpointCircuitBreaker + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/circuit_breaker")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointCircuitBreaker, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointCircuitBreaker + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/circuit_breaker")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/circuit_breaker")).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 +} diff --git a/endpoint_compression_module/client.go b/endpoint_compression_module/client.go new file mode 100644 index 0000000..1b3cfe0 --- /dev/null +++ b/endpoint_compression_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_compression_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointCompressionReplace, +) (*ngrok.EndpointCompression, error) { + var res ngrok.EndpointCompression + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/compression")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointCompression, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointCompression + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/compression")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/compression")).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 +} diff --git a/endpoint_configurations/client.go b/endpoint_configurations/client.go new file mode 100644 index 0000000..d09fc26 --- /dev/null +++ b/endpoint_configurations/client.go @@ -0,0 +1,214 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_configurations + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +// Endpoint Configuration managementAn +// (https://ngrok.com/docs/ngrok-link#api-endpoint-configurations)Endpoint +// Configuration describes +// a ngrok network endpoint instance.Endpoints are your gateway to ngrok features! + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new endpoint configuration +func (c *Client) Create( + ctx context.Context, + arg *ngrok.EndpointConfigurationCreate, +) (*ngrok.EndpointConfiguration, error) { + var res ngrok.EndpointConfiguration + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/endpoint_configurations")).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 +} + +// Delete an endpoint configuration. This operation will fail if the endpoint +// configuration is still referenced by any reserved domain or reserved address. +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("/endpoint_configurations/{{ .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 +} + +// Returns detailed information about an endpoint configuration +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointConfiguration, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointConfiguration + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// Returns a list of all endpoint configurations on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.EndpointConfigurationList, error) { + var res ngrok.EndpointConfigurationList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/endpoint_configurations")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.EndpointConfiguration + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.EndpointConfigurations + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.EndpointConfiguration { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Updates an endpoint configuration. If a module is not specified in the update, +// it will not be modified. However, each module configuration that is specified +// will completely replace the existing value. There is no way to delete an +// existing module via this API, instead use the delete module API. +func (c *Client) Update( + ctx context.Context, + arg *ngrok.EndpointConfigurationUpdate, +) (*ngrok.EndpointConfiguration, error) { + var res ngrok.EndpointConfiguration + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/endpoint_configurations/{{ .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 +} diff --git a/endpoint_ip_policy_module/client.go b/endpoint_ip_policy_module/client.go new file mode 100644 index 0000000..e50a3a1 --- /dev/null +++ b/endpoint_ip_policy_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_ip_policy_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointIPPolicyReplace, +) (*ngrok.EndpointIPPolicy, error) { + var res ngrok.EndpointIPPolicy + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/ip_policy")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointIPPolicy, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointIPPolicy + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/ip_policy")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/ip_policy")).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 +} diff --git a/endpoint_logging_module/client.go b/endpoint_logging_module/client.go new file mode 100644 index 0000000..2e9d551 --- /dev/null +++ b/endpoint_logging_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_logging_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointLoggingReplace, +) (*ngrok.EndpointLogging, error) { + var res ngrok.EndpointLogging + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/logging")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointLogging, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointLogging + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/logging")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/logging")).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 +} diff --git a/endpoint_mutual_tls_module/client.go b/endpoint_mutual_tls_module/client.go new file mode 100644 index 0000000..eb6b3d2 --- /dev/null +++ b/endpoint_mutual_tls_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_mutual_tls_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointMutualTLSReplace, +) (*ngrok.EndpointMutualTLS, error) { + var res ngrok.EndpointMutualTLS + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/mutual_tls")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointMutualTLS, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointMutualTLS + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/mutual_tls")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/mutual_tls")).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 +} diff --git a/endpoint_o_auth_module/client.go b/endpoint_o_auth_module/client.go new file mode 100644 index 0000000..a25fb70 --- /dev/null +++ b/endpoint_o_auth_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_o_auth_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointOAuthReplace, +) (*ngrok.EndpointOAuth, error) { + var res ngrok.EndpointOAuth + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/oauth")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointOAuth, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointOAuth + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/oauth")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/oauth")).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 +} diff --git a/endpoint_oidc_module/client.go b/endpoint_oidc_module/client.go new file mode 100644 index 0000000..3e9216e --- /dev/null +++ b/endpoint_oidc_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_oidc_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointOIDCReplace, +) (*ngrok.EndpointOIDC, error) { + var res ngrok.EndpointOIDC + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/oidc")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointOIDC, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointOIDC + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/oidc")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/oidc")).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 +} diff --git a/endpoint_request_headers_module/client.go b/endpoint_request_headers_module/client.go new file mode 100644 index 0000000..af7ec79 --- /dev/null +++ b/endpoint_request_headers_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_request_headers_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointRequestHeadersReplace, +) (*ngrok.EndpointRequestHeaders, error) { + var res ngrok.EndpointRequestHeaders + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/request_headers")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointRequestHeaders, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointRequestHeaders + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/request_headers")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/request_headers")).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 +} diff --git a/endpoint_response_headers_module/client.go b/endpoint_response_headers_module/client.go new file mode 100644 index 0000000..3740c58 --- /dev/null +++ b/endpoint_response_headers_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_response_headers_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointResponseHeadersReplace, +) (*ngrok.EndpointResponseHeaders, error) { + var res ngrok.EndpointResponseHeaders + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/response_headers")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointResponseHeaders, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointResponseHeaders + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/response_headers")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/response_headers")).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 +} diff --git a/endpoint_saml_module/client.go b/endpoint_saml_module/client.go new file mode 100644 index 0000000..e3af0f6 --- /dev/null +++ b/endpoint_saml_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_saml_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointSAMLReplace, +) (*ngrok.EndpointSAML, error) { + var res ngrok.EndpointSAML + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/saml")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointSAML, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointSAML + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/saml")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/saml")).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 +} diff --git a/endpoint_tls_termination_module/client.go b/endpoint_tls_termination_module/client.go new file mode 100644 index 0000000..409341c --- /dev/null +++ b/endpoint_tls_termination_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_tls_termination_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointTLSTerminationReplace, +) (*ngrok.EndpointTLSTermination, error) { + var res ngrok.EndpointTLSTermination + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/tls_termination")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointTLSTermination, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointTLSTermination + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/tls_termination")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/tls_termination")).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 +} diff --git a/endpoint_webhook_validation_module/client.go b/endpoint_webhook_validation_module/client.go new file mode 100644 index 0000000..f19fd4b --- /dev/null +++ b/endpoint_webhook_validation_module/client.go @@ -0,0 +1,90 @@ +// Code generated by apic. DO NOT EDIT. + +package endpoint_webhook_validation_module + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Replace( + ctx context.Context, + arg *ngrok.EndpointWebhookValidationReplace, +) (*ngrok.EndpointWebhookValidation, error) { + var res ngrok.EndpointWebhookValidation + var path bytes.Buffer + if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/webhook_validation")).Execute(&path, arg); err != nil { + panic(err) + } + arg.ID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + bodyArg = arg.Module + + if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EndpointWebhookValidation, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EndpointWebhookValidation + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/webhook_validation")).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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +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("/endpoint_configurations/{{ .ID }}/webhook_validation")).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 +} diff --git a/error.go b/error.go new file mode 100644 index 0000000..6f04c1a --- /dev/null +++ b/error.go @@ -0,0 +1,41 @@ +package ngrok + +import ( + "fmt" + "net/http" +) + +// Returns true if the error is a not found response from the ngrok API. +func IsNotFound(err error) bool { + if ee, ok := err.(*Error); ok { + return int(ee.StatusCode) == http.StatusNotFound + } + return false +} + +// Returns true if the given error is caused by any of the specified ngrok error codes. +func IsErrorCode(err error, codes ...int) bool { + if ee, ok := err.(*Error); ok { + for _, code := range codes { + if ee.ErrorCode == fmt.Sprintf("ERR_NGROK_%d", code) { + return true + } + } + } + return false +} + +func (e *Error) Error() string { + msg := fmt.Sprintf("HTTP %d: %s", e.StatusCode, e.Msg) + if e.ErrorCode != "" { + msg += fmt.Sprintf(" [%s]", e.ErrorCode) + } + if e.operationID() != "" { + msg += fmt.Sprintf("\n\nOperation ID: %s", e.operationID()) + } + return msg +} + +func (e *Error) operationID() string { + return e.Details["operation_id"] +} diff --git a/event_destinations/client.go b/event_destinations/client.go new file mode 100644 index 0000000..4e045b8 --- /dev/null +++ b/event_destinations/client.go @@ -0,0 +1,235 @@ +// Code generated by apic. DO NOT EDIT. + +package event_destinations + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new Event Destination. It will not apply to anything until it is +// associated with an Event Stream, and that Event Stream is associated with an +// Endpoint Config. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.EventDestinationCreate, +) (*ngrok.EventDestination, error) { + var res ngrok.EventDestination + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/event_destinations")).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 +} + +// Delete an Event Destination. If the Event Destination is still referenced by an +// Event Stream, this will throw an error until that Event Stream has removed that +// reference. +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("/event_destinations/{{ .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 +} + +// Get detailed information about an Event Destination by ID. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EventDestination, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EventDestination + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/event_destinations/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all Event Destinations on this account. +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.EventDestinationList, error) { + var res ngrok.EventDestinationList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/event_destinations")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.EventDestination + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.EventDestinations + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.EventDestination { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an Event Destination. +func (c *Client) Update( + ctx context.Context, + arg *ngrok.EventDestinationUpdate, +) (*ngrok.EventDestination, error) { + var res ngrok.EventDestination + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/event_destinations/{{ .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 +} + +// Send a test event to an Event Destination +func (c *Client) SendTestEvent( + ctx context.Context, + id string, + +) (*ngrok.SentEvent, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.SentEvent + var path bytes.Buffer + if err := template.Must(template.New("send_test_event_path").Parse("/event_destinations/{{ .ID }}/send_test_event")).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, "POST", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} diff --git a/event_sources/client.go b/event_sources/client.go new file mode 100644 index 0000000..76ecbda --- /dev/null +++ b/event_sources/client.go @@ -0,0 +1,141 @@ +// Code generated by apic. DO NOT EDIT. + +package event_sources + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// TODO +func (c *Client) Create( + ctx context.Context, + arg *ngrok.EventSourceCreate, +) (*ngrok.EventSource, error) { + var res ngrok.EventSource + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources")).Execute(&path, arg); err != nil { + panic(err) + } + arg.SubscriptionID = "" + 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 +} + +// TODO +func (c *Client) Delete( + ctx context.Context, + arg *ngrok.EventSourceItem, +) error { + var path bytes.Buffer + if err := template.Must(template.New("delete_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil { + panic(err) + } + arg.SubscriptionID = "" + arg.Type = "" + 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 +} + +// TODO +func (c *Client) Get( + ctx context.Context, + arg *ngrok.EventSourceItem, +) (*ngrok.EventSource, error) { + var res ngrok.EventSource + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil { + panic(err) + } + arg.SubscriptionID = "" + arg.Type = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// TODO +func (c *Client) List( + ctx context.Context, + subscriptionId string, + +) (*ngrok.EventSourceList, error) { + arg := &ngrok.EventSourcePage{SubscriptionID: subscriptionId} + var res ngrok.EventSourceList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources")).Execute(&path, arg); err != nil { + panic(err) + } + arg.SubscriptionID = "" + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// TODO +func (c *Client) Update( + ctx context.Context, + arg *ngrok.EventSourceUpdate, +) (*ngrok.EventSource, error) { + var res ngrok.EventSource + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil { + panic(err) + } + arg.SubscriptionID = "" + arg.Type = "" + 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 +} diff --git a/event_streams/client.go b/event_streams/client.go new file mode 100644 index 0000000..527d8b5 --- /dev/null +++ b/event_streams/client.go @@ -0,0 +1,206 @@ +// Code generated by apic. DO NOT EDIT. + +package event_streams + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new Event Stream. It will not apply to anything until you associate it +// with one or more Endpoint Configs. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.EventStreamCreate, +) (*ngrok.EventStream, error) { + var res ngrok.EventStream + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/event_streams")).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 +} + +// Delete an Event Stream. Associated Event Destinations will be preserved. +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("/event_streams/{{ .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 +} + +// Get detailed information about an Event Stream by ID. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EventStream, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EventStream + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/event_streams/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all Event Streams available on this account. +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.EventStreamList, error) { + var res ngrok.EventStreamList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/event_streams")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.EventStream + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.EventStreams + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.EventStream { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an Event Stream by ID. +func (c *Client) Update( + ctx context.Context, + arg *ngrok.EventStreamUpdate, +) (*ngrok.EventStream, error) { + var res ngrok.EventStream + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/event_streams/{{ .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 +} diff --git a/event_subscriptions/client.go b/event_subscriptions/client.go new file mode 100644 index 0000000..7a34c84 --- /dev/null +++ b/event_subscriptions/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package event_subscriptions + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create an Event Subscription. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.EventSubscriptionCreate, +) (*ngrok.EventSubscription, error) { + var res ngrok.EventSubscription + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/event_subscriptions")).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 +} + +// TODO +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("/event_subscriptions/{{ .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 +} + +// Get an Event Subscription by ID. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.EventSubscription, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.EventSubscription + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/event_subscriptions/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List this Account's Event Subscriptions. +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.EventSubscriptionList, error) { + var res ngrok.EventSubscriptionList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/event_subscriptions")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.EventSubscription + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.EventSubscriptions + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.EventSubscription { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// TODO +func (c *Client) Update( + ctx context.Context, + arg *ngrok.EventSubscriptionUpdate, +) (*ngrok.EventSubscription, error) { + var res ngrok.EventSubscription + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/event_subscriptions/{{ .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 +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bd6631f --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/ngrok/ngrok-api-go + +go 1.16 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/stretchr/testify v1.7.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect +) diff --git a/ip_policies/client.go b/ip_policies/client.go new file mode 100644 index 0000000..6f7eede --- /dev/null +++ b/ip_policies/client.go @@ -0,0 +1,208 @@ +// Code generated by apic. DO NOT EDIT. + +package ip_policies + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new IP policy. It will not apply to any traffic until you associate to +// a traffic source via an endpoint configuration or IP restriction. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.IPPolicyCreate, +) (*ngrok.IPPolicy, error) { + var res ngrok.IPPolicy + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/ip_policies")).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 +} + +// Delete an IP policy. If the IP policy is referenced by another object for the +// purposes of traffic restriction it will be treated as if the IP policy remains +// but has zero rules. +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("/ip_policies/{{ .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 +} + +// Get detailed information about an IP policy by ID. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.IPPolicy, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.IPPolicy + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/ip_policies/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all IP policies on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.IPPolicyList, error) { + var res ngrok.IPPolicyList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/ip_policies")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.IPPolicy + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.IPPolicies + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.IPPolicy { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an IP policy by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.IPPolicyUpdate, +) (*ngrok.IPPolicy, error) { + var res ngrok.IPPolicy + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/ip_policies/{{ .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 +} diff --git a/ip_policy_rules/client.go b/ip_policy_rules/client.go new file mode 100644 index 0000000..cf642a6 --- /dev/null +++ b/ip_policy_rules/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package ip_policy_rules + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new IP policy rule attached to an IP Policy. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.IPPolicyRuleCreate, +) (*ngrok.IPPolicyRule, error) { + var res ngrok.IPPolicyRule + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/ip_policy_rules")).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 +} + +// Delete an IP policy rule. +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("/ip_policy_rules/{{ .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 +} + +// Get detailed information about an IP policy rule by ID. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.IPPolicyRule, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.IPPolicyRule + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/ip_policy_rules/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all IP policy rules on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.IPPolicyRuleList, error) { + var res ngrok.IPPolicyRuleList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/ip_policy_rules")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.IPPolicyRule + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.IPPolicyRules + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.IPPolicyRule { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an IP policy rule by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.IPPolicyRuleUpdate, +) (*ngrok.IPPolicyRule, error) { + var res ngrok.IPPolicyRule + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/ip_policy_rules/{{ .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 +} diff --git a/ip_restrictions/client.go b/ip_restrictions/client.go new file mode 100644 index 0000000..c724a96 --- /dev/null +++ b/ip_restrictions/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package ip_restrictions + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new IP restriction +func (c *Client) Create( + ctx context.Context, + arg *ngrok.IPRestrictionCreate, +) (*ngrok.IPRestriction, error) { + var res ngrok.IPRestriction + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/ip_restrictions")).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 +} + +// Delete an IP restriction +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("/ip_restrictions/{{ .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 +} + +// Get detailed information about an IP restriction +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.IPRestriction, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.IPRestriction + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/ip_restrictions/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all IP restrictions on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.IPRestrictionList, error) { + var res ngrok.IPRestrictionList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/ip_restrictions")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.IPRestriction + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.IPRestrictions + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.IPRestriction { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an IP restriction by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.IPRestrictionUpdate, +) (*ngrok.IPRestriction, error) { + var res ngrok.IPRestriction + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/ip_restrictions/{{ .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 +} diff --git a/ip_whitelist/client.go b/ip_whitelist/client.go new file mode 100644 index 0000000..987fd41 --- /dev/null +++ b/ip_whitelist/client.go @@ -0,0 +1,206 @@ +// Code generated by apic. DO NOT EDIT. + +package ip_whitelist + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new IP whitelist entry that will restrict traffic to all tunnel +// endpoints on the account. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.IPWhitelistEntryCreate, +) (*ngrok.IPWhitelistEntry, error) { + var res ngrok.IPWhitelistEntry + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/ip_whitelist")).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 +} + +// Delete an IP whitelist entry. +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("/ip_whitelist/{{ .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 +} + +// Get detailed information about an IP whitelist entry by ID. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.IPWhitelistEntry, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.IPWhitelistEntry + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/ip_whitelist/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all IP whitelist entries on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.IPWhitelistEntryList, error) { + var res ngrok.IPWhitelistEntryList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/ip_whitelist")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.IPWhitelistEntry + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.Whitelist + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.IPWhitelistEntry { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an IP whitelist entry by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.IPWhitelistEntryUpdate, +) (*ngrok.IPWhitelistEntry, error) { + var res ngrok.IPWhitelistEntry + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/ip_whitelist/{{ .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 +} diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..23d1f60 --- /dev/null +++ b/main_test.go @@ -0,0 +1,64 @@ +package ngrok_test + +import ( + "context" + "testing" + + "github.com/ngrok/ngrok-api-go" + "github.com/ngrok/ngrok-api-go/ip_policies" + "github.com/stretchr/testify/require" +) + +func TestIPPolicy(t *testing.T) { + ctx := context.Background() + c, err := ngrok.NewClient() + require.NoError(t, err) + + policies := ip_policies.NewClient(c) + + // test that a list call works + _, err = policies.List(ctx, &ngrok.Page{}) + require.NoError(t, err) + + // test policy creation + createInstance, err := policies.Create(ctx, &ngrok.IPPolicyCreate{ + Action: "allow", + Description: "ngrok-api-go tests", + }) + require.NoError(t, err) + + // test get + getInstance, err := policies.Get(ctx, createInstance.ID) + require.NoError(t, err) + require.Equal(t, createInstance, getInstance) + + // test update + metadata := `{"device-id": "malamute-12"` + updatedInstance, err := policies.Update(ctx, &ngrok.IPPolicyUpdate{ + ID: createInstance.ID, + Metadata: ngrok.String(metadata), + }) + require.NoError(t, err) + require.Equal(t, updatedInstance.Metadata, metadata) + + // test get after update + getAfterUpdateInstance, err := policies.Get(ctx, createInstance.ID) + require.NoError(t, err) + require.Equal(t, updatedInstance, getAfterUpdateInstance) + + iter := policies.Iter(ctx) + var iterPolicies []*ngrok.IPPolicy + for iter.Next() { + iterPolicies = append(iterPolicies, iter.Item()) + } + require.NoError(t, iter.Err()) + require.Contains(t, iterPolicies, updatedInstance) + + // test delete + err = policies.Delete(ctx, createInstance.ID) + require.NoError(t, err) + + // test 404 + _, err = policies.Get(ctx, createInstance.ID) + require.True(t, ngrok.IsNotFound(err)) +} diff --git a/priority_backends/client.go b/priority_backends/client.go new file mode 100644 index 0000000..2baa284 --- /dev/null +++ b/priority_backends/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package priority_backends + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new Priority backend +func (c *Client) Create( + ctx context.Context, + arg *ngrok.PriorityBackendCreate, +) (*ngrok.PriorityBackend, error) { + var res ngrok.PriorityBackend + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/backends/priority")).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 +} + +// Delete a Priority backend by ID. TODO what if used? +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("/backends/priority/{{ .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 +} + +// Get detailed information about a Priority backend by ID +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.PriorityBackend, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.PriorityBackend + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/backends/priority/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all Priority backends on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.PriorityBackendList, error) { + var res ngrok.PriorityBackendList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/backends/priority")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.PriorityBackend + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.Backends + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.PriorityBackend { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update Priority backend by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.PriorityBackendUpdate, +) (*ngrok.PriorityBackend, error) { + var res ngrok.PriorityBackend + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/backends/priority/{{ .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 +} diff --git a/reserved_addrs/client.go b/reserved_addrs/client.go new file mode 100644 index 0000000..4ceb626 --- /dev/null +++ b/reserved_addrs/client.go @@ -0,0 +1,229 @@ +// Code generated by apic. DO NOT EDIT. + +package reserved_addrs + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new reserved address. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.ReservedAddrCreate, +) (*ngrok.ReservedAddr, error) { + var res ngrok.ReservedAddr + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/reserved_addrs")).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 +} + +// Delete a reserved address. +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("/reserved_addrs/{{ .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 +} + +// Get the details of a reserved address. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.ReservedAddr, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.ReservedAddr + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/reserved_addrs/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all reserved addresses on this account. +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.ReservedAddrList, error) { + var res ngrok.ReservedAddrList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/reserved_addrs")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.ReservedAddr + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.ReservedAddrs + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.ReservedAddr { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update the attributes of a reserved address. +func (c *Client) Update( + ctx context.Context, + arg *ngrok.ReservedAddrUpdate, +) (*ngrok.ReservedAddr, error) { + var res ngrok.ReservedAddr + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/reserved_addrs/{{ .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 +} + +// Detach the endpoint configuration attached to a reserved address. +func (c *Client) DeleteEndpointConfig( + ctx context.Context, + id string, + +) error { + arg := &ngrok.Item{ID: id} + var path bytes.Buffer + if err := template.Must(template.New("delete_endpoint_config_path").Parse("/reserved_addrs/{{ .ID }}/endpoint_configuration")).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 +} diff --git a/reserved_domains/client.go b/reserved_domains/client.go new file mode 100644 index 0000000..89b5b1d --- /dev/null +++ b/reserved_domains/client.go @@ -0,0 +1,301 @@ +// Code generated by apic. DO NOT EDIT. + +package reserved_domains + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new reserved domain. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.ReservedDomainCreate, +) (*ngrok.ReservedDomain, error) { + var res ngrok.ReservedDomain + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/reserved_domains")).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 +} + +// Delete a reserved domain. +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("/reserved_domains/{{ .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 +} + +// Get the details of a reserved domain. +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.ReservedDomain, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.ReservedDomain + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/reserved_domains/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all reserved domains on this account. +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.ReservedDomainList, error) { + var res ngrok.ReservedDomainList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/reserved_domains")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.ReservedDomain + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.ReservedDomains + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.ReservedDomain { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update the attributes of a reserved domain. +func (c *Client) Update( + ctx context.Context, + arg *ngrok.ReservedDomainUpdate, +) (*ngrok.ReservedDomain, error) { + var res ngrok.ReservedDomain + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/reserved_domains/{{ .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 +} + +// Detach the certificate management policy attached to a reserved domain. +func (c *Client) DeleteCertificateManagementPolicy( + ctx context.Context, + id string, + +) error { + arg := &ngrok.Item{ID: id} + var path bytes.Buffer + if err := template.Must(template.New("delete_certificate_management_policy_path").Parse("/reserved_domains/{{ .ID }}/certificate_management_policy")).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 +} + +// Detach the certificate attached to a reserved domain. +func (c *Client) DeleteCertificate( + ctx context.Context, + id string, + +) error { + arg := &ngrok.Item{ID: id} + var path bytes.Buffer + if err := template.Must(template.New("delete_certificate_path").Parse("/reserved_domains/{{ .ID }}/certificate")).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 +} + +// Detach the http endpoint configuration attached to a reserved domain. +func (c *Client) DeleteHTTPEndpointConfig( + ctx context.Context, + id string, + +) error { + arg := &ngrok.Item{ID: id} + var path bytes.Buffer + if err := template.Must(template.New("delete_http_endpoint_config_path").Parse("/reserved_domains/{{ .ID }}/http_endpoint_configuration")).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 +} + +// Detach the https endpoint configuration attached to a reserved domain. +func (c *Client) DeleteHTTPSEndpointConfig( + ctx context.Context, + id string, + +) error { + arg := &ngrok.Item{ID: id} + var path bytes.Buffer + if err := template.Must(template.New("delete_https_endpoint_config_path").Parse("/reserved_domains/{{ .ID }}/https_endpoint_configuration")).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 +} diff --git a/root/client.go b/root/client.go new file mode 100644 index 0000000..39533f3 --- /dev/null +++ b/root/client.go @@ -0,0 +1,41 @@ +// Code generated by apic. DO NOT EDIT. + +package root + +import ( + "bytes" + "context" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +func (c *Client) Get( + ctx context.Context, + arg *ngrok.Empty, +) (*ngrok.RootResponse, error) { + var res ngrok.RootResponse + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} diff --git a/ssh_certificate_authorities/client.go b/ssh_certificate_authorities/client.go new file mode 100644 index 0000000..29345b7 --- /dev/null +++ b/ssh_certificate_authorities/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package ssh_certificate_authorities + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new SSH Certificate Authority +func (c *Client) Create( + ctx context.Context, + arg *ngrok.SSHCertificateAuthorityCreate, +) (*ngrok.SSHCertificateAuthority, error) { + var res ngrok.SSHCertificateAuthority + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/ssh_certificate_authorities")).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 +} + +// Delete an SSH Certificate Authority +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("/ssh_certificate_authorities/{{ .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 +} + +// Get detailed information about an SSH Certficate Authority +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.SSHCertificateAuthority, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.SSHCertificateAuthority + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/ssh_certificate_authorities/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all SSH Certificate Authorities on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.SSHCertificateAuthorityList, error) { + var res ngrok.SSHCertificateAuthorityList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/ssh_certificate_authorities")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.SSHCertificateAuthority + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.SSHCertificateAuthorities + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.SSHCertificateAuthority { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update an SSH Certificate Authority +func (c *Client) Update( + ctx context.Context, + arg *ngrok.SSHCertificateAuthorityUpdate, +) (*ngrok.SSHCertificateAuthority, error) { + var res ngrok.SSHCertificateAuthority + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/ssh_certificate_authorities/{{ .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 +} diff --git a/ssh_credentials/client.go b/ssh_credentials/client.go new file mode 100644 index 0000000..b9b0969 --- /dev/null +++ b/ssh_credentials/client.go @@ -0,0 +1,206 @@ +// Code generated by apic. DO NOT EDIT. + +package ssh_credentials + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new ssh_credential from an uploaded public SSH key. This ssh credential +// can be used to start new tunnels via ngrok's SSH gateway. +func (c *Client) Create( + ctx context.Context, + arg *ngrok.SSHCredentialCreate, +) (*ngrok.SSHCredential, error) { + var res ngrok.SSHCredential + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/ssh_credentials")).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 +} + +// Delete an ssh_credential by ID +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("/ssh_credentials/{{ .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 +} + +// Get detailed information about an ssh_credential +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.SSHCredential, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.SSHCredential + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/ssh_credentials/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all ssh credentials on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.SSHCredentialList, error) { + var res ngrok.SSHCredentialList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/ssh_credentials")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.SSHCredential + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.SSHCredentials + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.SSHCredential { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of an ssh_credential by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.SSHCredentialUpdate, +) (*ngrok.SSHCredential, error) { + var res ngrok.SSHCredential + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/ssh_credentials/{{ .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 +} diff --git a/ssh_host_certificates/client.go b/ssh_host_certificates/client.go new file mode 100644 index 0000000..2008b1b --- /dev/null +++ b/ssh_host_certificates/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package ssh_host_certificates + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new SSH Host Certificate +func (c *Client) Create( + ctx context.Context, + arg *ngrok.SSHHostCertificateCreate, +) (*ngrok.SSHHostCertificate, error) { + var res ngrok.SSHHostCertificate + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/ssh_host_certificates")).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 +} + +// Delete an SSH Host Certificate +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("/ssh_host_certificates/{{ .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 +} + +// Get detailed information about an SSH Host Certficate +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.SSHHostCertificate, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.SSHHostCertificate + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/ssh_host_certificates/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all SSH Host Certificates issued on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.SSHHostCertificateList, error) { + var res ngrok.SSHHostCertificateList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/ssh_host_certificates")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.SSHHostCertificate + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.SSHHostCertificates + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.SSHHostCertificate { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update an SSH Host Certificate +func (c *Client) Update( + ctx context.Context, + arg *ngrok.SSHHostCertificateUpdate, +) (*ngrok.SSHHostCertificate, error) { + var res ngrok.SSHHostCertificate + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/ssh_host_certificates/{{ .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 +} diff --git a/ssh_user_certificates/client.go b/ssh_user_certificates/client.go new file mode 100644 index 0000000..254e227 --- /dev/null +++ b/ssh_user_certificates/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package ssh_user_certificates + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new SSH User Certificate +func (c *Client) Create( + ctx context.Context, + arg *ngrok.SSHUserCertificateCreate, +) (*ngrok.SSHUserCertificate, error) { + var res ngrok.SSHUserCertificate + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/ssh_user_certificates")).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 +} + +// Delete an SSH User Certificate +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("/ssh_user_certificates/{{ .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 +} + +// Get detailed information about an SSH User Certficate +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.SSHUserCertificate, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.SSHUserCertificate + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/ssh_user_certificates/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all SSH User Certificates issued on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.SSHUserCertificateList, error) { + var res ngrok.SSHUserCertificateList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/ssh_user_certificates")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.SSHUserCertificate + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.SSHUserCertificates + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.SSHUserCertificate { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update an SSH User Certificate +func (c *Client) Update( + ctx context.Context, + arg *ngrok.SSHUserCertificateUpdate, +) (*ngrok.SSHUserCertificate, error) { + var res ngrok.SSHUserCertificate + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/ssh_user_certificates/{{ .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 +} diff --git a/static_backends/client.go b/static_backends/client.go new file mode 100644 index 0000000..77c6765 --- /dev/null +++ b/static_backends/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package static_backends + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new static backend +func (c *Client) Create( + ctx context.Context, + arg *ngrok.StaticBackendCreate, +) (*ngrok.StaticBackend, error) { + var res ngrok.StaticBackend + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/backends/static")).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 +} + +// Delete a static backend by ID. TODO what if used? +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("/backends/static/{{ .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 +} + +// Get detailed information about a static backend by ID +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.StaticBackend, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.StaticBackend + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/backends/static/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all static backends on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.StaticBackendList, error) { + var res ngrok.StaticBackendList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/backends/static")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.StaticBackend + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.Backends + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.StaticBackend { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update static backend by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.StaticBackendUpdate, +) (*ngrok.StaticBackend, error) { + var res ngrok.StaticBackend + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/backends/static/{{ .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 +} diff --git a/tls_certificates/client.go b/tls_certificates/client.go new file mode 100644 index 0000000..368f92a --- /dev/null +++ b/tls_certificates/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package tls_certificates + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Upload a new TLS certificate +func (c *Client) Create( + ctx context.Context, + arg *ngrok.TLSCertificateCreate, +) (*ngrok.TLSCertificate, error) { + var res ngrok.TLSCertificate + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/tls_certificates")).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 +} + +// Delete a TLS certificate +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("/tls_certificates/{{ .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 +} + +// Get detailed information about a TLS certificate +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.TLSCertificate, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.TLSCertificate + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/tls_certificates/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all TLS certificates on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.TLSCertificateList, error) { + var res ngrok.TLSCertificateList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/tls_certificates")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.TLSCertificate + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.TLSCertificates + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.TLSCertificate { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update attributes of a TLS Certificate by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.TLSCertificateUpdate, +) (*ngrok.TLSCertificate, error) { + var res ngrok.TLSCertificate + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/tls_certificates/{{ .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 +} diff --git a/tunnel_group_backends/client.go b/tunnel_group_backends/client.go new file mode 100644 index 0000000..a3ee80a --- /dev/null +++ b/tunnel_group_backends/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package tunnel_group_backends + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new TunnelGroup backend +func (c *Client) Create( + ctx context.Context, + arg *ngrok.TunnelGroupBackendCreate, +) (*ngrok.TunnelGroupBackend, error) { + var res ngrok.TunnelGroupBackend + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/backends/tunnel-group")).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 +} + +// Delete a TunnelGroup backend by ID. TODO what if used? +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("/backends/tunnel-group/{{ .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 +} + +// Get detailed information about a TunnelGroup backend by ID +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.TunnelGroupBackend, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.TunnelGroupBackend + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/backends/tunnel-group/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all TunnelGroup backends on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.TunnelGroupBackendList, error) { + var res ngrok.TunnelGroupBackendList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/backends/tunnel-group")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.TunnelGroupBackend + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.Backends + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.TunnelGroupBackend { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update TunnelGroup backend by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.TunnelGroupBackendUpdate, +) (*ngrok.TunnelGroupBackend, error) { + var res ngrok.TunnelGroupBackend + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/backends/tunnel-group/{{ .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 +} diff --git a/tunnel_sessions/client.go b/tunnel_sessions/client.go new file mode 100644 index 0000000..7318b05 --- /dev/null +++ b/tunnel_sessions/client.go @@ -0,0 +1,224 @@ +// Code generated by apic. DO NOT EDIT. + +package tunnel_sessions + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// List all online tunnel sessions running on this account. +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.TunnelSessionList, error) { + var res ngrok.TunnelSessionList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/tunnel_sessions")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.TunnelSession + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.TunnelSessions + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.TunnelSession { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Get the detailed status of a tunnel session by ID +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.TunnelSession, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.TunnelSession + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/tunnel_sessions/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// Issues a command instructing the ngrok agent to restart. The agent restarts +// itself by calling exec() on platforms that support it. This operation is notably +// not supported on Windows. When an agent restarts, it reconnects with a new +// tunnel session ID. +func (c *Client) Restart( + ctx context.Context, + id string, + +) error { + arg := &ngrok.Item{ID: id} + var path bytes.Buffer + if err := template.Must(template.New("restart_path").Parse("/tunnel_sessions/{{ .ID }}/restart")).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, "POST", apiURL, bodyArg, nil); err != nil { + return err + } + return nil +} + +// Issues a command instructing the ngrok agent that started this tunnel session to +// exit. +func (c *Client) Stop( + ctx context.Context, + id string, + +) error { + arg := &ngrok.Item{ID: id} + var path bytes.Buffer + if err := template.Must(template.New("stop_path").Parse("/tunnel_sessions/{{ .ID }}/stop")).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, "POST", apiURL, bodyArg, nil); err != nil { + return err + } + return nil +} + +// Issues a command instructing the ngrok agent to update itself to the latest +// version. After this call completes successfully, the ngrok agent will be in the +// update process. A caller should wait some amount of time to allow the update to +// complete (at least 10 seconds) before making a call to the Restart endpoint to +// request that the agent restart itself to start using the new code. This call +// will never update an ngrok agent to a new major version which could cause +// breaking compatibility issues. If you wish to update to a new major version, +// that must be done manually. Still, please be aware that updating your ngrok +// agent could break your integration. This call will fail in any of the following +// circumstances: there is no update available the ngrok agent's configuration +// disabled update checks the agent is currently in process of updating the agent +// has already successfully updated but has not yet been restarted +func (c *Client) Update( + ctx context.Context, + id string, + +) error { + arg := &ngrok.TunnelSessionsUpdate{ID: id} + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/tunnel_sessions/{{ .ID }}/update")).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, "POST", apiURL, bodyArg, nil); err != nil { + return err + } + return nil +} diff --git a/tunnels/client.go b/tunnels/client.go new file mode 100644 index 0000000..7b028ad --- /dev/null +++ b/tunnels/client.go @@ -0,0 +1,109 @@ +// Code generated by apic. DO NOT EDIT. + +package tunnels + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// List all online tunnels currently running on the account. +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.TunnelList, error) { + var res ngrok.TunnelList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/tunnels")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.Tunnel + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.Tunnels + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.Tunnel { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} diff --git a/type_helpers.go b/type_helpers.go new file mode 100644 index 0000000..4138384 --- /dev/null +++ b/type_helpers.go @@ -0,0 +1,15 @@ +// Code generated by apic. DO NOT EDIT. + +package ngrok + +func Bool(v bool) *bool { + return &v +} + +func String(s string) *string { + return &s +} + +func Uint32(v uint32) *uint32 { + return &v +} diff --git a/weighted_backends/client.go b/weighted_backends/client.go new file mode 100644 index 0000000..ee748e4 --- /dev/null +++ b/weighted_backends/client.go @@ -0,0 +1,205 @@ +// Code generated by apic. DO NOT EDIT. + +package weighted_backends + +import ( + "bytes" + "context" + "fmt" + "net/url" + "text/template" + + "github.com/ngrok/ngrok-api-go" +) + +type Client struct { + apiClient *ngrok.Client +} + +func NewClient(apiClient *ngrok.Client) *Client { + return &Client{apiClient: apiClient} +} + +// Create a new Weighted backend +func (c *Client) Create( + ctx context.Context, + arg *ngrok.WeightedBackendCreate, +) (*ngrok.WeightedBackend, error) { + var res ngrok.WeightedBackend + var path bytes.Buffer + if err := template.Must(template.New("create_path").Parse("/backends/weighted")).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 +} + +// Delete a Weighted backend by ID. TODO what if used? +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("/backends/weighted/{{ .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 +} + +// Get detailed information about a Weighted backend by ID +func (c *Client) Get( + ctx context.Context, + id string, + +) (*ngrok.WeightedBackend, error) { + arg := &ngrok.Item{ID: id} + var res ngrok.WeightedBackend + var path bytes.Buffer + if err := template.Must(template.New("get_path").Parse("/backends/weighted/{{ .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, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +// List all Weighted backends on this account +func (c *Client) List( + ctx context.Context, + arg *ngrok.Page, +) (*ngrok.WeightedBackendList, error) { + var res ngrok.WeightedBackendList + var path bytes.Buffer + if err := template.Must(template.New("list_path").Parse("/backends/weighted")).Execute(&path, arg); err != nil { + panic(err) + } + var ( + apiURL = &url.URL{Path: path.String()} + bodyArg interface{} + ) + apiURL.Path = path.String() + queryVals := make(url.Values) + if arg.BeforeID != nil { + queryVals.Set("before_id", *arg.BeforeID) + } + if arg.Limit != nil { + queryVals.Set("limit", *arg.Limit) + } + apiURL.RawQuery = queryVals.Encode() + + if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *Client) Iter(ctx context.Context) *Iter { + return &Iter{ + client: c, + ctx: ctx, + limit: 100, + n: -1, + } +} + +type Iter struct { + client *Client + ctx context.Context + n int + limit int + items []ngrok.WeightedBackend + err error +} + +func (it *Iter) Next() bool { + // no more if there is an error + if it.err != nil { + return false + } + + // are there items remaining? + if it.n < len(it.items)-1 { + it.n += 1 + return true + } + + // fetch the next page + lastItemID := "" + if it.n > 0 { + lastItemID = it.items[it.n].ID + } + fmt.Println("lastItemID", lastItemID, "n", it.n) + resp, err := it.client.List(it.ctx, &ngrok.Page{ + BeforeID: ngrok.String(lastItemID), + Limit: ngrok.String(fmt.Sprintf("%d", it.limit)), + }) + if err != nil { + it.err = err + return false + } + it.n = 0 + it.items = resp.Backends + fmt.Println(len(it.items), it.items) + return len(it.items) > 0 +} + +func (it *Iter) Item() *ngrok.WeightedBackend { + return &it.items[it.n] +} + +func (it *Iter) Err() error { + return it.err +} + +// Update Weighted backend by ID +func (c *Client) Update( + ctx context.Context, + arg *ngrok.WeightedBackendUpdate, +) (*ngrok.WeightedBackend, error) { + var res ngrok.WeightedBackend + var path bytes.Buffer + if err := template.Must(template.New("update_path").Parse("/backends/weighted/{{ .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 +}