1 module vibe.aws.credentials; 2 3 4 /** 5 AWS Credentials 6 */ 7 struct AWSCredentials { 8 string accessKeyID; 9 string accessKeySecret; 10 string sessionToken; 11 } 12 13 /** 14 AWS Credential source 15 16 Classes that implement this provide credentials for AWS requests. A 17 Credential Source is an active object, since credentials may change during 18 the lifetime of the application 19 */ 20 interface AWSCredentialSource { 21 /** 22 Retrieve the current set of credentials 23 */ 24 AWSCredentials credentials(string credScope); 25 26 /** 27 Called when credentials turn out to be rejected by the backend 28 */ 29 void credentialsInvalid(string credScope, AWSCredentials creds, string reason); 30 } 31 32 /** 33 Provider of a static set of AWS credentials 34 35 This will never use a session token, since the credentials have to be root or 36 static IAM credentials. 37 */ 38 class StaticAWSCredentials : AWSCredentialSource 39 { 40 AWSCredentials m_creds; 41 42 this(string accessKeyID, string accessKeySecret) 43 { 44 m_creds = AWSCredentials(accessKeyID, accessKeySecret, ""); 45 } 46 47 AWSCredentials credentials(string credScope) 48 { 49 // FIXME: Different creds for different scopes? 50 return m_creds; 51 } 52 53 void credentialsInvalid(string credScope, AWSCredentials creds, string reason) 54 { 55 // Nothing we can do about this, just throw an exception 56 throw new Exception("Static credentials with ID " ~ creds.accessKeyID ~ " rejected because: " ~ reason); 57 } 58 }