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

fix(archives): convert jvmId to subdirectoryName for web-client requests #991

Merged
merged 1 commit into from
Apr 25, 2023
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
3 changes: 1 addition & 2 deletions src/app/AppLayout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ import { Notification, NotificationsContext } from '@app/Notifications/Notificat
import { IAppRoute, navGroups, routes } from '@app/routes';
import { selectTab, SettingTab, tabAsParam, ThemeSetting } from '@app/Settings/SettingsUtils';
import { DynamicFeatureFlag, FeatureFlag } from '@app/Shared/FeatureFlag/FeatureFlag';
import { SessionState } from '@app/Shared/Services/Login.service';
import { NotificationCategory } from '@app/Shared/Services/NotificationChannel.service';
import { ServiceContext } from '@app/Shared/Services/Services';
import { FeatureLevel } from '@app/Shared/Services/Settings.service';
import { saveToLocalStorage } from '@app/utils/LocalStorage';
import { useLogin } from '@app/utils/useLogin';
import { useSubscriptions } from '@app/utils/useSubscriptions';
import { useTheme } from '@app/utils/useTheme';
import { cleanDataId, isAssetNew, openTabForUrl, portalRoot } from '@app/utils/utils';
Expand Down Expand Up @@ -104,7 +104,6 @@ import CryostatJoyride from '../Joyride/CryostatJoyride';
import { GlobalQuickStartDrawer } from '../QuickStarts/QuickStartDrawer';
import { AuthModal } from './AuthModal';
import { SslErrorModal } from './SslErrorModal';
import { useLogin } from '@app/utils/useLogin';
interface AppLayoutProps {
children: React.ReactNode;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ import { css } from '@patternfly/react-styles';
import * as React from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useHistory, useLocation } from 'react-router-dom';
import { paramAsTab, SettingTab, tabAsParam, _TransformedUserSetting } from './SettingsUtils';
import { AutoRefresh } from './AutoRefresh';
import { AutomatedAnalysisConfig } from './AutomatedAnalysisConfig';
import { AutoRefresh } from './AutoRefresh';
import { ChartCardsConfig } from './ChartCardsConfig';
import { CredentialsStorage } from './CredentialsStorage';
import { DatetimeControl } from './DatetimeControl';
import { DeletionDialogControl } from './DeletionDialogControl';
import { FeatureLevels } from './FeatureLevels';
import { Language } from './Language';
import { NotificationControl } from './NotificationControl';
import { paramAsTab, SettingTab, tabAsParam, _TransformedUserSetting } from './SettingsUtils';
import { Theme } from './Theme';
import { WebSocketDebounce } from './WebSocketDebounce';

Expand Down
15 changes: 7 additions & 8 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { Notifications } from '@app/Notifications/Notifications';
import { RecordingLabel } from '@app/RecordingMetadata/RecordingLabel';
import { Rule } from '@app/Rules/Rules';
import { EnvironmentNode } from '@app/Topology/typings';
import { createBlobURL } from '@app/utils/utils';
import { createBlobURL, jvmIdToSubdirectoryName } from '@app/utils/utils';
import { ValidatedOptions } from '@patternfly/react-core';
import _ from 'lodash';
import { EMPTY, forkJoin, from, Observable, ObservableInput, of, ReplaySubject, shareReplay, throwError } from 'rxjs';
Expand Down Expand Up @@ -513,15 +513,17 @@ export class ApiService {
}

// from file system path functions
uploadArchivedRecordingToGrafanaFromPath(subdirectoryName: string, recordingName: string): Observable<boolean> {
uploadArchivedRecordingToGrafanaFromPath(jvmId: string, recordingName: string): Observable<boolean> {
const subdirectoryName = jvmIdToSubdirectoryName(jvmId);
return this.sendRequest('beta', `fs/recordings/${subdirectoryName}/${encodeURIComponent(recordingName)}/upload`, {
method: 'POST',
}).pipe(
map((resp) => resp.ok),
first()
);
}
deleteArchivedRecordingFromPath(subdirectoryName: string, recordingName: string): Observable<boolean> {
deleteArchivedRecordingFromPath(jvmId: string, recordingName: string): Observable<boolean> {
const subdirectoryName = jvmIdToSubdirectoryName(jvmId);
return this.sendRequest('beta', `fs/recordings/${subdirectoryName}/${encodeURIComponent(recordingName)}`, {
method: 'DELETE',
}).pipe(
Expand All @@ -538,11 +540,8 @@ export class ApiService {
return JSON.stringify(rawLabels);
}

postRecordingMetadataFromPath(
subdirectoryName: string,
recordingName: string,
labels: RecordingLabel[]
): Observable<boolean> {
postRecordingMetadataFromPath(jvmId: string, recordingName: string, labels: RecordingLabel[]): Observable<boolean> {
const subdirectoryName = jvmIdToSubdirectoryName(jvmId);
return this.sendRequest(
'beta',
`fs/recordings/${subdirectoryName}/${encodeURIComponent(recordingName)}/metadata/labels`,
Expand Down
38 changes: 38 additions & 0 deletions src/app/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* SOFTWARE.
*/

import { UPLOADS_SUBDIRECTORY } from '@app/Shared/Services/Api.service';
import { ISortBy, SortByDirection } from '@patternfly/react-table';
import _ from 'lodash';
import { useHistory } from 'react-router-dom';
Expand Down Expand Up @@ -309,3 +310,40 @@ export const isAssetNew = (currVerStr: string) => {
// Invalid (old) version is ignored.
return !oldVer || compareSemVer(currVer, oldVer) > 0;
};

export const utf8ToBase32 = (str: string): string => {
const encoder = new TextEncoder();
const byteArray = encoder.encode(str);
const BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
let bits = 0;
let value = 0;
let base32 = '';

for (let i = 0; i < byteArray.length; i++) {
value = (value << 8) | byteArray[i];
bits += 8;
while (bits >= 5) {
bits -= 5;
base32 += BASE32_ALPHABET[(value >>> bits) & 0x1f];
}
}

if (bits > 0) {
value <<= 5 - bits;
base32 += BASE32_ALPHABET[value & 0x1f];
}

const paddingLength = base32.length % 8 !== 0 ? 8 - (base32.length % 8) : 0;
for (let i = 0; i < paddingLength; i++) {
base32 += '=';
}

return base32;
};

export const jvmIdToSubdirectoryName = (jvmId: string): string => {
if (jvmId === UPLOADS_SUBDIRECTORY || jvmId === 'lost') {
return jvmId;
}
return utf8ToBase32(jvmId);
};