import dayjs from 'dayjs'
import * as wmill from "windmill-client"
// The variable's value is deliberately not a parameter: job arguments and results are
// stored in cleartext and shown in Runs, so this handler is given a path to rotate and
// never a value to handle. Do not add one.
export async function main(
workspace_id: string, // The workspace the variable belongs to
variable_path: string, // The path of the variable whose value is expiring
description: string, // The variable's description
value_expires_at: string, // The datetime at which the value expires
is_secret: boolean, // Whether the variable is a secret
channel: string,
) {
const baseUrl = process.env["WM_BASE_URL"];
const variablesUrl = `${baseUrl}/variables?workspace=${encodeURIComponent(workspace_id)}`;
const expiresAt = dayjs(value_expires_at).format("DD.MM.YYYY HH:mm (Z)");
const kind = is_secret ? "Secret" : "Variable";
const mdText = `*${kind} [${variable_path}](${variablesUrl}) is about to expire*\n- Expires at: ${expiresAt}`
await wmill.TeamsService.sendMessageToConversation(
{
requestBody: {
conversation_id: channel,
success: true,
text: mdText,
card_block: {
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Variable Expiration Handler"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Icon",
"name": "Key",
"size": "Medium",
"style": "Filled",
"color": "Warning"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": mdText,
"wrap": true
},
{
"type": "TextBlock",
"text": description
? `Rotate it before it stops working.\n\n${description}`
: "Rotate it before it stops working.",
"wrap": true
}
],
"width": "stretch"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.6"
}
}
]
}
}
}
)
}
Submitted by hugo989 3 hours ago