cloudflare

package
v0.0.0-...-dfb16cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBaseURL = "https://api.cloudflare.com/client/v4"
	APITokenEnv    = "CF_API_TOKEN"
)

Variables

View Source
var (
	ErrNotFound                 = errors.New("not found")
	ErrUnexpectedMultipleTunnel = errors.New("unexpected have multiple tunnel with same name")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	AccountID() string
	ZoneID() string

	Tunnels() TunnelClient
	Zones() ZoneClient
}

func NewClient

func NewClient(opts ...ClientOption) (Client, error)

type ClientOption

type ClientOption func(c *client) error

func WithAPIToken

func WithAPIToken(token string) ClientOption

WithAPIToken use oauth2 client with given token as static token source

NOTE: When used, this option should be called before any options to avoid overwrite existing http.Client

func WithLogger

func WithLogger(logger logr.Logger) ClientOption

func WithOriginCert

func WithOriginCert(origincert []byte) ClientOption

WithOriginCert use origincert to populate accountID and zoneID. This options also wrap the http.DefaultTransport to inject X-Auth-User-Service-Key header

type Error

type Error struct {
	Code    json.Number `json:"code,omitempty"`
	Message string      `json:"message,omitempty"`
}

func (Error) Error

func (e Error) Error() string

type Request

type Request struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(c *client) *Request

func (*Request) AccountPrefix

func (r *Request) AccountPrefix(account string) *Request

func (*Request) Body

func (r *Request) Body(body interface{}) *Request

func (*Request) Do

func (r *Request) Do(ctx context.Context) RequestResult

func (*Request) Header

func (r *Request) Header(key string, values ...string) *Request

func (*Request) Param

func (r *Request) Param(params interface{}) *Request

func (*Request) PathPrefix

func (r *Request) PathPrefix(prefix string) *Request

func (*Request) Resource

func (r *Request) Resource(resource string) *Request

func (*Request) ResourceID

func (r *Request) ResourceID(id string) *Request

func (*Request) SubPath

func (r *Request) SubPath(path string) *Request

func (*Request) URL

func (r *Request) URL() *url.URL

URL build url from given r. url.Path will constructed as following:

/{basePath}/{pathPrefix}/{resourceName}/{resourceID}/{subPath}

where are:

  • basePath = `/client/v4`
  • pathPrefix = could be `/accounts/{account_id}` or `/zones/{zone_id}` (optional)
  • resourceName = cloudflare resources endpoint name eg: `/tunnels`
  • resourceID = cloudflare resource id `/:uuid` (optional)
  • subPath = cloudflare sub resource endpoint eg: `/routes`

beside path, this function also construct url.Query from given r.params

func (*Request) Verb

func (r *Request) Verb(verb string) *Request

func (*Request) ZonePrefix

func (r *Request) ZonePrefix(zone string) *Request

type RequestResult

type RequestResult struct {
	// contains filtered or unexported fields
}

func (RequestResult) Error

func (r RequestResult) Error() error

func (RequestResult) Into

func (r RequestResult) Into(o interface{}) error

func (RequestResult) Raw

func (r RequestResult) Raw() ([]byte, error)

func (RequestResult) StatusCode

func (r RequestResult) StatusCode() int

type Response

type Response struct {
	Success    bool            `json:"success,omitempty"`
	Errors     []Error         `json:"errors,omitempty"`
	Messages   []string        `json:"messages,omitempty"`
	Result     json.RawMessage `json:"result,omitempty"`
	ResultInfo ResultInfo      `json:"result_info,omitempty"`
}

type ResultInfo

type ResultInfo struct {
	Page       int               `json:"page"`
	PerPage    int               `json:"per_page"`
	TotalPages int               `json:"total_pages"`
	Count      int               `json:"count"`
	Total      int               `json:"total_count"`
	Cursor     string            `json:"cursor"`
	Cursors    ResultInfoCursors `json:"cursors"`
}

type ResultInfoCursors

type ResultInfoCursors struct {
	Before string `json:"before"`
	After  string `json:"after"`
}

type ServiceKeyTransport

type ServiceKeyTransport struct {
	Base       http.RoundTripper
	ServiceKey string
}

func (*ServiceKeyTransport) RoundTrip

func (t *ServiceKeyTransport) RoundTrip(r *http.Request) (*http.Response, error)

type Tunnel

type Tunnel struct {
	ID              uuid.UUID          `json:"id"`
	Name            string             `json:"name"`
	CreatedAt       time.Time          `json:"created_at"`
	DeletedAt       time.Time          `json:"deleted_at"`
	CredentialsFile *TunnelCredentials `json:"credentials_file,omitempty"`
}

type TunnelClient

type TunnelClient interface {
	Get(ctx context.Context, tunnelID uuid.UUID) (*Tunnel, error)
	GetByName(ctx context.Context, name string) (*Tunnel, error)
	List(ctx context.Context, opts *TunnelListOptions) ([]*Tunnel, error)
	Create(ctx context.Context, name string) (*Tunnel, error)
	Delete(ctx context.Context, tunnelID uuid.UUID) error
	Route(ctx context.Context, tunnelID uuid.UUID, route TunnelRoute) error
}

type TunnelCredentials

type TunnelCredentials struct {
	AccountTag   string
	TunnelSecret []byte
	TunnelID     uuid.UUID
	TunnelName   string
}

type TunnelDNSRoute

type TunnelDNSRoute struct {
	Hostname          string
	OverwriteExisting bool
}

func (*TunnelDNSRoute) MarshalJSON

func (r *TunnelDNSRoute) MarshalJSON() ([]byte, error)

func (*TunnelDNSRoute) Type

func (r *TunnelDNSRoute) Type() string

type TunnelLBRoute

type TunnelLBRoute struct {
	LBName string
	LBPool string
}

func (*TunnelLBRoute) MarshalJSON

func (r *TunnelLBRoute) MarshalJSON() ([]byte, error)

func (*TunnelLBRoute) Type

func (r *TunnelLBRoute) Type() string

type TunnelListOptions

type TunnelListOptions struct {
	UUID      string `url:"uuid,omitempty"`
	Name      string `url:"name,omitempty"`
	IsDeleted bool   `url:"is_deleted"`
	ExistedAt string `url:"existed_at,omitempty"`
}

type TunnelRoute

type TunnelRoute interface {
	json.Marshaler
	Type() string
}

type Zone

type Zone struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type ZoneClient

type ZoneClient interface {
	Get(ctx context.Context, zoneID string) (*Zone, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL