2019-09-26 18:47:07 +00:00
|
|
|
import { Factory } from 'ember-cli-mirage';
|
2019-10-03 14:13:08 +00:00
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
2017-10-14 18:01:28 +00:00
|
|
|
|
|
|
|
export default Factory.extend({
|
|
|
|
id: () => faker.random.uuid(),
|
|
|
|
accessorId() {
|
|
|
|
return this.id;
|
|
|
|
},
|
|
|
|
secretId: () => faker.random.uuid(),
|
2022-05-17 18:52:14 +00:00
|
|
|
name: (i) => `${i === 0 ? 'Manager ' : ''}${faker.name.findName()}`,
|
2017-10-14 18:01:28 +00:00
|
|
|
global: () => faker.random.boolean(),
|
2022-05-17 18:52:14 +00:00
|
|
|
type: (i) => (i === 0 ? 'management' : 'client'),
|
2017-10-14 18:01:28 +00:00
|
|
|
|
2021-04-01 18:21:30 +00:00
|
|
|
oneTimeSecret: () => faker.random.uuid(),
|
|
|
|
|
2017-10-14 18:01:28 +00:00
|
|
|
afterCreate(token, server) {
|
|
|
|
const policyIds = Array(faker.random.number({ min: 1, max: 5 }))
|
|
|
|
.fill(0)
|
2017-10-16 18:33:49 +00:00
|
|
|
.map(() => faker.hacker.verb())
|
|
|
|
.uniq();
|
2017-10-14 18:01:28 +00:00
|
|
|
|
2022-05-17 18:52:14 +00:00
|
|
|
policyIds.forEach((policy) => {
|
2017-10-14 18:01:28 +00:00
|
|
|
const dbPolicy = server.db.policies.find(policy);
|
|
|
|
if (!dbPolicy) {
|
|
|
|
server.create('policy', { id: policy });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
token.update({ policyIds });
|
2022-05-17 18:52:14 +00:00
|
|
|
|
|
|
|
// Create a special policy with secure variables rules in place
|
|
|
|
if (token.id === '53cur3-v4r14bl35') {
|
|
|
|
const variableMakerPolicy = {
|
|
|
|
id: 'Variable Maker',
|
|
|
|
rules: `
|
|
|
|
# Allow read only access to the default namespace
|
|
|
|
namespace "default" {
|
|
|
|
policy = "read"
|
|
|
|
capabilities = ["list-jobs", "alloc-exec", "read-logs"]
|
|
|
|
secure_variables {
|
|
|
|
path "*" {
|
|
|
|
capabilities = ["list"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
|
|
|
|
rulesJSON: {
|
|
|
|
Namespaces: [
|
|
|
|
{
|
|
|
|
Name: 'default',
|
|
|
|
Capabilities: ['list-jobs', 'alloc-exec', 'read-logs'],
|
|
|
|
SecureVariables: {
|
|
|
|
'Path "*"': {
|
|
|
|
Capabilities: ['list'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
server.create('policy', variableMakerPolicy);
|
|
|
|
token.policyIds.push(variableMakerPolicy.id);
|
|
|
|
}
|
2017-10-14 18:01:28 +00:00
|
|
|
},
|
|
|
|
});
|