mirror of
https://github.com/ngrok/ngrok-api-go.git
synced 2026-05-17 16:50:37 +00:00
@@ -0,0 +1,70 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package abuse_reports
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Creates a new abuse report which will be reviewed by our system and abuse
|
||||
// response team. This API is only available to authorized accounts. Contact
|
||||
// abuse@ngrok.com to request access
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.AbuseReportCreate,
|
||||
) (*ngrok.AbuseReport, error) {
|
||||
var res ngrok.AbuseReport
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/abuse_reports")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Get the detailed status of abuse report by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.AbuseReport, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.AbuseReport
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/abuse_reports/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package api_keys
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new API key. The generated API key can be used to authenticate to the
|
||||
// ngrok API.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.APIKeyCreate,
|
||||
) (*ngrok.APIKey, error) {
|
||||
var res ngrok.APIKey
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/api_keys")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an API key by ID
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/api_keys/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get the details of an API key by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.APIKey, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.APIKey
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/api_keys/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all API keys owned by this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.APIKeyList, error) {
|
||||
var res ngrok.APIKeyList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/api_keys")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.APIKey
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Keys
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.APIKey {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an API key by ID.
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.APIKeyUpdate,
|
||||
) (*ngrok.APIKey, error) {
|
||||
var res ngrok.APIKey
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/api_keys/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package certificate_authorities
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Upload a new Certificate Authority
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.CertificateAuthorityCreate,
|
||||
) (*ngrok.CertificateAuthority, error) {
|
||||
var res ngrok.CertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/certificate_authorities")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a Certificate Authority
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a certficate authority
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.CertificateAuthority, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.CertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all Certificate Authority on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.CertificateAuthorityList, error) {
|
||||
var res ngrok.CertificateAuthorityList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/certificate_authorities")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.CertificateAuthority
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.CertificateAuthorities
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.CertificateAuthority {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of a Certificate Authority by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.CertificateAuthorityUpdate,
|
||||
) (*ngrok.CertificateAuthority, error) {
|
||||
var res ngrok.CertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ngrok
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
const (
|
||||
apiVersion = "2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
cfg *clientConfig
|
||||
}
|
||||
|
||||
func NewClient(opts ...ClientOption) (*Client, error) {
|
||||
var cfg clientConfig
|
||||
if err := cfg.parseOptions(opts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{cfg: &cfg}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Do(ctx context.Context, method string, reqURL *url.URL, reqBody interface{}, respBody interface{}) error {
|
||||
req, err := c.buildRequest(ctx, method, reqURL, reqBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := c.cfg.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = c.readResponse(resp, respBody); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) buildRequest(ctx context.Context, method string, reqURL *url.URL, reqBody interface{}) (*http.Request, error) {
|
||||
body, err := c.buildRequestBody(reqBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqURLString := c.cfg.baseURL.ResolveReference(reqURL).String()
|
||||
r, err := http.NewRequestWithContext(ctx, method, reqURLString, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.Header.Set("authorization", fmt.Sprintf("Bearer %s", c.cfg.apiKey))
|
||||
//r.Header.Set("user-agent", "github.com/ngrok/ngrok-api-go")
|
||||
r.Header.Set("ngrok-version", apiVersion)
|
||||
if body != nil {
|
||||
r.Header.Set("content-type", "application/json")
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (c *Client) buildRequestBody(reqBody interface{}) (io.Reader, error) {
|
||||
if reqBody == nil {
|
||||
return nil, nil
|
||||
}
|
||||
jsonBytes, err := json.Marshal(reqBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bytes.NewReader(jsonBytes), nil
|
||||
}
|
||||
|
||||
func (c *Client) readResponse(resp *http.Response, out interface{}) error {
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
if resp.StatusCode >= 400 {
|
||||
return c.readErrorResponse(resp)
|
||||
}
|
||||
return c.readResponseBody(resp, out)
|
||||
}
|
||||
|
||||
// read an error response body
|
||||
func (c *Client) readErrorResponse(resp *http.Response) error {
|
||||
var out Error
|
||||
err := c.readResponseBody(resp, &out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
// unmarshal a response body
|
||||
func (c *Client) readResponseBody(resp *http.Response, out interface{}) error {
|
||||
if out == nil {
|
||||
return nil
|
||||
}
|
||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return c.buildUnmarshalError(resp, bodyBytes, err)
|
||||
}
|
||||
if err := json.Unmarshal(bodyBytes, out); err != nil {
|
||||
return c.buildUnmarshalError(resp, bodyBytes, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// if an error occurs while trying to read a response body, construct a new
|
||||
// error explaining the unmarshalling failure
|
||||
func (c *Client) buildUnmarshalError(resp *http.Response, bodyBytes []byte, err error) error {
|
||||
return &Error{
|
||||
Msg: fmt.Sprintf("failed to unmarshal response body: %s. body: %s", err, bodyBytes),
|
||||
StatusCode: int32(resp.StatusCode),
|
||||
Details: map[string]string{
|
||||
"unmarshal_error": err.Error(),
|
||||
"invalid_body": string(bodyBytes),
|
||||
"operation_id": resp.Header.Get("ngrok-operation-id"),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package ngrok
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultBaseURL, _ = url.Parse("https://api.ngrok.com")
|
||||
)
|
||||
|
||||
type clientConfig struct {
|
||||
apiKey string
|
||||
baseURL *url.URL
|
||||
debug Debug
|
||||
httpClient *http.Client
|
||||
err error
|
||||
}
|
||||
|
||||
type ClientOption func(cc *clientConfig)
|
||||
|
||||
func (cc *clientConfig) parseOptions(opts []ClientOption) error {
|
||||
for _, o := range opts {
|
||||
o(cc)
|
||||
}
|
||||
cc.setDefaults()
|
||||
return cc.err
|
||||
}
|
||||
|
||||
func (c *clientConfig) setDefaults() {
|
||||
if c.httpClient == nil {
|
||||
c.httpClient = http.DefaultClient
|
||||
}
|
||||
if c.baseURL == nil {
|
||||
c.baseURL = defaultBaseURL
|
||||
}
|
||||
if c.apiKey == "" {
|
||||
c.apiKey = os.Getenv("NGROK_API_KEY")
|
||||
}
|
||||
}
|
||||
|
||||
func WithAPIKey(apiKey string) ClientOption {
|
||||
return func(cc *clientConfig) {
|
||||
cc.apiKey = apiKey
|
||||
}
|
||||
}
|
||||
|
||||
func WithBaseURL(baseURL string) ClientOption {
|
||||
return func(cc *clientConfig) {
|
||||
cc.baseURL, cc.err = url.Parse(baseURL)
|
||||
}
|
||||
}
|
||||
|
||||
func WithDebug(debug Debug) ClientOption {
|
||||
return func(cc *clientConfig) {
|
||||
cc.debug = debug
|
||||
}
|
||||
}
|
||||
|
||||
func WithHTTPClient(httpClient *http.Client) ClientOption {
|
||||
return func(cc *clientConfig) {
|
||||
cc.httpClient = httpClient
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package credentials
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new tunnel authtoken credential. This authtoken credential can be used
|
||||
// to start a new tunnel session. The response to this API call is the only time
|
||||
// the generated token is available. If you need it for future use, you must save
|
||||
// it securely yourself.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.CredentialCreate,
|
||||
) (*ngrok.Credential, error) {
|
||||
var res ngrok.Credential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/credentials")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a tunnel authtoken credential by ID
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a tunnel authtoken credential
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.Credential, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.Credential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all tunnel authtoken credentials on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.CredentialList, error) {
|
||||
var res ngrok.CredentialList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/credentials")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.Credential
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Credentials
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.Credential {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an tunnel authtoken credential by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.CredentialUpdate,
|
||||
) (*ngrok.Credential, error) {
|
||||
var res ngrok.Credential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
+2277
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,153 @@
|
||||
package ngrok
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Debug struct {
|
||||
Stdout, Stderr io.Writer
|
||||
Verbose bool
|
||||
Include bool
|
||||
DryRun bool
|
||||
}
|
||||
|
||||
// implements the io.TeeReader logic, but closes the writer when the reader
|
||||
// completes
|
||||
type teeReaderCloser struct {
|
||||
r io.Reader
|
||||
w io.WriteCloser
|
||||
done <-chan struct{}
|
||||
}
|
||||
|
||||
func (r teeReaderCloser) Read(p []byte) (n int, err error) {
|
||||
n, err = r.r.Read(p)
|
||||
if n > 0 {
|
||||
if n, err := r.w.Write(p[:n]); err != nil {
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
if errors.Is(err, io.EOF) {
|
||||
r.w.Close()
|
||||
<-r.done
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (d Debug) makeRequest(ctx context.Context, body io.Reader) (context.Context, io.Reader) {
|
||||
if (!d.Verbose && !d.DryRun) || d.Stderr == nil {
|
||||
return ctx, body
|
||||
}
|
||||
|
||||
ctx = httptrace.WithClientTrace(ctx, &httptrace.ClientTrace{
|
||||
WroteHeaderField: func(key string, value []string) {
|
||||
fmt.Fprintf(d.Stderr, "> %s: %s\n", key, value)
|
||||
},
|
||||
WroteHeaders: func() {
|
||||
fmt.Fprintln(d.Stderr)
|
||||
},
|
||||
})
|
||||
|
||||
if body != nil {
|
||||
ch := make(chan struct{})
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
body = teeReaderCloser{
|
||||
r: body,
|
||||
w: pw,
|
||||
done: ch,
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer close(ch)
|
||||
decoder := json.NewDecoder(pr)
|
||||
for decoder.More() {
|
||||
var i interface{}
|
||||
if err := decoder.Decode(&i); err == nil {
|
||||
enc := json.NewEncoder(d.Stderr)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(i)
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(d.Stderr)
|
||||
}()
|
||||
}
|
||||
|
||||
return ctx, body
|
||||
}
|
||||
|
||||
func (d Debug) printResponse(r *http.Response) {
|
||||
if d.Stderr != nil {
|
||||
// status
|
||||
if d.Verbose {
|
||||
fmt.Fprintf(d.Stderr, "Status: %s\n", r.Status)
|
||||
} else {
|
||||
fmt.Fprintln(d.Stderr, r.Status)
|
||||
}
|
||||
|
||||
// headers
|
||||
if d.Verbose || d.Include {
|
||||
fmt.Fprintln(d.Stderr)
|
||||
for k, v := range r.Header {
|
||||
fmt.Fprintf(d.Stderr, "< %s: %v\n", k, v)
|
||||
}
|
||||
fmt.Fprintln(d.Stderr)
|
||||
}
|
||||
}
|
||||
|
||||
if d.Stdout != nil && (r.StatusCode < 400 || d.Verbose) {
|
||||
body, _ := ioutil.ReadAll(r.Body)
|
||||
r.Body.Close()
|
||||
r.Body = ioutil.NopCloser(bytes.NewReader(body))
|
||||
|
||||
var i interface{}
|
||||
if err := json.Unmarshal(body, &i); err == nil {
|
||||
enc := json.NewEncoder(d.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(i)
|
||||
} else {
|
||||
fmt.Fprint(d.Stdout, string(body))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type eofReader struct{}
|
||||
|
||||
func (eofReader) Read([]byte) (int, error) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func emptyHTTPResponse(req *http.Request) *http.Response {
|
||||
return &http.Response{
|
||||
Body: ioutil.NopCloser(eofReader{}),
|
||||
Header: http.Header{},
|
||||
Trailer: http.Header{},
|
||||
Request: req,
|
||||
}
|
||||
}
|
||||
|
||||
func (d Debug) dryRunResponse(req *http.Request) (*http.Response, error) {
|
||||
if d.Verbose && d.Stderr != nil {
|
||||
fmt.Fprintf(d.Stderr, "> :authority: [%s]\n", req.URL.Hostname())
|
||||
fmt.Fprintf(d.Stderr, "> :method: [%s]\n", req.Method)
|
||||
fmt.Fprintf(d.Stderr, "> :path: [%s]\n", req.URL.Path)
|
||||
fmt.Fprintf(d.Stderr, "> :scheme: [%s]\n", req.URL.Scheme)
|
||||
for k, v := range req.Header {
|
||||
fmt.Fprintf(d.Stderr, "> %s: %s\n", strings.ToLower(k), v)
|
||||
}
|
||||
fmt.Fprintln(d.Stderr)
|
||||
}
|
||||
if req.Body != nil {
|
||||
// if Verbose this causes the request to be printed to stderr
|
||||
ioutil.ReadAll(req.Body)
|
||||
}
|
||||
return emptyHTTPResponse(req), nil
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_backend_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointBackend, error) {
|
||||
arg := &ngrok.EndpointBackendReplace{ID: id}
|
||||
var res ngrok.EndpointBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/backend")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/backend")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/backend")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_basic_auth_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointBasicAuth, error) {
|
||||
arg := &ngrok.EndpointBasicAuthReplace{ID: id}
|
||||
var res ngrok.EndpointBasicAuth
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/basic_auth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointBasicAuth, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointBasicAuth
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/basic_auth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/basic_auth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_circuit_breaker_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointCircuitBreakerReplace,
|
||||
) (*ngrok.EndpointCircuitBreaker, error) {
|
||||
var res ngrok.EndpointCircuitBreaker
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/circuit_breaker")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointCircuitBreaker, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointCircuitBreaker
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/circuit_breaker")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/circuit_breaker")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_compression_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointCompressionReplace,
|
||||
) (*ngrok.EndpointCompression, error) {
|
||||
var res ngrok.EndpointCompression
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/compression")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointCompression, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointCompression
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/compression")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/compression")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_configurations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
// Endpoint Configuration managementAn
|
||||
// (https://ngrok.com/docs/ngrok-link#api-endpoint-configurations)Endpoint
|
||||
// Configuration describes
|
||||
// a ngrok network endpoint instance.Endpoints are your gateway to ngrok features!
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new endpoint configuration
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointConfigurationCreate,
|
||||
) (*ngrok.EndpointConfiguration, error) {
|
||||
var res ngrok.EndpointConfiguration
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/endpoint_configurations")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an endpoint configuration. This operation will fail if the endpoint
|
||||
// configuration is still referenced by any reserved domain or reserved address.
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns detailed information about an endpoint configuration
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointConfiguration, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointConfiguration
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Returns a list of all endpoint configurations on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.EndpointConfigurationList, error) {
|
||||
var res ngrok.EndpointConfigurationList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/endpoint_configurations")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.EndpointConfiguration
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.EndpointConfigurations
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.EndpointConfiguration {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Updates an endpoint configuration. If a module is not specified in the update,
|
||||
// it will not be modified. However, each module configuration that is specified
|
||||
// will completely replace the existing value. There is no way to delete an
|
||||
// existing module via this API, instead use the delete module API.
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointConfigurationUpdate,
|
||||
) (*ngrok.EndpointConfiguration, error) {
|
||||
var res ngrok.EndpointConfiguration
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/endpoint_configurations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_ip_policy_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointIPPolicyReplace,
|
||||
) (*ngrok.EndpointIPPolicy, error) {
|
||||
var res ngrok.EndpointIPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/ip_policy")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointIPPolicy, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointIPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/ip_policy")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/ip_policy")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_logging_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointLoggingReplace,
|
||||
) (*ngrok.EndpointLogging, error) {
|
||||
var res ngrok.EndpointLogging
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/logging")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointLogging, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointLogging
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/logging")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/logging")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_mutual_tls_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointMutualTLSReplace,
|
||||
) (*ngrok.EndpointMutualTLS, error) {
|
||||
var res ngrok.EndpointMutualTLS
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/mutual_tls")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointMutualTLS, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointMutualTLS
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/mutual_tls")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/mutual_tls")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_o_auth_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointOAuthReplace,
|
||||
) (*ngrok.EndpointOAuth, error) {
|
||||
var res ngrok.EndpointOAuth
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/oauth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointOAuth, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointOAuth
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/oauth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/oauth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_oidc_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointOIDCReplace,
|
||||
) (*ngrok.EndpointOIDC, error) {
|
||||
var res ngrok.EndpointOIDC
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/oidc")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointOIDC, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointOIDC
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/oidc")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/oidc")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_request_headers_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointRequestHeadersReplace,
|
||||
) (*ngrok.EndpointRequestHeaders, error) {
|
||||
var res ngrok.EndpointRequestHeaders
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/request_headers")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointRequestHeaders, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointRequestHeaders
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/request_headers")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/request_headers")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_response_headers_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointResponseHeadersReplace,
|
||||
) (*ngrok.EndpointResponseHeaders, error) {
|
||||
var res ngrok.EndpointResponseHeaders
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/response_headers")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointResponseHeaders, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointResponseHeaders
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/response_headers")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/response_headers")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_saml_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointSAMLReplace,
|
||||
) (*ngrok.EndpointSAML, error) {
|
||||
var res ngrok.EndpointSAML
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/saml")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointSAML, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointSAML
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/saml")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/saml")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_tls_termination_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointTLSTerminationReplace,
|
||||
) (*ngrok.EndpointTLSTermination, error) {
|
||||
var res ngrok.EndpointTLSTermination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/tls_termination")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointTLSTermination, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointTLSTermination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/tls_termination")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/tls_termination")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_webhook_validation_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointWebhookValidationReplace,
|
||||
) (*ngrok.EndpointWebhookValidation, error) {
|
||||
var res ngrok.EndpointWebhookValidation
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/webhook_validation")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointWebhookValidation, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointWebhookValidation
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/webhook_validation")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/webhook_validation")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package ngrok
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Returns true if the error is a not found response from the ngrok API.
|
||||
func IsNotFound(err error) bool {
|
||||
if ee, ok := err.(*Error); ok {
|
||||
return int(ee.StatusCode) == http.StatusNotFound
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Returns true if the given error is caused by any of the specified ngrok error codes.
|
||||
func IsErrorCode(err error, codes ...int) bool {
|
||||
if ee, ok := err.(*Error); ok {
|
||||
for _, code := range codes {
|
||||
if ee.ErrorCode == fmt.Sprintf("ERR_NGROK_%d", code) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e *Error) Error() string {
|
||||
msg := fmt.Sprintf("HTTP %d: %s", e.StatusCode, e.Msg)
|
||||
if e.ErrorCode != "" {
|
||||
msg += fmt.Sprintf(" [%s]", e.ErrorCode)
|
||||
}
|
||||
if e.operationID() != "" {
|
||||
msg += fmt.Sprintf("\n\nOperation ID: %s", e.operationID())
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func (e *Error) operationID() string {
|
||||
return e.Details["operation_id"]
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package event_destinations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new Event Destination. It will not apply to anything until it is
|
||||
// associated with an Event Stream, and that Event Stream is associated with an
|
||||
// Endpoint Config.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventDestinationCreate,
|
||||
) (*ngrok.EventDestination, error) {
|
||||
var res ngrok.EventDestination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/event_destinations")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an Event Destination. If the Event Destination is still referenced by an
|
||||
// Event Stream, this will throw an error until that Event Stream has removed that
|
||||
// reference.
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/event_destinations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an Event Destination by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EventDestination, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EventDestination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/event_destinations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all Event Destinations on this account.
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.EventDestinationList, error) {
|
||||
var res ngrok.EventDestinationList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/event_destinations")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.EventDestination
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.EventDestinations
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.EventDestination {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an Event Destination.
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventDestinationUpdate,
|
||||
) (*ngrok.EventDestination, error) {
|
||||
var res ngrok.EventDestination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/event_destinations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Send a test event to an Event Destination
|
||||
func (c *Client) SendTestEvent(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SentEvent, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.SentEvent
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("send_test_event_path").Parse("/event_destinations/{{ .ID }}/send_test_event")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package event_sources
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSourceCreate,
|
||||
) (*ngrok.EventSource, error) {
|
||||
var res ngrok.EventSource
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSourceItem,
|
||||
) error {
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
arg.Type = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSourceItem,
|
||||
) (*ngrok.EventSource, error) {
|
||||
var res ngrok.EventSource
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
arg.Type = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
subscriptionId string,
|
||||
|
||||
) (*ngrok.EventSourceList, error) {
|
||||
arg := &ngrok.EventSourcePage{SubscriptionID: subscriptionId}
|
||||
var res ngrok.EventSourceList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSourceUpdate,
|
||||
) (*ngrok.EventSource, error) {
|
||||
var res ngrok.EventSource
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
arg.Type = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package event_streams
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new Event Stream. It will not apply to anything until you associate it
|
||||
// with one or more Endpoint Configs.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventStreamCreate,
|
||||
) (*ngrok.EventStream, error) {
|
||||
var res ngrok.EventStream
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/event_streams")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an Event Stream. Associated Event Destinations will be preserved.
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/event_streams/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an Event Stream by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EventStream, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EventStream
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/event_streams/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all Event Streams available on this account.
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.EventStreamList, error) {
|
||||
var res ngrok.EventStreamList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/event_streams")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.EventStream
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.EventStreams
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.EventStream {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an Event Stream by ID.
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventStreamUpdate,
|
||||
) (*ngrok.EventStream, error) {
|
||||
var res ngrok.EventStream
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/event_streams/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package event_subscriptions
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create an Event Subscription.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSubscriptionCreate,
|
||||
) (*ngrok.EventSubscription, error) {
|
||||
var res ngrok.EventSubscription
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/event_subscriptions")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/event_subscriptions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get an Event Subscription by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EventSubscription, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EventSubscription
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/event_subscriptions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List this Account's Event Subscriptions.
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.EventSubscriptionList, error) {
|
||||
var res ngrok.EventSubscriptionList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/event_subscriptions")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.EventSubscription
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.EventSubscriptions
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.EventSubscription {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSubscriptionUpdate,
|
||||
) (*ngrok.EventSubscription, error) {
|
||||
var res ngrok.EventSubscription
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/event_subscriptions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
module github.com/ngrok/ngrok-api-go
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/stretchr/testify v1.7.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
)
|
||||
@@ -0,0 +1,208 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ip_policies
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new IP policy. It will not apply to any traffic until you associate to
|
||||
// a traffic source via an endpoint configuration or IP restriction.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPPolicyCreate,
|
||||
) (*ngrok.IPPolicy, error) {
|
||||
var res ngrok.IPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ip_policies")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an IP policy. If the IP policy is referenced by another object for the
|
||||
// purposes of traffic restriction it will be treated as if the IP policy remains
|
||||
// but has zero rules.
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ip_policies/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an IP policy by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.IPPolicy, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.IPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ip_policies/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all IP policies on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.IPPolicyList, error) {
|
||||
var res ngrok.IPPolicyList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ip_policies")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.IPPolicy
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.IPPolicies
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.IPPolicy {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an IP policy by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPPolicyUpdate,
|
||||
) (*ngrok.IPPolicy, error) {
|
||||
var res ngrok.IPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ip_policies/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ip_policy_rules
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new IP policy rule attached to an IP Policy.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPPolicyRuleCreate,
|
||||
) (*ngrok.IPPolicyRule, error) {
|
||||
var res ngrok.IPPolicyRule
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ip_policy_rules")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an IP policy rule.
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ip_policy_rules/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an IP policy rule by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.IPPolicyRule, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.IPPolicyRule
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ip_policy_rules/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all IP policy rules on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.IPPolicyRuleList, error) {
|
||||
var res ngrok.IPPolicyRuleList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ip_policy_rules")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.IPPolicyRule
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.IPPolicyRules
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.IPPolicyRule {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an IP policy rule by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPPolicyRuleUpdate,
|
||||
) (*ngrok.IPPolicyRule, error) {
|
||||
var res ngrok.IPPolicyRule
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ip_policy_rules/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ip_restrictions
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new IP restriction
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPRestrictionCreate,
|
||||
) (*ngrok.IPRestriction, error) {
|
||||
var res ngrok.IPRestriction
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ip_restrictions")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an IP restriction
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ip_restrictions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an IP restriction
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.IPRestriction, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.IPRestriction
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ip_restrictions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all IP restrictions on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.IPRestrictionList, error) {
|
||||
var res ngrok.IPRestrictionList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ip_restrictions")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.IPRestriction
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.IPRestrictions
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.IPRestriction {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an IP restriction by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPRestrictionUpdate,
|
||||
) (*ngrok.IPRestriction, error) {
|
||||
var res ngrok.IPRestriction
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ip_restrictions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ip_whitelist
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new IP whitelist entry that will restrict traffic to all tunnel
|
||||
// endpoints on the account.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPWhitelistEntryCreate,
|
||||
) (*ngrok.IPWhitelistEntry, error) {
|
||||
var res ngrok.IPWhitelistEntry
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ip_whitelist")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an IP whitelist entry.
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ip_whitelist/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an IP whitelist entry by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.IPWhitelistEntry, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.IPWhitelistEntry
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ip_whitelist/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all IP whitelist entries on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.IPWhitelistEntryList, error) {
|
||||
var res ngrok.IPWhitelistEntryList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ip_whitelist")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.IPWhitelistEntry
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Whitelist
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.IPWhitelistEntry {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an IP whitelist entry by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPWhitelistEntryUpdate,
|
||||
) (*ngrok.IPWhitelistEntry, error) {
|
||||
var res ngrok.IPWhitelistEntry
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ip_whitelist/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package ngrok_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
"github.com/ngrok/ngrok-api-go/ip_policies"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIPPolicy(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
c, err := ngrok.NewClient()
|
||||
require.NoError(t, err)
|
||||
|
||||
policies := ip_policies.NewClient(c)
|
||||
|
||||
// test that a list call works
|
||||
_, err = policies.List(ctx, &ngrok.Page{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// test policy creation
|
||||
createInstance, err := policies.Create(ctx, &ngrok.IPPolicyCreate{
|
||||
Action: "allow",
|
||||
Description: "ngrok-api-go tests",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// test get
|
||||
getInstance, err := policies.Get(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, createInstance, getInstance)
|
||||
|
||||
// test update
|
||||
metadata := `{"device-id": "malamute-12"`
|
||||
updatedInstance, err := policies.Update(ctx, &ngrok.IPPolicyUpdate{
|
||||
ID: createInstance.ID,
|
||||
Metadata: ngrok.String(metadata),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, updatedInstance.Metadata, metadata)
|
||||
|
||||
// test get after update
|
||||
getAfterUpdateInstance, err := policies.Get(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, updatedInstance, getAfterUpdateInstance)
|
||||
|
||||
iter := policies.Iter(ctx)
|
||||
var iterPolicies []*ngrok.IPPolicy
|
||||
for iter.Next() {
|
||||
iterPolicies = append(iterPolicies, iter.Item())
|
||||
}
|
||||
require.NoError(t, iter.Err())
|
||||
require.Contains(t, iterPolicies, updatedInstance)
|
||||
|
||||
// test delete
|
||||
err = policies.Delete(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// test 404
|
||||
_, err = policies.Get(ctx, createInstance.ID)
|
||||
require.True(t, ngrok.IsNotFound(err))
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package priority_backends
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new Priority backend
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.PriorityBackendCreate,
|
||||
) (*ngrok.PriorityBackend, error) {
|
||||
var res ngrok.PriorityBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/backends/priority")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a Priority backend by ID. TODO what if used?
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/backends/priority/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a Priority backend by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.PriorityBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.PriorityBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/backends/priority/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all Priority backends on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.PriorityBackendList, error) {
|
||||
var res ngrok.PriorityBackendList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/backends/priority")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.PriorityBackend
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Backends
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.PriorityBackend {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update Priority backend by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.PriorityBackendUpdate,
|
||||
) (*ngrok.PriorityBackend, error) {
|
||||
var res ngrok.PriorityBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/backends/priority/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package reserved_addrs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new reserved address.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.ReservedAddrCreate,
|
||||
) (*ngrok.ReservedAddr, error) {
|
||||
var res ngrok.ReservedAddr
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/reserved_addrs")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a reserved address.
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/reserved_addrs/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get the details of a reserved address.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.ReservedAddr, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.ReservedAddr
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/reserved_addrs/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all reserved addresses on this account.
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.ReservedAddrList, error) {
|
||||
var res ngrok.ReservedAddrList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/reserved_addrs")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.ReservedAddr
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.ReservedAddrs
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.ReservedAddr {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update the attributes of a reserved address.
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.ReservedAddrUpdate,
|
||||
) (*ngrok.ReservedAddr, error) {
|
||||
var res ngrok.ReservedAddr
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/reserved_addrs/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Detach the endpoint configuration attached to a reserved address.
|
||||
func (c *Client) DeleteEndpointConfig(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_endpoint_config_path").Parse("/reserved_addrs/{{ .ID }}/endpoint_configuration")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package reserved_domains
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new reserved domain.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.ReservedDomainCreate,
|
||||
) (*ngrok.ReservedDomain, error) {
|
||||
var res ngrok.ReservedDomain
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/reserved_domains")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a reserved domain.
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/reserved_domains/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get the details of a reserved domain.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.ReservedDomain, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.ReservedDomain
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/reserved_domains/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all reserved domains on this account.
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.ReservedDomainList, error) {
|
||||
var res ngrok.ReservedDomainList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/reserved_domains")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.ReservedDomain
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.ReservedDomains
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.ReservedDomain {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update the attributes of a reserved domain.
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.ReservedDomainUpdate,
|
||||
) (*ngrok.ReservedDomain, error) {
|
||||
var res ngrok.ReservedDomain
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/reserved_domains/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Detach the certificate management policy attached to a reserved domain.
|
||||
func (c *Client) DeleteCertificateManagementPolicy(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_certificate_management_policy_path").Parse("/reserved_domains/{{ .ID }}/certificate_management_policy")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Detach the certificate attached to a reserved domain.
|
||||
func (c *Client) DeleteCertificate(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_certificate_path").Parse("/reserved_domains/{{ .ID }}/certificate")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Detach the http endpoint configuration attached to a reserved domain.
|
||||
func (c *Client) DeleteHTTPEndpointConfig(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_http_endpoint_config_path").Parse("/reserved_domains/{{ .ID }}/http_endpoint_configuration")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Detach the https endpoint configuration attached to a reserved domain.
|
||||
func (c *Client) DeleteHTTPSEndpointConfig(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_https_endpoint_config_path").Parse("/reserved_domains/{{ .ID }}/https_endpoint_configuration")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package root
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Empty,
|
||||
) (*ngrok.RootResponse, error) {
|
||||
var res ngrok.RootResponse
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ssh_certificate_authorities
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new SSH Certificate Authority
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHCertificateAuthorityCreate,
|
||||
) (*ngrok.SSHCertificateAuthority, error) {
|
||||
var res ngrok.SSHCertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ssh_certificate_authorities")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an SSH Certificate Authority
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ssh_certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an SSH Certficate Authority
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SSHCertificateAuthority, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.SSHCertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ssh_certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all SSH Certificate Authorities on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.SSHCertificateAuthorityList, error) {
|
||||
var res ngrok.SSHCertificateAuthorityList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ssh_certificate_authorities")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.SSHCertificateAuthority
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.SSHCertificateAuthorities
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.SSHCertificateAuthority {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update an SSH Certificate Authority
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHCertificateAuthorityUpdate,
|
||||
) (*ngrok.SSHCertificateAuthority, error) {
|
||||
var res ngrok.SSHCertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ssh_certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ssh_credentials
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new ssh_credential from an uploaded public SSH key. This ssh credential
|
||||
// can be used to start new tunnels via ngrok's SSH gateway.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHCredentialCreate,
|
||||
) (*ngrok.SSHCredential, error) {
|
||||
var res ngrok.SSHCredential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ssh_credentials")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an ssh_credential by ID
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ssh_credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an ssh_credential
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SSHCredential, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.SSHCredential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ssh_credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all ssh credentials on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.SSHCredentialList, error) {
|
||||
var res ngrok.SSHCredentialList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ssh_credentials")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.SSHCredential
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.SSHCredentials
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.SSHCredential {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an ssh_credential by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHCredentialUpdate,
|
||||
) (*ngrok.SSHCredential, error) {
|
||||
var res ngrok.SSHCredential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ssh_credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ssh_host_certificates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new SSH Host Certificate
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHHostCertificateCreate,
|
||||
) (*ngrok.SSHHostCertificate, error) {
|
||||
var res ngrok.SSHHostCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ssh_host_certificates")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an SSH Host Certificate
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ssh_host_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an SSH Host Certficate
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SSHHostCertificate, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.SSHHostCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ssh_host_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all SSH Host Certificates issued on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.SSHHostCertificateList, error) {
|
||||
var res ngrok.SSHHostCertificateList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ssh_host_certificates")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.SSHHostCertificate
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.SSHHostCertificates
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.SSHHostCertificate {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update an SSH Host Certificate
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHHostCertificateUpdate,
|
||||
) (*ngrok.SSHHostCertificate, error) {
|
||||
var res ngrok.SSHHostCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ssh_host_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ssh_user_certificates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new SSH User Certificate
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHUserCertificateCreate,
|
||||
) (*ngrok.SSHUserCertificate, error) {
|
||||
var res ngrok.SSHUserCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ssh_user_certificates")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete an SSH User Certificate
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ssh_user_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about an SSH User Certficate
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SSHUserCertificate, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.SSHUserCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ssh_user_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all SSH User Certificates issued on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.SSHUserCertificateList, error) {
|
||||
var res ngrok.SSHUserCertificateList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ssh_user_certificates")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.SSHUserCertificate
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.SSHUserCertificates
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.SSHUserCertificate {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update an SSH User Certificate
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHUserCertificateUpdate,
|
||||
) (*ngrok.SSHUserCertificate, error) {
|
||||
var res ngrok.SSHUserCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ssh_user_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package static_backends
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new static backend
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.StaticBackendCreate,
|
||||
) (*ngrok.StaticBackend, error) {
|
||||
var res ngrok.StaticBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/backends/static")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a static backend by ID. TODO what if used?
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/backends/static/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a static backend by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.StaticBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.StaticBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/backends/static/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all static backends on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.StaticBackendList, error) {
|
||||
var res ngrok.StaticBackendList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/backends/static")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.StaticBackend
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Backends
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.StaticBackend {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update static backend by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.StaticBackendUpdate,
|
||||
) (*ngrok.StaticBackend, error) {
|
||||
var res ngrok.StaticBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/backends/static/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package tls_certificates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Upload a new TLS certificate
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.TLSCertificateCreate,
|
||||
) (*ngrok.TLSCertificate, error) {
|
||||
var res ngrok.TLSCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/tls_certificates")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a TLS certificate
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/tls_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a TLS certificate
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.TLSCertificate, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.TLSCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/tls_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all TLS certificates on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.TLSCertificateList, error) {
|
||||
var res ngrok.TLSCertificateList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/tls_certificates")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.TLSCertificate
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.TLSCertificates
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.TLSCertificate {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of a TLS Certificate by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.TLSCertificateUpdate,
|
||||
) (*ngrok.TLSCertificate, error) {
|
||||
var res ngrok.TLSCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/tls_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package tunnel_group_backends
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new TunnelGroup backend
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.TunnelGroupBackendCreate,
|
||||
) (*ngrok.TunnelGroupBackend, error) {
|
||||
var res ngrok.TunnelGroupBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/backends/tunnel-group")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a TunnelGroup backend by ID. TODO what if used?
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/backends/tunnel-group/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a TunnelGroup backend by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.TunnelGroupBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.TunnelGroupBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/backends/tunnel-group/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all TunnelGroup backends on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.TunnelGroupBackendList, error) {
|
||||
var res ngrok.TunnelGroupBackendList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/backends/tunnel-group")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.TunnelGroupBackend
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Backends
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.TunnelGroupBackend {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update TunnelGroup backend by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.TunnelGroupBackendUpdate,
|
||||
) (*ngrok.TunnelGroupBackend, error) {
|
||||
var res ngrok.TunnelGroupBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/backends/tunnel-group/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package tunnel_sessions
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// List all online tunnel sessions running on this account.
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.TunnelSessionList, error) {
|
||||
var res ngrok.TunnelSessionList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/tunnel_sessions")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.TunnelSession
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.TunnelSessions
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.TunnelSession {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Get the detailed status of a tunnel session by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.TunnelSession, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.TunnelSession
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/tunnel_sessions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Issues a command instructing the ngrok agent to restart. The agent restarts
|
||||
// itself by calling exec() on platforms that support it. This operation is notably
|
||||
// not supported on Windows. When an agent restarts, it reconnects with a new
|
||||
// tunnel session ID.
|
||||
func (c *Client) Restart(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("restart_path").Parse("/tunnel_sessions/{{ .ID }}/restart")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Issues a command instructing the ngrok agent that started this tunnel session to
|
||||
// exit.
|
||||
func (c *Client) Stop(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("stop_path").Parse("/tunnel_sessions/{{ .ID }}/stop")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Issues a command instructing the ngrok agent to update itself to the latest
|
||||
// version. After this call completes successfully, the ngrok agent will be in the
|
||||
// update process. A caller should wait some amount of time to allow the update to
|
||||
// complete (at least 10 seconds) before making a call to the Restart endpoint to
|
||||
// request that the agent restart itself to start using the new code. This call
|
||||
// will never update an ngrok agent to a new major version which could cause
|
||||
// breaking compatibility issues. If you wish to update to a new major version,
|
||||
// that must be done manually. Still, please be aware that updating your ngrok
|
||||
// agent could break your integration. This call will fail in any of the following
|
||||
// circumstances: there is no update available the ngrok agent's configuration
|
||||
// disabled update checks the agent is currently in process of updating the agent
|
||||
// has already successfully updated but has not yet been restarted
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.TunnelSessionsUpdate{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/tunnel_sessions/{{ .ID }}/update")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package tunnels
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// List all online tunnels currently running on the account.
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.TunnelList, error) {
|
||||
var res ngrok.TunnelList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/tunnels")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.Tunnel
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Tunnels
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.Tunnel {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ngrok
|
||||
|
||||
func Bool(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
||||
func String(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
func Uint32(v uint32) *uint32 {
|
||||
return &v
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package weighted_backends
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new Weighted backend
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.WeightedBackendCreate,
|
||||
) (*ngrok.WeightedBackend, error) {
|
||||
var res ngrok.WeightedBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/backends/weighted")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a Weighted backend by ID. TODO what if used?
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/backends/weighted/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a Weighted backend by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.WeightedBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.WeightedBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/backends/weighted/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all Weighted backends on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.WeightedBackendList, error) {
|
||||
var res ngrok.WeightedBackendList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/backends/weighted")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.WeightedBackend
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Backends
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.WeightedBackend {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update Weighted backend by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.WeightedBackendUpdate,
|
||||
) (*ngrok.WeightedBackend, error) {
|
||||
var res ngrok.WeightedBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/backends/weighted/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user