Skip to content

Commit

Permalink
chore: add supabase env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
pratapalakshmi committed Oct 28, 2024
1 parent df51d4c commit f65a598
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
3 changes: 3 additions & 0 deletions deploy/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
3 changes: 3 additions & 0 deletions deploy/docker-compose-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions services/workflows-service/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
35 changes: 18 additions & 17 deletions services/workflows-service/src/auth/local/local-auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Request>();

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;
}
}
27 changes: 15 additions & 12 deletions services/workflows-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit f65a598

Please sign in to comment.