Skip to content

fix: use playground setup in all example #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Store encrypted data alongside your existing data:
- Encrypted data is stored using a `jsonb` column type
- Query encrypted data with specialized SQL functions
- Index encrypted columns to enable searchable encryption
- Integrate with [CipherStash Proxy](/docs/tutorials/PROXY.md) for transparent encryption/decryption
- Integrate with [CipherStash Proxy](/docs/tutorials/PROXY.md) for transparent encryption/decryption.

## Table of Contents

Expand Down Expand Up @@ -65,6 +65,8 @@ The simplest way to get up and running with EQL is to execute the install SQL fi
EQL relies on [CipherStash Proxy](docs/tutorials/PROXY.md) for low-latency encryption & decryption.
We plan to support direct language integration in the future.

If you want to use CipherStash Proxy with the below examples or the [helper packages](#helper-packages-and-examples), you can use the [playground environment](playground/README.md).

## Documentation

You can read more about the EQL concepts and reference guides in the [documentation directory](docs/README.md).
Expand Down
File renamed without changes.
21 changes: 0 additions & 21 deletions examples/go/xorm/.envrc.example

This file was deleted.

96 changes: 24 additions & 72 deletions examples/go/xorm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,15 @@

## Running / Development

Create an [account](https://cipherstash.com/signup).

Install the CLI:

```shell
brew install cipherstash/tap/stash
```

Login:

```shell
stash login
```

Create a [dataset](https://cipherstash.com/docs/how-to/creating-datasets) and [client](https://cipherstash.com/docs/how-to/creating-clients), and record them as `CS_CLIENT_ID` and `CS_CLIENT_KEY`.

```shell
stash datasets create xorm
# grab dataset ID and export CS_DATASET_ID=

stash clients create xorm --dataset-id $CS_DATASET_ID
# grab the client ID and export CS_CLIENT_ID=
# grab the client key and export CS_CLIENT_KEY=
```

Create an [access key](https://cipherstash.com/docs/how-to/creating-access-keys) for CipherStash Proxy:

```shell
stash workspaces
# grab the workspace ID and export CS_WORKSPACE_ID=
stash access-keys create --workspace-id $CS_WORKSPACE_ID xorm
# grab the client access key and export CS_CLIENT_ACCESS_KEY=
```

Copy over the example `.envrc` file:

```shell
cp .envrc.example .envrc
```

Update the `.envrc` file with these environment variables `CS_WORKSPACE_ID`, `CS_CLIENT_ACCESS_KEY`, `CS_CLIENT_ID`, `CS_CLIENT_KEY` and `CS_DATASET_ID`:

```shell
source .envrc
```

Start Postgres and CipherStash Proxy and install EQL:

```shell
./run.sh setup
```

Run tests:

```shell
./run.sh tests
```
1. Set up the [playground environment](../../playground/README.md).
2. Run the setup script:
```shell
./run.sh setup
```
3. Run tests:
```shell
./run.sh tests
```

## Integrating EQL into a Xorm app

Expand Down Expand Up @@ -115,8 +67,8 @@ Example for a text field:
```go
func (et EncryptedTextField) ToDB() ([]byte, error) {
etCs := goeql.EncryptedText(et)
// e.g table name is "examples" and field is "encrypted_text_field"
return (&etCs).Serialize("examples", "encrypted_text_field")
// e.g table name is "goexamples" and field is "encrypted_text_field"
return (&etCs).Serialize("goexamples", "encrypted_text_field")
}

func (et *EncryptedTextField) FromDB(data []byte) error {
Expand All @@ -138,8 +90,8 @@ Example for a jsonb field:
```go
func (ej EncryptedJsonbField) ToDB() ([]byte, error) {
ejCs := goeql.EncryptedJsonb(ej)
// e.g table name is "examples" and field is "encrypted_jsonb_field"
return (&ejCs).Serialize("examples", "encrypted_jsonb_field")
// e.g table name is "goexamples" and field is "encrypted_jsonb_field"
return (&ejCs).Serialize("goexamples", "encrypted_jsonb_field")
}

func (ej *EncryptedJsonbField) FromDB(data []byte) error {
Expand All @@ -163,10 +115,10 @@ These checks will validate that the json payload is correct and that encrypted d
Example:

```sql
ALTER TABLE examples ADD CONSTRAINT encrypted_text_field_encrypted_check
ALTER TABLE goexamples ADD CONSTRAINT encrypted_text_field_encrypted_check
CHECK ( cs_check_encrypted_v1(encrypted_text_field) );

ALTER TABLE examples ADD CONSTRAINT encrypted_jsonb_encrypted_check
ALTER TABLE goexamples ADD CONSTRAINT encrypted_jsonb_encrypted_check
CHECK ( cs_check_encrypted_v1(encrypted_jsonb_field) );
```

Expand All @@ -175,17 +127,17 @@ Example:
Example:

```sql
SELECT cs_add_index_v1('examples', 'encrypted_text_field', 'unique', 'text', '{"token_filters": [{"kind": "downcase"}]}');
SELECT cs_add_index_v1('examples', 'encrypted_text_field', 'match', 'text');
SELECT cs_add_index_v1('examples', 'encrypted_text_field', 'ore', 'text');
SELECT cs_add_index_v1('examples', 'encrypted_jsonb_field', 'ste_vec', 'jsonb', '{"prefix": "examples/encrypted_jsonb_field"}');
SELECT cs_add_index_v1('goexamples', 'encrypted_text_field', 'unique', 'text', '{"token_filters": [{"kind": "downcase"}]}');
SELECT cs_add_index_v1('goexamples', 'encrypted_text_field', 'match', 'text');
SELECT cs_add_index_v1('goexamples', 'encrypted_text_field', 'ore', 'text');
SELECT cs_add_index_v1('goexamples', 'encrypted_jsonb_field', 'ste_vec', 'jsonb', '{"prefix": "goexamples/encrypted_jsonb_field"}');

-- The below indexes will also need to be added to enable full search functionality on the encrypted columns

CREATE UNIQUE INDEX ON examples(cs_unique_v1(encrypted_text_field));
CREATE INDEX ON examples USING GIN (cs_match_v1(encrypted_text_field));
CREATE INDEX ON examples (cs_ore_64_8_v1(encrypted_text_field));
CREATE INDEX ON examples USING GIN (cs_ste_vec_v1(encrypted_jsonb_field));
CREATE UNIQUE INDEX ON goexamples(cs_unique_v1(encrypted_text_field));
CREATE INDEX ON goexamples USING GIN (cs_match_v1(encrypted_text_field));
CREATE INDEX ON goexamples (cs_ore_64_8_v1(encrypted_text_field));
CREATE INDEX ON goexamples USING GIN (cs_ste_vec_v1(encrypted_jsonb_field));

-- Run these functions to activate

Expand Down Expand Up @@ -222,7 +174,7 @@ Examples of how to use these are in the [e2e_test.go](./e2e_test.go) file.
Below is an example of running a match query on a text field.

```go
query, errTwo := goeql.MatchQuery("some", "examples", "encrypted_text_field")
query, errTwo := goeql.MatchQuery("some", "goexamples", "encrypted_text_field")
if errTwo != nil {
log.Fatalf("Error marshaling encrypted_text_field: %v", errTwo)
}
Expand Down
40 changes: 0 additions & 40 deletions examples/go/xorm/docker-compose.yml

This file was deleted.

Loading