Skip to content
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
110 changes: 0 additions & 110 deletions api/src/__test__/mothership/api-key/api-key-check-jobs.test.ts

This file was deleted.

54 changes: 0 additions & 54 deletions api/src/__test__/mothership/api-key/retry-validate-api-key.test.ts

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions api/src/graphql/resolvers/mutation/connect/connect-sign-in.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import { decodeJwt } from 'jose';

import type { ConnectSignInInput } from '@app/graphql/generated/api/types';
import { NODE_ENV } from '@app/environment';
import { Role } from '@app/graphql/generated/api/types';
import { API_KEY_STATUS } from '@app/mothership/api-key/api-key-types';
import { validateApiKeyWithKeyServer } from '@app/mothership/api-key/validate-api-key-with-keyserver';
import { getters, store } from '@app/store/index';
import { loginUser } from '@app/store/modules/config';
import { FileLoadStatus } from '@app/store/types';
import { ApiKeyService } from '@app/unraid-api/auth/api-key.service';

export const connectSignIn = async (input: ConnectSignInInput): Promise<boolean> => {
if (getters.emhttp().status === FileLoadStatus.LOADED) {
const result =
NODE_ENV === 'development'
? API_KEY_STATUS.API_KEY_VALID
: await validateApiKeyWithKeyServer({
apiKey: input.apiKey,
flashGuid: getters.emhttp().var.flashGuid,
});
if (result !== API_KEY_STATUS.API_KEY_VALID) {
throw new Error(`Validating API Key Failed with Error: ${result}`);
}

const userInfo = input.idToken ? decodeJwt(input.idToken) : (input.userInfo ?? null);

if (
Expand Down
7 changes: 1 addition & 6 deletions api/src/graphql/resolvers/query/cloud/check-api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { logger } from '@app/core/log';
import { getters } from '@app/store';
import { type ApiKeyResponse } from '@app/graphql/generated/api/types';
import { isApiKeyValid } from '@app/store/getters/index';

export const checkApi = async (): Promise<ApiKeyResponse> => {
logger.trace('Cloud endpoint: Checking API');
const valid = isApiKeyValid();
const error = valid ? null : getters.apiKey().status;

return { valid, error };
return { valid: true };
};
16 changes: 9 additions & 7 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { PingTimeoutJobs } from '@app/mothership/jobs/ping-timeout-jobs';
import { store } from '@app/store';
import { loadDynamixConfigFile } from '@app/store/actions/load-dynamix-config-file';
import { shutdownApiEvent } from '@app/store/actions/shutdown-api-event';
import { validateApiKeyIfPresent } from '@app/store/listeners/api-key-listener';
import { startMiddlewareListeners } from '@app/store/listeners/listener-middleware';
import { loadConfigFile } from '@app/store/modules/config';
import { loadStateFiles } from '@app/store/modules/emhttp';
Expand All @@ -33,6 +32,8 @@ import { StateManager } from '@app/store/watch/state-watch';
import { setupVarRunWatch } from '@app/store/watch/var-run-watch';
import { bootstrapNestServer } from '@app/unraid-api/main';

import { setupNewMothershipSubscription } from './mothership/subscribe-to-mothership';

let server: NestFastifyApplication<RawServerDefault> | null = null;

const unlinkUnixPort = () => {
Expand Down Expand Up @@ -72,6 +73,8 @@ try {
// Load my dynamix config file into store
await store.dispatch(loadDynamixConfigFile());

await setupNewMothershipSubscription();

// Start listening to file updates
StateManager.getInstance();

Expand All @@ -92,15 +95,12 @@ try {

// Start webserver
server = await bootstrapNestServer();
PingTimeoutJobs.init();

startMiddlewareListeners();

await validateApiKeyIfPresent();

// On process exit stop HTTP server
exitHook(() => {
console.log('exithook');
exitHook((signal) => {
console.log('exithook', signal);
server?.close?.();
// If port is unix socket, delete socket before exiting
unlinkUnixPort();
Expand All @@ -113,7 +113,9 @@ try {
await new Promise(() => {});
} catch (error: unknown) {
if (error instanceof Error) {
logger.error('API-ERROR %s %s', error.message, error.stack);
logger.error(error, 'API-ERROR');
} else {
logger.error(error, 'Encountered unexpected error');
}
if (server) {
await server?.close?.();
Expand Down
8 changes: 0 additions & 8 deletions api/src/mothership/api-key/api-key-types.ts

This file was deleted.

25 changes: 0 additions & 25 deletions api/src/mothership/api-key/retry-validate-api-key.ts

This file was deleted.

Loading
Loading