@yarkivaev/scada 2.16.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -2
- package/package.json +3 -2
- package/src/application/deploy/collectorSourcePlan.js +97 -0
- package/src/application/deploy/compileCollectorTasks.js +31 -0
- package/src/application/deploy/compileControlCatalog.js +66 -0
- package/src/application/deploy/controlPlacement.js +71 -0
- package/src/application/deploy/controlPlan.js +51 -4
- package/src/application/deploy/controlPlaneConfiguration.js +62 -0
- package/src/application/deploy/controlReaderSpecs.js +37 -0
- package/src/application/deploy/liveReleaseOverlay.js +17 -0
- package/src/application/deploy/projectControlPlane.js +48 -0
- package/src/application/deploy/projectTopology.js +41 -0
- package/src/application/deploy/readDeploymentDocument.js +25 -0
- package/src/infrastructure/deploy/brokerReplicaTopology.js +97 -0
- package/src/infrastructure/deploy/brokerSecurity.js +89 -0
- package/src/infrastructure/deploy/brokerSecurityInput.js +85 -0
- package/src/infrastructure/deploy/brokerTopology.js +125 -0
- package/src/infrastructure/deploy/buildDeploymentStages.js +23 -0
- package/src/infrastructure/deploy/centralTelemetry.js +51 -0
- package/src/infrastructure/deploy/clickhouseTelemetryPolicy.js +64 -0
- package/src/infrastructure/deploy/collectorChartPlan.js +68 -0
- package/src/infrastructure/deploy/compileDeploymentHooks.js +48 -0
- package/src/infrastructure/deploy/configuredHistorySeed.js +54 -0
- package/src/infrastructure/deploy/configuredPostgresMaintenance.js +23 -0
- package/src/infrastructure/deploy/databaseSecurity.js +39 -0
- package/src/infrastructure/deploy/deploymentRecovery.js +49 -0
- package/src/infrastructure/deploy/deploymentTemplate.js +67 -0
- package/src/infrastructure/deploy/executeConfiguredChartDeployment.js +65 -0
- package/src/infrastructure/deploy/executeManagedDeployment.js +46 -0
- package/src/infrastructure/deploy/highAvailability/brokerOwnership.js +19 -0
- package/src/infrastructure/deploy/highAvailability/catalogReconciler.js +61 -0
- package/src/infrastructure/deploy/highAvailability/classifyFederation.js +57 -0
- package/src/infrastructure/deploy/highAvailability/classifyGate.js +114 -0
- package/src/infrastructure/deploy/highAvailability/classifyLoop.js +139 -0
- package/src/infrastructure/deploy/highAvailability/classifyShovels.js +70 -0
- package/src/infrastructure/deploy/highAvailability/classifyWatermark.js +45 -0
- package/src/infrastructure/deploy/highAvailability/compileClassifierRules.js +21 -0
- package/src/infrastructure/deploy/highAvailability/controllerReconcile.js +14 -0
- package/src/infrastructure/deploy/highAvailability/historyReceiver.js +49 -0
- package/src/infrastructure/deploy/highAvailability/historyWatermark.js +42 -0
- package/src/infrastructure/deploy/highAvailability/index.js +14 -0
- package/src/infrastructure/deploy/highAvailability/reconcileBrokerThroughController.js +18 -0
- package/src/infrastructure/deploy/highAvailability/reconciliationBundle.js +28 -0
- package/src/infrastructure/deploy/highAvailability/segmentAdmit.js +24 -0
- package/src/infrastructure/deploy/highAvailability/segmentPublish.js +27 -0
- package/src/infrastructure/deploy/highAvailability/supervisorReplica.js +36 -0
- package/src/infrastructure/deploy/index.js +33 -1
- package/src/infrastructure/deploy/projectClassification.js +42 -0
- package/src/infrastructure/deploy/securityPolicy.js +16 -0
- package/src/infrastructure/deploy/stagedStoragePreflight.js +72 -0
- package/src/infrastructure/deploy/validateStagedDeploymentEvidence.js +16 -0
- package/src/infrastructure/ingest/telemetry/centralPolicy.js +29 -8
- package/src/infrastructure/management/kiosk/kioskDeployment.js +60 -0
- package/src/infrastructure/mdmesh/bootstrapMdmeshCredentials.js +47 -0
- package/src/infrastructure/mdmesh/hmiPlan.js +123 -0
- package/src/infrastructure/mdmesh/index.js +3 -0
- package/src/infrastructure/mdmesh/mdmeshServerRelease.js +58 -0
- package/src/infrastructure/messaging/rabbitmq/definitions.js +12 -6
- package/src/infrastructure/opcua/projectSources.js +36 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { deploymentStage } from './compileDeploymentHooks.js';
|
|
2
|
+
import { preserveKubeRestart } from './deploymentKube.js';
|
|
3
|
+
import preflightKubeStorage from './preflightKubeStorage.js';
|
|
4
|
+
import verifyPeerBrokerPerimeter from './verifyPeerBrokerPerimeter.js';
|
|
5
|
+
|
|
6
|
+
function preserveRestart(plan, declarations, kube) {
|
|
7
|
+
for (const declaration of declarations) {
|
|
8
|
+
const stage = plan.stages.find(({ id }) => { return id === declaration.stage; });
|
|
9
|
+
if (stage && declaration.workload) {
|
|
10
|
+
stage.values.podAnnotations = preserveKubeRestart(kube, declaration.workload, stage.values.podAnnotations);
|
|
11
|
+
}
|
|
12
|
+
for (const object of stage?.values.extraObjects ?? []) {
|
|
13
|
+
if (declaration.objectKind && object.kind === declaration.objectKind) {
|
|
14
|
+
const { metadata } = object.spec.template;
|
|
15
|
+
metadata.annotations = preserveKubeRestart(kube, `${object.kind.toLowerCase()}/${object.metadata.name}`, metadata.annotations, stage.namespace);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function secrets({ postgresSecret, brokerSecrets, runtimeSecret, requiredSecretKeys, databaseRuntime }, database) {
|
|
22
|
+
return [
|
|
23
|
+
...(brokerSecrets ?? []).map((name) => { return { name }; }),
|
|
24
|
+
{ name: runtimeSecret, keys: requiredSecretKeys },
|
|
25
|
+
{ name: postgresSecret, keys: database.secretKeys },
|
|
26
|
+
...(databaseRuntime ? [{ name: databaseRuntime.runtimeSecret, keys: [databaseRuntime.runtimeKey] }] : [])
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function storageTemplates(plan, database, postgres, broker, rabbitmq) {
|
|
31
|
+
if (!plan.preserveStoragePodTemplates) { return []; }
|
|
32
|
+
return [{ name: database.name, values: postgres }, ...(plan.brokerSecurity ? [] : [{ name: broker.name, values: rabbitmq }])];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function checkPerimeter(plan, evidence, selector, kube) {
|
|
36
|
+
const policy = plan.prerequisites.peerBrokerPerimeter;
|
|
37
|
+
if (!policy) { return; }
|
|
38
|
+
const allowedPeers = policy.spec.ingress[0].from.filter((peer) => { return peer.ipBlock; }).map((peer) => {
|
|
39
|
+
return peer.ipBlock.cidr.replace(/\/(?:32|128)$/u, '');
|
|
40
|
+
});
|
|
41
|
+
verifyPeerBrokerPerimeter({ context: plan.context, policy, allowedPeers, selector, proof: evidence.peerBrokerPerimeter }, kube);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function storageResources(plan, policy) {
|
|
45
|
+
const declared = (policy.requiredResources ?? []).filter(({ stage }) => {
|
|
46
|
+
return !stage || plan.stages.some(({ id }) => { return stage === id; });
|
|
47
|
+
}).map(({ name, namespace }) => { return { name, namespace }; });
|
|
48
|
+
return [...plan.prerequisites.preservedConfigMaps.map((name) => { return { name: `configmap/${name}` }; }), ...declared];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Bind rollout storage checks to the projected resources and supplied identity evidence. */
|
|
52
|
+
export default function stagedStoragePreflight(plan, policy, { evidence, execute, action }) {
|
|
53
|
+
const stage = deploymentStage(plan, policy.stage);
|
|
54
|
+
const { postgres, rabbitmq } = stage.values;
|
|
55
|
+
const { database, broker } = policy;
|
|
56
|
+
return preflightKubeStorage({
|
|
57
|
+
context: plan.context,
|
|
58
|
+
namespace: plan.namespace,
|
|
59
|
+
nodeAddress: plan.nodeAddress,
|
|
60
|
+
secrets: secrets(plan.prerequisites, database),
|
|
61
|
+
beforeStorage: evidence && ((kube) => { checkPerimeter(plan, evidence, broker.selector, kube); }),
|
|
62
|
+
layouts: [{ name: database.name, volume: database.volume, mountPath: database.mountPath, claim: postgres.existingClaim,
|
|
63
|
+
env: database.environment, environmentValue: postgres.data }],
|
|
64
|
+
preserveTemplates: storageTemplates(plan, database, postgres, broker, rabbitmq),
|
|
65
|
+
preserveAnnotations(kube) { preserveRestart(plan, policy.preserveRestart ?? [], kube); },
|
|
66
|
+
verifyTemplates: evidence && { stage, workloads: rabbitmq.definitionsSecret ? [database.name] : [database.name, broker.name] },
|
|
67
|
+
claims: plan.prerequisites.existingClaims.map((name) => {
|
|
68
|
+
return { name, claimUid: evidence?.claims[name], volumeName: evidence?.volumes[name].name, volumeUid: evidence?.volumes[name].uid };
|
|
69
|
+
}),
|
|
70
|
+
resources: storageResources(plan, policy)
|
|
71
|
+
}, action, execute);
|
|
72
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { deploymentStage } from './compileDeploymentHooks.js';
|
|
2
|
+
import { validateDeploymentEvidence } from './deploymentChecks.js';
|
|
3
|
+
|
|
4
|
+
/** Validate rollout proof against the readers assigned by the prepared plan. */
|
|
5
|
+
export default function validateStagedDeploymentEvidence(plan, policy, evidence, now) {
|
|
6
|
+
const collector = deploymentStage(plan, policy.collectorStage);
|
|
7
|
+
const { controlCatalog } = collector;
|
|
8
|
+
const tasks = controlCatalog ? controlCatalog.tasks.filter(({ pinnedNode }) => {
|
|
9
|
+
return pinnedNode === plan.context;
|
|
10
|
+
}) : JSON.parse(collector.values.processes[0].env.COLLECTOR_MANIFEST).assignments;
|
|
11
|
+
const readers = Object.fromEntries(Object.entries(policy.optionalReaders ?? {}).map(([key, adapter]) => {
|
|
12
|
+
return [key, tasks.some((task) => { return task.spec.adapter === adapter; })];
|
|
13
|
+
}));
|
|
14
|
+
return validateDeploymentEvidence({ context: plan.context, required: policy.required,
|
|
15
|
+
claims: plan.prerequisites.existingClaims, catalogVersion: controlCatalog?.version, readers }, evidence, now);
|
|
16
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export const centralTelemetryVersion = 4;
|
|
2
|
+
|
|
1
3
|
function keys(value, allowed) {
|
|
2
4
|
if (!value || typeof value !== 'object' || Array.isArray(value)
|
|
3
5
|
|| Object.keys(value).some((key) => { return !allowed.includes(key); })) {
|
|
@@ -22,20 +24,20 @@ export function centralRule(value, fallback = ruleDefaults) {
|
|
|
22
24
|
}
|
|
23
25
|
return rule;
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
export default function centralPolicy(input = {}) {
|
|
27
|
-
const config = typeof input === 'string' ? JSON.parse(input) : input;
|
|
27
|
+
function parsePolicy(config, strict = false) {
|
|
28
28
|
keys(config, ['enabled', 'default', 'topics', 'queue', 'queueMaxBytes', 'maxPendingBatches', 'batchSize']);
|
|
29
|
-
if (config.enabled !== undefined && typeof config.enabled !== 'boolean') { throw new TypeError('Invalid central policy enabled'); }
|
|
29
|
+
if ((strict || config.enabled !== undefined) && typeof config.enabled !== 'boolean') { throw new TypeError('Invalid central policy enabled'); }
|
|
30
30
|
keys(config.default ?? {}, CENTRAL_RULE_FIELDS);
|
|
31
31
|
const defaults = centralRule(config.default ?? {});
|
|
32
|
-
|
|
32
|
+
const entries = config.topics === undefined || (!strict && config.topics === null) ? [] : config.topics;
|
|
33
|
+
if (!Array.isArray(entries)) { throw new TypeError('Invalid central policy topics'); }
|
|
33
34
|
const topics = new Map();
|
|
34
|
-
|
|
35
|
+
entries.forEach((entry) => {
|
|
35
36
|
keys(entry, ['topic', ...CENTRAL_RULE_FIELDS]);
|
|
36
37
|
if (typeof entry.topic !== 'string' || !entry.topic || entry.topic.length > 1024
|
|
37
38
|
// eslint-disable-next-line no-control-regex
|
|
38
|
-
|| /[\s\u0000-\u001f\u007f#+*]/u.test(entry.topic) || topics.has(entry.topic)
|
|
39
|
+
|| /[\s\u0000-\u001f\u007f#+*]/u.test(entry.topic) || topics.has(entry.topic)
|
|
40
|
+
|| (strict && /[\p{Cc}{}]/u.test(entry.topic))) {
|
|
39
41
|
throw new TypeError('Invalid or duplicate central policy topic');
|
|
40
42
|
}
|
|
41
43
|
topics.set(entry.topic, centralRule(entry, defaults));
|
|
@@ -44,8 +46,27 @@ export default function centralPolicy(input = {}) {
|
|
|
44
46
|
if (typeof queue !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,254}$/u.test(queue) || queue.startsWith('amq.')) {
|
|
45
47
|
throw new TypeError('Invalid central policy queue');
|
|
46
48
|
}
|
|
47
|
-
return { enabled: config.enabled === true,
|
|
49
|
+
return { enabled: config.enabled === true, defaults, topics, queue,
|
|
48
50
|
queueMaxBytes: positive(config.queueMaxBytes ?? 1073741824, 'queue bytes'),
|
|
49
51
|
maxPendingBatches: positive(config.maxPendingBatches ?? 100000, 'pending batches', 2147483647),
|
|
50
52
|
batchSize: positive(config.batchSize ?? 500, 'batch size', 1000) };
|
|
51
53
|
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function serializedRule({ compactWindowMs, maxGapMs, ...rest }) {
|
|
57
|
+
return { compactWindowMs, maxGapMs, ...rest };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Normalize and validate the policy object serialized into deployment values and collector specs. */
|
|
61
|
+
export function normalizeCentralPolicy(config) {
|
|
62
|
+
const { enabled, defaults, topics, ...options } = parsePolicy(config, true);
|
|
63
|
+
return { enabled, default: serializedRule(defaults),
|
|
64
|
+
topics: [...topics].map(([topic, rule]) => { return { topic, ...serializedRule(rule) }; }), ...options };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Native point storage with a bounded immutable archive. */
|
|
68
|
+
export default function centralPolicy(input = {}) {
|
|
69
|
+
const config = typeof input === 'string' ? JSON.parse(input) : input;
|
|
70
|
+
const { enabled, defaults, topics, queue, ...limits } = parsePolicy(config);
|
|
71
|
+
return { enabled, queue, forTopic(topic) { return topics.get(topic) ?? defaults; }, ...limits };
|
|
72
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import operateRemote from './operateKiosk.js';
|
|
3
|
+
import renderResources from './renderKioskResources.js';
|
|
4
|
+
|
|
5
|
+
const restartAnnotation = 'kubectl.kubernetes.io/restartedAt';
|
|
6
|
+
|
|
7
|
+
function between(value, minimum, maximum) {
|
|
8
|
+
return Number.isInteger(value) && value >= minimum && value <= maximum;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function checkSettings(config) {
|
|
12
|
+
if (!config || !/^[a-z_][a-z0-9_-]*$/u.test(config.audioUser ?? '') || !between(config.volumePercent, 0, 100)
|
|
13
|
+
|| !between(config.audioCard, 0, 32) || !between(config.debugPort, 1, 65535)) {
|
|
14
|
+
throw new TypeError('Invalid kiosk audio/browser settings');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function browserTarget(host, nodeAddress, config, policy, targetPattern) {
|
|
19
|
+
const match = targetPattern.exec(host ?? '');
|
|
20
|
+
if (!match) { throw new TypeError('Exact kiosk target required'); }
|
|
21
|
+
checkSettings(config);
|
|
22
|
+
const url = new URL(config.url.replace('{number}', match[1]));
|
|
23
|
+
if (url.protocol !== 'http:' || !['localhost', '127.0.0.1', nodeAddress].includes(url.hostname)
|
|
24
|
+
|| url.username || url.password || url.port !== policy.port || url.hash
|
|
25
|
+
|| (url.search && url.search !== policy.query.replace('{number}', match[1])) || !/^[\w/.-]*$/u.test(url.pathname)) {
|
|
26
|
+
throw new TypeError('Invalid kiosk HMI URL');
|
|
27
|
+
}
|
|
28
|
+
if (!/^\d{1,3}(?:\.\d{1,3}){3}$/u.test(nodeAddress ?? '')) { throw new TypeError('Invalid kiosk node address'); }
|
|
29
|
+
return { ...config, url: url.href, host, nodeAddress };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function browserObjects(plan, declaration, policy) {
|
|
33
|
+
const objects = renderResources(declaration);
|
|
34
|
+
for (const object of objects.filter(({ kind }) => { return kind === 'DaemonSet'; })) {
|
|
35
|
+
const pod = object.spec.template.metadata;
|
|
36
|
+
for (const metadata of [object.metadata, pod]) {
|
|
37
|
+
metadata.labels = { ...metadata.labels, [policy.workloadLabel]: plan.host };
|
|
38
|
+
}
|
|
39
|
+
delete pod.annotations?.[restartAnnotation];
|
|
40
|
+
}
|
|
41
|
+
objects.find(({ metadata }) => { return metadata.name === policy.urlConfigMap; }).data.url = plan.url;
|
|
42
|
+
const browser = objects.find(({ metadata }) => { return metadata.name === policy.browser; });
|
|
43
|
+
browser.spec.template.metadata.annotations[policy.checksumAnnotation] = createHash('sha256').update(plan.url).digest('hex');
|
|
44
|
+
return objects;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Project the declared browser resources and connect per-installation SSH credentials. */
|
|
48
|
+
export default function kioskDeployment(policy, declaration) {
|
|
49
|
+
const targetPattern = new RegExp(policy.targetPattern, 'u');
|
|
50
|
+
return {
|
|
51
|
+
kioskPlan(host, nodeAddress, config) { return browserTarget(host, nodeAddress, config, policy, targetPattern); },
|
|
52
|
+
kioskObjects(plan) { return browserObjects(plan, declaration, policy); },
|
|
53
|
+
operateKiosk(plan, action, execute, environment = process.env) {
|
|
54
|
+
const ssh = Object.fromEntries(Object.entries(policy.sshEnvironment ?? {}).map(([key, name]) => {
|
|
55
|
+
return [key, environment[name]];
|
|
56
|
+
}));
|
|
57
|
+
return operateRemote(plan, action, { execute, environment, ssh });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
function hash(input) {
|
|
5
|
+
return createHash('sha1').update(`${createHash('md5').update(input).digest('hex').toUpperCase()}5YdSYHyg2U`).digest('hex');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function password() { return randomBytes(32).toString('base64url'); }
|
|
9
|
+
|
|
10
|
+
function connectionSecret(name, namespace, declared) {
|
|
11
|
+
const admin = declared?.password || password();
|
|
12
|
+
const api = password();
|
|
13
|
+
const monitor = password();
|
|
14
|
+
const values = {
|
|
15
|
+
DB_USER: 'mdmesh', DB_PASSWORD: password(), HASH_SECRET: randomBytes(32).toString('hex'), JWT_SECRET: randomBytes(64).toString('hex'),
|
|
16
|
+
ADMIN_PASSWORD: admin, ADMIN_PASSWORD_HASH: hash(admin), ADMIN_RESET_TOKEN: randomBytes(20).toString('hex'),
|
|
17
|
+
API_LOGIN: 'hmi-controller', API_PASSWORD: api, API_PASSWORD_HASH: hash(api),
|
|
18
|
+
MONITOR_LOGIN: 'hmi-monitor', MONITOR_PASSWORD: monitor, MONITOR_PASSWORD_HASH: hash(monitor), CONTROL_TOKEN: password()
|
|
19
|
+
};
|
|
20
|
+
return { apiVersion: 'v1', kind: 'Secret', metadata: { name, namespace }, type: 'Opaque',
|
|
21
|
+
data: Object.fromEntries(Object.entries(values).map(([key, value]) => { return [key, Buffer.from(value).toString('base64')]; })) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function registrySecret(name, namespace, registryFile, policy) {
|
|
25
|
+
if (!registryFile) { throw new Error('HMI bootstrap requires a dedicated read-only registry credential file'); }
|
|
26
|
+
const config = JSON.parse(readFileSync(registryFile, 'utf8'));
|
|
27
|
+
const token = new RegExp(policy.registryIdentityPattern, 'u');
|
|
28
|
+
const entries = Object.entries(config.auths || {});
|
|
29
|
+
if (!entries.length || entries.some(([repository, value]) => {
|
|
30
|
+
return !policy.registryRepositories.includes(repository) || !token.test(Buffer.from(value.auth || '', 'base64').toString())
|
|
31
|
+
|| Object.keys(value).some((key) => { return key !== 'auth'; });
|
|
32
|
+
})) { throw new Error('HMI registry credentials require project-scoped deploy tokens'); }
|
|
33
|
+
const data = Buffer.from(JSON.stringify({ auths: Object.fromEntries(entries) })).toString('base64');
|
|
34
|
+
return { apiVersion: 'v1', kind: 'Secret', metadata: { name, namespace }, type: 'kubernetes.io/dockerconfigjson',
|
|
35
|
+
data: { '.dockerconfigjson': data } };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Initialize absent MDMesh and registry credentials without replacing existing passwords. */
|
|
39
|
+
export default function bootstrapMdmeshCredentials(plan, kube, policy, registryFile = process.env[policy.registryFileEnvironment]) {
|
|
40
|
+
const { namespace, values } = plan;
|
|
41
|
+
function apply(object) { kube(['apply', '--server-side', `--field-manager=${policy.fieldManager}`, '-f', '-'], JSON.stringify(object)); }
|
|
42
|
+
function missing(name) { return !kube(['get', 'secret', name, '--ignore-not-found', '-o', 'name']).trim(); }
|
|
43
|
+
apply({ apiVersion: 'v1', kind: 'Namespace', metadata: { name: namespace } });
|
|
44
|
+
if (missing(values.secret)) { apply(connectionSecret(values.secret, namespace, values.admin)); }
|
|
45
|
+
if (missing(values.pullSecret)) { apply(registrySecret(values.pullSecret, namespace, registryFile, policy)); }
|
|
46
|
+
return { namespace, credentialSecret: values.secret };
|
|
47
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import paths from '../../application/deploy/paths.js';
|
|
2
|
+
|
|
3
|
+
function record(value, context) {
|
|
4
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) { throw new TypeError(`HMI ${context} must be an object`); }
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function text(value, context) {
|
|
9
|
+
if (typeof value !== 'string' || !value.trim()) { throw new TypeError(`HMI ${context} must be a nonempty string`); }
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function credentials(value) {
|
|
14
|
+
Object.entries(value).forEach(([key, entry]) => {
|
|
15
|
+
if (/password|secret|token|credential|command/iu.test(key)) { throw new TypeError(`HMI catalog cannot embed ${key}`); }
|
|
16
|
+
if (entry && typeof entry === 'object') { credentials(entry); }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function moduleFor(servers, id) {
|
|
21
|
+
const server = servers.find((entry) => { return entry.id === id; });
|
|
22
|
+
const module = server?.modules?.mdmesh;
|
|
23
|
+
if (!module || module.enabled !== true) { throw new TypeError(`HMI server ${id} requires enabled mdmesh module`); }
|
|
24
|
+
if (typeof module.namespace !== 'string' || module.namespace.length > 63
|
|
25
|
+
|| !/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(module.namespace)) {
|
|
26
|
+
throw new TypeError(`HMI server ${id} requires a DNS namespace`);
|
|
27
|
+
}
|
|
28
|
+
return module;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function profilesFor(profiles) {
|
|
32
|
+
Object.entries(record(profiles, 'profiles')).forEach(([id, profile]) => {
|
|
33
|
+
record(profile, `profile ${id}`);
|
|
34
|
+
if (!['landscape', 'portrait'].includes(profile.orientation)) { throw new TypeError(`HMI profile ${id} has invalid orientation`); }
|
|
35
|
+
['kiosk', 'keepScreenOnWhileCharging', 'alarmSound'].forEach((key) => {
|
|
36
|
+
if (typeof profile[key] !== 'boolean') { throw new TypeError(`HMI profile ${id} requires boolean ${key}`); }
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return profiles;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function unique(value, seen, context) {
|
|
43
|
+
text(value, context);
|
|
44
|
+
if (seen.has(value)) { throw new TypeError(`HMI duplicate ${context} ${value}`); }
|
|
45
|
+
seen.add(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function artifactFor(apk, { packageName, downloadPrefix }) {
|
|
49
|
+
if (apk.package !== packageName || !/^\d+\.\d+\.\d+$/u.test(apk.version)
|
|
50
|
+
|| !Number.isSafeInteger(apk.versionCode) || apk.versionCode < 1 || !/^[a-f0-9]{64}$/u.test(apk.sha256)) { throw new TypeError('HMI APK requires a package, version and SHA-256'); }
|
|
51
|
+
const url = new URL(apk.url);
|
|
52
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash
|
|
53
|
+
|| (!url.pathname.startsWith(downloadPrefix) || !/^[a-z0-9-]+\.apk$/u.test(url.pathname.slice(downloadPrefix.length)))) { throw new TypeError('HMI APK requires its dedicated HTTPS download path'); }
|
|
54
|
+
if (apk.retire && (!Array.isArray(apk.retire) || apk.retire.some((pkg) => { return typeof pkg !== 'string' || !pkg.startsWith(`${packageName}.`) || !/^[a-z][a-z0-9_]*$/u.test(pkg.slice(packageName.length + 1)); }))) {
|
|
55
|
+
throw new TypeError('HMI APK retire list requires former machine packages');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function applicationFor(device, policy) {
|
|
60
|
+
const app = device.application;
|
|
61
|
+
if (!Object.hasOwn(app, 'autoStart')) { return; }
|
|
62
|
+
if (typeof app.autoStart !== 'boolean') { throw new TypeError('HMI autoStart must be boolean'); }
|
|
63
|
+
if (!app.autoStart) { return; }
|
|
64
|
+
const href = new URL(policy.address(app.href));
|
|
65
|
+
if (href.searchParams.get('machine') !== device.machine) { throw new TypeError('HMI autoStart requires a matching machine URL'); }
|
|
66
|
+
artifactFor(record(app.apk, 'application APK'), policy);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function shared(devices) {
|
|
70
|
+
const apks = devices.filter((device) => { return device.application.autoStart; }).map((device) => { return device.application.apk; });
|
|
71
|
+
if (apks.some((apk) => { return ['package', 'version', 'versionCode', 'url', 'sha256'].some((key) => { return apk[key] !== apks[0][key]; }); })) {
|
|
72
|
+
throw new TypeError('HMI autoStart devices must share one APK');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function binding(device, document, machines, profiles, policy) {
|
|
77
|
+
record(device, 'device');
|
|
78
|
+
record(device.orchestrator, `device ${device.id} orchestrator`);
|
|
79
|
+
record(device.application, `device ${device.id} application`);
|
|
80
|
+
if (device.orchestrator.module !== 'mdmesh') { throw new TypeError(`HMI device ${device.id} requires mdmesh orchestrator`); }
|
|
81
|
+
moduleFor(document.servers, device.orchestrator.server);
|
|
82
|
+
if (!document.servers.some((server) => { return server.id === device.application.server; })) {
|
|
83
|
+
throw new TypeError(`HMI device ${device.id} references unknown application server ${device.application.server}`);
|
|
84
|
+
}
|
|
85
|
+
applicationFor(device, policy);
|
|
86
|
+
if (device.application.autoStart && !profiles[device.profile]?.kiosk) { throw new TypeError('Automatic HMI requires a kiosk profile'); }
|
|
87
|
+
if (!Object.hasOwn(profiles, device.profile)) { throw new TypeError(`HMI device ${device.id} references unknown profile ${device.profile}`); }
|
|
88
|
+
if (!machines.has(device.machine) || device.application.machine !== device.machine) {
|
|
89
|
+
throw new TypeError(`HMI device ${device.id} requires a matching namespace machine ${device.machine}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function devicesFor(catalog) {
|
|
94
|
+
if (!Array.isArray(catalog.devices)) { throw new TypeError('HMI devices must be an array'); }
|
|
95
|
+
if (catalog.apk === undefined) { return catalog.devices; }
|
|
96
|
+
const apk = record(catalog.apk, 'shared APK');
|
|
97
|
+
return catalog.devices.map((device) => {
|
|
98
|
+
if (device?.application?.autoStart !== true) { return device; }
|
|
99
|
+
const app = device.application;
|
|
100
|
+
const override = app.apk === undefined ? {} : record(app.apk, 'application APK');
|
|
101
|
+
return { ...device, application: { ...app, apk: { ...apk, ...override } } };
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Validate the complete declarative tablet catalog before selecting one orchestrator server. */
|
|
106
|
+
export default function hmiPlan(serverId, document, policy) {
|
|
107
|
+
const catalog = record(document.hmi, 'catalog');
|
|
108
|
+
credentials(catalog);
|
|
109
|
+
const profiles = profilesFor(catalog.profiles);
|
|
110
|
+
const module = moduleFor(document.servers || [], serverId);
|
|
111
|
+
const machines = new Set(paths(document).filter((name) => { return name.split('/').length === 3; }).map((name) => { return name.split('/').at(-1); }));
|
|
112
|
+
const identifiers = new Set();
|
|
113
|
+
const references = new Set();
|
|
114
|
+
const devices = devicesFor(catalog);
|
|
115
|
+
devices.forEach((device) => {
|
|
116
|
+
binding(device, document, machines, profiles, policy);
|
|
117
|
+
unique(device.id, identifiers, 'device id');
|
|
118
|
+
if (Object.hasOwn(device, 'deviceRef')) { unique(device.deviceRef, references, 'device reference'); }
|
|
119
|
+
});
|
|
120
|
+
shared(devices);
|
|
121
|
+
return { server: serverId, namespace: module.namespace, profiles,
|
|
122
|
+
devices: devices.filter((device) => { return device.orchestrator.server === serverId; }) };
|
|
123
|
+
}
|
|
@@ -5,3 +5,6 @@ export { default as hmiMonitor, metrics } from './hmiMonitor.js';
|
|
|
5
5
|
export { default as hmiReconcile } from './hmiReconcile.js';
|
|
6
6
|
export { default as hmiRuntime } from './hmiRuntime.js';
|
|
7
7
|
export { default as mdmeshClient } from './mdmeshClient.js';
|
|
8
|
+
export { default as hmiPlan } from './hmiPlan.js';
|
|
9
|
+
export { default as mdmeshServerRelease } from './mdmeshServerRelease.js';
|
|
10
|
+
export { default as bootstrapMdmeshCredentials } from './bootstrapMdmeshCredentials.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import deploymentTemplate from '../deploy/deploymentTemplate.js';
|
|
2
|
+
|
|
3
|
+
function label(value, context) {
|
|
4
|
+
if (typeof value !== 'string' || value.length > 63 || !/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(value)) {
|
|
5
|
+
throw new Error(`Invalid HMI ${context}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function databaseSettings({ postgresNamespace, postgresHost }, namespace) {
|
|
10
|
+
label(postgresNamespace, 'database namespace');
|
|
11
|
+
const database = postgresHost?.split('.');
|
|
12
|
+
if (postgresNamespace === namespace || database?.length !== 5 || database[1] !== postgresNamespace || database.slice(2).join('.') !== 'svc.cluster.local') {
|
|
13
|
+
throw new Error('HMI database must use a cluster Service outside its namespace');
|
|
14
|
+
}
|
|
15
|
+
label(database[0], 'database service');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function authenticationSettings({ authentication }, { namespace, authenticationProvider }) {
|
|
19
|
+
if (authentication?.provider !== authenticationProvider || authentication.namespace === namespace) {
|
|
20
|
+
throw new Error('HMI authentication must remain outside the application namespace');
|
|
21
|
+
}
|
|
22
|
+
label(authentication.namespace, 'authentication namespace');
|
|
23
|
+
if (new URL(authentication.portalUrl).protocol !== 'https:') { throw new Error('HMI authentication requires HTTPS'); }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function imageSettings(values) {
|
|
27
|
+
for (const key of ['serverImage', 'webImage', 'supervisorImage']) {
|
|
28
|
+
if (typeof values[key] !== 'string' || !/@sha256:[a-f0-9]{64}$/u.test(values[key])) {
|
|
29
|
+
throw new Error(`HMI ${key} requires an immutable digest`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (values.publicConsole?.enabled && !/@sha256:[a-f0-9]{64}$/u.test(values.publicConsole.image || '')) {
|
|
33
|
+
throw new Error('HMI public console requires an immutable digest');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function settings(values, policy) {
|
|
38
|
+
const url = new URL(values.baseUrl);
|
|
39
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash || url.pathname !== '/') {
|
|
40
|
+
throw new Error('HMI orchestrator requires a public HTTPS origin');
|
|
41
|
+
}
|
|
42
|
+
imageSettings(values);
|
|
43
|
+
for (const key of ['secret', 'pullSecret']) { label(values[key], key); }
|
|
44
|
+
if (values.admin && (values.admin.login !== 'admin' || typeof values.admin.password !== 'string' || !values.admin.password.length)) {
|
|
45
|
+
throw new Error('Managed MDMesh administrator requires login admin and a nonempty password');
|
|
46
|
+
}
|
|
47
|
+
authenticationSettings(values, policy);
|
|
48
|
+
databaseSettings(values, policy.namespace);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Compile an isolated MDMesh release from the supplied catalog and service policy. */
|
|
52
|
+
export default function mdmeshServerRelease(target, catalog, values, policy) {
|
|
53
|
+
if (catalog.namespace !== policy.namespace) { throw new Error(`HMI workloads require their dedicated ${policy.namespace} namespace`); }
|
|
54
|
+
settings(values, policy);
|
|
55
|
+
return { context: target, namespace: catalog.namespace, release: deploymentTemplate(policy.release, { target }),
|
|
56
|
+
chart: policy.chart, fieldManager: policy.fieldManager,
|
|
57
|
+
values: { ...values, platformResources: false, catalog, planJSON: JSON.stringify(catalog) } };
|
|
58
|
+
}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/** AMQP 0-9-1 forwarder with persistent messages, supporting queues and exchanges. */
|
|
2
|
+
export function brokerShovel({ name, sourceUri, queue, destinationUri, exchange, destinationQueue, reconnectDelay, vhost = '/' }) {
|
|
3
|
+
return { vhost, component: 'shovel', name, value: {
|
|
4
|
+
'src-protocol': 'amqp091', 'src-uri': sourceUri, 'src-queue': queue,
|
|
5
|
+
'dest-protocol': 'amqp091', 'dest-uri': destinationUri,
|
|
6
|
+
...(destinationQueue === undefined ? { 'dest-exchange': exchange } : { 'dest-queue': destinationQueue }),
|
|
7
|
+
'reconnect-delay': reconnectDelay, 'dest-publish-properties': { delivery_mode: 2 }
|
|
8
|
+
} };
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/** Builds durable topic exchanges, queues and AMQP 0-9-1 outboxes for one virtual host. */
|
|
2
12
|
export default function rabbitmqDefinitions({ vhost, users = [], permissions = [], exchanges = [],
|
|
3
13
|
queues = [], bindings = [], outboxes = [] }) {
|
|
@@ -13,12 +23,8 @@ export default function rabbitmqDefinitions({ vhost, users = [], permissions = [
|
|
|
13
23
|
return { source, vhost, destination, destination_type: 'queue', routing_key: key, arguments: {} };
|
|
14
24
|
}),
|
|
15
25
|
parameters: outboxes.filter(({ shovel }) => { return shovel; }).map(({ queue, shovel }) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'dest-protocol': 'amqp091', 'dest-uri': shovel.destinationUri,
|
|
19
|
-
'dest-exchange': shovel.destinationExchange, 'reconnect-delay': shovel.reconnectDelay,
|
|
20
|
-
'dest-publish-properties': { delivery_mode: 2 }
|
|
21
|
-
} };
|
|
26
|
+
const { name, sourceUri, destinationUri, destinationExchange, reconnectDelay } = shovel;
|
|
27
|
+
return brokerShovel({ name, vhost, queue, sourceUri, destinationUri, exchange: destinationExchange, reconnectDelay });
|
|
22
28
|
})
|
|
23
29
|
};
|
|
24
30
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { validateConnections } from './config.js';
|
|
2
|
+
|
|
3
|
+
/** Selects sampling policy by stream path while the fan-in remains the source inventory. */
|
|
4
|
+
function timing(name, config) {
|
|
5
|
+
const match = (config.sampling || []).find((item) => {
|
|
6
|
+
const parts = item.name.split('/');
|
|
7
|
+
const path = name.split('/');
|
|
8
|
+
return parts.length === path.length && parts.every((part, index) => {
|
|
9
|
+
return part === '*' || part === path[index];
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
const healthRequired = match?.healthRequired === undefined ? true : match.healthRequired;
|
|
13
|
+
if (typeof healthRequired !== 'boolean') { throw new TypeError('OPC UA healthRequired must be boolean'); }
|
|
14
|
+
return { publishMs: match?.publishMs ?? config.publishMs, heartbeatMs: match?.heartbeatMs ?? config.heartbeatMs, healthRequired };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Groups DSL point mappings by physical endpoint; machine identity belongs to each channel. */
|
|
18
|
+
export default function projectOpcuaSources(rows, config, deviceFor) {
|
|
19
|
+
const connections = new Map();
|
|
20
|
+
rows.forEach((row) => {
|
|
21
|
+
const intervals = timing(row.name, config);
|
|
22
|
+
const connection = connections.get(row.from) || { url: row.from, ...intervals, channels: [] };
|
|
23
|
+
if (connection.publishMs !== intervals.publishMs || connection.heartbeatMs !== intervals.heartbeatMs || connection.healthRequired !== intervals.healthRequired) {
|
|
24
|
+
throw new Error(`incompatible OPC UA sampling policies at ${row.from}`);
|
|
25
|
+
}
|
|
26
|
+
if (!row.mapping || !Object.keys(row.mapping).length) {
|
|
27
|
+
throw new Error(`OPC UA stream ${row.name} requires a point mapping`);
|
|
28
|
+
}
|
|
29
|
+
const device = deviceFor(row);
|
|
30
|
+
connection.channels.push(...Object.entries(row.mapping).map(([key, nodeId]) => {
|
|
31
|
+
return { nodeId, key, device };
|
|
32
|
+
}));
|
|
33
|
+
connections.set(row.from, connection);
|
|
34
|
+
});
|
|
35
|
+
return validateConnections([...connections.values()]);
|
|
36
|
+
}
|