Esempio n. 1
0
        public static GetObjectResponse GetFile(AwsCommonParams commonParams,
            string bucketName, string filePath)
        {
            // We need to strip off any leading '/' in the path or
            // else it creates a path with an empty leading segment
            // This also implements behavior consistent with the
            // edit counterpart routine for verification purposes
            if (filePath.StartsWith("/"))
                filePath = filePath.Substring(1);

            using (var s3 = new Amazon.S3.AmazonS3Client(
                commonParams.ResolveCredentials(),
                commonParams.RegionEndpoint))
            {
                var s3Requ = new Amazon.S3.Model.GetObjectRequest
                {
                    BucketName = bucketName,
                    //Prefix = filePath,
                    Key = filePath,
                };

                //var s3Resp = s3.ListObjects(s3Requ);
                try
                {
                    var s3Resp = s3.GetObject(s3Requ);

                    return s3Resp;
                }
                catch (AmazonS3Exception ex)
                    when (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    return null;
                }
            }
        }
Esempio n. 2
0
        public void TestHandlerUploadAndCleanUpObject()
        {
            var r  = new Random();
            var bn = new byte[10];
            var bv = new byte[10];

            r.NextBytes(bn);
            r.NextBytes(bv);
            var rn = BitConverter.ToString(bn);
            var rv = BitConverter.ToString(bv);

            var c = new HttpChallenge(AcmeProtocol.CHALLENGE_TYPE_HTTP, new HttpChallengeAnswer())
            {
                Token       = "FOOBAR",
                FileUrl     = $"http://foobar.acmetesting.zyborg.io/utest/{rn}",
                FilePath    = $"/utest/{rn}",
                FileContent = rv,
            };

            var awsParams = new AwsCommonParams();

            awsParams.InitParams(_handlerParams);

            var p = GetProvider();

            using (var h = p.GetHandler(c, _handlerParams))
            {
                // Assert test file does not exist
                var s3Obj = AwsS3ChallengeHandler.GetFile(awsParams,
                                                          _handlerParams.BucketName, c.FilePath);

                // Assert test record does *not* exist
                Assert.IsNull(s3Obj);

                // Create the record...
                h.Handle(c);

                // ...and assert it does exist
                s3Obj = AwsS3ChallengeHandler.GetFile(awsParams,
                                                      _handlerParams.BucketName, c.FilePath);

                Assert.IsNotNull(s3Obj);
                using (var sr = new StreamReader(s3Obj.ResponseStream))
                {
                    var v = sr.ReadToEnd();
                    Assert.AreEqual(c.FileContent, v);
                }

                // Clean up the record...
                h.CleanUp(c);

                // ...and assert it does not exist once more
                s3Obj = AwsS3ChallengeHandler.GetFile(awsParams,
                                                      _handlerParams.BucketName, c.FilePath);

                Assert.IsNull(s3Obj);
            }
        }
Esempio n. 3
0
        public void TestHandleCreateAndCleanUpFiles()
        {
            var r = new Random();
            var bn = new byte[10];
            var bv = new byte[10];
            r.NextBytes(bn);
            r.NextBytes(bv);
            var rn = BitConverter.ToString(bn);
            var rv = BitConverter.ToString(bv);

            var c = new HttpChallenge(AcmeProtocol.CHALLENGE_TYPE_HTTP, new HttpChallengeAnswer())
            {
                Token = "FOOBAR",
                FileUrl = $"http://foobar.acmetesting.zyborg.io/utest/{rn}",
                FilePath = $"utest/{rn}",
                FileContent = rv,
            };

            var awsParams = new AwsCommonParams();
            awsParams.InitParams(_handlerParams);

            var p = GetProvider();
            using (var h = p.GetHandler(c, _handlerParams))
            {
                var sites = IisChallengeHandler.ListHttpWebSites();
                Assert.IsNotNull(sites);
                var site = sites.First(x => x.SiteName == _handlerParams.WebSiteRef);
                Assert.IsNotNull(site);

                var fullPath = Environment.ExpandEnvironmentVariables(
                        Path.Combine(site.SiteRoot, c.FilePath));

                // Assert test file does not exist
                Assert.IsFalse(File.Exists(fullPath));

                // Create the record...
                h.Handle(c);

                // ...and assert it does exist
                Assert.IsTrue(File.Exists(fullPath));
                Assert.AreEqual(c.FileContent, File.ReadAllText(fullPath));

                // Clean up the record...
                h.CleanUp(c);

                // ...and assert it does not exist once more
                Assert.IsFalse(File.Exists(fullPath));
            }
        }
        public static IEnumerable<ServerCertificateMetadata> GetServerCertificates(AwsCommonParams commonParams)
        {
            using (var client = new AmazonIdentityManagementServiceClient(
                commonParams.ResolveCredentials(),
                commonParams.RegionEndpoint))
            {
                var iamRequ = new ListServerCertificatesRequest();

                do
                {
                    var iamResp = client.ListServerCertificates(iamRequ);
                    foreach (var r in iamResp.ServerCertificateMetadataList)
                        yield return r;

                    iamRequ.Marker = iamResp.Marker;
                    if (!iamResp.IsTruncated)
                        iamRequ = null;
                } while (iamRequ != null);
            }
        }
Esempio n. 5
0
        public static GetObjectResponse GetFile(AwsCommonParams commonParams,
                                                string bucketName, string filePath)
        {
            // We need to strip off any leading '/' in the path or
            // else it creates a path with an empty leading segment
            // This also implements behavior consistent with the
            // edit counterpart routine for verification purposes
            if (filePath.StartsWith("/"))
            {
                filePath = filePath.Substring(1);
            }

            using (var s3 = new Amazon.S3.AmazonS3Client(
                       commonParams.ResolveCredentials(),
                       commonParams.RegionEndpoint))
            {
                var s3Requ = new Amazon.S3.Model.GetObjectRequest
                {
                    BucketName = bucketName,
                    //Prefix = filePath,
                    Key = filePath,
                };

                //var s3Resp = s3.ListObjects(s3Requ);
                try
                {
                    var s3Resp = s3.GetObject(s3Requ);

                    return(s3Resp);
                }
                catch (AmazonS3Exception ex)
                    when(ex.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(null);
                    }
            }
        }
Esempio n. 6
0
        public static IEnumerable <ServerCertificateMetadata> GetServerCertificates(AwsCommonParams commonParams)
        {
            using (var client = new AmazonIdentityManagementServiceClient(
                       commonParams.ResolveCredentials(),
                       commonParams.RegionEndpoint))
            {
                var iamRequ = new ListServerCertificatesRequest();

                do
                {
                    var iamResp = client.ListServerCertificates(iamRequ);
                    foreach (var r in iamResp.ServerCertificateMetadataList)
                    {
                        yield return(r);
                    }

                    iamRequ.Marker = iamResp.Marker;
                    if (!iamResp.IsTruncated)
                    {
                        iamRequ = null;
                    }
                } while (iamRequ != null);
            }
        }
Esempio n. 7
0
        public void TestHandlerUploadAndCleanUpObject()
        {
            var r = new Random();
            var bn = new byte[10];
            var bv = new byte[10];
            r.NextBytes(bn);
            r.NextBytes(bv);
            var rn = BitConverter.ToString(bn);
            var rv = BitConverter.ToString(bv);

            var c = new HttpChallenge(AcmeProtocol.CHALLENGE_TYPE_HTTP, new HttpChallengeAnswer())
            {
                Token = "FOOBAR",
                FileUrl = $"http://foobar.acmetesting.zyborg.io/utest/{rn}",
                FilePath = $"/utest/{rn}",
                FileContent = rv,
            };

            var awsParams = new AwsCommonParams();
            awsParams.InitParams(_handlerParams);

            var p = GetProvider();
            using (var h = p.GetHandler(c, _handlerParams))
            {
                // Assert test file does not exist
                var s3Obj = AwsS3ChallengeHandler.GetFile(awsParams,
                        _handlerParams.BucketName, c.FilePath);
                
                // Assert test record does *not* exist
                Assert.IsNull(s3Obj);

                // Create the record...
                h.Handle(c);

                // ...and assert it does exist
                s3Obj = AwsS3ChallengeHandler.GetFile(awsParams,
                        _handlerParams.BucketName, c.FilePath);

                Assert.IsNotNull(s3Obj);
                using (var sr = new StreamReader(s3Obj.ResponseStream))
                {
                    var v = sr.ReadToEnd();
                    Assert.AreEqual(c.FileContent, v);
                }

                // Clean up the record...
                h.CleanUp(c);

                // ...and assert it does not exist once more
                s3Obj = AwsS3ChallengeHandler.GetFile(awsParams,
                        _handlerParams.BucketName, c.FilePath);

                Assert.IsNull(s3Obj);
            }
        }