Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor to avoid additional parameters #4

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading