This commit is contained in:
tree 2022-10-21 10:01:02 +02:00
revize 2e8d1fc078
6 změnil soubory, kde provedl 179 přidání a 0 odebrání

3
.gitignore vendorováno Normal file
Zobrazit soubor

@ -0,0 +1,3 @@
node_modules
.DS_Store
build

15
README.md Normal file
Zobrazit soubor

@ -0,0 +1,15 @@
# services
To install dependencies:
```bash
bun install
```
To run:
```bash
bun run index.ts
```
This project was created using `bun init` in bun v0.1.13. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

binární
bun.lockb Executable file

Binární soubor nebyl zobrazen.

15
package.json Normal file
Zobrazit soubor

@ -0,0 +1,15 @@
{
"name": "gweicz-services",
"module": "index.ts",
"scripts": {
"build": "bun scripts/build.js"
},
"type": "module",
"devDependencies": {
"bun-types": "^0.1.0"
},
"dependencies": {
"js-yaml": "^4.1.0",
"jsonata": "^1.8.6"
}
}

46
scripts/build.js Executable file
Zobrazit soubor

@ -0,0 +1,46 @@
const yaml = require('js-yaml')
const fs = require('fs')
const jsonata = require('jsonata')
const outputFn = 'build/spec.json'
const strategies = {
async default (conf, all) {
const req = await fetch(conf.url)
const resp = await req.json()
return jsonata(conf.query).evaluate(resp)
},
async github (conf, all) {
const req = await fetch('https://api.github.com/repos/@@/releases/latest'.replace(/@@/, all.repo))
const resp = await req.json()
return jsonata('$match(tag_name,/^v(.+)/)[0].groups[0]').evaluate(resp)
},
async html (conf, all) {
const req = await fetch(conf.url)
const resp = await req.text()
return resp.match(conf.query)[1]
}
}
async function getVersions (config, all) {
const local = await strategies[config.from.strategy ? config.from.strategy : 'default'](config.from, all)
const latest = await strategies[config.to.strategy ? config.to.strategy : 'default'](config.to, all)
return { local, latest }
}
async function build () {
const spec = yaml.load(fs.readFileSync('./spec/services.yaml'))
for (const item of spec.services) {
item.url = item.host ? `https://${item.host}` : item.url
item.versions = await getVersions(item.version_conf, item)
delete item.version_conf
}
fs.writeFileSync(outputFn, JSON.stringify(spec, null, 2))
console.log(`saved: ${outputFn}`)
console.log('build done')
}
build()

100
spec/services.yaml Normal file
Zobrazit soubor

@ -0,0 +1,100 @@
services:
- name: Gitea
host: git.gwei.cz
repo: go-gitea/gitea
monitor: 6
version_conf:
from:
url: https://git.gwei.cz/api/v1/version
query: version
to:
strategy: github
- name: Mastodon
host: social.gwei.cz
repo: mastodon/mastodon
monitor: 3
version_conf:
from:
url: https://social.gwei.cz/nodeinfo/2.0
query: software.version
to:
strategy: github
- name: Synapse (Matrix)
repo: matrix-org/synapse
monitor: 1
version_conf:
from:
url: https://gwei.cz/_synapse/admin/v1/server_version
query: server_version
to:
strategy: github
- name: Cinny
repo: cinnyapp/cinny
monitor: 8
version_conf:
from:
url: https://cinny.gwei.cz/version.json
query: $match(version,/^v(.+)/)[0].groups[0]
to:
strategy: github
- name: Tor Relay (#1) (Exit)
monitor: 34
version_conf:
from:
url: https://onionoo.torproject.org/details?lookup=F36E7C8746649077DA254397F721851ABBD4B528
query: relays[0].version
to:
strategy: html
url: https://www.torproject.org/download/tor/
query: "<td>(\\d+\\.\\d+\\.\\d+\\.\\d+)<\/td>"
- name: Tor Relay (#2)
monitor: 33
version_conf:
from:
url: https://onionoo.torproject.org/details?lookup=6DD7CFE5DAE710940E8DF978A5495085FEBB1703
query: relays[0].version
to:
strategy: html
url: https://www.torproject.org/download/tor/
query: "<td>(\\d+\\.\\d+\\.\\d+\\.\\d+)<\/td>"
- name: Discourse (Gwei.cz)
host: forum.gwei.cz
repo: discourse/discourse
monitor: 2
version_conf:
from:
strategy: html
url: https://forum.gwei.cz
query: 'content="Discourse ([^\s]+) -'
to:
strategy: github
- name: Discourse (dCZK)
host: forum.dczk.cz
repo: discourse/discourse
monitor: 2
version_conf:
from:
strategy: html
url: https://forum.dczk.cz
query: 'content="Discourse ([^\s]+) -'
to:
strategy: github
- name: SFTPGo
host: sftpgo.gwei.cz
repo: drakkan/sftpgo
monitor: 37
version_conf:
from:
strategy: html
url: https://sftpgo.gwei.cz/web/admin/login
query: 'WebAdmin - ([^<]+)<\/h1>'
to:
strategy: github