caddy_storage_cf_kv

package module
v0.0.0-...-939ac14 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

README

Caddy Storate Cloudflare KV

Use Cloudflare KV as Caddy storage.

Caddy module name
caddy.storage.cloudflare_kv
Build custom Caddy with this storage using xcaddy
xcaddy build --with github.com/mentimeter/caddy-storage-cf-kv
Token required permissions
  • Workers KV Storage Read
  • Workers KV Storage Write
Setup Caddyfile
{
    storage cloudflare_kv {
        api_token "<TOKEN>"
        account_id "<ACCOUNT_ID>"
        namespace_id "<NAMESPACE_ID>"
    }
}

or using environment variables

{
    storage cloudflare_kv {
        api_token "{env.CLOUDFLARE_API_TOKEN}"
        account_id "{env.CLOUDFLARE_ACCOUNT_ID}"
        namespace_id "{env.CLOUDFLARE_NAMESPACE_ID}"
    }
}

which will replace {env.CLOUDFLARE_API_TOKEN}, {env.CLOUDFLARE_ACCOUNT_ID} and {env.CLOUDFLARE_NAMESPACE} with the equivalent CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_NAMESPACE environment variables at runtime.

For example, running with Cloudflare as the DNS resolver (using https://github.com/caddy-dns/cloudflare) and storage for the created TLS certificates.

{
    http_port 80
    https_port 443

    storage cloudflare_kv {
        api_token "{env.CLOUDFLARE_API_TOKEN}"
        account_id "{env.CLOUDFLARE_ACCOUNT_ID}"
        namespace_id "{env.CLOUDFLARE_NAMESPACE_ID}"
    }
}

example.org, *.example.org {
    reverse_proxy localhost:3000

    tls {
        dns cloudflare {env.CLOUDFLARE_API_TOKEN}
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudflareKVStorage

type CloudflareKVStorage struct {
	Logger *zap.SugaredLogger `json:"-"`

	APIToken    string `json:"api_token,omitempty"`    // The Cloudflare API token
	AccountID   string `json:"account_id,omitempty"`   // Cloudflare Account ID
	NamespaceID string `json:"namespace_id,omitempty"` // KV Namespace ID
	// contains filtered or unexported fields
}

CloudflareKVStorage implements a Caddy storage backend for Cloudflare KV

func (CloudflareKVStorage) CaddyModule

func (CloudflareKVStorage) CaddyModule() caddy.ModuleInfo

func (*CloudflareKVStorage) CertMagicStorage

func (s *CloudflareKVStorage) CertMagicStorage() (certmagic.Storage, error)

func (*CloudflareKVStorage) Delete

func (s *CloudflareKVStorage) Delete(ctx context.Context, key string) error

func (*CloudflareKVStorage) Exists

func (s *CloudflareKVStorage) Exists(ctx context.Context, key string) bool

func (*CloudflareKVStorage) List

func (s *CloudflareKVStorage) List(_ context.Context, path string, recursive bool) ([]string, error)

func (*CloudflareKVStorage) Load

func (s *CloudflareKVStorage) Load(_ context.Context, key string) ([]byte, error)

func (*CloudflareKVStorage) Lock

func (s *CloudflareKVStorage) Lock(ctx context.Context, key string) error

func (*CloudflareKVStorage) Provision

func (s *CloudflareKVStorage) Provision(ctx caddy.Context) error

func (*CloudflareKVStorage) Stat

func (*CloudflareKVStorage) Store

func (s *CloudflareKVStorage) Store(_ context.Context, key string, value []byte) error

func (CloudflareKVStorage) String

func (s CloudflareKVStorage) String() string

func (*CloudflareKVStorage) Unlock

func (s *CloudflareKVStorage) Unlock(_ context.Context, key string) error

func (*CloudflareKVStorage) UnmarshalCaddyfile

func (s *CloudflareKVStorage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

type LoadValueResponse

type LoadValueResponse struct {
	MetadataJsonString string `json:"metadata"`
	Value              string `json:"value"`
}

type Metadata

type Metadata struct {
	Modified time.Time `json:"modified"`
}

Jump to

Keyboard shortcuts

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