@@ -13,7 +13,13 @@ import { PublicConfig as V105PublicConfig } from '../types/v105'
1313
1414import { Ctx } from '../processor'
1515import assert from "assert" ;
16- import { allowedNodeEnvironmentFlags } from "process" ;
16+
17+ export function parseNodeCertification ( kind : string ) : NodeCertification {
18+ switch ( kind ) {
19+ case 'Certified' : return NodeCertification . Certified
20+ default : return NodeCertification . Diy
21+ }
22+ }
1723
1824export async function nodeStored (
1925 ctx : Ctx ,
@@ -137,8 +143,6 @@ export async function nodeStored(
137143 resourcesTotal . cru = nodeEvent . resources . cru
138144 await ctx . store . save < NodeResourcesTotal > ( resourcesTotal )
139145
140- newNode . interfaces = [ ]
141-
142146 const interfacesPromisses = nodeEvent . interfaces . map ( async ( intf , index ) => {
143147 const newInterface = new Interfaces ( )
144148 newInterface . id = item . event . id + '-' + index
@@ -226,21 +230,9 @@ export async function nodeUpdated(
226230 savedNode . country = validateString ( ctx , nodeAsV28 . country . toString ( ) )
227231 savedNode . city = validateString ( ctx , nodeAsV28 . city . toString ( ) )
228232
229- if ( nodeAsV28 . certificationType ) {
230- const certificationTypeAsString = nodeAsV28 . certificationType . __kind . toString ( )
231- let certType = NodeCertification . Diy
232- switch ( certificationTypeAsString ) {
233- case 'Diy' :
234- certType = NodeCertification . Diy
235- break
236- case 'Certified' :
237- certType = NodeCertification . Certified
238- break
239- }
240- savedNode . certification = certType
241- } else {
242- savedNode . certification = NodeCertification . Diy
243- }
233+ savedNode . certification = nodeAsV28 . certificationType
234+ ? parseNodeCertification ( nodeAsV28 . certificationType . __kind . toString ( ) )
235+ : NodeCertification . Diy
244236 }
245237
246238 if ( node . isV43 ) {
@@ -250,21 +242,9 @@ export async function nodeUpdated(
250242 savedNode . secure = nodeAsV43 . secureBoot ? true : false
251243 savedNode . virtualized = nodeAsV43 . virtualized ? true : false
252244 savedNode . serialNumber = validateString ( ctx , nodeAsV43 . serialNumber . toString ( ) )
253- if ( nodeAsV43 . certificationType ) {
254- const certificationTypeAsString = nodeAsV43 . certificationType . __kind . toString ( )
255- let certType = NodeCertification . Diy
256- switch ( certificationTypeAsString ) {
257- case 'Diy' :
258- certType = NodeCertification . Diy
259- break
260- case 'Certified' :
261- certType = NodeCertification . Certified
262- break
263- }
264- savedNode . certification = certType
265- } else {
266- savedNode . certification = NodeCertification . Diy
267- }
245+ savedNode . certification = nodeAsV43 . certificationType
246+ ? parseNodeCertification ( nodeAsV43 . certificationType . __kind . toString ( ) )
247+ : NodeCertification . Diy
268248 }
269249
270250 if ( node . isV63 || node . isV105 ) {
@@ -281,21 +261,9 @@ export async function nodeUpdated(
281261 savedNode . secure = nodeEvent . secureBoot ? true : false
282262 savedNode . virtualized = nodeEvent . virtualized ? true : false
283263 savedNode . serialNumber = validateString ( ctx , nodeEvent . serialNumber . toString ( ) )
284- if ( nodeEvent . certification ) {
285- const certificationTypeAsString = nodeEvent . certification . __kind . toString ( )
286- let certType = NodeCertification . Diy
287- switch ( certificationTypeAsString ) {
288- case 'Diy' :
289- certType = NodeCertification . Diy
290- break
291- case 'Certified' :
292- certType = NodeCertification . Certified
293- break
294- }
295- savedNode . certification = certType
296- } else {
297- savedNode . certification = NodeCertification . Diy
298- }
264+ savedNode . certification = nodeEvent . certification
265+ ? parseNodeCertification ( nodeEvent . certification . __kind . toString ( ) )
266+ : NodeCertification . Diy
299267 }
300268
301269 if ( node . isV118 ) {
@@ -306,21 +274,9 @@ export async function nodeUpdated(
306274 savedNode . secure = nodeEvent . secureBoot ? true : false
307275 savedNode . virtualized = nodeEvent . virtualized ? true : false
308276 savedNode . serialNumber = nodeEvent . serialNumber ? validateString ( ctx , nodeEvent . serialNumber . toString ( ) ) : 'Unknown'
309- if ( nodeEvent . certification ) {
310- const certificationTypeAsString = nodeEvent . certification . __kind . toString ( )
311- let certType = NodeCertification . Diy
312- switch ( certificationTypeAsString ) {
313- case 'Diy' :
314- certType = NodeCertification . Diy
315- break
316- case 'Certified' :
317- certType = NodeCertification . Certified
318- break
319- }
320- savedNode . certification = certType
321- } else {
322- savedNode . certification = NodeCertification . Diy
323- }
277+ savedNode . certification = nodeEvent . certification
278+ ? parseNodeCertification ( nodeEvent . certification . __kind . toString ( ) )
279+ : NodeCertification . Diy
324280 }
325281
326282 // First remove all ifs
@@ -337,7 +293,6 @@ export async function nodeUpdated(
337293 newInterface . node = savedNode
338294 await ctx . store . save < Interfaces > ( newInterface )
339295
340- savedNode . interfaces . push ( newInterface )
341296 } ) )
342297
343298 await ctx . store . save < Node > ( savedNode )
@@ -499,17 +454,7 @@ export async function nodeCertificationSet(
499454 const savedNode = await ctx . store . get ( Node , { where : { nodeID : nodeID } , relations : { location : true , interfaces : true } } )
500455 if ( ! savedNode ) return
501456
502- let certType = NodeCertification . Diy
503- switch ( certification . __kind . toString ( ) ) {
504- case 'Diy' :
505- certType = NodeCertification . Diy
506- break
507- case 'Certified' :
508- certType = NodeCertification . Certified
509- break
510- }
511-
512- savedNode . certification = certType
457+ savedNode . certification = parseNodeCertification ( certification . __kind . toString ( ) )
513458
514459 await ctx . store . save < Node > ( savedNode )
515460}
@@ -669,8 +614,6 @@ function getNodePublicConfig(ctx: Ctx, node: TfgridModuleNodeStoredEvent): NodeP
669614 if ( nodeEvent . publicConfig . domain ) {
670615 domain = nodeEvent . publicConfig . domain . toString ( )
671616 }
672- let h = nodeEvent . publicConfig ?. ip6 ?. ip . toString ( ) ;
673- let r = nodeEvent . publicConfig ?. ip4 . ip . toString ( ) ;
674617 return {
675618 ip4 : validateString ( ctx , nodeEvent . publicConfig ?. ip4 . ip . toString ( ) ) ,
676619 gw4 : validateString ( ctx , nodeEvent . publicConfig ?. ip4 . gw . toString ( ) ) ,
0 commit comments