Skip to content

Commit

Permalink
WIP: jolokia api server without login phase
Browse files Browse the repository at this point in the history
The new jolokia api server doesn't require to login to access its
services but requires to have a bearer token passed onto every requests
alongside the actual jolokia endpoint that is the target of the request.

This PoC uses these new information and strips down the previous login
phase we had.

Since I haven't updated the readme yet, here are the information that
you need to run this successfully:

* first you need to login to you oc env
* then go in the folder 'bridge-auth-https' and run ./setup.sh
* in one terminal run `yarn start-tls` and in another one `yarn
  start-console-tls`, you need to be in tls mode for this to work for
  now, I'll debug later the http version.
* then head out to the PoC PR for the jolokia api server and build & run
  it as usual arkmq-org/activemq-artemis-jolokia-api-server#3

Let me know how it goes!
  • Loading branch information
lavocatt committed Dec 12, 2024
1 parent 1ce2073 commit d469ca6
Show file tree
Hide file tree
Showing 21 changed files with 358 additions and 795 deletions.
305 changes: 112 additions & 193 deletions api-server/openapi.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fireEvent, render, screen } from '@app/test-utils';
import { AddressDetails } from './AddressDetails.component';
import { JolokiaAuthentication } from '@app/jolokia/components/JolokiaAuthentication';
import { useJolokiaServiceReadAddressAttributes } from '@app/openapi/jolokia/queries';
import { useJolokiaLogin } from '@app/jolokia/customHooks';
import { useGetEndpointData } from '@app/jolokia/customHooks';

jest.mock('../../openapi/jolokia/queries', () => ({
useJolokiaServiceReadAddressAttributes: jest.fn(),
Expand All @@ -15,7 +15,7 @@ jest.mock('../../jolokia/customHooks', () => ({

const mockUseJolokiaServiceReadAddressAttributes =
useJolokiaServiceReadAddressAttributes as jest.Mock;
const mockUseJolokiaLogin = useJolokiaLogin as jest.Mock;
const mockUseJolokiaLogin = useGetEndpointData as jest.Mock;

describe('AddressDetails', () => {
const mockData = [
Expand Down
4 changes: 2 additions & 2 deletions src/addresses/Address-details/AddressDetails.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ const AddressDetails: FC<AddressDetailsTableProps> = ({ name }) => {
'UnRoutedMessageCount',
];

const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);
const {
data: readAddressAttrs,
isSuccess,
error,
} = useJolokiaServiceReadAddressAttributes({
jolokiaSessionId: authToken,
name: name,
attrs: allAddressAttrs,
targetEndpoint: authContext.targetEndpoint,
});

const [page, setPage] = useState(1);
Expand Down
4 changes: 2 additions & 2 deletions src/addresses/Addresses/Address.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@app/test-utils';
import { Addresses } from './Address.component';
import { JolokiaAuthentication } from '@app/jolokia/components/JolokiaAuthentication';
import { useJolokiaServiceGetAddresses } from '@app/openapi/jolokia/queries';
import { useJolokiaLogin } from '@app/jolokia/customHooks';
import { useGetEndpointData } from '@app/jolokia/customHooks';

jest.mock('@openshift-console/dynamic-plugin-sdk', () => ({
VirtualizedTable: jest.fn(({ Row, data, columns }) => (
Expand Down Expand Up @@ -34,7 +34,7 @@ jest.mock('./AddressRow', () => ({

const mockUseJolokiaServiceReadAddressAttributes =
useJolokiaServiceGetAddresses as jest.Mock;
const mockUseJolokiaLogin = useJolokiaLogin as jest.Mock;
const mockUseJolokiaLogin = useGetEndpointData as jest.Mock;

describe('Addresses', () => {
const mockData = [
Expand Down
4 changes: 2 additions & 2 deletions src/addresses/Addresses/Address.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ type AddressesProps = {

const Addresses: FC<AddressesProps> = ({ isBrokerPod }) => {
const { t } = useTranslation();
const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);
const {
data: addressData,
isSuccess,
isLoading,
error: loadError,
} = useJolokiaServiceGetAddresses({
jolokiaSessionId: authToken,
targetEndpoint: authContext.targetEndpoint,
});

const columns: TableColumn<Address>[] = [
Expand Down
4 changes: 2 additions & 2 deletions src/addresses/Addresses/AddressRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export const AddressRow: FC<AddressRowProps> = ({
columns,
}) => {
const { name } = obj;
const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);
const { data: routingTypes, isSuccess } =
useJolokiaServiceReadAddressAttributes({
jolokiaSessionId: authToken,
name: name,
attrs: ['RoutingTypes'],
targetEndpoint: authContext.targetEndpoint,
});

return (
Expand Down
47 changes: 3 additions & 44 deletions src/brokers/broker-details/BrokerDetails.container.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useContext } from 'react';
import { FC } from 'react';
import {
Tabs,
Tab,
Expand All @@ -7,7 +7,6 @@ import {
PageSection,
PageSectionVariants,
Alert,
Spinner,
} from '@patternfly/react-core';
import { useTranslation } from '@app/i18n/i18n';
import { ClientsContainer } from './components/Clients/Clients.container';
Expand All @@ -28,12 +27,7 @@ import {
} from 'react-router-dom-v5-compat';
import { JolokiaAuthentication } from '@app/jolokia/components/JolokiaAuthentication';
import { useGetBrokerCR } from '@app/k8s/customHooks';
import { AuthContext } from '@app/jolokia/context';
import { BrokerCR } from '@app/k8s/types';
import {
GreenCheckCircleIcon,
RedExclamationCircleIcon,
} from '@openshift-console/dynamic-plugin-sdk';

type AuthenticatedPageContentPropType = {
brokerCr: BrokerCR;
Expand All @@ -58,11 +52,6 @@ const AuthenticatedPageContent: FC<AuthenticatedPageContentPropType> = ({
searchParams.set('tab', eventKey.toString());
navigate({ search: searchParams.toString() });
};
const {
isSuccess: isSuccessToken,
isLoading: isLoadingToken,
isError: isErrorToken,
} = useContext(AuthContext);
return (
<PageSection
variant={PageSectionVariants.light}
Expand Down Expand Up @@ -100,22 +89,7 @@ const AuthenticatedPageContent: FC<AuthenticatedPageContentPropType> = ({
{process.env.NODE_ENV === 'development' && (
<Tab
eventKey={'jolokiaTestPanel'}
title={
<TabTitleText>
{t('check-jolokia ')}
{isLoadingToken && (
<Spinner size="sm" aria-label={t('connecting to jolokia')} />
)}
{isSuccessToken && (
<GreenCheckCircleIcon title={t('Jolokia connected')} />
)}
{isErrorToken && (
<RedExclamationCircleIcon
title={t('Jolokia connection failed')}
/>
)}
</TabTitleText>
}
title={<TabTitleText>{t('check-jolokia ')}</TabTitleText>}
>
<JolokiaTestPanel />
<br />
Expand All @@ -124,22 +98,7 @@ const AuthenticatedPageContent: FC<AuthenticatedPageContentPropType> = ({
{process.env.NODE_ENV === 'development' && (
<Tab
eventKey={'jolokia-details'}
title={
<TabTitleText>
{t('jolokia-details')}
{isLoadingToken && (
<Spinner size="sm" aria-label={t('connecting to jolokia')} />
)}
{isSuccessToken && (
<GreenCheckCircleIcon title={t('Jolokia connected')} />
)}
{isErrorToken && (
<RedExclamationCircleIcon
title={t('Jolokia connection failed')}
/>
)}
</TabTitleText>
}
title={<TabTitleText>{t('jolokia-details')}</TabTitleText>}
>
<Tabs defaultActiveKey={0}>
<Tab
Expand Down
73 changes: 43 additions & 30 deletions src/brokers/broker-details/components/JolokiaDevComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const SignatureSubForm: FC<SignatureSubFormType> = ({
name,
signature,
}) => {
const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);
const [formValues, setFormvalues] = useState<Record<string, string>>({});
const update = (name: string, value: string) => {
const newFormValues = { ...formValues };
Expand Down Expand Up @@ -105,7 +105,7 @@ export const SignatureSubForm: FC<SignatureSubFormType> = ({
return;
}
execRequest({
jolokiaSessionId: authToken,
targetEndpoint: authContext.targetEndpoint,
requestBody: {
signature: {
name: name,
Expand Down Expand Up @@ -205,7 +205,7 @@ export const FetchAttr: FC<DisplayDetailsType> = ({
acceptor,
queue,
}) => {
const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);
const [formSelectValue, setFormSelectValue] = useState('');

const onChange = (value: string) => {
Expand Down Expand Up @@ -233,24 +233,30 @@ export const FetchAttr: FC<DisplayDetailsType> = ({
queryFn: () => {
if (queue) {
return JolokiaService.readQueueAttributes(
authToken,
queue.name,
queue.address.name,
queue['routing-type'],
authContext.targetEndpoint,
[formSelectValue],
);
}
if (acceptor) {
return JolokiaService.readAcceptorAttributes(authToken, acceptor.name, [
formSelectValue,
]);
return JolokiaService.readAcceptorAttributes(
acceptor.name,
authContext.targetEndpoint,
[formSelectValue],
);
}
if (address) {
return JolokiaService.readAddressAttributes(authToken, address.name, [
formSelectValue,
]);
return JolokiaService.readAddressAttributes(
address.name,
authContext.targetEndpoint,
[formSelectValue],
);
}
return JolokiaService.readBrokerAttributes(authToken, [formSelectValue]);
return JolokiaService.readBrokerAttributes(authContext.targetEndpoint, [
formSelectValue,
]);
},
enabled: formSelectValue !== '',
});
Expand Down Expand Up @@ -296,16 +302,16 @@ export const FetchAttr: FC<DisplayDetailsType> = ({
};

export const JolokiaBrokerDetails: FC = () => {
const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);

const { data: brokers, isSuccess: brokersSuccess } =
useJolokiaServiceGetBrokers({ jolokiaSessionId: authToken });
useJolokiaServiceGetBrokers({ targetEndpoint: authContext.targetEndpoint });

const broker0Name = brokersSuccess ? brokers[0].name : '';

const { data: brokersDetails, isSuccess: isSuccesBrokersDetails } = useQuery({
queryKey: [useJolokiaServiceGetBrokerDetailsKey + broker0Name],
queryFn: () => JolokiaService.getBrokerDetails(authToken),
queryFn: () => JolokiaService.getBrokerDetails(authContext.targetEndpoint),
enabled: brokersSuccess,
});
if (!isSuccesBrokersDetails) {
Expand All @@ -324,17 +330,22 @@ export const JolokiaBrokerDetails: FC = () => {
};

export const JolokiaAddressDetails: FC = () => {
const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);
const [selectedAddress, setSelectedAddress] = useState('');

const { data: addresses, isSuccess: addressesSuccess } =
useJolokiaServiceGetAddresses({ jolokiaSessionId: authToken });
useJolokiaServiceGetAddresses({
targetEndpoint: authContext.targetEndpoint,
});

const { data: addressDetails, isSuccess: isSuccessAddressDetails } = useQuery(
{
queryKey: [useJolokiaServiceGetAddressDetailsKey + selectedAddress],
queryFn: () =>
JolokiaService.getAddressDetails(authToken, selectedAddress),
JolokiaService.getAddressDetails(
authContext.targetEndpoint,
selectedAddress,
),
enabled: addressesSuccess && selectedAddress !== '',
},
);
Expand Down Expand Up @@ -377,17 +388,22 @@ export const JolokiaAddressDetails: FC = () => {
};

export const JolokiaAcceptorDetails: FC = () => {
const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);
const [selectedAcceptor, setSelectedAcceptor] = useState('');

const { data: acceptors, isSuccess: isAcceptorsSuccess } =
useJolokiaServiceGetAcceptors({ jolokiaSessionId: authToken });
useJolokiaServiceGetAcceptors({
targetEndpoint: authContext.targetEndpoint,
});

const { data: addressDetails, isSuccess: isSuccessAddressDetails } = useQuery(
{
queryKey: [useJolokiaServiceGetAcceptorsKey + selectedAcceptor],
queryFn: () =>
JolokiaService.getAcceptorDetails(authToken, selectedAcceptor),
JolokiaService.getAcceptorDetails(
authContext.targetEndpoint,
selectedAcceptor,
),
enabled: isAcceptorsSuccess && selectedAcceptor !== '',
},
);
Expand Down Expand Up @@ -430,11 +446,11 @@ export const JolokiaAcceptorDetails: FC = () => {
};

export const JolokiaQueueDetails: FC = () => {
const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);
const [selectedQueue, setSelectesQueue] = useState('');

const { data: queues, isSuccess: isQueueSuccess } =
useJolokiaServiceGetQueues({ jolokiaSessionId: authToken });
useJolokiaServiceGetQueues({ targetEndpoint: authContext.targetEndpoint });

const queue =
selectedQueue !== ''
Expand All @@ -445,7 +461,7 @@ export const JolokiaQueueDetails: FC = () => {
queryKey: [useJolokiaServiceGetQueueDetailsKey + selectedQueue],
queryFn: () =>
JolokiaService.getQueueDetails(
authToken,
authContext.targetEndpoint,
queue.name,
queue['routing-type'],
queue.address.name,
Expand Down Expand Up @@ -486,7 +502,7 @@ const JolokiaTestPanel: FC = () => {
const [jolokiaTestResult, setJolokiaTestResult] = useState('Result:');
const [requestError, setRequestError] = useState(false);

const { token: authToken } = useContext(AuthContext);
const authContext = useContext(AuthContext);

const setError = (error: string) => {
setJolokiaTestResult(error);
Expand Down Expand Up @@ -542,9 +558,7 @@ const JolokiaTestPanel: FC = () => {
const encodedUrl = testUrl.replace(/,/g, '%2C');
fetch(encodedUrl, {
method: 'GET', // *GET, POST, PUT, DELETE, etc.
headers: {
'jolokia-session-id': authToken,
},
headers: {},
})
.then((result): void => {
if (result.ok) {
Expand Down Expand Up @@ -588,7 +602,7 @@ const JolokiaTestPanel: FC = () => {
}
/>
<div>
<Button name="query" onClick={onButtonClick} disabled={!authToken}>
<Button name="query" onClick={onButtonClick}>
Submit query
</Button>
&nbsp;&nbsp;&nbsp;
Expand All @@ -600,7 +614,7 @@ const JolokiaTestPanel: FC = () => {
name="exec"
onClick={() =>
performExecBrokerOperation({
jolokiaSessionId: authToken,
targetEndpoint: authContext.targetEndpoint,
requestBody: {
signature: {
name: 'listAddresses',
Expand All @@ -614,7 +628,6 @@ const JolokiaTestPanel: FC = () => {
},
})
}
disabled={!authToken}
>
Test Operation
</Button>
Expand Down
Loading

0 comments on commit d469ca6

Please sign in to comment.