Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSuperiorStanislav committed Nov 1, 2023
1 parent ce3d183 commit 72f86d0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 16 deletions.
79 changes: 73 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Collection of [invoke](https://www.pyinvoke.org/) commands used by Saritasa
* [git](#git)
* [git.set-git-setting](#gitset-git-setting)
* [git.setup](#gitsetup)
* [git.clone-repo](#gitclone-repo)
* [pre-commit](#pre-commit)
* [pre-commit.install](#pre-commitinstall)
* [pre-commit.run-hooks](#pre-commitrun-hooks)
Expand Down Expand Up @@ -252,6 +253,10 @@ Settings:
* `merge_ff` setting value for `merge.ff` (Default: `false`)
* `pull_ff` setting value for `pull.ff` (Default: `only`)

#### git.clone-repo

Clone repo or pull latest changes to specified repo

### pre-commit

#### pre-commit.install
Expand Down Expand Up @@ -466,7 +471,18 @@ Uses [create_dump](#db-k8screate-dump) and [get-dump](#db-k8sget-dump)
Settings:

* `settings_path` default django settings (Default: `config.settings.local`)
* `remote_db_config_mapping` Mapping of db config (Default: `{"dbname": "RDS_DB_NAME", "host": "RDS_DB_HOST", "port": "RDS_DB_PORT", "username": "RDS_DB_USER", "password": "RDS_DB_PASSWORD"}`)
* `remote_db_config_mapping` Mapping of db config
Default:

```python
{
"dbname": "RDS_DB_NAME",
"host": "RDS_DB_HOST",
"port": "RDS_DB_PORT",
"username": "RDS_DB_USER",
"password": "RDS_DB_PASSWORD",
}
```

#### django.load-remote-db

Expand Down Expand Up @@ -556,7 +572,19 @@ Installed with `[env_settings]`

Settings:

* `db_config_mapping` Mapping of db config (Default: `{ "dbname": "rds_db_name", "host": "rds_db_host", "port": "rds_db_port", "username": "rds_db_user", "password": "rds_db_password"}`)
* `db_config_mapping` Mapping of db config

Default:

```python
{
"dbname": "rds_db_name",
"host": "rds_db_host",
"port": "rds_db_port",
"username": "rds_db_user",
"password": "rds_db_password",
}
```

#### alembic.backup-local-db

Expand All @@ -570,7 +598,19 @@ Installed with `[env_settings]`

Settings:

* `db_config_mapping` Mapping of db config (Default: `{ "dbname": "rds_db_name", "host": "rds_db_host", "port": "rds_db_port", "username": "rds_db_user", "password": "rds_db_password"}`)
* `db_config_mapping` Mapping of db config

Default:

```python
{
"dbname": "rds_db_name",
"host": "rds_db_host",
"port": "rds_db_port",
"username": "rds_db_user",
"password": "rds_db_password",
}
```

#### alembic.backup-remote-db

Expand All @@ -584,13 +624,25 @@ Installed with `[env_settings]`

Settings:

* `db_config_mapping` Mapping of db config (Default: `{ "dbname": "rds_db_name", "host": "rds_db_host", "port": "rds_db_port", "username": "rds_db_user", "password": "rds_db_password"}`)
* `db_config_mapping` Mapping of db config

Default:

```python
{
"dbname": "rds_db_name",
"host": "rds_db_host",
"port": "rds_db_port",
"username": "rds_db_user",
"password": "rds_db_password",
}
```

#### alembic.load-remote-db

Make dump of remote db and download it and apply to local db.

Uses [create_dump](#db-k8screate-dump) and [get-dump](#db-k8sget-dump) and
Uses [create-dump](#db-k8screate-dump) and [get-dump](#db-k8sget-dump) and
[load-db-dump](#alembicload-db-dump)

Requires [python-decouple](https://github.com/HBNetwork/python-decouple)
Expand All @@ -599,7 +651,19 @@ Installed with `[env_settings]`

Settings:

* `db_config_mapping` Mapping of db config (Default: `{ "dbname": "rds_db_name", "host": "rds_db_host", "port": "rds_db_port", "username": "rds_db_user", "password": "rds_db_password"}`)
* `db_config_mapping` Mapping of db config

Default:

```python
{
"dbname": "rds_db_name",
"host": "rds_db_host",
"port": "rds_db_port",
"username": "rds_db_user",
"password": "rds_db_password",
}
```

### celery

Expand Down Expand Up @@ -832,6 +896,9 @@ Settings:
#### secrets.setup-env-credentials

Fill specified credentials in your file from k8s.
This invocations downloads `.env` file from pod in k8s.
It will replace specified credentials(`--credentials`) in
specified file `.env` file (`--env_file_path` or `.env` as default)

Requires [python-decouple](https://github.com/HBNetwork/python-decouple)

Expand Down
8 changes: 4 additions & 4 deletions saritasa_invocations/alembic.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ def _load_local_env_db_settings(
"""
# decouple could not be installed during project init
# so we import decouple this way because it may not be installed
# at the project initialization stage
# so we import decouple this way to avoid import errors
# during project initialization
import decouple

secrets = decouple.Config(decouple.RepositoryEnv(file or ".env"))
Expand All @@ -256,8 +256,8 @@ def _load_remote_env_db_settings(
"""
# decouple could not be installed during project init
# so we import decouple this way because it may not be installed
# at the project initialization stage
# so we import decouple this way to avoid import errors
# during project initialization
import decouple

with k8s.get_env_secrets(context) as file_path:
Expand Down
4 changes: 2 additions & 2 deletions saritasa_invocations/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ def load_django_remote_env_db_settings(
)

# decouple could not be installed during project init
# so we import decouple this way because it may not be installed
# at the project initialization stage
# so we import decouple this way to avoid import errors
# during project initialization

import decouple

Expand Down
8 changes: 4 additions & 4 deletions saritasa_invocations/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def setup_env_credentials(
context: invoke.Context,
credentials: collections.abc.Sequence[str],
env_file_path: str = "",
env_file_path: str = ".env",
) -> None:
"""Fill specified credentials.
Expand All @@ -20,16 +20,16 @@ def setup_env_credentials(
"""
# decouple could not be installed during project init
# so we import decouple this way because it may not be installed
# at the project initialization stage
# so we import decouple this way to avoid import errors
# during project initialization

import decouple

with k8s.get_env_secrets(context) as file_path:
secrets = decouple.Config(decouple.RepositoryEnv(file_path))
cred_params = {cred: str(secrets(cred)) for cred in credentials}
env_secret_replacer(
env_file_path=env_file_path or ".env",
env_file_path=env_file_path,
**cred_params,
)

Expand Down

0 comments on commit 72f86d0

Please sign in to comment.