@@ -28,25 +28,24 @@ pub(crate) struct AppConfig {
28
28
pub primary_email : Option < String > ,
29
29
/// A 32-byte long hex string of the Gist ID with the validation string for the user GH account
30
30
/// E.g. `fb8fc0f87ee78231f064131022c8154a`
31
+ /// It is validated on change and then cached in config.json
31
32
pub gh_validation_id : Option < String > ,
32
- /// The URL is reconstructed from a Gist ID after validation.
33
- /// It may seize to exist or change the contents, but the URL itself is guaranteed to be valid
34
- pub gh_validation_url : Option < String > ,
35
33
/// Core config from stackmuncher_lib
36
34
pub lib_config : Config ,
37
35
/// Extracted from the key file stored next to the config file
38
36
pub user_key_pair : Ed25519KeyPair ,
39
37
/// The full path to the config file.
40
38
pub config_file_path : PathBuf ,
39
+ /// A stash for validation Gist details to avoid going to GitHub twice
40
+ /// Not cached and can only be present if --gist param was used to link to a new github a/c
41
+ pub gh_validation_gist : Option < crate :: cmd_config:: Gist > ,
41
42
}
42
43
43
44
/// A container for storing some config info locally as a file.
44
45
#[ derive( Serialize , Deserialize , PartialEq ) ]
45
46
struct AppConfigCache {
46
47
pub primary_email : Option < String > ,
47
- /// The URL is reconstructed from a Gist ID after validation.
48
- /// It may seize to exist or change the contents, but the URL itself is guaranteed to be valid
49
- pub gh_validation_url : Option < String > ,
48
+ pub gh_validation_id : Option < String > ,
50
49
pub git_identities : Vec < String > ,
51
50
}
52
51
@@ -235,29 +234,30 @@ impl AppConfig {
235
234
println ! ( ) ;
236
235
}
237
236
238
- // GitHub login validation - use the validated URL or None if --gist param was provided
237
+ // GitHub login validation - use the validated ID or None if --gist param was provided
239
238
// It means that the user requested a change of sorts.
240
239
// Otherwise use what is in the cache without any validation.
241
- let gh_validation_url = if app_args. gh_validation_id . is_some ( ) {
242
- // --gist was present - so something was requested
240
+ let ( gh_validation_id , gh_validation_gist ) = if app_args. gh_validation_id . is_some ( ) {
241
+ // --gist was present - so a change was requested by the user
243
242
match crate :: cmd_config:: get_validated_gist ( & app_args. gh_validation_id , & user_key_pair) . await {
244
- Some ( gist) => Some ( gist. html_url ) ,
245
- None => None ,
243
+ // the gist struct will be needed to print config details later
244
+ Some ( gist) => ( app_args. gh_validation_id . clone ( ) , Some ( gist) ) ,
245
+ None => ( None , None ) ,
246
246
}
247
247
} else {
248
248
// --gist was not present - use what's in cache
249
- app_config_cache. gh_validation_url . clone ( )
249
+ ( app_config_cache. gh_validation_id . clone ( ) , None )
250
250
} ;
251
251
252
252
let app_config = AppConfig {
253
253
command : app_args. command ,
254
254
dryrun : app_args. dryrun ,
255
255
primary_email,
256
- gh_validation_id : app_args. gh_validation_id ,
257
- gh_validation_url,
256
+ gh_validation_id,
258
257
lib_config : config,
259
258
user_key_pair,
260
259
config_file_path,
260
+ gh_validation_gist,
261
261
} ;
262
262
263
263
app_config_cache. save ( & app_config) ;
@@ -505,7 +505,7 @@ impl AppConfigCache {
505
505
// create a blank dummy to return in case of a problem
506
506
let app_config_cache = AppConfigCache {
507
507
primary_email : None ,
508
- gh_validation_url : None ,
508
+ gh_validation_id : None ,
509
509
git_identities : Vec :: new ( ) ,
510
510
} ;
511
511
@@ -557,7 +557,7 @@ impl AppConfigCache {
557
557
// prepare the data to save
558
558
let app_config_cache = AppConfigCache {
559
559
primary_email : app_config. primary_email . clone ( ) ,
560
- gh_validation_url : app_config. gh_validation_url . clone ( ) ,
560
+ gh_validation_id : app_config. gh_validation_id . clone ( ) ,
561
561
git_identities : app_config. lib_config . git_identities . clone ( ) ,
562
562
} ;
563
563
0 commit comments