1
0
Fork 0
mirror of synced 2024-06-14 08:24:48 +12:00

Add deployment environment to identities

This commit is contained in:
Rory Powell 2022-06-15 11:46:03 +01:00
parent cb9550734f
commit 7283e01442
3 changed files with 24 additions and 3 deletions

View file

@ -35,6 +35,7 @@ const pkg = require("../../package.json")
*/
export const getCurrentIdentity = async (): Promise<Identity> => {
let identityContext = identityCtx.getIdentity()
const environment = getDeploymentEnvironment()
let identityType
@ -52,6 +53,7 @@ export const getCurrentIdentity = async (): Promise<Identity> => {
hosting,
type: identityType,
installationId,
environment,
}
} else if (identityType === IdentityType.TENANT) {
const installationId = await getInstallationId()
@ -64,6 +66,7 @@ export const getCurrentIdentity = async (): Promise<Identity> => {
hosting,
installationId,
tenantId,
environment,
}
} else if (identityType === IdentityType.USER) {
const userContext = identityContext as UserContext
@ -84,6 +87,7 @@ export const getCurrentIdentity = async (): Promise<Identity> => {
hosting,
installationId,
tenantId,
environment,
}
} else {
throw new Error("Unknown identity type")
@ -98,12 +102,14 @@ export const identifyInstallationGroup = async (
const type = IdentityType.INSTALLATION
const hosting = getHostingFromEnv()
const version = pkg.version
const environment = getDeploymentEnvironment()
const group: InstallationGroup = {
id,
type,
hosting,
version,
environment,
}
await identifyGroup(group, timestamp)
@ -120,6 +126,7 @@ export const identifyTenantGroup = async (
const id = await getEventTenantId(tenantId)
const type = IdentityType.TENANT
const installationId = await getInstallationId()
const environment = getDeploymentEnvironment()
let hosting: Hosting
let profession: string | undefined
@ -137,6 +144,7 @@ export const identifyTenantGroup = async (
id,
type,
hosting,
environment,
installationId,
profession,
companySize,
@ -164,6 +172,7 @@ export const identifyUser = async (
account && account?.budibaseUserId === user._id ? account.verified : false
const installationId = await getInstallationId()
const hosting = account ? account.hosting : getHostingFromEnv()
const environment = getDeploymentEnvironment()
const identity: UserIdentity = {
id,
@ -176,6 +185,7 @@ export const identifyUser = async (
providerType,
builder,
admin,
environment,
}
await identify(identity, timestamp)
@ -190,6 +200,7 @@ export const identifyAccount = async (account: Account) => {
const accountHolder = true
const hosting = account.hosting
const installationId = await getInstallationId()
const environment = getDeploymentEnvironment()
if (isCloudAccount(account)) {
if (account.budibaseUserId) {
@ -207,6 +218,7 @@ export const identifyAccount = async (account: Account) => {
providerType,
verified,
accountHolder,
environment,
}
await identify(identity)
@ -226,6 +238,14 @@ export const identifyGroup = async (
await processors.identifyGroup(group, timestamp)
}
const getDeploymentEnvironment = () => {
if (env.isDev()) {
return "development"
} else {
return env.DEPLOYMENT_ENVIRONMENT
}
}
const getHostingFromEnv = () => {
return env.SELF_HOSTED ? Hosting.SELF : Hosting.CLOUD
}

View file

@ -23,7 +23,7 @@ export default class PosthogProcessor implements EventProcessor {
): Promise<void> {
properties.version = pkg.version
properties.service = env.SERVICE
properties.environment = env.DEPLOYMENT_ENVIRONMENT
properties.environment = identity.environment
properties.hosting = identity.hosting
const appId = context.getAppId()

View file

@ -10,6 +10,8 @@ export enum GroupType {
export interface Group {
id: string
type: IdentityType
environment: string
hosting: Hosting
}
export interface TenantGroup extends Group {
@ -17,13 +19,11 @@ export interface TenantGroup extends Group {
// as we don't have this at the user level
profession?: string // only available in cloud
companySize?: string // only available in cloud
hosting: Hosting // need hosting at the tenant level for cloud self host accounts
installationId: string
}
export interface InstallationGroup extends Group {
version: string
hosting: Hosting
}
// IDENTITIES
@ -38,6 +38,7 @@ export interface Identity {
id: string
type: IdentityType
hosting: Hosting
environment: string
installationId?: string
tenantId?: string
}