okta-mcp-server
Version:
Model Context Protocol (MCP) server for Okta API operations with support for bulk operations and caching
189 lines • 6.27 kB
JavaScript
import { faker } from '@faker-js/faker';
export class GroupGenerator {
faker;
typeDistribution;
prefixes;
departments;
roles;
generatedCount = 0;
generatedNames = new Set();
constructor(options = {}) {
this.faker = faker;
if (options.seed) {
this.faker.seed(options.seed);
}
this.typeDistribution = options.typeDistribution || {
OKTA_GROUP: 0.7,
APP_GROUP: 0.2,
BUILT_IN: 0.1,
};
this.prefixes = options.prefixes || [
'All',
'Department',
'Team',
'Project',
'Role',
'Region',
'Access',
'Security',
];
this.departments = options.departments || [
'Engineering',
'Sales',
'Marketing',
'Finance',
'HR',
'Operations',
'Product',
'Support',
'Legal',
'IT',
];
this.roles = options.roles || [
'Admin',
'Manager',
'Developer',
'Analyst',
'Designer',
'Architect',
'Lead',
'Coordinator',
'Specialist',
'Consultant',
];
}
generate() {
this.generatedCount++;
const id = `00g${this.faker.string.alphanumeric(17)}`;
const type = this.selectType();
const created = this.faker.date.past({ years: 2 });
const lastUpdated = this.faker.date.between({ from: created, to: new Date() });
const lastMembershipUpdated = this.faker.date.between({ from: lastUpdated, to: new Date() });
const name = this.generateUniqueName(type);
const description = this.generateDescription(name, type);
const objectClass = ['okta:user_group'];
if (type === 'APP_GROUP') {
objectClass.push('okta:app_group');
}
else if (type === 'BUILT_IN') {
objectClass.push('okta:built_in_group');
}
return {
id,
created: created.toISOString(),
lastUpdated: lastUpdated.toISOString(),
lastMembershipUpdated: lastMembershipUpdated.toISOString(),
objectClass,
type,
profile: {
name,
description,
},
};
}
generateBatch(count) {
return Array.from({ length: count }, () => this.generate());
}
selectType() {
const random = this.faker.number.float({ min: 0, max: 1 });
let cumulative = 0;
for (const [type, probability] of Object.entries(this.typeDistribution)) {
cumulative += probability;
if (random <= cumulative) {
return type;
}
}
return 'OKTA_GROUP';
}
generateUniqueName(type) {
let name;
let attempts = 0;
const maxAttempts = 100;
do {
name = this.generateName(type);
attempts++;
if (attempts >= maxAttempts) {
// Fallback to ensure uniqueness
name = `${name}_${this.faker.string.alphanumeric(6)}`;
break;
}
} while (this.generatedNames.has(name));
this.generatedNames.add(name);
return name;
}
generateName(type) {
switch (type) {
case 'BUILT_IN':
return this.faker.helpers.arrayElement([
'Everyone',
'Administrators',
'Developers',
'Users',
'Support',
]);
case 'APP_GROUP':
const app = this.faker.helpers.arrayElement([
'Salesforce',
'Office365',
'Slack',
'Jira',
'GitHub',
'AWS',
'Azure',
'Google Workspace',
]);
const suffix = this.faker.helpers.arrayElement(['Users', 'Admins', 'Readers', 'Writers']);
return `${app} ${suffix}`;
case 'OKTA_GROUP':
default:
const components = [];
// Optionally add prefix
if (this.faker.datatype.boolean({ probability: 0.4 })) {
components.push(this.faker.helpers.arrayElement(this.prefixes));
}
// Add main component
if (this.faker.datatype.boolean({ probability: 0.6 })) {
components.push(this.faker.helpers.arrayElement(this.departments));
}
else {
components.push(this.faker.helpers.arrayElement(this.roles));
}
// Optionally add suffix
if (this.faker.datatype.boolean({ probability: 0.3 })) {
const suffix = this.faker.helpers.arrayElement([
'Team',
'Group',
'Access',
this.faker.location.country(),
this.faker.location.state({ abbreviated: true }),
]);
components.push(suffix);
}
return components.join(' ');
}
}
generateDescription(name, type) {
const templates = [
`Members of the ${name} group`,
`Access control group for ${name}`,
`${name} - Managed by IT department`,
`Automatically synced group for ${name}`,
`${name} with specific permissions and access rights`,
];
if (type === 'BUILT_IN') {
return `Built-in Okta group for ${name}`;
}
if (type === 'APP_GROUP') {
return `Application group for ${name.split(' ')[0]} access`;
}
return this.faker.helpers.arrayElement(templates);
}
reset() {
this.generatedCount = 0;
this.generatedNames.clear();
}
getGeneratedCount() {
return this.generatedCount;
}
}
//# sourceMappingURL=group-generator.js.map