# -*- coding: utf-8 -*-

"""Console script for pycloud."""
import sys
import click

from pycloud.logger import configure_logger, get_logger, ALLOWED_LOG_LEVELS
from pycloud.core.provisioners.plan_executor import PlanExecutor
from pycloud.core.config import PyCloudConfig
from pycloud.core.keypair_storage import KeyPairStorage

logger = get_logger()

def validate_for_aws(access_key, secret_key):
    '''
    Validates the provided aws access_key and secret_key.
    '''
    if not access_key:
        click.secho(
            'Please provide AWS Access Key either as a parameter "--access-key=VALUE" '
            'or as an environment variable AWS_ACCESS_KEY',
            fg='red')
        raise click.BadParameter('Access Key is not set.')
    if not secret_key:
        click.secho(
            'Please provide AWS Secret Key either as a parameter "--secret-key=VALUE" '
            'or as an environment variable AWS_SECRET_KEY',
            fg='red')
        raise click.BadParameter('Secret Key is not set.')



@click.group()
@click.option('-l', '--log-level', envvar='PYCLOUD_LOG_LEVEL',
              help='Set the Log Level for the command. Default: info',
              type=click.Choice([l.lower() for l in ALLOWED_LOG_LEVELS]),
              default='info')
@click.pass_context
def pycloud(ctx, log_level):
    """
    PyCloud Provisions a VM in the cloud,
    """
    KeyPairStorage.initialize()
    PyCloudConfig.initialize_state_mgmt()

    ctx.obj = {}
    configure_logger(level=log_level)
    return 0

@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY',
              help='AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY',
              help='AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def setup(ctx, access_key, secret_key, plan):
    '''
    Sets up the infrastructure as specified by the plan.
    '''
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.setup()

@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY',
              help='AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY',
              help='AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def teardown(ctx, access_key, secret_key, plan):
    '''
    Tears down the infrastructure as specified by the plan.
    '''
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.teardown()

@pycloud.command()
@click.pass_context
def docs(ctx):
    '''
    Dumps the documentation for the available provisioners.
    '''
    executor = PlanExecutor(None, _globals=ctx.obj)
    executor.help()



if __name__ == "__main__":
    sys.exit(pycloud())  # pragma: no cover

9bccfc4524a91393d24fc17c9f0af8b3342b291c
<mask token>


def validate_for_aws(access_key, secret_key):
    """
    Validates the provided aws access_key and secret_key.
    """
    if not access_key:
        click.secho(
            'Please provide AWS Access Key either as a parameter "--access-key=VALUE" or as an environment variable AWS_ACCESS_KEY'
            , fg='red')
        raise click.BadParameter('Access Key is not set.')
    if not secret_key:
        click.secho(
            'Please provide AWS Secret Key either as a parameter "--secret-key=VALUE" or as an environment variable AWS_SECRET_KEY'
            , fg='red')
        raise click.BadParameter('Secret Key is not set.')


<mask token>


@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY', help=
    'AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY', help=
    'AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def setup(ctx, access_key, secret_key, plan):
    """
    Sets up the infrastructure as specified by the plan.
    """
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.setup()


@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY', help=
    'AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY', help=
    'AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def teardown(ctx, access_key, secret_key, plan):
    """
    Tears down the infrastructure as specified by the plan.
    """
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.teardown()


@pycloud.command()
@click.pass_context
def docs(ctx):
    """
    Dumps the documentation for the available provisioners.
    """
    executor = PlanExecutor(None, _globals=ctx.obj)
    executor.help()


<mask token>

<mask token>


def validate_for_aws(access_key, secret_key):
    """
    Validates the provided aws access_key and secret_key.
    """
    if not access_key:
        click.secho(
            'Please provide AWS Access Key either as a parameter "--access-key=VALUE" or as an environment variable AWS_ACCESS_KEY'
            , fg='red')
        raise click.BadParameter('Access Key is not set.')
    if not secret_key:
        click.secho(
            'Please provide AWS Secret Key either as a parameter "--secret-key=VALUE" or as an environment variable AWS_SECRET_KEY'
            , fg='red')
        raise click.BadParameter('Secret Key is not set.')


@click.group()
@click.option('-l', '--log-level', envvar='PYCLOUD_LOG_LEVEL', help=
    'Set the Log Level for the command. Default: info', type=click.Choice([
    l.lower() for l in ALLOWED_LOG_LEVELS]), default='info')
@click.pass_context
def pycloud(ctx, log_level):
    """
    PyCloud Provisions a VM in the cloud,
    """
    KeyPairStorage.initialize()
    PyCloudConfig.initialize_state_mgmt()
    ctx.obj = {}
    configure_logger(level=log_level)
    return 0


@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY', help=
    'AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY', help=
    'AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def setup(ctx, access_key, secret_key, plan):
    """
    Sets up the infrastructure as specified by the plan.
    """
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.setup()


@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY', help=
    'AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY', help=
    'AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def teardown(ctx, access_key, secret_key, plan):
    """
    Tears down the infrastructure as specified by the plan.
    """
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.teardown()


@pycloud.command()
@click.pass_context
def docs(ctx):
    """
    Dumps the documentation for the available provisioners.
    """
    executor = PlanExecutor(None, _globals=ctx.obj)
    executor.help()


<mask token>

<mask token>


def validate_for_aws(access_key, secret_key):
    """
    Validates the provided aws access_key and secret_key.
    """
    if not access_key:
        click.secho(
            'Please provide AWS Access Key either as a parameter "--access-key=VALUE" or as an environment variable AWS_ACCESS_KEY'
            , fg='red')
        raise click.BadParameter('Access Key is not set.')
    if not secret_key:
        click.secho(
            'Please provide AWS Secret Key either as a parameter "--secret-key=VALUE" or as an environment variable AWS_SECRET_KEY'
            , fg='red')
        raise click.BadParameter('Secret Key is not set.')


@click.group()
@click.option('-l', '--log-level', envvar='PYCLOUD_LOG_LEVEL', help=
    'Set the Log Level for the command. Default: info', type=click.Choice([
    l.lower() for l in ALLOWED_LOG_LEVELS]), default='info')
@click.pass_context
def pycloud(ctx, log_level):
    """
    PyCloud Provisions a VM in the cloud,
    """
    KeyPairStorage.initialize()
    PyCloudConfig.initialize_state_mgmt()
    ctx.obj = {}
    configure_logger(level=log_level)
    return 0


@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY', help=
    'AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY', help=
    'AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def setup(ctx, access_key, secret_key, plan):
    """
    Sets up the infrastructure as specified by the plan.
    """
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.setup()


@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY', help=
    'AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY', help=
    'AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def teardown(ctx, access_key, secret_key, plan):
    """
    Tears down the infrastructure as specified by the plan.
    """
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.teardown()


@pycloud.command()
@click.pass_context
def docs(ctx):
    """
    Dumps the documentation for the available provisioners.
    """
    executor = PlanExecutor(None, _globals=ctx.obj)
    executor.help()


if __name__ == '__main__':
    sys.exit(pycloud())

<mask token>
logger = get_logger()


def validate_for_aws(access_key, secret_key):
    """
    Validates the provided aws access_key and secret_key.
    """
    if not access_key:
        click.secho(
            'Please provide AWS Access Key either as a parameter "--access-key=VALUE" or as an environment variable AWS_ACCESS_KEY'
            , fg='red')
        raise click.BadParameter('Access Key is not set.')
    if not secret_key:
        click.secho(
            'Please provide AWS Secret Key either as a parameter "--secret-key=VALUE" or as an environment variable AWS_SECRET_KEY'
            , fg='red')
        raise click.BadParameter('Secret Key is not set.')


@click.group()
@click.option('-l', '--log-level', envvar='PYCLOUD_LOG_LEVEL', help=
    'Set the Log Level for the command. Default: info', type=click.Choice([
    l.lower() for l in ALLOWED_LOG_LEVELS]), default='info')
@click.pass_context
def pycloud(ctx, log_level):
    """
    PyCloud Provisions a VM in the cloud,
    """
    KeyPairStorage.initialize()
    PyCloudConfig.initialize_state_mgmt()
    ctx.obj = {}
    configure_logger(level=log_level)
    return 0


@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY', help=
    'AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY', help=
    'AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def setup(ctx, access_key, secret_key, plan):
    """
    Sets up the infrastructure as specified by the plan.
    """
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.setup()


@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY', help=
    'AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY', help=
    'AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def teardown(ctx, access_key, secret_key, plan):
    """
    Tears down the infrastructure as specified by the plan.
    """
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.teardown()


@pycloud.command()
@click.pass_context
def docs(ctx):
    """
    Dumps the documentation for the available provisioners.
    """
    executor = PlanExecutor(None, _globals=ctx.obj)
    executor.help()


if __name__ == '__main__':
    sys.exit(pycloud())

# -*- coding: utf-8 -*-

"""Console script for pycloud."""
import sys
import click

from pycloud.logger import configure_logger, get_logger, ALLOWED_LOG_LEVELS
from pycloud.core.provisioners.plan_executor import PlanExecutor
from pycloud.core.config import PyCloudConfig
from pycloud.core.keypair_storage import KeyPairStorage

logger = get_logger()

def validate_for_aws(access_key, secret_key):
    '''
    Validates the provided aws access_key and secret_key.
    '''
    if not access_key:
        click.secho(
            'Please provide AWS Access Key either as a parameter "--access-key=VALUE" '
            'or as an environment variable AWS_ACCESS_KEY',
            fg='red')
        raise click.BadParameter('Access Key is not set.')
    if not secret_key:
        click.secho(
            'Please provide AWS Secret Key either as a parameter "--secret-key=VALUE" '
            'or as an environment variable AWS_SECRET_KEY',
            fg='red')
        raise click.BadParameter('Secret Key is not set.')



@click.group()
@click.option('-l', '--log-level', envvar='PYCLOUD_LOG_LEVEL',
              help='Set the Log Level for the command. Default: info',
              type=click.Choice([l.lower() for l in ALLOWED_LOG_LEVELS]),
              default='info')
@click.pass_context
def pycloud(ctx, log_level):
    """
    PyCloud Provisions a VM in the cloud,
    """
    KeyPairStorage.initialize()
    PyCloudConfig.initialize_state_mgmt()

    ctx.obj = {}
    configure_logger(level=log_level)
    return 0

@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY',
              help='AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY',
              help='AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def setup(ctx, access_key, secret_key, plan):
    '''
    Sets up the infrastructure as specified by the plan.
    '''
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.setup()

@pycloud.command()
@click.option('-a', '--access-key', envvar='AWS_ACCESS_KEY',
              help='AWS Access Key. You can also set environment variable AWS_ACCESS_KEY.')
@click.option('-s', '--secret-key', envvar='AWS_SECRET_KEY',
              help='AWS Secret Key. You can also set environment variable AWS_SECRET_KEY.')
@click.argument('plan', type=click.Path(exists=True))
@click.pass_context
def teardown(ctx, access_key, secret_key, plan):
    '''
    Tears down the infrastructure as specified by the plan.
    '''
    validate_for_aws(access_key, secret_key)
    ctx.obj['AWS_ACCESS_KEY'] = access_key
    ctx.obj['AWS_SECRET_KEY'] = secret_key
    executor = PlanExecutor(plan, _globals=ctx.obj)
    executor.teardown()

@pycloud.command()
@click.pass_context
def docs(ctx):
    '''
    Dumps the documentation for the available provisioners.
    '''
    executor = PlanExecutor(None, _globals=ctx.obj)
    executor.help()



if __name__ == "__main__":
    sys.exit(pycloud())  # pragma: no cover
