Пример #1
0
 protected override bool Execute(AwsClientDetails clientDetails)
 {
     using (AmazonSQS client = GetClient(clientDetails))
     {
         return Execute(client);
     }
 }
        /// <summary>
        /// Load AWS client details from the registry.
        /// </summary>
        /// <param name="containerName">Encryption container name</param>
        /// <returns>Aws Client Details</returns>
        public AwsClientDetails Load(string containerName)
        {
            if (containerName == null)
            {
                throw new ArgumentNullException("containerName");
            }

            using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(RegistrySubKey))
            {
                if (registryKey == null)
                {
                    throw new ApplicationException("Registry key does not exist.");
                }

                var clientDetails = new AwsClientDetails();

                clientDetails.AwsAccessKeyId = (string)registryKey.GetValue(AccessKeyIdKeyName);
                if (string.IsNullOrEmpty(clientDetails.AwsAccessKeyId))
                {
                    throw new InvalidOperationException("Stored AWS Access key is not valid");
                }

                var encrypredPassword = (string)registryKey.GetValue(SecretAccessKeyKeyName);
                if (string.IsNullOrEmpty(encrypredPassword))
                {
                    throw new InvalidOperationException("Stored AWS Secret Access Key is not valid");
                }

                clientDetails.AwsSecretAccessKey = EncryptionHelper.Decrypt(containerName, encrypredPassword);



                return(clientDetails);
            }
        }
        /// <summary>
        /// Load AWS client details from the registry.
        /// </summary>
        /// <param name="containerName">Encryption container name</param>
        /// <returns>Aws Client Details</returns>
        public AwsClientDetails Load(string containerName)
        {
            if (containerName == null) throw new ArgumentNullException("containerName");

            using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(RegistrySubKey))
            {
                if (registryKey == null)
                {
                    throw new ApplicationException("Registry key does not exist.");
                }

                var clientDetails = new AwsClientDetails();

                clientDetails.AwsAccessKeyId = (string)registryKey.GetValue(AccessKeyIdKeyName);
                if (string.IsNullOrEmpty(clientDetails.AwsAccessKeyId))
                {
                    throw new InvalidOperationException("Stored AWS Access key is not valid");
                }

                var encrypredPassword = (string)registryKey.GetValue(SecretAccessKeyKeyName);
                if (string.IsNullOrEmpty(encrypredPassword))
                {
                    throw new InvalidOperationException("Stored AWS Secret Access Key is not valid");
                }

                clientDetails.AwsSecretAccessKey = EncryptionHelper.Decrypt(containerName, encrypredPassword);

                return clientDetails;
            }
        }
 protected override bool Execute(AwsClientDetails clientDetails)
 {
     using (AmazonIdentityManagementService client = GetService(clientDetails))
     {
         return Execute(client);
     }
 }
 private void DisassociateIpAddress(AwsClientDetails clientDetails)
 {
     using (var helper = new EC2Helper(clientDetails))
     {
         helper.DisassociateIpAddress(IpAddress);
         Log.LogMessage(MessageImportance.Normal, "Disassiociated IPAddress {0}", IpAddress);
     }
 }
 private void AddPermissions(AwsClientDetails clientDetails)
 {
     using (var helper = new SNSHelper(clientDetails))
     {
         helper.AddPermission(ActionNames, AwsAccountIds, Label, TopicArn);
         Log.LogMessage(MessageImportance.Normal, "Set permissiosn for AWS Accounts {0} to Topic Arn {1}", Join(AwsAccountIds), TopicArn);
     }
 }
 private void Subscribe(AwsClientDetails clientDetails)
 {
     using (var helper = new SNSHelper(clientDetails))
     {
         SubscriptionArn = helper.Subscribe(TopicArn, Protocol, Endpoint);
         Log.LogMessage(MessageImportance.Normal, "Subscribed to Topic {0}, SubscriptionArn {1}", TopicArn, SubscriptionArn);
     }
 }
 private void CreateBucket(AwsClientDetails clientDetails)
 {
     using (var helper = new S3Helper(clientDetails))
     {
         helper.DeleteObject(BucketName, Key);
         Log.LogMessage(MessageImportance.High, "Deleted AWS S3 Object {0} from bucket {1} ", Key, BucketName);
     }
 }
 private void SendMessage(AwsClientDetails clientDetails)
 {
     using (var helper = new SQSHelper(clientDetails))
     {
         MessageId = helper.SendMessage(MessageBody, QueueUrl);
         Log.LogMessage(MessageImportance.Normal, "Sent message to Queue {0}", QueueUrl);
     }
 }
 private void CreateTopic(AwsClientDetails clientDetails)
 {
     using (var helper = new SNSHelper(clientDetails))
     {
         TopicArn = helper.CreateTopic(TopicName);
         Log.LogMessage(MessageImportance.Normal, "Created Sns TopicAssociated {0}, Topic Arn {1}", TopicName, TopicArn);
     }
 }
 private void SetAcl(AwsClientDetails clientDetails)
 {
     using (var helper = new S3Helper(clientDetails))
     {
         helper.SetAcl(BucketName, CannedAcl, Key);
         Log.LogMessage(MessageImportance.High, "Setting Acl {0} on object {0} in bucket {1}", CannedAcl, Key, BucketName);
     }
 }
 private void DeleteQueue(AwsClientDetails clientDetails)
 {
     using (var helper = new SQSHelper(clientDetails))
     {
         helper.DeleteQueue(QueueUrl);
         Log.LogMessage(MessageImportance.Normal, "Deleted SQS Queue at {0}", QueueUrl);
     }
 }
 private void CleanBucket(AwsClientDetails clientDetails)
 {
     using (var helper = new S3Helper(clientDetails))
     {
         helper.CleanBucket(BucketName);
         Log.LogMessage(MessageImportance.Normal, "Deleted all files on AWS S3 from bucket {0} ", BucketName);
     }
 }
 private void GetAttribute(AwsClientDetails clientDetails)
 {
     using (var helper = new SimpleDBHelper(clientDetails))
     {
         AttributeValue = helper.GetAttribute(DomainName, ItemName, AttributeName);
         Log.LogMessage(MessageImportance.Normal, "Read Attribute {0} for Item {1}", AttributeName, ItemName);
     }
 }
 private void CreateVolume(AwsClientDetails clientDetails)
 {
     using (var helper = new EC2Helper(clientDetails))
     {
         VolumeId = helper.CreateVolumeFromSnapshot(AvailabilityZone, SnapShotId);
         Log.LogMessage(MessageImportance.Normal, "Created volume {0} from SnapShot {1}", VolumeId, SnapShotId);
     }
 }
 private void DeleteDomain(AwsClientDetails clientDetails)
 {
     using (var helper = new SimpleDBHelper(clientDetails))
     {
         helper.DeleteDomain(DomainName);
         Log.LogMessage(MessageImportance.High, "Deleted SimpleDB Domain {0}", DomainName);
     }
 }
 private void PutAttribute(AwsClientDetails clientDetails)
 {
     using (var helper = new SimpleDBHelper(clientDetails))
     {
         helper.PutAttribute(DomainName, ItemName, AttributeName, Replace, AttributeValue);
         Log.LogMessage(MessageImportance.Normal, "Stored Attribute {0} for Item {1}", AttributeName, ItemName);
     }
 }
 private void DetachVolume(AwsClientDetails clientDetails)
 {
     using (var helper = new EC2Helper(clientDetails))
     {
         helper.DetachVolume(Device, InstanceId, VolumeId, Force);
         Log.LogMessage(MessageImportance.Normal, "Detached volume");
     }
 }
 private void GrantRights(AwsClientDetails clientDetails)
 {
     using (var helper = new SQSHelper(clientDetails))
     {
         helper.GrantSendMessageRights(QueueUrl, SourceArn);
         Log.LogMessage(MessageImportance.Normal, "Granted rights for source {0} to SendMessage to SQS at {1}", SourceArn, QueueUrl);
     }
 }
 private void AssociateIpAddress(AwsClientDetails clientDetails)
 {
     using (var helper = new EC2Helper(clientDetails))
     {
         helper.AssociateIpAddress(InstanceId, IpAddress);
         Log.LogMessage(MessageImportance.Normal, "Associated IP Address {0} with InstanceId {1}", IpAddress, InstanceId);
     }
 }
 private void CreateVolume(AwsClientDetails clientDetails)
 {
     using (var helper = new EC2Helper(clientDetails))
     {
         VolumeId = helper.CreateNewVolume(AvailabilityZone, Size);
         Log.LogMessage(MessageImportance.Normal, "Created volume of size {0}MiB with VolumeId {1}", Size, VolumeId);
     }
 }
 private void DeleteSnapShot(AwsClientDetails clientDetails)
 {
     using (var helper = new EC2Helper(clientDetails))
     {
         helper.DeleteSnapShot(SnapShotId);
         Log.LogMessage(MessageImportance.Normal, "Deleted SnapShot {0}", SnapShotId);
     }
 }
 private void DeleteBucket(AwsClientDetails clientDetails)
 {
     using (var helper = new S3Helper(clientDetails))
     {
         helper.DeleteBucket(BucketName);
         Log.LogMessage(MessageImportance.High, "Deleted S3 Bucket {0}", BucketName);
     }
 }
 private void DeleteAttributes(AwsClientDetails clientDetails)
 {
     using (var helper = new SimpleDBHelper(clientDetails))
     {
         helper.DeleteAttributes(DomainName, ItemName, AttributeNames);
         Log.LogMessage(MessageImportance.Normal, "Deleted Attributes {0} for Item {1}", Join(AttributeNames), ItemName);
     }
 }
 private void StartInstances(AwsClientDetails clientDetails)
 {
     using (var helper = new EC2Helper(clientDetails))
     {
         helper.StartInstances(InstanceIds);
         Log.LogMessage(MessageImportance.Normal, "Started Instances {0}", Join(InstanceIds));
     }
 }
 private void PublishNotifiation(AwsClientDetails clientDetails)
 {
     using (var helper = new SNSHelper(clientDetails))
     {
         MessageId = helper.Publish(TopicArn, Subject, Message);
         Log.LogMessage(MessageImportance.Normal, "Published SNS Notification {0}", Subject);
     }
 }
 private void PublishFiles(AwsClientDetails clientDetails)
 {
     using (var helper = new S3Helper(clientDetails))
     {
         helper.Publish(SourceFiles, DestinationBucket, DestinationFolder, PublicRead);
         Log.LogMessage(MessageImportance.Normal, "Published {0} files to S3", SourceFiles.Length);
     }
 }
 private void DeleteTopic(AwsClientDetails clientDetails)
 {
     using (var helper = new SNSHelper(clientDetails))
     {
         helper.DeleteTopic(TopicArn);
         Log.LogMessage(MessageImportance.Normal, "Deleted SNS Topic {0}", TopicArn);
     }
 }
 private void PutFileObject(AwsClientDetails clientDetails)
 {
     using (var helper = new S3Helper(clientDetails))
     {
         helper.PutFileObject(BucketName, Key, FileName);
         Log.LogMessage(MessageImportance.Normal, "Put file {0} into object {0} in bucket {1}", FileName, Key, BucketName);
     }
 }
 private void CreateBucket(AwsClientDetails clientDetails)
 {
     using (var helper = new S3Helper(clientDetails))
     {
         helper.CreateBucket(BucketName);
         Log.LogMessage(MessageImportance.Normal, "Created S3 Bucket {0}", BucketName);
     }
 }
 private void DownloadFile(AwsClientDetails clientDetails)
 {
     using (var helper = new S3Helper(clientDetails))
     {
         Log.LogMessage(MessageImportance.Normal, "Downloading Sourcefiles={0} to {1}", Join(FilesName), SavePath);
         helper.DownloadFile(BucketName, FilesName, SavePath, Version);
         //Log.LogMessage(MessageImportance.Normal, "Deleted all files on AWS S3 from bucket {0} ", BucketName);
     }
 }
        /// <summary>
        /// Save the Aws Client Details to the registry, encrypts the secret key in the process.
        /// </summary>
        /// <param name="containerName">Encryption container to use</param>
        /// <param name="clientDetails">Client details to store</param>
        public void Save(string containerName, AwsClientDetails clientDetails)
        {
            string encryptedKey = EncryptionHelper.Encrypt(containerName, clientDetails.AwsSecretAccessKey);

            CreateSubKeyIfNotExists();

            using (var registryKey = Registry.CurrentUser.OpenSubKey(RegistrySubKey, true))
            {
                if (registryKey == null)
                {
                    throw new ApplicationException("Failed to open registry key.");
                }

                registryKey.SetValue(AccessKeyIdKeyName, clientDetails.AwsAccessKeyId);
                registryKey.SetValue(SecretAccessKeyKeyName, encryptedKey);
            }
        }
Пример #33
0
        public override bool Execute()
        {
            Log.LogMessage(MessageImportance.Normal, "Storing AWS Client details");
            try
            {
                var clientDetails = new AwsClientDetails
                {
                    AwsAccessKeyId     = AwsAccessKeyId,
                    AwsSecretAccessKey = AwsSecretAccessKey
                };

                // TODO: Allow for dependency injection to facilitate testing.
                var store = new ClientDetailsStore();
                store.Save(EncryptionContainerName, clientDetails);

                return(true);
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex);
                return(false);
            }
        }