@aifabrix/builder 2.45.0 → 2.46.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/.cursor/rules/cli-layout.mdc +2 -0
- package/.cursor/rules/cli-product-neutral.mdc +43 -0
- package/.cursor/rules/docs-rules.mdc +3 -1
- package/.cursor/rules/project-rules.mdc +1 -0
- package/README.md +43 -17
- package/integration/hubspot-test/wizard-hubspot-e2e.yaml +1 -1
- package/jest.config.default.js +2 -1
- package/jest.config.isolated.js +2 -1
- package/jest.global-live-fabrix-hooks.js +36 -0
- package/jest.isolated-projects.js +130 -0
- package/jest.projects.js +69 -121
- package/lib/api/agent-metadata-validation.api.js +93 -0
- package/lib/api/api-response-errors.js +124 -0
- package/lib/api/audit-api-helpers.js +68 -0
- package/lib/api/audit.api.js +119 -0
- package/lib/api/auth-cache.api.js +44 -0
- package/lib/api/certificates.api.js +4 -4
- package/lib/api/credential.api.js +2 -2
- package/lib/api/dataplane-health.api.js +137 -0
- package/lib/api/dataplane-sync.api.js +27 -0
- package/lib/api/datasources-core.api.js +21 -18
- package/lib/api/datasources-extended.api.js +22 -22
- package/lib/api/dimensions.api.js +3 -0
- package/lib/api/external-systems.api.js +13 -13
- package/lib/api/governance-scenario-pack.api.js +159 -0
- package/lib/api/governance-scenarios.api.js +39 -0
- package/lib/api/groups.api.js +79 -0
- package/lib/api/index.js +88 -5
- package/lib/api/lifecycle.api.js +77 -0
- package/lib/api/pipeline.api.js +7 -5
- package/lib/api/protection.api.js +157 -0
- package/lib/api/records-bulk.api.js +43 -0
- package/lib/api/records-search-parse.js +49 -0
- package/lib/api/records-search.api.js +29 -0
- package/lib/api/types/agent-metadata-validation.types.js +67 -0
- package/lib/api/types/audit.types.js +72 -0
- package/lib/api/types/dataplane-health.types.js +27 -0
- package/lib/api/types/dimensions.types.js +2 -0
- package/lib/api/types/governance-scenarios.types.js +39 -0
- package/lib/api/types/protection.types.js +69 -0
- package/lib/api/types/records-bulk.types.js +35 -0
- package/lib/api/types/records-search.types.js +28 -0
- package/lib/api/user-groups.api.js +50 -0
- package/lib/api/users.api.js +95 -0
- package/lib/api/validation-run.api.js +3 -3
- package/lib/api/validation-runner.js +5 -3
- package/lib/api/wizard-platform.api.js +3 -3
- package/lib/api/wizard.api.js +21 -21
- package/lib/app/deploy-config.js +4 -1
- package/lib/app/deploy.js +34 -19
- package/lib/app/down.js +20 -1
- package/lib/app/push.js +4 -5
- package/lib/app/register.js +7 -4
- package/lib/app/run-env-compose.js +84 -30
- package/lib/build/index.js +5 -0
- package/lib/certification/sync-system-certification.js +13 -6
- package/lib/cli/index.js +8 -2
- package/lib/cli/infra-guided-auth.js +109 -0
- package/lib/cli/infra-guided.js +91 -69
- package/lib/cli/setup-app.help.js +19 -2
- package/lib/cli/setup-app.js +58 -23
- package/lib/cli/setup-app.test-commands.js +28 -21
- package/lib/cli/setup-auth.js +55 -3
- package/lib/cli/setup-certification-commands.js +147 -0
- package/lib/cli/setup-certification.help.js +141 -0
- package/lib/cli/setup-environment.js +19 -2
- package/lib/cli/setup-external-system-help.js +62 -0
- package/lib/cli/setup-external-system.js +62 -6
- package/lib/cli/setup-infra.js +9 -1
- package/lib/cli/setup-platform.js +6 -1
- package/lib/cli/setup-secrets.js +33 -1
- package/lib/cli/setup-utility-help-after.js +65 -0
- package/lib/cli/setup-utility-repair.js +198 -0
- package/lib/cli/setup-utility-resolve.js +42 -6
- package/lib/cli/setup-utility-validate.js +197 -0
- package/lib/cli/setup-utility.js +41 -258
- package/lib/commands/auth-status-client-tokens.js +214 -0
- package/lib/commands/auth-status-dataplane-version.js +269 -0
- package/lib/commands/auth-status-display.js +94 -0
- package/lib/commands/auth-status.js +111 -53
- package/lib/commands/credential-push.js +10 -5
- package/lib/commands/datasource-load-export-cli.js +178 -0
- package/lib/commands/datasource-test-trust-cli.js +118 -0
- package/lib/commands/datasource-unified-test-cli.js +31 -20
- package/lib/commands/datasource-unified-test-cli.options.js +22 -3
- package/lib/commands/datasource-unified-test-e2e-cli-helpers.js +5 -5
- package/lib/commands/datasource-verify-audit-cli.js +96 -0
- package/lib/commands/datasource.js +68 -1
- package/lib/commands/dev-show-display.js +8 -1
- package/lib/commands/dimension-value.js +43 -13
- package/lib/commands/dimension.js +38 -7
- package/lib/commands/governance-cli-shared.js +94 -0
- package/lib/commands/governance-command-action.js +132 -0
- package/lib/commands/governance-download-external.js +34 -0
- package/lib/commands/governance-generate-external.js +71 -0
- package/lib/commands/governance-upload-external.js +36 -0
- package/lib/commands/governance-verify-external.js +64 -0
- package/lib/commands/governance.js +144 -0
- package/lib/commands/identity-apply-sync.js +131 -0
- package/lib/commands/identity-group-cli.js +146 -0
- package/lib/commands/identity-membership-role-cache.js +175 -0
- package/lib/commands/identity-shared.js +94 -0
- package/lib/commands/identity-user-cli.js +158 -0
- package/lib/commands/identity.js +43 -0
- package/lib/commands/lifecycle-command-action.js +123 -0
- package/lib/commands/lifecycle-external.js +268 -0
- package/lib/commands/login.js +56 -17
- package/lib/commands/protection-cli-leaves.js +286 -0
- package/lib/commands/protection.js +50 -0
- package/lib/commands/repair-auth-apply.js +127 -0
- package/lib/commands/repair-changed-files.js +41 -0
- package/lib/commands/repair-datasource-keys.js +4 -1
- package/lib/commands/repair-datasource-run.js +59 -0
- package/lib/commands/repair-datasource-test-payload.js +259 -0
- package/lib/commands/repair-datasource.js +1 -51
- package/lib/commands/repair-env-template.js +64 -13
- package/lib/commands/repair-external-run.js +216 -0
- package/lib/commands/repair-openapi-sync.js +23 -0
- package/lib/commands/repair-persist.js +4 -0
- package/lib/commands/repair-rbac.js +52 -1
- package/lib/commands/repair-steps.js +145 -0
- package/lib/commands/repair.js +29 -286
- package/lib/commands/secrets-get.js +184 -0
- package/lib/commands/secrets-remove-all.js +3 -1
- package/lib/commands/setup-image-refresh.js +146 -0
- package/lib/commands/setup-modes.js +158 -162
- package/lib/commands/setup-platform-auth.js +76 -0
- package/lib/commands/setup-prompts-admin.js +244 -0
- package/lib/commands/setup-prompts-platform-mode.js +67 -0
- package/lib/commands/setup-prompts-validators.js +36 -0
- package/lib/commands/setup-prompts.js +24 -76
- package/lib/commands/setup-run-context.js +45 -0
- package/lib/commands/setup-spinners.js +39 -0
- package/lib/commands/setup.js +27 -5
- package/lib/commands/teardown.js +39 -0
- package/lib/commands/test-e2e-external.js +61 -14
- package/lib/commands/test-governance-cli-options.js +47 -0
- package/lib/commands/test-governance-external.js +67 -0
- package/lib/commands/test-trust-cli-options.js +32 -0
- package/lib/commands/test-trust-external.js +126 -0
- package/lib/commands/up-common.js +25 -13
- package/lib/commands/up-dataplane.js +50 -13
- package/lib/commands/upload-publish-context.js +75 -0
- package/lib/commands/upload-sidecar-followups.js +89 -0
- package/lib/commands/upload.js +108 -105
- package/lib/commands/verify-governance-combined-external.js +61 -0
- package/lib/commands/verify-governance-command-action.js +64 -0
- package/lib/commands/verify-governance-db.js +102 -0
- package/lib/commands/verify-governance-external.js +77 -0
- package/lib/commands/verify-governance-result-builders.js +71 -0
- package/lib/commands/verify-operations-command-action.js +68 -0
- package/lib/commands/verify-operations-external.js +268 -0
- package/lib/commands/verify-operations-persist.js +75 -0
- package/lib/commands/verify-operations-step-plan.js +68 -0
- package/lib/commands/verify-operations-steps.js +111 -0
- package/lib/commands/verify-trust-command-action.js +70 -0
- package/lib/commands/verify-trust-external.js +67 -0
- package/lib/commands/wizard-config-normalizer.js +43 -23
- package/lib/commands/wizard-core.js +5 -0
- package/lib/core/admin-password-generator.js +38 -0
- package/lib/core/admin-secrets-bundle.js +111 -0
- package/lib/core/admin-secrets-env-overlay.js +62 -0
- package/lib/core/admin-secrets.js +32 -4
- package/lib/core/config-attach-extensions.js +3 -0
- package/lib/core/config-device-dataplane.js +185 -0
- package/lib/core/config-platform-controller.js +44 -0
- package/lib/core/config-setup-installation-profile.js +42 -0
- package/lib/core/config-setup-platform-mode.js +46 -0
- package/lib/core/config.js +46 -36
- package/lib/core/secrets-admin-env.js +6 -2
- package/lib/core/secrets-ensure.js +4 -0
- package/lib/core/secrets-env-content.js +54 -48
- package/lib/core/secrets-env-write.js +10 -1
- package/lib/core/secrets-infra-placeholder-sync.js +2 -0
- package/lib/core/setup-installation-profile.js +43 -0
- package/lib/core/setup-platform-mode.js +55 -0
- package/lib/datasource/agent-trust-debug-log.js +45 -0
- package/lib/datasource/agent-trust-fetch.js +115 -0
- package/lib/datasource/agent-trust-map.js +101 -0
- package/lib/datasource/agent-trust-mock.js +44 -0
- package/lib/datasource/agent-trust-run.js +95 -0
- package/lib/datasource/agent-trust-timeout.js +25 -0
- package/lib/datasource/audit-evidence-display.js +80 -0
- package/lib/datasource/audit-evidence-extract-debug.js +115 -0
- package/lib/datasource/audit-evidence-extract.js +180 -0
- package/lib/datasource/audit-evidence-matrix-rows.js +158 -0
- package/lib/datasource/audit-evidence-operation-aliases.js +63 -0
- package/lib/datasource/audit-evidence-poll.js +109 -0
- package/lib/datasource/audit-evidence-run.js +177 -0
- package/lib/datasource/audit-evidence-verify-helpers.js +167 -0
- package/lib/datasource/audit-evidence-verify-matrix.js +205 -0
- package/lib/datasource/audit-evidence-verify.js +108 -0
- package/lib/datasource/bulk-loader-run-batches.js +100 -0
- package/lib/datasource/bulk-loader-service-retry.js +52 -0
- package/lib/datasource/bulk-loader-service.js +127 -0
- package/lib/datasource/capability/run-capability-dimension.js +2 -1
- package/lib/datasource/datasource-exporter-resolve.js +82 -0
- package/lib/datasource/datasource-exporter-service.js +144 -0
- package/lib/datasource/datasource-identifier.js +148 -0
- package/lib/datasource/datasource-load-export-context.js +95 -0
- package/lib/datasource/integration-context.js +6 -4
- package/lib/datasource/local-data-paths.js +145 -0
- package/lib/datasource/log-cleaner.js +241 -0
- package/lib/datasource/log-viewer.js +111 -6
- package/lib/datasource/record-file-parser.js +85 -0
- package/lib/datasource/record-mapper.js +129 -0
- package/lib/datasource/resolve-app.js +74 -55
- package/lib/datasource/test-e2e.js +29 -2
- package/lib/datasource/unified-validation-run-body.js +3 -1
- package/lib/datasource/unified-validation-run-resolve.js +45 -12
- package/lib/datasource/unified-validation-run.js +47 -18
- package/lib/datasource/validate.js +37 -20
- package/lib/deployment/environment-poll-status.js +138 -0
- package/lib/deployment/environment.js +42 -34
- package/lib/external-system/download.js +21 -20
- package/lib/external-system/generator.js +5 -1
- package/lib/external-system/integration-auth-context.js +45 -0
- package/lib/external-system/test-auth.js +12 -5
- package/lib/external-system/test-system-level.js +25 -4
- package/lib/external-system/test.js +9 -7
- package/lib/generator/external-controller-manifest.js +15 -0
- package/lib/governance/governance-cli-errors.js +96 -0
- package/lib/governance/governance-download-display.js +38 -0
- package/lib/governance/governance-pack-loader.js +70 -0
- package/lib/governance/governance-run-display.js +309 -0
- package/lib/identity/identity-apply-core.js +108 -0
- package/lib/identity/identity-apply-phases.js +244 -0
- package/lib/identity/identity-apply-service.js +77 -0
- package/lib/identity/identity-csv-parser.js +114 -0
- package/lib/infrastructure/admin-secrets-apply.js +84 -0
- package/lib/infrastructure/admin-secrets-ensure.js +130 -0
- package/lib/infrastructure/admin-secrets-resolve.js +95 -0
- package/lib/infrastructure/admin-secrets-sync.js +91 -0
- package/lib/infrastructure/helpers.js +23 -129
- package/lib/infrastructure/index.js +5 -6
- package/lib/infrastructure/orphan-infra-docker-teardown.js +11 -5
- package/lib/internal/fs-real-sync.js +29 -1
- package/lib/lifecycle/certification-progress.js +231 -0
- package/lib/lifecycle/dataplane-ui-url.js +145 -0
- package/lib/lifecycle/exit-codes.js +24 -0
- package/lib/lifecycle/json-envelope.js +25 -0
- package/lib/lifecycle/lifecycle-governance-options.js +51 -0
- package/lib/lifecycle/logger-quiet.js +29 -0
- package/lib/lifecycle/open-api-published.js +59 -0
- package/lib/lifecycle/operations-readiness-metrics.js +101 -0
- package/lib/lifecycle/product-model.js +196 -0
- package/lib/lifecycle/report-display.js +471 -0
- package/lib/lifecycle/scenario-upload.js +191 -0
- package/lib/lifecycle/verify-step-progress.js +87 -0
- package/lib/parameters/infra-kv-discovery.js +27 -2
- package/lib/protection/auth-context.js +51 -0
- package/lib/protection/convert-batch.js +90 -0
- package/lib/protection/load.js +41 -0
- package/lib/protection/paths.js +158 -0
- package/lib/protection/preflight-datasource-ready.js +46 -0
- package/lib/protection/protection-create-probe-lines.js +142 -0
- package/lib/protection/protection-create-probes.js +95 -0
- package/lib/protection/protection-create-scaffold.js +281 -0
- package/lib/protection/protection-display-helpers.js +445 -0
- package/lib/protection/protection-display.js +215 -0
- package/lib/protection/protection-preset-registry.js +97 -0
- package/lib/protection/report-exit.js +62 -0
- package/lib/protection/resolve.js +202 -0
- package/lib/protection/run-commands-validate.js +130 -0
- package/lib/protection/run-commands.js +216 -0
- package/lib/protection/run-protection-create-helpers.js +134 -0
- package/lib/protection/run-protection-create-probes-flow.js +43 -0
- package/lib/protection/run-protection-create.js +191 -0
- package/lib/protection/scope.js +22 -0
- package/lib/protection/sync-after-upload.js +64 -0
- package/lib/protection/upload-batch.js +127 -0
- package/lib/protection/validate-batch.js +113 -0
- package/lib/protection/validate-local.js +65 -0
- package/lib/resolvers/dimension-file.js +29 -4
- package/lib/schema/application-schema.json +1 -1
- package/lib/schema/datasource-test-run.schema.json +89 -6
- package/lib/schema/external-datasource.schema.json +2636 -2588
- package/lib/schema/external-system.schema.json +1089 -761
- package/lib/schema/flag-map-validation-run.json +2 -2
- package/lib/schema/infra.parameter.yaml +45 -0
- package/lib/schema/protection.schema.json +374 -0
- package/lib/schema/type/credential-field-registry.json +642 -0
- package/lib/schema/wizard-config.schema.json +1 -1
- package/lib/utils/agent-trust-run-display.js +231 -0
- package/lib/utils/agent-trust-run-exit.js +59 -0
- package/lib/utils/agent-trust-wait-ui.js +94 -0
- package/lib/utils/aifabrix-test-runtime-guard.js +125 -0
- package/lib/utils/api.js +55 -31
- package/lib/utils/app-relative-path-env.js +112 -0
- package/lib/utils/cli-exit-codes.js +30 -0
- package/lib/utils/cli-secrets-error-format.js +83 -21
- package/lib/utils/cli-sync-options.js +33 -0
- package/lib/utils/cli-utils.js +16 -4
- package/lib/utils/compose-generate-docker-compose.js +4 -0
- package/lib/utils/compose-traefik-ingress-base.js +16 -1
- package/lib/utils/config-secrets-path.js +46 -0
- package/lib/utils/controller-url.js +88 -1
- package/lib/utils/credential-push-ui.js +90 -0
- package/lib/utils/credential-secrets-env.js +137 -9
- package/lib/utils/dataplane-cli-version-gate.js +202 -0
- package/lib/utils/dataplane-cli-version-help.js +74 -0
- package/lib/utils/dataplane-resolver.js +129 -2
- package/lib/utils/datasource-export-display.js +137 -0
- package/lib/utils/datasource-load-display.js +174 -0
- package/lib/utils/datasource-load-export-ui.js +120 -0
- package/lib/utils/datasource-test-run-capability-scope.js +3 -3
- package/lib/utils/datasource-test-run-display.js +3 -3
- package/lib/utils/datasource-test-run-tty-log.js +5 -1
- package/lib/utils/declarative-url-ports.js +3 -3
- package/lib/utils/deployment-auth-mode.js +41 -0
- package/lib/utils/developer-volume-id.js +33 -0
- package/lib/utils/env-copy.js +14 -9
- package/lib/utils/env-kv-orphan-lines.js +43 -0
- package/lib/utils/error-formatters/network-errors.js +13 -4
- package/lib/utils/external-env-template.js +1 -0
- package/lib/utils/external-system-readiness-core.js +10 -0
- package/lib/utils/external-system-readiness-display.js +80 -23
- package/lib/utils/health-check.js +4 -1
- package/lib/utils/help-builder.js +35 -26
- package/lib/utils/keycloak-realm-ready.js +101 -0
- package/lib/utils/load-cip-capacity-display-config.js +61 -15
- package/lib/utils/manifest-source-emit.js +24 -0
- package/lib/utils/pipeline-upload-auth-retry.js +82 -0
- package/lib/utils/platform-controller-url.js +156 -0
- package/lib/utils/postgres-platform-bootstrap.js +199 -0
- package/lib/utils/postgres-wipe.js +9 -2
- package/lib/utils/resolve-env-mode.js +47 -0
- package/lib/utils/secrets-generator.js +31 -25
- package/lib/utils/secrets-missing-error.js +164 -0
- package/lib/utils/semver-compare.js +127 -0
- package/lib/utils/service-url-label.js +81 -0
- package/lib/utils/setup-quiet-output.js +25 -0
- package/lib/utils/template-helpers.js +15 -0
- package/lib/utils/token-manager-client-credentials.js +201 -0
- package/lib/utils/token-manager-messages.js +8 -0
- package/lib/utils/token-manager-refresh.js +12 -2
- package/lib/utils/token-manager.js +86 -105
- package/lib/utils/upload-pipeline-ui.js +98 -0
- package/lib/utils/upload-sync-options.js +42 -0
- package/lib/utils/url-declarative-public-base.js +21 -3
- package/lib/utils/url-declarative-vdir-inactive-env.js +14 -4
- package/lib/utils/validation-poll-ui.js +22 -7
- package/lib/utils/validation-run-stage.js +45 -0
- package/lib/validation/wizard-config-validator.js +58 -19
- package/package.json +1 -1
- package/templates/applications/dataplane/application.yaml +2 -1
- package/templates/applications/dataplane/env.template +36 -1
- package/templates/applications/dataplane/rbac.yaml +4 -0
- package/templates/applications/miso-controller/env.template +16 -0
- package/templates/external-system/README.md.hbs +116 -11
- package/templates/python/docker-compose.hbs +19 -18
- package/templates/typescript/docker-compose.hbs +18 -17
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Run dataplane agent metadata validation for one datasource (404.5 / plan 143).
|
|
3
|
+
* @author AI Fabrix Team
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const chalk = require('chalk');
|
|
10
|
+
const logger = require('../utils/logger');
|
|
11
|
+
const { formatSuccessLine } = require('../utils/cli-test-layout-chalk');
|
|
12
|
+
const { getConfig } = require('../core/config');
|
|
13
|
+
const { setupIntegrationTestAuth } = require('../external-system/test-auth');
|
|
14
|
+
const { resolveAppKeyForDatasource } = require('./resolve-app');
|
|
15
|
+
const { getSystemKeyFromAppKey } = require('./integration-context');
|
|
16
|
+
const { requireBearerForDataplanePipeline } = require('../utils/token-manager');
|
|
17
|
+
const { buildMinimalUploadSyncOptions } = require('../utils/upload-sync-options');
|
|
18
|
+
const { fetchTrustRunFromDataplane } = require('./agent-trust-fetch');
|
|
19
|
+
|
|
20
|
+
async function maybeSyncBeforeTrust({ noSync, authConfig, systemKey, options = {} }) {
|
|
21
|
+
if (noSync === true) return;
|
|
22
|
+
requireBearerForDataplanePipeline(authConfig);
|
|
23
|
+
logger.log(chalk.cyan('Syncing local config to dataplane…'));
|
|
24
|
+
const { uploadExternalSystem } = require('../commands/upload');
|
|
25
|
+
await uploadExternalSystem(systemKey, buildMinimalUploadSyncOptions(options));
|
|
26
|
+
logger.log(formatSuccessLine('Sync complete'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function buildTransportFailureTrustRun(datasourceKey, systemKey, err) {
|
|
30
|
+
return {
|
|
31
|
+
datasourceKey,
|
|
32
|
+
systemKey,
|
|
33
|
+
status: 'fail',
|
|
34
|
+
trustDecision: 'notTrusted',
|
|
35
|
+
validationStatus: 'failed',
|
|
36
|
+
confidence: 0,
|
|
37
|
+
summary: err && err.message ? String(err.message) : 'Request failed',
|
|
38
|
+
transportError: true
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @async
|
|
44
|
+
* @param {string} datasourceKey
|
|
45
|
+
* @param {Object} options
|
|
46
|
+
* @returns {Promise<{ trustRun: Object, apiError: Object|null }>}
|
|
47
|
+
*/
|
|
48
|
+
async function runDatasourceAgentTrust(datasourceKey, options = {}) {
|
|
49
|
+
if (!datasourceKey || typeof datasourceKey !== 'string') {
|
|
50
|
+
throw new Error('Datasource key is required');
|
|
51
|
+
}
|
|
52
|
+
const { appKey } = await resolveAppKeyForDatasource(datasourceKey, options.app);
|
|
53
|
+
const systemKey = await getSystemKeyFromAppKey(appKey);
|
|
54
|
+
|
|
55
|
+
let authConfig = options.authConfig;
|
|
56
|
+
let dataplaneUrl = options.dataplaneUrl || options.dataplane;
|
|
57
|
+
if (!authConfig || !dataplaneUrl) {
|
|
58
|
+
const configObj = await getConfig();
|
|
59
|
+
const auth = await setupIntegrationTestAuth(
|
|
60
|
+
appKey,
|
|
61
|
+
{ environment: options.environment, dataplane: options.dataplane },
|
|
62
|
+
configObj
|
|
63
|
+
);
|
|
64
|
+
authConfig = auth.authConfig;
|
|
65
|
+
dataplaneUrl = auth.dataplaneUrl;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await maybeSyncBeforeTrust({
|
|
69
|
+
noSync: options.noSync === true,
|
|
70
|
+
authConfig,
|
|
71
|
+
systemKey,
|
|
72
|
+
options
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const trustRun = await fetchTrustRunFromDataplane({
|
|
77
|
+
datasourceKey,
|
|
78
|
+
systemKey,
|
|
79
|
+
dataplaneUrl,
|
|
80
|
+
authConfig,
|
|
81
|
+
options
|
|
82
|
+
});
|
|
83
|
+
return { trustRun, apiError: null };
|
|
84
|
+
} catch (err) {
|
|
85
|
+
return {
|
|
86
|
+
trustRun: buildTransportFailureTrustRun(datasourceKey, systemKey, err),
|
|
87
|
+
apiError: err
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
runDatasourceAgentTrust,
|
|
94
|
+
maybeSyncBeforeTrust
|
|
95
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTTP timeout parsing for agent trust CLI (plan 143).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_TRUST_TIMEOUT_MS = 120000;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Object} [options]
|
|
11
|
+
* @returns {number}
|
|
12
|
+
*/
|
|
13
|
+
function parseTrustTimeoutMs(options = {}) {
|
|
14
|
+
const raw = options.timeout;
|
|
15
|
+
if (raw !== undefined && raw !== null && raw !== '') {
|
|
16
|
+
const n = parseInt(String(raw), 10);
|
|
17
|
+
if (Number.isFinite(n) && n > 0) return n;
|
|
18
|
+
}
|
|
19
|
+
return DEFAULT_TRUST_TIMEOUT_MS;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
DEFAULT_TRUST_TIMEOUT_MS,
|
|
24
|
+
parseTrustTimeoutMs
|
|
25
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview TTY and JSON output for audit evidence verification (407.3)
|
|
3
|
+
* @author AI Fabrix Team
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const chalk = require('chalk');
|
|
10
|
+
const logger = require('../utils/logger');
|
|
11
|
+
const {
|
|
12
|
+
sectionTitle,
|
|
13
|
+
formatSuccessLine,
|
|
14
|
+
formatBlockingError,
|
|
15
|
+
successGlyph,
|
|
16
|
+
failureGlyph
|
|
17
|
+
} = require('../utils/cli-test-layout-chalk');
|
|
18
|
+
|
|
19
|
+
const SEP = '────────────────────────────────';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {'passed'|'failed'} status
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
function rowGlyph(status) {
|
|
26
|
+
return status === 'passed' ? successGlyph() : failureGlyph();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {import('../api/types/audit.types').AuditEvidenceVerification} result
|
|
31
|
+
* @param {boolean} [verbose]
|
|
32
|
+
*/
|
|
33
|
+
function displayAuditEvidenceMatrixTTY(result, verbose = false) {
|
|
34
|
+
logger.log(SEP);
|
|
35
|
+
logger.log(sectionTitle('Audit evidence matrix'));
|
|
36
|
+
logger.log(chalk.gray(` Datasource: ${result.datasourceKey}`));
|
|
37
|
+
if (result.correlationId) {
|
|
38
|
+
logger.log(chalk.gray(` Correlation: ${result.correlationId}`));
|
|
39
|
+
}
|
|
40
|
+
if (verbose && result.executionIds.length) {
|
|
41
|
+
logger.log(chalk.gray(` Execution ids: ${result.executionIds.length}`));
|
|
42
|
+
}
|
|
43
|
+
logger.log('');
|
|
44
|
+
for (const row of result.matrix || []) {
|
|
45
|
+
logger.log(` ${rowGlyph(row.status)} Row ${row.row}: ${row.detail}`);
|
|
46
|
+
if (verbose && row.code) {
|
|
47
|
+
logger.log(chalk.gray(` code: ${row.code}`));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
logger.log('');
|
|
51
|
+
if (result.status === 'passed') {
|
|
52
|
+
logger.log(formatSuccessLine('Audit evidence verification passed'));
|
|
53
|
+
} else {
|
|
54
|
+
const failed = (result.matrix || []).filter(r => r.status === 'failed').length;
|
|
55
|
+
logger.log(formatBlockingError(`Audit evidence verification failed (${failed} row(s))`));
|
|
56
|
+
}
|
|
57
|
+
logger.log(SEP);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {import('../api/types/audit.types').AuditEvidenceVerification} result
|
|
62
|
+
*/
|
|
63
|
+
function printAuditEvidenceVerificationJson(result) {
|
|
64
|
+
logger.log(
|
|
65
|
+
JSON.stringify({
|
|
66
|
+
auditEvidenceVerification: {
|
|
67
|
+
status: result.status,
|
|
68
|
+
datasourceKey: result.datasourceKey,
|
|
69
|
+
correlationId: result.correlationId,
|
|
70
|
+
executionIds: result.executionIds,
|
|
71
|
+
matrix: result.matrix
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = {
|
|
78
|
+
displayAuditEvidenceMatrixTTY,
|
|
79
|
+
printAuditEvidenceVerificationJson
|
|
80
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Extract execution ids from DatasourceTestRun debug / async E2E payloads
|
|
3
|
+
* @author AI Fabrix Team
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const { parseCapacityDetailKey } = require('../utils/load-cip-capacity-display-config');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {Array<*>} ids
|
|
13
|
+
* @returns {string[]}
|
|
14
|
+
*/
|
|
15
|
+
function dedupeIds(ids) {
|
|
16
|
+
if (!Array.isArray(ids)) return [];
|
|
17
|
+
const out = [];
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
for (const raw of ids) {
|
|
20
|
+
const id = raw !== null && raw !== undefined ? String(raw).trim() : '';
|
|
21
|
+
if (!id || seen.has(id)) continue;
|
|
22
|
+
seen.add(id);
|
|
23
|
+
out.push(id);
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {*} node
|
|
30
|
+
* @param {string[]} out
|
|
31
|
+
*/
|
|
32
|
+
function collectExecutionIdFields(node, out) {
|
|
33
|
+
if (!node || typeof node !== 'object') return;
|
|
34
|
+
if (typeof node.executionId === 'string' && node.executionId.trim()) {
|
|
35
|
+
out.push(node.executionId.trim());
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(node.jobs)) {
|
|
38
|
+
for (const job of node.jobs) collectExecutionIdFields(job, out);
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(node.datasources)) {
|
|
41
|
+
for (const ds of node.datasources) collectExecutionIdFields(ds, out);
|
|
42
|
+
}
|
|
43
|
+
if (node.audit && typeof node.audit === 'object') {
|
|
44
|
+
collectExecutionIdFields(node.audit, out);
|
|
45
|
+
}
|
|
46
|
+
if (node.evidence && typeof node.evidence === 'object') {
|
|
47
|
+
collectExecutionIdFields(node.evidence, out);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {Object|null|undefined} envelope
|
|
53
|
+
* @returns {string[]}
|
|
54
|
+
*/
|
|
55
|
+
function executionIdsFromDebugEnvelope(envelope) {
|
|
56
|
+
const dbg = envelope && envelope.debug;
|
|
57
|
+
if (!dbg || typeof dbg !== 'object') return [];
|
|
58
|
+
const found = [];
|
|
59
|
+
if (dbg.executionIds) {
|
|
60
|
+
found.push(...(Array.isArray(dbg.executionIds) ? dbg.executionIds : [dbg.executionIds]));
|
|
61
|
+
}
|
|
62
|
+
const asyncDbg = dbg.e2eAsyncDebug;
|
|
63
|
+
if (asyncDbg && Array.isArray(asyncDbg.stepDebug)) {
|
|
64
|
+
for (const step of asyncDbg.stepDebug) {
|
|
65
|
+
if (step && step.evidence) collectExecutionIdFields(step.evidence, found);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return dedupeIds(found);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {Object|null|undefined} envelope
|
|
73
|
+
* @returns {Object|null}
|
|
74
|
+
*/
|
|
75
|
+
function getCapacityStepFromEnvelope(envelope) {
|
|
76
|
+
const asyncDbg = envelope && envelope.debug && envelope.debug.e2eAsyncDebug;
|
|
77
|
+
if (!asyncDbg || !Array.isArray(asyncDbg.stepDebug)) return null;
|
|
78
|
+
return asyncDbg.stepDebug.find(s => s && s.name === 'capacity') || null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Operation names from CIP capacity evidence keys (`capacity:<op>#<index>`), without product aliases.
|
|
83
|
+
* @param {*} details
|
|
84
|
+
* @returns {Set<string>}
|
|
85
|
+
*/
|
|
86
|
+
function collectCipOpsFromCapabilityDetails(details) {
|
|
87
|
+
const ops = new Set();
|
|
88
|
+
if (!Array.isArray(details)) return ops;
|
|
89
|
+
for (const ds of details) {
|
|
90
|
+
if (!ds || !Array.isArray(ds.capabilityDetails)) continue;
|
|
91
|
+
for (const item of ds.capabilityDetails) {
|
|
92
|
+
const parsed = parseCapacityDetailKey(item && item.key);
|
|
93
|
+
if (parsed && parsed.op) ops.add(parsed.op);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return ops;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* CIP operation names from capacity step (insert, update, list, …).
|
|
101
|
+
* @param {Object|null|undefined} envelope
|
|
102
|
+
* @returns {string[]}
|
|
103
|
+
*/
|
|
104
|
+
function cipOperationsFromDebugEnvelope(envelope) {
|
|
105
|
+
const capStep = getCapacityStepFromEnvelope(envelope);
|
|
106
|
+
if (!capStep || !capStep.evidence) return [];
|
|
107
|
+
return [...collectCipOpsFromCapabilityDetails(capStep.evidence.datasources)];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = {
|
|
111
|
+
dedupeIds,
|
|
112
|
+
executionIdsFromDebugEnvelope,
|
|
113
|
+
cipOperationsFromDebugEnvelope,
|
|
114
|
+
collectExecutionIdFields
|
|
115
|
+
};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Extract audit evidence inputs from DatasourceTestRun envelope or debug log
|
|
3
|
+
* @author AI Fabrix Team
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fsp = require('node:fs').promises;
|
|
11
|
+
const { getIntegrationPath } = require('../utils/paths');
|
|
12
|
+
const { resolveAppKeyForDatasource } = require('./resolve-app');
|
|
13
|
+
const { getLatestLogPath } = require('./log-viewer');
|
|
14
|
+
const {
|
|
15
|
+
executionIdsFromDebugEnvelope,
|
|
16
|
+
cipOperationsFromDebugEnvelope,
|
|
17
|
+
dedupeIds: dedupeIdsFromDebug
|
|
18
|
+
} = require('./audit-evidence-extract-debug');
|
|
19
|
+
const loadCipCapacityDisplayConfig = require('../utils/load-cip-capacity-display-config');
|
|
20
|
+
|
|
21
|
+
/** @param {Array<*>} ids @returns {string[]} */
|
|
22
|
+
function dedupeIds(ids) {
|
|
23
|
+
return dedupeIdsFromDebug(ids);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {Object|null|undefined} envelope
|
|
28
|
+
* @returns {string[]}
|
|
29
|
+
*/
|
|
30
|
+
function executionIdsFromEnvelope(envelope) {
|
|
31
|
+
const audit = envelope && envelope.audit;
|
|
32
|
+
const merged = [
|
|
33
|
+
...(audit && audit.executionIds ? audit.executionIds : []),
|
|
34
|
+
...executionIdsFromDebugEnvelope(envelope)
|
|
35
|
+
];
|
|
36
|
+
return dedupeIds(merged);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* E2E uses testRunId as CipExecution.correlationId (see external_data_e2e_helpers).
|
|
41
|
+
* @param {Object|null|undefined} envelope
|
|
42
|
+
* @returns {string|null}
|
|
43
|
+
*/
|
|
44
|
+
function correlationIdFromAsyncDebug(envelope) {
|
|
45
|
+
const dbg = envelope && envelope.debug;
|
|
46
|
+
const asyncDbg = dbg && dbg.e2eAsyncDebug;
|
|
47
|
+
if (!asyncDbg || typeof asyncDbg !== 'object') return null;
|
|
48
|
+
const requestId =
|
|
49
|
+
asyncDbg.requestId !== undefined && asyncDbg.requestId !== null
|
|
50
|
+
? String(asyncDbg.requestId).trim()
|
|
51
|
+
: '';
|
|
52
|
+
if (requestId) return requestId;
|
|
53
|
+
const nested =
|
|
54
|
+
asyncDbg.testRunId !== undefined && asyncDbg.testRunId !== null
|
|
55
|
+
? String(asyncDbg.testRunId).trim()
|
|
56
|
+
: '';
|
|
57
|
+
return nested || null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Ephemeral envelope runId (run-*) is not stored as CipExecution.correlationId.
|
|
62
|
+
* @param {string} runId
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
function isEphemeralEnvelopeRunId(runId) {
|
|
66
|
+
return /^run-[a-f0-9]{12}$/i.test(runId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function correlationIdFromEnvelope(envelope) {
|
|
70
|
+
if (!envelope || typeof envelope !== 'object') return null;
|
|
71
|
+
const testRunId =
|
|
72
|
+
envelope.testRunId !== undefined && envelope.testRunId !== null
|
|
73
|
+
? String(envelope.testRunId).trim()
|
|
74
|
+
: '';
|
|
75
|
+
if (testRunId && !isEphemeralEnvelopeRunId(testRunId)) return testRunId;
|
|
76
|
+
const fromDebug = correlationIdFromAsyncDebug(envelope);
|
|
77
|
+
if (fromDebug) return fromDebug;
|
|
78
|
+
const runId =
|
|
79
|
+
envelope.runId !== undefined && envelope.runId !== null ? String(envelope.runId).trim() : '';
|
|
80
|
+
if (runId && !isEphemeralEnvelopeRunId(runId)) return runId;
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Expected capacity/sync operations for matrix rows 1 and 8.
|
|
86
|
+
* @param {Object|null|undefined} envelope
|
|
87
|
+
* @returns {string[]}
|
|
88
|
+
*/
|
|
89
|
+
function expectedOperationsFromEnvelope(envelope) {
|
|
90
|
+
const fromCapacity = cipOperationsFromDebugEnvelope(envelope);
|
|
91
|
+
if (fromCapacity.length) return fromCapacity;
|
|
92
|
+
const { standardOrder } = loadCipCapacityDisplayConfig.getCipCapacityDisplayConfig();
|
|
93
|
+
const allowed = new Set(
|
|
94
|
+
(standardOrder || []).map(op => String(op).trim().toLowerCase()).filter(Boolean)
|
|
95
|
+
);
|
|
96
|
+
const ops = new Set();
|
|
97
|
+
const caps = envelope && Array.isArray(envelope.capabilities) ? envelope.capabilities : [];
|
|
98
|
+
for (const cap of caps) {
|
|
99
|
+
if (!cap || cap.status === 'skipped' || !cap.key) continue;
|
|
100
|
+
const key = String(cap.key).trim().toLowerCase();
|
|
101
|
+
if (allowed.has(key)) ops.add(key);
|
|
102
|
+
}
|
|
103
|
+
const integration = envelope && envelope.integration;
|
|
104
|
+
if (integration && integration.sync && integration.sync.status === 'ok') {
|
|
105
|
+
ops.add('list');
|
|
106
|
+
}
|
|
107
|
+
return [...ops];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {Object|null|undefined} envelope
|
|
112
|
+
* @returns {{ datasourceKey: string, correlationId: string|null, executionIds: string[], expectedOperations: string[] }}
|
|
113
|
+
*/
|
|
114
|
+
function extractAuditEvidenceContext(envelope, opts = {}) {
|
|
115
|
+
if (!envelope || typeof envelope !== 'object') {
|
|
116
|
+
return {
|
|
117
|
+
datasourceKey: opts.datasourceKey ? String(opts.datasourceKey).trim() : '',
|
|
118
|
+
correlationId: null,
|
|
119
|
+
executionIds: [],
|
|
120
|
+
expectedOperations: []
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const datasourceKey =
|
|
124
|
+
opts.datasourceKey !== undefined && opts.datasourceKey !== null
|
|
125
|
+
? String(opts.datasourceKey).trim()
|
|
126
|
+
: envelope.datasourceKey !== undefined && envelope.datasourceKey !== null
|
|
127
|
+
? String(envelope.datasourceKey).trim()
|
|
128
|
+
: '';
|
|
129
|
+
return {
|
|
130
|
+
datasourceKey,
|
|
131
|
+
correlationId: correlationIdFromEnvelope(envelope),
|
|
132
|
+
executionIds: executionIdsFromEnvelope(envelope),
|
|
133
|
+
expectedOperations: expectedOperationsFromEnvelope(envelope)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {Object} logPayload - Saved test-e2e debug log `{ request, response }`
|
|
139
|
+
* @returns {Object|null}
|
|
140
|
+
*/
|
|
141
|
+
function envelopeFromLogPayload(logPayload) {
|
|
142
|
+
if (!logPayload || typeof logPayload !== 'object') return null;
|
|
143
|
+
if (logPayload.response && typeof logPayload.response === 'object') {
|
|
144
|
+
return logPayload.response;
|
|
145
|
+
}
|
|
146
|
+
return logPayload;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @async
|
|
151
|
+
* @param {string} datasourceKey
|
|
152
|
+
* @param {Object} options
|
|
153
|
+
* @param {string} [options.app]
|
|
154
|
+
* @param {string} [options.file]
|
|
155
|
+
* @returns {Promise<Object|null>}
|
|
156
|
+
*/
|
|
157
|
+
async function loadEnvelopeFromLatestE2eLog(datasourceKey, options = {}) {
|
|
158
|
+
if (options.file) {
|
|
159
|
+
const raw = await fsp.readFile(path.resolve(options.file), 'utf8');
|
|
160
|
+
const parsed = JSON.parse(raw);
|
|
161
|
+
return envelopeFromLogPayload(parsed);
|
|
162
|
+
}
|
|
163
|
+
const { appKey } = await resolveAppKeyForDatasource(datasourceKey, options.app);
|
|
164
|
+
const logsDir = path.join(getIntegrationPath(appKey), 'logs');
|
|
165
|
+
const logPath = await getLatestLogPath(logsDir, 'test-e2e-');
|
|
166
|
+
if (!logPath) return null;
|
|
167
|
+
const raw = await fsp.readFile(logPath, 'utf8');
|
|
168
|
+
const parsed = JSON.parse(raw);
|
|
169
|
+
return envelopeFromLogPayload(parsed);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = {
|
|
173
|
+
dedupeIds,
|
|
174
|
+
executionIdsFromEnvelope,
|
|
175
|
+
correlationIdFromEnvelope,
|
|
176
|
+
expectedOperationsFromEnvelope,
|
|
177
|
+
extractAuditEvidenceContext,
|
|
178
|
+
envelopeFromLogPayload,
|
|
179
|
+
loadEnvelopeFromLatestE2eLog
|
|
180
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Plan 407.1 nine-row audit evidence matrix checks (pure helpers)
|
|
3
|
+
* @author AI Fabrix Team
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const CAPTURED = 'captured';
|
|
10
|
+
|
|
11
|
+
const RBAC_SKIP_REASON_PREFIXES = [
|
|
12
|
+
'rbacAuditInternalPath',
|
|
13
|
+
'rbacAuditApiKeyBypass',
|
|
14
|
+
'rbacAudit'
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {import('../api/types/audit.types').AuditEvidenceMatrixRow} row
|
|
19
|
+
* @returns {import('../api/types/audit.types').AuditEvidenceMatrixRow}
|
|
20
|
+
*/
|
|
21
|
+
function passRow(row, detail, code) {
|
|
22
|
+
const out = { ...row, status: 'passed', detail };
|
|
23
|
+
if (code) {
|
|
24
|
+
out.code = code;
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {import('../api/types/audit.types').AuditEvidenceMatrixRow} row
|
|
31
|
+
* @param {string} detail
|
|
32
|
+
* @param {string} [code]
|
|
33
|
+
* @returns {import('../api/types/audit.types').AuditEvidenceMatrixRow}
|
|
34
|
+
*/
|
|
35
|
+
function failRow(row, detail, code) {
|
|
36
|
+
return { ...row, status: 'failed', detail, code: code || row.code };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {*} ref
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
function hasFkRef(ref) {
|
|
44
|
+
if (!ref || typeof ref !== 'object') return false;
|
|
45
|
+
const id = ref.id !== undefined && ref.id !== null ? String(ref.id).trim() : '';
|
|
46
|
+
const key = ref.key !== undefined && ref.key !== null ? String(ref.key).trim() : '';
|
|
47
|
+
return Boolean(id || key);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {Object} item
|
|
52
|
+
* @returns {boolean}
|
|
53
|
+
*/
|
|
54
|
+
function executionRowCaptured(item) {
|
|
55
|
+
if (!item || typeof item !== 'object') return false;
|
|
56
|
+
const rbacOk = item.rbacAuditStatus === CAPTURED && hasFkRef(item.rbacDecision);
|
|
57
|
+
const abacOk = item.abacAuditStatus === CAPTURED && hasFkRef(item.abacTrace);
|
|
58
|
+
return rbacOk && abacOk;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Row 1 — executions by datasource.
|
|
63
|
+
* @param {Object} input
|
|
64
|
+
* @returns {import('../api/types/audit.types').AuditEvidenceMatrixRow}
|
|
65
|
+
*/
|
|
66
|
+
function checkRow1ExecutionsByDatasource(input) {
|
|
67
|
+
const row = { row: 1, status: 'failed', detail: '', code: 'executionsByDatasource' };
|
|
68
|
+
const { executions, minExpected } = input;
|
|
69
|
+
const total = input.totalItems !== undefined ? input.totalItems : executions.length;
|
|
70
|
+
if (total < minExpected) {
|
|
71
|
+
return failRow(row, `executions=${total} expected>=${minExpected}`, 'executionsCountLow');
|
|
72
|
+
}
|
|
73
|
+
const captured = executions.filter(executionRowCaptured).length;
|
|
74
|
+
if (captured < minExpected) {
|
|
75
|
+
return failRow(
|
|
76
|
+
row,
|
|
77
|
+
`executions=${total} captured=${captured} (need captured rbac/abac FKs)`,
|
|
78
|
+
'executionsNotCaptured'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return passRow(row, `executions=${total} captured=${captured}`, 'executionsByDatasource');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Row 2 — RBAC decisions list.
|
|
86
|
+
* @param {Object} input
|
|
87
|
+
* @returns {import('../api/types/audit.types').AuditEvidenceMatrixRow}
|
|
88
|
+
*/
|
|
89
|
+
function checkRow2RbacDecisionsList(input) {
|
|
90
|
+
const row = { row: 2, status: 'failed', detail: '', code: 'rbacListEmpty' };
|
|
91
|
+
const items = input.rbacItems || [];
|
|
92
|
+
const total = input.totalItems !== undefined ? input.totalItems : items.length;
|
|
93
|
+
if (total < 1 || items.length < 1) {
|
|
94
|
+
return failRow(row, 'rbac-decisions list empty', 'rbacListEmpty');
|
|
95
|
+
}
|
|
96
|
+
const first = items[0];
|
|
97
|
+
const execRef = first && first.executionId;
|
|
98
|
+
if (!hasFkRef(execRef)) {
|
|
99
|
+
return failRow(row, 'rbac row missing executionId ref', 'rbacMissingExecutionId');
|
|
100
|
+
}
|
|
101
|
+
const reason = first && first.reason ? String(first.reason) : '';
|
|
102
|
+
const skipOk =
|
|
103
|
+
reason &&
|
|
104
|
+
RBAC_SKIP_REASON_PREFIXES.some(prefix => reason.startsWith(prefix) || reason.includes(prefix));
|
|
105
|
+
if (!skipOk && !reason) {
|
|
106
|
+
return failRow(row, 'rbac row missing skip/capture reason', 'rbacReasonMissing');
|
|
107
|
+
}
|
|
108
|
+
return passRow(row, `rbac rows=${total} reason=${reason || 'present'}`, 'rbacListOk');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Row 3 — ABAC traces list.
|
|
113
|
+
* @param {Object} input
|
|
114
|
+
* @returns {import('../api/types/audit.types').AuditEvidenceMatrixRow}
|
|
115
|
+
*/
|
|
116
|
+
function checkRow3AbacTracesList(input) {
|
|
117
|
+
const row = { row: 3, status: 'failed', detail: '', code: 'abacListEmpty' };
|
|
118
|
+
const items = input.abacItems || [];
|
|
119
|
+
const total = input.totalItems !== undefined ? input.totalItems : items.length;
|
|
120
|
+
if (total < 1 || items.length < 1) {
|
|
121
|
+
return failRow(row, 'abac-traces list empty', 'abacListEmpty');
|
|
122
|
+
}
|
|
123
|
+
const first = items[0];
|
|
124
|
+
const decision = first && first.decision ? String(first.decision) : '';
|
|
125
|
+
const reason = first && first.reason ? String(first.reason) : '';
|
|
126
|
+
if (!reason) {
|
|
127
|
+
return failRow(row, 'abac row missing reason', 'abacReasonMissing');
|
|
128
|
+
}
|
|
129
|
+
return passRow(row, `abac rows=${total} decision=${decision || 'n/a'} reason=${reason}`, 'abacListOk');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Rows 4–7, 9 — per-execution sub-resources.
|
|
134
|
+
* @param {number} rowNum
|
|
135
|
+
* @param {string} code
|
|
136
|
+
* @param {string} label
|
|
137
|
+
* @param {*} payload
|
|
138
|
+
* @param {(payload: *) => boolean} isValid
|
|
139
|
+
* @returns {import('../api/types/audit.types').AuditEvidenceMatrixRow}
|
|
140
|
+
*/
|
|
141
|
+
function checkPerExecutionRow(rowNum, code, label, payload, isValid) {
|
|
142
|
+
const row = { row: rowNum, status: 'failed', detail: '', code };
|
|
143
|
+
if (!isValid(payload)) {
|
|
144
|
+
return failRow(row, `${label} missing or invalid`, code);
|
|
145
|
+
}
|
|
146
|
+
return passRow(row, `${label} ok`, `${label}Ok`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
CAPTURED,
|
|
151
|
+
RBAC_SKIP_REASON_PREFIXES,
|
|
152
|
+
hasFkRef,
|
|
153
|
+
executionRowCaptured,
|
|
154
|
+
checkRow1ExecutionsByDatasource,
|
|
155
|
+
checkRow2RbacDecisionsList,
|
|
156
|
+
checkRow3AbacTracesList,
|
|
157
|
+
checkPerExecutionRow
|
|
158
|
+
};
|