Skip to content

Commit 4fb2fd7

Browse files
committed
fix: use playground setup in xorm example
1 parent d2f873c commit 4fb2fd7

File tree

11 files changed

+112
-148
lines changed

11 files changed

+112
-148
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Store encrypted data alongside your existing data:
1313
- Encrypted data is stored using a `jsonb` column type
1414
- Query encrypted data with specialized SQL functions
1515
- Index encrypted columns to enable searchable encryption
16-
- Integrate with [CipherStash Proxy](/docs/tutorials/PROXY.md) for transparent encryption/decryption
16+
- Integrate with [CipherStash Proxy](/docs/tutorials/PROXY.md) for transparent encryption/decryption.
1717

1818
## Table of Contents
1919

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

68+
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).
69+
6870
## Documentation
6971

7072
You can read more about the EQL concepts and reference guides in the [documentation directory](docs/README.md).

examples/go/xorm/.envrc.example

-21
This file was deleted.

examples/go/xorm/README.md

+9-57
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,15 @@
1010

1111
## Running / Development
1212

13-
Create an [account](https://cipherstash.com/signup).
14-
15-
Install the CLI:
16-
17-
```shell
18-
brew install cipherstash/tap/stash
19-
```
20-
21-
Login:
22-
23-
```shell
24-
stash login
25-
```
26-
27-
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`.
28-
29-
```shell
30-
stash datasets create xorm
31-
# grab dataset ID and export CS_DATASET_ID=
32-
33-
stash clients create xorm --dataset-id $CS_DATASET_ID
34-
# grab the client ID and export CS_CLIENT_ID=
35-
# grab the client key and export CS_CLIENT_KEY=
36-
```
37-
38-
Create an [access key](https://cipherstash.com/docs/how-to/creating-access-keys) for CipherStash Proxy:
39-
40-
```shell
41-
stash workspaces
42-
# grab the workspace ID and export CS_WORKSPACE_ID=
43-
stash access-keys create --workspace-id $CS_WORKSPACE_ID xorm
44-
# grab the client access key and export CS_CLIENT_ACCESS_KEY=
45-
```
46-
47-
Copy over the example `.envrc` file:
48-
49-
```shell
50-
cp .envrc.example .envrc
51-
```
52-
53-
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`:
54-
55-
```shell
56-
source .envrc
57-
```
58-
59-
Start Postgres and CipherStash Proxy and install EQL:
60-
61-
```shell
62-
./run.sh setup
63-
```
64-
65-
Run tests:
66-
67-
```shell
68-
./run.sh tests
69-
```
13+
1. Set up the [playground environment](../../playground/README.md).
14+
2. Run the setup script:
15+
```shell
16+
./run.sh setup
17+
```
18+
3. Run tests:
19+
```shell
20+
./run.sh tests
21+
```
7022

7123
## Integrating EQL into a Xorm app
7224

examples/go/xorm/docker-compose.yml

-40
This file was deleted.

examples/go/xorm/e2e_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
func proxyEngine() *xorm.Engine {
1616

17-
proxyConnStr := "user=postgres password=postgres port=6432 host=localhost dbname=gotest sslmode=disable"
17+
proxyConnStr := "user=postgres password=postgres port=6432 host=localhost dbname=postgres sslmode=disable"
1818
proxyEngine, err := xorm.NewEngine("pgx", proxyConnStr)
1919

2020
if err != nil {

examples/go/xorm/init-db/Dockerfile

-9
This file was deleted.

examples/go/xorm/init-db/create-db.sql

-1
This file was deleted.

examples/go/xorm/init-db/init.sh

-4
This file was deleted.

examples/go/xorm/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ func (eb *EncryptedBoolField) FromDB(data []byte) error {
124124
}
125125

126126
func createTable() {
127-
connStr := "user=postgres password=postgres port=5432 host=localhost dbname=gotest sslmode=disable"
127+
connStr := "user=postgres password=postgres port=5432 host=localhost dbname=postgres sslmode=disable"
128128
engine, err := xorm.NewEngine("pgx", connStr)
129129

130130
if err != nil {
131-
log.Fatalf("Could not connect to gotest database: %v", err)
131+
log.Fatalf("Could not connect to postgres database: %v", err)
132132
}
133133

134134
// need to map from struct to postgres snake case lowercase
@@ -145,7 +145,7 @@ func createTable() {
145145
}
146146

147147
func addIndexesConstraints() {
148-
connStr := "user=postgres password=postgres port=5432 host=localhost dbname=gotest sslmode=disable"
148+
connStr := "user=postgres password=postgres port=5432 host=localhost dbname=postgres sslmode=disable"
149149
// Install Eql, custom types, indexes and constraints
150150
// To install our custom types we need to use the database/sql package due to an issue
151151
// with how xorm interprets `?`.

examples/go/xorm/run.sh

-11
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@ if [ "${BASH_SOURCE[0]}" != "./run.sh" ]; then
1515
fi
1616

1717
subproject_setup() {
18-
# start postgres and proxy (create db and install eql)
19-
docker compose up -d
2018
# constraints and indexes
2119
go run . setupDev
2220
}
2321

24-
subproject_teardown() {
25-
# start postgres
26-
docker compose down
27-
}
28-
2922
subproject_tests(){
3023
# run e2e tests
3124
make gotest
@@ -37,10 +30,6 @@ case $subcommand in
3730
subproject_setup
3831
;;
3932

40-
teardown)
41-
subproject_teardown
42-
;;
43-
4433
tests)
4534
subproject_tests
4635
;;

playground/README.md

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# EQL and CipherStash Proxy playground
2+
3+
This playground environment provides a simple setup to experiment with **CipherStash Proxy** and **EQL** in a Docker Compose environment.
4+
It includes a PostgreSQL database with EQL installed at build time and a CipherStash Proxy configured to integrate with your CipherStash account.
5+
This environment is ideal for running the examples in the repository or testing CipherStash features.
6+
7+
## Prerequisites
8+
9+
1. [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed.
10+
2. A CipherStash account and access to the [CipherStash Dashboard](https://dashboard.cipherstash.com) to obtain required environment variables.
11+
3. The [CipherStash CLI](https://cipherstash.com/docs/reference/cli) installed and configured with your account credentials.
12+
13+
New to CipherStash? [Sign up for a free account](https://cipherstash.com/signup) to get started.
14+
15+
## Services
16+
17+
- **Postgres**: A PostgreSQL database with EQL installed at build time.
18+
- **Proxy**: The CipherStash Proxy service that encrypts/decrypts data and manages schema encryption.
19+
20+
## Setup
21+
22+
1. Clone the repository:
23+
```bash
24+
git clone https://github.com/cipherstash/encrypt-query-language.git
25+
cd encrypt-query-language/playground
26+
```
27+
28+
2. Create a `.envrc` file with the following variables:
29+
```env
30+
# CipherStash account credentials
31+
export CS_WORKSPACE_ID=your_workspace_id
32+
export CS_CLIENT_ACCESS_KEY=your_client_access_key
33+
34+
# Encryption keys
35+
export CS_ENCRYPTION__CLIENT_ID=your_client_id
36+
export CS_ENCRYPTION__CLIENT_KEY=your_client_key
37+
export CS_ENCRYPTION__DATASET_ID=your_dataset_id
38+
39+
# Optional overrides
40+
export PGPORT=5432
41+
export CS_PORT=6432
42+
```
43+
44+
These values are available in your [CipherStash Dashboard](https://dashboard.cipherstash.com).
45+
The [Client ID and Key](https://cipherstash.com/docs/how-to/creating-clients) and [Dataset ID](https://cipherstash.com/docs/how-to/creating-datasets) are created through the CipherStash CLI.
46+
47+
3. Build and run the environment:
48+
```bash
49+
docker compose up --build
50+
```
51+
52+
## Usage
53+
54+
### Connecting to PostgreSQL
55+
56+
The PostgreSQL service is exposed on `localhost:${PGPORT:-5432}`. You can connect using any PostgreSQL client:
57+
58+
```bash
59+
psql -h localhost -p 5432 -U postgres
60+
```
61+
62+
### Connecting to CipherStash Proxy
63+
64+
The CipherStash Proxy service is exposed on `localhost:${CS_PORT:-6432}`. Example connection string:
65+
66+
```text
67+
postgresql://postgres:postgres@localhost:6432/postgres
68+
```
69+
70+
or using `psql`:
71+
72+
```bash
73+
psql -h localhost -p 6432 -U postgres
74+
```
75+
76+
### Logs
77+
78+
- PostgreSQL logs all SQL statements (`log_statement=all`) for debugging purposes.
79+
- CipherStash Proxy supports unsafe logging for development. Disable it in production by setting `CS_UNSAFE_LOGGING` to `false`.
80+
81+
### Examples
82+
83+
Use this playground to test any examples from the repository's [examples](../examples/) directory:
84+
85+
## Notes
86+
87+
- **Security warning**: Do not use this environment in production. It is designed for local development and testing purposes only.
88+
- **EQL installation**: The `eql-playground-pg` container automatically installs EQL during the build process. If modifications are needed, update the Dockerfile in the `db` directory.
89+
90+
## Stopping the Environment
91+
92+
To stop and remove the containers:
93+
94+
```bash
95+
docker compose down
96+
```

0 commit comments

Comments
 (0)