From dd9e75dbab0be5460792fd8afcf54d655b665307 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Tue, 16 Apr 2024 23:43:21 -0400 Subject: [PATCH] refactor cleanup --- src/app/AppLayout/AuthModal.tsx | 6 ++- .../Services/AuthCredentials.service.tsx | 31 ------------- src/app/Shared/Services/Services.tsx | 4 -- .../Services/JmxCredentials.service.test.tsx | 43 ------------------- 4 files changed, 4 insertions(+), 80 deletions(-) delete mode 100644 src/app/Shared/Services/AuthCredentials.service.tsx delete mode 100644 src/test/Shared/Services/JmxCredentials.service.test.tsx diff --git a/src/app/AppLayout/AuthModal.tsx b/src/app/AppLayout/AuthModal.tsx index 030ea28c40..a7790ac185 100644 --- a/src/app/AppLayout/AuthModal.tsx +++ b/src/app/AppLayout/AuthModal.tsx @@ -43,7 +43,9 @@ export const AuthModal: React.FC = ({ onDismiss, onSave: onProps filter((target) => !!target), first(), map((target: Target) => target.connectUrl), - mergeMap((connectUrl) => context.authCredentials.setCredential(connectUrl, username, password)), + mergeMap((connectUrl) => + context.api.postCredentials(`target.connectUrl == "${connectUrl}"`, username, password), + ), ) .subscribe((ok) => { setLoading(false); @@ -53,7 +55,7 @@ export const AuthModal: React.FC = ({ onDismiss, onSave: onProps }), ); }, - [addSubscription, context.authCredentials, targetObs, setLoading, onPropsSave], + [addSubscription, context.api, targetObs, setLoading, onPropsSave], ); return ( diff --git a/src/app/Shared/Services/AuthCredentials.service.tsx b/src/app/Shared/Services/AuthCredentials.service.tsx deleted file mode 100644 index 9378716872..0000000000 --- a/src/app/Shared/Services/AuthCredentials.service.tsx +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { Observable, of } from 'rxjs'; -import type { ApiService } from './Api.service'; -import { Credential } from './service.types'; - -export class AuthCredentials { - constructor(private readonly api: () => ApiService) {} - - setCredential(targetId: string, username: string, password: string): Observable { - return this.api().postCredentials(`target.connectUrl == "${targetId}"`, username, password); - } - - getCredential(_: string): Observable { - // if this is stored on the backend then Cryostat should be using those and not prompting us to request from the user - return of(undefined); - } -} diff --git a/src/app/Shared/Services/Services.tsx b/src/app/Shared/Services/Services.tsx index e967c455eb..1dd7f78d22 100644 --- a/src/app/Shared/Services/Services.tsx +++ b/src/app/Shared/Services/Services.tsx @@ -15,7 +15,6 @@ */ import * as React from 'react'; import { ApiService } from './Api.service'; -import { AuthCredentials } from './AuthCredentials.service'; import { LoginService } from './Login.service'; import { NotificationChannel } from './NotificationChannel.service'; import { NotificationsInstance } from './Notifications.service'; @@ -28,7 +27,6 @@ export interface Services { target: TargetService; targets: TargetsService; api: ApiService; - authCredentials: AuthCredentials; notificationChannel: NotificationChannel; reports: ReportService; settings: SettingsService; @@ -37,7 +35,6 @@ export interface Services { const target = new TargetService(); const settings = new SettingsService(); -const authCredentials = new AuthCredentials(() => api); const login = new LoginService(settings); const api = new ApiService(target, NotificationsInstance, login); const notificationChannel = new NotificationChannel(NotificationsInstance, login); @@ -48,7 +45,6 @@ const defaultServices: Services = { target, targets, api, - authCredentials, notificationChannel, reports, settings, diff --git a/src/test/Shared/Services/JmxCredentials.service.test.tsx b/src/test/Shared/Services/JmxCredentials.service.test.tsx deleted file mode 100644 index 131042f4b1..0000000000 --- a/src/test/Shared/Services/JmxCredentials.service.test.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* eslint @typescript-eslint/no-explicit-any: 0 */ -import { ApiService } from '@app/Shared/Services/Api.service'; -import { AuthCredentials } from '@app/Shared/Services/AuthCredentials.service'; -import { firstValueFrom, Observable, of } from 'rxjs'; - -const mockApi = { - postCredentials: (_expr: string, _user: string, _pass: string): Observable => of(true), -} as ApiService; -const postCredentialsSpy = jest.spyOn(mockApi, 'postCredentials'); - -describe('AuthCredentials.service', () => { - let svc: AuthCredentials; - beforeEach(() => { - postCredentialsSpy.mockReset(); - svc = new AuthCredentials(() => mockApi); - }); - - it('does not retrieve credentials', async () => { - const cred = await firstValueFrom(svc.getCredential('myTarget')); - expect(cred).toBeUndefined(); - expect(postCredentialsSpy).not.toHaveBeenCalled(); - }); - - it('POSTs credentials to API service', async () => { - svc.setCredential('myTarget', 'foouser', 'foopass'); - expect(postCredentialsSpy).toHaveBeenCalled(); - }); -});