globe-and-citizen / layer8

This repo contains the Layer8 Resource/Authentication Server, Proxy, and Service Provider Mocks
GNU General Public License v2.0
1 stars 2 forks source link

Automatic Client Registration on calleing `$make setup_and_run`. #121

Open stravid87 opened 3 months ago

stravid87 commented 3 months ago

Description

When running the make setup_and_run command, the client of WGP is not automatically registered requiring manual adjustment to the database.

User Story

As a developer I want to run the dev environment with a single command When I run $make steup_and_go I get the client, WGP, automatically registered with layer8.

stravid87 commented 2 months ago

See Daniel's Makefile command set_client_creds: Maybe this can be leveraged?

SP_MOCK := wgp
set_client_creds:
    db_name=$$(cat server/.env | grep ^DB_NAME | cut -d '=' -f2); \
    db_user=$$(cat server/.env | grep ^DB_USER | cut -d '=' -f2); \
    client_username=$$(cat server/.env | grep TEST_CLIENT_USERNAME | cut -d '=' -f2); \
    client_id=$$(docker exec layer8-postgres psql -U $$db_user -d $$db_name \
        -c "SELECT id FROM clients WHERE username='$$client_username'" -t -A); \
    client_secret=$$(docker exec layer8-postgres psql -U $$db_user -d $$db_name \
        -c "SELECT secret FROM clients WHERE username='$$client_username'" -t -A); \
    if [ -z "$$client_id" ]; then \
        echo "Client not found"; \
    else \
        if [ "$(SP_MOCK)" = "wgp" ]; then \
            echo "LAYER8_CLIENT_ID=$$client_id" >> sp_mocks/wgp/backend/.env; \
            echo "LAYER8_CLIENT_SECRET=$$client_secret" >> sp_mocks/wgp/backend/.env; \
        elif [ "$(SP_MOCK)" = "imsharer" ]; then \
            echo "LAYER8_CLIENT_ID=$$client_id" >> sp_mocks/imsharer/backend/.env; \
            echo "LAYER8_CLIENT_SECRET=$$client_secret" >> sp_mocks/imsharer/backend/.env; \
        else \
            echo "Invalid SP_MOCK"; \
        fi; \
    fi