Documentation
¶
Index ¶
- Constants
- func APIError(err error) error
- func IsNotFound(err error) bool
- func IsTimeout(err error) bool
- func ListAccounts(ctx context.Context, c *cloudflare.Client) ([]accounts.Account, error)
- func Messages(err error) string
- func NewClient(token string) *cloudflare.Client
- func ResolveZone(ctx context.Context, app *App, nameOrID string) (*zones.Zone, error)
- func StatusCode(err error) int
- type App
- type TokenInfo
Constants ¶
const AccountTokenPrefix = "cfat_"
AccountTokenPrefix marks account-owned API tokens.
Variables ¶
This section is empty.
Functions ¶
func APIError ¶
APIError turns an SDK error into a short "HTTP 403: message" error. Request headers (and so the token) are never included.
func IsTimeout ¶ added in v0.1.2
IsTimeout reports whether err is a context deadline or network timeout.
func ListAccounts ¶
ListAccounts returns every account the token can see (GET /accounts).
It pages explicitly instead of using the SDK auto-pager: it stops on an empty page, at result_info.total_pages, or after maxAccountPages.
func NewClient ¶
func NewClient(token string) *cloudflare.Client
NewClient builds a Cloudflare SDK client that authenticates with token. It sends every request through api.NewHTTPClient, so the read-only guard applies to the SDK too.
The SDK also reads CLOUDFLARE_API_KEY / CLOUDFLARE_EMAIL from the environment; those headers are stripped so only the bearer token is used.
func ResolveZone ¶
ResolveZone accepts a zone name (example.com) or a 32-char zone ID and returns the zone.
func StatusCode ¶
StatusCode returns the HTTP status of a Cloudflare API error, or 0.
Types ¶
type App ¶
type App struct {
Client *cloudflare.Client
AccountID string
// contains filtered or unexported fields
}
App holds the authenticated Cloudflare client and resolved account ID.
type TokenInfo ¶ added in v0.1.1
type TokenInfo struct {
ID string `json:"id"`
Status string `json:"status"`
ExpiresOn time.Time `json:"expires_on,omitempty"`
// Type is config.TokenTypeUser or config.TokenTypeAccount.
Type string `json:"type"`
// AccountID is the owning account, for account-owned tokens.
AccountID string `json:"account_id,omitempty"`
}
TokenInfo describes a verified API token. It never holds the token itself.
func ValidateToken ¶
func ValidateToken(ctx context.Context, token string, candidates []string, hint string) (*TokenInfo, error)
ValidateToken verifies a token and works out whether it is a user token or an account-owned token. See VerifyToken.
func VerifyToken ¶ added in v0.1.1
func VerifyToken(ctx context.Context, c *cloudflare.Client, token string, candidates []string, hint string) (*TokenInfo, error)
VerifyToken verifies a token against the right endpoint:
- user tokens: GET /user/tokens/verify
- account tokens: GET /accounts/{id}/tokens/verify
The user endpoint is tried first, unless the token starts with cfat_ or hint says "account". If it rejects the token (401), each candidate account ID is tried.