Skip to content

Commit

Permalink
Merge branch 'JamieCressey-profile_support'
Browse files Browse the repository at this point in the history
* JamieCressey-profile_support:
  Add profile support when creating new projects
  • Loading branch information
jamesls committed Jul 14, 2016
2 parents 762e07b + a81aa0c commit 0c90fd3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sample/
.cache
venv
17 changes: 13 additions & 4 deletions chalice/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def deploy(ctx, project_dir, autogen_policy, stage):
app_obj = load_chalice_app(project_dir)
ctx.obj['chalice_app'] = app_obj
ctx.obj['autogen_policy'] = autogen_policy
d = deployer.Deployer(prompter=click)
try:
d = deployer.Deployer(prompter=click, profile=config['profile'])
except KeyError:
d = deployer.Deployer(prompter=click)
try:
d.deploy(ctx.obj)
except botocore.exceptions.NoRegionError:
Expand Down Expand Up @@ -176,8 +179,9 @@ def gen_policy(ctx, filename):

@cli.command('new-project')
@click.argument('project_name', required=False)
@click.option('--profile', required=False)
@click.pass_context
def new_project(ctx, project_name):
def new_project(ctx, project_name, profile):
if project_name is None:
project_name = prompts.getting_started_prompt(click)
if os.path.isdir(project_name):
Expand All @@ -186,9 +190,14 @@ def new_project(ctx, project_name):
chalice_dir = os.path.join(project_name, '.chalice')
os.makedirs(chalice_dir)
config = os.path.join(project_name, '.chalice', 'config.json')
cfg = {
'app_name': project_name,
'stage': 'dev'
}
if profile:
cfg['profile'] = profile
with open(config, 'w') as f:
f.write(json.dumps({'app_name': project_name,
'stage': 'dev'}, indent=2))
f.write(json.dumps(cfg, indent=2))
with open(os.path.join(project_name, 'requirements.txt'), 'w') as f:
pass
with open(os.path.join(project_name, 'app.py'), 'w') as f:
Expand Down
11 changes: 9 additions & 2 deletions chalice/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def node(name, uri_path, is_route=False):


class NoPrompt(object):

def confirm(self, text, default=False, abort=False):
return default

Expand All @@ -163,10 +164,13 @@ class Deployer(object):
LAMBDA_CREATE_ATTEMPTS = 5
DELAY_TIME = 3

def __init__(self, session=None, prompter=None):
def __init__(self, session=None, prompter=None, profile=None):
# type: (botocore.session.Session) -> None
if session is None:
session = botocore.session.get_session()
if profile:
session = botocore.session.Session(profile=profile)
else:
session = botocore.session.get_session()
if prompter is None:
prompter = NoPrompt()
self._session = session
Expand Down Expand Up @@ -480,6 +484,7 @@ def _create_resources_for_api(self, config, rest_api_id):

class APIGatewayResourceCreator(object):
"""Create hierarchical resources in API gateway from chalice routes."""

def __init__(self, client, lambda_client, rest_api_id, lambda_arn,
random_id_generator=lambda: str(uuid.uuid4())):
# type: (Any, Any, str, str, Callable[[], str]) -> None
Expand Down Expand Up @@ -609,6 +614,7 @@ def _lambda_uri(self):


class LambdaDeploymentPackager(object):

def __init__(self):
pass

Expand Down Expand Up @@ -765,6 +771,7 @@ def inject_latest_app(self, deployment_package_filename, project_dir):


class ResourceQuery(object):

def __init__(self, lambda_client, apigateway_client):
self._lambda_client = lambda_client
self._apigateway_client = apigateway_client
Expand Down

0 comments on commit 0c90fd3

Please sign in to comment.