Skip to content

Commit

Permalink
feat: refactor prevent use of clientId & secret and patToken together
Browse files Browse the repository at this point in the history
  • Loading branch information
mjacholke committed Jul 9, 2024
1 parent d0d0db6 commit 079f9aa
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/commands/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ export type ConfigurationParameters = {
dstHubId?: string;
};

export type StoredConfigurationParameters = {
clientId?: string;
clientSecret?: string;
patToken?: string;
hubId?: string;
dstClientId?: string;
dstSecret?: string;
dstHubId?: string;
};

type ConfigArgument = {
config: string;
};
Expand Down Expand Up @@ -113,19 +103,19 @@ export const readConfigFile = (configFile: string, ignoreError?: boolean): objec

export const handler = (argv: Arguments<ConfigurationParameters & ConfigArgument>): void => {
const { clientId, clientSecret, hubId, patToken } = argv;
const storedConfig: StoredConfigurationParameters = readConfigFile(argv.config);
const storedConfig = readConfigFile(argv.config);
const newConfig: ConfigurationParameters = { clientId, clientSecret, hubId, patToken };
const commandLineArgs = getCommandLineArgs();

if ((commandLineArgs.clientId || commandLineArgs.clientSecret) && commandLineArgs.patToken) {
console.error('You cannot specify both clientId and clientSecret together with patToken.');
console.error('Error: Specify clientId & clientSecret or patToken, not both');
return;
}
if (commandLineArgs.patToken && (storedConfig.clientId || storedConfig.clientSecret)) {
if (commandLineArgs.patToken && (clientId || clientSecret)) {
delete newConfig.clientId;
delete newConfig.clientSecret;
}
if ((commandLineArgs.clientId || commandLineArgs.clientSecret) && storedConfig.patToken) {
if ((commandLineArgs.clientId || commandLineArgs.clientSecret) && patToken) {
delete newConfig.patToken;
}
if (argv.dstClientId) newConfig.dstClientId = argv.dstClientId;
Expand Down

0 comments on commit 079f9aa

Please sign in to comment.