~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to boto/iam/connection.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2011-11-13 11:58:40 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20111113115840-ckzyt3h17uh8s41y
Tags: 2.0-2
Promote new upstream to unstable (Closes: #638931).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
23
import boto
 
24
import boto.jsonresponse
 
25
from boto.connection import AWSQueryConnection
 
26
 
 
27
#boto.set_stream_logger('iam')
 
28
 
 
29
class IAMConnection(AWSQueryConnection):
 
30
 
 
31
    APIVersion = '2010-05-08'
 
32
 
 
33
    def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
 
34
                 is_secure=True, port=None, proxy=None, proxy_port=None,
 
35
                 proxy_user=None, proxy_pass=None, host='iam.amazonaws.com',
 
36
                 debug=0, https_connection_factory=None, path='/'):
 
37
        AWSQueryConnection.__init__(self, aws_access_key_id,
 
38
                                    aws_secret_access_key,
 
39
                                    is_secure, port, proxy,
 
40
                                    proxy_port, proxy_user, proxy_pass,
 
41
                                    host, debug, https_connection_factory, path)
 
42
 
 
43
    def _required_auth_capability(self):
 
44
        return ['iam']
 
45
 
 
46
    def get_response(self, action, params, path='/', parent=None,
 
47
                     verb='GET', list_marker='Set'):
 
48
        """
 
49
        Utility method to handle calls to IAM and parsing of responses.
 
50
        """
 
51
        if not parent:
 
52
            parent = self
 
53
        response = self.make_request(action, params, path, verb)
 
54
        body = response.read()
 
55
        boto.log.debug(body)
 
56
        if response.status == 200:
 
57
            e = boto.jsonresponse.Element(list_marker=list_marker,
 
58
                                          pythonize_name=True)
 
59
            h = boto.jsonresponse.XmlHandler(e, parent)
 
60
            h.parse(body)
 
61
            return e
 
62
        else:
 
63
            boto.log.error('%s %s' % (response.status, response.reason))
 
64
            boto.log.error('%s' % body)
 
65
            raise self.ResponseError(response.status, response.reason, body)
 
66
 
 
67
    #
 
68
    # Group methods
 
69
    #
 
70
    
 
71
    def get_all_groups(self, path_prefix='/', marker=None, max_items=None):
 
72
        """
 
73
        List the groups that have the specified path prefix.
 
74
 
 
75
        :type path_prefix: string
 
76
        :param path_prefix: If provided, only groups whose paths match
 
77
                            the provided prefix will be returned.
 
78
 
 
79
        :type marker: string
 
80
        :param marker: Use this only when paginating results and only in
 
81
                       follow-up request after you've received a response
 
82
                       where the results are truncated.  Set this to the
 
83
                       value of the Marker element in the response you
 
84
                       just received.
 
85
 
 
86
        :type max_items: int
 
87
        :param max_items: Use this only when paginating results to indicate
 
88
                          the maximum number of groups you want in the
 
89
                          response.
 
90
        """
 
91
        params = {}
 
92
        if path_prefix:
 
93
            params['PathPrefix'] = path_prefix
 
94
        if marker:
 
95
            params['Marker'] = marker
 
96
        if max_items:
 
97
            params['MaxItems'] = max_items
 
98
        return self.get_response('ListGroups', params,
 
99
                                 list_marker='Groups')
 
100
    
 
101
    def get_group(self, group_name, marker=None, max_items=None):
 
102
        """
 
103
        Return a list of users that are in the specified group.
 
104
 
 
105
        :type group_name: string
 
106
        :param group_name: The name of the group whose information should
 
107
                           be returned.
 
108
        :type marker: string
 
109
        :param marker: Use this only when paginating results and only in
 
110
                       follow-up request after you've received a response
 
111
                       where the results are truncated.  Set this to the
 
112
                       value of the Marker element in the response you
 
113
                       just received.
 
114
 
 
115
        :type max_items: int
 
116
        :param max_items: Use this only when paginating results to indicate
 
117
                          the maximum number of groups you want in the
 
118
                          response.
 
119
        """
 
120
        params = {'GroupName' : group_name}
 
121
        if marker:
 
122
            params['Marker'] = marker
 
123
        if max_items:
 
124
            params['MaxItems'] = max_items
 
125
        return self.get_response('GetGroup', params, list_marker='Users')
 
126
        
 
127
    def create_group(self, group_name, path='/'):
 
128
        """
 
129
        Create a group.
 
130
 
 
131
        :type group_name: string
 
132
        :param group_name: The name of the new group
 
133
 
 
134
        :type path: string
 
135
        :param path: The path to the group (Optional).  Defaults to /.
 
136
 
 
137
        """
 
138
        params = {'GroupName' : group_name,
 
139
                  'Path' : path}
 
140
        return self.get_response('CreateGroup', params)
 
141
 
 
142
    def delete_group(self, group_name):
 
143
        """
 
144
        Delete a group. The group must not contain any Users or
 
145
        have any attached policies
 
146
 
 
147
        :type group_name: string
 
148
        :param group_name: The name of the group to delete.
 
149
 
 
150
        """
 
151
        params = {'GroupName' : group_name}
 
152
        return self.get_response('DeleteGroup', params)
 
153
 
 
154
    def update_group(self, group_name, new_group_name=None, new_path=None):
 
155
        """
 
156
        Updates name and/or path of the specified group.
 
157
 
 
158
        :type group_name: string
 
159
        :param group_name: The name of the new group
 
160
 
 
161
        :type new_group_name: string
 
162
        :param new_group_name: If provided, the name of the group will be
 
163
                               changed to this name.
 
164
 
 
165
        :type new_path: string
 
166
        :param new_path: If provided, the path of the group will be
 
167
                         changed to this path.
 
168
 
 
169
        """
 
170
        params = {'GroupName' : group_name}
 
171
        if new_group_name:
 
172
            params['NewGroupName'] = new_group_name
 
173
        if new_path:
 
174
            params['NewPath'] = new_path
 
175
        return self.get_response('UpdateGroup', params)
 
176
 
 
177
    def add_user_to_group(self, group_name, user_name):
 
178
        """
 
179
        Add a user to a group
 
180
 
 
181
        :type group_name: string
 
182
        :param group_name: The name of the group
 
183
 
 
184
        :type user_name: string
 
185
        :param user_name: The to be added to the group.
 
186
 
 
187
        """
 
188
        params = {'GroupName' : group_name,
 
189
                  'UserName' : user_name}
 
190
        return self.get_response('AddUserToGroup', params)
 
191
 
 
192
    def remove_user_from_group(self, group_name, user_name):
 
193
        """
 
194
        Remove a user from a group.
 
195
 
 
196
        :type group_name: string
 
197
        :param group_name: The name of the group
 
198
 
 
199
        :type user_name: string
 
200
        :param user_name: The user to remove from the group.
 
201
 
 
202
        """
 
203
        params = {'GroupName' : group_name,
 
204
                  'UserName' : user_name}
 
205
        return self.get_response('RemoveUserFromGroup', params)
 
206
 
 
207
    def put_group_policy(self, group_name, policy_name, policy_json):
 
208
        """
 
209
        Adds or updates the specified policy document for the specified group.
 
210
 
 
211
        :type group_name: string
 
212
        :param group_name: The name of the group the policy is associated with.
 
213
 
 
214
        :type policy_name: string
 
215
        :param policy_name: The policy document to get.
 
216
 
 
217
        :type policy_json: string
 
218
        :param policy_json: The policy document.
 
219
        
 
220
        """
 
221
        params = {'GroupName' : group_name,
 
222
                  'PolicyName' : policy_name,
 
223
                  'PolicyDocument' : policy_json}
 
224
        return self.get_response('PutGroupPolicy', params, verb='POST')
 
225
 
 
226
    def get_all_group_policies(self, group_name, marker=None, max_items=None):
 
227
        """
 
228
        List the names of the policies associated with the specified group.
 
229
 
 
230
        :type group_name: string
 
231
        :param group_name: The name of the group the policy is associated with.
 
232
 
 
233
        :type marker: string
 
234
        :param marker: Use this only when paginating results and only in
 
235
                       follow-up request after you've received a response
 
236
                       where the results are truncated.  Set this to the
 
237
                       value of the Marker element in the response you
 
238
                       just received.
 
239
 
 
240
        :type max_items: int
 
241
        :param max_items: Use this only when paginating results to indicate
 
242
                          the maximum number of groups you want in the
 
243
                          response.
 
244
        """
 
245
        params = {'GroupName' : group_name}
 
246
        if marker:
 
247
            params['Marker'] = marker
 
248
        if max_items:
 
249
            params['MaxItems'] = max_items
 
250
        return self.get_response('ListGroupPolicies', params,
 
251
                                 list_marker='PolicyNames')
 
252
 
 
253
    def get_group_policy(self, group_name, policy_name):
 
254
        """
 
255
        Retrieves the specified policy document for the specified group.
 
256
 
 
257
        :type group_name: string
 
258
        :param group_name: The name of the group the policy is associated with.
 
259
 
 
260
        :type policy_name: string
 
261
        :param policy_name: The policy document to get.
 
262
        
 
263
        """
 
264
        params = {'GroupName' : group_name,
 
265
                  'PolicyName' : policy_name}
 
266
        return self.get_response('GetGroupPolicy', params, verb='POST')
 
267
 
 
268
    def delete_group_policy(self, group_name, policy_name):
 
269
        """
 
270
        Deletes the specified policy document for the specified group.
 
271
 
 
272
        :type group_name: string
 
273
        :param group_name: The name of the group the policy is associated with.
 
274
 
 
275
        :type policy_name: string
 
276
        :param policy_name: The policy document to delete.
 
277
        
 
278
        """
 
279
        params = {'GroupName' : group_name,
 
280
                  'PolicyName' : policy_name}
 
281
        return self.get_response('DeleteGroupPolicy', params, verb='POST')
 
282
 
 
283
    def get_all_users(self, path_prefix='/', marker=None, max_items=None):
 
284
        """
 
285
        List the users that have the specified path prefix.
 
286
 
 
287
        :type path_prefix: string
 
288
        :param path_prefix: If provided, only users whose paths match
 
289
                            the provided prefix will be returned.
 
290
 
 
291
        :type marker: string
 
292
        :param marker: Use this only when paginating results and only in
 
293
                       follow-up request after you've received a response
 
294
                       where the results are truncated.  Set this to the
 
295
                       value of the Marker element in the response you
 
296
                       just received.
 
297
 
 
298
        :type max_items: int
 
299
        :param max_items: Use this only when paginating results to indicate
 
300
                          the maximum number of groups you want in the
 
301
                          response.
 
302
        """
 
303
        params = {'PathPrefix' : path_prefix}
 
304
        if marker:
 
305
            params['Marker'] = marker
 
306
        if max_items:
 
307
            params['MaxItems'] = max_items
 
308
        return self.get_response('ListUsers', params, list_marker='Users')
 
309
        
 
310
    #
 
311
    # User methods
 
312
    #
 
313
    
 
314
    def create_user(self, user_name, path='/'):
 
315
        """
 
316
        Create a user.
 
317
 
 
318
        :type user_name: string
 
319
        :param user_name: The name of the new user
 
320
 
 
321
        :type path: string
 
322
        :param path: The path in which the user will be created.
 
323
                     Defaults to /.
 
324
 
 
325
        """
 
326
        params = {'UserName' : user_name,
 
327
                  'Path' : path}
 
328
        return self.get_response('CreateUser', params)
 
329
 
 
330
    def delete_user(self, user_name):
 
331
        """
 
332
        Delete a user including the user's path, GUID and ARN.
 
333
 
 
334
        If the user_name is not specified, the user_name is determined
 
335
        implicitly based on the AWS Access Key ID used to sign the request.
 
336
 
 
337
        :type user_name: string
 
338
        :param user_name: The name of the user to delete.
 
339
 
 
340
        """
 
341
        params = {'UserName' : user_name}
 
342
        return self.get_response('DeleteUser', params)
 
343
 
 
344
    def get_user(self, user_name=None):
 
345
        """
 
346
        Retrieve information about the specified user.
 
347
 
 
348
        If the user_name is not specified, the user_name is determined
 
349
        implicitly based on the AWS Access Key ID used to sign the request.
 
350
 
 
351
        :type user_name: string
 
352
        :param user_name: The name of the user to delete.
 
353
                          If not specified, defaults to user making
 
354
                          request.
 
355
 
 
356
        """
 
357
        params = {}
 
358
        if user_name:
 
359
            params['UserName'] = user_name
 
360
        return self.get_response('GetUser', params)
 
361
 
 
362
    def update_user(self, user_name, new_user_name=None, new_path=None):
 
363
        """
 
364
        Updates name and/or path of the specified user.
 
365
 
 
366
        :type user_name: string
 
367
        :param user_name: The name of the user
 
368
 
 
369
        :type new_user_name: string
 
370
        :param new_user_name: If provided, the username of the user will be
 
371
                              changed to this username.
 
372
 
 
373
        :type new_path: string
 
374
        :param new_path: If provided, the path of the user will be
 
375
                         changed to this path.
 
376
 
 
377
        """
 
378
        params = {'UserName' : user_name}
 
379
        if new_user_name:
 
380
            params['NewUserName'] = new_user_name
 
381
        if new_path:
 
382
            params['NewPath'] = new_path
 
383
        return self.get_response('UpdateUser', params)
 
384
    
 
385
    def get_all_user_policies(self, user_name, marker=None, max_items=None):
 
386
        """
 
387
        List the names of the policies associated with the specified user.
 
388
 
 
389
        :type user_name: string
 
390
        :param user_name: The name of the user the policy is associated with.
 
391
 
 
392
        :type marker: string
 
393
        :param marker: Use this only when paginating results and only in
 
394
                       follow-up request after you've received a response
 
395
                       where the results are truncated.  Set this to the
 
396
                       value of the Marker element in the response you
 
397
                       just received.
 
398
 
 
399
        :type max_items: int
 
400
        :param max_items: Use this only when paginating results to indicate
 
401
                          the maximum number of groups you want in the
 
402
                          response.
 
403
        """
 
404
        params = {'UserName' : user_name}
 
405
        if marker:
 
406
            params['Marker'] = marker
 
407
        if max_items:
 
408
            params['MaxItems'] = max_items
 
409
        return self.get_response('ListUserPolicies', params,
 
410
                                 list_marker='PolicyNames')
 
411
 
 
412
    def put_user_policy(self, user_name, policy_name, policy_json):
 
413
        """
 
414
        Adds or updates the specified policy document for the specified user.
 
415
 
 
416
        :type user_name: string
 
417
        :param user_name: The name of the user the policy is associated with.
 
418
 
 
419
        :type policy_name: string
 
420
        :param policy_name: The policy document to get.
 
421
 
 
422
        :type policy_json: string
 
423
        :param policy_json: The policy document.
 
424
        
 
425
        """
 
426
        params = {'UserName' : user_name,
 
427
                  'PolicyName' : policy_name,
 
428
                  'PolicyDocument' : policy_json}
 
429
        return self.get_response('PutUserPolicy', params, verb='POST')
 
430
 
 
431
    def get_user_policy(self, user_name, policy_name):
 
432
        """
 
433
        Retrieves the specified policy document for the specified user.
 
434
 
 
435
        :type user_name: string
 
436
        :param user_name: The name of the user the policy is associated with.
 
437
 
 
438
        :type policy_name: string
 
439
        :param policy_name: The policy document to get.
 
440
        
 
441
        """
 
442
        params = {'UserName' : user_name,
 
443
                  'PolicyName' : policy_name}
 
444
        return self.get_response('GetUserPolicy', params, verb='POST')
 
445
 
 
446
    def delete_user_policy(self, user_name, policy_name):
 
447
        """
 
448
        Deletes the specified policy document for the specified user.
 
449
 
 
450
        :type user_name: string
 
451
        :param user_name: The name of the user the policy is associated with.
 
452
 
 
453
        :type policy_name: string
 
454
        :param policy_name: The policy document to delete.
 
455
        
 
456
        """
 
457
        params = {'UserName' : user_name,
 
458
                  'PolicyName' : policy_name}
 
459
        return self.get_response('DeleteUserPolicy', params, verb='POST')
 
460
 
 
461
    def get_groups_for_user(self, user_name, marker=None, max_items=None):
 
462
        """
 
463
        List the groups that a specified user belongs to.
 
464
 
 
465
        :type user_name: string
 
466
        :param user_name: The name of the user to list groups for.
 
467
 
 
468
        :type marker: string
 
469
        :param marker: Use this only when paginating results and only in
 
470
                       follow-up request after you've received a response
 
471
                       where the results are truncated.  Set this to the
 
472
                       value of the Marker element in the response you
 
473
                       just received.
 
474
 
 
475
        :type max_items: int
 
476
        :param max_items: Use this only when paginating results to indicate
 
477
                          the maximum number of groups you want in the
 
478
                          response.
 
479
        """
 
480
        params = {'UserName' : user_name}
 
481
        if marker:
 
482
            params['Marker'] = marker
 
483
        if max_items:
 
484
            params['MaxItems'] = max_items
 
485
        return self.get_response('ListGroupsForUser', params,
 
486
                                 list_marker='Groups')
 
487
        
 
488
    #
 
489
    # Access Keys
 
490
    #
 
491
    
 
492
    def get_all_access_keys(self, user_name, marker=None, max_items=None):
 
493
        """
 
494
        Get all access keys associated with an account.
 
495
 
 
496
        :type user_name: string
 
497
        :param user_name: The username of the user
 
498
 
 
499
        :type marker: string
 
500
        :param marker: Use this only when paginating results and only in
 
501
                       follow-up request after you've received a response
 
502
                       where the results are truncated.  Set this to the
 
503
                       value of the Marker element in the response you
 
504
                       just received.
 
505
 
 
506
        :type max_items: int
 
507
        :param max_items: Use this only when paginating results to indicate
 
508
                          the maximum number of groups you want in the
 
509
                          response.
 
510
        """
 
511
        params = {'UserName' : user_name}
 
512
        if marker:
 
513
            params['Marker'] = marker
 
514
        if max_items:
 
515
            params['MaxItems'] = max_items
 
516
        return self.get_response('ListAccessKeys', params,
 
517
                                 list_marker='AccessKeyMetadata')
 
518
 
 
519
    def create_access_key(self, user_name=None):
 
520
        """
 
521
        Create a new AWS Secret Access Key and corresponding AWS Access Key ID
 
522
        for the specified user.  The default status for new keys is Active
 
523
 
 
524
        If the user_name is not specified, the user_name is determined
 
525
        implicitly based on the AWS Access Key ID used to sign the request.
 
526
 
 
527
        :type user_name: string
 
528
        :param user_name: The username of the user
 
529
 
 
530
        """
 
531
        params = {'UserName' : user_name}
 
532
        return self.get_response('CreateAccessKey', params)
 
533
 
 
534
    def update_access_key(self, access_key_id, status, user_name=None):
 
535
        """
 
536
        Changes the status of the specified access key from Active to Inactive
 
537
        or vice versa.  This action can be used to disable a user's key as
 
538
        part of a key rotation workflow.
 
539
 
 
540
        If the user_name is not specified, the user_name is determined
 
541
        implicitly based on the AWS Access Key ID used to sign the request.
 
542
 
 
543
        :type access_key_id: string
 
544
        :param access_key_id: The ID of the access key.
 
545
 
 
546
        :type status: string
 
547
        :param status: Either Active or Inactive.
 
548
 
 
549
        :type user_name: string
 
550
        :param user_name: The username of user (optional).
 
551
 
 
552
        """
 
553
        params = {'AccessKeyId' : access_key_id,
 
554
                  'Status' : status}
 
555
        if user_name:
 
556
            params['UserName'] = user_name
 
557
        return self.get_response('UpdateAccessKey', params)
 
558
 
 
559
    def delete_access_key(self, access_key_id, user_name=None):
 
560
        """
 
561
        Delete an access key associated with a user.
 
562
 
 
563
        If the user_name is not specified, it is determined implicitly based
 
564
        on the AWS Access Key ID used to sign the request.
 
565
 
 
566
        :type access_key_id: string
 
567
        :param access_key_id: The ID of the access key to be deleted.
 
568
 
 
569
        :type user_name: string
 
570
        :param user_name: The username of the user
 
571
 
 
572
        """
 
573
        params = {'AccessKeyId' : access_key_id}
 
574
        if user_name:
 
575
            params['UserName'] = user_name
 
576
        return self.get_response('DeleteAccessKey', params)
 
577
 
 
578
    #
 
579
    # Signing Certificates
 
580
    #
 
581
    
 
582
    def get_all_signing_certs(self, marker=None, max_items=None,
 
583
                              user_name=None):
 
584
        """
 
585
        Get all signing certificates associated with an account.
 
586
 
 
587
        If the user_name is not specified, it is determined implicitly based
 
588
        on the AWS Access Key ID used to sign the request.
 
589
 
 
590
        :type marker: string
 
591
        :param marker: Use this only when paginating results and only in
 
592
                       follow-up request after you've received a response
 
593
                       where the results are truncated.  Set this to the
 
594
                       value of the Marker element in the response you
 
595
                       just received.
 
596
 
 
597
        :type max_items: int
 
598
        :param max_items: Use this only when paginating results to indicate
 
599
                          the maximum number of groups you want in the
 
600
                          response.
 
601
                          
 
602
        :type user_name: string
 
603
        :param user_name: The username of the user
 
604
 
 
605
        """
 
606
        params = {}
 
607
        if marker:
 
608
            params['Marker'] = marker
 
609
        if max_items:
 
610
            params['MaxItems'] = max_items
 
611
        if user_name:
 
612
            params['UserName'] = user_name
 
613
        return self.get_response('ListSigningCertificates',
 
614
                                 params, list_marker='Certificates')
 
615
 
 
616
    def update_signing_cert(self, cert_id, status, user_name=None):
 
617
        """
 
618
        Change the status of the specified signing certificate from
 
619
        Active to Inactive or vice versa.
 
620
 
 
621
        If the user_name is not specified, it is determined implicitly based
 
622
        on the AWS Access Key ID used to sign the request.
 
623
 
 
624
        :type cert_id: string
 
625
        :param cert_id: The ID of the signing certificate
 
626
 
 
627
        :type status: string
 
628
        :param status: Either Active or Inactive.
 
629
 
 
630
        :type user_name: string
 
631
        :param user_name: The username of the user
 
632
        """
 
633
        params = {'CertificateId' : cert_id,
 
634
                  'Status' : status}
 
635
        if user_name:
 
636
            params['UserName'] = user_name
 
637
        return self.get_response('UpdateSigningCertificate', params)
 
638
 
 
639
    def upload_signing_cert(self, cert_body, user_name=None):
 
640
        """
 
641
        Uploads an X.509 signing certificate and associates it with
 
642
        the specified user.
 
643
 
 
644
        If the user_name is not specified, it is determined implicitly based
 
645
        on the AWS Access Key ID used to sign the request.
 
646
 
 
647
        :type cert_body: string
 
648
        :param cert_body: The body of the signing certificate.
 
649
 
 
650
        :type user_name: string
 
651
        :param user_name: The username of the user
 
652
 
 
653
        """
 
654
        params = {'CertificateBody' : cert_body}
 
655
        if user_name:
 
656
            params['UserName'] = user_name
 
657
        return self.get_response('UploadSigningCertificate', params,
 
658
                                 verb='POST')
 
659
 
 
660
    def delete_signing_cert(self, cert_id, user_name=None):
 
661
        """
 
662
        Delete a signing certificate associated with a user.
 
663
 
 
664
        If the user_name is not specified, it is determined implicitly based
 
665
        on the AWS Access Key ID used to sign the request.
 
666
 
 
667
        :type user_name: string
 
668
        :param user_name: The username of the user
 
669
 
 
670
        :type cert_id: string
 
671
        :param cert_id: The ID of the certificate.
 
672
 
 
673
        """
 
674
        params = {'CertificateId' : cert_id}
 
675
        if user_name:
 
676
            params['UserName'] = user_name
 
677
        return self.get_response('DeleteSigningCertificate', params)
 
678
 
 
679
    #
 
680
    # Server Certificates
 
681
    #
 
682
    
 
683
    def get_all_server_certs(self, path_prefix='/',
 
684
                             marker=None, max_items=None):
 
685
        """
 
686
        Lists the server certificates that have the specified path prefix.
 
687
        If none exist, the action returns an empty list.
 
688
 
 
689
        :type path_prefix: string
 
690
        :param path_prefix: If provided, only certificates whose paths match
 
691
                            the provided prefix will be returned.
 
692
 
 
693
        :type marker: string
 
694
        :param marker: Use this only when paginating results and only in
 
695
                       follow-up request after you've received a response
 
696
                       where the results are truncated.  Set this to the
 
697
                       value of the Marker element in the response you
 
698
                       just received.
 
699
 
 
700
        :type max_items: int
 
701
        :param max_items: Use this only when paginating results to indicate
 
702
                          the maximum number of groups you want in the
 
703
                          response.
 
704
                          
 
705
        """
 
706
        params = {}
 
707
        if path_prefix:
 
708
            params['PathPrefix'] = path_prefix
 
709
        if marker:
 
710
            params['Marker'] = marker
 
711
        if max_items:
 
712
            params['MaxItems'] = max_items
 
713
        return self.get_response('ListServerCertificates',
 
714
                                 params,
 
715
                                 list_marker='ServerCertificateMetadataList')
 
716
 
 
717
    def update_server_cert(self, cert_name, new_cert_name=None,
 
718
                           new_path=None):
 
719
        """
 
720
        Updates the name and/or the path of the specified server certificate.
 
721
 
 
722
        :type cert_name: string
 
723
        :param cert_name: The name of the server certificate that you want
 
724
                          to update.
 
725
 
 
726
        :type new_cert_name: string
 
727
        :param new_cert_name: The new name for the server certificate.
 
728
                              Include this only if you are updating the
 
729
                              server certificate's name.
 
730
 
 
731
        :type new_path: string
 
732
        :param new_path: If provided, the path of the certificate will be
 
733
                         changed to this path.
 
734
        """
 
735
        params = {'ServerCertificateName' : cert_name}
 
736
        if new_cert_name:
 
737
            params['NewServerCertificateName'] = new_cert_name
 
738
        if new_path:
 
739
            params['NewPath'] = new_path
 
740
        return self.get_response('UpdateServerCertificate', params)
 
741
 
 
742
    def upload_server_cert(self, cert_name, cert_body, private_key,
 
743
                           cert_chain=None, path=None):
 
744
        """
 
745
        Uploads a server certificate entity for the AWS Account.
 
746
        The server certificate entity includes a public key certificate,
 
747
        a private key, and an optional certificate chain, which should
 
748
        all be PEM-encoded.
 
749
 
 
750
        :type cert_name: string
 
751
        :param cert_name: The name for the server certificate. Do not
 
752
                          include the path in this value.
 
753
 
 
754
        :type cert_body: string
 
755
        :param cert_body: The contents of the public key certificate
 
756
                          in PEM-encoded format.
 
757
 
 
758
        :type private_key: string
 
759
        :param private_key: The contents of the private key in
 
760
                            PEM-encoded format.
 
761
 
 
762
        :type cert_chain: string
 
763
        :param cert_chain: The contents of the certificate chain. This
 
764
                           is typically a concatenation of the PEM-encoded
 
765
                           public key certificates of the chain.
 
766
 
 
767
        :type path: string
 
768
        :param path: The path for the server certificate.
 
769
 
 
770
        """
 
771
        params = {'ServerCertificateName' : cert_name,
 
772
                  'CertificateBody' : cert_body,
 
773
                  'PrivateKey' : private_key}
 
774
        if cert_chain:
 
775
            params['CertificateChain'] = cert_chain
 
776
        if path:
 
777
            params['Path'] = path
 
778
        return self.get_response('UploadServerCertificate', params,
 
779
                                 verb='POST')
 
780
 
 
781
    def get_server_certificate(self, cert_name):
 
782
        """
 
783
        Retrieves information about the specified server certificate.
 
784
 
 
785
        :type cert_name: string
 
786
        :param cert_name: The name of the server certificate you want
 
787
                          to retrieve information about.
 
788
        
 
789
        """
 
790
        params = {'ServerCertificateName' : cert_name}
 
791
        return self.get_response('GetServerCertificate', params)
 
792
 
 
793
    def delete_server_cert(self, cert_name):
 
794
        """
 
795
        Delete the specified server certificate.
 
796
 
 
797
        :type cert_name: string
 
798
        :param cert_name: The name of the server certificate you want
 
799
                          to delete.
 
800
 
 
801
        """
 
802
        params = {'ServerCertificateName' : cert_name}
 
803
        return self.get_response('DeleteServerCertificate', params)
 
804
 
 
805
    #
 
806
    # MFA Devices
 
807
    #
 
808
    
 
809
    def get_all_mfa_devices(self, user_name, marker=None, max_items=None):
 
810
        """
 
811
        Get all MFA devices associated with an account.
 
812
 
 
813
        :type user_name: string
 
814
        :param user_name: The username of the user
 
815
 
 
816
        :type marker: string
 
817
        :param marker: Use this only when paginating results and only in
 
818
                       follow-up request after you've received a response
 
819
                       where the results are truncated.  Set this to the
 
820
                       value of the Marker element in the response you
 
821
                       just received.
 
822
 
 
823
        :type max_items: int
 
824
        :param max_items: Use this only when paginating results to indicate
 
825
                          the maximum number of groups you want in the
 
826
                          response.
 
827
                          
 
828
        """
 
829
        params = {'UserName' : user_name}
 
830
        if marker:
 
831
            params['Marker'] = marker
 
832
        if max_items:
 
833
            params['MaxItems'] = max_items
 
834
        return self.get_response('ListMFADevices',
 
835
                                 params, list_marker='MFADevices')
 
836
 
 
837
    def enable_mfa_device(self, user_name, serial_number,
 
838
                          auth_code_1, auth_code_2):
 
839
        """
 
840
        Enables the specified MFA device and associates it with the
 
841
        specified user.
 
842
 
 
843
        :type user_name: string
 
844
        :param user_name: The username of the user
 
845
        
 
846
        :type serial_number: string
 
847
        :param seriasl_number: The serial number which uniquely identifies
 
848
                               the MFA device.
 
849
 
 
850
        :type auth_code_1: string
 
851
        :param auth_code_1: An authentication code emitted by the device.
 
852
 
 
853
        :type auth_code_2: string
 
854
        :param auth_code_2: A subsequent authentication code emitted
 
855
                            by the device.
 
856
 
 
857
        """
 
858
        params = {'UserName' : user_name,
 
859
                  'SerialNumber' : serial_number,
 
860
                  'AuthenticationCode1' : auth_code_1,
 
861
                  'AuthenticationCode2' : auth_code_2}
 
862
        return self.get_response('EnableMFADevice', params)
 
863
 
 
864
    def deactivate_mfa_device(self, user_name, serial_number):
 
865
        """
 
866
        Deactivates the specified MFA device and removes it from
 
867
        association with the user.
 
868
 
 
869
        :type user_name: string
 
870
        :param user_name: The username of the user
 
871
        
 
872
        :type serial_number: string
 
873
        :param seriasl_number: The serial number which uniquely identifies
 
874
                               the MFA device.
 
875
 
 
876
        """
 
877
        params = {'UserName' : user_name,
 
878
                  'SerialNumber' : serial_number}
 
879
        return self.get_response('DeactivateMFADevice', params)
 
880
 
 
881
    def resync_mfa_device(self, user_name, serial_number,
 
882
                          auth_code_1, auth_code_2):
 
883
        """
 
884
        Syncronizes the specified MFA device with the AWS servers.
 
885
 
 
886
        :type user_name: string
 
887
        :param user_name: The username of the user
 
888
        
 
889
        :type serial_number: string
 
890
        :param seriasl_number: The serial number which uniquely identifies
 
891
                               the MFA device.
 
892
 
 
893
        :type auth_code_1: string
 
894
        :param auth_code_1: An authentication code emitted by the device.
 
895
 
 
896
        :type auth_code_2: string
 
897
        :param auth_code_2: A subsequent authentication code emitted
 
898
                            by the device.
 
899
 
 
900
        """
 
901
        params = {'UserName' : user_name,
 
902
                  'SerialNumber' : serial_number,
 
903
                  'AuthenticationCode1' : auth_code_1,
 
904
                  'AuthenticationCode2' : auth_code_2}
 
905
        return self.get_response('ResyncMFADevice', params)
 
906
 
 
907
    #
 
908
    # Login Profiles
 
909
    #
 
910
 
 
911
    def get_login_profiles(self, user_name):
 
912
        """
 
913
        Retrieves the login profile for the specified user.
 
914
        
 
915
        :type user_name: string
 
916
        :param user_name: The username of the user
 
917
        
 
918
        """
 
919
        params = {'UserName' : user_name}
 
920
        return self.get_response('GetLoginProfile', params)
 
921
    
 
922
    def create_login_profile(self, user_name, password):
 
923
        """
 
924
        Creates a login profile for the specified user, give the user the
 
925
        ability to access AWS services and the AWS Management Console.
 
926
 
 
927
        :type user_name: string
 
928
        :param user_name: The name of the user
 
929
 
 
930
        :type password: string
 
931
        :param password: The new password for the user
 
932
 
 
933
        """
 
934
        params = {'UserName' : user_name,
 
935
                  'Password' : password}
 
936
        return self.get_response('CreateLoginProfile', params)
 
937
 
 
938
    def delete_login_profile(self, user_name):
 
939
        """
 
940
        Deletes the login profile associated with the specified user.
 
941
 
 
942
        :type user_name: string
 
943
        :param user_name: The name of the user to delete.
 
944
 
 
945
        """
 
946
        params = {'UserName' : user_name}
 
947
        return self.get_response('DeleteLoginProfile', params)
 
948
 
 
949
    def update_login_profile(self, user_name, password):
 
950
        """
 
951
        Resets the password associated with the user's login profile.
 
952
 
 
953
        :type user_name: string
 
954
        :param user_name: The name of the user
 
955
 
 
956
        :type password: string
 
957
        :param password: The new password for the user
 
958
 
 
959
        """
 
960
        params = {'UserName' : user_name,
 
961
                  'Password' : password}
 
962
        return self.get_response('UpdateLoginProfile', params)
 
963
    
 
964
    def create_account_alias(self, alias):
 
965
        """
 
966
        Creates a new alias for the AWS account.
 
967
 
 
968
        For more information on account id aliases, please see
 
969
        http://goo.gl/ToB7G
 
970
 
 
971
        :type alias: string
 
972
        :param alias: The alias to attach to the account. 
 
973
        """
 
974
        params = {'AccountAlias': alias}
 
975
        return self.get_response('CreateAccountAlias', params)
 
976
    
 
977
    def delete_account_alias(self, alias):
 
978
        """
 
979
        Deletes an alias for the AWS account.
 
980
 
 
981
        For more information on account id aliases, please see
 
982
        http://goo.gl/ToB7G
 
983
 
 
984
        :type alias: string
 
985
        :param alias: The alias to remove from the account.
 
986
        """
 
987
        params = {'AccountAlias': alias}
 
988
        return self.get_response('DeleteAccountAlias', params)
 
989
    
 
990
    def get_account_alias(self):
 
991
        """
 
992
        Get the alias for the current account.
 
993
 
 
994
        This is referred to in the docs as list_account_aliases,
 
995
        but it seems you can only have one account alias currently.
 
996
        
 
997
        For more information on account id aliases, please see
 
998
        http://goo.gl/ToB7G
 
999
        """
 
1000
        r = self.get_response('ListAccountAliases', {})
 
1001
        response = r.get('ListAccountAliasesResponse')
 
1002
        result = response.get('ListAccountAliasesResult')
 
1003
        aliases = result.get('AccountAliases')
 
1004
        return aliases.get('member', None)
 
1005
 
 
1006
    def get_signin_url(self, service='ec2'):
 
1007
        """
 
1008
        Get the URL where IAM users can use their login profile to sign in
 
1009
        to this account's console.
 
1010
 
 
1011
        :type service: string
 
1012
        :param service: Default service to go to in the console.
 
1013
        """
 
1014
        alias = self.get_account_alias()
 
1015
        if not alias:
 
1016
            raise Exception('No alias associated with this account.  Please use iam.create_account_alias() first.')
 
1017
 
 
1018
        return "https://%s.signin.aws.amazon.com/console/%s" % (alias, service)