ecs_files_composer package

Subpackages

Submodules

ecs_files_composer.aws_mgmt module

AWS module.

class ecs_files_composer.aws_mgmt. AwsResourceHandler ( role_arn = None , external_id = None , region = None , iam_config_object = None , client_session_override = None ) [source]

Bases: object

Class to handle all AWS related credentials init.

class ecs_files_composer.aws_mgmt. S3Fetcher ( role_arn = None , external_id = None , region = None , iam_config_object = None , client_session_override = None ) [source]

Bases: ecs_files_composer.aws_mgmt.AwsResourceHandler

Class to handle S3 actions

bucket_re = re.compile('(?:s3://)(?P<bucket>[a-z0-9-.]+)/(?P<key>[\\S]+$)')
get_content ( s3_uri = None , s3_bucket = None , s3_key = None ) [source]

Retrieves a file in a temp dir and returns content

Parameters
  • s3_uri ( str ) –

  • s3_bucket ( str ) –

  • s3_key ( str ) –

Returns

The Stream Body for the file, allowing to do various things

class ecs_files_composer.aws_mgmt. SecretFetcher ( role_arn = None , external_id = None , region = None , iam_config_object = None , client_session_override = None ) [source]

Bases: ecs_files_composer.aws_mgmt.AwsResourceHandler

Class to handle Secret Manager actions

get_content ( secret ) [source]

Import the Content of a given parameter

Parameters

secret ( input.SecretDef ) –

Returns

class ecs_files_composer.aws_mgmt. SsmFetcher ( role_arn = None , external_id = None , region = None , iam_config_object = None , client_session_override = None ) [source]

Bases: ecs_files_composer.aws_mgmt.AwsResourceHandler

Class to handle SSM actions

arn_re = re.compile('(?:^arn:aws(?:-[a-z]+)?:ssm:[\\S]+:[0-9]+:parameter)(?P<name>/[\\S]+)$')
get_content ( parameter_name ) [source]

Import the Content of a given parameter If the parameter name is a valid ARN, parses and uses the name from ARN

Parameters

parameter_name

Returns

ecs_files_composer.aws_mgmt. create_session_from_creds ( tmp_creds , region = None ) [source]

Function to easily convert the AssumeRole reply into a boto3 session :param tmp_creds: :return: :rtype boto3.session.Session

ecs_files_composer.aws_mgmt. set_session_from_iam_object ( iam_config_object , source_session = None ) [source]

Function to define the client session based on config input

Parameters
Returns

boto session

Return type

boto3.session.Session

ecs_files_composer.certificates_mgmt module

class ecs_files_composer.certificates_mgmt. X509Certificate ( * , dir_path : str = None , emailAddress : pydantic.networks.EmailStr = 'files-composer@compose-x.tld' , commonName : ecs_files_composer.input.ConstrainedStrValue = None , countryName : ecs_files_composer.input.ConstrainedStrValue = 'AW' , localityName : str = 'AWS' , stateOrProvinceName : str = 'AWS' , organizationName : str = 'AWS' , organizationUnitName : str = 'AWS' , validityEndInSeconds : float = 8035200 , keyFileName : str , certFileName : str , group : str = 'root' , owner : str = 'root' , ** data : Any ) [source]

Bases: ecs_files_composer.input.X509CertDef , object

Class to wrap actions around a new X509 certificate

cert_file_name : str
common_name : Optional[constr(regex='^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]{0,61}[A-Za-z0-9])\\Z')]
country_name : Optional [ str ]
dir_path : Optional [ str ]
email_address : Optional [ EmailStr ]
generate_cert ( ) [source]
generate_cert_content ( ) [source]
generate_key ( ) [source]
group : Optional [ str ]
init_cert_paths ( ) [source]
key_file_name : str
locality_name : Optional [ str ]
organization_name : Optional [ str ]
organization_unit_name : Optional [ str ]
owner : Optional [ str ]
set_cert_files ( ) [source]
set_common_name ( ) [source]
state_or_province_name : Optional [ str ]
validity_end_in_seconds : Optional [ float ]
ecs_files_composer.certificates_mgmt. process_x509_certs ( job ) [source]
Parameters

job ( ecs_files_composer.input.Model ) –

Returns

ecs_files_composer.cli module

Console script for ecs_files_composer.

ecs_files_composer.cli. main ( ) [source]

Console script for ecs_files_composer.

ecs_files_composer.common module

ecs_files_composer.common. setup_logging ( ) [source]

Function to setup logging for ECS ComposeX. In case this is used in a Lambda function, removes the AWS Lambda default log handler

Returns

the_logger

Return type

Logger

ecs_files_composer.ecs_files_composer module

Main module.

ecs_files_composer.ecs_files_composer. init_config ( raw = None , file_path = None , env_var = None , ssm_parameter = None , s3_config = None , secret_config = None , role_arn = None , external_id = None , decode_base64 = False , context = None ) [source]

Function to initialize the configuration

Parameters
  • raw – The raw content of a content

  • file_path ( str ) – The path to a job configuration file

  • env_var ( str ) –

  • ssm_parameter ( str ) –

  • s3_config ( str ) –

  • secret_config ( str ) –

  • role_arn ( str ) –

  • external_id ( str ) –

  • decode_base64 ( bool ) –

Returns

The ECS Config description

Return type

dict

ecs_files_composer.ecs_files_composer. start_jobs ( config , override_session = None ) [source]

Starting point to run the files job

Parameters
  • config

  • override_session

Returns

ecs_files_composer.envsubst module

Module to do a better env variables handling.

ecs_files_composer.envsubst. expandvars ( path , default = None , skip_escaped = True , enable_litteral = True ) [source]
Expand environment variables of form $var and ${var}.

If parameter ‘skip_escaped’ is True, all escaped variable references (i.e. preceded by backslashes) are skipped. Unknown variables are set to ‘default’. If ‘default’ is None, they are left unchanged.

ecs_files_composer.files_mgmt module

Main module.

class ecs_files_composer.files_mgmt. File ( * , path : str = None , content : str = None , source : ecs_files_composer.input.SourceDef = None , encoding : ecs_files_composer.input.Encoding = 'plain' , group : str = 'root' , owner : str = 'root' , mode : str = '0644' , context : ecs_files_composer.input.Context = 'plain' , ignore_if_failed : bool = False , commands : ecs_files_composer.input.Commands = None , ** data : Any ) [source]

Bases: ecs_files_composer.input.FileDef , object

Class to wrap common files actions around

commands : Optional [ Commands ]
content : Optional [ str ]
context : Optional [ Context ]
encoding : Optional [ Encoding ]
exec_post_commands ( ) [source]
group : Optional [ str ]
handle_s3_source ( iam_override = None , session_override = None ) [source]

Handles retrieving the content from S3

Parameters
Returns

handle_secret_source ( iam_override = None , session_override = None ) [source]

Handles retrieving secrets from AWS Secrets Manager

Parameters
Returns

handle_sources ( iam_override = None , session_override = None ) [source]

Handles files from external sources

Parameters
handle_ssm_source ( iam_override = None , session_override = None ) [source]

Handles retrieving the content from SSM Parameter

Parameters
Returns

handle_url_source ( ) [source]

Fetches the content from a provided URI

handler ( iam_override = None , session_override = None ) [source]

Main entrypoint for files to relate

Parameters
ignore_if_failed : Optional [ bool ]
mode : Optional [ str ]
owner : Optional [ str ]
path : Optional [ str ]
render_jinja ( ) [source]

Allows to use the temp directory as environment base, the original file as source template, and render a final template.

set_dir_path ( ) [source]
set_unix_settings ( ) [source]

Applies UNIX settings to given file

source : Optional [ SourceDef ]
write_content ( is_template = True , as_bytes = False , bytes_content = None ) [source]

Function to write the content retrieved to path.

Parameters
  • is_template ( bool ) – Whether the content should be considered to be a template.

  • as_bytes

  • bytes_content

Returns

ecs_files_composer.input module

class ecs_files_composer.input. Certificates ( * , x509 : Any = None ) [source]

Bases: pydantic.main.BaseModel

class Config [source]

Bases: object

extra = 'forbid'
x509 : Optional [ Any ]
class ecs_files_composer.input. Commands ( * , post : ecs_files_composer.input.CommandsDef = None , pre : ecs_files_composer.input.CommandsDef = None ) [source]

Bases: pydantic.main.BaseModel

post : Optional [ ecs_files_composer.input.CommandsDef ]
pre : Optional [ ecs_files_composer.input.CommandsDef ]
class ecs_files_composer.input. CommandsDef ( * , __root__ : List [ str ] ) [source]

Bases: pydantic.main.BaseModel

class ecs_files_composer.input. Context ( value ) [source]

Bases: enum.Enum

An enumeration.

jinja2 = 'jinja2'
plain = 'plain'
class ecs_files_composer.input. Encoding ( value ) [source]

Bases: enum.Enum

An enumeration.

base64 = 'base64'
plain = 'plain'
class ecs_files_composer.input. FileDef ( * , path : str = None , content : str = None , source : ecs_files_composer.input.SourceDef = None , encoding : ecs_files_composer.input.Encoding = 'plain' , group : str = 'root' , owner : str = 'root' , mode : str = '0644' , context : ecs_files_composer.input.Context = 'plain' , ignore_if_failed : bool = False , commands : ecs_files_composer.input.Commands = None , ** extra_data : Any ) [source]

Bases: pydantic.main.BaseModel

class Config [source]

Bases: object

extra = 'allow'
commands : Optional [ ecs_files_composer.input.Commands ]
content : Optional [ str ]
context : Optional [ ecs_files_composer.input.Context ]
encoding : Optional [ ecs_files_composer.input.Encoding ]
group : Optional [ str ]
ignore_if_failed : Optional [ bool ]
mode : Optional [ str ]
owner : Optional [ str ]
path : Optional [ str ]
source : Optional [ ecs_files_composer.input.SourceDef ]
class ecs_files_composer.input. IamOverrideDef ( * , RoleArn : str = None , SessionName : str = 'S3File@EcsConfigComposer' , ExternalId : str = None , RegionName : str = None , AccessKeyId : str = None , SecretAccessKey : str = None , SessionToken : str = None ) [source]

Bases: pydantic.main.BaseModel

access_key_id : Optional [ str ]
external_id : Optional [ str ]
region_name : Optional [ str ]
role_arn : Optional [ str ]
secret_access_key : Optional [ str ]
session_name : Optional [ str ]
session_token : Optional [ str ]
class ecs_files_composer.input. Model ( * , files : Dict [ str , Any ] , certificates : ecs_files_composer.input.Certificates = None , IamOverride : ecs_files_composer.input.IamOverrideDef = None ) [source]

Bases: pydantic.main.BaseModel

certificates : Optional [ ecs_files_composer.input.Certificates ]
files : Dict [ str , Any ]
iam_override : Optional [ ecs_files_composer.input.IamOverrideDef ]
class ecs_files_composer.input. S3Def ( * , BucketName : str , BucketRegion : str = None , Key : str , IamOverride : ecs_files_composer.input.IamOverrideDef = None ) [source]

Bases: pydantic.main.BaseModel

bucket_name : str
bucket_region : Optional [ str ]
iam_override : Optional [ ecs_files_composer.input.IamOverrideDef ]
key : str
class ecs_files_composer.input. SecretDef ( * , SecretId : str , VersionId : str = None , VersionStage : str = None , IamOverride : ecs_files_composer.input.IamOverrideDef = None ) [source]

Bases: pydantic.main.BaseModel

iam_override : Optional [ ecs_files_composer.input.IamOverrideDef ]
secret_id : str
version_id : Optional [ str ]
version_stage : Optional [ str ]
class ecs_files_composer.input. SourceDef ( * , Url : ecs_files_composer.input.UrlDef = None , Ssm : ecs_files_composer.input.SsmDef = None , S3 : ecs_files_composer.input.S3Def = None , Secret : ecs_files_composer.input.SecretDef = None ) [source]

Bases: pydantic.main.BaseModel

s3 : Optional [ ecs_files_composer.input.S3Def ]
secret : Optional [ ecs_files_composer.input.SecretDef ]
ssm : Optional [ ecs_files_composer.input.SsmDef ]
url : Optional [ ecs_files_composer.input.UrlDef ]
class ecs_files_composer.input. SsmDef ( * , ParameterName : str = None , IamOverride : ecs_files_composer.input.IamOverrideDef = None ) [source]

Bases: pydantic.main.BaseModel

iam_override : Optional [ ecs_files_composer.input.IamOverrideDef ]
parameter_name : Optional [ str ]
class ecs_files_composer.input. UrlDef ( * , Url : pydantic.networks.AnyUrl = None , Username : str = None , Password : str = None ) [source]

Bases: pydantic.main.BaseModel

password : Optional [ str ]
url : Optional [ pydantic.networks.AnyUrl ]
username : Optional [ str ]
class ecs_files_composer.input. X509CertDef ( * , dir_path : str = None , emailAddress : pydantic.networks.EmailStr = 'files-composer@compose-x.tld' , commonName : ecs_files_composer.input.ConstrainedStrValue = None , countryName : ecs_files_composer.input.ConstrainedStrValue = 'AW' , localityName : str = 'AWS' , stateOrProvinceName : str = 'AWS' , organizationName : str = 'AWS' , organizationUnitName : str = 'AWS' , validityEndInSeconds : float = 8035200 , keyFileName : str , certFileName : str , group : str = 'root' , owner : str = 'root' , ** extra_data : Any ) [source]

Bases: pydantic.main.BaseModel

class Config [source]

Bases: object

extra = 'allow'
cert_file_name : str
common_name : Optional [ ecs_files_composer.input.ConstrainedStrValue ]
country_name : Optional [ str ]
dir_path : Optional [ str ]
email_address : Optional [ pydantic.networks.EmailStr ]
group : Optional [ str ]
key_file_name : str
locality_name : Optional [ str ]
organization_name : Optional [ str ]
organization_unit_name : Optional [ str ]
owner : Optional [ str ]
state_or_province_name : Optional [ str ]
validity_end_in_seconds : Optional [ float ]

Module contents

Top-level package for ECS Files Composer.