2022-01-05 16:28:56 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2022-03-16 06:35:32 +00:00
|
|
|
import { Team } from '@/portainer/teams/types';
|
|
|
|
import { Role, User, UserId } from '@/portainer/users/types';
|
2022-06-22 17:11:46 +00:00
|
|
|
import { Environment } from '@/portainer/environments/types';
|
2022-03-16 06:35:32 +00:00
|
|
|
|
|
|
|
export function createMockUsers(
|
|
|
|
count: number,
|
|
|
|
roles: Role | Role[] | ((id: UserId) => Role) = () => _.random(1, 3)
|
|
|
|
): User[] {
|
2022-01-05 16:28:56 +00:00
|
|
|
return _.range(1, count + 1).map((value) => ({
|
|
|
|
Id: value,
|
|
|
|
Username: `user${value}`,
|
2022-03-16 06:35:32 +00:00
|
|
|
Role: getRoles(roles, value),
|
2022-01-05 16:28:56 +00:00
|
|
|
UserTheme: '',
|
|
|
|
RoleName: '',
|
|
|
|
AuthenticationMethod: '',
|
|
|
|
Checked: false,
|
|
|
|
EndpointAuthorizations: {},
|
|
|
|
PortainerAuthorizations: {},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-03-16 06:35:32 +00:00
|
|
|
function getRoles(
|
|
|
|
roles: Role | Role[] | ((id: UserId) => Role),
|
|
|
|
id: UserId
|
|
|
|
): Role {
|
|
|
|
if (typeof roles === 'function') {
|
|
|
|
return roles(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof roles === 'number') {
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
return roles[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createMockTeams(count: number): Team[] {
|
2022-01-05 16:28:56 +00:00
|
|
|
return _.range(1, count + 1).map((value) => ({
|
|
|
|
Id: value,
|
|
|
|
Name: `team${value}`,
|
|
|
|
}));
|
|
|
|
}
|
2022-02-24 23:22:56 +00:00
|
|
|
|
|
|
|
export function createMockSubscriptions(count: number) {
|
|
|
|
const subscriptions = _.range(1, count + 1).map((x) => ({
|
|
|
|
id: `/subscriptions/subscription-${x}`,
|
|
|
|
subscriptionId: `subscription-${x}`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return { value: subscriptions };
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createMockResourceGroups(subscription: string, count: number) {
|
|
|
|
const resourceGroups = _.range(1, count + 1).map((x) => ({
|
|
|
|
id: `/subscriptions/${subscription}/resourceGroups/resourceGroup-${x}`,
|
|
|
|
name: `resourcegroup-${x}`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return { value: resourceGroups };
|
|
|
|
}
|
2022-06-22 17:11:46 +00:00
|
|
|
|
|
|
|
export function createMockEnvironment(): Environment {
|
|
|
|
return {
|
|
|
|
TagIds: [],
|
|
|
|
GroupId: 1,
|
|
|
|
Type: 1,
|
|
|
|
Name: 'environment',
|
|
|
|
Status: 1,
|
|
|
|
URL: 'url',
|
|
|
|
Snapshots: [],
|
|
|
|
Kubernetes: { Snapshots: [] },
|
|
|
|
EdgeKey: '',
|
|
|
|
Id: 3,
|
|
|
|
UserTrusted: false,
|
|
|
|
Edge: {
|
|
|
|
AsyncMode: false,
|
|
|
|
PingInterval: 0,
|
|
|
|
CommandInterval: 0,
|
|
|
|
SnapshotInterval: 0,
|
|
|
|
},
|
2022-06-23 07:25:56 +00:00
|
|
|
SecuritySettings: {
|
|
|
|
allowBindMountsForRegularUsers: false,
|
|
|
|
allowPrivilegedModeForRegularUsers: false,
|
|
|
|
allowContainerCapabilitiesForRegularUsers: false,
|
|
|
|
allowDeviceMappingForRegularUsers: false,
|
|
|
|
allowHostNamespaceForRegularUsers: false,
|
|
|
|
allowStackManagementForRegularUsers: false,
|
|
|
|
allowSysctlSettingForRegularUsers: false,
|
|
|
|
allowVolumeBrowserForRegularUsers: false,
|
|
|
|
enableHostManagementFeatures: false,
|
|
|
|
},
|
2022-07-17 23:02:14 +00:00
|
|
|
Gpus: [],
|
2022-08-11 04:32:12 +00:00
|
|
|
Agent: {
|
|
|
|
Version: '',
|
|
|
|
},
|
2022-06-22 17:11:46 +00:00
|
|
|
};
|
|
|
|
}
|