From 3ccadb8f509bcd28cdab9779c35502a851751f95 Mon Sep 17 00:00:00 2001 From: Fionera Date: Mon, 17 Jul 2023 19:41:00 +0200 Subject: [PATCH] feat: allow definition of custom autnums Closes monogon-dev/NetMeta#127 Change-Id: I9fe950411d90836f7c0e29e2c952d0dc947d4796 Reviewed-on: https://review.monogon.dev/c/NetMeta/+/1940 Reviewed-by: Leopold Schabel --- deploy/single-node/config.cue | 12 ++++ deploy/single-node/defs.cue | 1 + .../single-node/k8s/clickhouse/clickhouse.cue | 9 +++ deploy/single-node/k8s/clickhouse/files.cue | 56 +++++++++++++++++++ .../0002_create_dictionaries_database.sql | 5 ++ 5 files changed, 83 insertions(+) create mode 100644 deploy/single-node/schema/0002_create_dictionaries_database.sql diff --git a/deploy/single-node/config.cue b/deploy/single-node/config.cue index 22f6312..15c252a 100644 --- a/deploy/single-node/config.cue +++ b/deploy/single-node/config.cue @@ -143,6 +143,15 @@ _deviceAddressTest: { } } +#UserData: { + // Custom ASNs + autnums: [ASN=string]: { + asn: *strconv.Atoi(ASN) | int + name: string + country: string + } +} + #NetMetaConfig: { // Allow the use of legacy config parameters #LegacyNetMetaConfig @@ -221,6 +230,9 @@ _deviceAddressTest: { // Config parameter like interface names. See #SamplerConfig sampler: #SamplerConfig + + // Userprovided data like custom ASNs + userData: #UserData } #Image: { diff --git a/deploy/single-node/defs.cue b/deploy/single-node/defs.cue index 7ddf5ba..35a1d2f 100644 --- a/deploy/single-node/defs.cue +++ b/deploy/single-node/defs.cue @@ -72,6 +72,7 @@ k8s_list: [ clickhouseReadonlyPassword: netmeta.config.clickhouseReadonlyPassword enableClickhouseIngress: netmeta.config.enableClickhouseIngress sampler: netmeta.config.sampler + userData: netmeta.config.userData } }), diff --git a/deploy/single-node/k8s/clickhouse/clickhouse.cue b/deploy/single-node/k8s/clickhouse/clickhouse.cue index 0a9eb60..e3ff809 100644 --- a/deploy/single-node/k8s/clickhouse/clickhouse.cue +++ b/deploy/single-node/k8s/clickhouse/clickhouse.cue @@ -26,11 +26,20 @@ import ( ... } +#UserData: { + autnums: [string]: { + asn: int + name: string + country: string + } +} + #Config: { clickhouseAdminPassword: string clickhouseReadonlyPassword: string enableClickhouseIngress: bool sampler: #SamplerConfig + userData: #UserData } ClickHouseInstallation: netmeta: spec: { diff --git a/deploy/single-node/k8s/clickhouse/files.cue b/deploy/single-node/k8s/clickhouse/files.cue index be0cce7..bd9aa81 100644 --- a/deploy/single-node/k8s/clickhouse/files.cue +++ b/deploy/single-node/k8s/clickhouse/files.cue @@ -175,6 +175,31 @@ _files: HostNames: { } } +_files: user_autnums: { + data: strings.Join([ for _, e in #Config.userData.autnums { + strings.Join(["\(e.asn)", e.name, e.country], "\t") + }], "\n") + + cfg: { + layout: flat: null + structure: [{ + id: name: "asnum" + }, { + attribute: { + name: "name" + type: "String" + null_value: null + } + }, { + attribute: { + name: "country" + type: "String" + null_value: null + } + }] + } +} + ClickHouseInstallation: netmeta: spec: configuration: files: "risinfo.conf": (xml.#Marshal & {in: { yandex: dictionary: { name: "risinfo" @@ -199,6 +224,37 @@ ClickHouseInstallation: netmeta: spec: configuration: files: "risinfo.conf": (xm ClickHouseInstallation: netmeta: spec: configuration: files: "autnums.conf": (xml.#Marshal & {in: { yandex: dictionary: { name: "autnums" + source: clickhouse: { + query: + #""" + SELECT * FROM dictionaries.risinfo_autnums + UNION ALL + SELECT * FROM dictionaries.user_autnums + """# + } + lifetime: 3600 + layout: flat: null + structure: [{ + id: name: "asnum" + }, { + attribute: { + name: "name" + type: "String" + null_value: null + } + }, { + attribute: { + name: "country" + type: "String" + null_value: null + } + }] + } +}}).out + +ClickHouseInstallation: netmeta: spec: configuration: files: "risinfo_autnums.conf": (xml.#Marshal & {in: { + yandex: dictionary: { + name: "risinfo_autnums" source: http: { url: "http://risinfo/autnums.tsv" format: "TabSeparated" diff --git a/deploy/single-node/schema/0002_create_dictionaries_database.sql b/deploy/single-node/schema/0002_create_dictionaries_database.sql new file mode 100644 index 0000000..348950e --- /dev/null +++ b/deploy/single-node/schema/0002_create_dictionaries_database.sql @@ -0,0 +1,5 @@ +-- +goose Up +CREATE DATABASE dictionaries Engine=Dictionary; + +-- +goose Down +DROP DATABASE dictionaries; \ No newline at end of file