basic org creation

This commit is contained in:
c0repwn3r 2023-03-01 13:43:43 -05:00
parent 147742b214
commit 597ab081f6
Signed by: core
GPG Key ID: FDBF740DADDCEECF
4 changed files with 46 additions and 6 deletions

View File

@ -92,6 +92,10 @@
"subnetprompt": "What subnets would you like to allow?",
"subnethelp": "Comma-separated list of subnets in CIDR notation. This will constrain which subnets can be applied to client certs. Default: empty (any)",
"groupprompt": "What groups would you like to allow?",
"grouphelp": "Comma-separated list of groups. This will constrain which groups can be applied to client certs. Default: empty (any)"
"grouphelp": "Comma-separated list of groups. This will constrain which groups can be applied to client certs. Default: empty (any)",
"apierror": {
"orgcreate": "Unable to create organization",
"TypeError: NetworkError when attempting to fetch resource": "Unable to contact the backend. Please try again later."
}
}
}

View File

@ -1,4 +1,4 @@
export async function fetch_timeout(resource: RequestInfo | URL, options = {}) {
export async function fetch_timeout(resource: RequestInfo | URL, options: RequestInit | undefined = {}) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { timeout = 8000 } = options;

View File

@ -8,6 +8,8 @@
import {get_user_info} from "$lib/auth";
import {org} from "$lib/orgs";
import type {Organization} from "$lib/orgs";
import {API_ROOT} from "$lib/config";
import {fetch_timeout} from "$lib/util";
let logger = new Logger("admin/+page.svelte");
logSetup();
@ -73,8 +75,34 @@
let showAdditionalConstraints = false;
function newOrg() {
async function doCreateFlow() {
// STEP ONE: Create the org
logger.info("Creating base organization");
let created_org_id;
try {
let resp = await fetch_timeout(`${API_ROOT}/v1/org`, {
'method': 'POST',
'headers': {
'Authorization': 'Bearer ' + api_token
}
});
if (resp.code !== 200) {
let err = await resp.json().errors[0].message;
logger.error(`${await resp.json().errors[0]}`);
fullPageError = true;
fullPageErrorTitle = t('neworg.apierror.orgcreate');
fullPageErrorSubtitle = t('neworg.apierror.' + err);
return;
}
created_org_id = resp.json().org_id;
logger.info("Able to create base organization with id " + created_org_id);
} catch (e) {
logger.error(`${e}`);
fullPageError = true;
fullPageErrorTitle = t('neworg.apierror.orgcreate');
fullPageErrorSubtitle = t('neworg.apierror.' + `${e}`.replaceAll('.', ''));
return;
}
}
</script>
@ -90,7 +118,7 @@
<h3 class="text-sm">{t('neworg.cahelp')}</h3>
</div>
<form class="mt-5" action="#" method="POST" on:submit|preventDefault={newOrg}>
<form class="mt-5" action="#" method="POST" on:submit|preventDefault={doCreateFlow}>
<div class=" rounded-md shadow-sm">
<label for="iprange" class="mb-5">{t('neworg.iprangeprompt')}</label>
<input bind:value={org_ip_range} id="iprange"

View File

@ -8,7 +8,15 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
"strict": true,
"paths": {
"$lib": [
"./src/lib"
],
"$lib/*": [
"./src/lib/*"
]
}
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//