membership watcher
This commit is contained in:
12
app.yml
12
app.yml
@@ -36,6 +36,18 @@ wwMeta:
|
|||||||
# frequency: 60000 # 1'
|
# frequency: 60000 # 1'
|
||||||
# maxLate: 14400 # 4h
|
# maxLate: 14400 # 4h
|
||||||
|
|
||||||
|
memberships:
|
||||||
|
# Tous les 1j ==> 3 mois de prévenance
|
||||||
|
# - {address: https://g1.cgeek.fr, currency: ğ1, frequency: 86400, mustRemain: 7776000, pubkey: 2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ, memberAlias: cgeek}
|
||||||
|
# - {address: https://g1.cgeek.fr, currency: ğ1, frequency: 86400, mustRemain: 7776000, pubkey: 4GdKJq2LqV1rrCkixUoSpg4w5Abz41knU4h9eov2R3QU, memberAlias: Audrey35}
|
||||||
|
# Tous les 1j ==> 1 mois de prévenance
|
||||||
|
- {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 2592000, pubkey: 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj, memberAlias: cgeek}
|
||||||
|
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 2592000, pubkey: 39YyHCMQNmXY7NkPCXXfzpV1vYct4GBxwgfyd4d72HmB, memberAlias: cgeek-4}
|
||||||
|
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 7776000, pubkey: 36UhAqrkDx11ifN7WaBM6Q5bMUJxhKb1wJnnPFnkLkCF, memberAlias: cgeek-2} # Compte révoqué
|
||||||
|
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 7776000, pubkey: 81jPYhcyruwKJ9Dy4Vz7MtmxiSdeESuJcvjPotxbCTgS, memberAlias: cgeek-3} # Compte révoqué
|
||||||
|
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 7776000, pubkey: 78Tus1ajGnztK6FW7suYsprWFZUkiiG1bakuMNsHooWo, memberAlias: cgeek-dev} # Compte révoqué
|
||||||
|
# - {address: https://g1-test.cgeek.fr, currency: ğtest, frequency: 86400, mustRemain: 7776000, pubkey: 4Ec3yqwfCxJM2pB3jCGrbUSvxqDGxasQcBCxCyA81Nwh, memberAlias: cgeek-test-revocation} # Compte révoqué
|
||||||
|
|
||||||
mail:
|
mail:
|
||||||
enabled: false
|
enabled: false
|
||||||
frequency: 3000 # 10"
|
frequency: 3000 # 10"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {Watcher} from "./types/state";
|
|||||||
import {headWatcher} from "./watchers/bma/head-watcher";
|
import {headWatcher} from "./watchers/bma/head-watcher";
|
||||||
import {jsonWatcher} from "./watchers/wotwizard/json-watcher";
|
import {jsonWatcher} from "./watchers/wotwizard/json-watcher";
|
||||||
import {initConfMail} from './mail'
|
import {initConfMail} from './mail'
|
||||||
|
import {membershipWatcher} from './watchers/bma/membership-watcher'
|
||||||
|
|
||||||
export async function dwatch(confFile: string) {
|
export async function dwatch(confFile: string) {
|
||||||
|
|
||||||
@@ -22,5 +23,6 @@ export async function dwatch(confFile: string) {
|
|||||||
(await Promise.all((conf.webDiffServers || []).map(webDiffWatcher(conf)))).forEach(w => watchers.push(w));
|
(await Promise.all((conf.webDiffServers || []).map(webDiffWatcher(conf)))).forEach(w => watchers.push(w));
|
||||||
(await Promise.all((conf.headServers || []).map(headWatcher(conf)))).forEach(w => watchers.push(w));
|
(await Promise.all((conf.headServers || []).map(headWatcher(conf)))).forEach(w => watchers.push(w));
|
||||||
(await Promise.all((conf.wwMeta || []).map(jsonWatcher(conf)))).forEach(w => watchers.push(w));
|
(await Promise.all((conf.wwMeta || []).map(jsonWatcher(conf)))).forEach(w => watchers.push(w));
|
||||||
|
(await Promise.all((conf.memberships || []).map(membershipWatcher(conf)))).forEach(w => watchers.push(w));
|
||||||
return watchers
|
return watchers
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export interface Conf {
|
|||||||
webDiffServers: ConfWebDiff[]
|
webDiffServers: ConfWebDiff[]
|
||||||
headServers: ConfHead[]
|
headServers: ConfHead[]
|
||||||
wwMeta: ConfWWMeta[]
|
wwMeta: ConfWWMeta[]
|
||||||
|
memberships: ConfMembership[]
|
||||||
mail: ConfMail
|
mail: ConfMail
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +37,13 @@ export interface ConfBMA extends ConfURL {
|
|||||||
maxLate?: number
|
maxLate?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ConfMembership extends ConfURL {
|
||||||
|
pubkey: string
|
||||||
|
memberAlias: string
|
||||||
|
currency: string
|
||||||
|
mustRemain: number
|
||||||
|
}
|
||||||
|
|
||||||
export interface ConfHead extends ConfURL {
|
export interface ConfHead extends ConfURL {
|
||||||
observedPubkey: string
|
observedPubkey: string
|
||||||
maxLateBlocks: number
|
maxLateBlocks: number
|
||||||
|
|||||||
41
src/lib/watchers/bma/membership-watcher.ts
Normal file
41
src/lib/watchers/bma/membership-watcher.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import {Conf, ConfMembership} from "../../types/conf";
|
||||||
|
import {urlWatcher, UrlWatcherResult} from '../abstract/url-watcher'
|
||||||
|
|
||||||
|
export function membershipWatcher(conf: Conf) {
|
||||||
|
|
||||||
|
const URL_PATH = '/wot/requirements/'
|
||||||
|
|
||||||
|
return async (confMS: ConfMembership) => {
|
||||||
|
|
||||||
|
function getSubjectTitle(state: string) {
|
||||||
|
return `State ${state} MS of ${confMS.memberAlias} (${confMS.currency})`
|
||||||
|
}
|
||||||
|
|
||||||
|
let state = 'INIT'
|
||||||
|
|
||||||
|
return urlWatcher(conf, async (data) => {
|
||||||
|
const json = data as { identities: {membershipExpiresIn: number}[] }
|
||||||
|
// On se base sur la clé publique donc a priori une seule identité OK
|
||||||
|
const idty = json.identities[0]
|
||||||
|
if (idty.membershipExpiresIn < confMS.mustRemain) {
|
||||||
|
if (idty.membershipExpiresIn > 0) {
|
||||||
|
state = 'WARNING'
|
||||||
|
const remainingDays = Math.floor(idty.membershipExpiresIn / (3600 * 24))
|
||||||
|
return UrlWatcherResult.ko(`Membership is going to expire in ${remainingDays.toFixed(0)} days`)
|
||||||
|
} else {
|
||||||
|
state = 'ERROR'
|
||||||
|
return UrlWatcherResult.ko(`Membership expired`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state = 'OK'
|
||||||
|
return UrlWatcherResult.ok()
|
||||||
|
})({
|
||||||
|
name: `membership ${confMS.pubkey}`,
|
||||||
|
address: confMS.address + URL_PATH + confMS.pubkey,
|
||||||
|
frequency: confMS.frequency
|
||||||
|
},
|
||||||
|
() => getSubjectTitle(state),
|
||||||
|
() => getSubjectTitle(state),
|
||||||
|
() => getSubjectTitle(state))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user