-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track logins on supabase add infra related details to the balle…
…rine
- Loading branch information
1 parent
901a591
commit d505994
Showing
10 changed files
with
207 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
infra_file="/tmp/infra.json" | ||
|
||
## Get cloudProvider details | ||
function get_cloud_provider() { | ||
release_details=$(uname -r) | ||
if [[ $release_details == *"amzn"* ]];then | ||
# Example: 5.10.192-183.736.amzn2.x86_64 | ||
cloud_provider="amazon"; | ||
elif [[ $release_details == *"azure"* ]];then | ||
# Example: 5.15.0-1059-azure | ||
cloud_provider="azure"; | ||
elif [[ $release_details == *"cloud"* ]];then | ||
# Example: 6.1.0-18-cloud-amd64 | ||
cloud_provider="gcp"; | ||
elif [[ $release_details == *"generic"* ]];then | ||
# Example: 6.8.0-31-generic | ||
cloud_provider="digitalocean" | ||
elif [[ $release_details == *"ecs"* ]];then | ||
cloud_provider="alibaba" | ||
elif [[ -n "${DYNO}" ]];then | ||
cloud_provider="heroku" | ||
else | ||
cloud_provider="others(including local)"; | ||
fi | ||
} | ||
|
||
## Get deployment tool details | ||
function get_tool() { | ||
if [[ -z "${KUBERNETES_SERVICE_HOST}" ]]; then | ||
dep_tool="likely docker"; | ||
else | ||
dep_tool="kubernetes"; | ||
fi | ||
} | ||
|
||
|
||
## Check hostname | ||
function get_hostname() { | ||
hostname="$(cat /etc/hostname)" | ||
} | ||
|
||
## Get current Time | ||
function get_current_time(){ | ||
currentTime="$(date -u -Iseconds)" | ||
} | ||
|
||
## Check if it's a ECS Fargate deployment | ||
function check_for_fargate() { | ||
if [[ $cloud_provider == "amazon" && $dep_tool == "likely docker" ]]; then | ||
dep_tool="ecs-fargate" | ||
fi | ||
} | ||
|
||
## Main Block | ||
get_cloud_provider | ||
get_tool | ||
get_hostname | ||
check_for_fargate | ||
get_current_time | ||
|
||
infra_json='{"cloudProvider":"'"$cloud_provider"'","tool":"'"$dep_tool"'","hostname":"'"$hostname"'", "currentTime": "'"$currentTime"'"}' | ||
echo "$infra_json" | ||
|
||
echo $infra_json > $infra_file | ||
|
||
dumb-init npm run prod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 23 additions & 2 deletions
25
services/workflows-service/src/auth/local/local-auth.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { ExecutionContext } from '@nestjs/common'; | ||
import type { Request } from 'express'; | ||
import { createClient } from '@supabase/supabase-js'; | ||
import { env } from '@/env'; | ||
|
||
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) { | ||
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 false; | ||
} | ||
} catch (err) { | ||
console.error('Unexpected error:', err); | ||
} | ||
} | ||
return result as boolean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters