From ecfb4defffc51cd06f48d06ee8eea82d051ca702 Mon Sep 17 00:00:00 2001 From: jacovinus Date: Mon, 11 Dec 2023 16:41:38 +0100 Subject: [PATCH 1/2] update: version --- packages/main/package.json | 2 +- pnpm-lock.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/main/package.json b/packages/main/package.json index a79b8f78..029bb98c 100644 --- a/packages/main/package.json +++ b/packages/main/package.json @@ -1,7 +1,7 @@ { "name": "@ui/main", "private": true, - "version": "0.25.1", + "version": "0.27.3", "type": "module", "scripts": { "dev": "VITE_APP_VERSION=$npm_package_version vite", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 65a6210c..a797f352 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' settings: autoInstallPeers: true From 30e684e7867e0edaf4ba487b294c04056eb368af Mon Sep 17 00:00:00 2001 From: jacovinus Date: Mon, 11 Dec 2023 17:41:03 +0100 Subject: [PATCH 2/2] fix: cardinality auth --- .../Cardinality/api/CardinalityRequest.tsx | 43 +++++++++++++------ packages/main/plugins/Cardinality/helpers.tsx | 6 ++- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/packages/main/plugins/Cardinality/api/CardinalityRequest.tsx b/packages/main/plugins/Cardinality/api/CardinalityRequest.tsx index 9153f158..bb0bd830 100644 --- a/packages/main/plugins/Cardinality/api/CardinalityRequest.tsx +++ b/packages/main/plugins/Cardinality/api/CardinalityRequest.tsx @@ -39,18 +39,20 @@ export const getDeletedFingerprints = async ( setError, setDeletedQueries, setIsLoading, - headers + headers, + auth ) => { const deleteEndpoint = import.meta.env.VITE_API_DELETE_URL || url; try { setIsLoading(true); const urlDelete = deleteEndpoint + "/loki/api/v1/delete"; - + const { u, p } = auth; await fetch(urlDelete, { method: "GET", headers: { ...headers, + Authorization: `Basic ${btoa(u + ":" + p)}`, }, }).then((response) => { if ( @@ -76,14 +78,15 @@ export const deleteFingerprints = async ( setError, setDeleteQueries, setIsLoading, - headers + headers, + auth ) => { const deleteEndpoint = import.meta.env.VITE_API_DELETE_URL || url; try { // start and end should calculated according to current date in seconds setIsLoading(true); - + const { u, p } = auth; const urlDelete = deleteEndpoint + "/loki/api/v1/delete?query=" + @@ -98,6 +101,7 @@ export const deleteFingerprints = async ( headers: { ...headers, + Authorization: `Basic ${btoa(u + ":" + p)}`, }, }).then((response) => { if ( @@ -150,10 +154,10 @@ const requestCardinality = async ( setError: (error: string) => void, setIsLoading: (isLoading: boolean) => void, setTsdbStatus: (tsdbStatus: any) => void, - headers: any + headers: any, + auth: { u: string; p: string } ) => { const { match } = reqParams; - const totalParams = { date: reqParams.date, topN: 0, @@ -177,10 +181,18 @@ const requestCardinality = async ( setIsLoading(true); // set //this makes the multiple fetch requests - + try { + const { u, p } = auth; const responses = await Promise.all( - urls.map((url) => fetch(url, { headers })) + urls.map((url) => + fetch(url, { + headers: { + ...headers, + Authorization: `Basic ${btoa(u + ":" + p)}`, + }, + }) + ) ); // add headers and auth in here . make it with axios if (responses[0].status === 400 || responses[0].status === 500) { @@ -262,7 +274,8 @@ export const useCardinalityRequest = ( const reqParams = { match, focusLabel, topN, date: reqDate }; - const { url, headers } = useDataSourceData("logs"); + const { url, headers, user_pass } = useDataSourceData("logs"); + // const [isLoading, setIsLoading] = useState(false); // const [error, setError] = useState(""); @@ -284,7 +297,8 @@ export const useCardinalityRequest = ( setError, setDeletedQueries, setIsLoading, - headers + headers, + user_pass ); }; @@ -294,7 +308,8 @@ export const useCardinalityRequest = ( setError, setDeletedQueries, setIsLoading, - headers + headers, + user_pass ); }; @@ -312,7 +327,8 @@ export const useCardinalityRequest = ( setError, setIsLoading, setTsdbStatus, - headers + headers, + user_pass ); }; @@ -324,7 +340,8 @@ export const useCardinalityRequest = ( setError, setIsLoading, setTsdbStatus, - headers + headers, + user_pass ); } }, [url, match, focusLabel, topN, date]); diff --git a/packages/main/plugins/Cardinality/helpers.tsx b/packages/main/plugins/Cardinality/helpers.tsx index 493b3393..f67787cc 100644 --- a/packages/main/plugins/Cardinality/helpers.tsx +++ b/packages/main/plugins/Cardinality/helpers.tsx @@ -229,15 +229,19 @@ export const useDataSourceData = (type: string) => { const isAuth = authData.basicAuth.value; + let user_pass= {u: '', p:''} + if (isAuth) { let [user, password] = authData.fields.basicAuth; let passwordValue = password.value; let userValue = user.value; + user_pass.u = user?.value; + user_pass.p = password?.value; auth = serializeUserPassword(userValue, passwordValue); } - return { url, auth, headers: reqHeaders }; + return { url, auth, user_pass, headers: reqHeaders }; }; // gets the data from the CardinalityStore