cfapi

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package cfapi is the shared transport for every Cloudflare v4 API call upkeep makes: R2 buckets, their settings, and Pages projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Forbidden

func Forbidden(err error) bool

Forbidden reports a permission failure, which upkeep turns into a manual action rather than a crash: the operator can do in a dashboard what this token may not.

func NotConfigured

func NotConfigured(err error) bool

NotConfigured reports the codes R2 returns for a setting that has never been set. They are not failures — an absent CORS policy is the normal state of a new bucket, and treating it as an error would make the first plan unusable.

Types

type CLISession

type CLISession struct {
	Token   string
	Expires time.Time
	// Expired is checked rather than assumed: an expired OAuth token fails as
	// a 401 on the first call, which reads like a permission problem and sends
	// people looking at their account instead of at `wrangler login`.
	Expired bool
}

CLISession is a credential upkeep borrowed from wrangler rather than asking the operator for a second one.

func TokenFromWrangler

func TokenFromWrangler() (CLISession, bool)

TokenFromWrangler reads the session `wrangler login` already stored, so an operator who can run wrangler needs no second long-lived key on disk.

It returns nothing rather than an error when wrangler has never been used: that is not a problem to report, it is simply one fewer place to look.

func (CLISession) ExpiredMessage

func (s CLISession) ExpiredMessage() string

ExpiredMessage says what to do, rather than leaving a 401 to be diagnosed.

type Client

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

func New

func New(baseURL, token string) *Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body, result any) error

Do performs one request. body is JSON-marshalled when non-nil; result is JSON-unmarshalled from the envelope's result field when non-nil.

func (*Client) String

func (c *Client) String() string

String redacts the token so that printing a Client cannot leak it.

type Error

type Error struct {
	Status   int
	Code     int
	Message  string
	Endpoint string
}

Error is a Cloudflare API failure with its code kept, so a caller can tell "does not exist yet" from "you are not allowed to ask".

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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