OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2011 Mitch Garnaat http://garnaat.org/ |
| 2 # Copyright (c) 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 |
| 23 from boto.connection import AWSQueryConnection |
| 24 from boto.regioninfo import RegionInfo |
| 25 from credentials import Credentials, FederationToken |
| 26 import boto |
| 27 |
| 28 class STSConnection(AWSQueryConnection): |
| 29 |
| 30 DefaultRegionName = 'us-east-1' |
| 31 DefaultRegionEndpoint = 'sts.amazonaws.com' |
| 32 APIVersion = '2011-06-15' |
| 33 |
| 34 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, |
| 35 is_secure=True, port=None, proxy=None, proxy_port=None, |
| 36 proxy_user=None, proxy_pass=None, debug=0, |
| 37 https_connection_factory=None, region=None, path='/', |
| 38 converter=None): |
| 39 if not region: |
| 40 region = RegionInfo(self, self.DefaultRegionName, |
| 41 self.DefaultRegionEndpoint, |
| 42 connection_cls=STSConnection) |
| 43 self.region = region |
| 44 AWSQueryConnection.__init__(self, aws_access_key_id, |
| 45 aws_secret_access_key, |
| 46 is_secure, port, proxy, proxy_port, |
| 47 proxy_user, proxy_pass, |
| 48 self.region.endpoint, debug, |
| 49 https_connection_factory, path) |
| 50 |
| 51 def _required_auth_capability(self): |
| 52 return ['sign-v2'] |
| 53 |
| 54 def get_session_token(self, duration=None): |
| 55 """ |
| 56 :type duration: int |
| 57 :param duration: The number of seconds the credentials should |
| 58 remain valid. |
| 59 |
| 60 """ |
| 61 params = {} |
| 62 if duration: |
| 63 params['Duration'] = duration |
| 64 return self.get_object('GetSessionToken', params, |
| 65 Credentials, verb='POST') |
| 66 |
| 67 |
| 68 def get_federation_token(self, name, duration=None, policy=None): |
| 69 """ |
| 70 :type name: str |
| 71 :param name: The name of the Federated user associated with |
| 72 the credentials. |
| 73 |
| 74 :type duration: int |
| 75 :param duration: The number of seconds the credentials should |
| 76 remain valid. |
| 77 |
| 78 :type policy: str |
| 79 :param policy: A JSON policy to associate with these credentials. |
| 80 |
| 81 """ |
| 82 params = {'Name' : name} |
| 83 if duration: |
| 84 params['Duration'] = duration |
| 85 if policy: |
| 86 params['Policy'] = policy |
| 87 return self.get_object('GetFederationToken', params, |
| 88 FederationToken, verb='POST') |
| 89 |
| 90 |
OLD | NEW |