Skip to content

Commit c716c3f

Browse files
authored
Read settings from .env file (fixes #53) (#131)
* Add python-dotenv dependency * Read settings from .env file (fixes #53) * Move local dev example to .env.example * Run detect-secrets scan --baseline .secrets.baseline * Run tests using .env.example
1 parent 5be404d commit c716c3f

File tree

9 files changed

+92
-511
lines changed

9 files changed

+92
-511
lines changed
File renamed without changes.

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,3 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130-
131-
# Don't check in your own Env
132-
/config/local_dev.env

.secrets.baseline

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,31 +100,31 @@
100100
}
101101
],
102102
"results": {
103-
"README.md": [
104-
{
105-
"type": "Hex High Entropy String",
106-
"filename": "README.md",
107-
"hashed_secret": "04e78d6e804f2b59e6cb282cb9ed2c7bfd8a9737",
108-
"is_verified": false,
109-
"line_number": 184
110-
}
111-
],
112-
"config/local_dev.env": [
103+
".env.example": [
113104
{
114105
"type": "Secret Keyword",
115-
"filename": "config/local_dev.env",
106+
"filename": ".env.example",
116107
"hashed_secret": "4b9a4ce92b6a01a4cd6ee1672d31c043f2ae79ab",
117108
"is_verified": false,
118109
"line_number": 7
119110
},
120111
{
121112
"type": "Secret Keyword",
122-
"filename": "config/local_dev.env",
113+
"filename": ".env.example",
123114
"hashed_secret": "77ea6398f252999314d609a708842a49fc43e055",
124115
"is_verified": false,
125116
"line_number": 10
126117
}
118+
],
119+
"README.md": [
120+
{
121+
"type": "Hex High Entropy String",
122+
"filename": "README.md",
123+
"hashed_secret": "04e78d6e804f2b59e6cb282cb9ed2c7bfd8a9737",
124+
"is_verified": false,
125+
"line_number": 194
126+
}
127127
]
128128
},
129-
"generated_at": "2022-07-21T07:58:50Z"
129+
"generated_at": "2022-07-21T13:06:53Z"
130130
}

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ _GID ?= 10001
66

77
VENV := $(shell echo $${VIRTUAL_ENV-.venv})
88
INSTALL_STAMP = $(VENV)/.install.stamp
9+
DOTENV_FILE = ".env"
910
POETRY_VIRTUALENVS_IN_PROJECT = true
1011

1112
.PHONY: help
@@ -48,15 +49,18 @@ lint: $(INSTALL_STAMP)
4849
bin/lint.sh
4950

5051
.PHONY: start
51-
start:
52+
start: $(INSTALL_STAMP) $(DOTENV_FILE)
5253
poetry run python -m src.app.api
5354

55+
$(DOTENV_FILE):
56+
cp -n .env.example $(DOTENV_FILE)
57+
5458
.PHONY: docker-shell
55-
docker-shell:
59+
docker-shell: $(DOTENV_FILE)
5660
docker-compose run --rm web /bin/sh
5761

5862
.PHONY: docker-start
59-
docker-start:
63+
docker-start: $(DOTENV_FILE)
6064
docker-compose up
6165

6266
.PHONY: test

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Jira Bugzilla Integration (JBI)
66
System to sync Bugzilla bugs to Jira issues.
77

8-
### Caveats
8+
## Caveats
99
- The system accepts webhook events from Bugzilla
1010
- Bugs' `whiteboard` tags are used to determine if they should be synchronized or ignored
1111
- The events are transformed into Jira issues
@@ -91,7 +91,7 @@ features on top of the default.
9191

9292
It will attempt to assign the Jira issue the same person as the bug is assigned to. This relies on
9393
the user using the same email address in both Bugzilla and Jira. If the user does not exist in Jira
94-
then the assignee is cleared from the Jira issue. The Jira account that JBI uses requires the "Browse
94+
then the assignee is cleared from the Jira issue. The Jira account that JBI uses requires the "Browse
9595
users and groups" global permission in order to set the assignee.
9696

9797
If configured, the action supports setting the Jira issues's status when the Bugzilla status and resolution change.
@@ -145,6 +145,16 @@ graph TD
145145
end
146146
```
147147

148+
## Development
149+
150+
- `make start`: run the application locally (http://localhost:8000)
151+
- `make test`: run the unit tests suites
152+
- `make lint`: static analysis of the code base
153+
154+
You may consider:
155+
156+
* Tweaking the application settings in the `.env` file (See `src/app/environment.py` for details)
157+
* Installing a pre-commit hook to lint your changes with `pre-commit install`
148158

149159
## Deployment
150160

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
build: .
55
command: python -m src.app.api
66
env_file:
7-
- config/local_dev.env
7+
- .env
88
# Let the init system handle signals for us.
99
# among other things this helps shutdown be fast
1010
init: true

poetry.lock

Lines changed: 51 additions & 487 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MPL"
88
[tool.poetry.dependencies]
99
python = ">=3.8, <3.11"
1010
fastapi = "^0.73.0"
11-
pydantic = {version = "^1.9.1", extras = ["email"]}
11+
pydantic = {version = "^1.9.1", extras = ["dotenv", "email"]}
1212
uvicorn = {extras = ["standard"], version = "^0.18.2"}
1313
gunicorn = "^20.1.0"
1414
prometheus-client = "^0.14.1"
@@ -44,7 +44,7 @@ testpaths = [
4444
]
4545
env_override_existing_values = true
4646
env_files = [
47-
"config/local_dev.env"
47+
".env.example"
4848
]
4949

5050
[tool.pylint]

src/app/environment.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class Settings(BaseSettings):
3636
# Sentry
3737
sentry_dsn: Optional[SentryDsn]
3838

39+
class Config:
40+
"""Pydantic configuration"""
41+
42+
env_file = ".env"
43+
env_file_encoding = "utf-8"
44+
3945

4046
@lru_cache()
4147
def get_settings() -> Settings:

0 commit comments

Comments
 (0)