Merge pull request #1154 from octodns/env-int-refix

Fix env var int handling regression
This commit is contained in:
Ross McFarland
2024-03-17 12:39:13 -07:00
committed by GitHub
3 changed files with 19 additions and 18 deletions
-12
View File
@@ -434,18 +434,6 @@ class Manager(object):
else:
v = handler.fetch(name, source)
if isinstance(v, str):
try:
if '.' in v:
# has a dot, try converting it to a float
v = float(v)
else:
# no dot, try converting it to an int
v = int(v)
except ValueError:
# just leave it as a string
pass
kwargs[k] = v
return kwargs
+8 -3
View File
@@ -22,11 +22,16 @@ class EnvironSecrets(BaseSecrets):
raise EnvironSecretsException(
f'Incorrect provider config, missing env var {name}, {source.context}'
)
try:
# try converting the value to a number to see if it
# converts
v = float(v)
if '.' in v:
# has a dot, try converting it to a float
v = float(v)
else:
# no dot, try converting it to an int
v = int(v)
except ValueError:
# just leave it as a string
pass
return v
+11 -3
View File
@@ -19,9 +19,17 @@ class TestEnvironSecrets(TestCase):
es = EnvironSecrets('env')
source = ContextDict({}, context='xyz')
self.assertEqual('and has a val', es.fetch('THIS_EXISTS', source))
self.assertEqual(42, es.fetch('THIS_IS_AN_INT', source))
self.assertEqual(43.44, es.fetch('THIS_IS_A_FLOAT', source))
v = es.fetch('THIS_EXISTS', source)
self.assertEqual('and has a val', v)
self.assertIsInstance(v, str)
v = es.fetch('THIS_IS_AN_INT', source)
self.assertEqual(42, v)
self.assertIsInstance(v, int)
v = es.fetch('THIS_IS_A_FLOAT', source)
self.assertEqual(43.44, v)
self.assertIsInstance(v, float)
with self.assertRaises(EnvironSecretsException) as ctx:
es.fetch('DOES_NOT_EXIST', source)