forked from cloudtools/stacker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make lookup-logic more generic (cloudtools#665)
* Rewrote Lookup-parser The new parser will build the entire AST to support nested lookups. * Move dependency injection of ${output} to the lookup itself * Addressed comments * Removed dead code * Fix lint warnings * Fix lint errors after master merge * Fix lint error (unused exception) * Add warning when using old style lookups * Convert lookups to new style * Reformat code to fix linting errors
- Loading branch information
1 parent
ee623ba
commit f5100d1
Showing
35 changed files
with
1,063 additions
and
687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
from __future__ import division | ||
|
||
|
||
class LookupHandler(object): | ||
@classmethod | ||
def handle(cls, value, context, provider): | ||
""" | ||
Perform the actual lookup | ||
:param value: Parameter(s) given to this lookup | ||
:type value: str | ||
:param context: | ||
:param provider: | ||
:return: Looked-up value | ||
:rtype: str | ||
""" | ||
raise NotImplementedError() | ||
|
||
@classmethod | ||
def dependencies(cls, lookup_data): | ||
""" | ||
Calculate any dependencies required to perform this lookup. | ||
Note that lookup_data may not be (completely) resolved at this time. | ||
:param lookup_data: Parameter(s) given to this lookup | ||
:type lookup_data VariableValue | ||
:return: Set of stack names (str) this lookup depends on | ||
:rtype: set | ||
""" | ||
del lookup_data # unused in this implementation | ||
return set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
from __future__ import print_function | ||
from __future__ import division | ||
from __future__ import absolute_import | ||
|
||
from . import LookupHandler | ||
|
||
|
||
TYPE_NAME = "default" | ||
|
||
|
||
def handler(value, **kwargs): | ||
"""Use a value from the environment or fall back to a default if the | ||
environment doesn't contain the variable. | ||
class DefaultLookup(LookupHandler): | ||
@classmethod | ||
def handle(cls, value, **kwargs): | ||
"""Use a value from the environment or fall back to a default if the | ||
environment doesn't contain the variable. | ||
Format of value: | ||
Format of value: | ||
<env_var>::<default value> | ||
<env_var>::<default value> | ||
For example: | ||
For example: | ||
Groups: ${default app_security_groups::sg-12345,sg-67890} | ||
Groups: ${default app_security_groups::sg-12345,sg-67890} | ||
If `app_security_groups` is defined in the environment, its defined value | ||
will be returned. Otherwise, `sg-12345,sg-67890` will be the returned | ||
value. | ||
If `app_security_groups` is defined in the environment, its defined | ||
value will be returned. Otherwise, `sg-12345,sg-67890` will be the | ||
returned value. | ||
This allows defaults to be set at the config file level. | ||
""" | ||
This allows defaults to be set at the config file level. | ||
""" | ||
|
||
try: | ||
env_var_name, default_val = value.split("::", 1) | ||
except ValueError: | ||
raise ValueError("Invalid value for default: %s. Must be in " | ||
"<env_var>::<default value> format." % value) | ||
try: | ||
env_var_name, default_val = value.split("::", 1) | ||
except ValueError: | ||
raise ValueError("Invalid value for default: %s. Must be in " | ||
"<env_var>::<default value> format." % value) | ||
|
||
if env_var_name in kwargs['context'].environment: | ||
return kwargs['context'].environment[env_var_name] | ||
else: | ||
return default_val | ||
if env_var_name in kwargs['context'].environment: | ||
return kwargs['context'].environment[env_var_name] | ||
else: | ||
return default_val |
Oops, something went wrong.