mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2026-01-28 21:51:51 +00:00
Support new API token format
This commit is contained in:
parent
c0ead010ec
commit
c3dcc6c59f
|
|
@ -76,6 +76,7 @@ COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
|
||||||
COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py
|
COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py
|
||||||
COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh
|
COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh
|
||||||
COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh
|
COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh
|
||||||
|
COPY docker/super_user.py /opt/netbox/super_user.py
|
||||||
COPY configuration/ /etc/netbox/config/
|
COPY configuration/ /etc/netbox/config/
|
||||||
COPY docker/granian.py /opt/netbox/netbox/netbox/granian.py
|
COPY docker/granian.py /opt/netbox/netbox/netbox/granian.py
|
||||||
COPY VERSION /opt/netbox/VERSION
|
COPY VERSION /opt/netbox/VERSION
|
||||||
|
|
|
||||||
|
|
@ -71,26 +71,10 @@ else
|
||||||
SUPERUSER_API_TOKEN='0123456789abcdef0123456789abcdef01234567'
|
SUPERUSER_API_TOKEN='0123456789abcdef0123456789abcdef01234567'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./manage.py shell --interface python <<END
|
./manage.py shell --interface python < /opt/netbox/super_user.py
|
||||||
from users.models import Token, User
|
|
||||||
if not User.objects.filter(username='${SUPERUSER_NAME}'):
|
|
||||||
u = User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')
|
|
||||||
Token.objects.create(user=u, key='${SUPERUSER_API_TOKEN}')
|
|
||||||
END
|
|
||||||
|
|
||||||
echo "💡 Superuser Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./manage.py shell --interface python <<END
|
|
||||||
from users.models import Token
|
|
||||||
try:
|
|
||||||
old_default_token = Token.objects.get(key="0123456789abcdef0123456789abcdef01234567")
|
|
||||||
if old_default_token:
|
|
||||||
print("⚠️ Warning: You have the old default admin API token in your database. This token is widely known; please remove it. Log in as your superuser and check API Tokens in your user menu.")
|
|
||||||
except Token.DoesNotExist:
|
|
||||||
pass
|
|
||||||
END
|
|
||||||
|
|
||||||
echo "✅ Initialisation is done."
|
echo "✅ Initialisation is done."
|
||||||
|
|
||||||
# Launch whatever is passed by docker
|
# Launch whatever is passed by docker
|
||||||
|
|
|
||||||
22
docker/super_user.py
Normal file
22
docker/super_user.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
from os import environ
|
||||||
|
from users.models import Token, User
|
||||||
|
from users.choices import TokenVersionChoices
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
su_name = environ.get("SUPERUSER_NAME")
|
||||||
|
su_email = environ.get("SUPERUSER_EMAIL")
|
||||||
|
su_password = environ.get("SUPERUSER_PASSWORD")
|
||||||
|
su_api_token = environ.get("SUPERUSER_API_TOKEN")
|
||||||
|
|
||||||
|
if not User.objects.filter(username=su_name):
|
||||||
|
u = User.objects.create_superuser(su_name, su_email, su_password)
|
||||||
|
msg = ""
|
||||||
|
if not settings.API_TOKEN_PEPPERS:
|
||||||
|
print("⚠️ No API token will be created as API_TOKEN_PEPPERS is not set")
|
||||||
|
msg = f"💡 Superuser Username: {su_name}, E-Mail: {su_email}"
|
||||||
|
else:
|
||||||
|
t = Token.objects.create(
|
||||||
|
user=u, token=su_api_token, version=TokenVersionChoices.V2
|
||||||
|
)
|
||||||
|
msg = f"💡 Superuser Username: {su_name}, E-Mail: {su_email}, API Token: {t} (use with '{t.get_auth_header_prefix()}<Your token>')"
|
||||||
|
print(msg)
|
||||||
Loading…
Reference in a new issue