PageRenderTime 21ms CodeModel.GetById 18ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Python | 70 lines | 17 code | 4 blank | 49 comment | 6 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
23from connection import STSConnection
24from boto.regioninfo import RegionInfo
25
26def regions():
27    """
28    Get all available regions for the STS service.
29
30    :rtype: list
31    :return: A list of :class:`boto.regioninfo.RegionInfo` instances
32    """
33    return [RegionInfo(name='us-east-1',
34                       endpoint='sts.amazonaws.com',
35                       connection_cls=STSConnection)
36            ]
37
38def connect_to_region(region_name, **kw_params):
39    """
40    Given a valid region name, return a 
41    :class:`boto.sts.connection.STSConnection`.
42
43    :type: str
44    :param region_name: The name of the region to connect to.
45    
46    :rtype: :class:`boto.sts.connection.STSConnection` or ``None``
47    :return: A connection to the given region, or None if an invalid region
48             name is given
49    """
50    for region in regions():
51        if region.name == region_name:
52            return region.connect(**kw_params)
53    return None
54
55def get_region(region_name, **kw_params):
56    """
57    Find and return a :class:`boto.regioninfo.RegionInfo` object
58    given a region name.
59
60    :type: str
61    :param: The name of the region.
62
63    :rtype: :class:`boto.regioninfo.RegionInfo`
64    :return: The RegionInfo object for the given region or None if
65             an invalid region name is provided.
66    """
67    for region in regions(**kw_params):
68        if region.name == region_name:
69            return region
70    return None