コード例 #1
0
        public void PutFileObjectTest()
        {
            // Get the client details from the stored client details (rather than embed secret keys in the test).
            // Ensure that your AWS/Secret keys have been stored before running.
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            S3Helper helper = new S3Helper(clientDetails);

            const string bucketName = "ExampleTestBucket";
            const string key = "ExampleObject";

            // Put a simple text object into the bucket to delete.
            helper.CreateBucket(bucketName);
            try
            {

                helper.PutFileObject(bucketName, key, @"C:\Temp\IMD.WebSite.zip");
            }
            catch (Exception ex)
            {

            }
            finally
            {
                //helper.DeleteObject(bucketName, key);
                //helper.DeleteBucket(bucketName);
            }
        }
コード例 #2
0
        public void DeleteObject_Should_Succeed()
        {
            // Get the client details from the stored client details (rather than embed secret keys in the test).
            // Ensure that your AWS/Secret keys have been stored before running.
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            S3Helper helper = new S3Helper(clientDetails);

            const string bucketName = "ExampleTestBucket";
            const string key = "ExampleObject";

            // Put a simple text object into the bucket to delete.
            helper.CreateBucket(bucketName);
            helper.PutTextObject(bucketName, key, "Example text to store in the object");

            try
            {
                helper.DeleteObject(bucketName, key);
            }
            finally
            {
                helper.DeleteBucket(bucketName);
            }
        }
コード例 #3
0
 protected virtual AwsClientDetails GetClientDetails()
 {
     var clientDetailsStore = new ClientDetailsStore();
     AwsClientDetails clientDetails = clientDetailsStore.Load(EncryptionContainerName);
     Log.LogMessage(MessageImportance.Normal, "Connecting to AWS using AwsAccessKeyId: {0}", clientDetails.AwsAccessKeyId);
     return clientDetails;
 }
コード例 #4
0
        public void AssociateIpAddressWithInstance_Should_Succeed()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            ec2Helper.AssociateIpAddress(DefaultInstanceId, DefaultIpAddress);
        }
コード例 #5
0
        public void CreateDomain_Should_Succeed()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SimpleDBHelper helper = new SimpleDBHelper(clientDetails);

            const string domainName = "TestDomain";
            helper.CreateDomain(domainName);
        }
コード例 #6
0
        public void DeleteBucket_Should_Succeed()
        {
            // Get the client details from the stored client details (rather than embed secret keys in the test).
            // Ensure that your AWS/Secret keys have been stored before running.
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            S3Helper helper = new S3Helper(clientDetails);

            helper.DeleteBucket("ExampleTestBucket");
        }
コード例 #7
0
        public void ListTopics_Should_ReturnTopics()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SNSHelper helper = new SNSHelper(clientDetails);

            string[] topics = helper.ListTopics("");

            Assert.AreEqual(2, topics.Length);
        }
コード例 #8
0
        public void CreateNewVolume_Should_CreateNewVolume()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            // Create a 2Gb volumne.
            string volumeId = ec2Helper.CreateNewVolume("us-east-1b", "2"); // "us-east-1b"

            Assert.IsNotEmpty(volumeId, "Expected VolumeId");
        }
コード例 #9
0
        public void CreateQueueTwice_Should_Succeed()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            string url1 = helper.CreateQueue("TestQ2");
            string url2 = helper.CreateQueue("TestQ2");

            Assert.AreEqual(url1, url2, "Url's should match");
        }
コード例 #10
0
        public void DeleteQueue_Should_DeleteQueue()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            // Qreate a queue to delete.
            string queueUrl = helper.CreateQueue("TestQ");

            helper.DeleteQueue(queueUrl);
        }
コード例 #11
0
        public void CreateTopicTwice_Should_Succeed_WithMatchingArns()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SNSHelper helper = new SNSHelper(clientDetails);

            string topicArn = helper.CreateTopic("TestTopic2");
            string topicArn2 = helper.CreateTopic("TestTopic2");

            Assert.AreEqual(topicArn, topicArn2, "Topic Arn's should match");
        }
コード例 #12
0
        public void Publish_Should_PublishANotification()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SNSHelper helper = new SNSHelper(clientDetails);

            const string topicArn = "arn:aws:sns:us-east-1:167532394791:TestTopic";

            string messageId = helper.Publish(topicArn, "Test", "This is a test of Publish...");

            Assert.IsNotEmpty(messageId);
        }
コード例 #13
0
        public void CreateTopic_Should_CreateTopic()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SNSHelper helper = new SNSHelper(clientDetails);

            string topicId = helper.CreateTopic("TestTopic");

            System.Diagnostics.Debug.WriteLine("Topic Id: " + topicId);

            Assert.IsNotEmpty(topicId);
        }
コード例 #14
0
        public void AttachVolumeToInstance_Should_AttachVolume()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            const string device = "xvdf";
            const string volumeId = "vol-6bd56a02";
            const string instanceId = "i-6de0a406";

            ec2Helper.AttachVolume(device, instanceId, volumeId);
        }
コード例 #15
0
        public void CreateQueue_Should_CreateQueue()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            string queueUrl = helper.CreateQueue("TestQ");

            System.Diagnostics.Debug.WriteLine(queueUrl, "queueUrl:");

            Assert.IsNotEmpty(queueUrl);
        }
コード例 #16
0
        public void CreateSnapShotFromVolume_Should_CreateSnapShot()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            const string volumeId = "vol-d1e15eb8";
            const string description = "Test SnapShot";

            // Create a 2Gb volumne.
            string snapShotId = ec2Helper.CreateSnapShot(volumeId, description);

            Assert.IsNotEmpty(snapShotId, "Expected SnapShot Id");
        }
コード例 #17
0
        public void SaveAndLoadClientDetails_AreCorrectlyStored()
        {
            const string containerName = "S3BuildPublisher.TestContainer.ClientDetailsStore";
            var clientDetails = new AwsClientDetails
                                    {
                                        AwsAccessKeyId = "AwsAccessKeyId",
                                        AwsSecretAccessKey = "AwsSecretAccessKey"
                                    };

            var store = new ClientDetailsStore(DefaultTestRegistrySubKey);

            store.Save(containerName, clientDetails);

            AwsClientDetails actual = store.Load(containerName);

            Assert.AreEqual(clientDetails.AwsAccessKeyId, actual.AwsAccessKeyId, "AwsAccessKeyId");
            Assert.AreEqual(clientDetails.AwsSecretAccessKey, actual.AwsSecretAccessKey, "AwsSecretAccessKey");
        }
コード例 #18
0
        public void DeleteAttributes_Should_Succeed()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SimpleDBHelper helper = new SimpleDBHelper(clientDetails);

            const string domainName = "TestDomain";
            const string itemName = "TesItem";
            const string attributeName = "attributeName";
            string expectedValue = DateTime.Now.ToLongTimeString();

            // Ensure the domain exists and store the test item.
            helper.CreateDomain(domainName);
            helper.PutAttribute(domainName, itemName, attributeName, true, expectedValue);

            helper.DeleteAttributes(domainName, itemName, new [] { attributeName });
        }
コード例 #19
0
        public void TestAddPermission_Sets_PermissionsOnTopic()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SNSHelper helper = new SNSHelper(clientDetails);
            string topicArn = helper.CreateTopic("TestSetPermissionsTopic");

            // TODO: Replace this with a valid AWS account Id.
            string[] awsAccountIds = new[] { "123456789012" };
            string[] actionNames = new[] { "*" };
            const string label = "Test Topic Permissions";

            // There appears to be an issue with the AWS SDK 1.0.8.1 which failes validation
            // for action names and aws account ids whilst they are valid.
            helper.AddPermission(actionNames, awsAccountIds, label, topicArn);

            // Now clean up and delete the topic.
            helper.DeleteTopic(topicArn);
        }
コード例 #20
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;
            }
        }
コード例 #21
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);
            }
        }
コード例 #22
0
        public void ReceiveMessage_Should_ReceiveMessageAndNotRemoveIt()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            string queueUrl = helper.CreateQueue("TestQ");

            // Add a message to the queue to ensure that their is one and wait for 2 seconds to allow
            // the message to propogate.
            // Add the time on to ensure the correct message is received.
            string expectedMessage = "Sample test message " + DateTime.Now.ToLongTimeString();
            helper.SendMessage(expectedMessage, queueUrl);

            // Messages can be very slow to appear on the queue.
            Thread.Sleep(60000);

            // Get the sent message.
            Amazon.SQS.Model.Message message = helper.ReceiveMessage(queueUrl);
            Assert.IsNotNull(message, "No messages");

            try
            {
                Assert.AreEqual(expectedMessage, message.Body, "Expected message body first time");

                // Ensure that we can get the message a second time.
                Amazon.SQS.Model.Message message2 = helper.ReceiveMessage(queueUrl);
                Assert.IsNotNull(message2, "Message should not have been removed.");
                Assert.AreEqual(expectedMessage, message2.Body, "Expected message body second time");
            }
            finally
            {
                // Delete the message.
                helper.DeleteMessage(queueUrl, message.ReceiptHandle);
            }
        }
コード例 #23
0
        public void PutAttrubute_Should_Succeed()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SimpleDBHelper helper = new SimpleDBHelper(clientDetails);

            const string domainName = "TestDomain";
            const string itemName = "TesItem";
            const string name = "attributeName";
            const bool replace = true;
            string value = DateTime.Now.ToLongTimeString();

            helper.PutAttribute(domainName, itemName, name, replace, value);
        }
コード例 #24
0
        public void GetUnknownAttribute_Should_ReturnEmptyString()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SimpleDBHelper helper = new SimpleDBHelper(clientDetails);

            const string domainName = "TestDomain";
            const string itemName = "TesItem";
            const string attributeName = "UnknownAttributeThatDoesntExist";
            string expectedValue = string.Empty;

            // Ensure the domain exists and store the test item.
            helper.CreateDomain(domainName);

            string actualValue = helper.GetAttribute(domainName, itemName, attributeName);

            Assert.AreEqual(expectedValue, actualValue);
        }
コード例 #25
0
        public void RunInstance_Should_RunInstance()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            // Modify these to match your own AWS settings.
            const string ami = "ami-bfab42d6";
            const string keyPair = "BookSwapPair1";
            const string securityGroup = "Basic";
            const string userData = "";
            const string availabilityZone = "us-east-1a";

            List<string> instances = ec2Helper.RunInstance(ami, 1, keyPair, userData, new string[] { securityGroup }, availabilityZone);

            Assert.IsNotEmpty(instances);
        }
コード例 #26
0
        public void StopInstances_Should_Stop_Instance()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            ec2Helper.StopInstances(new string[] { DefaultInstanceId });
        }
コード例 #27
0
        public void SendMessage_Should_ReturnMessageId()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            const string messageBody = "TestMessageBody";
            string queueUrl = helper.CreateQueue("TestQ");

            string messageId = helper.SendMessage(messageBody, queueUrl);

            Assert.IsNotEmpty(messageId);
        }
コード例 #28
0
        public void CreateVolumeFromSnapShot_Should_CreateNewVolume()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            const string availabilityZone = "us-east-1b";
            const string snapShotId = "snap-422c832a";

            // Create a 2Gb volumne.
            string volumeId = ec2Helper.CreateVolumeFromSnapshot(availabilityZone, snapShotId);

            Assert.IsNotEmpty(volumeId, "Expected VolumeId");
        }
コード例 #29
0
        public void StartInstances_Should_Start_Instance()
        {
            // Get the client details from the stored client details (rather than embed secret keys in the test).
            // Ensure that your AWS/Secret keys have been stored before running.
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            ec2Helper.StartInstances(new string[] { DefaultInstanceId });
        }
コード例 #30
0
        public void WaitForMessage_Should_ThrowTimeoutException()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            string queueUrl = helper.CreateQueue("TestQ");

            // Get the sent message.
            helper.WaitForMessage(queueUrl, 10, 5);
        }
コード例 #31
0
        public void TerminateInstnace_Should_TerminateInstance()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            // TODO: this instanceId will change based on the Run Instance test.
            ec2Helper.TerminateInstance(new string[] { "i-6503450e" });
        }