@mesh-tech/mesh-cli
Version:
CLI for Mesh platform development utilities
50 lines (49 loc) • 2.06 kB
JavaScript
import { LOCAL_ENV, LOCAL_TENANT } from "./seed.js";
export const HUB_AUTHZ_POINTER_PARAM = `/mesh-platform/${LOCAL_TENANT}/${LOCAL_ENV}/apps/hub/stacks/local/authz`;
export const HUB_OPS_HUB_METADATA_PARAM = `${HUB_AUTHZ_POINTER_PARAM}/ops-hub-metadata`;
export function withHubCatalogRefs(pointer, metadataRef) {
return {
spicedb: { instanceRefs: [] },
...pointer,
opsHubMetadataRef: metadataRef,
mode: typeof pointer.mode === "string" ? pointer.mode : "policy-engine",
};
}
export async function publishHubAuthzCatalog(compiled, awsConfig) {
const { SSMClient, GetParameterCommand, PutParameterCommand } = await import("@aws-sdk/client-ssm");
const ssm = new SSMClient(awsConfig);
await ssm.send(new PutParameterCommand({
Name: HUB_OPS_HUB_METADATA_PARAM,
Type: "String",
Tier: "Advanced",
Overwrite: true,
Value: JSON.stringify(compiled.metadata),
Description: "Hub role catalog — ops-hub-metadata (local analog of MeshHub's SpiceDBSchema export)",
}));
let current = {};
try {
const existing = await ssm.send(new GetParameterCommand({ Name: HUB_AUTHZ_POINTER_PARAM }));
current = JSON.parse(existing.Parameter?.Value ?? "{}");
}
catch {
}
await ssm.send(new PutParameterCommand({
Name: HUB_AUTHZ_POINTER_PARAM,
Type: "String",
Overwrite: true,
Value: JSON.stringify(withHubCatalogRefs(current, HUB_OPS_HUB_METADATA_PARAM)),
Description: "Hub authz pointer (local analog of the platform Pulumi program)",
}));
return { bundles: catalogBundleNames(compiled.metadata) };
}
export function catalogBundleNames(metadata) {
const bundles = metadata.bundles;
if (Array.isArray(bundles)) {
return bundles
.map((b) => (b && typeof b === "object" && typeof b.name === "string" ? b.name : null))
.filter((n) => n !== null);
}
if (bundles && typeof bundles === "object")
return Object.keys(bundles);
return [];
}