Skip to content

Commit

Permalink
feat: add public_key property to node entity
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Nov 4, 2024
1 parent 8b303b1 commit 69fe08e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
33 changes: 31 additions & 2 deletions packages/client-vue/src/components/node/FNodeForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
DomainType,
NodeType,
} from '@privateaim/core-kit';
import { alphaNumHyphenUnderscoreRegex } from '@privateaim/kit';
import { alphaNumHyphenUnderscoreRegex, hexToUTF8, isHex } from '@privateaim/kit';
import {
buildFormGroup,
buildFormInput, buildFormInputCheckbox, buildFormSelect,
buildFormInput, buildFormInputCheckbox, buildFormSelect, buildFormTextarea,
} from '@vuecs/form-controls';
import type { ListBodySlotProps, ListItemSlotProps } from '@vuecs/list-controls';
import useVuelidate from '@vuelidate/core';
Expand Down Expand Up @@ -57,6 +57,7 @@ export default defineComponent({
const busy = ref(false);
const form = reactive({
name: '',
public_key: '',
external_name: '',
realm_id: '',
registry_id: '',
Expand All @@ -70,6 +71,10 @@ export default defineComponent({
minLength: minLength(3),
maxLength: maxLength(128),
},
public_key: {
minLength: minLength(10),
maxLength: maxLength(4096),
},
hidden: {

},
Expand Down Expand Up @@ -103,6 +108,12 @@ export default defineComponent({
const initForm = () => {
initFormAttributesFromSource(form, manager.data.value);

if (form.public_key) {
form.public_key = isHex(form.public_key) ?
hexToUTF8(form.public_key) :
form.public_key;
}

if (!form.realm_id && props.realmId) {
form.realm_id = props.realmId;
}
Expand Down Expand Up @@ -213,6 +224,22 @@ export default defineComponent({
}),
});

const publicKey = buildFormGroup({
validationMessages: translationsValidation.public_key.value,
validationSeverity: getSeverity($v.value.public_key),
label: true,
labelContent: 'PublicKey',
content: buildFormTextarea({
value: form.public_key,
onChange(input) {
form.public_key = input;
},
props: {
rows: 6,
},
}),
});

const hidden = buildFormGroup({
validationMessages: translationsValidation.hidden.value,
validationSeverity: getSeverity($v.value.hidden),
Expand Down Expand Up @@ -284,6 +311,8 @@ export default defineComponent({
h('hr'),
hidden,
h('hr'),
publicKey,
h('hr'),
submitNode,
]),
]),
Expand Down
2 changes: 2 additions & 0 deletions packages/core-kit/src/domains/node/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface Node {

external_name: string | null;

public_key: string | null;

name: string;

hidden: boolean;
Expand Down
7 changes: 7 additions & 0 deletions packages/server-core/src/domains/node/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export class NodeEntity implements Node {
@Column({ type: 'varchar', length: 64, nullable: true })
external_name: string;

@Column({
type: 'varchar',
length: 4096,
nullable: true,
})
public_key: string;

@Column({ type: 'varchar', length: 128 })
name: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {
RegistryProjectType,
} from '@privateaim/core-kit';
import { PermissionName, createNanoID } from '@privateaim/kit';
import { PermissionName, createNanoID, isHex } from '@privateaim/kit';
import type { Request, Response } from 'routup';
import { sendCreated } from 'routup';
import { useDataSource } from 'typeorm-extension';
Expand All @@ -31,6 +31,17 @@ export async function createNodeRouteHandler(req: Request, res: Response) : Prom

// -----------------------------------------------------

if (
entity.public_key &&
!isHex(result.data.public_key)
) {
entity.public_key = Buffer
.from(entity.public_key, 'utf8')
.toString('hex');
}

// -----------------------------------------------------

let registryId : string | undefined;
if (entity.registry_id) {
registryId = entity.registry_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async function checkAndApplyFields(req: Request, query: SelectQueryBuilder<any>,
'hidden',
'type',
'online',
'public_key',
'robot_id',
'realm_id',
'registry_id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {
RegistryProjectType,
} from '@privateaim/core-kit';
import { PermissionName, createNanoID } from '@privateaim/kit';
import { PermissionName, createNanoID, isHex } from '@privateaim/kit';
import { ForbiddenError, NotFoundError } from '@ebec/http';
import { isRealmResourceWritable } from '@authup/core-kit';
import type { Request, Response } from 'routup';
Expand All @@ -31,6 +31,15 @@ export async function updateNodeRouteHandler(req: Request, res: Response) : Prom
return sendAccepted(res);
}

if (
result.data.public_key &&
!isHex(result.data.public_key)
) {
result.data.public_key = Buffer
.from(result.data.public_key, 'utf8')
.toString('hex');
}

const dataSource = await useDataSource();
const repository = dataSource.getRepository(NodeEntity);
const query = repository.createQueryBuilder('station')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export async function runNodeValidation(

// -------------------------------------------------------------

await check('public_key')
.isLength({ min: 5, max: 4096 })
.exists()
.optional({ nullable: true })
.run(req);

// -------------------------------------------------------------

await check('external_name')
.isLength({ min: 1, max: 64 })
.exists()
Expand Down

0 comments on commit 69fe08e

Please sign in to comment.