virtual protected AwsClientDetails GetClientDetails()
        {
            if (string.IsNullOrEmpty(EncryptionContainerName))
            {
                throw new Exception("EncryptionContainerName not set");
            }

            var clientDetailsStore         = new ClientDetailsStore();
            AwsClientDetails clientDetails = clientDetailsStore.Load(EncryptionContainerName);

            clientDetails.AmazonS3Config = new AmazonS3Config();
            var http = Amazon.S3.Model.Protocol.HTTP.ToString();

            switch (Protocol.ToUpper())
            {
            case "HTTP": clientDetails.AmazonS3Config.CommunicationProtocol = Amazon.S3.Model.Protocol.HTTP;
                break;

            default:
                clientDetails.AmazonS3Config.CommunicationProtocol = Amazon.S3.Model.Protocol.HTTPS;
                break;
            }
            Logger.LogMessage(MessageImportance.Normal, "Connecting to AWS using AwsAccessKeyId: {0}", clientDetails.AwsAccessKeyId);
            return(clientDetails);
        }
Beispiel #2
0
        public void SetAcl_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.SetAcl(bucketName, "AuthenticatedRead", key);
            }
            finally
            {
                helper.DeleteObject(bucketName, key);
                helper.DeleteBucket(bucketName);
            }
        }
Beispiel #3
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);
            }
        }
        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 });
        }
        public void AssociateIpAddressWithInstance_Should_Succeed()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            ec2Helper.AssociateIpAddress(DefaultInstanceId, DefaultIpAddress);
        }
        public void Reboot_Should_RebootInstance()
        {
            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.RebootInstance(new string[] { "i-4501472e" });
        }
        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" });
        }
        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 });
        }
        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);
        }
        public void DeleteSnapShot_Should_DeleteSnapShot()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            const string snapShotId = "snap-422c832a";

            ec2Helper.DeleteSnapShot(snapShotId);
        }
Beispiel #11
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");
        }
        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);
        }
        public void DeleteVolume_Should_DeleteVolume()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            const string volumeId = "vol-d1e15eb8";

            // Delete the volume
            ec2Helper.DeleteVolume(volumeId);
        }
        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");
        }
        public void TestUnSubscribe_Doesnt_Fail()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SNSHelper helper = new SNSHelper(clientDetails);

            // TODO: Replace this with the valid subscription Arn
            const string subscriptionArn = "arn:aws:sns:us-east-1:167532394791:TestTopic:37be7a47-7e3f-418f-961e-2ef68af1749c";

            helper.Unsubscribe(subscriptionArn);
        }
        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");
        }
        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);
        }
        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);
        }
Beispiel #19
0
        virtual protected AwsClientDetails GetClientDetails()
        {
            if (string.IsNullOrEmpty(EncryptionContainerName))
            {
                throw new Exception("EncryptionContainerName not set");
            }

            var clientDetailsStore         = new ClientDetailsStore();
            AwsClientDetails clientDetails = clientDetailsStore.Load(EncryptionContainerName);

            Logger.LogMessage(MessageImportance.Normal, "Connecting to AWS using AwsAccessKeyId: {0}", clientDetails.AwsAccessKeyId);
            return(clientDetails);
        }
        public void DetachVolume_Should_DetachVolume()
        {
            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.DetachVolume(device, instanceId, volumeId, true);
        }
        public void DescribeInstance_Should_ReturnInstanceDetails()
        {
            // NB: This test requires an EC2 Instance to succeed.
            const string instanceId = "i-6de0a406";

            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            EC2Helper ec2Helper = new EC2Helper(clientDetails);

            Amazon.EC2.Model.RunningInstance instance = ec2Helper.DescribeInstance(instanceId);

            Assert.IsNotNull(instance, "No instance");
        }
        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");
        }
        public void TestSubscrive_Should_Subscribe()
        {
            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";
            const string protocol = "email";
            const string endpoint = "*****@*****.**";

            string subscriptionArn = helper.Subscribe(topicArn, protocol, endpoint);

            Assert.IsNotEmpty(subscriptionArn);
        }
        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);
        }
        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");
        }
        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");
        }
        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 });
        }
        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);
        }
        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);
        }
        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);
        }