Module contents
aws_cdk_config.config module
- class aws_cdk_config.config.CdkConfig(*, config_file: str | None = None, file_format: str | None = None, config: dict = {}, namespace: str = '', inputs: List[Input] | List[dict] = [])
Bases:
object
Create a config of inputs. Values can be passed via config_file or config argument. The inputs themselves can be passed either as inputs or added after instantiation with add_input()
- Parameters:
config_file – Path to a config file to take values from
file_format – JSON or YAML, only used with config_file
config – Dict containing values to be passed to inputs. Can be used with, or instead of, a config file
namespace – Parse values from a top level key
inputs – Optional list of either Input or dict, that can be passed unpacked as arguments to Input. Removes the need to use CdkConfig.add_input()
- add_input(*args, **kwargs) None
Adds inputs to self.__inputs so they are ready for self.parse(). Accepts the same inputs as the Inputs class
- as_dict() dict
Return the config as a dict with the input’s name as the key and the full input as the value
- get_namespace() str
Returns the namespace passed in initializer from which all input values are taken
- items()
Returns self.as_dict().items() iterable
- parse() None
Parse the config and make it immutable. If the config has already been parsed then AlreadyInitialized will be raised.
- classmethod validate_input_name(name: str) bool
Validates that input names are valid python identifiers. Will either return True or raise CdkConfig.exceptions.InputError
- Raises:
CdkConfig.exceptions.InputError
- values()
Returns self.as_dict().values()
- Returns:
dict_values
aws_cdk_config.exceptions module
- exception aws_cdk_config.exceptions.AlreadyInitialized(message='Cannot add inputs after config is parsed.')
Bases:
InputError
Raised when calling CdkConfig.add_input() or CdkConfig.parse() after CdkConfig.parse() has already been called
- exception aws_cdk_config.exceptions.ConfigurationError(message='Invalid config')
Bases:
InputError
Raised when the config file cannot be parsed due to formatting
- exception aws_cdk_config.exceptions.InputError
Bases:
Exception
- exception aws_cdk_config.exceptions.InputTypeError(name: str, expected: type, got: type)
Bases:
InputError
Raised when an input’s value doesn’t match its declared type
- exception aws_cdk_config.exceptions.InputValidationError(name, message='')
Bases:
InputError
Raised when an input fails its own validator
- exception aws_cdk_config.exceptions.NamespaceError(namespace)
Bases:
InputError
Raised when namespace is passed to CdkConfig but doesn’t exist in the config
aws_cdk_config.input module
- class aws_cdk_config.input.Input(name: str, type: type, value: ~typing.Any = <aws_cdk_config.input.NoValue object>, description: str = '', validator: ~typing.Callable = <function Input.<lambda>>)
Bases:
NamedTuple
- Parameters:
name – A valid identifier for the input. Inputs will be added to the CdkConfig object and accessed by their name attribute. The builtin str.isidentifier(name) must return True
type – This can be any python type. Inputs will be validated against their type here. Input values will also be cast to these types when the config is parsed. Since YAML and JSON don’t allow for complex types we will pass values that are sequences as *args and dicts as **kwargs to the class’s initializer
validator – Any callable accepts the value as the first and only argument and returns a boolean. If it returns False a validation error will be raised.
value – A default value
- Pamam description:
A description for the input. Also used in CdkConfig.print()
- description: str
Alias for field number 3
- property dict
Returns NamedTuple._asdict()
- property json
Deserializes complex objects and returns a JSON string
- name: str
Alias for field number 0
- type: type
Alias for field number 1
- validator: Callable
Alias for field number 4
- value: Any
Alias for field number 2
- class aws_cdk_config.input.NoValue
Bases:
object
Provides a type that we can use for inputs without a value passed that won’t conflict with None