Skip to content

Commit

Permalink
refactor: refactor to avoid additional parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Barbosa <tbarbos@hotmail.com>
  • Loading branch information
t1agob committed Apr 13, 2024
1 parent 8902e34 commit 4918a2c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Binary file removed .yarn/install-state.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions src/actions/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type CreatePagerDutyServiceActionProps = {
logger: LoggerService;
};

export const createPagerDutyServiceAction = (props : CreatePagerDutyServiceActionProps) => {
export const createPagerDutyServiceAction = (props? : CreatePagerDutyServiceActionProps) => {

let loggerService: LoggerService;

Expand Down Expand Up @@ -40,7 +40,7 @@ export const createPagerDutyServiceAction = (props : CreatePagerDutyServiceActio
async handler(ctx) {
try {
loggerService = props?.logger ? props.logger : ctx.logger;
const configService = props?.config ?? props.config;
const configService = props?.config;

const legacyConfig: Config = await loadBackendConfig({
logger: loggerService,
Expand Down
19 changes: 8 additions & 11 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Auth = {
}

export type LoadAuthConfigProps = {
config: RootConfigService;
config: RootConfigService | undefined;
legacyConfig: Config;
logger: LoggerService;
}
Expand All @@ -22,8 +22,7 @@ interface JsonObject {
type JsonArray = JsonValue[];

let authPersistence: Auth;
let isLegacyConfig: boolean;
let _config: RootConfigService;
let _config: RootConfigService | undefined;
let _legacyConfig: Config;
let _logger: LoggerService;

Expand All @@ -47,9 +46,6 @@ export async function getAuthToken(): Promise<string> {

export async function loadAuthConfig({config, legacyConfig, logger}: LoadAuthConfigProps) {
try {
// check if we are using new backend system. Fallback to legacy config if not
isLegacyConfig = !config;

// set config and logger
_config = config;
_legacyConfig = legacyConfig;
Expand Down Expand Up @@ -93,23 +89,24 @@ export async function loadAuthConfig({config, legacyConfig, logger}: LoadAuthCon
}

function readOptionalString(key: string) : string | undefined {
if (isLegacyConfig) {
if (!_config) {
return _legacyConfig.getOptionalString(key);
}
}

return _config.getOptionalString(key);

}

function readOptionalObject(key: string): JsonValue | undefined {
if (isLegacyConfig) {
if (!_config) {
return _legacyConfig.getOptional(key);
}

return _config.getOptional(key);
}

function readString(key: string) : string {
if (isLegacyConfig) {
if (!_config) {
return _legacyConfig.getString(key);
}

Expand Down

0 comments on commit 4918a2c

Please sign in to comment.