Skip to content

Commit

Permalink
extract kv url to an environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Grunet authored May 26, 2024
1 parent 3ac8a07 commit 030051a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ Create a script called `updateKv.ts` (for use with the Deno CLI) as follows
```ts
import { createKvClient } from "jsr:@grunet/openfeature-for-denodeploy";

const urlToKv =
"https://api.deno.com/databases/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/connect";

const urlToKv = Deno.env.get("URL_TO_KV");
const kv = await Deno.openKv(urlToKv);
const client = createKvClient(kv);

Expand All @@ -85,16 +83,20 @@ Before you can run it you'll need to get 2 things
2. A Deno Deploy access token

The former can be found at
`https://dash.deno.com/projects/<your project name>/kv`. Update the `urlToKv`
variable in the script with its value.
`https://dash.deno.com/projects/<your project name>/kv`. It should look like
`"https://api.deno.com/databases/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/connect"`.

The latter can be created at https://dash.deno.com/account#access-tokens.

To run the script you'll want to run the following command from the script's
working directory, substituting in your access token for the placeholder.
To run the script you'll want to run the following commands from the script's
working directory, substituting in the KV url and your access token for the
placeholders.

```bash
DENO_KV_ACCESS_TOKEN=<replace with your access token> deno run --unstable-kv --allow-read=flags.json --allow-env=DENO_KV_ACCESS_TOKEN --allow-net updateKv.ts
export URL_TO_KV=<replace with the url to KV>
export DENO_KV_ACCESS_TOKEN=<replace with your access token>

deno run --unstable-kv --allow-read=flags.json --allow-env=URL_TO_KV,DENO_KV_ACCESS_TOKEN --allow-net updateKv.ts
```

This will store the flag definitions JSON into KV in Deno Deploy for your
Expand Down
13 changes: 7 additions & 6 deletions examples/attribute-targeting/updateKv.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Run from this as the working directory with the following
// DENO_KV_ACCESS_TOKEN=<Gotten from https://dash.deno.com/account#access-tokens> deno run --unstable-kv --allow-read=flags.json --allow-env=DENO_KV_ACCESS_TOKEN --allow-net updateKv.ts
// Have to use --allow-net because wildcards aren't allowed and the CLI is reaching out to a URL like "us-east4.txnproxy.deno-gcp.net" (see https://github.com/denoland/deno/issues/6532)

import { createKvClient } from "jsr:@grunet/openfeature-for-denodeploy";
// export URL_TO_KV=<Gotten from https://dash.deno.com/projects/<your project name>/kv>
// export DENO_KV_ACCESS_TOKEN=<Gotten from https://dash.deno.com/account#access-tokens>
// deno run --unstable-kv --allow-read=flags.json --allow-env=URL_TO_KV,DENO_KV_ACCESS_TOKEN --allow-net updateKv.ts

// Had to use --allow-net because wildcards aren't allowed and the CLI is reaching out to a URL like "us-east4.txnproxy.deno-gcp.net" (see https://github.com/denoland/deno/issues/6532)

// TODO - replace this with your project's URL (found at https://dash.deno.com/projects/<your project name>/kv)
const urlToKv =
"https://api.deno.com/databases/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/connect";
import { createKvClient } from "jsr:@grunet/openfeature-for-denodeploy";

const urlToKv = Deno.env.get("URL_TO_KV");
const kv = await Deno.openKv(urlToKv);
const client = createKvClient(kv);

Expand Down

0 comments on commit 030051a

Please sign in to comment.