Files
threshold-ui/addons/api/mirage/scenarios/default.js
T

151 lines
4.3 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
export default function (server) {
// Scope resources
2020-06-04 16:53:37 -04:00
// creates a global scope
const globalScope = server.create('scope', {
id: 'global',
type: 'global',
name: 'Global',
});
const orgScope = server.createList(
'scope',
3,
{
type: 'org',
scope: { id: globalScope.id, type: globalScope.type },
},
'withChildren',
)[0];
2020-06-18 15:51:40 -04:00
// Auth
const globalAuthMethods = server.createList(
'auth-method',
5,
{ scope: globalScope },
'withAccountsAndUsersAndManagedGroups',
);
const orgAuthMethods = server.createList(
'auth-method',
3,
{ scope: orgScope },
'withAccountsAndUsersAndManagedGroups',
);
// Authenticated user/account
const user = server.create('user', {
id: 'authenticateduser',
scope: globalScope,
});
const { id: accountID } = server.create('account', {
id: 'authenticatedaccount',
scope: globalScope,
authMethod: globalAuthMethods[0],
type: 'password',
});
user.update({ accountIds: [accountID] });
// Assign primary auth methods per scope
// TODO make this generic
2021-03-26 12:47:49 -04:00
globalScope.update({ primaryAuthMethodId: globalAuthMethods[0].id });
orgScope.update({ primaryAuthMethodId: orgAuthMethods[1].id });
2020-09-01 12:03:36 -04:00
// Groups and Users
server.createList('group', 1, { scope: globalScope }, 'withMembers');
server.createList('group', 5, { scope: orgScope }, 'withMembers');
2020-08-12 13:41:23 -04:00
// Role
const globalScopeRoles = server.createList(
'role',
1,
{ scope: globalScope },
'withPrincipals',
);
//create managed groups for role/principals in globalScope
globalScopeRoles.forEach((role) => {
const { scope } = role;
const oidcAuthMethod = globalAuthMethods.filter(
(auth) => auth.type === TYPE_AUTH_METHOD_OIDC,
)[0];
const { type } = oidcAuthMethod;
const managedGroups = server.createList('managed-group', 2, {
scope,
authMethodId: oidcAuthMethod.id,
type,
});
role.update({ managedGroups });
});
const orgScopeRoles = server.createList(
'role',
5,
{ scope: orgScope },
'withPrincipals',
);
//create managed groups for role/principals in orgScope
orgScopeRoles.forEach((role) => {
const { scope } = role;
const oidcAuthMethod = orgAuthMethods.filter(
(auth) => auth.type === TYPE_AUTH_METHOD_OIDC,
)[0];
const { type } = oidcAuthMethod;
const managedGroups = server.createList('managed-group', 2, {
scope,
authMethodId: oidcAuthMethod.id,
type,
});
role.update({ managedGroups });
});
2020-06-22 21:39:38 -04:00
// Storage Buckets
server.createList('storage-bucket', 3, { scope: globalScope });
server.createList('storage-bucket', 2, { scope: orgScope });
// Storage Policies
server.createList('policy', 3, { scope: globalScope });
server.createList('policy', 3, { scope: orgScope });
// Other resources
server.schema.scopes.where({ type: 'project' }).models.forEach((scope) => {
server.createList('host-catalog', 8, { scope }, 'withChildren');
2021-07-12 16:03:06 -04:00
server.createList('credential-store', 3, { scope }, 'withAssociations');
server.createList('target', 2, { scope }, 'withAssociations');
server.create('target', { scope, address: '0.0.0.0' });
// Sessions have target data. Create it after targets.
server.createList('session', 4, { scope }, 'withAssociations');
2023-06-07 18:28:33 -07:00
// Also create sessions for "authenticateduser" for Desktop,
// which filters user_id by the currently authenticated user.
server.createList('session', 1, { scope, user }, 'withAssociations');
// Create IAM resources for project
server.createList('group', 3, { scope });
server.createList('role', 3, { scope });
2020-07-28 11:06:06 -04:00
});
// Workers
server.createList('worker', 3, { scope: globalScope });
// Session Recordings
server.createList(
2023-03-16 13:49:04 -04:00
'session-recording',
3,
{ scope: globalScope },
'withConnectionAndChannels',
'withExistingUserAndTarget',
);
server.create(
2023-03-16 13:49:04 -04:00
'session-recording',
{ scope: globalScope },
'withConnectionAndChannels',
'withNonExistingUserAndTarget',
);
server.createList(
2023-03-16 13:49:04 -04:00
'session-recording',
2,
{ scope: orgScope },
'withConnectionAndChannels',
'withExistingUserAndTarget',
);
}