Skip to content

Commit

Permalink
separate accounts for user and test
Browse files Browse the repository at this point in the history
Signed-off-by: Fotis Nikolaidis <[email protected]>
  • Loading branch information
fnikolai committed Dec 1, 2023
1 parent 35eacc8 commit 04f7b77
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 19 deletions.
4 changes: 2 additions & 2 deletions deploy/testenv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

### Available users:

`superduper:superduper` on `test_db` database
`superduper:superduper` on `user_db` database

```shell
mongosh "mongodb://superduper:superduper@mongodb:27017/test_db"
mongosh "mongodb://superduper:superduper@mongodb:27017/user_db"
```

Have in mind that `docker-compose` with source the `default credentials` from `.env` file.
Expand Down
10 changes: 6 additions & 4 deletions deploy/testenv/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
hostname: mongodb
ports:
- "27017:27017"
volumes:
- ./.mongo_data:/data/db
command : ["/bin/sh", "-c", "mongod --replSet rs0 --port 27017 --bind_ip 0.0.0.0 --dbpath /data/db/"]

mongo-init: # Once finished, Mongo is assumed to be ready.
Expand All @@ -35,7 +37,7 @@ services:
volumes:
- ../../:/home/superduper/superduperdb # mount the project path
environment:
SUPERDUPERDB_DATA_BACKEND: 'mongodb://superduper:superduper@mongodb:27017/test_db'
SUPERDUPERDB_DATA_BACKEND: 'mongodb://superduper:superduper@mongodb:27017/user_db'
SUPERDUPERDB_CLUSTER_VECTOR_SEARCH: 'http://localhost:8000'
command:
- /bin/sh
Expand Down Expand Up @@ -70,7 +72,7 @@ services:
volumes:
- ../../:/home/superduper/superduperdb # mount the project path
environment:
SUPERDUPERDB_DATA_BACKEND: 'mongodb://superduper:superduper@mongodb:27017/test_db'
SUPERDUPERDB_DATA_BACKEND: 'mongodb://superduper:superduper@mongodb:27017/user_db'
SUPERDUPERDB_CLUSTER_CDC: 'http://localhost:8001'
command:
- /bin/sh
Expand Down Expand Up @@ -106,7 +108,7 @@ services:
volumes:
- ../../:/home/superduper/superduperdb # mount the project path
environment:
SUPERDUPERDB_DATA_BACKEND: 'mongodb://superduper:superduper@mongodb:27017/test_db'
SUPERDUPERDB_DATA_BACKEND: 'mongodb://superduper:superduper@mongodb:27017/user_db'
command:
- /bin/sh
- -c
Expand All @@ -120,7 +122,7 @@ services:
volumes:
- ../../:/home/superduper/superduperdb # mount the project path
environment:
SUPERDUPERDB_DATA_BACKEND: 'mongodb://superduper:superduper@mongodb:27017/test_db'
SUPERDUPERDB_DATA_BACKEND: 'mongodb://superduper:superduper@mongodb:27017/user_db'
command:
- /bin/sh
- -c
Expand Down
25 changes: 23 additions & 2 deletions deploy/testenv/mongo-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mongosh --host mongodb <<EOF
rs.status()
EOF

echo "Creating normal user: superduper:superduper/test_db"
echo "Creating normal user: ${SDDB_USER}:${SDDB_PASS}/${SDDB_DATABASE}"
mongosh --host mongodb <<EOF
use ${SDDB_DATABASE}
db.createUser(
Expand All @@ -49,7 +49,28 @@ mongosh --host mongodb <<EOF
)
EOF

echo "Confirm everything works properly"
echo "Confirm normal user account"
echo "---------------------------------------"
mongosh --eval 'rs.status()' "mongodb://${SDDB_USER}:${SDDB_PASS}@mongodb:27017/${SDDB_DATABASE}"
echo "---------------------------------------"


echo "Creating test user: ${SDDB_TEST_USER}:${SDDB_TEST_PASS}/${SDDB_TEST_DATABASE}"
mongosh --host mongodb <<EOF
use ${SDDB_TEST_DATABASE}
db.createUser(
{
user: "${SDDB_TEST_USER}",
pwd: "${SDDB_TEST_PASS}",
roles: [ { role: "dbOwner", db: "${SDDB_TEST_DATABASE}" } ]
}
)
EOF


echo "Confirm test user account"
echo "---------------------------------------"
mongosh --eval 'rs.status()' "mongodb://${SDDB_TEST_USER}:${SDDB_TEST_PASS}@mongodb:27017/${SDDB_TEST_DATABASE}"
echo "---------------------------------------"


9 changes: 7 additions & 2 deletions deploy/testenv/users.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Custom user for SuperDuper
# Normal user account
SDDB_USER=superduper
SDDB_PASS=superduper
SDDB_DATABASE=test_db
SDDB_DATABASE=user_db

# Test user account
SDDB_TEST_USER=superduper_test
SDDB_TEST_PASS=superduper_test
SDDB_TEST_DATABASE=test_db
4 changes: 2 additions & 2 deletions docs/hr/content/docs/setup/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ configurations will then take on their default values.

```yaml

# URI of your database/ datastore (here the name of the db is `test_db`)
data_backend: mongodb://superduper:superduper@localhost:27017/test_db
# URI of your database/ datastore (here the name of the db is `user_db`)
data_backend: mongodb://superduper:superduper@localhost:27017/user_db

# URI of your artifact store (defaults to `data_backend`)
artifact_store: null
Expand Down
2 changes: 1 addition & 1 deletion docs/hr/content/docs/setup/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Now add these configurations to your setup by running:
```bash
mkdir -p .superduperdb
cat << Multi > .superduperdb/config.yaml
data_backend: mongodb://superduper:superduper@mongodb:27017/test_db
data_backend: mongodb://superduper:superduper@mongodb:27017/user_db
cluster:
cdc: http://cdc:8001
compute: dask://scheduler:8786
Expand Down
2 changes: 1 addition & 1 deletion examples/question_the_docs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"from superduperdb.backends.mongodb import Collection\n",
"import os\n",
"\n",
"mongodb_uri = os.getenv(\"MONGODB_URI\", \"mongodb://127.0.0.1:27017/test_db\")\n",
"mongodb_uri = os.getenv(\"MONGODB_URI\", \"mongodb://127.0.0.1:27017/user_db\")\n",
"\n",
"# SuperDuperDB, now handles your MongoDB database\n",
"# It just super dupers your database\n",
Expand Down
2 changes: 1 addition & 1 deletion superduperdb/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Config(BaseConfigJSONable):
def self_hosted_vector_search(self) -> bool:
return self.data_backend == self.vector_search

data_backend: str = 'mongodb://superduper:superduper@localhost:27017/test_db'
data_backend: str = 'mongodb://superduper:superduper@localhost:27017/user_db'

vector_search: 'str' = 'in_memory'
lance_home: str = os.path.join('.superduperdb', 'vector_indices')
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_db(monkeypatch, request) -> Iterator[Datalayer]:

# mongodb instead of localhost is required for CFG compatibility with docker-host
db_name = "test_db"
data_backend = f'mongodb://superduper:superduper@mongodb:27017/{db_name}'
data_backend = f'mongodb://superduper_test:superduper_test@mongodb:27017/{db_name}'

monkeypatch.setattr(CFG, 'data_backend', data_backend)

Expand Down
2 changes: 1 addition & 1 deletion test/db_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MONGOMOCK_URI = 'mongomock:///test_db'
MONGOMOCK_URI = 'mongomock:///user_db'
SQLITE_URI = 'sqlite://:memory:'
N_DATA_POINTS = 5

Expand Down
2 changes: 1 addition & 1 deletion test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def fake_updates(database_with_default_encoders_and_model):
@pytest.fixture
def dask_client(monkeypatch, request):
db_name = "test_db"
data_backend = f'mongodb://superduper:superduper@localhost:27017/{db_name}'
data_backend = f'mongodb://superduper_test:superduper_test@localhost:27017/{db_name}'

monkeypatch.setenv('SUPERDUPERDB_DATA_BACKEND', data_backend)

Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def distributed_db(monkeypatch, test_db, dask_client):

existing_databackend = CFG.data_backend
CFG.force_set(
'data_backend', 'mongodb://superduper:superduper@mongodb:27017/test_db'
'data_backend', 'mongodb://superduper:superduper@mongodb:27017/user_db'
)
cdc = 'http://localhost:8001'
vector_search = 'http://localhost:8000'
Expand Down

0 comments on commit 04f7b77

Please sign in to comment.