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

Backend improvements and add support for Google Sheet #3

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/weld-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
POETRY_VERSION: "1.8.2"
WELD_APP_CONFIG: ${{ vars.WELD_APP_SAMPLE_CONFIG }}
WELD_APP_CAMERA_CONFIG: ${{ vars.WELD_APP_CAMERA_SAMPLE_CONFIG }}
WELD_APP_DATABASE_CONFIG: ${{ vars.WELD_APP_DATABASE_SAMPLE_CONFIG }}
GROUNDLIGHT_API_TOKEN: ${{ secrets.GROUNDLIGHT_API_TOKEN }}

steps:
Expand Down
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,57 @@ The app requires the following environment variables:

Each `camera_config` entries will need to match the configuration settings for `FrameGrab` so the cameras can be intiialized correctly.

- `WELD_APP_DATABASE_CONFIG`: This is the database config for fetching data from Google API Service.

```json
{
"enabled": true,
"service_account": {
"type": "service_account",
"project_id": "PROJECT_ID_HERE",
"private_key_id": "PRIVATE_KEY_ID_HERE",
"private_key": "PRIVATE_KEY_HERE",
"client_email": "CLIENT_EMAIL_HERE",
"client_id": "CLIENT_ID_HERE",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "CLIENT_CERT_URL_HERE",
"universe_domain": "googleapis.com"
},
"database_id": "YOUR_DATABASE_ID_HERE",
"database_range": "Sheet1!A2:C"
}
```

The `service_account` section should match the credential JSON file downloaded from Google Cloud.

- `WELD_APP_SUPERVISOR_PASSWORD`: The supervisor password to lock/unlock the Jig Lock, default to None if not set

- `WELD_APP_DEVICE_ID`: Set the device ID for this particular device, should set this unique for each device for easier debugging

- `GROUNDLIGHT_API_TOKEN`: Groundlight API Token

- `LAUNCH_URL`: Set this to `http://router/hub/launch/1` to ensure that the device automatically redirects to the application main page when it is ready

### Creating Supervisor Password

If the you would like to only allow supervisors to lock/unlock the Jig Lock, you need to set the environment variable `WELD_APP_SUPERVISOR_PASSWORD` with the hashed password.

The hashed password can be created with the `generate_hash.py` script by running the following command:

```bash
poetry run python generate_hash.py PASSWORD
```

Copy the hashed password generated from the script to the environment variable:

```bash
export WELD_APP_SUPERVISOR_PASSWORD="HASHED_PASSWORD"
```

For balena deployment just copy the hashed password into the `Device Variables` tab.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be awkward, since we'll need to have them send their desired password, or choose a password for them. Either way involves some password handoff which tends to be an awkward business


## Local Testing

To run the app on your local machine just run this command:
Expand Down
22 changes: 22 additions & 0 deletions generate_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import bcrypt
import argparse


def hash_password(password):
# Generate a salt
salt = bcrypt.gensalt()
# Generate the hashed password
hashed_password = bcrypt.hashpw(password.encode(), salt)
return hashed_password.decode() # Store as a string


parser = argparse.ArgumentParser(description="Hash a password")
parser.add_argument("password", help="The password to hash")
args = parser.parse_args()

password = args.password

# Generate hashed password
hashed_password = hash_password(password)

print(f"Hashed password: {hashed_password}")
Loading
Loading