7
7
8
8
from pyms .cloud .aws .kms import Crypt as CryptAws
9
9
from pyms .config import get_conf
10
- from pyms .constants import LOGGER_NAME , CONFIGMAP_FILE_ENVIRONMENT , CRYPT_FILE_KEY_ENVIRONMENT , CONFIG_BASE
10
+ from pyms .constants import LOGGER_NAME , CONFIGMAP_FILE_ENVIRONMENT , CRYPT_FILE_KEY_ENVIRONMENT , CONFIG_BASE , \
11
+ CRYPT_FILE_KEY_ENVIRONMENT_LEGACY
11
12
from pyms .crypt .driver import CryptAbstract , CryptResource
12
13
from pyms .crypt .fernet import Crypt as CryptFernet
13
14
from pyms .exceptions import FileDoesNotExistException
@@ -78,7 +79,10 @@ def setUp(self):
78
79
79
80
def tearDown (self ):
80
81
del os .environ [CONFIGMAP_FILE_ENVIRONMENT ]
81
- del os .environ [CRYPT_FILE_KEY_ENVIRONMENT ]
82
+ if os .getenv (CRYPT_FILE_KEY_ENVIRONMENT ):
83
+ del os .environ [CRYPT_FILE_KEY_ENVIRONMENT ]
84
+ if os .getenv (CRYPT_FILE_KEY_ENVIRONMENT_LEGACY ):
85
+ del os .environ [CRYPT_FILE_KEY_ENVIRONMENT_LEGACY ]
82
86
83
87
def test_encrypt_conf (self ):
84
88
crypt = CryptFernet (path = self .BASE_DIR )
@@ -87,6 +91,15 @@ def test_encrypt_conf(self):
87
91
crypt .delete_key ()
88
92
assert config .database_url == "http://database-url"
89
93
94
+ def test_encrypt_conf_deprecated_env (self ):
95
+ os .environ [CRYPT_FILE_KEY_ENVIRONMENT_LEGACY ] = os .getenv (CRYPT_FILE_KEY_ENVIRONMENT )
96
+ del os .environ [CRYPT_FILE_KEY_ENVIRONMENT ]
97
+ crypt = CryptFernet (path = self .BASE_DIR )
98
+ crypt ._loader .put_file (b"9IXx2F5d5Ob-h5xdCnFSUXhuFKLGRibvLfSbixpcfCw=" , "wb" )
99
+ config = get_conf (service = CONFIG_BASE , uppercase = True , crypt = CryptFernet )
100
+ crypt .delete_key ()
101
+ assert config .database_url == "http://database-url"
102
+
90
103
91
104
class GetConfigEncryptedAWS (unittest .TestCase ):
92
105
BASE_DIR = os .path .dirname (os .path .abspath (__file__ ))
0 commit comments