PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/boto-2.5.2/boto/sts/__init__.py

#
Python | 70 lines | 17 code | 4 blank | 49 comment | 4 complexity | 0183ac660146ce782f23f52adffd26b8 MD5 | raw file
  1. # Copyright (c) 2010-2011 Mitch Garnaat http://garnaat.org/
  2. # Copyright (c) 2010-2011, Eucalyptus Systems, Inc.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a
  5. # copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish, dis-
  8. # tribute, sublicense, and/or sell copies of the Software, and to permit
  9. # persons to whom the Software is furnished to do so, subject to the fol-
  10. # lowing conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  17. # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  18. # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. # IN THE SOFTWARE.
  22. from connection import STSConnection
  23. from boto.regioninfo import RegionInfo
  24. def regions():
  25. """
  26. Get all available regions for the STS service.
  27. :rtype: list
  28. :return: A list of :class:`boto.regioninfo.RegionInfo` instances
  29. """
  30. return [RegionInfo(name='us-east-1',
  31. endpoint='sts.amazonaws.com',
  32. connection_cls=STSConnection)
  33. ]
  34. def connect_to_region(region_name, **kw_params):
  35. """
  36. Given a valid region name, return a
  37. :class:`boto.sts.connection.STSConnection`.
  38. :type: str
  39. :param region_name: The name of the region to connect to.
  40. :rtype: :class:`boto.sts.connection.STSConnection` or ``None``
  41. :return: A connection to the given region, or None if an invalid region
  42. name is given
  43. """
  44. for region in regions():
  45. if region.name == region_name:
  46. return region.connect(**kw_params)
  47. return None
  48. def get_region(region_name, **kw_params):
  49. """
  50. Find and return a :class:`boto.regioninfo.RegionInfo` object
  51. given a region name.
  52. :type: str
  53. :param: The name of the region.
  54. :rtype: :class:`boto.regioninfo.RegionInfo`
  55. :return: The RegionInfo object for the given region or None if
  56. an invalid region name is provided.
  57. """
  58. for region in regions(**kw_params):
  59. if region.name == region_name:
  60. return region
  61. return None