Exemple #1
0
def generate_sdk(ctx, sdk_type, outdir):
    # type: (click.Context, str, str) -> None
    config = create_config_obj(ctx)
    session = create_botocore_session(profile=config.profile,
                                      debug=ctx.obj['debug'])
    client = TypedAWSClient(session)
    rest_api_id = client.get_rest_api_id(config.app_name)
    stage_name = config.stage
    if rest_api_id is None:
        click.echo("Could not find API ID, has this application "
                   "been deployed?")
        raise click.Abort()
    zip_stream = client.get_sdk(rest_api_id, stage=stage_name,
                                sdk_type=sdk_type)
    tmpdir = tempfile.mkdtemp()
    with open(os.path.join(tmpdir, 'sdk.zip'), 'wb') as f:
        f.write(zip_stream.read())
    tmp_extract = os.path.join(tmpdir, 'extracted')
    with zipfile.ZipFile(os.path.join(tmpdir, 'sdk.zip')) as z:
        z.extractall(tmp_extract)
    # The extract zip dir will have a single directory:
    #  ['apiGateway-js-sdk']
    dirnames = os.listdir(tmp_extract)
    if len(dirnames) == 1:
        full_dirname = os.path.join(tmp_extract, dirnames[0])
        if os.path.isdir(full_dirname):
            final_dirname = '%s-js-sdk' % config.app_name
            full_renamed_name = os.path.join(tmp_extract, final_dirname)
            os.rename(full_dirname, full_renamed_name)
            shutil.move(full_renamed_name, outdir)
            return
    click.echo("The downloaded SDK had an unexpected directory structure: %s"
               % (', '.join(dirnames)))
    raise click.Abort()
Exemple #2
0
def generate_sdk(ctx, sdk_type, outdir):
    # type: (click.Context, str, str) -> None
    config = create_config_obj(ctx)
    session = create_botocore_session(profile=config.profile,
                                      debug=ctx.obj['debug'])
    client = TypedAWSClient(session)
    rest_api_id = client.get_rest_api_id(config.app_name)
    stage_name = config.stage
    if rest_api_id is None:
        click.echo("Could not find API ID, has this application "
                   "been deployed?")
        raise click.Abort()
    zip_stream = client.get_sdk(rest_api_id,
                                stage=stage_name,
                                sdk_type=sdk_type)
    tmpdir = tempfile.mkdtemp()
    with open(os.path.join(tmpdir, 'sdk.zip'), 'wb') as f:
        f.write(zip_stream.read())
    tmp_extract = os.path.join(tmpdir, 'extracted')
    with zipfile.ZipFile(os.path.join(tmpdir, 'sdk.zip')) as z:
        z.extractall(tmp_extract)
    # The extract zip dir will have a single directory:
    #  ['apiGateway-js-sdk']
    dirnames = os.listdir(tmp_extract)
    if len(dirnames) == 1:
        full_dirname = os.path.join(tmp_extract, dirnames[0])
        if os.path.isdir(full_dirname):
            final_dirname = '%s-js-sdk' % config.app_name
            full_renamed_name = os.path.join(tmp_extract, final_dirname)
            os.rename(full_dirname, full_renamed_name)
            shutil.move(full_renamed_name, outdir)
            return
    click.echo("The downloaded SDK had an unexpected directory structure: %s" %
               (', '.join(dirnames)))
    raise click.Abort()
Exemple #3
0
def url(ctx):
    # type: (click.Context) -> None
    config = create_config_obj(ctx)
    session = create_botocore_session(profile=config.profile,
                                      debug=ctx.obj['debug'])
    c = TypedAWSClient(session)
    rest_api_id = c.get_rest_api_id(config.app_name)
    stage_name = config.stage
    region_name = c.region_name
    click.echo(
        "https://{api_id}.execute-api.{region}.amazonaws.com/{stage}/".format(
            api_id=rest_api_id, region=region_name, stage=stage_name))
 def test_rest_api_does_not_exist(self, stubbed_session):
     stubbed_session.stub('apigateway').get_rest_apis()\
         .returns(
             {'items': [
                 {'createdDate': 1, 'id': 'wrongid1', 'name': 'wrong1'},
                 {'createdDate': 2, 'id': 'wrongid1', 'name': 'wrong2'},
                 {'createdDate': 3, 'id': 'wrongid3', 'name': 'wrong3'},
             ]})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.get_rest_api_id('myappname') is None
     stubbed_session.verify_stubs()
Exemple #5
0
 def test_rest_api_does_not_exist(self, stubbed_session):
     stubbed_session.stub('apigateway').get_rest_apis()\
         .returns(
             {'items': [
                 {'createdDate': 1, 'id': 'wrongid1', 'name': 'wrong1'},
                 {'createdDate': 2, 'id': 'wrongid1', 'name': 'wrong2'},
                 {'createdDate': 3, 'id': 'wrongid3', 'name': 'wrong3'},
             ]})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.get_rest_api_id('myappname') is None
     stubbed_session.verify_stubs()
 def test_rest_api_exists(self, stubbed_session):
     desired_name = 'myappname'
     stubbed_session.stub('apigateway').get_rest_apis()\
         .returns(
             {'items': [
                 {'createdDate': 1, 'id': 'wrongid1', 'name': 'wrong1'},
                 {'createdDate': 2, 'id': 'correct', 'name': desired_name},
                 {'createdDate': 3, 'id': 'wrongid3', 'name': 'wrong3'},
             ]})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.get_rest_api_id(desired_name) == 'correct'
     stubbed_session.verify_stubs()
Exemple #7
0
 def test_rest_api_exists(self, stubbed_session):
     desired_name = 'myappname'
     stubbed_session.stub('apigateway').get_rest_apis()\
         .returns(
             {'items': [
                 {'createdDate': 1, 'id': 'wrongid1', 'name': 'wrong1'},
                 {'createdDate': 2, 'id': 'correct', 'name': desired_name},
                 {'createdDate': 3, 'id': 'wrongid3', 'name': 'wrong3'},
             ]})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.get_rest_api_id(desired_name) == 'correct'
     stubbed_session.verify_stubs()
Exemple #8
0
def url(ctx):
    # type: (click.Context) -> None
    config = create_config_obj(ctx)
    session = create_botocore_session(profile=config.profile,
                                      debug=ctx.obj['debug'])
    c = TypedAWSClient(session)
    rest_api_id = c.get_rest_api_id(config.app_name)
    stage_name = config.stage
    region_name = c.region_name
    click.echo(
        "https://{api_id}.execute-api.{region}.amazonaws.com/{stage}/"
        .format(api_id=rest_api_id, region=region_name, stage=stage_name)
    )
Exemple #9
0
def generate_sdk(ctx, sdk_type, outdir):
    # type: (click.Context, str, str) -> None
    config = create_config_obj(ctx)
    session = create_botocore_session(profile=config.profile,
                                      debug=ctx.obj['debug'])
    client = TypedAWSClient(session)
    rest_api_id = client.get_rest_api_id(config.app_name)
    stage_name = config.stage
    if rest_api_id is None:
        click.echo("Could not find API ID, has this application "
                   "been deployed?")
        raise click.Abort()
    client.download_sdk(rest_api_id, outdir, stage=stage_name,
                        sdk_type=sdk_type)