@@ -171,7 +171,7 @@ fn log_fallback_reason(reason: &str) {
171171 println ! ( "{{\" DD_EXTENSION_FALLBACK_REASON\" :\" {reason}\" }}" ) ;
172172}
173173
174- fn fallback ( figment : & Figment , yaml_figment : & Figment ) -> Result < ( ) , ConfigError > {
174+ fn fallback ( figment : & Figment , yaml_figment : & Figment , region : & str ) -> Result < ( ) , ConfigError > {
175175 let ( config, yaml_config) : ( FallbackConfig , FallbackYamlConfig ) =
176176 match ( figment. extract ( ) , yaml_figment. extract ( ) ) {
177177 ( Ok ( env_config) , Ok ( yaml_config) ) => ( env_config, yaml_config) ,
@@ -237,11 +237,17 @@ fn fallback(figment: &Figment, yaml_figment: &Figment) -> Result<(), ConfigError
237237 return Err ( ConfigError :: UnsupportedField ( "intake_urls" . to_string ( ) ) ) ;
238238 }
239239
240+ // Govcloud Regions
241+ if region. starts_with ( "us-gov-" ) {
242+ log_fallback_reason ( "gov_region" ) ;
243+ return Err ( ConfigError :: UnsupportedField ( "gov_region" . to_string ( ) ) ) ;
244+ }
245+
240246 Ok ( ( ) )
241247}
242248
243249#[ allow( clippy:: module_name_repetitions) ]
244- pub fn get_config ( config_directory : & Path ) -> Result < Config , ConfigError > {
250+ pub fn get_config ( config_directory : & Path , region : & str ) -> Result < Config , ConfigError > {
245251 let path = config_directory. join ( "datadog.yaml" ) ;
246252
247253 // Get default config fields (and ENV specific ones)
@@ -254,7 +260,7 @@ pub fn get_config(config_directory: &Path) -> Result<Config, ConfigError> {
254260 // Get YAML nested fields
255261 let yaml_figment = Figment :: from ( Yaml :: file ( & path) ) ;
256262
257- fallback ( & figment, & yaml_figment) ?;
263+ fallback ( & figment, & yaml_figment, region ) ?;
258264
259265 let ( mut config, yaml_config) : ( Config , YamlConfig ) =
260266 match ( figment. extract ( ) , yaml_figment. extract ( ) ) {
@@ -359,19 +365,32 @@ pub mod tests {
359365 use crate :: config:: flush_strategy:: PeriodicStrategy ;
360366 use crate :: config:: processing_rule;
361367
368+ const MOCK_REGION : & str = "us-east-1" ;
369+
362370 #[ test]
363371 fn test_reject_on_opted_out ( ) {
364372 figment:: Jail :: expect_with ( |jail| {
365373 jail. clear_env ( ) ;
366374 jail. set_env ( "DD_EXTENSION_VERSION" , "compatibility" ) ;
367- let config = get_config ( Path :: new ( "" ) ) . expect_err ( "should reject unknown fields" ) ;
375+ let config =
376+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect_err ( "should reject unknown fields" ) ;
368377 assert_eq ! (
369378 config,
370379 ConfigError :: UnsupportedField ( "extension_version" . to_string( ) )
371380 ) ;
372381 Ok ( ( ) )
373382 } ) ;
374383 }
384+ #[ test]
385+ fn test_reject_on_gov_region ( ) {
386+ let mock_gov_region = "us-gov-east-1" ;
387+ let config =
388+ get_config ( Path :: new ( "" ) , mock_gov_region) . expect_err ( "should reject unknown fields" ) ;
389+ assert_eq ! (
390+ config,
391+ ConfigError :: UnsupportedField ( "gov_region" . to_string( ) )
392+ ) ;
393+ }
375394
376395 #[ test]
377396 fn test_fallback_on_otel ( ) {
@@ -382,7 +401,8 @@ pub mod tests {
382401 "localhost:4138" ,
383402 ) ;
384403
385- let config = get_config ( Path :: new ( "" ) ) . expect_err ( "should reject unknown fields" ) ;
404+ let config =
405+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect_err ( "should reject unknown fields" ) ;
386406 assert_eq ! ( config, ConfigError :: UnsupportedField ( "otel" . to_string( ) ) ) ;
387407 Ok ( ( ) )
388408 } ) ;
@@ -403,7 +423,8 @@ pub mod tests {
403423 " ,
404424 ) ?;
405425
406- let config = get_config ( Path :: new ( "" ) ) . expect_err ( "should reject unknown fields" ) ;
426+ let config =
427+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect_err ( "should reject unknown fields" ) ;
407428 assert_eq ! ( config, ConfigError :: UnsupportedField ( "otel" . to_string( ) ) ) ;
408429 Ok ( ( ) )
409430 } ) ;
@@ -423,7 +444,8 @@ pub mod tests {
423444 " ,
424445 ) ?;
425446
426- let config = get_config ( Path :: new ( "" ) ) . expect_err ( "should reject unknown fields" ) ;
447+ let config =
448+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect_err ( "should reject unknown fields" ) ;
427449 assert_eq ! ( config, ConfigError :: UnsupportedField ( "otel" . to_string( ) ) ) ;
428450 Ok ( ( ) )
429451 } ) ;
@@ -435,7 +457,8 @@ pub mod tests {
435457 jail. clear_env ( ) ;
436458 jail. set_env ( "DD_APM_DD_URL" , "some_url" ) ;
437459
438- let config = get_config ( Path :: new ( "" ) ) . expect_err ( "should reject unknown fields" ) ;
460+ let config =
461+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect_err ( "should reject unknown fields" ) ;
439462 assert_eq ! (
440463 config,
441464 ConfigError :: UnsupportedField ( "intake_urls" . to_string( ) )
@@ -456,7 +479,8 @@ pub mod tests {
456479 " ,
457480 ) ?;
458481
459- let config = get_config ( Path :: new ( "" ) ) . expect_err ( "should reject unknown fields" ) ;
482+ let config =
483+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect_err ( "should reject unknown fields" ) ;
460484 assert_eq ! (
461485 config,
462486 ConfigError :: UnsupportedField ( "intake_urls" . to_string( ) )
@@ -471,7 +495,8 @@ pub mod tests {
471495 jail. clear_env ( ) ;
472496 jail. set_env ( "DD_SERVERLESS_APPSEC_ENABLED" , "true" ) ;
473497
474- let config = get_config ( Path :: new ( "" ) ) . expect_err ( "should reject unknown fields" ) ;
498+ let config =
499+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect_err ( "should reject unknown fields" ) ;
475500 assert_eq ! (
476501 config,
477502 ConfigError :: UnsupportedField ( "appsec_enabled" . to_string( ) )
@@ -491,7 +516,7 @@ pub mod tests {
491516 " ,
492517 ) ?;
493518 jail. set_env ( "DD_SITE" , "datad0g.com" ) ;
494- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
519+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
495520 assert_eq ! ( config. site, "datad0g.com" ) ;
496521 Ok ( ( ) )
497522 } ) ;
@@ -506,7 +531,7 @@ pub mod tests {
506531 r"
507532 " ,
508533 ) ?;
509- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
534+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
510535 assert_eq ! ( config. site, "datadoghq.com" ) ;
511536 Ok ( ( ) )
512537 } ) ;
@@ -517,7 +542,7 @@ pub mod tests {
517542 figment:: Jail :: expect_with ( |jail| {
518543 jail. clear_env ( ) ;
519544 jail. set_env ( "DD_SITE" , "datadoghq.eu" ) ;
520- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
545+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
521546 assert_eq ! ( config. site, "datadoghq.eu" ) ;
522547 Ok ( ( ) )
523548 } ) ;
@@ -528,7 +553,7 @@ pub mod tests {
528553 figment:: Jail :: expect_with ( |jail| {
529554 jail. clear_env ( ) ;
530555 jail. set_env ( "DD_LOG_LEVEL" , "TRACE" ) ;
531- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
556+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
532557 assert_eq ! ( config. log_level, LogLevel :: Trace ) ;
533558 Ok ( ( ) )
534559 } ) ;
@@ -538,7 +563,7 @@ pub mod tests {
538563 fn test_parse_default ( ) {
539564 figment:: Jail :: expect_with ( |jail| {
540565 jail. clear_env ( ) ;
541- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
566+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
542567 assert_eq ! (
543568 config,
544569 Config {
@@ -559,7 +584,7 @@ pub mod tests {
559584 figment:: Jail :: expect_with ( |jail| {
560585 jail. clear_env ( ) ;
561586 jail. set_env ( "DD_PROXY_HTTPS" , "my-proxy:3128" ) ;
562- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
587+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
563588 assert_eq ! ( config. https_proxy, Some ( "my-proxy:3128" . to_string( ) ) ) ;
564589 Ok ( ( ) )
565590 } ) ;
@@ -575,7 +600,7 @@ pub mod tests {
575600 "NO_PROXY" ,
576601 "127.0.0.1,localhost,172.16.0.0/12,us-east-1.amazonaws.com,datadoghq.eu" ,
577602 ) ;
578- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse noproxy" ) ;
603+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse noproxy" ) ;
579604 assert_eq ! ( config. https_proxy, None ) ;
580605 Ok ( ( ) )
581606 } ) ;
@@ -593,7 +618,8 @@ pub mod tests {
593618 " ,
594619 ) ?;
595620
596- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse weird proxy config" ) ;
621+ let config =
622+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse weird proxy config" ) ;
597623 assert_eq ! ( config. https_proxy, Some ( "my-proxy:3128" . to_string( ) ) ) ;
598624 Ok ( ( ) )
599625 } ) ;
@@ -613,7 +639,8 @@ pub mod tests {
613639 " ,
614640 ) ?;
615641
616- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse weird proxy config" ) ;
642+ let config =
643+ get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse weird proxy config" ) ;
617644 assert_eq ! ( config. https_proxy, None ) ;
618645 // Assertion to ensure config.site runs before proxy
619646 // because we chenck that noproxy contains the site
@@ -627,7 +654,7 @@ pub mod tests {
627654 figment:: Jail :: expect_with ( |jail| {
628655 jail. clear_env ( ) ;
629656 jail. set_env ( "DD_SERVERLESS_FLUSH_STRATEGY" , "end" ) ;
630- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
657+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
631658 assert_eq ! ( config. serverless_flush_strategy, FlushStrategy :: End ) ;
632659 Ok ( ( ) )
633660 } ) ;
@@ -638,7 +665,7 @@ pub mod tests {
638665 figment:: Jail :: expect_with ( |jail| {
639666 jail. clear_env ( ) ;
640667 jail. set_env ( "DD_SERVERLESS_FLUSH_STRATEGY" , "periodically,100000" ) ;
641- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
668+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
642669 assert_eq ! (
643670 config. serverless_flush_strategy,
644671 FlushStrategy :: Periodically ( PeriodicStrategy { interval: 100_000 } )
@@ -652,7 +679,7 @@ pub mod tests {
652679 figment:: Jail :: expect_with ( |jail| {
653680 jail. clear_env ( ) ;
654681 jail. set_env ( "DD_SERVERLESS_FLUSH_STRATEGY" , "invalid_strategy" ) ;
655- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
682+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
656683 assert_eq ! ( config. serverless_flush_strategy, FlushStrategy :: Default ) ;
657684 Ok ( ( ) )
658685 } ) ;
@@ -666,7 +693,7 @@ pub mod tests {
666693 "DD_SERVERLESS_FLUSH_STRATEGY" ,
667694 "periodically,invalid_interval" ,
668695 ) ;
669- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
696+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
670697 assert_eq ! ( config. serverless_flush_strategy, FlushStrategy :: Default ) ;
671698 Ok ( ( ) )
672699 } ) ;
@@ -677,7 +704,7 @@ pub mod tests {
677704 figment:: Jail :: expect_with ( |jail| {
678705 jail. clear_env ( ) ;
679706 jail. set_env ( "DD_VERSION" , "123" ) ;
680- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
707+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
681708 assert_eq ! ( config. version. expect( "failed to parse DD_VERSION" ) , "123" ) ;
682709 Ok ( ( ) )
683710 } ) ;
@@ -702,7 +729,7 @@ pub mod tests {
702729 pattern: exclude-me-yaml
703730 " ,
704731 ) ?;
705- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
732+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
706733 assert_eq ! (
707734 config. logs_config_processing_rules,
708735 Some ( vec![ ProcessingRule {
@@ -731,7 +758,7 @@ pub mod tests {
731758 pattern: exclude
732759 " ,
733760 ) ?;
734- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
761+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
735762 assert_eq ! (
736763 config. logs_config_processing_rules,
737764 Some ( vec![ ProcessingRule {
@@ -754,7 +781,7 @@ pub mod tests {
754781 "datadog,tracecontext,b3,b3multi" ,
755782 ) ;
756783 jail. set_env ( "DD_EXTENSION_VERSION" , "next" ) ;
757- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
784+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
758785
759786 let expected_styles = vec ! [
760787 TracePropagationStyle :: Datadog ,
@@ -773,7 +800,7 @@ pub mod tests {
773800 figment:: Jail :: expect_with ( |jail| {
774801 jail. clear_env ( ) ;
775802 jail. set_env ( "DD_TRACE_PROPAGATION_STYLE_EXTRACT" , "datadog" ) ;
776- let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
803+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) . expect ( "should parse config" ) ;
777804
778805 assert_eq ! (
779806 config. trace_propagation_style,
@@ -798,7 +825,7 @@ pub mod tests {
798825 "DD_APM_REPLACE_TAGS" ,
799826 r#"[{"name":"resource.name","pattern":"(.*)/(foo[:%].+)","repl":"$1/{foo}"}]"# ,
800827 ) ;
801- let config = get_config ( Path :: new ( "" ) ) ;
828+ let config = get_config ( Path :: new ( "" ) , MOCK_REGION ) ;
802829 assert ! ( config. is_ok( ) ) ;
803830 Ok ( ( ) )
804831 } ) ;
0 commit comments