Skip to content

Latest commit

 

History

History
123 lines (93 loc) · 6.8 KB

README.md

File metadata and controls

123 lines (93 loc) · 6.8 KB

Cloudflare KV Action

Test Release semantic-release: conventional Conventional Commits

Put, get and delete values in Cloudflare KV.

Table of Contents

Usage

Bearer Token (recommended)

Create an API Token with Workers KV Storage permissions.

- name: cloudflare-kv-action
  uses: zentered/cloudflare-kv-action@v2
  id: cloudflare_kv
  env:
    CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
  with:
    namespace_identifier: '123'
    key_name: 'hello'
    value: 'world'
    expiration_ttl: 120
- name: Value
  run: echo "${{ steps.cloudflare_kv.outputs.value }}"

Legacy Auth (API Key + Email)

- name: cloudflare-kv-action
  uses: zentered/cloudflare-kv-action@v2
  id: cloudflare_kv
  env:
    CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
    CLOUDFLARE_ACCOUNT_EMAIL: ${{ secrets.CLOUDFLARE_ACCOUNT_EMAIL }}
    CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
  with:
    namespace_identifier: '123'
    key_name: 'hello'
    value: 'world'
    expiration_ttl: 120
- name: Value
  run: echo "${{ steps.cloudflare_kv.outputs.value }}"

Environment Variables / Secret

In the repository, go to "Settings", then "Secrets" and add your Cloudflare credentials. You can retrieve them on your Cloudflare account.

Variable Required Description
CLOUDFLARE_ACCOUNT_ID required From the URL: https://dash.cloudflare.com/123abc....
CLOUDFLARE_API_KEY required API Token (Bearer) or Global API Key (legacy)
CLOUDFLARE_ACCOUNT_EMAIL optional Required only for legacy API Key auth

Inputs

Name Requirement Description
namespace_identifier required Cloudflare namespace ID
key_name required KV key name
value optional Use "value" to set a key; omit to retrieve the current value. Ignored when operation is get or delete.
expiration optional Absolute expiration (Unix timestamp). Ignored for get and delete.
expiration_ttl optional Relative expiration in seconds. If both expiration and expiration_ttl are set, expiration takes precedence. Ignored for get and delete.
operation optional get, put or delete. Default: put if value is not empty, otherwise get. Use put to set an empty value.
fail_on_missing optional Default true: a get of a missing key fails the step. Set false to get an empty value output instead. Only a key-not-found 404 counts as missing. Other errors, such as an unknown namespace, always fail. Accepts only true, True, TRUE, false, False or FALSE. Any other value, including an empty one such as an unset vars.X, fails the step.

Cloudflare API Reference

Outputs

Name Description
value KV value

The output value and its parts are masked in logs: each line, and each string or number inside a JSON value. Short values such as 1 or true are masked too, so they also disappear from other log lines.

Development

Requirements: Node >= 20

# Install dependencies
npm install

# Copy and fill in your Cloudflare credentials
cp .env.example .env

# Run linter
npm run lint

# Run tests (unit tests run without credentials; integration tests require .env)
npm test

# Rebuild dist/ after code changes
npm run prepare

Contributing

See CONTRIBUTING.

License

See LICENSE.