Skip to content

Commit

Permalink
Merge pull request #1156 from gettakaro/fixes-to-init-domain-script
Browse files Browse the repository at this point in the history
Fixes to init domain script
  • Loading branch information
niekcandaele authored Aug 22, 2024
2 parents ba3c608 + 2da7c65 commit 7ffd160
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions scripts/init-domain.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
#!/bin/node

import { Client, AdminClient } from '@takaro/apiclient';
import crypto from 'crypto';

const takaroHost = process.env.TAKARO_HOST;
const adminClientSecret = process.env.ADMIN_CLIENT_SECRET;

if (!takaroHost) throw new Error('TAKARO_HOST is not set');
if (!adminClientSecret) throw new Error('ADMIN_CLIENT_SECRET is not set');

const userEmail = process.env.TAKARO_USER_EMAIL;
const domainName = process.env.TAKARO_DOMAIN_NAME;

if (!userEmail) throw new Error('TAKARO_USER_EMAIL is not set');
if (!domainName) throw new Error('TAKARO_DOMAIN_NAME is not set');

const userPassword = crypto.randomBytes(25).toString('base64');

const adminClient = new AdminClient({
url: takaroHost,
auth: {
Expand All @@ -38,27 +33,6 @@ async function main() {

console.log(`Created a domain with id ${domainRes.data.data.createdDomain.id}`);
console.log(`Root user: ${domainRes.data.data.rootUser.email} / ${domainRes.data.data.password}`);

const client = new Client({
url: takaroHost,
auth: {
username: domainRes.data.data.rootUser.email,
password: domainRes.data.data.password,
},
log: false,
});

await client.login();

const userRes = await client.user.userControllerCreate({
email: userEmail,
password: userPassword,
name: userEmail.split('@')[0],
});

console.log(`Created a user: ${userRes.data.data.email} / ${userPassword}`);

await client.user.userControllerAssignRole(userRes.data.data.id, domainRes.data.data.rootRole.id);
}

main().catch(console.error);

0 comments on commit 7ffd160

Please sign in to comment.