Skip to content

Commit

Permalink
Merge pull request #381 from gigapipehq/dev
Browse files Browse the repository at this point in the history
Update: Cardinality auth
  • Loading branch information
jacovinus authored Dec 11, 2023
2 parents 19e27b6 + b4da0b1 commit 5b53d7b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/main/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
43 changes: 30 additions & 13 deletions packages/main/plugins/Cardinality/api/CardinalityRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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=" +
Expand All @@ -98,6 +101,7 @@ export const deleteFingerprints = async (

headers: {
...headers,
Authorization: `Basic ${btoa(u + ":" + p)}`,
},
}).then((response) => {
if (
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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("");
Expand All @@ -284,7 +297,8 @@ export const useCardinalityRequest = (
setError,
setDeletedQueries,
setIsLoading,
headers
headers,
user_pass
);
};

Expand All @@ -294,7 +308,8 @@ export const useCardinalityRequest = (
setError,
setDeletedQueries,
setIsLoading,
headers
headers,
user_pass
);
};

Expand All @@ -312,7 +327,8 @@ export const useCardinalityRequest = (
setError,
setIsLoading,
setTsdbStatus,
headers
headers,
user_pass
);
};

Expand All @@ -324,7 +340,8 @@ export const useCardinalityRequest = (
setError,
setIsLoading,
setTsdbStatus,
headers
headers,
user_pass
);
}
}, [url, match, focusLabel, topN, date]);
Expand Down
6 changes: 5 additions & 1 deletion packages/main/plugins/Cardinality/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5b53d7b

Please sign in to comment.