Icu 12592 add filtering pagination support for auth methods (#2209)

* feat: 🎸 add filtering & pagination to auth methods

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12592

---------

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
This commit is contained in:
authored and Zhihe Li committed 2024-04-12 14:55:34 -04:00
1 parent 13da35c06b
commit ded8bdadd1
22 files changed
+623 -327

No files matched your search

@@ -20,10 +20,15 @@ export default class IndexedDbHandler {
switch (context.request.op) {
case 'query': {
const { store, data } = context.request;
// TODO: Remove storeToken option as this is a temporary fix for auth-methods.
const {
type,
query,
options: { pushToStore = true, peekIndexedDB = false } = {},
options: {
pushToStore = true,
peekIndexedDB = false,
storeToken = true,
} = {},
} = data;
const supportedModels = Object.keys(modelIndexes);
const { db: indexedDb } = this.indexedDb ?? {};
@@ -42,7 +47,11 @@ export default class IndexedDbHandler {
if (!peekIndexedDB) {
const tokenKey = `${type}-${hashCode(remainingQuery)}`;
const listToken = await indexedDb.token.get(tokenKey);
let listToken;
if (storeToken) {
listToken = await indexedDb.token.get(tokenKey);
}
let payload;
try {
@@ -77,7 +86,7 @@ export default class IndexedDbHandler {
}
// Store the token we just got back from the payload if it exists
if (payload.list_token) {
if (payload.list_token && storeToken) {
await indexedDb.token.put({
id: tokenKey,
token: payload.list_token,
+2
View File
@@ -22,6 +22,8 @@ export const modelIndexes = {
'&id, attributes.created_time, attributes.name, attributes.description, attributes.type, attributes.scope.scope_id',
'host-catalog':
'&id, attributes.created_time, attributes.type, attributes.name, attributes.description, attributes.scope.scope_id, attributes.plugin.name',
'auth-method':
'&id, attributes.created_time, attributes.type, attributes.name, attributes.description, attributes.is_primary, attributes.scope.scope_id',
};
export const formatDbName = (userId, clusterUrl) =>
+1 -22
View File
@@ -117,28 +117,7 @@ function routes() {
);
// Auth & IAM resources
this.get(
'/auth-methods',
({ authMethods }, { queryParams: { scope_id, recursive, filter } }) => {
let resultSet;
if (recursive && scope_id === 'global') {
resultSet = authMethods.all();
} else if (recursive) {
resultSet = authMethods.where((authMethod) => {
const authMethodModel = authMethods.find(authMethod.id);
return (
authMethod.scopeId === scope_id ||
authMethodModel?.scope?.scope?.id === scope_id
);
});
} else {
resultSet = authMethods.where(
(authMethod) => authMethod.scopeId === scope_id,
);
}
return resultSet.filter(makeBooleanFilter(filter));
},
);
this.get('/auth-methods');
this.post('/auth-methods', function ({ authMethods }) {
const attrs = this.normalizedRequestAttrs();
if (attrs.type === 'oidc') {