@@ -4,10 +4,10 @@ use regex::Regex;
44use serde;
55use std:: fmt;
66
7- pub mod templates;
87pub mod example_values;
8+ pub mod templates;
99
10- #[ derive( serde:: Serialize ) ]
10+ #[ derive( serde:: Serialize , Default ) ]
1111pub struct InitVars {
1212 pub flag_regex : String ,
1313 pub registry_domain : String ,
@@ -22,7 +22,7 @@ pub struct InitVars {
2222 pub profiles : Vec < Profile > ,
2323}
2424
25- #[ derive( Clone , serde:: Serialize ) ]
25+ #[ derive( Clone , serde:: Serialize , Default ) ]
2626pub struct Points {
2727 pub difficulty : String ,
2828 pub min : String ,
@@ -39,7 +39,7 @@ impl fmt::Display for Points {
3939 }
4040}
4141
42- #[ derive( serde:: Serialize ) ]
42+ #[ derive( serde:: Serialize , Default ) ]
4343pub struct Profile {
4444 pub profile_name : String ,
4545 pub frontend_url : String ,
@@ -70,40 +70,42 @@ pub fn interactive_init() -> inquire::error::InquireResult<InitVars> {
7070
7171 registry_domain : {
7272 inquire:: Text :: new ( "Container registry:" )
73- . with_help_message ( "Hosted challenges will be hosted in a container registry.The connection endpoint and the repository name." )
73+ . with_help_message ( "Hosted challenges will be hosted in a container registry.The connection endpoint and the repository name." )
7474 . with_placeholder ( example_values:: REGISTRY_DOMAIN )
7575 . prompt ( ) ?
7676 } ,
7777
7878 registry_build_user : {
79- inquire:: Text :: new ( "Container registry 'build' user:" )
80- . with_help_message ( "The username that will be used to push built containers." )
81- . with_placeholder ( example_values:: REGISTRY_BUILD_USER )
82- . prompt ( ) ?
79+ inquire:: Text :: new ( "Container registry 'build' user:" )
80+ . with_help_message ( "The username that will be used to push built containers." )
81+ . with_placeholder ( example_values:: REGISTRY_BUILD_USER )
82+ . prompt ( ) ?
8383 } ,
8484
8585 // TODO: do we actually want to be in charge of these credentials vs expecting the local building utility already be logged in?
8686 registry_build_pass : {
8787 inquire:: Password :: new ( "Container registry 'build' password:" )
88- . with_help_message ( "The password to the 'build' user account" ) // TODO: could this support username:pat too?
89- . with_display_mode ( inquire:: PasswordDisplayMode :: Masked )
90- . with_custom_confirmation_message ( "Enter again:" )
91- . prompt ( ) ?
88+ . with_help_message ( "The password to the 'build' user account" ) // TODO: could this support username:pat too?
89+ . with_display_mode ( inquire:: PasswordDisplayMode :: Masked )
90+ . with_custom_confirmation_message ( "Enter again:" )
91+ . prompt ( ) ?
9292 } ,
9393
9494 registry_cluster_user : {
95- inquire:: Text :: new ( "Container registry 'cluster' user:" )
96- . with_help_message ( "The username that the cluster will use to pull locally-built containers." )
97- . with_placeholder ( example_values:: REGISTRY_CLUSTER_USER )
98- . prompt ( ) ?
95+ inquire:: Text :: new ( "Container registry 'cluster' user:" )
96+ . with_help_message (
97+ "The username that the cluster will use to pull locally-built containers." ,
98+ )
99+ . with_placeholder ( example_values:: REGISTRY_CLUSTER_USER )
100+ . prompt ( ) ?
99101 } ,
100102
101103 registry_cluster_pass : {
102104 inquire:: Password :: new ( "Container registry 'cluster' password:" )
103- . with_help_message ( "The password to the 'cluster' user account" )
104- . with_display_mode ( inquire:: PasswordDisplayMode :: Masked )
105- . with_custom_confirmation_message ( "Enter again:" )
106- . prompt ( ) ?
105+ . with_help_message ( "The password to the 'cluster' user account" )
106+ . with_display_mode ( inquire:: PasswordDisplayMode :: Masked )
107+ . with_custom_confirmation_message ( "Enter again:" )
108+ . prompt ( ) ?
107109 } ,
108110
109111 points : {
@@ -117,10 +119,10 @@ pub fn interactive_init() -> inquire::error::InquireResult<InitVars> {
117119 let points_obj = Points {
118120 difficulty : {
119121 inquire:: Text :: new ( "Difficulty class:" )
120- . with_validator ( inquire:: required!( "Please provide a name." ) )
121- . with_help_message ( "The name of the difficulty class." )
122- . with_placeholder ( example_values:: POINTS_DIFFICULTY )
123- . prompt ( ) ?
122+ . with_validator ( inquire:: required!( "Please provide a name." ) )
123+ . with_help_message ( "The name of the difficulty class." )
124+ . with_placeholder ( example_values:: POINTS_DIFFICULTY )
125+ . prompt ( ) ?
124126 } ,
125127 min : {
126128 inquire:: CustomType :: < u64 > :: new ( "Minimum points:" )
@@ -211,9 +213,7 @@ pub fn interactive_init() -> inquire::error::InquireResult<InitVars> {
211213 } ,
212214 frontend_token : {
213215 inquire:: Text :: new ( "Frontend token:" )
214- . with_help_message (
215- "The token to authenticate into the RNG scoreboard." ,
216- )
216+ . with_help_message ( "The token to authenticate into the RNG scoreboard." )
217217 . with_placeholder ( example_values:: PROFILES_FRONTEND_TOKEN )
218218 . prompt ( ) ?
219219 } ,
@@ -269,42 +269,16 @@ pub fn interactive_init() -> inquire::error::InquireResult<InitVars> {
269269 profiles
270270 } ,
271271 } ;
272- return Ok ( options) ;
272+
273+ Ok ( options)
273274}
274275
275276pub fn blank_init ( ) -> InitVars {
276- return InitVars {
277- flag_regex : String :: new ( ) ,
278- registry_domain : String :: new ( ) ,
279- registry_build_user : String :: new ( ) ,
280- registry_build_pass : String :: new ( ) ,
281- registry_cluster_user : String :: new ( ) ,
282- registry_cluster_pass : String :: new ( ) ,
283- defaults_difficulty : String :: new ( ) ,
284- defaults_resources_cpu : String :: new ( ) ,
285- defaults_resources_memory : String :: new ( ) ,
286- points : vec ! [ Points {
287- difficulty: String :: new( ) ,
288- min: String :: new( ) ,
289- max: String :: new( ) ,
290- } ] ,
291- profiles : vec ! [ Profile {
292- profile_name: String :: from( example_values:: PROFILES_PROFILE_NAME ) ,
293- frontend_url: String :: new( ) ,
294- frontend_token: String :: new( ) ,
295- challenges_domain: String :: new( ) ,
296- kubecontext: String :: new( ) ,
297- s3_bucket_name: String :: new( ) ,
298- s3_endpoint: String :: new( ) ,
299- s3_region: String :: new( ) ,
300- s3_accesskey: String :: new( ) ,
301- s3_secretaccesskey: String :: new( ) ,
302- } ] ,
303- } ;
277+ InitVars :: default ( )
304278}
305279
306280pub fn example_init ( ) -> InitVars {
307- return InitVars {
281+ InitVars {
308282 flag_regex : String :: from ( example_values:: FLAG_REGEX ) ,
309283 registry_domain : String :: from ( example_values:: REGISTRY_DOMAIN ) ,
310284 registry_build_user : String :: from ( example_values:: REGISTRY_BUILD_USER ) ,
@@ -338,10 +312,9 @@ pub fn example_init() -> InitVars {
338312 s3_accesskey: String :: from( example_values:: PROFILES_S3_ACCESSKEY ) ,
339313 s3_secretaccesskey: String :: from( example_values:: PROFILES_S3_SECRETACCESSKEY ) ,
340314 } ] ,
341- } ;
315+ }
342316}
343317
344318pub fn templatize_init ( options : InitVars ) -> String {
345- let filled_template = minijinja:: render!( templates:: RCDS , options) ;
346- return filled_template;
319+ minijinja:: render!( templates:: RCDS , options)
347320}
0 commit comments