Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using GitHub codespace #62

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,20 @@ git push upstream <featurebranchname>:review --force
```
The `main` branch only accepts commits through pull requests.

NB: Note that Radix will always use the `radixconfig.yml` as it is in `main` branch (unless changed in Radix UI).
NB: Note that Radix will always use the `radixconfig.yml` as it is in `main` branch (unless changed in Radix UI).

### Usage in GitHub codespaces

Using the standard GitHub codespace image, you can easily start up the application by running
the same command as locally:
```
docker-compose up
```
in the terminal. When using GitHub codespaces you do not have to create the `.env` file since
environment variables are automatically set up for you at startup through repository settings.
Note that you need to have at least "collaborator" role in the repository in order to have
environment variables automatically set up.

When you start up the docker containers, GitHub codespace will automatically make a link where
you can access the application in development mode (i.e. changes you do the code will automatically
be reflected in the application).
13 changes: 9 additions & 4 deletions backend/src/backend/auth/auth_helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import base64
import time
from typing import List, Optional
Expand Down Expand Up @@ -33,11 +34,15 @@ async def _login_route(self, request: Request, redirect_url_after_login: Optiona
for value in config.RESOURCE_SCOPES_DICT.values():
all_scopes_list.extend(value)

if "CODESPACE_NAME" in os.environ:
# Developer is using GitHub codespace, so we use the GitHub codespace port forward URL
redirect_uri = f"https://{os.environ['CODESPACE_NAME']}-8080.app.github.dev/api/auth-callback"
print(f"You are using GitHub codespace. Remember to allow app registration redirect URI {redirect_uri}")
else:
redirect_uri = str(request.url_for("_authorized_callback_route"))

cca = _create_msal_confidential_client_app(token_cache=None)
flow_dict = cca.initiate_auth_code_flow(
scopes=all_scopes_list,
redirect_uri=str(request.url_for("_authorized_callback_route")),
)
flow_dict = cca.initiate_auth_code_flow(scopes=all_scopes_list, redirect_uri=redirect_uri)

request.session["flow"] = flow_dict

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
- WEBVIZ_SMDA_RESOURCE_SCOPE
- WEBVIZ_SMDA_SUBSCRIPTION_KEY
- WEBVIZ_SUMO_ENV
- CODESPACE_NAME # Automatically set env. variable by GitHub codespace
volumes:
- ./backend/src:/home/appuser/backend/src

Expand Down