@@ -587,7 +587,7 @@ def test_get_config_dynamic_config_item_under_pattern_properties(self):
587587 )
588588
589589 ####################
590- # values in objects under an object with additionalProperties
590+ # values in objects under an object with patternProperties
591591 values = {
592592 "profiles" : {
593593 "dev" : {
@@ -630,6 +630,105 @@ def test_get_config_dynamic_config_item_under_pattern_properties(self):
630630
631631 config_db .delete ()
632632
633+ def test_get_config_dynamic_config_item_properties_order_of_precedence (self ):
634+ pack_name = "dummy_pack_schema_with_properties_1"
635+ loader = ContentPackConfigLoader (pack_name = pack_name )
636+
637+ encrypted_value = crypto .symmetric_encrypt (
638+ KeyValuePairAPI .crypto_key , "v1_encrypted"
639+ )
640+ KeyValuePair .add_or_update (
641+ KeyValuePairDB (name = "k1_encrypted" , value = encrypted_value , secret = True )
642+ )
643+ KeyValuePair .add_or_update (
644+ KeyValuePairDB (name = "k2_encrypted" , value = encrypted_value , secret = True )
645+ )
646+ KeyValuePair .add_or_update (
647+ KeyValuePairDB (name = "k3_encrypted" , value = encrypted_value , secret = True )
648+ )
649+
650+ ####################
651+ # values in objects under an object with additionalProperties
652+ values = {
653+ "profiles" : {
654+ # properties
655+ "foo" : {
656+ "domain" : "foo.example.com" ,
657+ "token" : "hard-coded-secret" ,
658+ },
659+ "bar" : {
660+ "domain" : "bar.example.com" ,
661+ "token" : "{{st2kv.system.k1_encrypted}}" ,
662+ },
663+ # patternProperties start with env-
664+ "env-dev" : {
665+ "host" : "127.0.0.127" ,
666+ "token" : "hard-coded-secret" ,
667+ },
668+ "env-prod" : {
669+ "host" : "127.1.2.7" ,
670+ "port" : 8282 ,
671+ # encrypted in datastore
672+ "token" : "{{st2kv.system.k2_encrypted}}" ,
673+ # schema declares `secret: true` which triggers auto-decryption.
674+ # If this were not encrypted, it would try to decrypt it and fail.
675+ },
676+ # additionalProperties
677+ "dev" : {
678+ "url" : "https://example.com" ,
679+ "token" : "hard-coded-secret" ,
680+ },
681+ "prod" : {
682+ "url" : "https://other.example.com" ,
683+ "port" : 2345 ,
684+ "token" : "{{st2kv.system.k3_encrypted}}" ,
685+ },
686+ }
687+ }
688+ config_db = ConfigDB (pack = pack_name , values = values )
689+ config_db = Config .add_or_update (config_db )
690+
691+ config_rendered = loader .get_config ()
692+
693+ self .assertEqual (
694+ config_rendered ,
695+ {
696+ "region" : "us-east-1" ,
697+ "profiles" : {
698+ "foo" : {
699+ "domain" : "foo.example.com" ,
700+ "token" : "hard-coded-secret" ,
701+ },
702+ "bar" : {
703+ "domain" : "bar.example.com" ,
704+ "token" : "v1_encrypted" ,
705+ },
706+ "env-dev" : {
707+ "host" : "127.0.0.127" ,
708+ "port" : 8080 ,
709+ "token" : "hard-coded-secret" ,
710+ },
711+ "env-prod" : {
712+ "host" : "127.1.2.7" ,
713+ "port" : 8282 ,
714+ "token" : "v1_encrypted" ,
715+ },
716+ "dev" : {
717+ "url" : "https://example.com" ,
718+ "port" : 1234 ,
719+ "token" : "hard-coded-secret" ,
720+ },
721+ "prod" : {
722+ "url" : "https://other.example.com" ,
723+ "port" : 2345 ,
724+ "token" : "v1_encrypted" ,
725+ },
726+ },
727+ },
728+ )
729+
730+ config_db .delete ()
731+
633732 def test_get_config_dynamic_config_item_under_additional_items (self ):
634733 pack_name = "dummy_pack_schema_with_additional_items_1"
635734 loader = ContentPackConfigLoader (pack_name = pack_name )
0 commit comments