static void TestDecryptedS3(EncryptionMaterials encryptionMaterials)
        {
            string bucket_Name = null;
            AmazonS3EncryptionClient s3Client = new AmazonS3EncryptionClient(encryptionMaterials);

            bucket_Name = TdwUtils.rootBucketName + "encrypted-content";
            bucket_Name = TdwUtils.CreateBucket(s3Client, bucket_Name);

            GetObjectRequest getObjectRequest = new GetObjectRequest
            {
                BucketName = bucket_Name,
                Key        = TdwUtils.keyName
            };

            string data = null;

            using (GetObjectResponse getObjectResponse = s3Client.GetObject(getObjectRequest))
            {
                using (var stream = getObjectResponse.ResponseStream)
                    using (var reader = new StreamReader(stream))
                    {
                        data = reader.ReadToEnd();
                    }
                Console.WriteLine("===============>TestDecryptedS3 START<===============");
                Console.WriteLine("Encryption method was:");
                Console.WriteLine(getObjectResponse.ServerSideEncryptionMethod);
                Console.WriteLine("===============> <===============");
            }
            Console.WriteLine(data);
            Console.WriteLine("===============>TestDecryptedS3 END<===============");
        }
        static void TestEncryptedS3(EncryptionMaterials encryptionMaterials)
        {
            string bucket_Name = null;
            AmazonS3EncryptionClient s3Client = new AmazonS3EncryptionClient(encryptionMaterials);

            bucket_Name = TdwUtils.rootBucketName + "encrypted-content";
            try
            {
                AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucket_Name);
            }
            catch (Exception ex)
            {
                ex = null;
            }
            bucket_Name = TdwUtils.CreateBucket(s3Client, bucket_Name);

            string dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPath);

            byte[]           dataBytes = TdwUtils.FileToArray(dataPath);
            PutObjectRequest request   = new PutObjectRequest()
            {
                BucketName  = bucket_Name,
                Key         = TdwUtils.keyName,
                InputStream = new MemoryStream(dataBytes)
            };

            PutObjectResponse response = s3Client.PutObject(request);

            Console.WriteLine("===============>TestEncryptedS3 START<===============");
            Console.WriteLine("Encryption method was:");
            Console.WriteLine(response.ServerSideEncryptionMethod);
            Console.WriteLine("===============>TestEncryptedS3 END<===============");
        }
Exemplo n.º 3
0
        static void TestParentChildTemplates()
        {
            string bucket_Name  = QSS3BucketName;
            string templateName = QSS3KeyPrefix + TdwUtils.cfClassPathParentSubnet.Replace("tdw_cf_template\\", "");
            string stack_name   = templateName.Replace("-", "");

            stack_name = stack_name.Replace(".template", "");
            string dataPath = null;

            byte[]            dataBytes = null;
            PutObjectRequest  request   = null;
            PutObjectResponse response  = null;
            AmazonS3Client    s3Client  = new AmazonS3Client();

            bucket_Name = TdwUtils.CreateBucket(s3Client, QSS3BucketName);

            GetObjectRequest getObjectRequest = new GetObjectRequest
            {
                BucketName = bucket_Name,
                Key        = templateName,
            };

            string data = null;

            using (GetObjectResponse getObjectResponse = s3Client.GetObject(getObjectRequest))
            {
                using (var stream = getObjectResponse.ResponseStream)
                    using (var reader = new StreamReader(stream))
                    {
                        data = reader.ReadToEnd();
                    }
            }

            Amazon.CloudFormation.AmazonCloudFormationClient cfClient = new AmazonCloudFormationClient();

            try
            {
                DeleteStackRequest deleteRequest = new DeleteStackRequest()
                {
                    StackName = stack_name
                };
                cfClient.DeleteStack(deleteRequest);
            }
            catch (Exception ex)
            {
                ex = null;
            }

            List <string> CfCapabilities = new List <string>();

            CfCapabilities.Add("CAPABILITY_IAM");
            CreateStackRequest stackRequest = new CreateStackRequest()
            {
                StackName = stack_name, TemplateBody = data, Capabilities = CfCapabilities
            };
            CreateStackResponse stackResponse = cfClient.CreateStack(stackRequest);
        }
Exemplo n.º 4
0
        static void CopyTemplatesToS3(EncryptionMaterials encryptionMaterials)
        {
            string bucket_Name = null;
            string dataPath    = null;

            byte[]            dataBytes = null;
            PutObjectRequest  request   = null;
            PutObjectResponse response  = null;
            //AmazonS3EncryptionClient s3Client = new AmazonS3EncryptionClient(encryptionMaterials);
            AmazonS3Client s3Client = new AmazonS3Client();

            try
            {
                TdwUtils.TearDownS3BucketByPrefix(s3Client, "tdwcftdev");
                AmazonS3Util.DeleteS3BucketWithObjects(s3Client, QSS3BucketName);
            }
            catch (Exception ex)
            {
                ex = null;
            }
            bucket_Name = TdwUtils.CreateBucket(s3Client, QSS3BucketName);

            ///Cross stack communication, Parent
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathParentSubnet);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathParentSubnet.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///Cross stack communication, first child
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathChildSubnetProducer);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathChildSubnetProducer.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///Cross stack communication, second child
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathChildSubnet);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathChildSubnet.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///Application Template
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathApplication);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathApplication.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            //Config Rules
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathConfigRules);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathConfigRules.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///Iam Template
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathIam);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathIam.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            //Kinesis
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathKinesis);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathKinesis.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///Logging Template
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathLogging);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathLogging.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///Main Bastion Template
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathBastion);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathBastion.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///Management Vpc Template
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathManagementVpc);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathManagementVpc.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///Prod Vpc Template
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathProductionVpc);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathProductionVpc.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);

            ///ChangeSet Template for main bastion
            dataPath  = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathBastionChangeSet);
            dataBytes = TdwUtils.FileToArray(dataPath);
            request   = new PutObjectRequest()
            {
                BucketName  = QSS3BucketName,
                Key         = QSS3KeyPrefix + TdwUtils.cfClassPathBastionChangeSet.Replace("tdw_cf_template\\", ""),
                InputStream = new MemoryStream(dataBytes)
            };
            response = s3Client.PutObject(request);
        }