-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AAP-30986: Support deletion of WCA API_KEY from Admin Portal (Fronten…
…d) (#1333)
- Loading branch information
Showing
12 changed files
with
413 additions
and
152 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
ansible_ai_connect_admin_portal/config/webpack.mock.api.keys.modelids.ts
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,132 @@ | ||
import { | ||
delay, | ||
DELAY_MS, | ||
ERROR_DESCRIPTION, | ||
ORG_ID, | ||
} from "./webpack.mock.globals"; | ||
|
||
const webpackMockServer = require("webpack-mock-server"); | ||
|
||
export default webpackMockServer.add((app, helper) => { | ||
const KEY_FIELD = "key"; | ||
const MODEL_ID_FIELD = "model_id"; | ||
const LAST_UPDATED_FIELD = "last_update"; | ||
|
||
const keys = new Map<string, { key: string; last_update: Date }>(); | ||
const modelIds = new Map<string, { model_id: string; last_update: Date }>(); | ||
|
||
//API KEY RELATED ENDPOINTS | ||
app.get("/api/v0/wca/apikey/", async (_req, res) => { | ||
await delay(DELAY_MS); | ||
if (keys.has(ORG_ID)) { | ||
// Key response only contains the Last Updated field | ||
const data = keys.get(ORG_ID); | ||
res.json({ last_update: data[LAST_UPDATED_FIELD] }); | ||
} else { | ||
res.json({}); | ||
} | ||
}); | ||
|
||
app.get("/api/v0/wca/apikey/test/", async (_req, res) => { | ||
await delay(DELAY_MS); | ||
if (!keys.has(ORG_ID)) { | ||
res.sendStatus(404); | ||
return; | ||
} else { | ||
const data = keys.get(ORG_ID); | ||
const key = data[KEY_FIELD]; | ||
if (key === "error-test") { | ||
// Emulate a server-side error | ||
res.status(500).json({ detail: ERROR_DESCRIPTION }); | ||
return; | ||
} | ||
if (key === "invalid-test") { | ||
// Emulate an invalid API Key | ||
res.sendStatus(400); | ||
return; | ||
} | ||
} | ||
res.sendStatus(200); | ||
}); | ||
|
||
app.post("/api/v0/wca/apikey/", async (_req, res) => { | ||
await delay(DELAY_MS); | ||
const key = _req.body["key"]; | ||
if (key === "error") { | ||
// Emulate a server-side error | ||
res.status(500).json({ detail: ERROR_DESCRIPTION }); | ||
return; | ||
} | ||
if (key === "invalid") { | ||
// Emulate an invalid API Key | ||
res.sendStatus(400); | ||
return; | ||
} | ||
const entry = { key: key, last_update: new Date() }; | ||
keys.set(ORG_ID, entry); | ||
res.sendStatus(200); | ||
}); | ||
|
||
app.delete("/api/v0/wca/apikey/", async (_req, res) => { | ||
await delay(DELAY_MS); | ||
if (keys.has(ORG_ID)) { | ||
keys.delete(ORG_ID); | ||
if (modelIds.has(ORG_ID)) { | ||
modelIds.delete(ORG_ID); | ||
} | ||
res.sendStatus(200); | ||
} else { | ||
res.sendStatus(400); | ||
} | ||
}); | ||
|
||
//MODEL ID RELATED ENDPOINTS | ||
app.get("/api/v0/wca/modelid/", async (_req, res) => { | ||
await delay(DELAY_MS); | ||
if (modelIds.has(ORG_ID)) { | ||
res.json(modelIds.get(ORG_ID)); | ||
} else { | ||
res.json({}); | ||
} | ||
}); | ||
|
||
app.get("/api/v0/wca/modelid/test/", async (_req, res) => { | ||
await delay(DELAY_MS); | ||
if (!modelIds.has(ORG_ID)) { | ||
res.sendStatus(404); | ||
return; | ||
} else { | ||
const data = modelIds.get(ORG_ID); | ||
const modelId = data[MODEL_ID_FIELD]; | ||
if (modelId === "error-test") { | ||
// Emulate a server-side error | ||
res.status(500).json({ detail: ERROR_DESCRIPTION }); | ||
return; | ||
} | ||
if (modelId === "invalid-test") { | ||
// Emulate an invalid Model Id | ||
res.sendStatus(400); | ||
return; | ||
} | ||
} | ||
res.sendStatus(200); | ||
}); | ||
|
||
app.post("/api/v0/wca/modelid/", async (_req, res) => { | ||
await delay(DELAY_MS); | ||
const modelId = _req.body[MODEL_ID_FIELD]; | ||
if (modelId === "error") { | ||
// Emulate a server-side error | ||
res.status(500).json({ detail: ERROR_DESCRIPTION }); | ||
return; | ||
} | ||
if (modelId === "invalid") { | ||
// Emulate an invalid Model Id | ||
res.sendStatus(400); | ||
return; | ||
} | ||
const entry = { model_id: modelId, last_update: new Date() }; | ||
modelIds.set(ORG_ID, entry); | ||
res.sendStatus(200); | ||
}); | ||
}); |
65 changes: 0 additions & 65 deletions
65
ansible_ai_connect_admin_portal/config/webpack.mock.api.keys.ts
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
ansible_ai_connect_admin_portal/config/webpack.mock.api.modelids.ts
This file was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -15,3 +15,7 @@ | |
.Loading { | ||
height: 200px; | ||
} | ||
|
||
.Hidden { | ||
visibility: hidden; | ||
} |
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.