Guest User

Untitled

a guest
Dec 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import click
  2.  
  3. import mps.aws
  4. import mps.config
  5. from mps.exceptions import NoCredentialsException
  6.  
  7.  
  8. # create module-specific logger
  9. logger = logging.getLogger(__name__)
  10.  
  11.  
  12. class AppContext(click.Context): # pylint: disable=too-few-public-methods
  13. """ context object """
  14.  
  15. def __init__(self):
  16. self.__aws = {}
  17.  
  18. def aws(self, stage):
  19. """
  20. Returns an aws client for the specified stage
  21. """
  22.  
  23. if stage not in self.__aws:
  24.  
  25. region = mps.config.stage_region(stage)
  26.  
  27. logger.debug("Creating new aws object for stage %s in region %s", stage, region)
  28.  
  29. self.__aws[stage] = mps.aws.Aws.initialize(region)
  30.  
  31. return self.__aws[stage]
  32.  
  33. def check_credentials(self):
  34. """
  35. Make sure AWS credentials are found
  36. """
  37. try:
  38. mps.aws.Aws.check_credentials()
  39. except NoCredentialsException as e:
  40. raise click.ClickException(str(e))
  41.  
  42.  
  43. pass_ctx = click.make_pass_decorator(AppContext, ensure=True)
Add Comment
Please, Sign In to add comment