@@ -7,8 +7,7 @@ use crate::config::LogFormat;
77use crate :: error:: { ConfigError , Error } ;
88use crate :: Args ;
99use cipherstash_client:: config:: vars:: {
10- CS_CLIENT_ACCESS_KEY , CS_CLIENT_ID , CS_CLIENT_KEY , CS_DEFAULT_KEYSET_ID , CS_REGION ,
11- CS_WORKSPACE_CRN , CS_WORKSPACE_ID ,
10+ CS_CLIENT_ACCESS_KEY , CS_CLIENT_ID , CS_CLIENT_KEY , CS_DEFAULT_KEYSET_ID , CS_WORKSPACE_CRN ,
1211} ;
1312use config:: { Config , Environment } ;
1413use cts_common:: Crn ;
@@ -18,15 +17,13 @@ use std::collections::HashMap;
1817use std:: env;
1918use std:: path:: PathBuf ;
2019use std:: sync:: LazyLock ;
21- use tracing:: warn;
2220use uuid:: Uuid ;
2321
2422#[ derive( Clone , Debug , Deserialize ) ]
2523pub struct TandemConfig {
2624 #[ serde( default ) ]
2725 pub server : ServerConfig ,
2826 pub database : DatabaseConfig ,
29- #[ serde( deserialize_with = "deserialise_auth_config" ) ]
3027 pub auth : AuthConfig ,
3128 pub encrypt : EncryptConfig ,
3229 pub tls : Option < TlsConfig > ,
@@ -37,63 +34,10 @@ pub struct TandemConfig {
3734 pub development : Option < DevelopmentConfig > ,
3835}
3936
40- impl TandemConfig {
41- pub fn check_obsolete_config ( & self ) {
42- if let Some ( workspace_id) = & self . auth . obsolete . workspace_id {
43- warn ! (
44- msg = "'workspace_id' is superseded by 'workspace_crn' and will be ignored." ,
45- workspace_id = workspace_id
46- ) ;
47- }
48-
49- if let Some ( region) = & self . auth . obsolete . region {
50- warn ! (
51- msg = "'region' is superseded by 'workspace_crn' and will be ignored." ,
52- region = region
53- ) ;
54- }
55- }
56- }
57-
5837#[ derive( Clone , Debug , Deserialize ) ]
5938pub struct AuthConfig {
6039 pub workspace_crn : Crn ,
6140 pub client_access_key : String ,
62- pub obsolete : ObsoleteAuthConfig ,
63- }
64-
65- /// The old auth config values. Used for issuing warnings but never actually used for configuration
66- #[ derive( Clone , Debug , Deserialize , PartialEq ) ]
67- pub struct ObsoleteAuthConfig {
68- pub workspace_id : Option < String > ,
69- pub region : Option < String > ,
70- }
71-
72- fn deserialise_auth_config < ' de , D > ( deserializer : D ) -> Result < AuthConfig , D :: Error >
73- where
74- D : serde:: Deserializer < ' de > ,
75- {
76- #[ derive( Deserialize ) ]
77- struct AuthConfigRaw {
78- workspace_crn : Crn ,
79- client_access_key : String ,
80- // obsolete methods of configuration
81- workspace_id : Option < String > ,
82- region : Option < String > ,
83- }
84-
85- let auth_config_raw = AuthConfigRaw :: deserialize ( deserializer) ?;
86-
87- let obsolete_config = ObsoleteAuthConfig {
88- workspace_id : auth_config_raw. workspace_id . clone ( ) ,
89- region : auth_config_raw. region . clone ( ) ,
90- } ;
91-
92- Ok ( AuthConfig {
93- workspace_crn : auth_config_raw. workspace_crn ,
94- client_access_key : auth_config_raw. client_access_key ,
95- obsolete : obsolete_config,
96- } )
9741}
9842
9943#[ derive( Debug , Deserialize , Clone , PartialEq ) ]
@@ -210,14 +154,6 @@ impl TandemConfig {
210154 . map_err ( |_| ConfigError :: InvalidWorkspaceCrn { crn : value } ) ?;
211155 }
212156
213- if let Ok ( value) = std:: env:: var ( CS_WORKSPACE_ID ) {
214- env. insert ( "CS_AUTH__WORKSPACE_ID" . into ( ) , value) ;
215- }
216-
217- if let Ok ( value) = std:: env:: var ( CS_REGION ) {
218- env. insert ( "CS_AUTH__REGION" . into ( ) , value) ;
219- }
220-
221157 if let Ok ( value) = std:: env:: var ( CS_CLIENT_ACCESS_KEY ) {
222158 env. insert ( "CS_AUTH__CLIENT_ACCESS_KEY" . into ( ) , value) ;
223159 }
@@ -404,9 +340,7 @@ fn extract_invalid_field(input: &str) -> (String, String) {
404340
405341#[ cfg( test) ]
406342mod tests {
407- use super :: * ;
408- use crate :: log:: { set_format, subscriber} ;
409- use crate :: test_helpers:: { with_no_cs_vars, MockMakeWriter } ;
343+ use crate :: test_helpers:: with_no_cs_vars;
410344 use crate :: {
411345 config:: { tandem:: extract_missing_field_and_key, TandemConfig } ,
412346 error:: Error ,
@@ -415,8 +349,6 @@ mod tests {
415349 CS_CLIENT_ACCESS_KEY , CS_CLIENT_ID , CS_CLIENT_KEY , CS_DEFAULT_KEYSET_ID ,
416350 } ;
417351 use std:: collections:: HashMap ;
418- use tracing:: dispatcher:: set_default;
419- use tracing_subscriber:: fmt:: writer:: BoxMakeWriter ;
420352 use uuid:: Uuid ;
421353
422354 const CS_PREFIX : & str = "CS_TEST" ;
@@ -866,92 +798,4 @@ mod tests {
866798 } )
867799 } )
868800 }
869-
870- #[ test]
871- fn crn_from_toml_with_workspace_id_and_region_env_vars ( ) {
872- let env = merge_env_vars ( vec ! [
873- ( "CS_WORKSPACE_ID" , Some ( "DCMBTGHEX5R2RMR4" ) ) ,
874- ( "CS_REGION" , Some ( "us-west-1" ) ) ,
875- ] ) ;
876-
877- with_no_cs_vars ( || {
878- temp_env:: with_vars ( env, || {
879- // CRN in toml is used
880- let config =
881- TandemConfig :: build ( "tests/config/cipherstash-proxy-with-crn.toml" ) . unwrap ( ) ;
882-
883- assert_eq ! (
884- "E4UMRN47WJNSMAKR" ,
885- config. auth. workspace_crn. workspace_id. to_string( )
886- ) ;
887- assert_eq ! (
888- "us-west-1.aws" ,
889- config. auth. workspace_crn. region. to_string( )
890- ) ;
891-
892- // workspace_id and region in env vars are obsolete
893- assert_eq ! (
894- config. auth. obsolete,
895- ObsoleteAuthConfig {
896- workspace_id: Some ( "DCMBTGHEX5R2RMR4" . to_string( ) ) ,
897- region: Some ( "us-west-1" . to_string( ) ) ,
898- }
899- ) ;
900- } )
901- } ) ;
902- }
903-
904- #[ test]
905- fn crn_with_workspace_id_or_region_in_toml ( ) {
906- with_no_cs_vars ( || {
907- // CRN in toml is used
908- let config = TandemConfig :: build (
909- "tests/config/cipherstash-proxy-with-crn-region-workspace-id.toml" ,
910- )
911- . unwrap ( ) ;
912- assert_eq ! (
913- "E4UMRN47WJNSMAKR" ,
914- config. auth. workspace_crn. workspace_id. to_string( )
915- ) ;
916- assert_eq ! (
917- "us-west-1.aws" ,
918- config. auth. workspace_crn. region. to_string( )
919- ) ;
920-
921- // workspace_id and region in toml are obsolete
922- assert_eq ! (
923- config. auth. obsolete,
924- ObsoleteAuthConfig {
925- workspace_id: Some ( "DCMBTGHEX5R2RMR4" . to_string( ) ) ,
926- region: Some ( "ap-southeast-2.aws" . to_string( ) ) ,
927- }
928- ) ;
929- } ) ;
930- }
931-
932- #[ test]
933- fn print_warnings_about_obsolete_config ( ) {
934- let make_writer = MockMakeWriter :: default ( ) ;
935- let config = LogConfig :: with_level ( LogLevel :: Warn ) ;
936- let subscriber =
937- subscriber:: builder ( & config) . with_writer ( BoxMakeWriter :: new ( make_writer. clone ( ) ) ) ;
938- let subscriber = set_format ( & config, subscriber) ;
939- let _default = set_default ( & subscriber. into ( ) ) ;
940-
941- with_no_cs_vars ( || {
942- let tandem_config = TandemConfig :: build (
943- "tests/config/cipherstash-proxy-with-crn-region-workspace-id.toml" ,
944- )
945- . unwrap ( ) ;
946-
947- tandem_config. check_obsolete_config ( ) ;
948- } ) ;
949-
950- let log_contents = make_writer. get_string ( ) ;
951- assert ! ( log_contents
952- . contains( "'workspace_id' is superseded by 'workspace_crn' and will be ignored." ) ) ;
953- assert ! (
954- log_contents. contains( "'region' is superseded by 'workspace_crn' and will be ignored." )
955- ) ;
956- }
957801}
0 commit comments