Fix for iam credentials in boto version < 2.9
This commit is contained in:
		
							parent
							
								
									d7bfe5dea7
								
							
						
					
					
						commit
						c6d6a0273d
					
				| @ -55,17 +55,26 @@ def metadata_response(request, full_url, headers): | ||||
| 
 | ||||
|     http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html | ||||
|     """ | ||||
| 
 | ||||
|     parsed_url = urlparse(full_url) | ||||
|     tomorrow = datetime.datetime.now() + datetime.timedelta(days=1) | ||||
|     credentials = dict( | ||||
|         AccessKeyId="test-key", | ||||
|         SecretAccessKey="test-secret-key", | ||||
|         Token="test-session-token", | ||||
|         Expiration=tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ") | ||||
|     ) | ||||
| 
 | ||||
|     path = parsed_url.path.lstrip("/latest/meta-data/") | ||||
|     if path == 'iam/security-credentials/': | ||||
|     if path == '': | ||||
|         result = 'iam' | ||||
|     elif path == 'iam': | ||||
|         result = json.dumps({ | ||||
|             'security-credentials': { | ||||
|                 'default-role': credentials | ||||
|             } | ||||
|         }) | ||||
|     elif path == 'iam/security-credentials/': | ||||
|         result = 'default-role' | ||||
|     elif path == 'iam/security-credentials/default-role': | ||||
|         result = json.dumps(dict( | ||||
|             AccessKeyId="test-key", | ||||
|             SecretAccessKey="test-secret-key", | ||||
|             Token="test-session-token", | ||||
|             Expiration=tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ") | ||||
|         )) | ||||
|         result = json.dumps(credentials) | ||||
|     return 200, headers, result | ||||
|  | ||||
| @ -9,7 +9,7 @@ from moto import mock_ec2 | ||||
| 
 | ||||
| ################ Test Readme ############### | ||||
| def add_servers(ami_id, count): | ||||
|     conn = boto.connect_ec2('the_key', 'the_secret') | ||||
|     conn = boto.connect_ec2() | ||||
|     for index in range(count): | ||||
|         conn.run_instances(ami_id) | ||||
| 
 | ||||
| @ -18,7 +18,7 @@ def add_servers(ami_id, count): | ||||
| def test_add_servers(): | ||||
|     add_servers('ami-1234abcd', 2) | ||||
| 
 | ||||
|     conn = boto.connect_ec2('the_key', 'the_secret') | ||||
|     conn = boto.connect_ec2() | ||||
|     reservations = conn.get_all_instances() | ||||
|     assert len(reservations) == 2 | ||||
|     instance1 = reservations[0].instances[0] | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user