mirror of
https://github.com/ngrok/ngrok-api-go.git
synced 2026-05-17 16:50:37 +00:00
cut new release
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
Copyright 2021 ngrok, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,77 @@
|
||||
# ngrok API client library for Golang
|
||||
|
||||
This library wraps the [ngrok HTTP API](https://ngrok.com/docs/api) to make it
|
||||
easier to consume in Go.
|
||||
|
||||
## Installation
|
||||
|
||||
Installation is as simple as using `go get`.
|
||||
|
||||
go get github.com/ngrok/ngrok-api/go
|
||||
|
||||
## Documentation
|
||||
|
||||
A quickstart guide and a full API reference are included in the [ngrok go API documentation on pkg.go.dev](https://github.com/ngrok/ngrok-api-go)
|
||||
|
||||
## Quickstart
|
||||
|
||||
Please consult the [documentation](https://github.com/ngrok/ngrok-api-go) for additional examples.
|
||||
|
||||
### Create an IP Policy that allows traffic from some subnets
|
||||
|
||||
```go
|
||||
import (
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
"github.com/ngrok/ngrok-api-go/ip_policy"
|
||||
"github.com/ngrok/ngrok-api-go/ip_policy_rules"
|
||||
)
|
||||
|
||||
func example(ctx context.Context) error {
|
||||
// create clients to api resources
|
||||
apiClient := ngrok.NewClient("<API KEY>")
|
||||
policies := ip_policies.NewClient(apiClient)
|
||||
policyRules := ip_policy_rules.NewClient(apiClient)
|
||||
|
||||
// create the ip policy
|
||||
policy, err := ng.ip_policies.create(ctx, &ngrok.IPPolicyCreate{
|
||||
Action: "allow",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create rules for each cidr
|
||||
for _, cidr := range []string{"24.0.0.0/8", "12.0.0.0/8"} {
|
||||
policyRules.Create(ctx, &ngrok.IPPolicyRuleCreate{
|
||||
CIDR: cidr,
|
||||
IPPolicyID: policy.ID,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
### List all online tunnels
|
||||
|
||||
```go
|
||||
import (
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
"github.com/ngrok/ngrok-api-go/tunnels"
|
||||
)
|
||||
|
||||
func example(ctx context.Context) error {
|
||||
// construct the api client
|
||||
apiClient := ngrok.NewClient("<API KEY>")
|
||||
|
||||
// list all online tunnels
|
||||
tunnels := tunnels.NewClient(apiClient)
|
||||
iter := tunnels.List(ctx, nil)
|
||||
for iter.Next() {
|
||||
fmt.Println(iter.Item())
|
||||
}
|
||||
if err := iter.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
```
|
||||
@@ -23,6 +23,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
// response team. This API is only available to authorized accounts. Contact
|
||||
// abuse@ngrok.com to request access
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.AbuseReportCreate,
|
||||
) (*ngrok.AbuseReport, error) {
|
||||
@@ -46,11 +47,13 @@ func (c *Client) Create(
|
||||
|
||||
// Get the detailed status of abuse report by ID.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.AbuseReport, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.AbuseReport
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/abuse_reports/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
+50
-23
@@ -5,7 +5,6 @@ package api_keys
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -23,9 +22,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
// Create a new API key. The generated API key can be used to authenticate to the
|
||||
// ngrok API.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.APIKeyCreate,
|
||||
) (*ngrok.APIKey, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.APIKeyCreate)
|
||||
}
|
||||
var res ngrok.APIKey
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/api_keys")).Execute(&path, arg); err != nil {
|
||||
@@ -46,11 +49,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an API key by ID
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/api_keys/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -70,11 +75,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get the details of an API key by ID.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.APIKey, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.APIKey
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/api_keys/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -94,10 +101,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all API keys owned by this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.APIKeyList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.APIKeyList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/api_keys")).Execute(&path, arg); err != nil {
|
||||
@@ -123,24 +133,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all API keys owned by this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.APIKey
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.APIKey
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -150,18 +173,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -169,23 +188,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Keys
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the APIKey currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.APIKey {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an API key by ID.
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.APIKeyUpdate,
|
||||
) (*ngrok.APIKey, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.APIKeyUpdate)
|
||||
}
|
||||
var res ngrok.APIKey
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/api_keys/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -5,7 +5,6 @@ package certificate_authorities
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Upload a new Certificate Authority
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.CertificateAuthorityCreate,
|
||||
) (*ngrok.CertificateAuthority, error) {
|
||||
@@ -45,11 +45,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete a Certificate Authority
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +71,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about a certficate authority
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.CertificateAuthority, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.CertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +97,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all Certificate Authority on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.CertificateAuthorityList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.CertificateAuthorityList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/certificate_authorities")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +129,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all Certificate Authority on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.CertificateAuthority
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.CertificateAuthority
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +169,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +184,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.CertificateAuthorities
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the CertificateAuthority currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.CertificateAuthority {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of a Certificate Authority by ID
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.CertificateAuthorityUpdate,
|
||||
) (*ngrok.CertificateAuthority, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.CertificateAuthorityUpdate)
|
||||
}
|
||||
var res ngrok.CertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -18,15 +18,16 @@ const (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
cfg *clientConfig
|
||||
cfg *clientConfig
|
||||
apiKey string
|
||||
}
|
||||
|
||||
func NewClient(opts ...ClientOption) (*Client, error) {
|
||||
func NewClient(apiKey string, opts ...ClientOption) (*Client, error) {
|
||||
var cfg clientConfig
|
||||
if err := cfg.parseOptions(opts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{cfg: &cfg}, nil
|
||||
return &Client{apiKey: apiKey, cfg: &cfg}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Do(ctx context.Context, method string, reqURL *url.URL, reqBody interface{}, respBody interface{}) error {
|
||||
@@ -55,8 +56,8 @@ func (c *Client) buildRequest(ctx context.Context, method string, reqURL *url.UR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.Header.Set("authorization", fmt.Sprintf("Bearer %s", c.cfg.apiKey))
|
||||
//r.Header.Set("user-agent", "github.com/ngrok/ngrok-api-go")
|
||||
r.Header.Set("authorization", fmt.Sprintf("Bearer %s", c.apiKey))
|
||||
r.Header.Set("user-agent", "github.com/ngrok/ngrok-api-go")
|
||||
r.Header.Set("ngrok-version", apiVersion)
|
||||
if body != nil {
|
||||
r.Header.Set("content-type", "application/json")
|
||||
|
||||
@@ -3,7 +3,6 @@ package ngrok
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -11,9 +10,7 @@ var (
|
||||
)
|
||||
|
||||
type clientConfig struct {
|
||||
apiKey string
|
||||
baseURL *url.URL
|
||||
debug Debug
|
||||
httpClient *http.Client
|
||||
err error
|
||||
}
|
||||
@@ -35,15 +32,6 @@ func (c *clientConfig) setDefaults() {
|
||||
if c.baseURL == nil {
|
||||
c.baseURL = defaultBaseURL
|
||||
}
|
||||
if c.apiKey == "" {
|
||||
c.apiKey = os.Getenv("NGROK_API_KEY")
|
||||
}
|
||||
}
|
||||
|
||||
func WithAPIKey(apiKey string) ClientOption {
|
||||
return func(cc *clientConfig) {
|
||||
cc.apiKey = apiKey
|
||||
}
|
||||
}
|
||||
|
||||
func WithBaseURL(baseURL string) ClientOption {
|
||||
@@ -52,12 +40,6 @@ func WithBaseURL(baseURL string) ClientOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithDebug(debug Debug) ClientOption {
|
||||
return func(cc *clientConfig) {
|
||||
cc.debug = debug
|
||||
}
|
||||
}
|
||||
|
||||
func WithHTTPClient(httpClient *http.Client) ClientOption {
|
||||
return func(cc *clientConfig) {
|
||||
cc.httpClient = httpClient
|
||||
|
||||
+50
-23
@@ -5,7 +5,6 @@ package credentials
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -25,9 +24,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
// the generated token is available. If you need it for future use, you must save
|
||||
// it securely yourself.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.CredentialCreate,
|
||||
) (*ngrok.Credential, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.CredentialCreate)
|
||||
}
|
||||
var res ngrok.Credential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/credentials")).Execute(&path, arg); err != nil {
|
||||
@@ -48,11 +51,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete a tunnel authtoken credential by ID
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -72,11 +77,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about a tunnel authtoken credential
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.Credential, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.Credential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -96,10 +103,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all tunnel authtoken credentials on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.CredentialList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.CredentialList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/credentials")).Execute(&path, arg); err != nil {
|
||||
@@ -125,24 +135,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all tunnel authtoken credentials on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.Credential
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.Credential
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -152,18 +175,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -171,23 +190,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Credentials
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the Credential currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.Credential {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an tunnel authtoken credential by ID
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.CredentialUpdate,
|
||||
) (*ngrok.Credential, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.CredentialUpdate)
|
||||
}
|
||||
var res ngrok.Credential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
+2251
-376
File diff suppressed because it is too large
Load Diff
@@ -1,153 +0,0 @@
|
||||
package ngrok
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Debug struct {
|
||||
Stdout, Stderr io.Writer
|
||||
Verbose bool
|
||||
Include bool
|
||||
DryRun bool
|
||||
}
|
||||
|
||||
// implements the io.TeeReader logic, but closes the writer when the reader
|
||||
// completes
|
||||
type teeReaderCloser struct {
|
||||
r io.Reader
|
||||
w io.WriteCloser
|
||||
done <-chan struct{}
|
||||
}
|
||||
|
||||
func (r teeReaderCloser) Read(p []byte) (n int, err error) {
|
||||
n, err = r.r.Read(p)
|
||||
if n > 0 {
|
||||
if n, err := r.w.Write(p[:n]); err != nil {
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
if errors.Is(err, io.EOF) {
|
||||
r.w.Close()
|
||||
<-r.done
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (d Debug) makeRequest(ctx context.Context, body io.Reader) (context.Context, io.Reader) {
|
||||
if (!d.Verbose && !d.DryRun) || d.Stderr == nil {
|
||||
return ctx, body
|
||||
}
|
||||
|
||||
ctx = httptrace.WithClientTrace(ctx, &httptrace.ClientTrace{
|
||||
WroteHeaderField: func(key string, value []string) {
|
||||
fmt.Fprintf(d.Stderr, "> %s: %s\n", key, value)
|
||||
},
|
||||
WroteHeaders: func() {
|
||||
fmt.Fprintln(d.Stderr)
|
||||
},
|
||||
})
|
||||
|
||||
if body != nil {
|
||||
ch := make(chan struct{})
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
body = teeReaderCloser{
|
||||
r: body,
|
||||
w: pw,
|
||||
done: ch,
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer close(ch)
|
||||
decoder := json.NewDecoder(pr)
|
||||
for decoder.More() {
|
||||
var i interface{}
|
||||
if err := decoder.Decode(&i); err == nil {
|
||||
enc := json.NewEncoder(d.Stderr)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(i)
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(d.Stderr)
|
||||
}()
|
||||
}
|
||||
|
||||
return ctx, body
|
||||
}
|
||||
|
||||
func (d Debug) printResponse(r *http.Response) {
|
||||
if d.Stderr != nil {
|
||||
// status
|
||||
if d.Verbose {
|
||||
fmt.Fprintf(d.Stderr, "Status: %s\n", r.Status)
|
||||
} else {
|
||||
fmt.Fprintln(d.Stderr, r.Status)
|
||||
}
|
||||
|
||||
// headers
|
||||
if d.Verbose || d.Include {
|
||||
fmt.Fprintln(d.Stderr)
|
||||
for k, v := range r.Header {
|
||||
fmt.Fprintf(d.Stderr, "< %s: %v\n", k, v)
|
||||
}
|
||||
fmt.Fprintln(d.Stderr)
|
||||
}
|
||||
}
|
||||
|
||||
if d.Stdout != nil && (r.StatusCode < 400 || d.Verbose) {
|
||||
body, _ := ioutil.ReadAll(r.Body)
|
||||
r.Body.Close()
|
||||
r.Body = ioutil.NopCloser(bytes.NewReader(body))
|
||||
|
||||
var i interface{}
|
||||
if err := json.Unmarshal(body, &i); err == nil {
|
||||
enc := json.NewEncoder(d.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(i)
|
||||
} else {
|
||||
fmt.Fprint(d.Stdout, string(body))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type eofReader struct{}
|
||||
|
||||
func (eofReader) Read([]byte) (int, error) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func emptyHTTPResponse(req *http.Request) *http.Response {
|
||||
return &http.Response{
|
||||
Body: ioutil.NopCloser(eofReader{}),
|
||||
Header: http.Header{},
|
||||
Trailer: http.Header{},
|
||||
Request: req,
|
||||
}
|
||||
}
|
||||
|
||||
func (d Debug) dryRunResponse(req *http.Request) (*http.Response, error) {
|
||||
if d.Verbose && d.Stderr != nil {
|
||||
fmt.Fprintf(d.Stderr, "> :authority: [%s]\n", req.URL.Hostname())
|
||||
fmt.Fprintf(d.Stderr, "> :method: [%s]\n", req.Method)
|
||||
fmt.Fprintf(d.Stderr, "> :path: [%s]\n", req.URL.Path)
|
||||
fmt.Fprintf(d.Stderr, "> :scheme: [%s]\n", req.URL.Scheme)
|
||||
for k, v := range req.Header {
|
||||
fmt.Fprintf(d.Stderr, "> %s: %s\n", strings.ToLower(k), v)
|
||||
}
|
||||
fmt.Fprintln(d.Stderr)
|
||||
}
|
||||
if req.Body != nil {
|
||||
// if Verbose this causes the request to be printed to stderr
|
||||
ioutil.ReadAll(req.Body)
|
||||
}
|
||||
return emptyHTTPResponse(req), nil
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Package ngrok
|
||||
//
|
||||
// Quickstart
|
||||
//
|
||||
// Functional Option Configuration
|
||||
//
|
||||
// API Clients
|
||||
//
|
||||
// Nullable properties
|
||||
//
|
||||
// Transparent Paging
|
||||
//
|
||||
// Error Handling
|
||||
//
|
||||
// Pretty Printing (string and gostring)
|
||||
//
|
||||
// Examples
|
||||
package ngrok
|
||||
@@ -1,92 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_backend_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointBackend, error) {
|
||||
arg := &ngrok.EndpointBackendReplace{ID: id}
|
||||
var res ngrok.EndpointBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/backend")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/backend")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/backend")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_basic_auth_module
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointBasicAuth, error) {
|
||||
arg := &ngrok.EndpointBasicAuthReplace{ID: id}
|
||||
var res ngrok.EndpointBasicAuth
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/basic_auth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg.Module
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PUT", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointBasicAuth, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EndpointBasicAuth
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/basic_auth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/basic_auth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -5,7 +5,6 @@ package endpoint_configurations
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -27,9 +26,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Create a new endpoint configuration
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointConfigurationCreate,
|
||||
) (*ngrok.EndpointConfiguration, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointConfigurationCreate)
|
||||
}
|
||||
var res ngrok.EndpointConfiguration
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/endpoint_configurations")).Execute(&path, arg); err != nil {
|
||||
@@ -51,11 +54,13 @@ func (c *Client) Create(
|
||||
// Delete an endpoint configuration. This operation will fail if the endpoint
|
||||
// configuration is still referenced by any reserved domain or reserved address.
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -75,11 +80,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Returns detailed information about an endpoint configuration
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointConfiguration, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointConfiguration
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -99,10 +106,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// Returns a list of all endpoint configurations on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.EndpointConfigurationList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.EndpointConfigurationList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/endpoint_configurations")).Execute(&path, arg); err != nil {
|
||||
@@ -128,24 +138,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// Returns a list of all endpoint configurations on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.EndpointConfiguration
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.EndpointConfiguration
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -155,18 +178,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -174,14 +193,18 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.EndpointConfigurations
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the EndpointConfiguration currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.EndpointConfiguration {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
@@ -191,9 +214,13 @@ func (it *Iter) Err() error {
|
||||
// will completely replace the existing value. There is no way to delete an
|
||||
// existing module via this API, instead use the delete module API.
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointConfigurationUpdate,
|
||||
) (*ngrok.EndpointConfiguration, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointConfigurationUpdate)
|
||||
}
|
||||
var res ngrok.EndpointConfiguration
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/endpoint_configurations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -5,7 +5,6 @@ package event_destinations
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -24,9 +23,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
// associated with an Event Stream, and that Event Stream is associated with an
|
||||
// Endpoint Config.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventDestinationCreate,
|
||||
) (*ngrok.EventDestination, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EventDestinationCreate)
|
||||
}
|
||||
var res ngrok.EventDestination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/event_destinations")).Execute(&path, arg); err != nil {
|
||||
@@ -49,11 +52,13 @@ func (c *Client) Create(
|
||||
// Event Stream, this will throw an error until that Event Stream has removed that
|
||||
// reference.
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/event_destinations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -73,11 +78,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an Event Destination by ID.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EventDestination, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EventDestination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/event_destinations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -97,10 +104,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all Event Destinations on this account.
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.EventDestinationList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.EventDestinationList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/event_destinations")).Execute(&path, arg); err != nil {
|
||||
@@ -126,24 +136,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all Event Destinations on this account.
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.EventDestination
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.EventDestination
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -153,18 +176,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -172,23 +191,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.EventDestinations
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the EventDestination currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.EventDestination {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an Event Destination.
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventDestinationUpdate,
|
||||
) (*ngrok.EventDestination, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EventDestinationUpdate)
|
||||
}
|
||||
var res ngrok.EventDestination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/event_destinations/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -207,29 +234,3 @@ func (c *Client) Update(
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Send a test event to an Event Destination
|
||||
func (c *Client) SendTestEvent(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SentEvent, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.SentEvent
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("send_test_event_path").Parse("/event_destinations/{{ .ID }}/send_test_event")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package event_sources
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSourceCreate,
|
||||
) (*ngrok.EventSource, error) {
|
||||
var res ngrok.EventSource
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSourceItem,
|
||||
) error {
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
arg.Type = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSourceItem,
|
||||
) (*ngrok.EventSource, error) {
|
||||
var res ngrok.EventSource
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
arg.Type = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
subscriptionId string,
|
||||
|
||||
) (*ngrok.EventSourceList, error) {
|
||||
arg := &ngrok.EventSourcePage{SubscriptionID: subscriptionId}
|
||||
var res ngrok.EventSourceList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSourceUpdate,
|
||||
) (*ngrok.EventSource, error) {
|
||||
var res ngrok.EventSource
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/event_subscriptions/{{ .SubscriptionID }}/sources/{{ .Type }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.SubscriptionID = ""
|
||||
arg.Type = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
+50
-23
@@ -5,7 +5,6 @@ package event_streams
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -23,9 +22,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
// Create a new Event Stream. It will not apply to anything until you associate it
|
||||
// with one or more Endpoint Configs.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventStreamCreate,
|
||||
) (*ngrok.EventStream, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EventStreamCreate)
|
||||
}
|
||||
var res ngrok.EventStream
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/event_streams")).Execute(&path, arg); err != nil {
|
||||
@@ -46,11 +49,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an Event Stream. Associated Event Destinations will be preserved.
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/event_streams/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -70,11 +75,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an Event Stream by ID.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EventStream, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EventStream
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/event_streams/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -94,10 +101,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all Event Streams available on this account.
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.EventStreamList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.EventStreamList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/event_streams")).Execute(&path, arg); err != nil {
|
||||
@@ -123,24 +133,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all Event Streams available on this account.
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.EventStream
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.EventStream
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -150,18 +173,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -169,23 +188,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.EventStreams
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the EventStream currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.EventStream {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an Event Stream by ID.
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventStreamUpdate,
|
||||
) (*ngrok.EventStream, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EventStreamUpdate)
|
||||
}
|
||||
var res ngrok.EventStream
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/event_streams/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package event_subscriptions
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create an Event Subscription.
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSubscriptionCreate,
|
||||
) (*ngrok.EventSubscription, error) {
|
||||
var res ngrok.EventSubscription
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/event_subscriptions")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/event_subscriptions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get an Event Subscription by ID.
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EventSubscription, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.EventSubscription
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/event_subscriptions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List this Account's Event Subscriptions.
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.EventSubscriptionList, error) {
|
||||
var res ngrok.EventSubscriptionList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/event_subscriptions")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.EventSubscription
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.EventSubscriptions
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.EventSubscription {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.EventSubscriptionUpdate,
|
||||
) (*ngrok.EventSubscription, error) {
|
||||
var res ngrok.EventSubscription
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/event_subscriptions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ngrok_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
"github.com/ngrok/ngrok-api-go/ip_policies"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIPPolicy(t *testing.T) {
|
||||
var opts []ngrok.ClientOption
|
||||
|
||||
var mock mockTransport
|
||||
if os.Getenv("TEST_NO_MOCK") != "true" {
|
||||
opts = append(opts, ngrok.WithHTTPClient(&http.Client{
|
||||
Transport: &mock,
|
||||
}))
|
||||
} else if os.Getenv("TEST_DEBUG") == "true" {
|
||||
// dump requests and responses to stdout
|
||||
opts = append(opts, ngrok.WithHTTPClient(&http.Client{
|
||||
Transport: &debugTransport{
|
||||
rt: http.DefaultTransport,
|
||||
out: os.Stderr,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
c, err := ngrok.NewClient(os.Getenv("NGROK_API_KEY"), opts...)
|
||||
require.NoError(t, err)
|
||||
|
||||
policies := ip_policies.NewClient(c)
|
||||
|
||||
// test policy creation
|
||||
mock.SetResponse(201, `{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"","action":"allow"}`)
|
||||
createInstance, err := policies.Create(ctx, &ngrok.IPPolicyCreate{
|
||||
Action: "allow",
|
||||
Description: "ngrok-api-go tests",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// test get
|
||||
mock.SetResponse(200, `{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"","action":"allow"}`)
|
||||
getInstance, err := policies.Get(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, createInstance, getInstance)
|
||||
|
||||
// test update
|
||||
mock.SetResponse(200, `{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"{\"device-id\": \"malamute-12\"}","action":"allow"}`)
|
||||
metadata := `{"device-id": "malamute-12"}`
|
||||
updatedInstance, err := policies.Update(ctx, &ngrok.IPPolicyUpdate{
|
||||
ID: createInstance.ID,
|
||||
Metadata: ngrok.String(metadata),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, updatedInstance.Metadata, metadata)
|
||||
|
||||
// test get after update
|
||||
mock.SetResponse(200, `{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"{\"device-id\": \"malamute-12\"}","action":"allow"}`)
|
||||
getAfterUpdateInstance, err := policies.Get(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, updatedInstance, getAfterUpdateInstance)
|
||||
|
||||
mock.SetResponse(200, `{"ip_policies":[{"id":"ipp_1sbMfZquosZtu5mZPgA91UDFaDC","uri":"https://api.ngrok.com/ip_policies/ipp_1sbMfZquosZtu5mZPgA91UDFaDC","created_at":"2021-05-16T03:48:59Z","description":"ngrok-api-go tests","metadata":"{\"device-id\": \"malamute-12\"}","action":"allow"},{"id":"ipp_1qXI4T0q6cgkoOVvqSEjU7LiWIr","uri":"https://api.ngrok.com/ip_policies/ipp_1qXI4T0q6cgkoOVvqSEjU7LiWIr","created_at":"2021-03-31T19:35:16Z","description":"martin demo","metadata":"","action":"allow"}],"uri":"https://api.ngrok.com/ip_policies","next_page_uri":null}`)
|
||||
mock.SetResponse(200, `{"ip_policies":[],"uri":"https://api.ngrok.com/ip_policies","next_page_uri":null}`)
|
||||
iter := policies.List(ctx, nil)
|
||||
var iterPolicies []*ngrok.IPPolicy
|
||||
for iter.Next() {
|
||||
iterPolicies = append(iterPolicies, iter.Item())
|
||||
}
|
||||
require.NoError(t, iter.Err())
|
||||
require.Contains(t, iterPolicies, updatedInstance)
|
||||
|
||||
// test delete
|
||||
mock.SetResponse(204, "")
|
||||
err = policies.Delete(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// test 404
|
||||
mock.SetResponse(404, `{"status_code":404,"msg":"Resource not found","details":{"operation_id":"op_1sbMfWvXaRA26gTJoBPIgyPD8MF"}}`)
|
||||
_, err = policies.Get(ctx, createInstance.ID)
|
||||
require.True(t, ngrok.IsNotFound(err))
|
||||
}
|
||||
+47
-23
@@ -5,7 +5,6 @@ package ip_policies
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -23,6 +22,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
// Create a new IP policy. It will not apply to any traffic until you associate to
|
||||
// a traffic source via an endpoint configuration or IP restriction.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPPolicyCreate,
|
||||
) (*ngrok.IPPolicy, error) {
|
||||
@@ -48,11 +48,13 @@ func (c *Client) Create(
|
||||
// purposes of traffic restriction it will be treated as if the IP policy remains
|
||||
// but has zero rules.
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ip_policies/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -72,11 +74,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an IP policy by ID.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.IPPolicy, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.IPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ip_policies/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -96,10 +100,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all IP policies on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.IPPolicyList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.IPPolicyList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ip_policies")).Execute(&path, arg); err != nil {
|
||||
@@ -125,24 +132,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all IP policies on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.IPPolicy
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.IPPolicy
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -152,18 +172,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -171,23 +187,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.IPPolicies
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the IPPolicy currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.IPPolicy {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an IP policy by ID
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPPolicyUpdate,
|
||||
) (*ngrok.IPPolicy, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.IPPolicyUpdate)
|
||||
}
|
||||
var res ngrok.IPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ip_policies/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
+47
-23
@@ -5,7 +5,6 @@ package ip_policy_rules
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Create a new IP policy rule attached to an IP Policy.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPPolicyRuleCreate,
|
||||
) (*ngrok.IPPolicyRule, error) {
|
||||
@@ -45,11 +45,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an IP policy rule.
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ip_policy_rules/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +71,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an IP policy rule by ID.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.IPPolicyRule, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.IPPolicyRule
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ip_policy_rules/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +97,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all IP policy rules on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.IPPolicyRuleList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.IPPolicyRuleList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ip_policy_rules")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +129,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all IP policy rules on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.IPPolicyRule
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.IPPolicyRule
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +169,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +184,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.IPPolicyRules
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the IPPolicyRule currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.IPPolicyRule {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an IP policy rule by ID
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPPolicyRuleUpdate,
|
||||
) (*ngrok.IPPolicyRule, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.IPPolicyRuleUpdate)
|
||||
}
|
||||
var res ngrok.IPPolicyRule
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ip_policy_rules/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
+47
-23
@@ -5,7 +5,6 @@ package ip_restrictions
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Create a new IP restriction
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPRestrictionCreate,
|
||||
) (*ngrok.IPRestriction, error) {
|
||||
@@ -45,11 +45,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an IP restriction
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ip_restrictions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +71,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an IP restriction
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.IPRestriction, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.IPRestriction
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ip_restrictions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +97,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all IP restrictions on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.IPRestrictionList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.IPRestrictionList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ip_restrictions")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +129,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all IP restrictions on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.IPRestriction
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.IPRestriction
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +169,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +184,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.IPRestrictions
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the IPRestriction currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.IPRestriction {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an IP restriction by ID
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPRestrictionUpdate,
|
||||
) (*ngrok.IPRestriction, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.IPRestrictionUpdate)
|
||||
}
|
||||
var res ngrok.IPRestriction
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ip_restrictions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
+50
-23
@@ -5,7 +5,6 @@ package ip_whitelist
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -23,9 +22,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
// Create a new IP whitelist entry that will restrict traffic to all tunnel
|
||||
// endpoints on the account.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPWhitelistEntryCreate,
|
||||
) (*ngrok.IPWhitelistEntry, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.IPWhitelistEntryCreate)
|
||||
}
|
||||
var res ngrok.IPWhitelistEntry
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ip_whitelist")).Execute(&path, arg); err != nil {
|
||||
@@ -46,11 +49,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an IP whitelist entry.
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ip_whitelist/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -70,11 +75,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an IP whitelist entry by ID.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.IPWhitelistEntry, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.IPWhitelistEntry
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ip_whitelist/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -94,10 +101,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all IP whitelist entries on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.IPWhitelistEntryList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.IPWhitelistEntryList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ip_whitelist")).Execute(&path, arg); err != nil {
|
||||
@@ -123,24 +133,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all IP whitelist entries on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.IPWhitelistEntry
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.IPWhitelistEntry
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -150,18 +173,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -169,23 +188,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Whitelist
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the IPWhitelistEntry currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.IPWhitelistEntry {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an IP whitelist entry by ID
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.IPWhitelistEntryUpdate,
|
||||
) (*ngrok.IPWhitelistEntry, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.IPWhitelistEntryUpdate)
|
||||
}
|
||||
var res ngrok.IPWhitelistEntry
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ip_whitelist/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
package ngrok_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
"github.com/ngrok/ngrok-api-go/ip_policies"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIPPolicy(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
c, err := ngrok.NewClient()
|
||||
require.NoError(t, err)
|
||||
|
||||
policies := ip_policies.NewClient(c)
|
||||
|
||||
// test that a list call works
|
||||
_, err = policies.List(ctx, &ngrok.Page{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// test policy creation
|
||||
createInstance, err := policies.Create(ctx, &ngrok.IPPolicyCreate{
|
||||
Action: "allow",
|
||||
Description: "ngrok-api-go tests",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// test get
|
||||
getInstance, err := policies.Get(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, createInstance, getInstance)
|
||||
|
||||
// test update
|
||||
metadata := `{"device-id": "malamute-12"`
|
||||
updatedInstance, err := policies.Update(ctx, &ngrok.IPPolicyUpdate{
|
||||
ID: createInstance.ID,
|
||||
Metadata: ngrok.String(metadata),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, updatedInstance.Metadata, metadata)
|
||||
|
||||
// test get after update
|
||||
getAfterUpdateInstance, err := policies.Get(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, updatedInstance, getAfterUpdateInstance)
|
||||
|
||||
iter := policies.Iter(ctx)
|
||||
var iterPolicies []*ngrok.IPPolicy
|
||||
for iter.Next() {
|
||||
iterPolicies = append(iterPolicies, iter.Item())
|
||||
}
|
||||
require.NoError(t, iter.Err())
|
||||
require.Contains(t, iterPolicies, updatedInstance)
|
||||
|
||||
// test delete
|
||||
err = policies.Delete(ctx, createInstance.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// test 404
|
||||
_, err = policies.Get(ctx, createInstance.ID)
|
||||
require.True(t, ngrok.IsNotFound(err))
|
||||
}
|
||||
+9
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_circuit_breaker_module
|
||||
package circuit_breaker
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointCircuitBreakerReplace,
|
||||
) (*ngrok.EndpointCircuitBreaker, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointCircuitBreakerReplace)
|
||||
}
|
||||
var res ngrok.EndpointCircuitBreaker
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/circuit_breaker")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointCircuitBreaker, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointCircuitBreaker
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/circuit_breaker")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/circuit_breaker")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_compression_module
|
||||
package compression
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointCompressionReplace,
|
||||
) (*ngrok.EndpointCompression, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointCompressionReplace)
|
||||
}
|
||||
var res ngrok.EndpointCompression
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/compression")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointCompression, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointCompression
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/compression")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/compression")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_ip_policy_module
|
||||
package ip_policy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointIPPolicyReplace,
|
||||
) (*ngrok.EndpointIPPolicy, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointIPPolicyReplace)
|
||||
}
|
||||
var res ngrok.EndpointIPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/ip_policy")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointIPPolicy, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointIPPolicy
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/ip_policy")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/ip_policy")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_logging_module
|
||||
package logging
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointLoggingReplace,
|
||||
) (*ngrok.EndpointLogging, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointLoggingReplace)
|
||||
}
|
||||
var res ngrok.EndpointLogging
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/logging")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointLogging, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointLogging
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/logging")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/logging")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_mutual_tls_module
|
||||
package mutual_tls
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointMutualTLSReplace,
|
||||
) (*ngrok.EndpointMutualTLS, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointMutualTLSReplace)
|
||||
}
|
||||
var res ngrok.EndpointMutualTLS
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/mutual_tls")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointMutualTLS, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointMutualTLS
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/mutual_tls")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/mutual_tls")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_o_auth_module
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointOAuthReplace,
|
||||
) (*ngrok.EndpointOAuth, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointOAuthReplace)
|
||||
}
|
||||
var res ngrok.EndpointOAuth
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/oauth")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointOAuth, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointOAuth
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/oauth")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/oauth")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_oidc_module
|
||||
package oidc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointOIDCReplace,
|
||||
) (*ngrok.EndpointOIDC, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointOIDCReplace)
|
||||
}
|
||||
var res ngrok.EndpointOIDC
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/oidc")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointOIDC, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointOIDC
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/oidc")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/oidc")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
+9
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_request_headers_module
|
||||
package request_headers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointRequestHeadersReplace,
|
||||
) (*ngrok.EndpointRequestHeaders, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointRequestHeadersReplace)
|
||||
}
|
||||
var res ngrok.EndpointRequestHeaders
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/request_headers")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointRequestHeaders, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointRequestHeaders
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/request_headers")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/request_headers")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
+9
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_response_headers_module
|
||||
package response_headers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointResponseHeadersReplace,
|
||||
) (*ngrok.EndpointResponseHeaders, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointResponseHeadersReplace)
|
||||
}
|
||||
var res ngrok.EndpointResponseHeaders
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/response_headers")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointResponseHeaders, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointResponseHeaders
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/response_headers")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/response_headers")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_saml_module
|
||||
package saml
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointSAMLReplace,
|
||||
) (*ngrok.EndpointSAML, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointSAMLReplace)
|
||||
}
|
||||
var res ngrok.EndpointSAML
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/saml")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointSAML, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointSAML
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/saml")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/saml")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
+9
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_tls_termination_module
|
||||
package tls_termination
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointTLSTerminationReplace,
|
||||
) (*ngrok.EndpointTLSTermination, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointTLSTerminationReplace)
|
||||
}
|
||||
var res ngrok.EndpointTLSTermination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/tls_termination")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointTLSTermination, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointTLSTermination
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/tls_termination")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/tls_termination")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
+9
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package endpoint_webhook_validation_module
|
||||
package webhook_validation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,9 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) Replace(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.EndpointWebhookValidationReplace,
|
||||
) (*ngrok.EndpointWebhookValidation, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.EndpointWebhookValidationReplace)
|
||||
}
|
||||
var res ngrok.EndpointWebhookValidation
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("replace_path").Parse("/endpoint_configurations/{{ .ID }}/webhook_validation")).Execute(&path, arg); err != nil {
|
||||
@@ -43,11 +47,13 @@ func (c *Client) Replace(
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.EndpointWebhookValidation, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.EndpointWebhookValidation
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/endpoint_configurations/{{ .ID }}/webhook_validation")).Execute(&path, arg); err != nil {
|
||||
@@ -67,11 +73,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/endpoint_configurations/{{ .ID }}/webhook_validation")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -1,205 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package priority_backends
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new Priority backend
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.PriorityBackendCreate,
|
||||
) (*ngrok.PriorityBackend, error) {
|
||||
var res ngrok.PriorityBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/backends/priority")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a Priority backend by ID. TODO what if used?
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/backends/priority/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a Priority backend by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.PriorityBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.PriorityBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/backends/priority/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all Priority backends on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.PriorityBackendList, error) {
|
||||
var res ngrok.PriorityBackendList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/backends/priority")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.PriorityBackend
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Backends
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.PriorityBackend {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update Priority backend by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.PriorityBackendUpdate,
|
||||
) (*ngrok.PriorityBackend, error) {
|
||||
var res ngrok.PriorityBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/backends/priority/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
+52
-23
@@ -5,7 +5,6 @@ package reserved_addrs
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,9 +21,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Create a new reserved address.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.ReservedAddrCreate,
|
||||
) (*ngrok.ReservedAddr, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.ReservedAddrCreate)
|
||||
}
|
||||
var res ngrok.ReservedAddr
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/reserved_addrs")).Execute(&path, arg); err != nil {
|
||||
@@ -45,11 +48,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete a reserved address.
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/reserved_addrs/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +74,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get the details of a reserved address.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.ReservedAddr, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.ReservedAddr
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/reserved_addrs/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +100,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all reserved addresses on this account.
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.ReservedAddrList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.ReservedAddrList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/reserved_addrs")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +132,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all reserved addresses on this account.
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.ReservedAddr
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.ReservedAddr
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +172,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +187,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.ReservedAddrs
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the ReservedAddr currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.ReservedAddr {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update the attributes of a reserved address.
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.ReservedAddrUpdate,
|
||||
) (*ngrok.ReservedAddr, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.ReservedAddrUpdate)
|
||||
}
|
||||
var res ngrok.ReservedAddr
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/reserved_addrs/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -206,11 +233,13 @@ func (c *Client) Update(
|
||||
|
||||
// Detach the endpoint configuration attached to a reserved address.
|
||||
func (c *Client) DeleteEndpointConfig(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_endpoint_config_path").Parse("/reserved_addrs/{{ .ID }}/endpoint_configuration")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
|
||||
+55
-23
@@ -5,7 +5,6 @@ package reserved_domains
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Create a new reserved domain.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.ReservedDomainCreate,
|
||||
) (*ngrok.ReservedDomain, error) {
|
||||
@@ -45,11 +45,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete a reserved domain.
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/reserved_domains/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +71,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get the details of a reserved domain.
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.ReservedDomain, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.ReservedDomain
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/reserved_domains/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +97,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all reserved domains on this account.
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.ReservedDomainList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.ReservedDomainList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/reserved_domains")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +129,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all reserved domains on this account.
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.ReservedDomain
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.ReservedDomain
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +169,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +184,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.ReservedDomains
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the ReservedDomain currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.ReservedDomain {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update the attributes of a reserved domain.
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.ReservedDomainUpdate,
|
||||
) (*ngrok.ReservedDomain, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.ReservedDomainUpdate)
|
||||
}
|
||||
var res ngrok.ReservedDomain
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/reserved_domains/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -206,11 +230,13 @@ func (c *Client) Update(
|
||||
|
||||
// Detach the certificate management policy attached to a reserved domain.
|
||||
func (c *Client) DeleteCertificateManagementPolicy(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_certificate_management_policy_path").Parse("/reserved_domains/{{ .ID }}/certificate_management_policy")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -230,11 +256,13 @@ func (c *Client) DeleteCertificateManagementPolicy(
|
||||
|
||||
// Detach the certificate attached to a reserved domain.
|
||||
func (c *Client) DeleteCertificate(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_certificate_path").Parse("/reserved_domains/{{ .ID }}/certificate")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -254,11 +282,13 @@ func (c *Client) DeleteCertificate(
|
||||
|
||||
// Detach the http endpoint configuration attached to a reserved domain.
|
||||
func (c *Client) DeleteHTTPEndpointConfig(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_http_endpoint_config_path").Parse("/reserved_domains/{{ .ID }}/http_endpoint_configuration")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -278,11 +308,13 @@ func (c *Client) DeleteHTTPEndpointConfig(
|
||||
|
||||
// Detach the https endpoint configuration attached to a reserved domain.
|
||||
func (c *Client) DeleteHTTPSEndpointConfig(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_https_endpoint_config_path").Parse("/reserved_domains/{{ .ID }}/https_endpoint_configuration")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package root
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Empty,
|
||||
) (*ngrok.RootResponse, error) {
|
||||
var res ngrok.RootResponse
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
@@ -5,7 +5,6 @@ package ssh_certificate_authorities
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,9 +21,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Create a new SSH Certificate Authority
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHCertificateAuthorityCreate,
|
||||
) (*ngrok.SSHCertificateAuthority, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.SSHCertificateAuthorityCreate)
|
||||
}
|
||||
var res ngrok.SSHCertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/ssh_certificate_authorities")).Execute(&path, arg); err != nil {
|
||||
@@ -45,11 +48,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an SSH Certificate Authority
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ssh_certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +74,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an SSH Certficate Authority
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SSHCertificateAuthority, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.SSHCertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ssh_certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +100,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all SSH Certificate Authorities on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.SSHCertificateAuthorityList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.SSHCertificateAuthorityList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ssh_certificate_authorities")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +132,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all SSH Certificate Authorities on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.SSHCertificateAuthority
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.SSHCertificateAuthority
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +172,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +187,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.SSHCertificateAuthorities
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the SSHCertificateAuthority currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.SSHCertificateAuthority {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update an SSH Certificate Authority
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHCertificateAuthorityUpdate,
|
||||
) (*ngrok.SSHCertificateAuthority, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.SSHCertificateAuthorityUpdate)
|
||||
}
|
||||
var res ngrok.SSHCertificateAuthority
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ssh_certificate_authorities/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
+47
-23
@@ -5,7 +5,6 @@ package ssh_credentials
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -23,6 +22,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
// Create a new ssh_credential from an uploaded public SSH key. This ssh credential
|
||||
// can be used to start new tunnels via ngrok's SSH gateway.
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHCredentialCreate,
|
||||
) (*ngrok.SSHCredential, error) {
|
||||
@@ -46,11 +46,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an ssh_credential by ID
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ssh_credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -70,11 +72,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an ssh_credential
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SSHCredential, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.SSHCredential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ssh_credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -94,10 +98,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all ssh credentials on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.SSHCredentialList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.SSHCredentialList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ssh_credentials")).Execute(&path, arg); err != nil {
|
||||
@@ -123,24 +130,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all ssh credentials on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.SSHCredential
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.SSHCredential
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -150,18 +170,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -169,23 +185,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.SSHCredentials
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the SSHCredential currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.SSHCredential {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of an ssh_credential by ID
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHCredentialUpdate,
|
||||
) (*ngrok.SSHCredential, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.SSHCredentialUpdate)
|
||||
}
|
||||
var res ngrok.SSHCredential
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ssh_credentials/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -5,7 +5,6 @@ package ssh_host_certificates
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Create a new SSH Host Certificate
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHHostCertificateCreate,
|
||||
) (*ngrok.SSHHostCertificate, error) {
|
||||
@@ -45,11 +45,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an SSH Host Certificate
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ssh_host_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +71,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an SSH Host Certficate
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SSHHostCertificate, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.SSHHostCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ssh_host_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +97,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all SSH Host Certificates issued on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.SSHHostCertificateList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.SSHHostCertificateList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ssh_host_certificates")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +129,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all SSH Host Certificates issued on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.SSHHostCertificate
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.SSHHostCertificate
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +169,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +184,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.SSHHostCertificates
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the SSHHostCertificate currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.SSHHostCertificate {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update an SSH Host Certificate
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHHostCertificateUpdate,
|
||||
) (*ngrok.SSHHostCertificate, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.SSHHostCertificateUpdate)
|
||||
}
|
||||
var res ngrok.SSHHostCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ssh_host_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -5,7 +5,6 @@ package ssh_user_certificates
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Create a new SSH User Certificate
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHUserCertificateCreate,
|
||||
) (*ngrok.SSHUserCertificate, error) {
|
||||
@@ -45,11 +45,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete an SSH User Certificate
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/ssh_user_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +71,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about an SSH User Certficate
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.SSHUserCertificate, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.SSHUserCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/ssh_user_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +97,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all SSH User Certificates issued on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.SSHUserCertificateList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.SSHUserCertificateList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/ssh_user_certificates")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +129,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all SSH User Certificates issued on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.SSHUserCertificate
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.SSHUserCertificate
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +169,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +184,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.SSHUserCertificates
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the SSHUserCertificate currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.SSHUserCertificate {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update an SSH User Certificate
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.SSHUserCertificateUpdate,
|
||||
) (*ngrok.SSHUserCertificate, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.SSHUserCertificateUpdate)
|
||||
}
|
||||
var res ngrok.SSHUserCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/ssh_user_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package static_backends
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new static backend
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.StaticBackendCreate,
|
||||
) (*ngrok.StaticBackend, error) {
|
||||
var res ngrok.StaticBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/backends/static")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a static backend by ID. TODO what if used?
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/backends/static/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a static backend by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.StaticBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.StaticBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/backends/static/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all static backends on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.StaticBackendList, error) {
|
||||
var res ngrok.StaticBackendList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/backends/static")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.StaticBackend
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Backends
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.StaticBackend {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update static backend by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.StaticBackendUpdate,
|
||||
) (*ngrok.StaticBackend, error) {
|
||||
var res ngrok.StaticBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/backends/static/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
+47
-23
@@ -5,7 +5,6 @@ package tls_certificates
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -22,6 +21,7 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
|
||||
// Upload a new TLS certificate
|
||||
func (c *Client) Create(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.TLSCertificateCreate,
|
||||
) (*ngrok.TLSCertificate, error) {
|
||||
@@ -45,11 +45,13 @@ func (c *Client) Create(
|
||||
|
||||
// Delete a TLS certificate
|
||||
func (c *Client) Delete(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/tls_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -69,11 +71,13 @@ func (c *Client) Delete(
|
||||
|
||||
// Get detailed information about a TLS certificate
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.TLSCertificate, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.TLSCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/tls_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -93,10 +97,13 @@ func (c *Client) Get(
|
||||
}
|
||||
|
||||
// List all TLS certificates on this account
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.TLSCertificateList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.TLSCertificateList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/tls_certificates")).Execute(&path, arg); err != nil {
|
||||
@@ -122,24 +129,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all TLS certificates on this account
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.TLSCertificate
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.TLSCertificate
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -149,18 +169,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -168,23 +184,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.TLSCertificates
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the TLSCertificate currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.TLSCertificate {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update attributes of a TLS Certificate by ID
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
arg *ngrok.TLSCertificateUpdate,
|
||||
) (*ngrok.TLSCertificate, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.TLSCertificateUpdate)
|
||||
}
|
||||
var res ngrok.TLSCertificate
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/tls_certificates/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package ngrok_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
)
|
||||
|
||||
type debugTransport struct {
|
||||
rt http.RoundTripper
|
||||
out io.Writer
|
||||
}
|
||||
|
||||
func (t *debugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
// dump request
|
||||
rtid := rand.Int()
|
||||
fmt.Fprintf(t.out, "\n************** ROUND TRIP %x ********************\n", rtid)
|
||||
reqBytes, _ := httputil.DumpRequestOut(req, true)
|
||||
t.out.Write(reqBytes)
|
||||
fmt.Fprintln(t.out, "")
|
||||
|
||||
// execute round trip
|
||||
resp, err := t.rt.RoundTrip(req)
|
||||
|
||||
// dump response
|
||||
if err != nil {
|
||||
fmt.Fprintf(t.out, "RoundTrip error: %v\n", err)
|
||||
} else {
|
||||
respBytes, _ := httputil.DumpResponse(resp, true)
|
||||
t.out.Write(respBytes)
|
||||
fmt.Fprintln(t.out, "")
|
||||
}
|
||||
fmt.Fprintf(t.out, "\n************** END ROUND TRIP %x ********************\n", rtid)
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
type mockTransport struct {
|
||||
mockResponse []*http.Response
|
||||
mockResponseError []error
|
||||
}
|
||||
|
||||
func (s *mockTransport) SetResponse(statusCode int, body string) {
|
||||
s.mockResponse = append(s.mockResponse, &http.Response{
|
||||
Status: http.StatusText(statusCode),
|
||||
StatusCode: statusCode,
|
||||
Proto: "HTTP/1.1",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 1,
|
||||
Header: http.Header{
|
||||
"Content-Length": []string{fmt.Sprintf("%d", len(body))},
|
||||
"Connection": []string{"close"},
|
||||
},
|
||||
ContentLength: int64(len(body)),
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(body))),
|
||||
})
|
||||
s.mockResponseError = append(s.mockResponseError, nil)
|
||||
}
|
||||
|
||||
func (s *mockTransport) SetResponseError(err error) {
|
||||
s.mockResponse = append(s.mockResponse, nil)
|
||||
s.mockResponseError = append(s.mockResponseError, err)
|
||||
}
|
||||
|
||||
func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
resp := t.mockResponse[0]
|
||||
respErr := t.mockResponseError[0]
|
||||
t.mockResponse = t.mockResponse[1:]
|
||||
t.mockResponseError = t.mockResponseError[1:]
|
||||
return resp, respErr
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package tunnel_group_backends
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new TunnelGroup backend
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.TunnelGroupBackendCreate,
|
||||
) (*ngrok.TunnelGroupBackend, error) {
|
||||
var res ngrok.TunnelGroupBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/backends/tunnel-group")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a TunnelGroup backend by ID. TODO what if used?
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/backends/tunnel-group/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a TunnelGroup backend by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.TunnelGroupBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.TunnelGroupBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/backends/tunnel-group/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all TunnelGroup backends on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.TunnelGroupBackendList, error) {
|
||||
var res ngrok.TunnelGroupBackendList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/backends/tunnel-group")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.TunnelGroupBackend
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Backends
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.TunnelGroupBackend {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update TunnelGroup backend by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.TunnelGroupBackendUpdate,
|
||||
) (*ngrok.TunnelGroupBackend, error) {
|
||||
var res ngrok.TunnelGroupBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/backends/tunnel-group/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
+46
-23
@@ -5,7 +5,6 @@ package tunnel_sessions
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -21,10 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
// List all online tunnel sessions running on this account.
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.TunnelSessionList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.TunnelSessionList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/tunnel_sessions")).Execute(&path, arg); err != nil {
|
||||
@@ -50,24 +52,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all online tunnel sessions running on this account.
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.TunnelSession
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.TunnelSession
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -77,18 +92,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -96,25 +107,31 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.TunnelSessions
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the TunnelSession currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.TunnelSession {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Get the detailed status of a tunnel session by ID
|
||||
func (c *Client) Get(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.TunnelSession, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var res ngrok.TunnelSession
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/tunnel_sessions/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
@@ -138,11 +155,13 @@ func (c *Client) Get(
|
||||
// not supported on Windows. When an agent restarts, it reconnects with a new
|
||||
// tunnel session ID.
|
||||
func (c *Client) Restart(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("restart_path").Parse("/tunnel_sessions/{{ .ID }}/restart")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -164,11 +183,13 @@ func (c *Client) Restart(
|
||||
// Issues a command instructing the ngrok agent that started this tunnel session to
|
||||
// exit.
|
||||
func (c *Client) Stop(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("stop_path").Parse("/tunnel_sessions/{{ .ID }}/stop")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
@@ -200,11 +221,13 @@ func (c *Client) Stop(
|
||||
// disabled update checks the agent is currently in process of updating the agent
|
||||
// has already successfully updated but has not yet been restarted
|
||||
func (c *Client) Update(
|
||||
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.TunnelSessionsUpdate{ID: id}
|
||||
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/tunnel_sessions/{{ .ID }}/update")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
|
||||
+38
-23
@@ -5,7 +5,6 @@ package tunnels
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
@@ -21,10 +20,13 @@ func NewClient(apiClient *ngrok.Client) *Client {
|
||||
}
|
||||
|
||||
// List all online tunnels currently running on the account.
|
||||
func (c *Client) List(
|
||||
func (c *Client) list(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
arg *ngrok.Paging,
|
||||
) (*ngrok.TunnelList, error) {
|
||||
if arg == nil {
|
||||
arg = new(ngrok.Paging)
|
||||
}
|
||||
var res ngrok.TunnelList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/tunnels")).Execute(&path, arg); err != nil {
|
||||
@@ -50,24 +52,37 @@ func (c *Client) List(
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
// List all online tunnels currently running on the account.
|
||||
func (c *Client) List(ctx context.Context, paging *ngrok.Paging) *Iter {
|
||||
if paging == nil {
|
||||
paging = new(ngrok.Paging)
|
||||
}
|
||||
if paging.Limit == nil {
|
||||
paging.Limit = ngrok.String("100")
|
||||
}
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: paging.Limit,
|
||||
lastItemID: paging.BeforeID,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Iter allows the caller to iterate through a list of values while
|
||||
// automatically fetching new pages worth of values from the API.
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.Tunnel
|
||||
err error
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
items []ngrok.Tunnel
|
||||
err error
|
||||
limit *string
|
||||
lastItemID *string
|
||||
}
|
||||
|
||||
// Next() returns true if there is another value available in the iterator. If it
|
||||
// returs true it also advances the iterator to that next available item.
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
@@ -77,18 +92,14 @@ func (it *Iter) Next() bool {
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
it.lastItemID = ngrok.String(it.Item().ID)
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
resp, err := it.client.list(it.ctx, &ngrok.Paging{
|
||||
BeforeID: it.lastItemID,
|
||||
Limit: it.limit,
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
@@ -96,14 +107,18 @@ func (it *Iter) Next() bool {
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Tunnels
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
// Item() returns the Tunnel currently
|
||||
// pointed to by the iterator.
|
||||
func (it *Iter) Item() *ngrok.Tunnel {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
// If Next() returned false because an error was encountered while fetching the
|
||||
// next value Err() will return that error. A caller should always check Err()
|
||||
// after Next() returns false.
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
// Code generated by apic. DO NOT EDIT.
|
||||
|
||||
package weighted_backends
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ngrok/ngrok-api-go"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiClient *ngrok.Client
|
||||
}
|
||||
|
||||
func NewClient(apiClient *ngrok.Client) *Client {
|
||||
return &Client{apiClient: apiClient}
|
||||
}
|
||||
|
||||
// Create a new Weighted backend
|
||||
func (c *Client) Create(
|
||||
ctx context.Context,
|
||||
arg *ngrok.WeightedBackendCreate,
|
||||
) (*ngrok.WeightedBackend, error) {
|
||||
var res ngrok.WeightedBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("create_path").Parse("/backends/weighted")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// Delete a Weighted backend by ID. TODO what if used?
|
||||
func (c *Client) Delete(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) error {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("delete_path").Parse("/backends/weighted/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "DELETE", apiURL, bodyArg, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get detailed information about a Weighted backend by ID
|
||||
func (c *Client) Get(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
|
||||
) (*ngrok.WeightedBackend, error) {
|
||||
arg := &ngrok.Item{ID: id}
|
||||
var res ngrok.WeightedBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("get_path").Parse("/backends/weighted/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// List all Weighted backends on this account
|
||||
func (c *Client) List(
|
||||
ctx context.Context,
|
||||
arg *ngrok.Page,
|
||||
) (*ngrok.WeightedBackendList, error) {
|
||||
var res ngrok.WeightedBackendList
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("list_path").Parse("/backends/weighted")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
queryVals := make(url.Values)
|
||||
if arg.BeforeID != nil {
|
||||
queryVals.Set("before_id", *arg.BeforeID)
|
||||
}
|
||||
if arg.Limit != nil {
|
||||
queryVals.Set("limit", *arg.Limit)
|
||||
}
|
||||
apiURL.RawQuery = queryVals.Encode()
|
||||
|
||||
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Client) Iter(ctx context.Context) *Iter {
|
||||
return &Iter{
|
||||
client: c,
|
||||
ctx: ctx,
|
||||
limit: 100,
|
||||
n: -1,
|
||||
}
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
client *Client
|
||||
ctx context.Context
|
||||
n int
|
||||
limit int
|
||||
items []ngrok.WeightedBackend
|
||||
err error
|
||||
}
|
||||
|
||||
func (it *Iter) Next() bool {
|
||||
// no more if there is an error
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// are there items remaining?
|
||||
if it.n < len(it.items)-1 {
|
||||
it.n += 1
|
||||
return true
|
||||
}
|
||||
|
||||
// fetch the next page
|
||||
lastItemID := ""
|
||||
if it.n > 0 {
|
||||
lastItemID = it.items[it.n].ID
|
||||
}
|
||||
fmt.Println("lastItemID", lastItemID, "n", it.n)
|
||||
resp, err := it.client.List(it.ctx, &ngrok.Page{
|
||||
BeforeID: ngrok.String(lastItemID),
|
||||
Limit: ngrok.String(fmt.Sprintf("%d", it.limit)),
|
||||
})
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
it.n = 0
|
||||
it.items = resp.Backends
|
||||
fmt.Println(len(it.items), it.items)
|
||||
return len(it.items) > 0
|
||||
}
|
||||
|
||||
func (it *Iter) Item() *ngrok.WeightedBackend {
|
||||
return &it.items[it.n]
|
||||
}
|
||||
|
||||
func (it *Iter) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
// Update Weighted backend by ID
|
||||
func (c *Client) Update(
|
||||
ctx context.Context,
|
||||
arg *ngrok.WeightedBackendUpdate,
|
||||
) (*ngrok.WeightedBackend, error) {
|
||||
var res ngrok.WeightedBackend
|
||||
var path bytes.Buffer
|
||||
if err := template.Must(template.New("update_path").Parse("/backends/weighted/{{ .ID }}")).Execute(&path, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arg.ID = ""
|
||||
var (
|
||||
apiURL = &url.URL{Path: path.String()}
|
||||
bodyArg interface{}
|
||||
)
|
||||
apiURL.Path = path.String()
|
||||
bodyArg = arg
|
||||
|
||||
if err := c.apiClient.Do(ctx, "PATCH", apiURL, bodyArg, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user