Skip to content

Commit

Permalink
Oss login username set (#119)
Browse files Browse the repository at this point in the history
* username taken from env

* updated docs and platform.sh

* updated run script

* minor changes removed empty lines

* Update backend/README.md

Signed-off-by: Hari John Kuriakose <[email protected]>

* Apply suggestions from code review

Signed-off-by: Hari John Kuriakose <[email protected]>

* Update backend/sample.env

Signed-off-by: Hari John Kuriakose <[email protected]>

* Apply suggestions from code review

Signed-off-by: Hari John Kuriakose <[email protected]>

* Update run-platform.sh

Signed-off-by: Hari John Kuriakose <[email protected]>

---------

Signed-off-by: Hari John Kuriakose <[email protected]>
Co-authored-by: Hari John Kuriakose <[email protected]>
  • Loading branch information
muhammad-ali-e and hari-kuriakose authored Mar 16, 2024
1 parent 6f53013 commit 45d0273
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
15 changes: 12 additions & 3 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ python manage.py runserver localhost:8000

- Server will start and run at port 8000. (<http://localhost:8000>)

## Default Username and Password
## Setting Username and Password

The default username is `unstract` and the default password is `unstract`.

To customize your password, simply navigate to the `.env` file and update the `DEFAULT_AUTH_PASSWORD` config before launching the server. Then use your new password to log in.
To customize your username or password:
1. Navigate to the `.env` file located at `backend`.
2. Update the values for `DEFAULT_AUTH_USERNAME` and `DEFAULT_AUTH_PASSWORD` with strong, unique credentials of your choosing.
3. Save the `.env` file and restart the server to apply changes.

> **NOTE**: The username `admin` is reserved for Django admin, hence cannot be used.
To update the username or password after it's been set:
1. Modify the username and password in `.env`.
2. Restart server to apply updates.
3. Login with the new credentials.

To update the password after it's been set, first change it in the .env file, restart the server for it to take effect, then log in using the new password.

## Asynchronous execution/pipeline execution

Expand Down
3 changes: 3 additions & 0 deletions backend/account/authentication_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def authenticate_and_login(
"""
user = authenticate(request, username=username, password=password)
if user:
# To avoid conflicts with django superuser
if user.is_superuser:
return False
login(request, user)
return True
# Attempt to initiate default user and authenticate again
Expand Down
2 changes: 1 addition & 1 deletion backend/account/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ErrorMessage:
class DefaultOrg:
ORGANIZATION_NAME = "mock_org"
MOCK_ORG = "mock_org"
MOCK_USER = "unstract"
MOCK_USER = settings.DEFAULT_AUTH_USERNAME
MOCK_USER_ID = "mock_user_id"
MOCK_USER_EMAIL = "[email protected]"
MOCK_USER_PASSWORD = settings.DEFAULT_AUTH_PASSWORD
Expand Down
1 change: 1 addition & 0 deletions backend/backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def get_required_setting(
API_STORAGE_DIR = os.environ.get("API_STORAGE_DIR")
CACHE_TTL_SEC = os.environ.get("CACHE_TTL_SEC", 10800)

DEFAULT_AUTH_USERNAME = os.environ.get("DEFAULT_AUTH_USERNAME", "unstract")
DEFAULT_AUTH_PASSWORD = os.environ.get("DEFAULT_AUTH_PASSWORD", "unstract")

# Quick-start development settings - unsuitable for production
Expand Down
3 changes: 2 additions & 1 deletion backend/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ ENCRYPTION_KEY="Sample-Key"
# Cache TTL
CACHE_TTL_SEC=10800

# Default user
# Default auth credentials
DEFAULT_AUTH_USERNAME=
DEFAULT_AUTH_PASSWORD=
8 changes: 8 additions & 0 deletions run-platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ parse_args() {
setup_env() {
# Generate Fernet Key. Refer https://pypi.org/project/cryptography/. for both backend and platform-service.
ENCRYPTION_KEY=$(python3 -c "import secrets, base64; print(base64.urlsafe_b64encode(secrets.token_bytes(32)).decode())")
DEFAULT_AUTH_KEY="unstract"

for service in "${services[@]}"; do
sample_env_path="$script_dir/$service/sample.env"
env_path="$script_dir/$service/.env"
Expand All @@ -113,6 +115,12 @@ setup_env() {
echo -e "$blue_text""Adding encryption secret to $service""$default_text"
echo "ENCRYPTION_KEY=\"$ENCRYPTION_KEY\"" >> $env_path
fi
# Add default auth credentials for backend.
if [ "$service" == "backend" ]; then
echo -e "$blue_text""Adding default auth credentials to $service""$default_text"
echo "DEFAULT_AUTH_USERNAME=\"$DEFAULT_AUTH_KEY\"" >> $env_path
echo "DEFAULT_AUTH_PASSWORD=\"$DEFAULT_AUTH_KEY\"" >> $env_path
fi
echo -e "Created env for ""$blue_text""$service""$default_text" at ""$blue_text""$env_path""$default_text"."
else
echo -e "Found existing env for ""$blue_text""$service""$default_text" at ""$blue_text""$env_path""$default_text"."
Expand Down

0 comments on commit 45d0273

Please sign in to comment.