Merge pull request #1245 from benmuth/add-user-env-vars
This commit is contained in:
commit
2a1104c76a
2 changed files with 11 additions and 5 deletions
|
@ -91,6 +91,8 @@ CONFIG_SCHEMA: Dict[str, ConfigDefaultDict] = {
|
||||||
'OUTPUT_PERMISSIONS': {'type': str, 'default': '644'},
|
'OUTPUT_PERMISSIONS': {'type': str, 'default': '644'},
|
||||||
'RESTRICT_FILE_NAMES': {'type': str, 'default': 'windows'},
|
'RESTRICT_FILE_NAMES': {'type': str, 'default': 'windows'},
|
||||||
'URL_BLACKLIST': {'type': str, 'default': r'\.(css|js|otf|ttf|woff|woff2|gstatic\.com|googleapis\.com/css)(\?.*)?$'}, # to avoid downloading code assets as their own pages
|
'URL_BLACKLIST': {'type': str, 'default': r'\.(css|js|otf|ttf|woff|woff2|gstatic\.com|googleapis\.com/css)(\?.*)?$'}, # to avoid downloading code assets as their own pages
|
||||||
|
'ADMIN_USERNAME': {'type': str, 'default': None},
|
||||||
|
'ADMIN_PASSWORD': {'type': str, 'default': None},
|
||||||
'URL_WHITELIST': {'type': str, 'default': None},
|
'URL_WHITELIST': {'type': str, 'default': None},
|
||||||
'ENFORCE_ATOMIC_WRITES': {'type': bool, 'default': True},
|
'ENFORCE_ATOMIC_WRITES': {'type': bool, 'default': True},
|
||||||
'TAG_SEPARATOR_PATTERN': {'type': str, 'default': r'[,]'},
|
'TAG_SEPARATOR_PATTERN': {'type': str, 'default': r'[,]'},
|
||||||
|
|
|
@ -112,6 +112,8 @@ from .config import (
|
||||||
load_all_config,
|
load_all_config,
|
||||||
CONFIG,
|
CONFIG,
|
||||||
USER_CONFIG,
|
USER_CONFIG,
|
||||||
|
ADMIN_USERNAME,
|
||||||
|
ADMIN_PASSWORD,
|
||||||
get_real_name,
|
get_real_name,
|
||||||
setup_django,
|
setup_django,
|
||||||
)
|
)
|
||||||
|
@ -419,14 +421,16 @@ def init(force: bool=False, quick: bool=False, setup: bool=False, out_dir: Path=
|
||||||
write_main_index(list(pending_links.values()), out_dir=out_dir)
|
write_main_index(list(pending_links.values()), out_dir=out_dir)
|
||||||
|
|
||||||
print('\n{green}----------------------------------------------------------------------{reset}'.format(**ANSI))
|
print('\n{green}----------------------------------------------------------------------{reset}'.format(**ANSI))
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
if (ADMIN_USERNAME and ADMIN_PASSWORD) and not User.objects.filter(username=ADMIN_USERNAME).exists():
|
||||||
|
print('{green}[+] Found ADMIN_USERNAME and ADMIN_PASSWORD configuration options, creating new admin user.{reset}'.format(**ANSI))
|
||||||
|
User.objects.create_superuser(username=ADMIN_USERNAME, password=ADMIN_PASSWORD)
|
||||||
|
|
||||||
if existing_index:
|
if existing_index:
|
||||||
print('{green}[√] Done. Verified and updated the existing ArchiveBox collection.{reset}'.format(**ANSI))
|
print('{green}[√] Done. Verified and updated the existing ArchiveBox collection.{reset}'.format(**ANSI))
|
||||||
else:
|
else:
|
||||||
# TODO: allow creating new supersuer via env vars on first init
|
|
||||||
# if config.HTTP_USER and config.HTTP_PASS:
|
|
||||||
# from django.contrib.auth.models import User
|
|
||||||
# User.objects.create_superuser(HTTP_USER, '', HTTP_PASS)
|
|
||||||
|
|
||||||
print('{green}[√] Done. A new ArchiveBox collection was initialized ({} links).{reset}'.format(len(all_links) + len(pending_links), **ANSI))
|
print('{green}[√] Done. A new ArchiveBox collection was initialized ({} links).{reset}'.format(len(all_links) + len(pending_links), **ANSI))
|
||||||
|
|
||||||
json_index = out_dir / JSON_INDEX_FILENAME
|
json_index = out_dir / JSON_INDEX_FILENAME
|
||||||
|
|
Loading…
Reference in a new issue