forked from phoenix/litellm-mirror
feat(ui): enable admin to view all valid keys created on the proxy
This commit is contained in:
parent
cdbbedec36
commit
f2a7e2ee98
7 changed files with 312 additions and 209 deletions
|
@ -1,24 +1,24 @@
|
|||
/**
|
||||
* Helper file for calls being made to proxy
|
||||
*/
|
||||
import { message } from 'antd';
|
||||
import { message } from "antd";
|
||||
|
||||
const proxyBaseUrl = null;
|
||||
// const proxyBaseUrl = "http://localhost:4000" // http://localhost:4000
|
||||
const isLocal = process.env.NODE_ENV === "development";
|
||||
const proxyBaseUrl = isLocal ? "http://localhost:4000" : null;
|
||||
|
||||
export const keyCreateCall = async (
|
||||
accessToken: string,
|
||||
userID: string,
|
||||
formValues: Record<string, any>, // Assuming formValues is an object
|
||||
formValues: Record<string, any> // Assuming formValues is an object
|
||||
) => {
|
||||
try {
|
||||
console.log("Form Values in keyCreateCall:", formValues); // Log the form values before making the API call
|
||||
|
||||
console.log("Form Values in keyCreateCall:", formValues); // Log the form values before making the API call
|
||||
|
||||
// check if formValues.description is not undefined, make it a string and add it to formValues.metadata
|
||||
if (formValues.description) {
|
||||
// add to formValues.metadata
|
||||
if (!formValues.metadata) {
|
||||
formValues.metadata = {}
|
||||
formValues.metadata = {};
|
||||
}
|
||||
// value needs to be in "", valid JSON
|
||||
formValues.metadata.description = formValues.description;
|
||||
|
@ -26,7 +26,7 @@ export const keyCreateCall = async (
|
|||
delete formValues.description;
|
||||
formValues.metadata = JSON.stringify(formValues.metadata);
|
||||
}
|
||||
// if formValues.metadata is not undefined, make it a valid dict
|
||||
// if formValues.metadata is not undefined, make it a valid dict
|
||||
if (formValues.metadata) {
|
||||
console.log("formValues.metadata:", formValues.metadata);
|
||||
// if there's an exception JSON.parse, show it in the message
|
||||
|
@ -69,15 +69,11 @@ export const keyCreateCall = async (
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
export const keyDeleteCall = async (
|
||||
accessToken: String,
|
||||
user_key: String
|
||||
) => {
|
||||
export const keyDeleteCall = async (accessToken: String, user_key: String) => {
|
||||
try {
|
||||
const url = proxyBaseUrl ? `${proxyBaseUrl}/key/delete` : `/key/delete`;
|
||||
console.log("in keyDeleteCall:", user_key)
|
||||
|
||||
console.log("in keyDeleteCall:", user_key);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -108,21 +104,22 @@ export const keyDeleteCall = async (
|
|||
|
||||
export const userInfoCall = async (
|
||||
accessToken: String,
|
||||
userID: String
|
||||
userID: String,
|
||||
userRole: String
|
||||
) => {
|
||||
try {
|
||||
const url = proxyBaseUrl ? `${proxyBaseUrl}/user/info` : `/user/info`;
|
||||
console.log("in userInfoCall:", url)
|
||||
const response = await fetch(
|
||||
`${url}/?user_id=${userID}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
let url = proxyBaseUrl ? `${proxyBaseUrl}/user/info` : `/user/info`;
|
||||
if (userRole == "App Owner") {
|
||||
url = `${url}/?user_id=${userID}`;
|
||||
}
|
||||
message.info("Requesting user data");
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.text();
|
||||
|
@ -131,7 +128,7 @@ export const userInfoCall = async (
|
|||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
message.info("Received user data");
|
||||
return data;
|
||||
// Handle success - you might want to update some state or UI based on the created key
|
||||
} catch (error) {
|
||||
|
@ -140,24 +137,17 @@ export const userInfoCall = async (
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
export const keySpendLogsCall = async (
|
||||
accessToken: String,
|
||||
token: String
|
||||
) => {
|
||||
export const keySpendLogsCall = async (accessToken: String, token: String) => {
|
||||
try {
|
||||
const url = proxyBaseUrl ? `${proxyBaseUrl}/spend/logs` : `/spend/logs`;
|
||||
console.log("in keySpendLogsCall:", url)
|
||||
const response = await fetch(
|
||||
`${url}/?api_key=${token}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
console.log("in keySpendLogsCall:", url);
|
||||
const response = await fetch(`${url}/?api_key=${token}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
const errorData = await response.text();
|
||||
message.error(errorData);
|
||||
|
@ -171,4 +161,4 @@ export const keySpendLogsCall = async (
|
|||
console.error("Failed to create key:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue