-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Secrets to the admin page (#939)
* Add Secrets to the admin page * Apply suggestions from code review Co-authored-by: Ivan Ivanov <[email protected]> * Fix syntax errors * Switch to regex based env var validation * Make the project field an autocomplete field (fixes performance of add form) * Fix linting errors * Remove regex based value validation * Add validate_pg_service_conf * Ensure project is the first field in the ProjectSecretForm * Apply suggestions from code review Co-authored-by: Ivan Ivanov <[email protected]> * Apply suggestions from code review Co-authored-by: Ivan Ivanov <[email protected]> * Rename secret util to pg_service_file * Fixes from review and ProjectSecretInline * Prefer using `admin` decorator * Hack a way to add extra HTML in `InlineTabular` admin templates * Secret Admin: Fix "Created by" column name * Fix linting errors --------- Co-authored-by: Ivan Ivanov <[email protected]> Co-authored-by: Ivan Ivanov <[email protected]>
- Loading branch information
1 parent
46a29ef
commit 1e9868a
Showing
4 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
docker-app/qfieldcloud/core/templates/admin/edit_inline/tabular_customized.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% if qfc_admin_inline_included != 1 %} | ||
{% include "admin/edit_inline/tabular_extended.html" with qfc_admin_inline_included=1 %} | ||
{% endif %} | ||
|
||
{{ fieldset.opts.bottom_html }} |
1 change: 1 addition & 0 deletions
1
docker-app/qfieldcloud/core/templates/admin/edit_inline/tabular_extended.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% extends "admin/edit_inline/tabular.html" %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import configparser | ||
import io | ||
|
||
from django.core.exceptions import ValidationError | ||
from django.utils.translation import gettext as _ | ||
|
||
PGSERVICE_SECRET_NAME_PREFIX = "PG_SERVICE_" | ||
|
||
|
||
def validate_pg_service_conf(value: str) -> None: | ||
"""Checks if a string is a valid `pg_service.conf` file contents, otherwise throws a `ValueError`""" | ||
try: | ||
buffer = io.StringIO(value) | ||
config = configparser.ConfigParser() | ||
config.readfp(buffer) | ||
|
||
if len(config.sections()) != 1: | ||
raise ValidationError( | ||
_("The `.pg_service.conf` must have exactly one service definition.") | ||
) | ||
except ValidationError as err: | ||
raise err | ||
except Exception: | ||
raise ValidationError(_("Failed to parse the `.pg_service.conf` file.")) |