def _delete_app(application, temp_dirname): factory = CLIFactory(temp_dirname) config = factory.create_config_obj(chalice_stage_name='dev', autogen_policy=True) session = factory.create_botocore_session() d = factory.create_deletion_deployer(session, UI()) _deploy_with_retries(d, config)
def _deploy_app(): if not os.path.isdir(CHALICE_DIR): os.makedirs(CHALICE_DIR) with open(os.path.join(CHALICE_DIR, 'config.json'), 'w') as f: f.write('{"app_name": "smoketestapp"}\n') factory = CLIFactory(PROJECT_DIR) config = factory.create_config_obj( chalice_stage_name='dev', autogen_policy=True ) d = factory.create_default_deployer( factory.create_botocore_session(), None) deployed_stages = d.deploy(config) deployed = deployed_stages['dev'] url = ( "https://{rest_api_id}.execute-api.{region}.amazonaws.com/" "{api_gateway_stage}/".format(**deployed)) application = SmokeTestApplication( url=url, deployed_values=deployed, stage_name='dev', app_name='smoketestapp', ) record_deployed_values(deployed_stages, os.path.join( PROJECT_DIR, '.chalice', 'deployed.json')) return application
def _delete_dynamodb_table(table_name, temp_dirname): factory = CLIFactory(temp_dirname) session = factory.create_botocore_session() ddb = session.create_client('dynamodb') ddb.delete_table( TableName=table_name, )
def _deploy_app(temp_dirname): factory = CLIFactory(temp_dirname) config = factory.create_config_obj( chalice_stage_name='dev', autogen_policy=True ) d = factory.create_default_deployer( factory.create_botocore_session(), None) deployed_stages = _deploy_with_retries(d, config) deployed = deployed_stages['dev'] url = ( "https://{rest_api_id}.execute-api.{region}.amazonaws.com/" "{api_gateway_stage}/".format(**deployed)) application = SmokeTestApplication( url=url, deployed_values=deployed, stage_name='dev', app_name='smoketestapp', app_dir=temp_dirname, ) record_deployed_values( deployed_stages, os.path.join(temp_dirname, '.chalice', 'deployed.json') ) return application
def _delete_app(application, temp_dirname): factory = CLIFactory(temp_dirname) config = factory.create_config_obj( chalice_stage_name='dev', autogen_policy=True ) session = factory.create_botocore_session() d = factory.create_deletion_deployer(session, UI()) _deploy_with_retries(d, config)
def get_errors_from_dynamodb(temp_dirname): factory = CLIFactory(temp_dirname) session = factory.create_botocore_session() ddb = session.create_client('dynamodb') item = ddb.get_item(TableName=RANDOM_APP_NAME, Key={'entry': {'N': '-9999'}}) if 'Item' not in item: return None return item['Item']['errormsg']['S']
def __init__(self, app, stage_name='dev', project_dir='.'): # type: (Chalice, str, str) -> None self._app = app self._project_dir = project_dir self._stage_name = stage_name self._http_client = None # type: Optional[TestHTTPClient] self._events_client = None # type: Optional[TestEventsClient] self._lambda_client = None # type: Optional[TestLambdaClient] self._chalice_config_obj = None # type: Optional[Config] # We have to be careful about not passing in the CLIFactory # because this is a public interface we're exposing and we don't # want the CLIFactory to be part of that. self._cli_factory = CLIFactory(project_dir)
def get_numbers_from_dynamodb(temp_dirname): """Get numbers from DynamoDB in the format written by testwebsocketapp. """ factory = CLIFactory(temp_dirname) session = factory.create_botocore_session() ddb = session.create_client('dynamodb') paginator = ddb.get_paginator('scan') numbers = sorted([ int(item['entry']['N']) for page in paginator.paginate( TableName=RANDOM_APP_NAME, ConsistentRead=True, ) for item in page['Items'] ]) return numbers
def _deploy_app(temp_dirname): factory = CLIFactory(temp_dirname) config = factory.create_config_obj(chalice_stage_name='dev', autogen_policy=True) session = factory.create_botocore_session() d = factory.create_default_deployer(session, config, UI()) region = session.get_config_variable('region') deployed = _deploy_with_retries(d, config) application = SmokeTestApplication( region=region, deployed_values=deployed, stage_name='dev', app_name=RANDOM_APP_NAME, app_dir=temp_dirname, ) return application
def cli(ctx, project_dir, debug=False): # type: (click.Context, str, bool) -> None if project_dir is None: project_dir = os.getcwd() ctx.obj['project_dir'] = project_dir ctx.obj['debug'] = debug ctx.obj['factory'] = CLIFactory(project_dir, debug) os.chdir(project_dir)
def _deploy_app(temp_dirname): factory = CLIFactory(temp_dirname) config = factory.create_config_obj( chalice_stage_name='dev', autogen_policy=True ) session = factory.create_botocore_session() d = factory.create_default_deployer(session, config, UI()) region = session.get_config_variable('region') deployed = _deploy_with_retries(d, config) application = SmokeTestApplication( region=region, deployed_values=deployed, stage_name='dev', app_name=RANDOM_APP_NAME, app_dir=temp_dirname, ) return application
def package_app(project_dir, output_dir, stage, chalice_config=None, package_format='cloudformation', template_format='json'): # type: (str, str, str, Dict[str, Any], str, str) -> None factory = CLIFactory(project_dir, environ=os.environ) if chalice_config is None: chalice_config = {} config = factory.create_config_obj(stage, user_provided_params=chalice_config) options = factory.create_package_options() packager = factory.create_app_packager(config, options, package_format=package_format, template_format=template_format) packager.package_app(config, output_dir, stage)
def cli(ctx, project_dir, debug=False): # type: (click.Context, str, bool) -> None if project_dir is None: project_dir = os.getcwd() if debug is True: _configure_logging(logging.DEBUG) ctx.obj['project_dir'] = project_dir ctx.obj['debug'] = debug ctx.obj['factory'] = CLIFactory(project_dir, debug, environ=os.environ) os.chdir(project_dir)
def cli(ctx, project_dir, debug=False): # type: (click.Context, str, bool) -> None abs_project_dir = os.path.join( os.getenv('PWD'), project_dir ) if project_dir else os.getcwd() ctx.obj['project_dir'] = abs_project_dir ctx.obj['debug'] = debug ctx.obj['factory'] = CLIFactory(abs_project_dir, debug) os.chdir(abs_project_dir)
def _create_dynamodb_table(table_name, temp_dirname): factory = CLIFactory(temp_dirname) session = factory.create_botocore_session() ddb = session.create_client('dynamodb') ddb.create_table( TableName=table_name, AttributeDefinitions=[ { 'AttributeName': 'entry', 'AttributeType': 'N', }, ], KeySchema=[ { 'AttributeName': 'entry', 'KeyType': 'HASH', }, ], ProvisionedThroughput={ 'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5, }, )
class Client(object): def __init__(self, app, stage_name='dev', project_dir='.'): # type: (Chalice, str, str) -> None self._app = app self._project_dir = project_dir self._stage_name = stage_name self._http_client = None # type: Optional[TestHTTPClient] self._events_client = None # type: Optional[TestEventsClient] self._lambda_client = None # type: Optional[TestLambdaClient] self._chalice_config_obj = None # type: Optional[Config] # We have to be careful about not passing in the CLIFactory # because this is a public interface we're exposing and we don't # want the CLIFactory to be part of that. self._cli_factory = CLIFactory(project_dir) @property def _chalice_config(self): # type: () -> Config if self._chalice_config_obj is None: try: self._chalice_config_obj = self._cli_factory.create_config_obj( chalice_stage_name=self._stage_name) except RuntimeError: # Being able to load a valid config is not required to use # the test client. If you don't have one that you just won't # get any config related data added to your environment. self._chalice_config_obj = Config.create() return self._chalice_config_obj @property def http(self): # type: () -> TestHTTPClient if self._http_client is None: self._http_client = TestHTTPClient(self._app, self._chalice_config) return self._http_client @property def lambda_(self): # type: () -> TestLambdaClient if self._lambda_client is None: self._lambda_client = TestLambdaClient(self._app, self._chalice_config) return self._lambda_client @property def events(self): # type: () -> TestEventsClient if self._events_client is None: self._events_client = TestEventsClient(self._app) return self._events_client def __enter__(self): # type: () -> Client return self def __exit__( self, exception_type, # type: Optional[Type[BaseException]] exception_value, # type: Optional[BaseException] traceback, # type: Optional[TracebackType] ): # type: (...) -> None pass
import os from chalice import cli from chalice.cli.factory import CLIFactory project_dir = os.getcwd() obj = dict() obj['project_dir'] = project_dir obj['debug'] = True obj['factory'] = CLIFactory(project_dir, True) cli.local([], obj=obj)