Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
def deploy(ctx, autogen_policy, profile, api_gateway_stage, stage,
           deprecated_api_gateway_stage):
    # type: (click.Context, bool, str, str, str, str) -> None
    if api_gateway_stage is not None and \
            deprecated_api_gateway_stage is not None:
        raise _create_deprecated_stage_error(api_gateway_stage,
                                             deprecated_api_gateway_stage)
    if deprecated_api_gateway_stage is not None:
        # The "chalice deploy <stage>" is deprecated and will be removed
        # in future versions.  We'll support it for now, but let the
        # user know to stop using this.
        _warn_pending_removal(deprecated_api_gateway_stage)
        api_gateway_stage = deprecated_api_gateway_stage
    factory = ctx.obj['factory']  # type: CLIFactory
    factory.profile = profile
    config = factory.create_config_obj(
        chalice_stage_name=stage,
        autogen_policy=autogen_policy,
        api_gateway_stage=api_gateway_stage,
    )
    session = factory.create_botocore_session()
    d = factory.create_default_deployer(session=session, prompter=click)
    deployed_values = d.deploy(config, chalice_stage_name=stage)
    record_deployed_values(
        deployed_values,
        os.path.join(config.project_dir, '.chalice', 'deployed.json'))
Esempio n. 4
0
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
Esempio n. 5
0
def test_can_merge_recorded_values(tmpdir):
    filename = str(tmpdir.join('deployed.json'))
    first = {'dev': {'deployed': 'values'}}
    second = {'prod': {'deployed': 'values'}}
    utils.record_deployed_values(first, filename)
    utils.record_deployed_values(second, filename)
    combined = first.copy()
    combined.update(second)
    with open(filename, 'r') as f:
        data = json.load(f)
    assert data == combined
def deploy(ctx, autogen_policy, profile, api_gateway_stage, stage):
    # type: (click.Context, Optional[bool], str, str, str) -> None
    factory = ctx.obj['factory']  # type: CLIFactory
    factory.profile = profile
    config = factory.create_config_obj(
        chalice_stage_name=stage, autogen_policy=autogen_policy,
        api_gateway_stage=api_gateway_stage,
    )
    session = factory.create_botocore_session()
    d = factory.create_default_deployer(session=session, ui=UI())
    deployed_values = d.deploy(config, chalice_stage_name=stage)
    record_deployed_values(deployed_values, os.path.join(
        config.project_dir, '.chalice', 'deployed.json'))
Esempio n. 7
0
def test_can_retrieve_url(runner, mock_cli_factory):
    deployed_values_dev = {
        "schema_version":
        "2.0",
        "resources": [
            {
                "rest_api_url": "https://dev-url/",
                "name": "rest_api",
                "resource_type": "rest_api"
            },
        ]
    }
    deployed_values_prod = {
        "schema_version":
        "2.0",
        "resources": [
            {
                "rest_api_url": "https://prod-url/",
                "name": "rest_api",
                "resource_type": "rest_api"
            },
        ]
    }
    with runner.isolated_filesystem():
        cli.create_new_project_skeleton('testproject')
        os.chdir('testproject')
        deployed_dir = os.path.join('.chalice', 'deployed')
        os.makedirs(deployed_dir)
        record_deployed_values(deployed_values_dev,
                               os.path.join(deployed_dir, 'dev.json'))
        record_deployed_values(deployed_values_prod,
                               os.path.join(deployed_dir, 'prod.json'))
        result = _run_cli_command(runner,
                                  cli.url, [],
                                  cli_factory=mock_cli_factory)
        assert result.exit_code == 0
        assert result.output == 'https://dev-url/\n'

        prod_result = _run_cli_command(runner,
                                       cli.url, ['--stage', 'prod'],
                                       cli_factory=mock_cli_factory)
        assert prod_result.exit_code == 0
        assert prod_result.output == 'https://prod-url/\n'
Esempio n. 8
0
def test_can_retrieve_url(runner, mock_cli_factory):
    deployed_values = {
        "dev": {
            "rest_api_id": "rest_api_id",
            "chalice_version": "0.7.0",
            "region": "us-west-2",
            "backend": "api",
            "api_handler_name": "helloworld-dev",
            "api_handler_arn": "arn:...",
            "api_gateway_stage": "dev-apig",
            "lambda_functions": {},
        },
        "prod": {
            "rest_api_id": "rest_api_id_prod",
            "chalice_version": "0.7.0",
            "region": "us-west-2",
            "backend": "api",
            "api_handler_name": "helloworld-dev",
            "api_handler_arn": "arn:...",
            "api_gateway_stage": "prod-apig",
            "lambda_functions": {},
        },
    }
    with runner.isolated_filesystem():
        cli.create_new_project_skeleton('testproject')
        os.chdir('testproject')
        record_deployed_values(deployed_values,
                               os.path.join('.chalice', 'deployed.json'))
        result = _run_cli_command(runner,
                                  cli.url, [],
                                  cli_factory=mock_cli_factory)
        assert result.exit_code == 0
        assert result.output == (
            'https://rest_api_id.execute-api.us-west-2.amazonaws.com'
            '/dev-apig/\n')

        prod_result = _run_cli_command(runner,
                                       cli.url, ['--stage', 'prod'],
                                       cli_factory=mock_cli_factory)
        assert prod_result.exit_code == 0
        assert prod_result.output == (
            'https://rest_api_id_prod.execute-api.us-west-2.amazonaws.com'
            '/prod-apig/\n')
Esempio n. 9
0
def test_can_retrieve_url(runner, mock_cli_factory):
    deployed_values = {
        "dev": {
            "rest_api_id": "rest_api_id",
            "chalice_version": "0.7.0",
            "region": "us-west-2",
            "backend": "api",
            "api_handler_name": "helloworld-dev",
            "api_handler_arn": "arn:...",
            "api_gateway_stage": "dev-apig"
        },
        "prod": {
            "rest_api_id": "rest_api_id_prod",
            "chalice_version": "0.7.0",
            "region": "us-west-2",
            "backend": "api",
            "api_handler_name": "helloworld-dev",
            "api_handler_arn": "arn:...",
            "api_gateway_stage": "prod-apig"
        },
    }
    with runner.isolated_filesystem():
        cli.create_new_project_skeleton('testproject')
        os.chdir('testproject')
        record_deployed_values(deployed_values,
                               os.path.join('.chalice', 'deployed.json'))
        result = _run_cli_command(runner, cli.url, [],
                                  cli_factory=mock_cli_factory)
        assert result.exit_code == 0
        assert result.output == (
            'https://rest_api_id.execute-api.us-west-2.amazonaws.com'
            '/dev-apig/\n')

        prod_result = _run_cli_command(runner, cli.url, ['--stage', 'prod'],
                                       cli_factory=mock_cli_factory)
        assert prod_result.exit_code == 0
        assert prod_result.output == (
            'https://rest_api_id_prod.execute-api.us-west-2.amazonaws.com'
            '/prod-apig/\n')
Esempio n. 10
0
def test_can_retrieve_url(runner, mock_cli_factory):
    deployed_values_dev = {
        "schema_version": "2.0",
        "resources": [
            {"rest_api_url": "https://dev-url/",
             "name": "rest_api",
             "resource_type": "rest_api"},
        ]
    }
    deployed_values_prod = {
        "schema_version": "2.0",
        "resources": [
            {"rest_api_url": "https://prod-url/",
             "name": "rest_api",
             "resource_type": "rest_api"},
        ]
    }
    with runner.isolated_filesystem():
        cli.create_new_project_skeleton('testproject')
        os.chdir('testproject')
        deployed_dir = os.path.join('.chalice', 'deployed')
        os.makedirs(deployed_dir)
        record_deployed_values(
            deployed_values_dev,
            os.path.join(deployed_dir, 'dev.json')
        )
        record_deployed_values(
            deployed_values_prod,
            os.path.join(deployed_dir, 'prod.json')
        )
        result = _run_cli_command(runner, cli.url, [],
                                  cli_factory=mock_cli_factory)
        assert result.exit_code == 0
        assert result.output == 'https://dev-url/\n'

        prod_result = _run_cli_command(runner, cli.url, ['--stage', 'prod'],
                                       cli_factory=mock_cli_factory)
        assert prod_result.exit_code == 0
        assert prod_result.output == 'https://prod-url/\n'
Esempio n. 11
0
def deploy(ctx, autogen_policy, profile, api_gateway_stage, stage,
           deprecated_api_gateway_stage):
    # type: (click.Context, Optional[bool], str, str, str, str) -> None
    if api_gateway_stage is not None and \
            deprecated_api_gateway_stage is not None:
        raise _create_deprecated_stage_error(api_gateway_stage,
                                             deprecated_api_gateway_stage)
    if deprecated_api_gateway_stage is not None:
        # The "chalice deploy <stage>" is deprecated and will be removed
        # in future versions.  We'll support it for now, but let the
        # user know to stop using this.
        _warn_pending_removal(deprecated_api_gateway_stage)
        api_gateway_stage = deprecated_api_gateway_stage
    factory = ctx.obj['factory']  # type: CLIFactory
    factory.profile = profile
    config = factory.create_config_obj(
        chalice_stage_name=stage, autogen_policy=autogen_policy,
        api_gateway_stage=api_gateway_stage,
    )
    session = factory.create_botocore_session()
    d = factory.create_default_deployer(session=session, prompter=click)
    deployed_values = d.deploy(config, chalice_stage_name=stage)
    record_deployed_values(deployed_values, os.path.join(
        config.project_dir, '.chalice', 'deployed.json'))
Esempio n. 12
0
def test_can_write_recorded_values(tmpdir):
    filename = str(tmpdir.join('deployed.json'))
    utils.record_deployed_values({'dev': {'deployed': 'foo'}}, filename)
    with open(filename, 'r') as f:
        assert json.load(f) == {'dev': {'deployed': 'foo'}}
Esempio n. 13
0
def test_can_write_recorded_values(tmpdir):
    filename = str(tmpdir.join('deployed.yml'))
    utils.record_deployed_values({'dev': {'deployed': 'foo'}}, filename)
    with open(filename, 'r') as f:
        assert yaml.load(f, yaml.SafeLoader) == {'dev': {'deployed': 'foo'}}