Skip to content

Commit

Permalink
Merge pull request #1154 from octodns/env-int-refix
Browse files Browse the repository at this point in the history
Fix env var int handling regression
  • Loading branch information
ross committed Mar 17, 2024
2 parents b5047f9 + c263b6e commit b2d3c41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
12 changes: 0 additions & 12 deletions octodns/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,6 @@ def _build_kwargs(self, source):
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
Expand Down
11 changes: 8 additions & 3 deletions octodns/secret/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ def fetch(self, name, source):
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
14 changes: 11 additions & 3 deletions tests/test_octodns_secret_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ def test_environ_secrets(self):
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)
Expand Down

0 comments on commit b2d3c41

Please sign in to comment.