diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c130837 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2021 ngrok, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..587c8f9 --- /dev/null +++ b/README.md @@ -0,0 +1,77 @@ +# ngrok API client library for Golang + +This library wraps the [ngrok HTTP API](https://ngrok.com/docs/api) to make it +easier to consume in Go. + +## Installation + +Installation is as simple as using `go get`. + + go get github.com/ngrok/ngrok-api/go + +## Documentation + +A quickstart guide and a full API reference are included in the [ngrok go API documentation on pkg.go.dev](https://github.com/ngrok/ngrok-api-go) + +## Quickstart + +Please consult the [documentation](https://github.com/ngrok/ngrok-api-go) for additional examples. + +### Create an IP Policy that allows traffic from some subnets + +```go +import ( + "github.com/ngrok/ngrok-api-go" + "github.com/ngrok/ngrok-api-go/ip_policy" + "github.com/ngrok/ngrok-api-go/ip_policy_rules" +) + +func example(ctx context.Context) error { + // create clients to api resources + apiClient := ngrok.NewClient("") + policies := ip_policies.NewClient(apiClient) + policyRules := ip_policy_rules.NewClient(apiClient) + + // create the ip policy + policy, err := ng.ip_policies.create(ctx, &ngrok.IPPolicyCreate{ + Action: "allow", + }) + if err != nil { + return err + } + + // create rules for each cidr + for _, cidr := range []string{"24.0.0.0/8", "12.0.0.0/8"} { + policyRules.Create(ctx, &ngrok.IPPolicyRuleCreate{ + CIDR: cidr, + IPPolicyID: policy.ID, + }) + } + return nil +} +``` + +### List all online tunnels + +```go +import ( + "github.com/ngrok/ngrok-api-go" + "github.com/ngrok/ngrok-api-go/tunnels" +) + +func example(ctx context.Context) error { + // construct the api client + apiClient := ngrok.NewClient("") + + // list all online tunnels + tunnels := tunnels.NewClient(apiClient) + iter := tunnels.List(ctx, nil) + for iter.Next() { + fmt.Println(iter.Item()) + } + if err := iter.Err(); err != nil { + return err + } + return nil +} +``` diff --git a/abuse_reports/client.go b/abuse_reports/client.go index 88bcd9e..f6730b7 100644 --- a/abuse_reports/client.go +++ b/abuse_reports/client.go @@ -23,6 +23,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // 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) { @@ -46,11 +47,13 @@ func (c *Client) Create( // 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 { diff --git a/api_keys/client.go b/api_keys/client.go index f79c34a..e78a079 100644 --- a/api_keys/client.go +++ b/api_keys/client.go @@ -5,7 +5,6 @@ package api_keys import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -23,9 +22,13 @@ func NewClient(apiClient *ngrok.Client) *Client { // 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) { + if arg == nil { + arg = new(ngrok.APIKeyCreate) + } var res ngrok.APIKey var path bytes.Buffer if err := template.Must(template.New("create_path").Parse("/api_keys")).Execute(&path, arg); err != nil { @@ -46,11 +49,13 @@ func (c *Client) Create( // 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) @@ -70,11 +75,13 @@ func (c *Client) Delete( // 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 { @@ -94,10 +101,13 @@ func (c *Client) Get( } // List all API keys owned by this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.APIKeyList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.APIKeyList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/api_keys")).Execute(&path, arg); err != nil { @@ -123,24 +133,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all API keys owned by this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.APIKey - err error + client *Client + ctx context.Context + n int + items []ngrok.APIKey + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -150,18 +173,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -169,23 +188,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.Keys - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the APIKey currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.APIKey { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.APIKeyUpdate) + } 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 { diff --git a/certificate_authorities/client.go b/certificate_authorities/client.go index 16ad424..79e42de 100644 --- a/certificate_authorities/client.go +++ b/certificate_authorities/client.go @@ -5,7 +5,6 @@ package certificate_authorities import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // Upload a new Certificate Authority func (c *Client) Create( + ctx context.Context, arg *ngrok.CertificateAuthorityCreate, ) (*ngrok.CertificateAuthority, error) { @@ -45,11 +45,13 @@ func (c *Client) Create( // 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) @@ -69,11 +71,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +97,13 @@ func (c *Client) Get( } // List all Certificate Authority on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.CertificateAuthorityList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.CertificateAuthorityList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/certificate_authorities")).Execute(&path, arg); err != nil { @@ -122,24 +129,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all Certificate Authority on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.CertificateAuthority - err error + client *Client + ctx context.Context + n int + items []ngrok.CertificateAuthority + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +169,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +184,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.CertificateAuthorities - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the CertificateAuthority currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.CertificateAuthority { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.CertificateAuthorityUpdate) + } 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 { diff --git a/client.go b/client.go index 08d54f4..335c109 100644 --- a/client.go +++ b/client.go @@ -18,15 +18,16 @@ const ( ) type Client struct { - cfg *clientConfig + cfg *clientConfig + apiKey string } -func NewClient(opts ...ClientOption) (*Client, error) { +func NewClient(apiKey string, opts ...ClientOption) (*Client, error) { var cfg clientConfig if err := cfg.parseOptions(opts); err != nil { return nil, err } - return &Client{cfg: &cfg}, nil + return &Client{apiKey: apiKey, cfg: &cfg}, nil } func (c *Client) Do(ctx context.Context, method string, reqURL *url.URL, reqBody interface{}, respBody interface{}) error { @@ -55,8 +56,8 @@ func (c *Client) buildRequest(ctx context.Context, method string, reqURL *url.UR 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("authorization", fmt.Sprintf("Bearer %s", c.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") diff --git a/config.go b/config.go index cae2566..c80dbd5 100644 --- a/config.go +++ b/config.go @@ -3,7 +3,6 @@ package ngrok import ( "net/http" "net/url" - "os" ) var ( @@ -11,9 +10,7 @@ var ( ) type clientConfig struct { - apiKey string baseURL *url.URL - debug Debug httpClient *http.Client err error } @@ -35,15 +32,6 @@ func (c *clientConfig) setDefaults() { 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 { @@ -52,12 +40,6 @@ func WithBaseURL(baseURL string) ClientOption { } } -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 index f619ec1..9db4fbc 100644 --- a/credentials/client.go +++ b/credentials/client.go @@ -5,7 +5,6 @@ package credentials import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -25,9 +24,13 @@ func NewClient(apiClient *ngrok.Client) *Client { // 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) { + if arg == nil { + arg = new(ngrok.CredentialCreate) + } var res ngrok.Credential var path bytes.Buffer if err := template.Must(template.New("create_path").Parse("/credentials")).Execute(&path, arg); err != nil { @@ -48,11 +51,13 @@ func (c *Client) Create( // 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) @@ -72,11 +77,13 @@ func (c *Client) Delete( // 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 { @@ -96,10 +103,13 @@ func (c *Client) Get( } // List all tunnel authtoken credentials on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.CredentialList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.CredentialList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/credentials")).Execute(&path, arg); err != nil { @@ -125,24 +135,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all tunnel authtoken credentials on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.Credential - err error + client *Client + ctx context.Context + n int + items []ngrok.Credential + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -152,18 +175,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -171,23 +190,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.Credentials - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the Credential currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.Credential { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.CredentialUpdate) + } var res ngrok.Credential var path bytes.Buffer if err := template.Must(template.New("update_path").Parse("/credentials/{{ .ID }}")).Execute(&path, arg); err != nil { diff --git a/datatypes.go b/datatypes.go index 28d9003..97625c2 100644 --- a/datatypes.go +++ b/datatypes.go @@ -2,19 +2,68 @@ package ngrok +import ( + "bytes" + "fmt" + "text/tabwriter" +) + type Empty struct { } +func (x *Empty) String() string { + return x.GoString() +} + +func (x *Empty) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "Empty {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type Item struct { // a resource identifier ID string `json:"id,omitempty"` } -type Page struct { +func (x *Item) String() string { + return fmt.Sprintf("Item{ID: %v}", x.ID) + +} + +func (x *Item) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "Item {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + +type Paging struct { BeforeID *string `json:"before_id,omitempty"` Limit *string `json:"limit,omitempty"` } +func (x *Paging) String() string { + return x.GoString() +} + +func (x *Paging) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "Paging {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tBeforeID\t%v\n", x.BeforeID) + fmt.Fprintf(tw, "\tLimit\t%v\n", x.Limit) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type Error struct { ErrorCode string `json:"error_code,omitempty"` StatusCode int32 `json:"status_code,omitempty"` @@ -22,6 +71,23 @@ type Error struct { Details map[string]string `json:"details,omitempty"` } +func (x *Error) String() string { + return x.GoString() +} + +func (x *Error) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "Error {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tErrorCode\t%v\n", x.ErrorCode) + fmt.Fprintf(tw, "\tStatusCode\t%v\n", x.StatusCode) + fmt.Fprintf(tw, "\tMsg\t%v\n", x.Msg) + fmt.Fprintf(tw, "\tDetails\t%v\n", x.Details) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type Ref struct { // a resource identifier ID string `json:"id,omitempty"` @@ -29,6 +95,22 @@ type Ref struct { URI string `json:"uri,omitempty"` } +func (x *Ref) String() string { + return fmt.Sprintf("Ref{ID: %v}", x.ID) + +} + +func (x *Ref) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "Ref {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type AbuseReport struct { // ID of the abuse report ID string `json:"id,omitempty"` @@ -47,6 +129,27 @@ type AbuseReport struct { Hostnames []AbuseReportHostname `json:"hostnames,omitempty"` } +func (x *AbuseReport) String() string { + return fmt.Sprintf("AbuseReport{ID: %v}", x.ID) + +} + +func (x *AbuseReport) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "AbuseReport {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tURLs\t%v\n", x.URLs) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tStatus\t%v\n", x.Status) + fmt.Fprintf(tw, "\tHostnames\t%v\n", x.Hostnames) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type AbuseReportHostname struct { // the hostname ngrok has parsed out of one of the reported URLs in this abuse // report @@ -56,6 +159,21 @@ type AbuseReportHostname struct { Status string `json:"status,omitempty"` } +func (x *AbuseReportHostname) String() string { + return x.GoString() +} + +func (x *AbuseReportHostname) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "AbuseReportHostname {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tHostname\t%v\n", x.Hostname) + fmt.Fprintf(tw, "\tStatus\t%v\n", x.Status) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type AbuseReportCreate struct { // a list of URLs containing suspected abusive content URLs []string `json:"urls,omitempty"` @@ -63,6 +181,21 @@ type AbuseReportCreate struct { Metadata string `json:"metadata,omitempty"` } +func (x *AbuseReportCreate) String() string { + return x.GoString() +} + +func (x *AbuseReportCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "AbuseReportCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tURLs\t%v\n", x.URLs) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type APIKeyCreate struct { // human-readable description of what uses the API key to authenticate. optional, // max 255 bytes. @@ -71,6 +204,21 @@ type APIKeyCreate struct { Metadata string `json:"metadata,omitempty"` } +func (x *APIKeyCreate) String() string { + return x.GoString() +} + +func (x *APIKeyCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "APIKeyCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type APIKeyUpdate struct { ID string `json:"id,omitempty"` // human-readable description of what uses the API key to authenticate. optional, @@ -80,6 +228,23 @@ type APIKeyUpdate struct { Metadata *string `json:"metadata,omitempty"` } +func (x *APIKeyUpdate) String() string { + return fmt.Sprintf("APIKeyUpdate{ID: %v}", x.ID) + +} + +func (x *APIKeyUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "APIKeyUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type APIKey struct { // unique API key resource identifier ID string `json:"id,omitempty"` @@ -98,6 +263,26 @@ type APIKey struct { Token *string `json:"token,omitempty"` } +func (x *APIKey) String() string { + return fmt.Sprintf("APIKey{ID: %v}", x.ID) + +} + +func (x *APIKey) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "APIKey {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tToken\t%v\n", x.Token) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type APIKeyList struct { // the list of API keys for this account Keys []APIKey `json:"keys,omitempty"` @@ -107,179 +292,20 @@ type APIKeyList struct { 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"` +func (x *APIKeyList) String() string { + return x.GoString() } -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"` +func (x *APIKeyList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "APIKeyList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tKeys\t%v\n", x.Keys) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type CertificateAuthorityCreate struct { @@ -293,6 +319,22 @@ type CertificateAuthorityCreate struct { CAPEM string `json:"ca_pem,omitempty"` } +func (x *CertificateAuthorityCreate) String() string { + return x.GoString() +} + +func (x *CertificateAuthorityCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "CertificateAuthorityCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCAPEM\t%v\n", x.CAPEM) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type CertificateAuthorityUpdate struct { ID string `json:"id,omitempty"` // human-readable description of this Certificate Authority. optional, max 255 @@ -303,6 +345,23 @@ type CertificateAuthorityUpdate struct { Metadata *string `json:"metadata,omitempty"` } +func (x *CertificateAuthorityUpdate) String() string { + return fmt.Sprintf("CertificateAuthorityUpdate{ID: %v}", x.ID) + +} + +func (x *CertificateAuthorityUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "CertificateAuthorityUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type CertificateAuthority struct { // unique identifier for this Certificate Authority ID string `json:"id,omitempty"` @@ -331,6 +390,31 @@ type CertificateAuthority struct { ExtendedKeyUsages []string `json:"extended_key_usages,omitempty"` } +func (x *CertificateAuthority) String() string { + return fmt.Sprintf("CertificateAuthority{ID: %v}", x.ID) + +} + +func (x *CertificateAuthority) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "CertificateAuthority {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCAPEM\t%v\n", x.CAPEM) + fmt.Fprintf(tw, "\tSubjectCommonName\t%v\n", x.SubjectCommonName) + fmt.Fprintf(tw, "\tNotBefore\t%v\n", x.NotBefore) + fmt.Fprintf(tw, "\tNotAfter\t%v\n", x.NotAfter) + fmt.Fprintf(tw, "\tKeyUsages\t%v\n", x.KeyUsages) + fmt.Fprintf(tw, "\tExtendedKeyUsages\t%v\n", x.ExtendedKeyUsages) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type CertificateAuthorityList struct { // the list of all certificate authorities on this account CertificateAuthorities []CertificateAuthority `json:"certificate_authorities,omitempty"` @@ -340,6 +424,22 @@ type CertificateAuthorityList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *CertificateAuthorityList) String() string { + return x.GoString() +} + +func (x *CertificateAuthorityList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "CertificateAuthorityList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tCertificateAuthorities\t%v\n", x.CertificateAuthorities) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type CredentialCreate struct { // human-readable description of who or what will use the credential to // authenticate. Optional, max 255 bytes. @@ -359,6 +459,22 @@ type CredentialCreate struct { ACL []string `json:"acl,omitempty"` } +func (x *CredentialCreate) String() string { + return x.GoString() +} + +func (x *CredentialCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "CredentialCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tACL\t%v\n", x.ACL) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type CredentialUpdate struct { ID string `json:"id,omitempty"` // human-readable description of who or what will use the credential to @@ -379,6 +495,24 @@ type CredentialUpdate struct { ACL *[]string `json:"acl,omitempty"` } +func (x *CredentialUpdate) String() string { + return fmt.Sprintf("CredentialUpdate{ID: %v}", x.ID) + +} + +func (x *CredentialUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "CredentialUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tACL\t%v\n", x.ACL) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type Credential struct { // unique tunnel credential resource identifier ID string `json:"id,omitempty"` @@ -408,6 +542,27 @@ type Credential struct { ACL []string `json:"acl,omitempty"` } +func (x *Credential) String() string { + return fmt.Sprintf("Credential{ID: %v}", x.ID) + +} + +func (x *Credential) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "Credential {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tToken\t%v\n", x.Token) + fmt.Fprintf(tw, "\tACL\t%v\n", x.ACL) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type CredentialList struct { // the list of all tunnel credentials on this account Credentials []Credential `json:"credentials,omitempty"` @@ -417,6 +572,22 @@ type CredentialList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *CredentialList) String() string { + return x.GoString() +} + +func (x *CredentialList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "CredentialList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tCredentials\t%v\n", x.Credentials) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventStreamCreate struct { // Arbitrary user-defined machine-readable data of this Event Stream. Optional, max // 4096 bytes. @@ -436,6 +607,25 @@ type EventStreamCreate struct { SamplingRate float64 `json:"sampling_rate,omitempty"` } +func (x *EventStreamCreate) String() string { + return x.GoString() +} + +func (x *EventStreamCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventStreamCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tFields\t%v\n", x.Fields) + fmt.Fprintf(tw, "\tEventType\t%v\n", x.EventType) + fmt.Fprintf(tw, "\tDestinationIDs\t%v\n", x.DestinationIDs) + fmt.Fprintf(tw, "\tSamplingRate\t%v\n", x.SamplingRate) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventStreamUpdate struct { // Unique identifier for this Event Stream. ID string `json:"id,omitempty"` @@ -454,6 +644,26 @@ type EventStreamUpdate struct { SamplingRate *float64 `json:"sampling_rate,omitempty"` } +func (x *EventStreamUpdate) String() string { + return fmt.Sprintf("EventStreamUpdate{ID: %v}", x.ID) + +} + +func (x *EventStreamUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventStreamUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tFields\t%v\n", x.Fields) + fmt.Fprintf(tw, "\tDestinationIDs\t%v\n", x.DestinationIDs) + fmt.Fprintf(tw, "\tSamplingRate\t%v\n", x.SamplingRate) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventStreamList struct { // The list of all Event Streams on this account. EventStreams []EventStream `json:"event_streams,omitempty"` @@ -463,6 +673,22 @@ type EventStreamList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *EventStreamList) String() string { + return x.GoString() +} + +func (x *EventStreamList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventStreamList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEventStreams\t%v\n", x.EventStreams) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventStream struct { // Unique identifier for this Event Stream. ID string `json:"id,omitempty"` @@ -488,6 +714,29 @@ type EventStream struct { SamplingRate float64 `json:"sampling_rate,omitempty"` } +func (x *EventStream) String() string { + return fmt.Sprintf("EventStream{ID: %v}", x.ID) + +} + +func (x *EventStream) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventStream {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tFields\t%v\n", x.Fields) + fmt.Fprintf(tw, "\tEventType\t%v\n", x.EventType) + fmt.Fprintf(tw, "\tDestinationIDs\t%v\n", x.DestinationIDs) + fmt.Fprintf(tw, "\tSamplingRate\t%v\n", x.SamplingRate) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventDestinationCreate struct { // Arbitrary user-defined machine-readable data of this Event Destination. // Optional, max 4096 bytes. @@ -500,8 +749,24 @@ type EventDestinationCreate struct { // 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"` + Target EventTarget `json:"target,omitempty"` +} + +func (x *EventDestinationCreate) String() string { + return x.GoString() +} + +func (x *EventDestinationCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventDestinationCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tFormat\t%v\n", x.Format) + fmt.Fprintf(tw, "\tTarget\t%v\n", x.Target) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EventDestinationUpdate struct { @@ -518,8 +783,26 @@ type EventDestinationUpdate struct { // 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"` + Target *EventTarget `json:"target,omitempty"` +} + +func (x *EventDestinationUpdate) String() string { + return fmt.Sprintf("EventDestinationUpdate{ID: %v}", x.ID) + +} + +func (x *EventDestinationUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventDestinationUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tFormat\t%v\n", x.Format) + fmt.Fprintf(tw, "\tTarget\t%v\n", x.Target) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EventDestination struct { @@ -543,6 +826,27 @@ type EventDestination struct { URI string `json:"uri,omitempty"` } +func (x *EventDestination) String() string { + return fmt.Sprintf("EventDestination{ID: %v}", x.ID) + +} + +func (x *EventDestination) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventDestination {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tFormat\t%v\n", x.Format) + fmt.Fprintf(tw, "\tTarget\t%v\n", x.Target) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventDestinationList struct { // The list of all Event Destinations on this account. EventDestinations []EventDestination `json:"event_destinations,omitempty"` @@ -552,6 +856,22 @@ type EventDestinationList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *EventDestinationList) String() string { + return x.GoString() +} + +func (x *EventDestinationList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventDestinationList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEventDestinations\t%v\n", x.EventDestinations) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventTarget struct { // Configuration used to send events to Amazon Kinesis Data Firehose. Firehose *EventTargetFirehose `json:"firehose,omitempty"` @@ -559,8 +879,22 @@ type EventTarget struct { 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"` +} + +func (x *EventTarget) String() string { + return x.GoString() +} + +func (x *EventTarget) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventTarget {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tFirehose\t%v\n", x.Firehose) + fmt.Fprintf(tw, "\tKinesis\t%v\n", x.Kinesis) + fmt.Fprintf(tw, "\tCloudwatchLogs\t%v\n", x.CloudwatchLogs) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EventTargetFirehose struct { @@ -572,6 +906,21 @@ type EventTargetFirehose struct { DeliveryStreamARN string `json:"delivery_stream_arn,omitempty"` } +func (x *EventTargetFirehose) String() string { + return x.GoString() +} + +func (x *EventTargetFirehose) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventTargetFirehose {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tAuth\t%v\n", x.Auth) + fmt.Fprintf(tw, "\tDeliveryStreamARN\t%v\n", x.DeliveryStreamARN) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventTargetKinesis struct { // Configuration for how to authenticate into your AWS account. Exactly one of role // or creds should be configured. @@ -580,6 +929,21 @@ type EventTargetKinesis struct { StreamARN string `json:"stream_arn,omitempty"` } +func (x *EventTargetKinesis) String() string { + return x.GoString() +} + +func (x *EventTargetKinesis) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventTargetKinesis {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tAuth\t%v\n", x.Auth) + fmt.Fprintf(tw, "\tStreamARN\t%v\n", x.StreamARN) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EventTargetCloudwatchLogs struct { // Configuration for how to authenticate into your AWS account. Exactly one of role // or creds should be configured. @@ -589,27 +953,19 @@ type EventTargetCloudwatchLogs struct { 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"` +func (x *EventTargetCloudwatchLogs) String() string { + return x.GoString() } -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"` +func (x *EventTargetCloudwatchLogs) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EventTargetCloudwatchLogs {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tAuth\t%v\n", x.Auth) + fmt.Fprintf(tw, "\tLogGroupARN\t%v\n", x.LogGroupARN) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type AWSAuth struct { @@ -621,12 +977,41 @@ type AWSAuth struct { Creds *AWSCredentials `json:"creds,omitempty"` } +func (x *AWSAuth) String() string { + return x.GoString() +} + +func (x *AWSAuth) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "AWSAuth {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tRole\t%v\n", x.Role) + fmt.Fprintf(tw, "\tCreds\t%v\n", x.Creds) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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"` } +func (x *AWSRole) String() string { + return x.GoString() +} + +func (x *AWSRole) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "AWSRole {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tRoleARN\t%v\n", x.RoleARN) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type AWSCredentials struct { // The ID portion of an AWS access key. AWSAccessKeyID string `json:"aws_access_key_id,omitempty"` @@ -634,127 +1019,19 @@ type AWSCredentials struct { AWSSecretAccessKey *string `json:"aws_secret_access_key,omitempty"` } -type SentEvent struct { - EventID string `json:"event_id,omitempty"` +func (x *AWSCredentials) String() string { + return x.GoString() } -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"` +func (x *AWSCredentials) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "AWSCredentials {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tAWSAccessKeyID\t%v\n", x.AWSAccessKeyID) + fmt.Fprintf(tw, "\tAWSSecretAccessKey\t%v\n", x.AWSSecretAccessKey) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type IPPolicyCreate struct { @@ -768,6 +1045,22 @@ type IPPolicyCreate struct { Action string `json:"action,omitempty"` } +func (x *IPPolicyCreate) String() string { + return x.GoString() +} + +func (x *IPPolicyCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPPolicyCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tAction\t%v\n", x.Action) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPPolicyUpdate struct { ID string `json:"id,omitempty"` // human-readable description of the source IPs of this IP policy. optional, max @@ -778,6 +1071,23 @@ type IPPolicyUpdate struct { Metadata *string `json:"metadata,omitempty"` } +func (x *IPPolicyUpdate) String() string { + return fmt.Sprintf("IPPolicyUpdate{ID: %v}", x.ID) + +} + +func (x *IPPolicyUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPPolicyUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPPolicy struct { // unique identifier for this IP policy ID string `json:"id,omitempty"` @@ -795,6 +1105,26 @@ type IPPolicy struct { Action string `json:"action,omitempty"` } +func (x *IPPolicy) String() string { + return fmt.Sprintf("IPPolicy{ID: %v}", x.ID) + +} + +func (x *IPPolicy) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPPolicy {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tAction\t%v\n", x.Action) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPPolicyList struct { // the list of all IP policies on this account IPPolicies []IPPolicy `json:"ip_policies,omitempty"` @@ -804,6 +1134,22 @@ type IPPolicyList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *IPPolicyList) String() string { + return x.GoString() +} + +func (x *IPPolicyList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPPolicyList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tIPPolicies\t%v\n", x.IPPolicies) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPPolicyRuleCreate struct { // human-readable description of the source IPs of this IP rule. optional, max 255 // bytes. @@ -817,6 +1163,23 @@ type IPPolicyRuleCreate struct { IPPolicyID string `json:"ip_policy_id,omitempty"` } +func (x *IPPolicyRuleCreate) String() string { + return x.GoString() +} + +func (x *IPPolicyRuleCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPPolicyRuleCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCIDR\t%v\n", x.CIDR) + fmt.Fprintf(tw, "\tIPPolicyID\t%v\n", x.IPPolicyID) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPPolicyRuleUpdate struct { ID string `json:"id,omitempty"` // human-readable description of the source IPs of this IP rule. optional, max 255 @@ -829,6 +1192,24 @@ type IPPolicyRuleUpdate struct { CIDR *string `json:"cidr,omitempty"` } +func (x *IPPolicyRuleUpdate) String() string { + return fmt.Sprintf("IPPolicyRuleUpdate{ID: %v}", x.ID) + +} + +func (x *IPPolicyRuleUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPPolicyRuleUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCIDR\t%v\n", x.CIDR) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPPolicyRule struct { // unique identifier for this IP policy rule ID string `json:"id,omitempty"` @@ -848,6 +1229,27 @@ type IPPolicyRule struct { IPPolicy Ref `json:"ip_policy,omitempty"` } +func (x *IPPolicyRule) String() string { + return fmt.Sprintf("IPPolicyRule{ID: %v}", x.ID) + +} + +func (x *IPPolicyRule) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPPolicyRule {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCIDR\t%v\n", x.CIDR) + fmt.Fprintf(tw, "\tIPPolicy\t%v\n", x.IPPolicy) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPPolicyRuleList struct { // the list of all IP policy rules on this account IPPolicyRules []IPPolicyRule `json:"ip_policy_rules,omitempty"` @@ -857,6 +1259,22 @@ type IPPolicyRuleList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *IPPolicyRuleList) String() string { + return x.GoString() +} + +func (x *IPPolicyRuleList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPPolicyRuleList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tIPPolicyRules\t%v\n", x.IPPolicyRules) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPRestrictionCreate struct { // human-readable description of this IP restriction. optional, max 255 bytes. Description string `json:"description,omitempty"` @@ -874,6 +1292,24 @@ type IPRestrictionCreate struct { IPPolicyIDs []string `json:"ip_policy_ids,omitempty"` } +func (x *IPRestrictionCreate) String() string { + return x.GoString() +} + +func (x *IPRestrictionCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPRestrictionCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tEnforced\t%v\n", x.Enforced) + fmt.Fprintf(tw, "\tType\t%v\n", x.Type) + fmt.Fprintf(tw, "\tIPPolicyIDs\t%v\n", x.IPPolicyIDs) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPRestrictionUpdate struct { ID string `json:"id,omitempty"` // human-readable description of this IP restriction. optional, max 255 bytes. @@ -888,6 +1324,25 @@ type IPRestrictionUpdate struct { IPPolicyIDs []string `json:"ip_policy_ids,omitempty"` } +func (x *IPRestrictionUpdate) String() string { + return fmt.Sprintf("IPRestrictionUpdate{ID: %v}", x.ID) + +} + +func (x *IPRestrictionUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPRestrictionUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tEnforced\t%v\n", x.Enforced) + fmt.Fprintf(tw, "\tIPPolicyIDs\t%v\n", x.IPPolicyIDs) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPRestriction struct { // unique identifier for this IP restriction ID string `json:"id,omitempty"` @@ -911,6 +1366,28 @@ type IPRestriction struct { IPPolicies []Ref `json:"ip_policies,omitempty"` } +func (x *IPRestriction) String() string { + return fmt.Sprintf("IPRestriction{ID: %v}", x.ID) + +} + +func (x *IPRestriction) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPRestriction {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tEnforced\t%v\n", x.Enforced) + fmt.Fprintf(tw, "\tType\t%v\n", x.Type) + fmt.Fprintf(tw, "\tIPPolicies\t%v\n", x.IPPolicies) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPRestrictionList struct { // the list of all IP restrictions on this account IPRestrictions []IPRestriction `json:"ip_restrictions,omitempty"` @@ -920,6 +1397,22 @@ type IPRestrictionList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *IPRestrictionList) String() string { + return x.GoString() +} + +func (x *IPRestrictionList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPRestrictionList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tIPRestrictions\t%v\n", x.IPRestrictions) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPWhitelistEntryCreate struct { // human-readable description of the source IPs for this IP whitelist entry. // optional, max 255 bytes. @@ -933,6 +1426,22 @@ type IPWhitelistEntryCreate struct { IPNet string `json:"ip_net,omitempty"` } +func (x *IPWhitelistEntryCreate) String() string { + return x.GoString() +} + +func (x *IPWhitelistEntryCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPWhitelistEntryCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tIPNet\t%v\n", x.IPNet) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPWhitelistEntryUpdate struct { ID string `json:"id,omitempty"` // human-readable description of the source IPs for this IP whitelist entry. @@ -943,6 +1452,23 @@ type IPWhitelistEntryUpdate struct { Metadata *string `json:"metadata,omitempty"` } +func (x *IPWhitelistEntryUpdate) String() string { + return fmt.Sprintf("IPWhitelistEntryUpdate{ID: %v}", x.ID) + +} + +func (x *IPWhitelistEntryUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPWhitelistEntryUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPWhitelistEntry struct { // unique identifier for this IP whitelist entry ID string `json:"id,omitempty"` @@ -962,6 +1488,26 @@ type IPWhitelistEntry struct { IPNet string `json:"ip_net,omitempty"` } +func (x *IPWhitelistEntry) String() string { + return fmt.Sprintf("IPWhitelistEntry{ID: %v}", x.ID) + +} + +func (x *IPWhitelistEntry) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPWhitelistEntry {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tIPNet\t%v\n", x.IPNet) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type IPWhitelistEntryList struct { // the list of all IP whitelist entries on this account Whitelist []IPWhitelistEntry `json:"whitelist,omitempty"` @@ -971,6 +1517,22 @@ type IPWhitelistEntryList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *IPWhitelistEntryList) String() string { + return x.GoString() +} + +func (x *IPWhitelistEntryList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "IPWhitelistEntryList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tWhitelist\t%v\n", x.Whitelist) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointConfiguration struct { // unique identifier of this endpoint configuration ID string `json:"id,omitempty"` @@ -987,8 +1549,6 @@ type EndpointConfiguration struct { 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 @@ -1013,8 +1573,38 @@ type EndpointConfiguration struct { 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"` +} + +func (x *EndpointConfiguration) String() string { + return fmt.Sprintf("EndpointConfiguration{ID: %v}", x.ID) + +} + +func (x *EndpointConfiguration) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointConfiguration {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tType\t%v\n", x.Type) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCircuitBreaker\t%v\n", x.CircuitBreaker) + fmt.Fprintf(tw, "\tCompression\t%v\n", x.Compression) + fmt.Fprintf(tw, "\tRequestHeaders\t%v\n", x.RequestHeaders) + fmt.Fprintf(tw, "\tResponseHeaders\t%v\n", x.ResponseHeaders) + fmt.Fprintf(tw, "\tIPPolicy\t%v\n", x.IPPolicy) + fmt.Fprintf(tw, "\tMutualTLS\t%v\n", x.MutualTLS) + fmt.Fprintf(tw, "\tTLSTermination\t%v\n", x.TLSTermination) + fmt.Fprintf(tw, "\tWebhookValidation\t%v\n", x.WebhookValidation) + fmt.Fprintf(tw, "\tOAuth\t%v\n", x.OAuth) + fmt.Fprintf(tw, "\tLogging\t%v\n", x.Logging) + fmt.Fprintf(tw, "\tSAML\t%v\n", x.SAML) + fmt.Fprintf(tw, "\tOIDC\t%v\n", x.OIDC) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EndpointConfigurationList struct { @@ -1026,6 +1616,22 @@ type EndpointConfigurationList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *EndpointConfigurationList) String() string { + return x.GoString() +} + +func (x *EndpointConfigurationList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointConfigurationList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEndpointConfigurations\t%v\n", x.EndpointConfigurations) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointConfigurationUpdate struct { // unique identifier of this endpoint configuration ID string `json:"id,omitempty"` @@ -1035,8 +1641,6 @@ type EndpointConfigurationUpdate struct { // 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 @@ -1061,8 +1665,35 @@ type EndpointConfigurationUpdate struct { 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"` +} + +func (x *EndpointConfigurationUpdate) String() string { + return fmt.Sprintf("EndpointConfigurationUpdate{ID: %v}", x.ID) + +} + +func (x *EndpointConfigurationUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointConfigurationUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCircuitBreaker\t%v\n", x.CircuitBreaker) + fmt.Fprintf(tw, "\tCompression\t%v\n", x.Compression) + fmt.Fprintf(tw, "\tRequestHeaders\t%v\n", x.RequestHeaders) + fmt.Fprintf(tw, "\tResponseHeaders\t%v\n", x.ResponseHeaders) + fmt.Fprintf(tw, "\tIPPolicy\t%v\n", x.IPPolicy) + fmt.Fprintf(tw, "\tMutualTLS\t%v\n", x.MutualTLS) + fmt.Fprintf(tw, "\tTLSTermination\t%v\n", x.TLSTermination) + fmt.Fprintf(tw, "\tWebhookValidation\t%v\n", x.WebhookValidation) + fmt.Fprintf(tw, "\tOAuth\t%v\n", x.OAuth) + fmt.Fprintf(tw, "\tLogging\t%v\n", x.Logging) + fmt.Fprintf(tw, "\tSAML\t%v\n", x.SAML) + fmt.Fprintf(tw, "\tOIDC\t%v\n", x.OIDC) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EndpointConfigurationCreate struct { @@ -1075,8 +1706,6 @@ type EndpointConfigurationCreate struct { // 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 @@ -1101,8 +1730,34 @@ type EndpointConfigurationCreate struct { 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"` +} + +func (x *EndpointConfigurationCreate) String() string { + return x.GoString() +} + +func (x *EndpointConfigurationCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointConfigurationCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tType\t%v\n", x.Type) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCircuitBreaker\t%v\n", x.CircuitBreaker) + fmt.Fprintf(tw, "\tCompression\t%v\n", x.Compression) + fmt.Fprintf(tw, "\tRequestHeaders\t%v\n", x.RequestHeaders) + fmt.Fprintf(tw, "\tResponseHeaders\t%v\n", x.ResponseHeaders) + fmt.Fprintf(tw, "\tIPPolicy\t%v\n", x.IPPolicy) + fmt.Fprintf(tw, "\tMutualTLS\t%v\n", x.MutualTLS) + fmt.Fprintf(tw, "\tTLSTermination\t%v\n", x.TLSTermination) + fmt.Fprintf(tw, "\tWebhookValidation\t%v\n", x.WebhookValidation) + fmt.Fprintf(tw, "\tOAuth\t%v\n", x.OAuth) + fmt.Fprintf(tw, "\tLogging\t%v\n", x.Logging) + fmt.Fprintf(tw, "\tSAML\t%v\n", x.SAML) + fmt.Fprintf(tw, "\tOIDC\t%v\n", x.OIDC) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EndpointWebhookValidation struct { @@ -1118,12 +1773,42 @@ type EndpointWebhookValidation struct { Secret string `json:"secret,omitempty"` } +func (x *EndpointWebhookValidation) String() string { + return x.GoString() +} + +func (x *EndpointWebhookValidation) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointWebhookValidation {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tProvider\t%v\n", x.Provider) + fmt.Fprintf(tw, "\tSecret\t%v\n", x.Secret) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointCompression struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified Enabled *bool `json:"enabled,omitempty"` } +func (x *EndpointCompression) String() string { + return x.GoString() +} + +func (x *EndpointCompression) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointCompression {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointMutualTLS struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1133,6 +1818,21 @@ type EndpointMutualTLS struct { CertificateAuthorities []Ref `json:"certificate_authorities,omitempty"` } +func (x *EndpointMutualTLS) String() string { + return x.GoString() +} + +func (x *EndpointMutualTLS) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointMutualTLS {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tCertificateAuthorities\t%v\n", x.CertificateAuthorities) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointMutualTLSMutate struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1142,6 +1842,21 @@ type EndpointMutualTLSMutate struct { CertificateAuthorityIDs []string `json:"certificate_authority_ids,omitempty"` } +func (x *EndpointMutualTLSMutate) String() string { + return x.GoString() +} + +func (x *EndpointMutualTLSMutate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointMutualTLSMutate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tCertificateAuthorityIDs\t%v\n", x.CertificateAuthorityIDs) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointTLSTermination struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1157,20 +1872,20 @@ type EndpointTLSTermination struct { 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"` +func (x *EndpointTLSTermination) String() string { + return x.GoString() +} + +func (x *EndpointTLSTermination) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointTLSTermination {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tTerminateAt\t%v\n", x.TerminateAt) + fmt.Fprintf(tw, "\tMinVersion\t%v\n", x.MinVersion) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EndpointLogging struct { @@ -1182,6 +1897,21 @@ type EndpointLogging struct { EventStreams []Ref `json:"event_streams,omitempty"` } +func (x *EndpointLogging) String() string { + return x.GoString() +} + +func (x *EndpointLogging) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointLogging {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tEventStreams\t%v\n", x.EventStreams) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointLoggingMutate struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1191,6 +1921,21 @@ type EndpointLoggingMutate struct { EventStreamIDs []string `json:"event_stream_ids,omitempty"` } +func (x *EndpointLoggingMutate) String() string { + return x.GoString() +} + +func (x *EndpointLoggingMutate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointLoggingMutate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tEventStreamIDs\t%v\n", x.EventStreamIDs) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointRequestHeaders struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1203,6 +1948,22 @@ type EndpointRequestHeaders struct { Remove []string `json:"remove,omitempty"` } +func (x *EndpointRequestHeaders) String() string { + return x.GoString() +} + +func (x *EndpointRequestHeaders) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointRequestHeaders {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tAdd\t%v\n", x.Add) + fmt.Fprintf(tw, "\tRemove\t%v\n", x.Remove) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointResponseHeaders struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1215,6 +1976,22 @@ type EndpointResponseHeaders struct { Remove []string `json:"remove,omitempty"` } +func (x *EndpointResponseHeaders) String() string { + return x.GoString() +} + +func (x *EndpointResponseHeaders) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointResponseHeaders {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tAdd\t%v\n", x.Add) + fmt.Fprintf(tw, "\tRemove\t%v\n", x.Remove) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointIPPolicy struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1222,6 +1999,21 @@ type EndpointIPPolicy struct { IPPolicies []Ref `json:"ip_policies,omitempty"` } +func (x *EndpointIPPolicy) String() string { + return x.GoString() +} + +func (x *EndpointIPPolicy) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointIPPolicy {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tIPPolicies\t%v\n", x.IPPolicies) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointIPPolicyMutate struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1231,6 +2023,21 @@ type EndpointIPPolicyMutate struct { IPPolicyIDs []string `json:"ip_policy_ids,omitempty"` } +func (x *EndpointIPPolicyMutate) String() string { + return x.GoString() +} + +func (x *EndpointIPPolicyMutate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointIPPolicyMutate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tIPPolicyIDs\t%v\n", x.IPPolicyIDs) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointCircuitBreaker struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1250,6 +2057,25 @@ type EndpointCircuitBreaker struct { ErrorThresholdPercentage float64 `json:"error_threshold_percentage,omitempty"` } +func (x *EndpointCircuitBreaker) String() string { + return x.GoString() +} + +func (x *EndpointCircuitBreaker) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointCircuitBreaker {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tTrippedDuration\t%v\n", x.TrippedDuration) + fmt.Fprintf(tw, "\tRollingWindow\t%v\n", x.RollingWindow) + fmt.Fprintf(tw, "\tNumBuckets\t%v\n", x.NumBuckets) + fmt.Fprintf(tw, "\tVolumeThreshold\t%v\n", x.VolumeThreshold) + fmt.Fprintf(tw, "\tErrorThresholdPercentage\t%v\n", x.ErrorThresholdPercentage) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointOAuth struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1278,6 +2104,26 @@ type EndpointOAuth struct { AuthCheckInterval uint32 `json:"auth_check_interval,omitempty"` } +func (x *EndpointOAuth) String() string { + return x.GoString() +} + +func (x *EndpointOAuth) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOAuth {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tProvider\t%v\n", x.Provider) + fmt.Fprintf(tw, "\tOptionsPassthrough\t%v\n", x.OptionsPassthrough) + fmt.Fprintf(tw, "\tCookiePrefix\t%v\n", x.CookiePrefix) + fmt.Fprintf(tw, "\tInactivityTimeout\t%v\n", x.InactivityTimeout) + fmt.Fprintf(tw, "\tMaximumDuration\t%v\n", x.MaximumDuration) + fmt.Fprintf(tw, "\tAuthCheckInterval\t%v\n", x.AuthCheckInterval) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointOAuthProvider struct { // configuration for using github as the identity provider Github *EndpointOAuthGitHub `json:"github,omitempty"` @@ -1289,6 +2135,23 @@ type EndpointOAuthProvider struct { Google *EndpointOAuthGoogle `json:"google,omitempty"` } +func (x *EndpointOAuthProvider) String() string { + return x.GoString() +} + +func (x *EndpointOAuthProvider) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOAuthProvider {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tGithub\t%v\n", x.Github) + fmt.Fprintf(tw, "\tFacebook\t%v\n", x.Facebook) + fmt.Fprintf(tw, "\tMicrosoft\t%v\n", x.Microsoft) + fmt.Fprintf(tw, "\tGoogle\t%v\n", x.Google) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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 @@ -1320,6 +2183,26 @@ type EndpointOAuthGitHub struct { Organizations []string `json:"organizations,omitempty"` } +func (x *EndpointOAuthGitHub) String() string { + return x.GoString() +} + +func (x *EndpointOAuthGitHub) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOAuthGitHub {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tClientID\t%v\n", x.ClientID) + fmt.Fprintf(tw, "\tClientSecret\t%v\n", x.ClientSecret) + fmt.Fprintf(tw, "\tScopes\t%v\n", x.Scopes) + fmt.Fprintf(tw, "\tEmailAddresses\t%v\n", x.EmailAddresses) + fmt.Fprintf(tw, "\tEmailDomains\t%v\n", x.EmailDomains) + fmt.Fprintf(tw, "\tTeams\t%v\n", x.Teams) + fmt.Fprintf(tw, "\tOrganizations\t%v\n", x.Organizations) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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 @@ -1343,6 +2226,24 @@ type EndpointOAuthFacebook struct { EmailDomains []string `json:"email_domains,omitempty"` } +func (x *EndpointOAuthFacebook) String() string { + return x.GoString() +} + +func (x *EndpointOAuthFacebook) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOAuthFacebook {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tClientID\t%v\n", x.ClientID) + fmt.Fprintf(tw, "\tClientSecret\t%v\n", x.ClientSecret) + fmt.Fprintf(tw, "\tScopes\t%v\n", x.Scopes) + fmt.Fprintf(tw, "\tEmailAddresses\t%v\n", x.EmailAddresses) + fmt.Fprintf(tw, "\tEmailDomains\t%v\n", x.EmailDomains) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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 @@ -1366,6 +2267,24 @@ type EndpointOAuthMicrosoft struct { EmailDomains []string `json:"email_domains,omitempty"` } +func (x *EndpointOAuthMicrosoft) String() string { + return x.GoString() +} + +func (x *EndpointOAuthMicrosoft) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOAuthMicrosoft {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tClientID\t%v\n", x.ClientID) + fmt.Fprintf(tw, "\tClientSecret\t%v\n", x.ClientSecret) + fmt.Fprintf(tw, "\tScopes\t%v\n", x.Scopes) + fmt.Fprintf(tw, "\tEmailAddresses\t%v\n", x.EmailAddresses) + fmt.Fprintf(tw, "\tEmailDomains\t%v\n", x.EmailDomains) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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 @@ -1389,6 +2308,24 @@ type EndpointOAuthGoogle struct { EmailDomains []string `json:"email_domains,omitempty"` } +func (x *EndpointOAuthGoogle) String() string { + return x.GoString() +} + +func (x *EndpointOAuthGoogle) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOAuthGoogle {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tClientID\t%v\n", x.ClientID) + fmt.Fprintf(tw, "\tClientSecret\t%v\n", x.ClientSecret) + fmt.Fprintf(tw, "\tScopes\t%v\n", x.Scopes) + fmt.Fprintf(tw, "\tEmailAddresses\t%v\n", x.EmailAddresses) + fmt.Fprintf(tw, "\tEmailDomains\t%v\n", x.EmailDomains) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointSAML struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1406,11 +2343,6 @@ type EndpointSAML struct { // 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"` @@ -1448,6 +2380,33 @@ type EndpointSAML struct { MetadataURL string `json:"metadata_url,omitempty"` } +func (x *EndpointSAML) String() string { + return x.GoString() +} + +func (x *EndpointSAML) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointSAML {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tOptionsPassthrough\t%v\n", x.OptionsPassthrough) + fmt.Fprintf(tw, "\tCookiePrefix\t%v\n", x.CookiePrefix) + fmt.Fprintf(tw, "\tInactivityTimeout\t%v\n", x.InactivityTimeout) + fmt.Fprintf(tw, "\tMaximumDuration\t%v\n", x.MaximumDuration) + fmt.Fprintf(tw, "\tIdPMetadata\t%v\n", x.IdPMetadata) + fmt.Fprintf(tw, "\tForceAuthn\t%v\n", x.ForceAuthn) + fmt.Fprintf(tw, "\tAllowIdPInitiated\t%v\n", x.AllowIdPInitiated) + fmt.Fprintf(tw, "\tAuthorizedGroups\t%v\n", x.AuthorizedGroups) + fmt.Fprintf(tw, "\tEntityID\t%v\n", x.EntityID) + fmt.Fprintf(tw, "\tAssertionConsumerServiceURL\t%v\n", x.AssertionConsumerServiceURL) + fmt.Fprintf(tw, "\tSingleLogoutURL\t%v\n", x.SingleLogoutURL) + fmt.Fprintf(tw, "\tRequestSigningCertificatePEM\t%v\n", x.RequestSigningCertificatePEM) + fmt.Fprintf(tw, "\tMetadataURL\t%v\n", x.MetadataURL) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointSAMLMutate struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1465,11 +2424,6 @@ type EndpointSAMLMutate struct { // 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"` @@ -1487,6 +2441,28 @@ type EndpointSAMLMutate struct { AuthorizedGroups []string `json:"authorized_groups,omitempty"` } +func (x *EndpointSAMLMutate) String() string { + return x.GoString() +} + +func (x *EndpointSAMLMutate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointSAMLMutate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tOptionsPassthrough\t%v\n", x.OptionsPassthrough) + fmt.Fprintf(tw, "\tCookiePrefix\t%v\n", x.CookiePrefix) + fmt.Fprintf(tw, "\tInactivityTimeout\t%v\n", x.InactivityTimeout) + fmt.Fprintf(tw, "\tMaximumDuration\t%v\n", x.MaximumDuration) + fmt.Fprintf(tw, "\tIdPMetadata\t%v\n", x.IdPMetadata) + fmt.Fprintf(tw, "\tForceAuthn\t%v\n", x.ForceAuthn) + fmt.Fprintf(tw, "\tAllowIdPInitiated\t%v\n", x.AllowIdPInitiated) + fmt.Fprintf(tw, "\tAuthorizedGroups\t%v\n", x.AuthorizedGroups) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointOIDC struct { // true if the module will be applied to traffic, false to disable. default true if // unspecified @@ -1514,20 +2490,26 @@ type EndpointOIDC struct { 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"` +func (x *EndpointOIDC) String() string { + return x.GoString() } -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"` +func (x *EndpointOIDC) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOIDC {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tEnabled\t%v\n", x.Enabled) + fmt.Fprintf(tw, "\tOptionsPassthrough\t%v\n", x.OptionsPassthrough) + fmt.Fprintf(tw, "\tCookiePrefix\t%v\n", x.CookiePrefix) + fmt.Fprintf(tw, "\tInactivityTimeout\t%v\n", x.InactivityTimeout) + fmt.Fprintf(tw, "\tMaximumDuration\t%v\n", x.MaximumDuration) + fmt.Fprintf(tw, "\tIssuer\t%v\n", x.Issuer) + fmt.Fprintf(tw, "\tClientID\t%v\n", x.ClientID) + fmt.Fprintf(tw, "\tClientSecret\t%v\n", x.ClientSecret) + fmt.Fprintf(tw, "\tScopes\t%v\n", x.Scopes) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EndpointLoggingReplace struct { @@ -1535,9 +2517,20 @@ type EndpointLoggingReplace struct { Module EndpointLoggingMutate `json:"module,omitempty"` } -type EndpointBasicAuthReplace struct { - ID string `json:"id,omitempty"` - Module EndpointBasicAuth `json:"module,omitempty"` +func (x *EndpointLoggingReplace) String() string { + return fmt.Sprintf("EndpointLoggingReplace{ID: %v}", x.ID) + +} + +func (x *EndpointLoggingReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointLoggingReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type EndpointCircuitBreakerReplace struct { @@ -1545,59 +2538,230 @@ type EndpointCircuitBreakerReplace struct { Module EndpointCircuitBreaker `json:"module,omitempty"` } +func (x *EndpointCircuitBreakerReplace) String() string { + return fmt.Sprintf("EndpointCircuitBreakerReplace{ID: %v}", x.ID) + +} + +func (x *EndpointCircuitBreakerReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointCircuitBreakerReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointCompressionReplace struct { ID string `json:"id,omitempty"` Module EndpointCompression `json:"module,omitempty"` } +func (x *EndpointCompressionReplace) String() string { + return fmt.Sprintf("EndpointCompressionReplace{ID: %v}", x.ID) + +} + +func (x *EndpointCompressionReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointCompressionReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointTLSTerminationReplace struct { ID string `json:"id,omitempty"` Module EndpointTLSTermination `json:"module,omitempty"` } +func (x *EndpointTLSTerminationReplace) String() string { + return fmt.Sprintf("EndpointTLSTerminationReplace{ID: %v}", x.ID) + +} + +func (x *EndpointTLSTerminationReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointTLSTerminationReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointIPPolicyReplace struct { ID string `json:"id,omitempty"` Module EndpointIPPolicyMutate `json:"module,omitempty"` } +func (x *EndpointIPPolicyReplace) String() string { + return fmt.Sprintf("EndpointIPPolicyReplace{ID: %v}", x.ID) + +} + +func (x *EndpointIPPolicyReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointIPPolicyReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointMutualTLSReplace struct { ID string `json:"id,omitempty"` Module EndpointMutualTLSMutate `json:"module,omitempty"` } +func (x *EndpointMutualTLSReplace) String() string { + return fmt.Sprintf("EndpointMutualTLSReplace{ID: %v}", x.ID) + +} + +func (x *EndpointMutualTLSReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointMutualTLSReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointRequestHeadersReplace struct { ID string `json:"id,omitempty"` Module EndpointRequestHeaders `json:"module,omitempty"` } +func (x *EndpointRequestHeadersReplace) String() string { + return fmt.Sprintf("EndpointRequestHeadersReplace{ID: %v}", x.ID) + +} + +func (x *EndpointRequestHeadersReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointRequestHeadersReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointResponseHeadersReplace struct { ID string `json:"id,omitempty"` Module EndpointResponseHeaders `json:"module,omitempty"` } +func (x *EndpointResponseHeadersReplace) String() string { + return fmt.Sprintf("EndpointResponseHeadersReplace{ID: %v}", x.ID) + +} + +func (x *EndpointResponseHeadersReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointResponseHeadersReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointOAuthReplace struct { ID string `json:"id,omitempty"` Module EndpointOAuth `json:"module,omitempty"` } +func (x *EndpointOAuthReplace) String() string { + return fmt.Sprintf("EndpointOAuthReplace{ID: %v}", x.ID) + +} + +func (x *EndpointOAuthReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOAuthReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointWebhookValidationReplace struct { ID string `json:"id,omitempty"` Module EndpointWebhookValidation `json:"module,omitempty"` } +func (x *EndpointWebhookValidationReplace) String() string { + return fmt.Sprintf("EndpointWebhookValidationReplace{ID: %v}", x.ID) + +} + +func (x *EndpointWebhookValidationReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointWebhookValidationReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type EndpointSAMLReplace struct { ID string `json:"id,omitempty"` Module EndpointSAMLMutate `json:"module,omitempty"` } +func (x *EndpointSAMLReplace) String() string { + return fmt.Sprintf("EndpointSAMLReplace{ID: %v}", x.ID) + +} + +func (x *EndpointSAMLReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointSAMLReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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"` +func (x *EndpointOIDCReplace) String() string { + return fmt.Sprintf("EndpointOIDCReplace{ID: %v}", x.ID) + +} + +func (x *EndpointOIDCReplace) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "EndpointOIDCReplace {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tModule\t%v\n", x.Module) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type ReservedAddrCreate struct { @@ -1614,6 +2778,23 @@ type ReservedAddrCreate struct { EndpointConfigurationID string `json:"endpoint_configuration_id,omitempty"` } +func (x *ReservedAddrCreate) String() string { + return x.GoString() +} + +func (x *ReservedAddrCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedAddrCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tRegion\t%v\n", x.Region) + fmt.Fprintf(tw, "\tEndpointConfigurationID\t%v\n", x.EndpointConfigurationID) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedAddrUpdate struct { ID string `json:"id,omitempty"` // human-readable description of what this reserved address will be used for @@ -1626,6 +2807,24 @@ type ReservedAddrUpdate struct { EndpointConfigurationID *string `json:"endpoint_configuration_id,omitempty"` } +func (x *ReservedAddrUpdate) String() string { + return fmt.Sprintf("ReservedAddrUpdate{ID: %v}", x.ID) + +} + +func (x *ReservedAddrUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedAddrUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tEndpointConfigurationID\t%v\n", x.EndpointConfigurationID) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedAddr struct { // unique reserved address resource identifier ID string `json:"id,omitempty"` @@ -1648,6 +2847,28 @@ type ReservedAddr struct { EndpointConfiguration *Ref `json:"endpoint_configuration,omitempty"` } +func (x *ReservedAddr) String() string { + return fmt.Sprintf("ReservedAddr{ID: %v}", x.ID) + +} + +func (x *ReservedAddr) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedAddr {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tAddr\t%v\n", x.Addr) + fmt.Fprintf(tw, "\tRegion\t%v\n", x.Region) + fmt.Fprintf(tw, "\tEndpointConfiguration\t%v\n", x.EndpointConfiguration) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedAddrList struct { // the list of all reserved addresses on this account ReservedAddrs []ReservedAddr `json:"reserved_addrs,omitempty"` @@ -1657,6 +2878,22 @@ type ReservedAddrList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *ReservedAddrList) String() string { + return x.GoString() +} + +func (x *ReservedAddrList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedAddrList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tReservedAddrs\t%v\n", x.ReservedAddrs) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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. @@ -1684,6 +2921,27 @@ type ReservedDomainCreate struct { CertificateManagementPolicy *ReservedDomainCertPolicy `json:"certificate_management_policy,omitempty"` } +func (x *ReservedDomainCreate) String() string { + return x.GoString() +} + +func (x *ReservedDomainCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedDomainCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tName\t%v\n", x.Name) + fmt.Fprintf(tw, "\tRegion\t%v\n", x.Region) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tHTTPEndpointConfigurationID\t%v\n", x.HTTPEndpointConfigurationID) + fmt.Fprintf(tw, "\tHTTPSEndpointConfigurationID\t%v\n", x.HTTPSEndpointConfigurationID) + fmt.Fprintf(tw, "\tCertificateID\t%v\n", x.CertificateID) + fmt.Fprintf(tw, "\tCertificateManagementPolicy\t%v\n", x.CertificateManagementPolicy) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedDomainUpdate struct { ID string `json:"id,omitempty"` // human-readable description of what this reserved domain will be used for @@ -1706,6 +2964,27 @@ type ReservedDomainUpdate struct { CertificateManagementPolicy *ReservedDomainCertPolicy `json:"certificate_management_policy,omitempty"` } +func (x *ReservedDomainUpdate) String() string { + return fmt.Sprintf("ReservedDomainUpdate{ID: %v}", x.ID) + +} + +func (x *ReservedDomainUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedDomainUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tHTTPEndpointConfigurationID\t%v\n", x.HTTPEndpointConfigurationID) + fmt.Fprintf(tw, "\tHTTPSEndpointConfigurationID\t%v\n", x.HTTPSEndpointConfigurationID) + fmt.Fprintf(tw, "\tCertificateID\t%v\n", x.CertificateID) + fmt.Fprintf(tw, "\tCertificateManagementPolicy\t%v\n", x.CertificateManagementPolicy) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedDomain struct { // unique reserved domain resource identifier ID string `json:"id,omitempty"` @@ -1744,6 +3023,33 @@ type ReservedDomain struct { CertificateManagementStatus *ReservedDomainCertStatus `json:"certificate_management_status,omitempty"` } +func (x *ReservedDomain) String() string { + return fmt.Sprintf("ReservedDomain{ID: %v}", x.ID) + +} + +func (x *ReservedDomain) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedDomain {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tDomain\t%v\n", x.Domain) + fmt.Fprintf(tw, "\tRegion\t%v\n", x.Region) + fmt.Fprintf(tw, "\tCNAMETarget\t%v\n", x.CNAMETarget) + fmt.Fprintf(tw, "\tHTTPEndpointConfiguration\t%v\n", x.HTTPEndpointConfiguration) + fmt.Fprintf(tw, "\tHTTPSEndpointConfiguration\t%v\n", x.HTTPSEndpointConfiguration) + fmt.Fprintf(tw, "\tCertificate\t%v\n", x.Certificate) + fmt.Fprintf(tw, "\tCertificateManagementPolicy\t%v\n", x.CertificateManagementPolicy) + fmt.Fprintf(tw, "\tCertificateManagementStatus\t%v\n", x.CertificateManagementStatus) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedDomainList struct { // the list of all reserved domains on this account ReservedDomains []ReservedDomain `json:"reserved_domains,omitempty"` @@ -1753,6 +3059,22 @@ type ReservedDomainList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *ReservedDomainList) String() string { + return x.GoString() +} + +func (x *ReservedDomainList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedDomainList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tReservedDomains\t%v\n", x.ReservedDomains) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedDomainCertPolicy struct { // certificate authority to request certificates from. The only supported value is // letsencrypt. @@ -1762,6 +3084,21 @@ type ReservedDomainCertPolicy struct { PrivateKeyType string `json:"private_key_type,omitempty"` } +func (x *ReservedDomainCertPolicy) String() string { + return x.GoString() +} + +func (x *ReservedDomainCertPolicy) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedDomainCertPolicy {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tAuthority\t%v\n", x.Authority) + fmt.Fprintf(tw, "\tPrivateKeyType\t%v\n", x.PrivateKeyType) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedDomainCertStatus struct { // timestamp when the next renewal will be requested, RFC 3339 format RenewsAt *string `json:"renews_at,omitempty"` @@ -1770,6 +3107,21 @@ type ReservedDomainCertStatus struct { ProvisioningJob *ReservedDomainCertJob `json:"provisioning_job,omitempty"` } +func (x *ReservedDomainCertStatus) String() string { + return x.GoString() +} + +func (x *ReservedDomainCertStatus) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedDomainCertStatus {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tRenewsAt\t%v\n", x.RenewsAt) + fmt.Fprintf(tw, "\tProvisioningJob\t%v\n", x.ProvisioningJob) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type ReservedDomainCertNSTarget struct { // the zone that the nameservers need to be applied to Zone string `json:"zone,omitempty"` @@ -1777,6 +3129,21 @@ type ReservedDomainCertNSTarget struct { Nameservers []string `json:"nameservers,omitempty"` } +func (x *ReservedDomainCertNSTarget) String() string { + return x.GoString() +} + +func (x *ReservedDomainCertNSTarget) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedDomainCertNSTarget {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tZone\t%v\n", x.Zone) + fmt.Fprintf(tw, "\tNameservers\t%v\n", x.Nameservers) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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 @@ -1793,9 +3160,22 @@ type ReservedDomainCertJob struct { NSTargets []ReservedDomainCertNSTarget `json:"ns_targets,omitempty"` } -type RootResponse struct { - URI string `json:"uri,omitempty"` - SubresourceURIs map[string]string `json:"subresource_uris,omitempty"` +func (x *ReservedDomainCertJob) String() string { + return x.GoString() +} + +func (x *ReservedDomainCertJob) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "ReservedDomainCertJob {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tErrorCode\t%v\n", x.ErrorCode) + fmt.Fprintf(tw, "\tMsg\t%v\n", x.Msg) + fmt.Fprintf(tw, "\tStartedAt\t%v\n", x.StartedAt) + fmt.Fprintf(tw, "\tRetriesAt\t%v\n", x.RetriesAt) + fmt.Fprintf(tw, "\tNSTargets\t%v\n", x.NSTargets) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type SSHCertificateAuthorityCreate struct { @@ -1813,6 +3193,24 @@ type SSHCertificateAuthorityCreate struct { KeySize int64 `json:"key_size,omitempty"` } +func (x *SSHCertificateAuthorityCreate) String() string { + return x.GoString() +} + +func (x *SSHCertificateAuthorityCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHCertificateAuthorityCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tPrivateKeyType\t%v\n", x.PrivateKeyType) + fmt.Fprintf(tw, "\tEllipticCurve\t%v\n", x.EllipticCurve) + fmt.Fprintf(tw, "\tKeySize\t%v\n", x.KeySize) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHCertificateAuthorityUpdate struct { ID string `json:"id,omitempty"` // human-readable description of this SSH Certificate Authority. optional, max 255 @@ -1823,6 +3221,23 @@ type SSHCertificateAuthorityUpdate struct { Metadata *string `json:"metadata,omitempty"` } +func (x *SSHCertificateAuthorityUpdate) String() string { + return fmt.Sprintf("SSHCertificateAuthorityUpdate{ID: %v}", x.ID) + +} + +func (x *SSHCertificateAuthorityUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHCertificateAuthorityUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHCertificateAuthority struct { // unique identifier for this SSH Certificate Authority ID string `json:"id,omitempty"` @@ -1843,6 +3258,27 @@ type SSHCertificateAuthority struct { KeyType string `json:"key_type,omitempty"` } +func (x *SSHCertificateAuthority) String() string { + return fmt.Sprintf("SSHCertificateAuthority{ID: %v}", x.ID) + +} + +func (x *SSHCertificateAuthority) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHCertificateAuthority {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tPublicKey\t%v\n", x.PublicKey) + fmt.Fprintf(tw, "\tKeyType\t%v\n", x.KeyType) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHCertificateAuthorityList struct { // the list of all certificate authorities on this account SSHCertificateAuthorities []SSHCertificateAuthority `json:"ssh_certificate_authorities,omitempty"` @@ -1852,6 +3288,22 @@ type SSHCertificateAuthorityList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *SSHCertificateAuthorityList) String() string { + return x.GoString() +} + +func (x *SSHCertificateAuthorityList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHCertificateAuthorityList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tSSHCertificateAuthorities\t%v\n", x.SSHCertificateAuthorities) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHCredentialCreate struct { // human-readable description of who or what will use the ssh credential to // authenticate. Optional, max 255 bytes. @@ -1873,6 +3325,23 @@ type SSHCredentialCreate struct { PublicKey string `json:"public_key,omitempty"` } +func (x *SSHCredentialCreate) String() string { + return x.GoString() +} + +func (x *SSHCredentialCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHCredentialCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tACL\t%v\n", x.ACL) + fmt.Fprintf(tw, "\tPublicKey\t%v\n", x.PublicKey) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHCredentialUpdate struct { ID string `json:"id,omitempty"` // human-readable description of who or what will use the ssh credential to @@ -1893,6 +3362,24 @@ type SSHCredentialUpdate struct { ACL *[]string `json:"acl,omitempty"` } +func (x *SSHCredentialUpdate) String() string { + return fmt.Sprintf("SSHCredentialUpdate{ID: %v}", x.ID) + +} + +func (x *SSHCredentialUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHCredentialUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tACL\t%v\n", x.ACL) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHCredential struct { // unique ssh credential resource identifier ID string `json:"id,omitempty"` @@ -1920,6 +3407,27 @@ type SSHCredential struct { ACL []string `json:"acl,omitempty"` } +func (x *SSHCredential) String() string { + return fmt.Sprintf("SSHCredential{ID: %v}", x.ID) + +} + +func (x *SSHCredential) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHCredential {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tPublicKey\t%v\n", x.PublicKey) + fmt.Fprintf(tw, "\tACL\t%v\n", x.ACL) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHCredentialList struct { // the list of all ssh credentials on this account SSHCredentials []SSHCredential `json:"ssh_credentials,omitempty"` @@ -1929,6 +3437,22 @@ type SSHCredentialList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *SSHCredentialList) String() string { + return x.GoString() +} + +func (x *SSHCredentialList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHCredentialList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tSSHCredentials\t%v\n", x.SSHCredentials) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHHostCertificateCreate struct { // the ssh certificate authority that is used to sign this ssh host certificate SSHCertificateAuthorityID string `json:"ssh_certificate_authority_id,omitempty"` @@ -1954,6 +3478,26 @@ type SSHHostCertificateCreate struct { Metadata string `json:"metadata,omitempty"` } +func (x *SSHHostCertificateCreate) String() string { + return x.GoString() +} + +func (x *SSHHostCertificateCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHHostCertificateCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tSSHCertificateAuthorityID\t%v\n", x.SSHCertificateAuthorityID) + fmt.Fprintf(tw, "\tPublicKey\t%v\n", x.PublicKey) + fmt.Fprintf(tw, "\tPrincipals\t%v\n", x.Principals) + fmt.Fprintf(tw, "\tValidAfter\t%v\n", x.ValidAfter) + fmt.Fprintf(tw, "\tValidUntil\t%v\n", x.ValidUntil) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHHostCertificateUpdate struct { ID string `json:"id,omitempty"` // human-readable description of this SSH Host Certificate. optional, max 255 @@ -1964,6 +3508,23 @@ type SSHHostCertificateUpdate struct { Metadata *string `json:"metadata,omitempty"` } +func (x *SSHHostCertificateUpdate) String() string { + return fmt.Sprintf("SSHHostCertificateUpdate{ID: %v}", x.ID) + +} + +func (x *SSHHostCertificateUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHHostCertificateUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHHostCertificate struct { // unique identifier for this SSH Host Certificate ID string `json:"id,omitempty"` @@ -2000,6 +3561,32 @@ type SSHHostCertificate struct { Certificate string `json:"certificate,omitempty"` } +func (x *SSHHostCertificate) String() string { + return fmt.Sprintf("SSHHostCertificate{ID: %v}", x.ID) + +} + +func (x *SSHHostCertificate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHHostCertificate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tPublicKey\t%v\n", x.PublicKey) + fmt.Fprintf(tw, "\tKeyType\t%v\n", x.KeyType) + fmt.Fprintf(tw, "\tSSHCertificateAuthorityID\t%v\n", x.SSHCertificateAuthorityID) + fmt.Fprintf(tw, "\tPrincipals\t%v\n", x.Principals) + fmt.Fprintf(tw, "\tValidAfter\t%v\n", x.ValidAfter) + fmt.Fprintf(tw, "\tValidUntil\t%v\n", x.ValidUntil) + fmt.Fprintf(tw, "\tCertificate\t%v\n", x.Certificate) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHHostCertificateList struct { // the list of all ssh host certificates on this account SSHHostCertificates []SSHHostCertificate `json:"ssh_host_certificates,omitempty"` @@ -2009,6 +3596,22 @@ type SSHHostCertificateList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *SSHHostCertificateList) String() string { + return x.GoString() +} + +func (x *SSHHostCertificateList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHHostCertificateList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tSSHHostCertificates\t%v\n", x.SSHHostCertificates) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHUserCertificateCreate struct { // the ssh certificate authority that is used to sign this ssh user certificate SSHCertificateAuthorityID string `json:"ssh_certificate_authority_id,omitempty"` @@ -2048,6 +3651,28 @@ type SSHUserCertificateCreate struct { Metadata string `json:"metadata,omitempty"` } +func (x *SSHUserCertificateCreate) String() string { + return x.GoString() +} + +func (x *SSHUserCertificateCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHUserCertificateCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tSSHCertificateAuthorityID\t%v\n", x.SSHCertificateAuthorityID) + fmt.Fprintf(tw, "\tPublicKey\t%v\n", x.PublicKey) + fmt.Fprintf(tw, "\tPrincipals\t%v\n", x.Principals) + fmt.Fprintf(tw, "\tCriticalOptions\t%v\n", x.CriticalOptions) + fmt.Fprintf(tw, "\tExtensions\t%v\n", x.Extensions) + fmt.Fprintf(tw, "\tValidAfter\t%v\n", x.ValidAfter) + fmt.Fprintf(tw, "\tValidUntil\t%v\n", x.ValidUntil) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHUserCertificateUpdate struct { ID string `json:"id,omitempty"` // human-readable description of this SSH User Certificate. optional, max 255 @@ -2058,6 +3683,23 @@ type SSHUserCertificateUpdate struct { Metadata *string `json:"metadata,omitempty"` } +func (x *SSHUserCertificateUpdate) String() string { + return fmt.Sprintf("SSHUserCertificateUpdate{ID: %v}", x.ID) + +} + +func (x *SSHUserCertificateUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHUserCertificateUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHUserCertificate struct { // unique identifier for this SSH User Certificate ID string `json:"id,omitempty"` @@ -2108,6 +3750,34 @@ type SSHUserCertificate struct { Certificate string `json:"certificate,omitempty"` } +func (x *SSHUserCertificate) String() string { + return fmt.Sprintf("SSHUserCertificate{ID: %v}", x.ID) + +} + +func (x *SSHUserCertificate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHUserCertificate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tPublicKey\t%v\n", x.PublicKey) + fmt.Fprintf(tw, "\tKeyType\t%v\n", x.KeyType) + fmt.Fprintf(tw, "\tSSHCertificateAuthorityID\t%v\n", x.SSHCertificateAuthorityID) + fmt.Fprintf(tw, "\tPrincipals\t%v\n", x.Principals) + fmt.Fprintf(tw, "\tCriticalOptions\t%v\n", x.CriticalOptions) + fmt.Fprintf(tw, "\tExtensions\t%v\n", x.Extensions) + fmt.Fprintf(tw, "\tValidAfter\t%v\n", x.ValidAfter) + fmt.Fprintf(tw, "\tValidUntil\t%v\n", x.ValidUntil) + fmt.Fprintf(tw, "\tCertificate\t%v\n", x.Certificate) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type SSHUserCertificateList struct { // the list of all ssh user certificates on this account SSHUserCertificates []SSHUserCertificate `json:"ssh_user_certificates,omitempty"` @@ -2117,6 +3787,22 @@ type SSHUserCertificateList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *SSHUserCertificateList) String() string { + return x.GoString() +} + +func (x *SSHUserCertificateList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "SSHUserCertificateList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tSSHUserCertificates\t%v\n", x.SSHUserCertificates) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type TLSCertificateCreate struct { // human-readable description of this TLS certificate. optional, max 255 bytes. Description string `json:"description,omitempty"` @@ -2131,6 +3817,23 @@ type TLSCertificateCreate struct { PrivateKeyPEM string `json:"private_key_pem,omitempty"` } +func (x *TLSCertificateCreate) String() string { + return x.GoString() +} + +func (x *TLSCertificateCreate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TLSCertificateCreate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCertificatePEM\t%v\n", x.CertificatePEM) + fmt.Fprintf(tw, "\tPrivateKeyPEM\t%v\n", x.PrivateKeyPEM) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type TLSCertificateUpdate struct { ID string `json:"id,omitempty"` // human-readable description of this TLS certificate. optional, max 255 bytes. @@ -2140,6 +3843,23 @@ type TLSCertificateUpdate struct { Metadata *string `json:"metadata,omitempty"` } +func (x *TLSCertificateUpdate) String() string { + return fmt.Sprintf("TLSCertificateUpdate{ID: %v}", x.ID) + +} + +func (x *TLSCertificateUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TLSCertificateUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type TLSCertificate struct { // unique identifier for this TLS certificate ID string `json:"id,omitempty"` @@ -2188,6 +3908,41 @@ type TLSCertificate struct { SubjectCountry string `json:"subject_country,omitempty"` } +func (x *TLSCertificate) String() string { + return fmt.Sprintf("TLSCertificate{ID: %v}", x.ID) + +} + +func (x *TLSCertificate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TLSCertificate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tCreatedAt\t%v\n", x.CreatedAt) + fmt.Fprintf(tw, "\tDescription\t%v\n", x.Description) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tCertificatePEM\t%v\n", x.CertificatePEM) + fmt.Fprintf(tw, "\tSubjectCommonName\t%v\n", x.SubjectCommonName) + fmt.Fprintf(tw, "\tSubjectAlternativeNames\t%v\n", x.SubjectAlternativeNames) + fmt.Fprintf(tw, "\tIssuedAt\t%v\n", x.IssuedAt) + fmt.Fprintf(tw, "\tNotBefore\t%v\n", x.NotBefore) + fmt.Fprintf(tw, "\tNotAfter\t%v\n", x.NotAfter) + fmt.Fprintf(tw, "\tKeyUsages\t%v\n", x.KeyUsages) + fmt.Fprintf(tw, "\tExtendedKeyUsages\t%v\n", x.ExtendedKeyUsages) + fmt.Fprintf(tw, "\tPrivateKeyType\t%v\n", x.PrivateKeyType) + fmt.Fprintf(tw, "\tIssuerCommonName\t%v\n", x.IssuerCommonName) + fmt.Fprintf(tw, "\tSerialNumber\t%v\n", x.SerialNumber) + fmt.Fprintf(tw, "\tSubjectOrganization\t%v\n", x.SubjectOrganization) + fmt.Fprintf(tw, "\tSubjectOrganizationalUnit\t%v\n", x.SubjectOrganizationalUnit) + fmt.Fprintf(tw, "\tSubjectLocality\t%v\n", x.SubjectLocality) + fmt.Fprintf(tw, "\tSubjectProvince\t%v\n", x.SubjectProvince) + fmt.Fprintf(tw, "\tSubjectCountry\t%v\n", x.SubjectCountry) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type TLSCertificateList struct { // the list of all TLS certificates on this account TLSCertificates []TLSCertificate `json:"tls_certificates,omitempty"` @@ -2197,6 +3952,22 @@ type TLSCertificateList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *TLSCertificateList) String() string { + return x.GoString() +} + +func (x *TLSCertificateList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TLSCertificateList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tTLSCertificates\t%v\n", x.TLSCertificates) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type TLSCertificateSANs struct { // set of additional domains (including wildcards) this TLS certificate is valid // for @@ -2205,6 +3976,21 @@ type TLSCertificateSANs struct { IPs []string `json:"ips,omitempty"` } +func (x *TLSCertificateSANs) String() string { + return x.GoString() +} + +func (x *TLSCertificateSANs) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TLSCertificateSANs {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tDNSNames\t%v\n", x.DNSNames) + fmt.Fprintf(tw, "\tIPs\t%v\n", x.IPs) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type TunnelSession struct { // version of the ngrok agent that started this ngrok tunnel session AgentVersion string `json:"agent_version,omitempty"` @@ -2230,6 +4016,30 @@ type TunnelSession struct { URI string `json:"uri,omitempty"` } +func (x *TunnelSession) String() string { + return fmt.Sprintf("TunnelSession{ID: %v}", x.ID) + +} + +func (x *TunnelSession) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TunnelSession {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tAgentVersion\t%v\n", x.AgentVersion) + fmt.Fprintf(tw, "\tCredential\t%v\n", x.Credential) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tIP\t%v\n", x.IP) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tOS\t%v\n", x.OS) + fmt.Fprintf(tw, "\tRegion\t%v\n", x.Region) + fmt.Fprintf(tw, "\tStartedAt\t%v\n", x.StartedAt) + fmt.Fprintf(tw, "\tTransport\t%v\n", x.Transport) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type TunnelSessionList struct { // list of all tunnel sessions on this account TunnelSessions []TunnelSession `json:"tunnel_sessions,omitempty"` @@ -2239,11 +4049,39 @@ type TunnelSessionList struct { NextPageURI *string `json:"next_page_uri,omitempty"` } +func (x *TunnelSessionList) String() string { + return x.GoString() +} + +func (x *TunnelSessionList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TunnelSessionList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tTunnelSessions\t%v\n", x.TunnelSessions) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + 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"` +} + +func (x *TunnelSessionsUpdate) String() string { + return fmt.Sprintf("TunnelSessionsUpdate{ID: %v}", x.ID) + +} + +func (x *TunnelSessionsUpdate) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TunnelSessionsUpdate {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() } type Tunnel struct { @@ -2267,6 +4105,27 @@ type Tunnel struct { TunnelSession Ref `json:"tunnel_session,omitempty"` } +func (x *Tunnel) String() string { + return fmt.Sprintf("Tunnel{ID: %v}", x.ID) + +} + +func (x *Tunnel) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "Tunnel {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tID\t%v\n", x.ID) + fmt.Fprintf(tw, "\tPublicURL\t%v\n", x.PublicURL) + fmt.Fprintf(tw, "\tStartedAt\t%v\n", x.StartedAt) + fmt.Fprintf(tw, "\tMetadata\t%v\n", x.Metadata) + fmt.Fprintf(tw, "\tProto\t%v\n", x.Proto) + fmt.Fprintf(tw, "\tRegion\t%v\n", x.Region) + fmt.Fprintf(tw, "\tTunnelSession\t%v\n", x.TunnelSession) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} + type TunnelList struct { // the list of all online tunnels on this account Tunnels []Tunnel `json:"tunnels,omitempty"` @@ -2275,3 +4134,19 @@ type TunnelList struct { // URI of the next page, or null if there is no next page NextPageURI *string `json:"next_page_uri,omitempty"` } + +func (x *TunnelList) String() string { + return x.GoString() +} + +func (x *TunnelList) GoString() string { + var b bytes.Buffer + fmt.Fprintf(&b, "TunnelList {\n") + tw := tabwriter.NewWriter(&b, 0, 4, 0, ' ', 0) + fmt.Fprintf(tw, "\tTunnels\t%v\n", x.Tunnels) + fmt.Fprintf(tw, "\tURI\t%v\n", x.URI) + fmt.Fprintf(tw, "\tNextPageURI\t%v\n", x.NextPageURI) + tw.Flush() + fmt.Fprintf(&b, "}\n") + return b.String() +} diff --git a/debug.go b/debug.go deleted file mode 100644 index d8c10c5..0000000 --- a/debug.go +++ /dev/null @@ -1,153 +0,0 @@ -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/doc.go b/doc.go new file mode 100644 index 0000000..fa977c0 --- /dev/null +++ b/doc.go @@ -0,0 +1,18 @@ +// Package ngrok +// +// Quickstart +// +// Functional Option Configuration +// +// API Clients +// +// Nullable properties +// +// Transparent Paging +// +// Error Handling +// +// Pretty Printing (string and gostring) +// +// Examples +package ngrok diff --git a/endpoint_backend_module/client.go b/endpoint_backend_module/client.go deleted file mode 100644 index e10e512..0000000 --- a/endpoint_backend_module/client.go +++ /dev/null @@ -1,92 +0,0 @@ -// 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 deleted file mode 100644 index 3883c2d..0000000 --- a/endpoint_basic_auth_module/client.go +++ /dev/null @@ -1,92 +0,0 @@ -// 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_configurations/client.go b/endpoint_configurations/client.go index d09fc26..d75d15b 100644 --- a/endpoint_configurations/client.go +++ b/endpoint_configurations/client.go @@ -5,7 +5,6 @@ package endpoint_configurations import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -27,9 +26,13 @@ func NewClient(apiClient *ngrok.Client) *Client { // Create a new endpoint configuration func (c *Client) Create( + ctx context.Context, arg *ngrok.EndpointConfigurationCreate, ) (*ngrok.EndpointConfiguration, error) { + if arg == nil { + arg = new(ngrok.EndpointConfigurationCreate) + } var res ngrok.EndpointConfiguration var path bytes.Buffer if err := template.Must(template.New("create_path").Parse("/endpoint_configurations")).Execute(&path, arg); err != nil { @@ -51,11 +54,13 @@ func (c *Client) Create( // 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) @@ -75,11 +80,13 @@ func (c *Client) Delete( // 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 { @@ -99,10 +106,13 @@ func (c *Client) Get( } // Returns a list of all endpoint configurations on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.EndpointConfigurationList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.EndpointConfigurationList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/endpoint_configurations")).Execute(&path, arg); err != nil { @@ -128,24 +138,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// Returns a list of all endpoint configurations on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.EndpointConfiguration - err error + client *Client + ctx context.Context + n int + items []ngrok.EndpointConfiguration + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -155,18 +178,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -174,14 +193,18 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.EndpointConfigurations - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the EndpointConfiguration currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.EndpointConfiguration { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. func (it *Iter) Err() error { return it.err } @@ -191,9 +214,13 @@ func (it *Iter) Err() error { // 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) { + if arg == nil { + arg = new(ngrok.EndpointConfigurationUpdate) + } 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 { diff --git a/event_destinations/client.go b/event_destinations/client.go index 4e045b8..9990d6b 100644 --- a/event_destinations/client.go +++ b/event_destinations/client.go @@ -5,7 +5,6 @@ package event_destinations import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -24,9 +23,13 @@ func NewClient(apiClient *ngrok.Client) *Client { // 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) { + if arg == nil { + arg = new(ngrok.EventDestinationCreate) + } var res ngrok.EventDestination var path bytes.Buffer if err := template.Must(template.New("create_path").Parse("/event_destinations")).Execute(&path, arg); err != nil { @@ -49,11 +52,13 @@ func (c *Client) Create( // 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) @@ -73,11 +78,13 @@ func (c *Client) Delete( // 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 { @@ -97,10 +104,13 @@ func (c *Client) Get( } // List all Event Destinations on this account. -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.EventDestinationList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.EventDestinationList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/event_destinations")).Execute(&path, arg); err != nil { @@ -126,24 +136,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all Event Destinations on this account. +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.EventDestination - err error + client *Client + ctx context.Context + n int + items []ngrok.EventDestination + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -153,18 +176,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -172,23 +191,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.EventDestinations - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the EventDestination currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.EventDestination { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.EventDestinationUpdate) + } 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 { @@ -207,29 +234,3 @@ func (c *Client) Update( } 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 deleted file mode 100644 index 76ecbda..0000000 --- a/event_sources/client.go +++ /dev/null @@ -1,141 +0,0 @@ -// 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 index 527d8b5..285c691 100644 --- a/event_streams/client.go +++ b/event_streams/client.go @@ -5,7 +5,6 @@ package event_streams import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -23,9 +22,13 @@ func NewClient(apiClient *ngrok.Client) *Client { // 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) { + if arg == nil { + arg = new(ngrok.EventStreamCreate) + } var res ngrok.EventStream var path bytes.Buffer if err := template.Must(template.New("create_path").Parse("/event_streams")).Execute(&path, arg); err != nil { @@ -46,11 +49,13 @@ func (c *Client) Create( // 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) @@ -70,11 +75,13 @@ func (c *Client) Delete( // 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 { @@ -94,10 +101,13 @@ func (c *Client) Get( } // List all Event Streams available on this account. -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.EventStreamList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.EventStreamList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/event_streams")).Execute(&path, arg); err != nil { @@ -123,24 +133,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all Event Streams available on this account. +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.EventStream - err error + client *Client + ctx context.Context + n int + items []ngrok.EventStream + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -150,18 +173,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -169,23 +188,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.EventStreams - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the EventStream currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.EventStream { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.EventStreamUpdate) + } 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 { diff --git a/event_subscriptions/client.go b/event_subscriptions/client.go deleted file mode 100644 index 7a34c84..0000000 --- a/event_subscriptions/client.go +++ /dev/null @@ -1,205 +0,0 @@ -// 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/integration_test.go b/integration_test.go new file mode 100644 index 0000000..26cabf4 --- /dev/null +++ b/integration_test.go @@ -0,0 +1,89 @@ +// Code generated by apic. DO NOT EDIT. + +package ngrok_test + +import ( + "context" + "net/http" + "os" + "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) { + var opts []ngrok.ClientOption + + var mock mockTransport + if os.Getenv("TEST_NO_MOCK") != "true" { + opts = append(opts, ngrok.WithHTTPClient(&http.Client{ + Transport: &mock, + })) + } else if os.Getenv("TEST_DEBUG") == "true" { + // dump requests and responses to stdout + opts = append(opts, ngrok.WithHTTPClient(&http.Client{ + Transport: &debugTransport{ + rt: http.DefaultTransport, + out: os.Stderr, + }, + })) + } + + ctx := context.Background() + c, err := ngrok.NewClient(os.Getenv("NGROK_API_KEY"), opts...) + require.NoError(t, err) + + policies := ip_policies.NewClient(c) + + // test policy creation + mock.SetResponse(201, `{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"","action":"allow"}`) + createInstance, err := policies.Create(ctx, &ngrok.IPPolicyCreate{ + Action: "allow", + Description: "ngrok-api-go tests", + }) + require.NoError(t, err) + + // test get + mock.SetResponse(200, `{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"","action":"allow"}`) + getInstance, err := policies.Get(ctx, createInstance.ID) + require.NoError(t, err) + require.Equal(t, createInstance, getInstance) + + // test update + mock.SetResponse(200, `{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"{\"device-id\": \"malamute-12\"}","action":"allow"}`) + 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 + mock.SetResponse(200, `{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"{\"device-id\": \"malamute-12\"}","action":"allow"}`) + getAfterUpdateInstance, err := policies.Get(ctx, createInstance.ID) + require.NoError(t, err) + require.Equal(t, updatedInstance, getAfterUpdateInstance) + + mock.SetResponse(200, `{"ip_policies":[{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"{\"device-id\": \"malamute-12\"}","action":"allow"},{"id":"ipp_1qXI4T0q6cgkoOVvqSEjU7LiWIr","uri":"https://api.ngrok.com/ip_policies/ipp_1qXI4T0q6cgkoOVvqSEjU7LiWIr","created_at":"2021-03-31T19:35:16Z","description":"martin demo","metadata":"","action":"allow"}],"uri":"https://api.ngrok.com/ip_policies","next_page_uri":null}`) + mock.SetResponse(200, `{"ip_policies":[],"uri":"https://api.ngrok.com/ip_policies","next_page_uri":null}`) + iter := policies.List(ctx, nil) + var iterPolicies []*ngrok.IPPolicy + for iter.Next() { + iterPolicies = append(iterPolicies, iter.Item()) + } + require.NoError(t, iter.Err()) + require.Contains(t, iterPolicies, updatedInstance) + + // test delete + mock.SetResponse(204, "") + err = policies.Delete(ctx, createInstance.ID) + require.NoError(t, err) + + // test 404 + mock.SetResponse(404, `{"status_code":404,"msg":"Resource not found","details":{"operation_id":"op_1sbMfWvXaRA26gTJoBPIgyPD8MF"}}`) + _, err = policies.Get(ctx, createInstance.ID) + require.True(t, ngrok.IsNotFound(err)) +} diff --git a/ip_policies/client.go b/ip_policies/client.go index 6f7eede..9983821 100644 --- a/ip_policies/client.go +++ b/ip_policies/client.go @@ -5,7 +5,6 @@ package ip_policies import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -23,6 +22,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // 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) { @@ -48,11 +48,13 @@ func (c *Client) Create( // 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) @@ -72,11 +74,13 @@ func (c *Client) Delete( // 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 { @@ -96,10 +100,13 @@ func (c *Client) Get( } // List all IP policies on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.IPPolicyList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.IPPolicyList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/ip_policies")).Execute(&path, arg); err != nil { @@ -125,24 +132,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all IP policies on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.IPPolicy - err error + client *Client + ctx context.Context + n int + items []ngrok.IPPolicy + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -152,18 +172,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -171,23 +187,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.IPPolicies - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the IPPolicy currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.IPPolicy { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.IPPolicyUpdate) + } 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 { diff --git a/ip_policy_rules/client.go b/ip_policy_rules/client.go index cf642a6..5f93140 100644 --- a/ip_policy_rules/client.go +++ b/ip_policy_rules/client.go @@ -5,7 +5,6 @@ package ip_policy_rules import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // Create a new IP policy rule attached to an IP Policy. func (c *Client) Create( + ctx context.Context, arg *ngrok.IPPolicyRuleCreate, ) (*ngrok.IPPolicyRule, error) { @@ -45,11 +45,13 @@ func (c *Client) Create( // 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) @@ -69,11 +71,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +97,13 @@ func (c *Client) Get( } // List all IP policy rules on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.IPPolicyRuleList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } 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 { @@ -122,24 +129,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all IP policy rules on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.IPPolicyRule - err error + client *Client + ctx context.Context + n int + items []ngrok.IPPolicyRule + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +169,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +184,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.IPPolicyRules - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the IPPolicyRule currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.IPPolicyRule { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.IPPolicyRuleUpdate) + } 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 { diff --git a/ip_restrictions/client.go b/ip_restrictions/client.go index c724a96..1e0778e 100644 --- a/ip_restrictions/client.go +++ b/ip_restrictions/client.go @@ -5,7 +5,6 @@ package ip_restrictions import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // Create a new IP restriction func (c *Client) Create( + ctx context.Context, arg *ngrok.IPRestrictionCreate, ) (*ngrok.IPRestriction, error) { @@ -45,11 +45,13 @@ func (c *Client) Create( // 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) @@ -69,11 +71,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +97,13 @@ func (c *Client) Get( } // List all IP restrictions on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.IPRestrictionList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.IPRestrictionList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/ip_restrictions")).Execute(&path, arg); err != nil { @@ -122,24 +129,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all IP restrictions on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.IPRestriction - err error + client *Client + ctx context.Context + n int + items []ngrok.IPRestriction + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +169,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +184,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.IPRestrictions - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the IPRestriction currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.IPRestriction { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.IPRestrictionUpdate) + } 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 { diff --git a/ip_whitelist/client.go b/ip_whitelist/client.go index 987fd41..5a285a3 100644 --- a/ip_whitelist/client.go +++ b/ip_whitelist/client.go @@ -5,7 +5,6 @@ package ip_whitelist import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -23,9 +22,13 @@ func NewClient(apiClient *ngrok.Client) *Client { // 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) { + if arg == nil { + arg = new(ngrok.IPWhitelistEntryCreate) + } var res ngrok.IPWhitelistEntry var path bytes.Buffer if err := template.Must(template.New("create_path").Parse("/ip_whitelist")).Execute(&path, arg); err != nil { @@ -46,11 +49,13 @@ func (c *Client) Create( // 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) @@ -70,11 +75,13 @@ func (c *Client) Delete( // 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 { @@ -94,10 +101,13 @@ func (c *Client) Get( } // List all IP whitelist entries on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.IPWhitelistEntryList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.IPWhitelistEntryList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/ip_whitelist")).Execute(&path, arg); err != nil { @@ -123,24 +133,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all IP whitelist entries on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.IPWhitelistEntry - err error + client *Client + ctx context.Context + n int + items []ngrok.IPWhitelistEntry + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -150,18 +173,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -169,23 +188,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.Whitelist - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the IPWhitelistEntry currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.IPWhitelistEntry { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.IPWhitelistEntryUpdate) + } 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 { diff --git a/main_test.go b/main_test.go deleted file mode 100644 index 23d1f60..0000000 --- a/main_test.go +++ /dev/null @@ -1,64 +0,0 @@ -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/endpoint_circuit_breaker_module/client.go b/pointcfg_module/circuit_breaker/client.go similarity index 95% rename from endpoint_circuit_breaker_module/client.go rename to pointcfg_module/circuit_breaker/client.go index 26e105a..da0b25b 100644 --- a/endpoint_circuit_breaker_module/client.go +++ b/pointcfg_module/circuit_breaker/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_circuit_breaker_module +package circuit_breaker import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointCircuitBreakerReplace, ) (*ngrok.EndpointCircuitBreaker, error) { + if arg == nil { + arg = new(ngrok.EndpointCircuitBreakerReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_compression_module/client.go b/pointcfg_module/compression/client.go similarity index 95% rename from endpoint_compression_module/client.go rename to pointcfg_module/compression/client.go index 1b3cfe0..f43d9f2 100644 --- a/endpoint_compression_module/client.go +++ b/pointcfg_module/compression/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_compression_module +package compression import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointCompressionReplace, ) (*ngrok.EndpointCompression, error) { + if arg == nil { + arg = new(ngrok.EndpointCompressionReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_ip_policy_module/client.go b/pointcfg_module/ip_policy/client.go similarity index 95% rename from endpoint_ip_policy_module/client.go rename to pointcfg_module/ip_policy/client.go index e50a3a1..3892539 100644 --- a/endpoint_ip_policy_module/client.go +++ b/pointcfg_module/ip_policy/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_ip_policy_module +package ip_policy import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointIPPolicyReplace, ) (*ngrok.EndpointIPPolicy, error) { + if arg == nil { + arg = new(ngrok.EndpointIPPolicyReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_logging_module/client.go b/pointcfg_module/logging/client.go similarity index 95% rename from endpoint_logging_module/client.go rename to pointcfg_module/logging/client.go index 2e9d551..4091e95 100644 --- a/endpoint_logging_module/client.go +++ b/pointcfg_module/logging/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_logging_module +package logging import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointLoggingReplace, ) (*ngrok.EndpointLogging, error) { + if arg == nil { + arg = new(ngrok.EndpointLoggingReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_mutual_tls_module/client.go b/pointcfg_module/mutual_tls/client.go similarity index 95% rename from endpoint_mutual_tls_module/client.go rename to pointcfg_module/mutual_tls/client.go index eb6b3d2..ce3eb16 100644 --- a/endpoint_mutual_tls_module/client.go +++ b/pointcfg_module/mutual_tls/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_mutual_tls_module +package mutual_tls import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointMutualTLSReplace, ) (*ngrok.EndpointMutualTLS, error) { + if arg == nil { + arg = new(ngrok.EndpointMutualTLSReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_o_auth_module/client.go b/pointcfg_module/oauth/client.go similarity index 96% rename from endpoint_o_auth_module/client.go rename to pointcfg_module/oauth/client.go index a25fb70..d59d4a0 100644 --- a/endpoint_o_auth_module/client.go +++ b/pointcfg_module/oauth/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_o_auth_module +package oauth import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointOAuthReplace, ) (*ngrok.EndpointOAuth, error) { + if arg == nil { + arg = new(ngrok.EndpointOAuthReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_oidc_module/client.go b/pointcfg_module/oidc/client.go similarity index 96% rename from endpoint_oidc_module/client.go rename to pointcfg_module/oidc/client.go index 3e9216e..6b827f1 100644 --- a/endpoint_oidc_module/client.go +++ b/pointcfg_module/oidc/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_oidc_module +package oidc import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointOIDCReplace, ) (*ngrok.EndpointOIDC, error) { + if arg == nil { + arg = new(ngrok.EndpointOIDCReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_request_headers_module/client.go b/pointcfg_module/request_headers/client.go similarity index 95% rename from endpoint_request_headers_module/client.go rename to pointcfg_module/request_headers/client.go index af7ec79..ede65a3 100644 --- a/endpoint_request_headers_module/client.go +++ b/pointcfg_module/request_headers/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_request_headers_module +package request_headers import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointRequestHeadersReplace, ) (*ngrok.EndpointRequestHeaders, error) { + if arg == nil { + arg = new(ngrok.EndpointRequestHeadersReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_response_headers_module/client.go b/pointcfg_module/response_headers/client.go similarity index 95% rename from endpoint_response_headers_module/client.go rename to pointcfg_module/response_headers/client.go index 3740c58..5ff2469 100644 --- a/endpoint_response_headers_module/client.go +++ b/pointcfg_module/response_headers/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_response_headers_module +package response_headers import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointResponseHeadersReplace, ) (*ngrok.EndpointResponseHeaders, error) { + if arg == nil { + arg = new(ngrok.EndpointResponseHeadersReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_saml_module/client.go b/pointcfg_module/saml/client.go similarity index 96% rename from endpoint_saml_module/client.go rename to pointcfg_module/saml/client.go index e3af0f6..e552227 100644 --- a/endpoint_saml_module/client.go +++ b/pointcfg_module/saml/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_saml_module +package saml import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointSAMLReplace, ) (*ngrok.EndpointSAML, error) { + if arg == nil { + arg = new(ngrok.EndpointSAMLReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_tls_termination_module/client.go b/pointcfg_module/tls_termination/client.go similarity index 95% rename from endpoint_tls_termination_module/client.go rename to pointcfg_module/tls_termination/client.go index 409341c..0c04745 100644 --- a/endpoint_tls_termination_module/client.go +++ b/pointcfg_module/tls_termination/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_tls_termination_module +package tls_termination import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointTLSTerminationReplace, ) (*ngrok.EndpointTLSTermination, error) { + if arg == nil { + arg = new(ngrok.EndpointTLSTerminationReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/endpoint_webhook_validation_module/client.go b/pointcfg_module/webhook_validation/client.go similarity index 95% rename from endpoint_webhook_validation_module/client.go rename to pointcfg_module/webhook_validation/client.go index f19fd4b..901cab5 100644 --- a/endpoint_webhook_validation_module/client.go +++ b/pointcfg_module/webhook_validation/client.go @@ -1,6 +1,6 @@ // Code generated by apic. DO NOT EDIT. -package endpoint_webhook_validation_module +package webhook_validation import ( "bytes" @@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } func (c *Client) Replace( + ctx context.Context, arg *ngrok.EndpointWebhookValidationReplace, ) (*ngrok.EndpointWebhookValidation, error) { + if arg == nil { + arg = new(ngrok.EndpointWebhookValidationReplace) + } 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 { @@ -43,11 +47,13 @@ func (c *Client) Replace( } 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 { @@ -67,11 +73,13 @@ func (c *Client) Get( } 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) diff --git a/priority_backends/client.go b/priority_backends/client.go deleted file mode 100644 index 2baa284..0000000 --- a/priority_backends/client.go +++ /dev/null @@ -1,205 +0,0 @@ -// 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 index 4ceb626..2627d18 100644 --- a/reserved_addrs/client.go +++ b/reserved_addrs/client.go @@ -5,7 +5,6 @@ package reserved_addrs import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,9 +21,13 @@ func NewClient(apiClient *ngrok.Client) *Client { // Create a new reserved address. func (c *Client) Create( + ctx context.Context, arg *ngrok.ReservedAddrCreate, ) (*ngrok.ReservedAddr, error) { + if arg == nil { + arg = new(ngrok.ReservedAddrCreate) + } var res ngrok.ReservedAddr var path bytes.Buffer if err := template.Must(template.New("create_path").Parse("/reserved_addrs")).Execute(&path, arg); err != nil { @@ -45,11 +48,13 @@ func (c *Client) Create( // 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) @@ -69,11 +74,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +100,13 @@ func (c *Client) Get( } // List all reserved addresses on this account. -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.ReservedAddrList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.ReservedAddrList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/reserved_addrs")).Execute(&path, arg); err != nil { @@ -122,24 +132,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all reserved addresses on this account. +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.ReservedAddr - err error + client *Client + ctx context.Context + n int + items []ngrok.ReservedAddr + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +172,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +187,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.ReservedAddrs - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the ReservedAddr currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.ReservedAddr { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.ReservedAddrUpdate) + } 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 { @@ -206,11 +233,13 @@ func (c *Client) Update( // 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) diff --git a/reserved_domains/client.go b/reserved_domains/client.go index 89b5b1d..b810cb5 100644 --- a/reserved_domains/client.go +++ b/reserved_domains/client.go @@ -5,7 +5,6 @@ package reserved_domains import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // Create a new reserved domain. func (c *Client) Create( + ctx context.Context, arg *ngrok.ReservedDomainCreate, ) (*ngrok.ReservedDomain, error) { @@ -45,11 +45,13 @@ func (c *Client) Create( // 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) @@ -69,11 +71,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +97,13 @@ func (c *Client) Get( } // List all reserved domains on this account. -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.ReservedDomainList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.ReservedDomainList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/reserved_domains")).Execute(&path, arg); err != nil { @@ -122,24 +129,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all reserved domains on this account. +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.ReservedDomain - err error + client *Client + ctx context.Context + n int + items []ngrok.ReservedDomain + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +169,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +184,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.ReservedDomains - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the ReservedDomain currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.ReservedDomain { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.ReservedDomainUpdate) + } 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 { @@ -206,11 +230,13 @@ func (c *Client) Update( // 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) @@ -230,11 +256,13 @@ func (c *Client) DeleteCertificateManagementPolicy( // 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) @@ -254,11 +282,13 @@ func (c *Client) DeleteCertificate( // 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) @@ -278,11 +308,13 @@ func (c *Client) DeleteHTTPEndpointConfig( // 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) diff --git a/root/client.go b/root/client.go deleted file mode 100644 index 39533f3..0000000 --- a/root/client.go +++ /dev/null @@ -1,41 +0,0 @@ -// 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 index 29345b7..516b8ca 100644 --- a/ssh_certificate_authorities/client.go +++ b/ssh_certificate_authorities/client.go @@ -5,7 +5,6 @@ package ssh_certificate_authorities import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,9 +21,13 @@ func NewClient(apiClient *ngrok.Client) *Client { // Create a new SSH Certificate Authority func (c *Client) Create( + ctx context.Context, arg *ngrok.SSHCertificateAuthorityCreate, ) (*ngrok.SSHCertificateAuthority, error) { + if arg == nil { + arg = new(ngrok.SSHCertificateAuthorityCreate) + } 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 { @@ -45,11 +48,13 @@ func (c *Client) Create( // 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) @@ -69,11 +74,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +100,13 @@ func (c *Client) Get( } // List all SSH Certificate Authorities on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.SSHCertificateAuthorityList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } 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 { @@ -122,24 +132,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all SSH Certificate Authorities on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.SSHCertificateAuthority - err error + client *Client + ctx context.Context + n int + items []ngrok.SSHCertificateAuthority + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +172,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +187,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.SSHCertificateAuthorities - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the SSHCertificateAuthority currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.SSHCertificateAuthority { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.SSHCertificateAuthorityUpdate) + } 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 { diff --git a/ssh_credentials/client.go b/ssh_credentials/client.go index b9b0969..1534f08 100644 --- a/ssh_credentials/client.go +++ b/ssh_credentials/client.go @@ -5,7 +5,6 @@ package ssh_credentials import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -23,6 +22,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // 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) { @@ -46,11 +46,13 @@ func (c *Client) Create( // 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) @@ -70,11 +72,13 @@ func (c *Client) Delete( // 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 { @@ -94,10 +98,13 @@ func (c *Client) Get( } // List all ssh credentials on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.SSHCredentialList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.SSHCredentialList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/ssh_credentials")).Execute(&path, arg); err != nil { @@ -123,24 +130,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all ssh credentials on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.SSHCredential - err error + client *Client + ctx context.Context + n int + items []ngrok.SSHCredential + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -150,18 +170,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -169,23 +185,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.SSHCredentials - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the SSHCredential currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.SSHCredential { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.SSHCredentialUpdate) + } 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 { diff --git a/ssh_host_certificates/client.go b/ssh_host_certificates/client.go index 2008b1b..a284ae1 100644 --- a/ssh_host_certificates/client.go +++ b/ssh_host_certificates/client.go @@ -5,7 +5,6 @@ package ssh_host_certificates import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // Create a new SSH Host Certificate func (c *Client) Create( + ctx context.Context, arg *ngrok.SSHHostCertificateCreate, ) (*ngrok.SSHHostCertificate, error) { @@ -45,11 +45,13 @@ func (c *Client) Create( // 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) @@ -69,11 +71,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +97,13 @@ func (c *Client) Get( } // List all SSH Host Certificates issued on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.SSHHostCertificateList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } 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 { @@ -122,24 +129,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all SSH Host Certificates issued on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.SSHHostCertificate - err error + client *Client + ctx context.Context + n int + items []ngrok.SSHHostCertificate + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +169,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +184,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.SSHHostCertificates - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the SSHHostCertificate currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.SSHHostCertificate { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.SSHHostCertificateUpdate) + } 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 { diff --git a/ssh_user_certificates/client.go b/ssh_user_certificates/client.go index 254e227..bd74031 100644 --- a/ssh_user_certificates/client.go +++ b/ssh_user_certificates/client.go @@ -5,7 +5,6 @@ package ssh_user_certificates import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // Create a new SSH User Certificate func (c *Client) Create( + ctx context.Context, arg *ngrok.SSHUserCertificateCreate, ) (*ngrok.SSHUserCertificate, error) { @@ -45,11 +45,13 @@ func (c *Client) Create( // 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) @@ -69,11 +71,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +97,13 @@ func (c *Client) Get( } // List all SSH User Certificates issued on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.SSHUserCertificateList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } 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 { @@ -122,24 +129,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all SSH User Certificates issued on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.SSHUserCertificate - err error + client *Client + ctx context.Context + n int + items []ngrok.SSHUserCertificate + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +169,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +184,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.SSHUserCertificates - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the SSHUserCertificate currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.SSHUserCertificate { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.SSHUserCertificateUpdate) + } 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 { diff --git a/static_backends/client.go b/static_backends/client.go deleted file mode 100644 index 77c6765..0000000 --- a/static_backends/client.go +++ /dev/null @@ -1,205 +0,0 @@ -// 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 index 368f92a..651a706 100644 --- a/tls_certificates/client.go +++ b/tls_certificates/client.go @@ -5,7 +5,6 @@ package tls_certificates import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client { // Upload a new TLS certificate func (c *Client) Create( + ctx context.Context, arg *ngrok.TLSCertificateCreate, ) (*ngrok.TLSCertificate, error) { @@ -45,11 +45,13 @@ func (c *Client) Create( // 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) @@ -69,11 +71,13 @@ func (c *Client) Delete( // 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 { @@ -93,10 +97,13 @@ func (c *Client) Get( } // List all TLS certificates on this account -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.TLSCertificateList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.TLSCertificateList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/tls_certificates")).Execute(&path, arg); err != nil { @@ -122,24 +129,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all TLS certificates on this account +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.TLSCertificate - err error + client *Client + ctx context.Context + n int + items []ngrok.TLSCertificate + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -149,18 +169,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -168,23 +184,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.TLSCertificates - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the TLSCertificate currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.TLSCertificate { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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) { + if arg == nil { + arg = new(ngrok.TLSCertificateUpdate) + } 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 { diff --git a/transports_test.go b/transports_test.go new file mode 100644 index 0000000..e77669d --- /dev/null +++ b/transports_test.go @@ -0,0 +1,77 @@ +// Code generated by apic. DO NOT EDIT. + +package ngrok_test + +import ( + "bytes" + "fmt" + "io" + "io/ioutil" + "math/rand" + "net/http" + "net/http/httputil" +) + +type debugTransport struct { + rt http.RoundTripper + out io.Writer +} + +func (t *debugTransport) RoundTrip(req *http.Request) (*http.Response, error) { + // dump request + rtid := rand.Int() + fmt.Fprintf(t.out, "\n************** ROUND TRIP %x ********************\n", rtid) + reqBytes, _ := httputil.DumpRequestOut(req, true) + t.out.Write(reqBytes) + fmt.Fprintln(t.out, "") + + // execute round trip + resp, err := t.rt.RoundTrip(req) + + // dump response + if err != nil { + fmt.Fprintf(t.out, "RoundTrip error: %v\n", err) + } else { + respBytes, _ := httputil.DumpResponse(resp, true) + t.out.Write(respBytes) + fmt.Fprintln(t.out, "") + } + fmt.Fprintf(t.out, "\n************** END ROUND TRIP %x ********************\n", rtid) + + return resp, err +} + +type mockTransport struct { + mockResponse []*http.Response + mockResponseError []error +} + +func (s *mockTransport) SetResponse(statusCode int, body string) { + s.mockResponse = append(s.mockResponse, &http.Response{ + Status: http.StatusText(statusCode), + StatusCode: statusCode, + Proto: "HTTP/1.1", + ProtoMajor: 1, + ProtoMinor: 1, + Header: http.Header{ + "Content-Length": []string{fmt.Sprintf("%d", len(body))}, + "Connection": []string{"close"}, + }, + ContentLength: int64(len(body)), + Body: ioutil.NopCloser(bytes.NewReader([]byte(body))), + }) + s.mockResponseError = append(s.mockResponseError, nil) +} + +func (s *mockTransport) SetResponseError(err error) { + s.mockResponse = append(s.mockResponse, nil) + s.mockResponseError = append(s.mockResponseError, err) +} + +func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) { + resp := t.mockResponse[0] + respErr := t.mockResponseError[0] + t.mockResponse = t.mockResponse[1:] + t.mockResponseError = t.mockResponseError[1:] + return resp, respErr +} diff --git a/tunnel_group_backends/client.go b/tunnel_group_backends/client.go deleted file mode 100644 index a3ee80a..0000000 --- a/tunnel_group_backends/client.go +++ /dev/null @@ -1,205 +0,0 @@ -// 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 index 7318b05..5a78190 100644 --- a/tunnel_sessions/client.go +++ b/tunnel_sessions/client.go @@ -5,7 +5,6 @@ package tunnel_sessions import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -21,10 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } // List all online tunnel sessions running on this account. -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.TunnelSessionList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.TunnelSessionList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/tunnel_sessions")).Execute(&path, arg); err != nil { @@ -50,24 +52,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all online tunnel sessions running on this account. +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.TunnelSession - err error + client *Client + ctx context.Context + n int + items []ngrok.TunnelSession + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -77,18 +92,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -96,25 +107,31 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.TunnelSessions - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the TunnelSession currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.TunnelSession { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. 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 { @@ -138,11 +155,13 @@ func (c *Client) Get( // 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) @@ -164,11 +183,13 @@ func (c *Client) Restart( // 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) @@ -200,11 +221,13 @@ func (c *Client) Stop( // 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) diff --git a/tunnels/client.go b/tunnels/client.go index 7b028ad..1270a4c 100644 --- a/tunnels/client.go +++ b/tunnels/client.go @@ -5,7 +5,6 @@ package tunnels import ( "bytes" "context" - "fmt" "net/url" "text/template" @@ -21,10 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client { } // List all online tunnels currently running on the account. -func (c *Client) List( +func (c *Client) list( ctx context.Context, - arg *ngrok.Page, + arg *ngrok.Paging, ) (*ngrok.TunnelList, error) { + if arg == nil { + arg = new(ngrok.Paging) + } var res ngrok.TunnelList var path bytes.Buffer if err := template.Must(template.New("list_path").Parse("/tunnels")).Execute(&path, arg); err != nil { @@ -50,24 +52,37 @@ func (c *Client) List( return &res, nil } -func (c *Client) Iter(ctx context.Context) *Iter { +// List all online tunnels currently running on the account. +func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter { + if paging == nil { + paging = new(ngrok.Paging) + } + if paging.Limit == nil { + paging.Limit = ngrok.String("100") + } return &Iter{ - client: c, - ctx: ctx, - limit: 100, - n: -1, + client: c, + ctx: ctx, + limit: paging.Limit, + lastItemID: paging.BeforeID, + n: -1, } } +// Iter allows the caller to iterate through a list of values while +// automatically fetching new pages worth of values from the API. type Iter struct { - client *Client - ctx context.Context - n int - limit int - items []ngrok.Tunnel - err error + client *Client + ctx context.Context + n int + items []ngrok.Tunnel + err error + limit *string + lastItemID *string } +// Next() returns true if there is another value available in the iterator. If it +// returs true it also advances the iterator to that next available item. func (it *Iter) Next() bool { // no more if there is an error if it.err != nil { @@ -77,18 +92,14 @@ func (it *Iter) Next() bool { // are there items remaining? if it.n < len(it.items)-1 { it.n += 1 + it.lastItemID = ngrok.String(it.Item().ID) 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)), + resp, err := it.client.list(it.ctx, &ngrok.Paging{ + BeforeID: it.lastItemID, + Limit: it.limit, }) if err != nil { it.err = err @@ -96,14 +107,18 @@ func (it *Iter) Next() bool { } it.n = 0 it.items = resp.Tunnels - fmt.Println(len(it.items), it.items) return len(it.items) > 0 } +// Item() returns the Tunnel currently +// pointed to by the iterator. func (it *Iter) Item() *ngrok.Tunnel { return &it.items[it.n] } +// If Next() returned false because an error was encountered while fetching the +// next value Err() will return that error. A caller should always check Err() +// after Next() returns false. func (it *Iter) Err() error { return it.err } diff --git a/weighted_backends/client.go b/weighted_backends/client.go deleted file mode 100644 index ee748e4..0000000 --- a/weighted_backends/client.go +++ /dev/null @@ -1,205 +0,0 @@ -// 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 -}