@@ -2,7 +2,7 @@ use std::{
2
2
error:: Error ,
3
3
fs:: { self , File } ,
4
4
io:: { self , BufRead , BufReader , BufWriter , Read , Write } ,
5
- path:: PathBuf ,
5
+ path:: { Path , PathBuf } ,
6
6
time:: Duration ,
7
7
} ;
8
8
@@ -26,8 +26,9 @@ struct ProgramArgs {
26
26
/// In order to initialise the secret store, a root secret is also required. A credentials-directory path can be provided
27
27
/// where a `root-secret`` file is expected. This argument corresponds conveniently with systemd's CREDENTIALS_DIRECTORY
28
28
/// environment variable and is used by various services we have written.
29
- /// Also associated with this argument is the `secret_id` file` for role-based authentication with the secret store.
30
- /// This secret is expected to be found in a ss-secret-id file of the directory.
29
+ /// Also associated with this argument is an optional "secret id" file` for role-based authentication with the secret store.
30
+ /// This secret is expected to be found in a ss-secret-id file of the directory and, if not provided, will default to
31
+ /// an "unusedid" value.
31
32
#[ clap( env, long, default_value = "/tmp" ) ]
32
33
pub credentials_directory : PathBuf ,
33
34
@@ -145,14 +146,17 @@ async fn secret_store(
145
146
. ok_or ( Errors :: EmptyRootSecretFile ) ?
146
147
. map_err ( Errors :: RootSecretFileIo ) ?;
147
148
148
- let f = File :: open ( credentials_directory. join ( "ss-secret-id" ) )
149
- . map_err ( Errors :: SecretIdFileIo ) ?;
150
- let f = BufReader :: new ( f) ;
151
- let ss_secret_id = f
152
- . lines ( )
153
- . next ( )
154
- . ok_or ( Errors :: EmptyRootSecretFile ) ?
155
- . map_err ( Errors :: SecretIdFileIo ) ?;
149
+ let ss_secret_id = if Path :: exists ( & credentials_directory. join ( "ss-secret-id" ) ) {
150
+ let f = File :: open ( credentials_directory. join ( "ss-secret-id" ) )
151
+ . map_err ( Errors :: SecretIdFileIo ) ?;
152
+ let f = BufReader :: new ( f) ;
153
+ f. lines ( )
154
+ . next ( )
155
+ . ok_or ( Errors :: EmptyRootSecretFile ) ?
156
+ . map_err ( Errors :: SecretIdFileIo ) ?
157
+ } else {
158
+ String :: from ( "unusedid" )
159
+ } ;
156
160
157
161
( root_secret, ss_secret_id)
158
162
} ;
0 commit comments