Skip to content

Commit

Permalink
Merge pull request #81 from Critteros/ipxe_strategy_ui
Browse files Browse the repository at this point in the history
[Web] Ipxe strategy ui
  • Loading branch information
Critteros authored Dec 10, 2023
2 parents 138c274 + d4a3f1f commit ff21a10
Show file tree
Hide file tree
Showing 28 changed files with 1,061 additions and 12 deletions.
11 changes: 6 additions & 5 deletions apps/backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ type Query {

"""Get a single computer group"""
computerGroup(where: WhereUniqueComputerGroupInput!): ComputerGroup
basicBootStrategy(where: WhereUniqueIpxeStrategy!): BasicBootStrategy!

"""Get all ipxe assets"""
ipxeAssets: [IpxeAsset!]!
Expand All @@ -250,6 +251,11 @@ input WhereUniqueComputerGroupInput {
name: String
}

input WhereUniqueIpxeStrategy {
uid: String
name: String
}

union IpxeStrategy = BasicBootStrategy

type Mutation {
Expand Down Expand Up @@ -491,11 +497,6 @@ input WhereUniqueIpxeStrategyTemplate {
name: String
}

input WhereUniqueIpxeStrategy {
uid: String
name: String
}

input BasicBootStrategyUpdateInput {
"""Ipxe strategy template selector"""
template: WhereUniqueIpxeStrategyTemplate
Expand Down
17 changes: 17 additions & 0 deletions apps/backend/src/ipxe/resolvers/ipxe-strategy.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Prisma } from '@prisma/client';
import { ZodError } from 'zod';

import { MapErrors } from '@/errors/map-errors.decorator';
import { RequirePermission } from '@/rbac/decorators/require-permissions.decorator';

import { IpxeStrategyTemplate } from '../schemas/ipxe-strategy-template.object';
import {
Expand Down Expand Up @@ -58,6 +59,7 @@ export class IpxeStrategyResolver {
// ================================ Queries ================================

@Query(() => [IpxeStrategy])
@RequirePermission('ipxeStrategy.read')
async ipxeStrategies() {
return await this.ipxeStrategyService.findMany();
}
Expand All @@ -69,6 +71,7 @@ export class IpxeStrategyResolver {
if: IpxeStrategyDoesNotExists,
then: () => new BadRequestException('Ipxe strategy does not exists'),
})
@RequirePermission('ipxeStrategy.delete')
async deleteIpxeStrategy(
@Args('where', { type: () => WhereUniqueIpxeStrategy }) where: WhereUniqueIpxeStrategy,
) {
Expand All @@ -80,6 +83,18 @@ export class IpxeStrategyResolver {

@Resolver(() => BasicBootStrategy)
export class BasicStrategyResolver extends StrategyBaseResolver {
// ================================ Queries ================================

@Query(() => BasicBootStrategy)
async basicBootStrategy(
@Args('where', { type: () => WhereUniqueIpxeStrategy }) where: WhereUniqueIpxeStrategy,
) {
return await this.ipxeStrategyService.findStrategy({
whereStrategy: where as Prisma.IpxeStrategyWhereUniqueInput,
forTemplate: { id: 'strategy.basicBoot' },
});
}

// ================================ Mutations ==============================

@Mutation(() => BasicBootStrategy)
Expand All @@ -105,6 +120,7 @@ export class BasicStrategyResolver extends StrategyBaseResolver {
then: () => new BadRequestException('Strategy with provided name already exists'),
},
])
@RequirePermission('ipxeStrategy.create')
async createBasicBootStrategy(
@Args('input', { type: () => BasicBootStrategyCreateInput })
{ name, description, template, ...jsonData }: BasicBootStrategyCreateInput,
Expand Down Expand Up @@ -144,6 +160,7 @@ export class BasicStrategyResolver extends StrategyBaseResolver {
then: () => new BadRequestException('Requested ipxe strategy does not exists'),
},
])
@RequirePermission('ipxeStrategy.create')
async updateBasicBootStrategy(
@Args('where', { type: () => WhereUniqueIpxeStrategy }) where: WhereUniqueIpxeStrategy,
@Args('update', { type: () => BasicBootStrategyUpdateInput })
Expand Down
31 changes: 30 additions & 1 deletion apps/backend/src/ipxe/services/ipxe-strategy.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Injectable } from '@nestjs/common';

import { makeCustomError } from '@hydra-ipxe/common/shared/errors';
import type { BasicBootInfo } from '@hydra-ipxe/common/shared/ipxe/strategies.def';
import type { BasicBootInfo, IPXEStrategy } from '@hydra-ipxe/common/shared/ipxe/strategies.def';
import { Prisma } from '@prisma/client';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import type { Merge } from 'type-fest';

import { PrismaService } from '@/database/prisma.service';
import { PrismaErrorCode, remapPrismaError } from '@/utils/prisma/errors';
Expand Down Expand Up @@ -36,6 +37,34 @@ export class IpxeStrategyService {
return await this.prismaService.ipxeStrategy.findMany(params);
}

async findStrategy({
whereStrategy,
forTemplate,
}: {
whereStrategy: Prisma.IpxeStrategyWhereUniqueInput;
forTemplate?: Merge<Prisma.IpxeStrategyTemplateWhereUniqueInput, { id: IPXEStrategy }>;
}) {
const strategy = await this.prismaService.ipxeStrategy.findUnique({
where: whereStrategy,
include: { strategyTemplate: true },
});

if (!strategy) {
return null;
}

if (forTemplate) {
const requestedTemplate = await this.prismaService.ipxeStrategyTemplate.findUnique({
where: forTemplate,
});
if (!requestedTemplate || requestedTemplate.id !== strategy.strategyTemplateId) {
return null;
}
}

return strategy;
}

async createStrategy(
data: Omit<Prisma.IpxeStrategyCreateInput, 'configurationData'>,
configurationData: Record<string, unknown>,
Expand Down
30 changes: 30 additions & 0 deletions apps/web/src/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ff21a10

Please sign in to comment.