-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from fingerprintjs/feature/update-rollback
Health status page
- Loading branch information
Showing
3 changed files
with
158 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { HttpRequest } from '@azure/functions' | ||
import { CustomerVariables } from '../customer-variables/CustomerVariables' | ||
import { maybeObfuscateVariable } from '../customer-variables/maybeObfuscateVariable' | ||
import { CustomerVariableType } from '../customer-variables/types' | ||
import { HttpResponseSimple } from '@azure/functions/types/http' | ||
import { EnvVarInfo, StatusFormat } from '../../shared/status' | ||
|
||
export interface HandleStatusParams { | ||
httpRequest: HttpRequest | ||
customerVariables: CustomerVariables | ||
} | ||
|
||
export interface StatusInfo { | ||
version: string | ||
envInfo: EnvVarInfo[] | ||
} | ||
|
||
async function getEnvInfo(customerVariables: CustomerVariables) { | ||
const infoArray: EnvVarInfo[] = await Promise.all( | ||
Object.values(CustomerVariableType).map(async (variableType) => { | ||
const value = await customerVariables.getVariable(variableType) | ||
|
||
return { | ||
envVarName: variableType, | ||
value: maybeObfuscateVariable(variableType, value.value), | ||
isSet: Boolean(value.value), | ||
resolvedBy: value.resolvedBy, | ||
} | ||
}), | ||
) | ||
|
||
return infoArray | ||
} | ||
|
||
function renderEnvInfo(envInfo: EnvVarInfo[]) { | ||
const isAlSet = envInfo.every((info) => info.isSet && info.resolvedBy) | ||
|
||
if (isAlSet) { | ||
return ` | ||
<div> | ||
✅ All environment variables are set | ||
</div> | ||
` | ||
} | ||
|
||
const children = envInfo | ||
.filter((info) => !info.isSet || !info.resolvedBy) | ||
.map( | ||
(info) => ` | ||
<div class="env-info-item"> | ||
⚠️ <strong>${info.envVarName} </strong> is not defined${info.isSet ? ' and uses default value' : ''} | ||
</div>`, | ||
) | ||
|
||
return ` | ||
<div class="env-info"> | ||
${children.join('')} | ||
</div> | ||
` | ||
} | ||
|
||
function renderHtml({ version, envInfo }: StatusInfo) { | ||
return ` | ||
<html lang="en-US"> | ||
<head> | ||
<title>Azure integration status</title> | ||
<meta charset="utf-8"> | ||
<style> | ||
body, .env-info { | ||
display: flex; | ||
} | ||
body { | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
body > * { | ||
margin-bottom: 1em; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Azure integration status</h1> | ||
<div> | ||
Lambda function version: ${version} | ||
</div> | ||
${renderEnvInfo(envInfo)} | ||
<span> | ||
Please reach out our support via <a href="mailto:[email protected]">[email protected]</a> if you have any issues | ||
</span> | ||
</body> | ||
</html> | ||
` | ||
} | ||
|
||
export async function getStatusInfo(customerVariables: CustomerVariables): Promise<StatusInfo> { | ||
return { | ||
version: '__lambda_func_version__', | ||
envInfo: await getEnvInfo(customerVariables), | ||
} | ||
} | ||
|
||
export async function handleStatus({ | ||
customerVariables, | ||
httpRequest, | ||
}: HandleStatusParams): Promise<HttpResponseSimple> { | ||
const { format } = httpRequest.query | ||
|
||
const info = await getStatusInfo(customerVariables) | ||
|
||
if (format === StatusFormat.JSON) { | ||
return { | ||
status: '200', | ||
body: info, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
} | ||
|
||
return { | ||
status: '200', | ||
body: renderHtml(info).trim(), | ||
headers: { | ||
'Content-Type': 'text/html', | ||
}, | ||
} | ||
} |
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,16 @@ | ||
import { CustomerVariableValue } from '../proxy/customer-variables/types' | ||
|
||
export enum StatusFormat { | ||
HTML = 'html', | ||
JSON = 'json', | ||
} | ||
|
||
export interface EnvVarInfo { | ||
envVarName: string | ||
value: CustomerVariableValue | ||
isSet: boolean | ||
// If null, the variable was resolved with the default value, otherwise it was resolved by the provider with the given name | ||
resolvedBy: string | null | ||
} | ||
|
||
export const STATUS_PATH = 'status' |