From a3b65bcf42dc17ca6bad9986738c635a68bef869 Mon Sep 17 00:00:00 2001 From: Martynov Maxim Date: Mon, 5 Aug 2024 16:57:35 +0300 Subject: [PATCH] Web: encode job name in API requests Signed-off-by: Martynov Maxim --- web/src/store/requests/datasets.ts | 65 +++++++++++++++++------------- web/src/store/requests/jobs.ts | 28 ++++++++----- web/src/store/sagas/index.ts | 12 +++--- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/web/src/store/requests/datasets.ts b/web/src/store/requests/datasets.ts index 97eb134dde..b4deb2b3ee 100644 --- a/web/src/store/requests/datasets.ts +++ b/web/src/store/requests/datasets.ts @@ -6,9 +6,8 @@ import { Dataset, DatasetVersions, Datasets } from '../../types/api' import { genericFetchWrapper } from './index' export const getDatasets = async (namespace: string, limit = 20, offset = 0) => { - const url = `${API_URL}/namespaces/${encodeURIComponent( - namespace - )}/datasets?limit=${limit}&offset=${offset}` + const encodedNamespace = encodeURIComponent(namespace) + const url = `${API_URL}/namespaces/${encodedNamespace}/datasets?limit=${limit}&offset=${offset}` return genericFetchWrapper(url, { method: 'GET' }, 'fetchDatasets').then((r: Datasets) => { return { datasets: r.datasets.map((d) => ({ ...d, namespace: namespace })), @@ -19,13 +18,13 @@ export const getDatasets = async (namespace: string, limit = 20, offset = 0) => export const getDatasetVersions = async ( namespace: string, - dataset: string, + datasetName: string, limit: number, offset: number ) => { - const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/datasets/${encodeURIComponent( - dataset - )}/versions?limit=${limit}&offset=${offset}` + const encodedNamespace = encodeURIComponent(namespace) + const encodedDataset = encodeURIComponent(datasetName) + const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/versions?limit=${limit}&offset=${offset}` return genericFetchWrapper(url, { method: 'GET' }, 'fetchDatasetVersions').then( (r: DatasetVersions) => { return { versions: r.versions, totalCount: r.totalCount } @@ -33,52 +32,60 @@ export const getDatasetVersions = async ( ) } -export const getDataset = async (namespace: string, dataset: string) => { - const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/datasets/${encodeURIComponent( - dataset - )}` +export const getDataset = async (namespace: string, datasetName: string) => { + const encodedNamespace = encodeURIComponent(namespace) + const encodedDataset = encodeURIComponent(datasetName) + const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}` return genericFetchWrapper(url, { method: 'GET' }, 'fetchDataset').then((d: Dataset) => d) } -export const deleteDataset = async (datasetName: string, namespace: string) => { - const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/datasets/${datasetName}` +export const deleteDataset = async (namespace: string, datasetName: string) => { + const encodedNamespace = encodeURIComponent(namespace) + const encodedDataset = encodeURIComponent(datasetName) + const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}` return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteDataset') } export const deleteDatasetTag = async (namespace: string, datasetName: string, tag: string) => { - const url = `${API_URL}/namespaces/${encodeURIComponent( - namespace - )}/datasets/${datasetName}/tags/${tag}` + const encodedNamespace = encodeURIComponent(namespace) + const encodedDataset = encodeURIComponent(datasetName) + const encodedTag = encodeURIComponent(tag) + const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/tags/${encodedTag}` return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteDatasetTag') } export const addDatasetTag = async (namespace: string, datasetName: string, tag: string) => { - const url = `${API_URL}/namespaces/${encodeURIComponent( - namespace - )}/datasets/${datasetName}/tags/${tag}` + const encodedNamespace = encodeURIComponent(namespace) + const encodedDataset = encodeURIComponent(datasetName) + const encodedTag = encodeURIComponent(tag) + const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/tags/${encodedTag}` return genericFetchWrapper(url, { method: 'POST' }, 'addDatasetTag') } export const deleteDatasetFieldTag = async ( namespace: string, datasetName: string, - tag: string, - field: string + field: string, + tag: string ) => { - const url = `${API_URL}/namespaces/${encodeURIComponent( - namespace - )}/datasets/${datasetName}/fields/${field}/tags/${tag}` + const encodedNamespace = encodeURIComponent(namespace) + const encodedDataset = encodeURIComponent(datasetName) + const encodedField = encodeURIComponent(field) + const encodedTag = encodeURIComponent(tag) + const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/fields/${encodedField}/tags/${encodedTag}` return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteDatasetFieldTag') } export const addDatasetFieldTag = async ( namespace: string, datasetName: string, - tag: string, - field: string + field: string, + tag: string ) => { - const url = `${API_URL}/namespaces/${encodeURIComponent( - namespace - )}/datasets/${datasetName}/fields/${field}/tags/${tag}` + const encodedNamespace = encodeURIComponent(namespace) + const encodedDataset = encodeURIComponent(datasetName) + const encodedField = encodeURIComponent(field) + const encodedTag = encodeURIComponent(tag) + const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/fields/${encodedField}/tags/${encodedTag}` return genericFetchWrapper(url, { method: 'POST' }, 'addDatasetFieldTag') } diff --git a/web/src/store/requests/jobs.ts b/web/src/store/requests/jobs.ts index 59332e4725..e7d075e21b 100644 --- a/web/src/store/requests/jobs.ts +++ b/web/src/store/requests/jobs.ts @@ -14,8 +14,10 @@ export const getJobs = async (namespace: string, limit = 25, offset = 0) => { }) } -export const deleteJob = async (jobName: string, namespace: string) => { - const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${jobName}` +export const deleteJob = async (namespace: string, jobName: string) => { + const encodedNamespace = encodeURIComponent(namespace) + const encodedJob = encodeURIComponent(jobName) + const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}` return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteJob') } @@ -25,23 +27,31 @@ export const getRuns = async ( limit: number, offset: number ) => { - const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${encodeURIComponent( - jobName - )}/runs?limit=${limit}&offset=${offset}` + const encodedNamespace = encodeURIComponent(namespace) + const encodedJob = encodeURIComponent(jobName) + const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}/runs?limit=${limit}&offset=${offset}` return genericFetchWrapper(url, { method: 'GET' }, 'fetchRuns') } -export const getJob = async (namespace: string, job: string) => { - const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${job}` +export const getJob = async (namespace: string, jobName: string) => { + const encodedNamespace = encodeURIComponent(namespace) + const encodedJob = encodeURIComponent(jobName) + const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}` return genericFetchWrapper(url, { method: 'GET' }, 'fetchJob') } export const deleteJobTag = async (namespace: string, jobName: string, tag: string) => { - const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${jobName}/tags/${tag}` + const encodedNamespace = encodeURIComponent(namespace) + const encodedJob = encodeURIComponent(jobName) + const encodedTag = encodeURIComponent(tag) + const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}/tags/${encodedTag}` return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteJobTag') } export const addJobTag = async (namespace: string, jobName: string, tag: string) => { - const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${jobName}/tags/${tag}` + const encodedNamespace = encodeURIComponent(namespace) + const encodedJob = encodeURIComponent(jobName) + const encodedTag = encodeURIComponent(tag) + const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}/tags/${encodedTag}` return genericFetchWrapper(url, { method: 'POST' }, 'addJobTag') } diff --git a/web/src/store/sagas/index.ts b/web/src/store/sagas/index.ts index ed4e2c45c4..079a7c2e02 100644 --- a/web/src/store/sagas/index.ts +++ b/web/src/store/sagas/index.ts @@ -226,7 +226,7 @@ export function* deleteJobSaga() { while (true) { try { const { payload } = yield take(DELETE_JOB) - const job: Job = yield call(deleteJob, payload.jobName, payload.namespace) + const job: Job = yield call(deleteJob, payload.namespace, payload.jobName) yield put(deleteJobSuccess(job.name)) } catch (e) { yield put(applicationError('Something went wrong while removing job')) @@ -285,7 +285,7 @@ export function* deleteDatasetSaga() { while (true) { try { const { payload } = yield take(DELETE_DATASET) - const dataset: Dataset = yield call(deleteDataset, payload.datasetName, payload.namespace) + const dataset: Dataset = yield call(deleteDataset, payload.namespace, payload.datasetName) yield put(deleteDatasetSuccess(dataset.name)) } catch (e) { yield put(applicationError('Something went wrong while removing job')) @@ -325,8 +325,8 @@ export function* deleteDatasetFieldTagSaga() { deleteDatasetFieldTag, payload.namespace, payload.datasetName, - payload.tag, - payload.field + payload.field, + payload.tag ) yield put( deleteDatasetFieldTagSuccess( @@ -374,8 +374,8 @@ export function* addDatasetFieldTagSaga() { addDatasetFieldTag, payload.namespace, payload.datasetName, - payload.tag, - payload.field + payload.field, + payload.tag ) yield put( addDatasetFieldTagSuccess(