From f65a598a4c7a168c9228a90f2380456844f13613 Mon Sep 17 00:00:00 2001 From: Pratapa Lakshmi Date: Mon, 28 Oct 2024 22:24:39 +0530 Subject: [PATCH] chore: add supabase env variables --- deploy/.env | 3 ++ deploy/docker-compose-build.yml | 3 ++ services/workflows-service/.env.example | 3 ++ .../src/auth/local/local-auth.guard.ts | 35 ++++++++++--------- services/workflows-service/src/main.ts | 27 +++++++------- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/deploy/.env b/deploy/.env index 5c6dbf7f50..ab2e2b13fb 100644 --- a/deploy/.env +++ b/deploy/.env @@ -17,3 +17,6 @@ WORKFLOW_DASHBOARD_PORT=5200 WEBSOCKET_SVC_PORT=3500 KYB_APP_PORT=5201 DOMAIN_NAME="" +TELEMETRY_ENABLED=true +TELEMETRY_SUPABASE_URL="" +TELEMETRY_SUPABASE_API_KEY="" diff --git a/deploy/docker-compose-build.yml b/deploy/docker-compose-build.yml index af71e28857..ca1332b07a 100644 --- a/deploy/docker-compose-build.yml +++ b/deploy/docker-compose-build.yml @@ -59,6 +59,9 @@ services: UNIFIED_API_TOKEN: '' UNIFIED_API_SHARED_SECRET: '' ENVIRONMENT_NAME: 'development' + TELEMETRY_ENABLED: ${TELEMETRY_ENABLED} + TELEMETRY_SUPABASE_URL: ${TELEMETRY_SUPABASE_URL} + TELEMETRY_SUPABASE_API_KEY: ${TELEMETRY_SUPABASE_API_KEY} depends_on: ballerine-postgres: condition: service_healthy diff --git a/services/workflows-service/.env.example b/services/workflows-service/.env.example index 13c34ed72d..7573703719 100644 --- a/services/workflows-service/.env.example +++ b/services/workflows-service/.env.example @@ -34,3 +34,6 @@ SALESFORCE_CONSUMER_SECRET= APP_API_URL=http://localhost:3000 COLLECTION_FLOW_URL=http://localhost:5201 WEB_UI_SDK_URL=http://localhost:5202 +TELEMETRY_ENABLED=true +TELEMETRY_SUPABASE_URL="" +TELEMETRY_SUPABASE_API_KEY="" diff --git a/services/workflows-service/src/auth/local/local-auth.guard.ts b/services/workflows-service/src/auth/local/local-auth.guard.ts index 61701aea76..ab4c6dc0aa 100644 --- a/services/workflows-service/src/auth/local/local-auth.guard.ts +++ b/services/workflows-service/src/auth/local/local-auth.guard.ts @@ -8,26 +8,27 @@ export class LocalAuthGuard extends AuthGuard('local') { async canActivate(context: ExecutionContext) { const result = await super.canActivate(context); const request = context.switchToHttp().getRequest(); - await super.logIn(request); - if (env.TELEMETRY_ENABLED && env.TELEMETRY_SUPABASE_URL && env.TELEMETRY_SUPABASE_API_KEY) { - const SupabaseClient = createClient( - env.TELEMETRY_SUPABASE_URL, - env.TELEMETRY_SUPABASE_API_KEY, - { - db: { schema: 'public' }, - }, - ); - - const fullUrl = `${request.protocol}://${request.get('Host')}${request.originalUrl}`; - - await SupabaseClient.from('logins').insert([{ url: fullUrl }]); - - // @TODO: Set timeout - // @TODO: Handle errors + try{ + const SupabaseClient = createClient( + env.TELEMETRY_SUPABASE_URL, + env.TELEMETRY_SUPABASE_API_KEY, + { + db: { schema: 'public' }, + }, + ); + const fullUrl = `${request.protocol}://${request.get('Host')}${request.originalUrl}`; + const { data: result, error } = await SupabaseClient.from('logins').insert([{ url: fullUrl }]); + if(error) { + console.error('Error inserting data:', error.message); + return; + } + } + catch(err){ + console.error('Unexpected error:', err); + } } - return result as boolean; } } diff --git a/services/workflows-service/src/main.ts b/services/workflows-service/src/main.ts index e4e972cdcc..34205e07d5 100644 --- a/services/workflows-service/src/main.ts +++ b/services/workflows-service/src/main.ts @@ -38,19 +38,22 @@ const main = async () => { // Infra related data const infradata = require('/tmp/infra.json'); if (env.TELEMETRY_ENABLED && env.TELEMETRY_SUPABASE_URL && env.TELEMETRY_SUPABASE_API_KEY) { - const SupabaseClient = createClient( - env.TELEMETRY_SUPABASE_URL, - env.TELEMETRY_SUPABASE_API_KEY, - { - db: { schema: 'public' }, - }, - ); - - const { data, error } = await SupabaseClient.from('infra').insert([infradata]); - if (error) { + try { + const SupabaseClient = createClient( + env.TELEMETRY_SUPABASE_URL, + env.TELEMETRY_SUPABASE_API_KEY, + { + db: { schema: 'public' }, + }, + ); + const { data, error } = await SupabaseClient.from('infra').insert([infradata]); + if (error) { + console.error('Error inserting data:', error.message); + } else { + console.log('Data inserted successfully:', data); + } + } catch (error) { console.error('Error inserting data:', error.message); - } else { - console.log('Data inserted successfully:', data); } }