@@ -169,10 +169,16 @@ public Command Sign
169169
170170 if ( selfSign )
171171 {
172+ if ( ! Configuration . Settings [ "selfsign.enable" ] )
173+ {
174+ AnsiConsole . MarkupLine ( "[red]Self-Signing feature is disabled[/]" ) ;
175+ return ;
176+ }
177+
172178 X509Certificate2 ? rootCA = GetSelfSigningRootCA ( ) ;
173179 if ( rootCA == null )
174180 {
175- AnsiConsole . MarkupLine ( "[red]Self-Signing Root CA not found! [/]" ) ;
181+ AnsiConsole . MarkupLine ( "[red]Self-Signing Root CA not found[/]" ) ;
176182 return ;
177183 }
178184
@@ -432,13 +438,91 @@ public Command Trust
432438 }
433439 } , idArg , interOpt ) ;
434440
435- Command command = new Command ( "trust" , "Manage trusted root CAs and intermediate CAs" )
441+ Command command = new Command ( "trust" , "Manage trusted root CAs and intermediate CAs" ) ;
442+
443+ if ( Configuration . Settings [ "trust.enable" ] )
444+ {
445+ command . AddCommand ( addCmd ) ;
446+ command . AddCommand ( listCmd ) ;
447+ command . AddCommand ( removeCmd ) ;
448+ }
449+ else
450+ {
451+ command . SetHandler ( ( ) =>
452+ {
453+ AnsiConsole . MarkupLine ( "[red]Custom trust store feature is disabled[/]" ) ;
454+ return ;
455+ } ) ;
456+ }
457+
458+ return command ;
459+ }
460+ }
461+
462+ /// <summary>
463+ /// Gets the command for managing configuration settings.
464+ /// </summary>
465+ public Command Config
466+ {
467+ get
468+ {
469+ var keyArg = new Argument < string > ( "key" , "Key to set or get\n " +
470+ "if not specified, will list all keys" )
471+ {
472+ Arity = ArgumentArity . ZeroOrOne ,
473+ } ;
474+
475+ var valueArg = new Argument < string > ( "value" , "Value to set\n " +
476+ "if not specified, will get the value of the key" )
477+ {
478+ Arity = ArgumentArity . ZeroOrOne ,
479+ } ;
480+
481+ var forceOpt = new Option < bool > ( "--force" , "Set value even if it is not existing" ) ;
482+ forceOpt . AddAlias ( "-f" ) ;
483+
484+ var command = new Command ( "config" , "Get or set configuration values" )
436485 {
437- addCmd ,
438- listCmd ,
439- removeCmd ,
486+ keyArg ,
487+ valueArg ,
488+ forceOpt ,
440489 } ;
441490
491+ command . SetHandler ( ( key , value , force ) =>
492+ {
493+ if ( string . IsNullOrEmpty ( value ) )
494+ {
495+ var items = string . IsNullOrEmpty ( key ) ? Configuration . Settings : Configuration . Settings . Where ( x => x . Key . StartsWith ( key ) ) ;
496+
497+ foreach ( var item in items )
498+ {
499+ AnsiConsole . WriteLine ( $ "{ item . Key } = { item . Value } ") ;
500+ }
501+ }
502+ else
503+ {
504+ if ( ! force && ! Configuration . Settings . ContainsKey ( key ) )
505+ {
506+ AnsiConsole . MarkupLine ( $ "[red]Invalid key: { key } [/]") ;
507+ return ;
508+ }
509+
510+ bool bValue ;
511+ try
512+ {
513+ bValue = Utilities . ParseToBool ( value ) ;
514+ }
515+ catch
516+ {
517+ AnsiConsole . MarkupLine ( $ "[red]Invalid value: { value } [/]") ;
518+ return ;
519+ }
520+
521+ Configuration . Settings [ key ] = bValue ;
522+ AnsiConsole . MarkupLine ( $ "[green]{ key } set to { Configuration . Settings [ key ] } [/]") ;
523+ }
524+ } , keyArg , valueArg , forceOpt ) ;
525+
442526 return command ;
443527 }
444528 }
@@ -456,6 +540,12 @@ public Command Trust
456540 /// <param name="country">Country (C) - optional.</param>
457541 public virtual void RunSelfSign ( bool force , string ? commonName , string ? email , string ? organization , string ? organizationalUnit , string ? locality , string ? state , string ? country )
458542 {
543+ if ( ! Configuration . Settings [ "selfsign.enable" ] )
544+ {
545+ AnsiConsole . MarkupLine ( "[red]Self-Signing feature is disabled[/]" ) ;
546+ return ;
547+ }
548+
459549 Logger . LogInformation ( "Running self-sign command" ) ;
460550
461551 if ( force || Configuration . SelfSignedRootCA != null )
0 commit comments