61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
const fs = require('fs');
|
|
const tokenData = JSON.parse(fs.readFileSync('D:/cumin/ghaymah_dns_net_sec_tests/token.json', 'utf8'));
|
|
|
|
const PROJECT_ID = '3f55ceef-78ae-40c8-a41b-0505db8c59ee';
|
|
const clientId = crypto.randomUUID();
|
|
|
|
async function genDomainHash(name, id) {
|
|
const input = `${name}-${id}`;
|
|
const data = new TextEncoder().encode(input);
|
|
const hash = await crypto.subtle.digest('SHA-256', data);
|
|
const hex = Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
return hex.substring(0, 12);
|
|
}
|
|
|
|
async function main() {
|
|
const hash = await genDomainHash('client-terminal', clientId);
|
|
const domain = `client-terminal-${hash}.hosted.ghaymah.systems`;
|
|
console.log('Deploying client-terminal (tsl0922/ttyd:alpine) on domain:', domain);
|
|
|
|
const res = await fetch('https://graphql.ghaymah.systems/v1/graphql', {
|
|
method: 'POST',
|
|
headers: { 'Authorization': 'Bearer ' + tokenData.token, 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
query: `mutation CreateResource($id: uuid!, $userId: uuid!, $chartName: String!, $chartVersion: String!, $values: json!) {
|
|
insert_ghaymah_cloud_resources_one(object: {
|
|
id: $id,
|
|
user_id: $userId,
|
|
chart_name: $chartName,
|
|
chart_version: $chartVersion,
|
|
values: $values
|
|
}) {
|
|
id status
|
|
}
|
|
}`,
|
|
variables: {
|
|
id: clientId,
|
|
userId: tokenData.userId,
|
|
chartName: 'ghaymah-app',
|
|
chartVersion: '0.1',
|
|
values: {
|
|
name: 'client-terminal',
|
|
projectId: PROJECT_ID,
|
|
resourceTier: 't1',
|
|
ports: [{ number: 7681, expose: true }],
|
|
container: {
|
|
image: 'tsl0922/ttyd:alpine'
|
|
},
|
|
publicAccess: {
|
|
enabled: true,
|
|
domain: domain,
|
|
baseDomain: 'hosted.ghaymah.systems'
|
|
}
|
|
}
|
|
}
|
|
})
|
|
});
|
|
console.log('Result:', JSON.stringify(await res.json(), null, 2));
|
|
}
|
|
|
|
main().catch(console.error);
|