feat: 🎸 add sqlite support for scopes (#2968)

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17415
This commit is contained in:
Lisbet Alvarez authored and Zhihe Li committed 2025-09-03 11:41:42 -04:00
1 parent 9e612cf83d
commit ba7b8b8824
76 files changed
+268 -14

No files matched your search

+9
View File
@@ -57,6 +57,14 @@ export const modelMapping = {
scope_id: 'scope.scope_id',
created_time: 'created_time',
},
scope: {
id: 'id',
type: 'type',
name: 'name',
description: 'description',
scope_id: 'scope.scope_id',
created_time: 'created_time',
},
};
// A list of tables that we support searching using FTS5 in SQLite.
@@ -66,6 +74,7 @@ export const searchTables = new Set([
'role',
'user',
'credential-store',
'scope',
]);
export default class SqliteDbService extends Service {
+36
View File
@@ -195,6 +195,41 @@ CREATE TRIGGER IF NOT EXISTS credential_store_ad AFTER DELETE ON credential_stor
VALUES('delete', old.rowid, old.id, old.type, old.name, old.description, old.scope_id, old.created_time);
END;`;
const createScopeTables = `
CREATE TABLE IF NOT EXISTS scope (
id TEXT NOT NULL PRIMARY KEY,
type TEXT NOT NULL,
name TEXT,
description TEXT,
scope_id TEXT NOT NULL,
created_time TEXT NOT NULL,
data TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_scope_scope_id_created_time ON scope(scope_id, created_time DESC);
CREATE VIRTUAL TABLE IF NOT EXISTS scope_fts USING fts5(
id,
type,
name,
description,
scope_id,
created_time,
content='',
);
CREATE TRIGGER IF NOT EXISTS scope_ai AFTER INSERT ON scope BEGIN
INSERT INTO scope_fts(
id, type, name, description, scope_id, created_time
) VALUES (
new.id, new.type, new.name, new.description, new.scope_id, new.created_time
);
END;
CREATE TRIGGER IF NOT EXISTS scope_ad AFTER DELETE ON scope BEGIN
INSERT INTO scope_fts(scope_fts, rowid, id, type, name, description, scope_id, created_time)
VALUES('delete', old.rowid, old.id, old.type, old.name, old.description, old.scope_id, old.created_time);
END;`;
export const CREATE_TABLES = (version) => `
BEGIN;
@@ -210,6 +245,7 @@ ${createAliasTables}
${createRoleTables}
${createUserTables}
${createCredentialStoreTables}
${createScopeTables}
CREATE TABLE IF NOT EXISTS "group" (
id TEXT NOT NULL PRIMARY KEY,
+7 -2
View File
@@ -70,11 +70,16 @@ function routes() {
let resultSet;
// Default parent scope is global
if (!scope_id) scope_id = 'global';
// We do not return global scope to mimic our API.
if (recursive && scope_id === 'global') {
resultSet = scopes.all();
resultSet = scopes.where((scope) => {
return scope.scope ? scope.type !== 'global' : false;
});
} else {
resultSet = scopes.where((scope) => {
return scope.scope ? scope.scope.id === scope_id : false;
return scope.scope
? scope.scope.id === scope_id && scope.type !== 'global'
: false;
});
}
const filteredResultSet = resultSet.filter(makeBooleanFilter(filter));
+9
View File
@@ -78,6 +78,15 @@ export default factory.extend({
return name;
},
scope() {
if (this.type === 'global') {
return {
id: 'global',
type: 'global',
};
}
},
withChildren: trait({
afterCreate(record, server) {
if (record.type === 'global') {
+8
View File
@@ -0,0 +1,8 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Model from './base';
export default Model.extend({});