def __init__(self, stage, config_file=".cabbie/config.json", verbose=False): self.project_home = self.__project_home(config_file) self.active_stage = stage self.config = file_json('/'.join([self.project_home, config_file])) self.__live_resource_file = '@/.cabbie/{stage}/resources.json'.format(stage=self.active_stage) self.live_resources = self.__open_live_resources() # TODO: Maybe instead, load stage_vars into a dict and then have a method to return the values as needed? self.aws_profile = self.__stage_vars()['aws_profile'] self.session = boto3.session.Session(profile_name=self.aws_profile) self.clients = { # TODO: is this needed? 'iam': self.session.client('iam'), 'ddb': self.session.client('dynamodb'), 'lambda': self.session.client('lambda'), 'apigateway': self.session.client('apigateway'), 'cognito': self.session.client('cognito-idp'), 'sts': self.session.client('sts'), 's3' : self.session.client('s3') } # TODO: can use other response items for tracking? self.account_id = self.clients['sts'].get_caller_identity()['Account'] self.resource_template = self.__open_file( self.config['template'], fopen=file_json, copy_forward=True )
def external_file(self, path, function): # pass in evaluate # TODO: make it possible to pass things in other than eval? functions = {'eval': self.__evaluate} try: manifest = self.__evaluate( file_json('{}/manifest.json'.format(path))) except Exception as e: print(e) print('failed to open manifest!') try: template = file_string('{}/{}'.format(path, manifest['template'])) except Exception as e: print(e) print('failed to open template!') try: destination = self.__full_path(manifest['destination']) with open(destination, 'w') as outfile: outfile.write(functions[function](template)) except Exception as e: print(e) print('failed to write to destination!') return {}
def __init__(self, stage, config_file=".cabbie/config.json", verbose=False): self.project_home = self.__project_home(config_file) self.active_stage = stage self.config = file_json('/'.join([self.project_home, config_file])) self.__live_resource_file = '@/.cabbie/{stage}/resources.json'.format( stage=self.active_stage) self.live_resources = self.__open_live_resources() # TODO: Maybe instead, load stage_vars into a dict and then have a method to return the values as needed? self.aws_profile = self.__stage_vars()['aws_profile'] self.session = boto3.session.Session(profile_name=self.aws_profile) self.clients = { # TODO: is this needed? 'iam': self.session.client('iam'), 'ddb': self.session.client('dynamodb'), 'lambda': self.session.client('lambda'), 'apigateway': self.session.client('apigateway'), 'cognito': self.session.client('cognito-idp'), 'sts': self.session.client('sts'), 's3': self.session.client('s3') } # TODO: can use other response items for tracking? self.account_id = self.clients['sts'].get_caller_identity()['Account'] self.resource_template = self.__open_file(self.config['template'], fopen=file_json, copy_forward=True) # TODO: make these names a little more distinct... maybe prepend with "plugin_"? self.plugins = { 'external_file': { 'execution': (self.external_file, ['path', 'function']), 'complete': False }, 'os_command': { 'execution': (self.os_command, ['command', 'exec_dir']), 'complete': False }, 'zip': { 'execution': (self.zip_path, ['input_path', 'output_path']), 'complete': False } }
def external_file(path, function=lambda x: x): # pass in evaluate # TODO: make it possible to pass things in other than eval? try: manifest = evaluate(file_json('{}/manifest.json'.format(path))) except Exception as e: print(e) print('failed to open manifest!') try: template = file_string('{}/{}'.format(path, manifest['template'])) except Exception as e: print(e) print('failed to open template!') try: with open(manifest['destination'], 'w') as outfile: outfile.write(function(template)) except Exception as e: print(e) print('failed to write to destination!') return {}
def __init__(self, config_file=".cabbie/config.json"): self.config_file = config_file self.project_home = self.__project_home(config_file) self.config = file_json('/'.join([self.project_home, config_file])) # TODO: I think we actually only need alias?