-
Notifications
You must be signed in to change notification settings - Fork 55
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
Changes to integrate rate-limit headers for Commands left
component UI
#67
Merged
lucifercr07
merged 20 commits into
DiceDB:master
from
aasifkhan7:integrate_ratelimit_commandsleft
Oct 18, 2024
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
268adb2
1. commands left to be fixed dynamically. 2. assuming that cleanup ti…
cae29cd
fixed error handling in case of wrong commands
bb205a8
refactor: added the handleResult method in commonUtils.ts
38582df
remove the hardcoded headers
d146475
added test case for rate-limit
4463636
remove unnecessary comment
fdfa9ac
fixed comment above test case
d5638fd
fix formatting issues
e2411a7
fix formatting issues in src/lib/__tests__/api.test.ts
2764ad7
backmerge
10fe0a2
fix build error
811e758
remove changes to integrate cleanup time
6eb234d
added validation of zod
dc2c628
refactor
75a60d1
handle error in every condition
8fce1d1
remove redundant nullable from ErrorSchema
947bf44
resolve build failures
63a58f9
fixed tests
dbdc650
removed CLI
cfb6843
Merge remote-tracking branch 'dicedb/master' into integrate_ratelimit…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
// src/lib/api.ts | ||
import { WebService } from '@/services/webServices'; | ||
|
||
import { MonoResponse } from './monoResponse'; | ||
|
||
export const executeShellCommandOnServer = async ( | ||
cmd: string, | ||
cmdOptions: object, | ||
) => { | ||
): Promise<{ headers: { [key: string]: string }; body: MonoResponse }> => { | ||
const cmdExecURL = `/shell/exec/${cmd}`; | ||
|
||
try { | ||
const response = await WebService.post(cmdExecURL, cmdOptions); | ||
|
||
// Check if the response contains data or if it's an error response | ||
if (response?.data) { | ||
return response.data; | ||
} else if (response?.error) { | ||
return response.error; | ||
if (response?.body?.data) { | ||
return response; | ||
} else if (response?.body?.error) { | ||
return response; | ||
} else { | ||
throw new Error('Unexpected response structure'); | ||
} | ||
} catch (error) { | ||
// Propagate the error from the backend exactly as it is | ||
console.error('Error executing command:', error); | ||
return `${error}`; // Just return the error message directly | ||
throw new Error(`${error}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface MonoResponse { | ||
data: string | null; | ||
error: string | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { z } from 'zod'; | ||
|
||
const BodySchema = z.object({ | ||
data: z.string(), | ||
}); | ||
|
||
// Define the schema for an error response | ||
const ErrorSchema = z.object({ | ||
error: z.string(), | ||
}); | ||
|
||
// Combine the schemas | ||
export const MonoSchema = z.union([BodySchema, ErrorSchema]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have a type defined here? preferrably using zod schema. Idea is to ensure and catch early if there is an issue with the response.
right now, we just have a lot of
any
which should be avoided