@clef-sh/core 0.1.6-beta.32 → 0.1.7-beta.43

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/dist/index.mjs CHANGED
@@ -2605,7 +2605,7 @@ var LintRunner = class {
2605
2605
  /**
2606
2606
  * Lint service identity configurations for drift issues.
2607
2607
  */
2608
- async lintServiceIdentities(identities, manifest, _repoRoot, existingCells) {
2608
+ async lintServiceIdentities(identities, manifest, repoRoot, existingCells) {
2609
2609
  const issues = [];
2610
2610
  const declaredEnvNames = new Set(manifest.environments.map((e) => e.name));
2611
2611
  const declaredNsNames = new Set(manifest.namespaces.map((ns) => ns.name));
@@ -4139,6 +4139,55 @@ var ServiceIdentityManager = class {
4139
4139
  get(manifest, name) {
4140
4140
  return manifest.service_identities?.find((si) => si.name === name);
4141
4141
  }
4142
+ /**
4143
+ * Update environment backends on an existing service identity.
4144
+ * Switches age → KMS (removes old recipient) or updates KMS config.
4145
+ * Returns new private keys for any environments switched from KMS → age.
4146
+ */
4147
+ async updateEnvironments(name, kmsEnvConfigs, manifest, repoRoot) {
4148
+ const identity = this.get(manifest, name);
4149
+ if (!identity) {
4150
+ throw new Error(`Service identity '${name}' not found.`);
4151
+ }
4152
+ const manifestPath = path17.join(repoRoot, CLEF_MANIFEST_FILENAME);
4153
+ const raw = fs15.readFileSync(manifestPath, "utf-8");
4154
+ const doc = YAML10.parse(raw);
4155
+ const identities = doc.service_identities;
4156
+ const siDoc = identities.find((si) => si.name === name);
4157
+ const envs = siDoc.environments;
4158
+ const cells = this.matrixManager.resolveMatrix(manifest, repoRoot).filter((c) => c.exists);
4159
+ const privateKeys = {};
4160
+ for (const [envName, kmsConfig] of Object.entries(kmsEnvConfigs)) {
4161
+ const oldConfig = identity.environments[envName];
4162
+ if (!oldConfig) {
4163
+ throw new Error(`Environment '${envName}' not found on identity '${name}'.`);
4164
+ }
4165
+ if (oldConfig.recipient) {
4166
+ const scopedCells = cells.filter(
4167
+ (c) => identity.namespaces.includes(c.namespace) && c.environment === envName
4168
+ );
4169
+ for (const cell of scopedCells) {
4170
+ try {
4171
+ await this.encryption.removeRecipient(cell.filePath, oldConfig.recipient);
4172
+ } catch {
4173
+ }
4174
+ }
4175
+ }
4176
+ envs[envName] = { kms: kmsConfig };
4177
+ identity.environments[envName] = { kms: kmsConfig };
4178
+ }
4179
+ const tmp = path17.join(os.tmpdir(), `clef-manifest-${process.pid}-${Date.now()}.tmp`);
4180
+ try {
4181
+ fs15.writeFileSync(tmp, YAML10.stringify(doc), "utf-8");
4182
+ fs15.renameSync(tmp, manifestPath);
4183
+ } finally {
4184
+ try {
4185
+ fs15.unlinkSync(tmp);
4186
+ } catch {
4187
+ }
4188
+ }
4189
+ return { privateKeys };
4190
+ }
4142
4191
  /**
4143
4192
  * Register a service identity's public keys as SOPS recipients on scoped matrix files.
4144
4193
  */
@@ -4389,7 +4438,8 @@ var ArtifactPacker = class {
4389
4438
  try {
4390
4439
  const e = new Encrypter();
4391
4440
  e.addRecipient(ephemeralPublicKey);
4392
- ciphertext = await e.encrypt(plaintext);
4441
+ const encrypted = await e.encrypt(plaintext);
4442
+ ciphertext = typeof encrypted === "string" ? encrypted : Buffer.from(encrypted).toString("base64");
4393
4443
  } catch {
4394
4444
  throw new Error("Failed to age-encrypt artifact with ephemeral key.");
4395
4445
  }
@@ -4418,7 +4468,8 @@ var ArtifactPacker = class {
4418
4468
  const { Encrypter } = await import("age-encryption");
4419
4469
  const e = new Encrypter();
4420
4470
  e.addRecipient(resolved.recipient);
4421
- ciphertext = await e.encrypt(plaintext);
4471
+ const encrypted = await e.encrypt(plaintext);
4472
+ ciphertext = typeof encrypted === "string" ? encrypted : Buffer.from(encrypted).toString("base64");
4422
4473
  } catch {
4423
4474
  throw new Error("Failed to age-encrypt artifact. Check recipient key.");
4424
4475
  }