Skip to content

Commit

Permalink
fix: ignore encrypted configs that cannot be decrypted
Browse files Browse the repository at this point in the history
In case we have no encryption key available or some other error occurs
during decryption of the repository config, we need to ignore that repo
and continue with the other repositories that can be decrypted / are not
decrypted.
  • Loading branch information
ZauberNerd committed Dec 15, 2020
1 parent 3717867 commit d008169
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ describe('normalize config', () => {
process.env.CANARIST_ENCRYPTION_KEY = undefined;
});

it('should ignore repositories that cannot be decrypted', () => {
// $ canarist -r a-repo -r enc:G6VSEW8lxBM3OYn7E3k4yGH61ExqKxx/rsUtKS/h8GU=
const config = normalizeConfig(
{
_: [],
help: false,
clean: true,
repository: [
'a-repo',
'enc:G6VSEW8lxBM3OYn7E3k4yGH61ExqKxx/rsUtKS/h8GU=',
],
},
null
);

expect(config.repositories).toEqual<Config['repositories']>([
{
url: 'a-repo',
branch: 'master',
directory: 'a-repo',
commands: ['yarn test'],
},
]);
});

it('should normalize arguments for multiple repositories', () => {
// $ canarist -r a-repo -r b-repo
const config = normalizeConfig(
Expand Down
62 changes: 58 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,69 @@ export function normalizeConfig(
'';

if (typeof argv.repository === 'string') {
repositories.push(normalizeRepository(argv.repository));
try {
repositories.push(normalizeRepository(argv.repository));
} catch (error) {
console.warn(
`[canarist] could not parse repository config from: "${argv.repository}"`,
error
);
}
} else if (Array.isArray(argv.repository)) {
repositories.push(...argv.repository.map(normalizeRepository));
repositories.push(
...argv.repository
.map((repo) => {
try {
return normalizeRepository(repo);
} catch (error) {
console.warn(
`[canarist] could not parse repository config from:`,
repo,
error
);
return undefined;
}
})
.filter((repo): repo is RepositoryConfig => typeof repo !== 'undefined')
);
} else if (argv.project && config && isProjectsConfig(config.config)) {
if (project) {
repositories.push(...project.repositories.map(normalizeRepository));
repositories.push(
...project.repositories
.map((repo) => {
try {
return normalizeRepository(repo);
} catch (error) {
console.warn(
`[canarist] could not parse repository config from:`,
repo,
error
);
return undefined;
}
})
.filter(
(repo): repo is RepositoryConfig => typeof repo !== 'undefined'
)
);
}
} else if (config && isSingleConfig(config.config)) {
repositories.push(...config.config.repositories.map(normalizeRepository));
repositories.push(
...config.config.repositories
.map((repo) => {
try {
return normalizeRepository(repo);
} catch (error) {
console.warn(
`[canarist] could not parse repository config from:`,
repo,
error
);
return undefined;
}
})
.filter((repo): repo is RepositoryConfig => typeof repo !== 'undefined')
);
}

return {
Expand Down

0 comments on commit d008169

Please sign in to comment.