示例#1
0
def _get_heroku_api_key(build):
    """Get a heroku API key for interaction with the heroku API.

	First looks to see if we have one stored in local_config.json,
	if not then asks the user for their heroku credentials
	so we can authenticate with the service to obtain one.
	"""
    api_key = build.tool_config.get('web.profile.heroku_api_key')

    while api_key is None:
        heroku_username, heroku_password = _request_heroku_credentials()
        api_key = _heroku_get_api_key(heroku_username, heroku_password)

        if api_key is not None:
            lib.set_dotted_attributes(build,
                                      {'web.profile.heroku_api_key': api_key})

    return api_key
示例#2
0
def _get_app_to_push_to(build, api_key):
    app = build.tool_config.get('web.profile.heroku_app_name')

    if app is not None:
        return app

    LOG.info('Querying heroku about registered apps...')
    apps = json.loads(_heroku_get(api_key, 'apps').content)
    app_names = [a['name'] for a in apps]

    create_new_heroku_app = True
    if app_names:
        message = (
            "You don't have a heroku app name specified in local_config.json."
            'You can choose either to:')

        chosen_n = lib.ask_multichoice(
            question_text=message,
            choices=[
                'Create a new heroku application',
                'Push to a currently registered heroku application'
            ])

        if chosen_n == 1:
            create_new_heroku_app = True
        else:
            create_new_heroku_app = False

    # either create a new heroku app, or choose an already existing app
    if create_new_heroku_app:
        LOG.info('Creating new heroku application')
        response = _heroku_post(api_key, 'apps', data='app[stack]=cedar')
        chosen_app = json.loads(response.content)['name']

    else:
        chosen_n = lib.ask_multichoice(
            question_text='Choose an existing heroku app to deploy to:',
            choices=app_names,
            radio=False)
        chosen_app = app_names[chosen_n - 1]

    lib.set_dotted_attributes(build,
                              {'web.profile.heroku_app_name': chosen_app})
    return chosen_app
示例#3
0
def _get_heroku_api_key(build):
	"""Get a heroku API key for interaction with the heroku API.

	First looks to see if we have one stored in local_config.json,
	if not then asks the user for their heroku credentials
	so we can authenticate with the service to obtain one.
	"""
	api_key = build.tool_config.get('web.profile.heroku_api_key')

	while api_key is None:
		heroku_username, heroku_password = _request_heroku_credentials()
		api_key = _heroku_get_api_key(heroku_username, heroku_password)

		if api_key is not None:
			lib.set_dotted_attributes(build, {
				'web.profile.heroku_api_key': api_key
			})

	return api_key
示例#4
0
def _get_app_to_push_to(build, api_key):
	app = build.tool_config.get('web.profile.heroku_app_name')

	if app is not None:
		return app

	LOG.info('Querying heroku about registered apps...')
	apps = json.loads(_heroku_get(api_key, 'apps').content)
	app_names = [app['name'] for app in apps]

	create_new_heroku_app = True
	if app_names:
		message = (
			"You don't have a heroku app name specified in local_config.json."
			'You can choose either to:'
		)

		chosen_n = lib.ask_multichoice(question_text=message, choices=[
			'Create a new heroku application',
			'Push to a currently registered heroku application'
		])

		if chosen_n == 1:
			create_new_heroku_app = True
		else:
			create_new_heroku_app = False

	# either create a new heroku app, or choose an already existing app
	if create_new_heroku_app:
		LOG.info('Creating new heroku application')
		response = _heroku_post(api_key, 'apps', data='app[stack]=cedar')
		chosen_app = json.loads(response.content)['name']

	else:
		chosen_n = lib.ask_multichoice(question_text='Choose an existing heroku app to deploy to:', choices=app_names, radio=False)
		chosen_app = app_names[chosen_n - 1]

	lib.set_dotted_attributes(build, {
		'web.profile.heroku_app_name': chosen_app
	})
	return chosen_app