Skip to content

Commit

Permalink
feat: use secret_key config field instead of api_key
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Mar 15, 2023
1 parent 903a643 commit e231e74
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api/libretime_api/settings/prod.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os import getenv
from warnings import warn

# pylint: disable=unused-import
from ._internal import (
Expand All @@ -24,7 +25,15 @@

CONFIG = Config(LIBRETIME_CONFIG_FILEPATH) # type: ignore[arg-type, misc]

SECRET_KEY = CONFIG.general.api_key
if CONFIG.general.secret_key is None:
warn(
"The [general.secret_key] configuration field is not set but will be required "
"in the next major release. Using [general.api_key] as fallback.",
FutureWarning,
)
SECRET_KEY = CONFIG.general.api_key
else:
SECRET_KEY = CONFIG.general.secret_key

ALLOWED_HOSTS = ["*"]

Expand Down
1 change: 1 addition & 0 deletions api/libretime_api/settings/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
os.environ.setdefault("LIBRETIME_DEBUG", "true")
os.environ.setdefault("LIBRETIME_GENERAL_PUBLIC_URL", "http://localhost")
os.environ.setdefault("LIBRETIME_GENERAL_API_KEY", "testing")
os.environ.setdefault("LIBRETIME_GENERAL_SECRET_KEY", "testing")
os.environ.setdefault("LIBRETIME_STORAGE_PATH", str(fixture_path))

# pylint: disable=wrong-import-position,unused-import
Expand Down
1 change: 1 addition & 0 deletions docker/config.dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
general:
public_url: http://localhost:8080
api_key: some_secret_api_key
secret_key: some_secret_key

database:
host: postgres
Expand Down
3 changes: 3 additions & 0 deletions docker/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ general:
# The internal API authentication key.
# > this field is REQUIRED
api_key:
# The Django API secret key. If not defined, the value of [general.api_key] will be
# used as fallback.
secret_key:

# List of origins allowed to access resources on the server, the public url
# origin is automatically included.
Expand Down
3 changes: 3 additions & 0 deletions docker/example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ general:
# The internal API authentication key.
# > this field is REQUIRED
api_key: some_secret_api_key
# The Django API secret key. If not defined, the value of [general.api_key] will be
# used as fallback.
secret_key:

# List of origins allowed to access resources on the server, the public url
# origin is automatically included.
Expand Down
2 changes: 2 additions & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ if $is_first_install; then
fi
set_config "$(generate_random_password)" general api_key

set_config "$(generate_random_password)" general secret_key

if [[ -n "$LIBRETIME_TIMEZONE" ]]; then
set_config "$LIBRETIME_TIMEZONE" general timezone
fi
Expand Down
3 changes: 3 additions & 0 deletions installer/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ general:
# The internal API authentication key.
# > this field is REQUIRED
api_key:
# The Django API secret key. If not defined, the value of [general.api_key] will be
# used as fallback.
secret_key:

# List of origins allowed to access resources on the server, the public url
# origin is automatically included.
Expand Down
1 change: 1 addition & 0 deletions shared/libretime_shared/config/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def strip_leading_slash(cls: Any, value: Any) -> Any:
class GeneralConfig(BaseModel):
public_url: AnyHttpUrl
api_key: str
secret_key: Optional[str] = None

timezone: str = "UTC"

Expand Down

0 comments on commit e231e74

Please sign in to comment.