@aspruyt/xfg 8.3.1 → 8.3.2
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/cli/secrets-command.js +2 -1
- package/dist/lifecycle/index.d.ts +1 -0
- package/dist/lifecycle/index.js +1 -0
- package/dist/settings/secrets/index.d.ts +1 -1
- package/dist/settings/secrets/processor.d.ts +3 -2
- package/dist/settings/secrets/processor.js +17 -6
- package/dist/settings/secrets/types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { mkdirSync } from "node:fs";
|
|
|
2
2
|
import { loadRawConfig, normalizeConfig, validateSecretsConfig, validateNormalizedConfig, } from "../config/index.js";
|
|
3
3
|
import { SecretsProcessor, GitHubSecretsStrategy, SodiumEncryptor, } from "../settings/secrets/index.js";
|
|
4
4
|
import { GitHubEnvironmentsStrategy } from "../settings/environments/index.js";
|
|
5
|
+
import { GitHubLifecycleProvider } from "../lifecycle/index.js";
|
|
5
6
|
import { GitHubRepoMetadataProvider, parseGitUrl, getRepoDisplayName, } from "../repo/index.js";
|
|
6
7
|
import { EnvResolver } from "../shared/env-resolver.js";
|
|
7
8
|
import { ProcessExecutor } from "../shared/command-executor.js";
|
|
@@ -26,7 +27,7 @@ function createDefaultProcessor(cwd, retries, tokenProvider) {
|
|
|
26
27
|
cwd,
|
|
27
28
|
retries,
|
|
28
29
|
}),
|
|
29
|
-
});
|
|
30
|
+
}, new GitHubLifecycleProvider({ executor, retries, cwd }));
|
|
30
31
|
}
|
|
31
32
|
function hostQualifiedName(repoInfo) {
|
|
32
33
|
const name = getRepoDisplayName(repoInfo);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export type { IRepoLifecycleManager, LifecycleActionKind } from "./types.js";
|
|
2
2
|
export { RepoLifecycleManager } from "./repo-lifecycle-manager.js";
|
|
3
|
+
export { GitHubLifecycleProvider } from "./github-lifecycle-provider.js";
|
|
3
4
|
export { runLifecycleCheck, toCreateRepoSettings, type LifecycleCheckResult, } from "./helpers.js";
|
package/dist/lifecycle/index.js
CHANGED
|
@@ -4,4 +4,4 @@ export { formatSecretsPlan, formatSecretLabel, type SecretsPlanEntry, type Secre
|
|
|
4
4
|
export { diffSecrets, type SecretAction, type SecretChange } from "./diff.js";
|
|
5
5
|
export { GitHubSecretsStrategy } from "./github-secrets-strategy.js";
|
|
6
6
|
export { SodiumEncryptor, type ISecretEncryptor } from "./encryption.js";
|
|
7
|
-
export type { ISecretsStrategy, GitHubSecret, GitHubPublicKey, } from "./types.js";
|
|
7
|
+
export type { ISecretsStrategy, GitHubSecret, GitHubPublicKey, IRepoExistenceChecker, } from "./types.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IRepoMetadataProvider, RepoInfo } from "../../repo/index.js";
|
|
2
2
|
import type { RepoConfig } from "../../config/index.js";
|
|
3
|
-
import type { ISecretsStrategy } from "./types.js";
|
|
3
|
+
import type { ISecretsStrategy, IRepoExistenceChecker } from "./types.js";
|
|
4
4
|
import type { IEnvironmentSecretsStrategy } from "../environments/types.js";
|
|
5
5
|
import type { ISecretEncryptor } from "./encryption.js";
|
|
6
6
|
import type { IEnvResolver } from "../../shared/env-resolver.js";
|
|
@@ -28,7 +28,8 @@ export declare class SecretsProcessor implements ISecretsProcessor {
|
|
|
28
28
|
private readonly envResolver;
|
|
29
29
|
private readonly tokenProvider?;
|
|
30
30
|
private readonly environments?;
|
|
31
|
-
|
|
31
|
+
private readonly repoExistence?;
|
|
32
|
+
constructor(strategy: ISecretsStrategy, encryptor: ISecretEncryptor, envResolver: IEnvResolver, tokenProvider?: IGitHubTokenProvider | undefined, environments?: EnvironmentSecretsDependencies | undefined, repoExistence?: IRepoExistenceChecker | undefined);
|
|
32
33
|
private hasDesiredSecrets;
|
|
33
34
|
process(repoConfig: RepoConfig, repoInfo: RepoInfo, options: SecretsProcessorOptions): Promise<SecretsProcessorResult>;
|
|
34
35
|
private applySettings;
|
|
@@ -42,12 +42,14 @@ export class SecretsProcessor {
|
|
|
42
42
|
envResolver;
|
|
43
43
|
tokenProvider;
|
|
44
44
|
environments;
|
|
45
|
-
|
|
45
|
+
repoExistence;
|
|
46
|
+
constructor(strategy, encryptor, envResolver, tokenProvider, environments, repoExistence) {
|
|
46
47
|
this.strategy = strategy;
|
|
47
48
|
this.encryptor = encryptor;
|
|
48
49
|
this.envResolver = envResolver;
|
|
49
50
|
this.tokenProvider = tokenProvider;
|
|
50
51
|
this.environments = environments;
|
|
52
|
+
this.repoExistence = repoExistence;
|
|
51
53
|
}
|
|
52
54
|
hasDesiredSecrets(repoConfig) {
|
|
53
55
|
return (hasRepoSecrets(repoConfig) ||
|
|
@@ -80,15 +82,22 @@ export class SecretsProcessor {
|
|
|
80
82
|
token = resolved.token;
|
|
81
83
|
}
|
|
82
84
|
const { dryRun, noDelete } = options;
|
|
85
|
+
const repoMissing = dryRun === true &&
|
|
86
|
+
this.repoExistence !== undefined &&
|
|
87
|
+
!(await this.repoExistence.exists({ repo: githubRepo, token }));
|
|
83
88
|
const secrets = (repoConfig.settings?.secrets ?? {});
|
|
84
89
|
const configDeleteOrphaned = secrets.deleteOrphaned === true;
|
|
85
90
|
const deleteOrphaned = configDeleteOrphaned && !(noDelete ?? false);
|
|
86
91
|
const secretEntries = secretEntriesOf(repoConfig).filter((entry) => typeof entry[1] !== "boolean");
|
|
87
92
|
const strategyOptions = { token, host: githubRepo.host };
|
|
88
|
-
const
|
|
89
|
-
|
|
93
|
+
const managesRepoSecrets = secretEntries.length > 0 || deleteOrphaned;
|
|
94
|
+
const currentRepoSecrets = managesRepoSecrets && !repoMissing
|
|
95
|
+
? await this.strategy.list(githubRepo, strategyOptions)
|
|
90
96
|
: [];
|
|
91
|
-
const
|
|
97
|
+
const repoChanges = managesRepoSecrets
|
|
98
|
+
? diffSecrets(currentRepoSecrets, secretEntries.map(([name]) => name), deleteOrphaned)
|
|
99
|
+
: [];
|
|
100
|
+
const envGroups = await this.readEnvironments(githubRepo, repoConfig, strategyOptions, noDelete ?? false, repoMissing);
|
|
92
101
|
const envChanges = await this.diffEnvironmentSecrets(githubRepo, envGroups, strategyOptions);
|
|
93
102
|
if (dryRun) {
|
|
94
103
|
const planned = [...repoChanges, ...envChanges];
|
|
@@ -193,13 +202,15 @@ export class SecretsProcessor {
|
|
|
193
202
|
return new Map();
|
|
194
203
|
return this.envResolver.resolveAll(entries.map(([name, config]) => ({ name, envVar: config.env })));
|
|
195
204
|
}
|
|
196
|
-
async readEnvironments(githubRepo, repoConfig, strategyOptions, noDelete) {
|
|
205
|
+
async readEnvironments(githubRepo, repoConfig, strategyOptions, noDelete, repoMissing) {
|
|
197
206
|
const configured = this.environments
|
|
198
207
|
? environmentSecretsOf(repoConfig)
|
|
199
208
|
: [];
|
|
200
209
|
if (configured.length === 0)
|
|
201
210
|
return [];
|
|
202
|
-
const current =
|
|
211
|
+
const current = repoMissing
|
|
212
|
+
? []
|
|
213
|
+
: await this.environments.strategy.list(githubRepo, strategyOptions);
|
|
203
214
|
const existing = new Map(current.map((env) => [env.name.toLowerCase(), env.name]));
|
|
204
215
|
return configured.map(({ name, entries, deleteOrphaned }) => {
|
|
205
216
|
const actual = existing.get(name.toLowerCase());
|
|
@@ -19,3 +19,10 @@ export interface ISecretsStrategy {
|
|
|
19
19
|
upsert(repoInfo: RepoInfo, name: string, encryptedValue: string, keyId: string, options?: GhApiOptions): Promise<void>;
|
|
20
20
|
delete(repoInfo: RepoInfo, name: string, options?: GhApiOptions): Promise<void>;
|
|
21
21
|
}
|
|
22
|
+
/** `xfg sync` creates a missing repo, so a plan reads its current state as empty. */
|
|
23
|
+
export interface IRepoExistenceChecker {
|
|
24
|
+
exists(params: {
|
|
25
|
+
repo: RepoInfo;
|
|
26
|
+
token?: string;
|
|
27
|
+
}): Promise<boolean>;
|
|
28
|
+
}
|
package/package.json
CHANGED