Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import click
- import mps.aws
- import mps.config
- from mps.exceptions import NoCredentialsException
- # create module-specific logger
- logger = logging.getLogger(__name__)
- class AppContext(click.Context): # pylint: disable=too-few-public-methods
- """ context object """
- def __init__(self):
- self.__aws = {}
- def aws(self, stage):
- """
- Returns an aws client for the specified stage
- """
- if stage not in self.__aws:
- region = mps.config.stage_region(stage)
- logger.debug("Creating new aws object for stage %s in region %s", stage, region)
- self.__aws[stage] = mps.aws.Aws.initialize(region)
- return self.__aws[stage]
- def check_credentials(self):
- """
- Make sure AWS credentials are found
- """
- try:
- mps.aws.Aws.check_credentials()
- except NoCredentialsException as e:
- raise click.ClickException(str(e))
- pass_ctx = click.make_pass_decorator(AppContext, ensure=True)
Add Comment
Please, Sign In to add comment