question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Allow for non-interactive createsuperuser

See original GitHub issue

Is your feature request related to a problem? Please describe.

When deploying Evennia in a test environment where the DB gets wiped on each deploy, it would be nice if I could specify the super user creds using environmental variables.

Describe the solution you’d like

This might be an anti-pattern, so I’m interested in other’s opinion, but could we do something like the following?

def create_superuser():
    """
    Create the superuser account

    """
    print(
        "\nCreate a superuser below. The superuser is Account #1, the 'owner' "
        "account of the server. Email is optional and can be empty.\n"
    )
    from os import environ
    if ("DJANGO_SUPERUSER_USERNAME" in environ) and ("DJANGO_SUPERUSER_EMAIL" in environ):
        username = environ["DJANGO_SUPERUSER_USERNAME"]
        email = environ["DJANGO_SUPERUSER_EMAIL"]
        django.core.management.call_command("createsuperuser", "--noinput",
                                            "--username=" + username,
                                            "--email=" + email, interactive=False)
    else:
        django.core.management.call_command("createsuperuser", interactive=True)

    if "DJANGO_SUPERUSER_PASSWORD" in environ:
        password = environ["DJANGO_SUPERUSER_PASSWORD"]
        from evennia.accounts.models import AccountDB
        u = AccountDB.objects.get(username=username)
        u.set_password(password)
        u.save()

Of course you could have the username without the email, as the email is optional. Let me know if this seems reasonable and can create a PR.

Describe alternatives you’ve considered

I could be missing something but the alternative seems to be to type in the information manually whenever setting up a new DB.

Additional context

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Griatchcommented, Jan 11, 2021

@srmeier, @jerryaldrichiii Sorry for not getting back to you on this before now. This looks like a good idea. Between the two solutions offered here I think @srmeier’s is likely the cleanest one; it should work also for those wanting to use docker (you can just pass the envvars into the docker if so desired).

I’d be interested in a PR against develop branch for this one 👍.

0reactions
srmeiercommented, Jan 11, 2021

@srmeier, @jerryaldrichiii Sorry for not getting back to you on this before now. This looks like a good idea. Between the two solutions offered here I think @srmeier’s is likely the cleanest one; it should work also for those wanting to use docker (you can just pass the envvars into the docker if so desired).

I’d be interested in a PR against develop branch for this one 👍.

No problem, will make changes and PR for review.

Read more comments on GitHub >

github_iconTop Results From Across the Web

#27801 (Make createsuperuser inspect environment variables ...
I made a ​PR to read the password from environment variables in the non-interactive mode. Based on the use case proposed on ticket,...
Read more >
How to automate createsuperuser on django? - Stack Overflow
And remember that first comes username, then the email. If you have a custom user model you need to import that and not...
Read more >
Support "non-interactive mode" for migrations and data seeds
One idea was to implement custom classes that shunt all input/output instead of interacting with the console. The problem with that approach is ......
Read more >
Administration Guide - WireCloud - Read the Docs
WireCloud allows admin users to impersonate other users. ... This feature does not require you to know the credentials of the user to...
Read more >
django-admin - Utility script for the Django Web framework
For Windows users, who do not have symlinking functionality available, ... If you do want to allow Django to manage the table's lifecycle,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found