Skip to content

Commit e36bd2b

Browse files
author
Andrei Neagu
committed
fixed openapi specs script
1 parent 4e9ccca commit e36bd2b

File tree

3 files changed

+76
-20
lines changed

3 files changed

+76
-20
lines changed

services/notifications/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ include ../../scripts/common.Makefile
55
include ../../scripts/common-service.Makefile
66

77

8+
.env-ignore:
9+
$(APP_CLI_NAME) echo-dotenv > $@
10+
811
.PHONY: openapi.json
912
openapi-specs: openapi.json
10-
openapi.json: .env
13+
openapi.json: .env-ignore ## produces openapi.json
1114
# generating openapi specs file (need to have the environment set for this)
1215
@set -o allexport; \
1316
source $<; \
1417
set +o allexport; \
1518
python3 -c "import json; from $(APP_PACKAGE_NAME).main import *; print( json.dumps(the_app.openapi(), indent=2) )" > $@
16-
17-
# validates OAS file: $@
18-
$(call validate_openapi_specs,$@)

services/notifications/openapi.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,13 @@
99
{
1010
"url": "/",
1111
"description": "Default server: requests directed to serving url"
12-
},
13-
{
14-
"url": "http://{host}:{port}",
15-
"description": "Development server: can configure any base url",
16-
"variables": {
17-
"host": {
18-
"default": "127.0.0.1"
19-
},
20-
"port": {
21-
"default": "8000"
22-
}
23-
}
2412
}
2513
],
2614
"paths": {
27-
"/health": {
15+
"/": {
2816
"get": {
2917
"summary": "Check Service Health",
30-
"operationId": "check_service_health_health_get",
18+
"operationId": "check_service_health__get",
3119
"responses": {
3220
"200": {
3321
"description": "Successful Response",
Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,82 @@
11
import logging
2+
import os
23

34
import typer
4-
from settings_library.utils_cli import create_settings_command, create_version_callback
5+
from settings_library.postgres import PostgresSettings
6+
from settings_library.rabbit import RabbitSettings
7+
from settings_library.utils_cli import (
8+
create_settings_command,
9+
create_version_callback,
10+
print_as_envfile,
11+
)
512

613
from ._meta import APP_NAME, __version__
714
from .core.settings import ApplicationSettings
815

916
log = logging.getLogger(__name__)
1017

11-
main = typer.Typer(name=APP_NAME)
18+
main = typer.Typer(
19+
name=APP_NAME,
20+
pretty_exceptions_enable=False,
21+
pretty_exceptions_show_locals=False,
22+
)
1223

1324
main.command()(create_settings_command(settings_cls=ApplicationSettings, logger=log))
1425
main.callback()(create_version_callback(__version__))
26+
27+
28+
@main.command()
29+
def echo_dotenv(ctx: typer.Context, *, minimal: bool = True) -> None:
30+
"""Generates and displays a valid environment variables file (also known as dot-envfile)
31+
32+
Usage:
33+
$ simcore-service echo-dotenv > .env
34+
$ cat .env
35+
$ set -o allexport; source .env; set +o allexport
36+
"""
37+
assert ctx # nosec
38+
39+
# NOTE: we normally DO NOT USE `os.environ` to capture env vars but this is a special case
40+
# The idea here is to have a command that can generate a **valid** `.env` file that can be used
41+
# to initialized the app. For that reason we fill required fields of the `ApplicationSettings` with
42+
# "fake" but valid values (e.g. generating a password or adding tags as `replace-with-api-key).
43+
# Nonetheless, if the caller of this CLI has already some **valid** env vars in the environment we want to use them ...
44+
# and that is why we use `os.environ`.
45+
46+
settings = ApplicationSettings.create_from_envs(
47+
SC_BOOT_MODE="default",
48+
NOTIFICATIONS_POSTGRES=os.environ.get(
49+
"NOTIFICATIONS_POSTGRES",
50+
PostgresSettings.create_from_envs(
51+
POSTGRES_HOST=os.environ.get(
52+
"POSTGRES_HOST", "replace-with-postgres-host"
53+
),
54+
POSTGRES_USER=os.environ.get(
55+
"POSTGRES_USER", "replace-with-postgres-user"
56+
),
57+
POSTGRES_DB=os.environ.get("POSTGRES_DB", "replace-with-postgres-db"),
58+
POSTGRES_PASSWORD=os.environ.get(
59+
"POSTGRES_PASSWORD", "replace-with-postgres-password"
60+
),
61+
),
62+
),
63+
NOTIFICATIONS_RABBITMQ=os.environ.get(
64+
"NOTIFICATIONS_RABBITMQ",
65+
RabbitSettings.create_from_envs(
66+
RABBIT_HOST=os.environ.get("RABBIT_HOST", "replace-with-rabbit-host"),
67+
RABBIT_SECURE=os.environ.get("RABBIT_SECURE", "True"),
68+
RABBIT_USER=os.environ.get("RABBIT_USER", "replace-with-rabbit-user"),
69+
RABBIT_PASSWORD=os.environ.get(
70+
"RABBIT_PASSWORD", "replace-with-rabbit-password"
71+
),
72+
),
73+
),
74+
)
75+
76+
print_as_envfile(
77+
settings,
78+
compact=False,
79+
verbose=True,
80+
show_secrets=True,
81+
exclude_unset=minimal,
82+
)

0 commit comments

Comments
 (0)