16
16
*
17
17
*/
18
18
19
+ use clap:: error:: ErrorKind ;
19
20
use clap:: { command, value_parser, Arg , Args , Command , FromArgMatches } ;
20
- use crossterm :: style :: Stylize ;
21
+
21
22
use std:: path:: { Path , PathBuf } ;
22
23
use std:: sync:: Arc ;
23
24
24
- use crate :: banner;
25
25
use crate :: storage:: {
26
26
FSConfig , ObjectStorage , ObjectStorageError , ObjectStorageProvider , S3Config ,
27
27
LOCAL_SYNC_INTERVAL ,
28
28
} ;
29
- use crate :: utils:: capitalize_ascii;
30
29
31
30
lazy_static:: lazy_static! {
32
31
#[ derive( Debug ) ]
@@ -54,6 +53,15 @@ impl Config {
54
53
Err ( err) => err. exit ( ) ,
55
54
} ;
56
55
56
+ if server. local_staging_path == storage. root {
57
+ parseable_cli_command ( )
58
+ . error (
59
+ ErrorKind :: ValueValidation ,
60
+ "Cannot use same path for storage and staging" ,
61
+ )
62
+ . exit ( )
63
+ }
64
+
57
65
Config {
58
66
parseable : server,
59
67
storage : Arc :: new ( storage) ,
@@ -80,15 +88,6 @@ impl Config {
80
88
}
81
89
}
82
90
83
- pub fn print ( & self ) {
84
- let scheme = CONFIG . parseable . get_scheme ( ) ;
85
- self . status_info ( & scheme) ;
86
- banner:: version:: print ( ) ;
87
- self . storage_info ( ) ;
88
- banner:: system_info ( ) ;
89
- println ! ( ) ;
90
- }
91
-
92
91
pub fn validate ( & self ) {
93
92
if CONFIG . parseable . upload_interval < LOCAL_SYNC_INTERVAL {
94
93
panic ! ( "object storage upload_interval (P_STORAGE_UPLOAD_INTERVAL) must be 60 seconds or more" ) ;
@@ -113,39 +112,18 @@ impl Config {
113
112
}
114
113
}
115
114
116
- fn status_info ( & self , scheme : & str ) {
117
- let url = format ! ( "{}://{}" , scheme, self . parseable. address) . underlined ( ) ;
118
- eprintln ! (
119
- "
120
- {}
121
- {}
122
- {}" ,
123
- format!( "Parseable server started at: {}" , url) . bold( ) ,
124
- format!( "Username: {}" , self . parseable. username) . bold( ) ,
125
- format!( "Password: {}" , self . parseable. password) . bold( ) ,
126
- )
127
- }
128
-
129
- fn storage_info ( & self ) {
130
- eprintln ! (
131
- "
132
- {}
133
- Local Staging Path: {}
134
- {} Storage: {}" ,
135
- "Storage:" . to_string( ) . blue( ) . bold( ) ,
136
- self . staging_dir( ) . to_string_lossy( ) ,
137
- capitalize_ascii( self . storage_name) ,
138
- self . storage( ) . get_endpoint( ) ,
139
- )
140
- }
141
-
142
115
pub fn storage ( & self ) -> Arc < dyn ObjectStorageProvider + Send + Sync > {
143
116
self . storage . clone ( )
144
117
}
145
118
146
119
pub fn staging_dir ( & self ) -> & Path {
147
120
& self . parseable . local_staging_path
148
121
}
122
+
123
+ pub fn is_default_creds ( & self ) -> bool {
124
+ self . parseable . username == Server :: DEFAULT_USERNAME
125
+ && self . parseable . password == Server :: DEFAULT_PASSWORD
126
+ }
149
127
}
150
128
151
129
impl Default for Config {
@@ -160,10 +138,10 @@ fn parseable_cli_command() -> Command {
160
138
161
139
let local = local
162
140
. mut_arg ( Server :: USERNAME , |arg| {
163
- arg. required ( false ) . default_value ( "admin" )
141
+ arg. required ( false ) . default_value ( Server :: DEFAULT_USERNAME )
164
142
} )
165
143
. mut_arg ( Server :: PASSWORD , |arg| {
166
- arg. required ( false ) . default_value ( "admin" )
144
+ arg. required ( false ) . default_value ( Server :: DEFAULT_PASSWORD )
167
145
} ) ;
168
146
169
147
let s3 = Server :: get_clap_command ( "--s3-store" ) ;
@@ -259,6 +237,8 @@ impl Server {
259
237
pub const UPLOAD_INTERVAL : & str = "upload-interval" ;
260
238
pub const USERNAME : & str = "username" ;
261
239
pub const PASSWORD : & str = "password" ;
240
+ pub const DEFAULT_USERNAME : & str = "admin" ;
241
+ pub const DEFAULT_PASSWORD : & str = "admin" ;
262
242
263
243
pub fn local_stream_data_path ( & self , stream_name : & str ) -> PathBuf {
264
244
self . local_staging_path . join ( stream_name)
@@ -305,7 +285,7 @@ impl Server {
305
285
. env ( "P_STAGING_DIR" )
306
286
. value_name ( "DIR" )
307
287
. default_value ( "./staging" )
308
- . value_parser ( value_parser ! ( PathBuf ) )
288
+ . value_parser ( validation :: canonicalize_path )
309
289
. help ( "The local staging path is used as a temporary landing point for incoming events and local cache" )
310
290
. next_line_help ( true ) ,
311
291
)
@@ -339,7 +319,11 @@ impl Server {
339
319
}
340
320
341
321
pub mod validation {
342
- use std:: { net:: ToSocketAddrs , path:: PathBuf } ;
322
+ use std:: {
323
+ fs:: { canonicalize, create_dir_all} ,
324
+ net:: ToSocketAddrs ,
325
+ path:: PathBuf ,
326
+ } ;
343
327
344
328
pub fn file_path ( s : & str ) -> Result < PathBuf , String > {
345
329
if s. is_empty ( ) {
@@ -355,6 +339,17 @@ pub mod validation {
355
339
Ok ( path)
356
340
}
357
341
342
+ pub fn canonicalize_path ( s : & str ) -> Result < PathBuf , String > {
343
+ let path = PathBuf :: from ( s) ;
344
+
345
+ create_dir_all ( & path)
346
+ . map_err ( |err| err. to_string ( ) )
347
+ . and_then ( |_| {
348
+ canonicalize ( & path)
349
+ . map_err ( |_| "Cannot use the path provided as an absolute path" . to_string ( ) )
350
+ } )
351
+ }
352
+
358
353
pub fn socket_addr ( s : & str ) -> Result < String , String > {
359
354
s. to_socket_addrs ( )
360
355
. is_ok ( )
0 commit comments