Ejemplo n.º 1
0
        public void UriParserAwsPathStyleUri()
        {
            Uri s3 = new Uri("https://s3.us-west-2.amazonaws.com/mybucket/puppy.jpg");

            Assert.Equal("s3.us-west-2.amazonaws.com", s3.Host);
            Assert.Equal("mybucket", S3UriParser.GetBucketName(s3));
            Assert.Equal("puppy.jpg", S3UriParser.GetKey(s3));
        }
Ejemplo n.º 2
0
        public void UriParserGenericS3WithSlash()
        {
            Uri s3 = new Uri("s3://processing_results/");

            Assert.Equal("", s3.Host);
            Assert.Equal("processing_results", S3UriParser.GetBucketName(s3));
            Assert.Equal("", S3UriParser.GetKey(s3));
        }
Ejemplo n.º 3
0
        public void UriParserAwsVirtualHostUri()
        {
            Uri s3 = new Uri("https://my-bucket.s3.us-west-2.amazonaws.com/puppy.png");

            Assert.Equal("my-bucket.s3.us-west-2.amazonaws.com", s3.Host);
            Assert.Equal("my-bucket", S3UriParser.GetBucketName(s3));
            Assert.Equal("puppy.png", S3UriParser.GetKey(s3));
        }
Ejemplo n.º 4
0
        public void UriParserOpenStackS3()
        {
            Uri s3 = new Uri("s3://user1:processing_results/test");

            Assert.Equal("", s3.Host);
            Assert.Equal("", s3.LocalPath);
            Assert.Equal("user1:processing_results/test", s3.AbsolutePath);
            Assert.Equal("user1:processing_results", S3UriParser.GetBucketName(s3));
            Assert.Equal("test", S3UriParser.GetKey(s3));
            var s3f = new Uri(s3, "file.jpg");

            Assert.Equal("user1:processing_results/file.jpg", s3f.AbsolutePath);
        }
Ejemplo n.º 5
0
        public void UriParserGenericS3_3()
        {
            Uri s3 = new Uri("s3://processing_results/test/file.png");

            Assert.Equal("", s3.Host);
            Assert.Equal("", s3.LocalPath);
            Assert.Equal("processing_results/test/file.png", s3.AbsolutePath);
            Assert.Equal("processing_results", S3UriParser.GetBucketName(s3));
            Assert.Equal("test/file.png", S3UriParser.GetKey(s3));
            var s3f = new Uri(s3, "file.jpg");

            Assert.Equal("processing_results/test/file.jpg", s3f.AbsolutePath);
            s3f = new Uri(s3, "/file.jpg");
            Assert.Equal("processing_results/file.jpg", s3f.AbsolutePath);
        }
Ejemplo n.º 6
0
        public IDestination To(IResource subroute, string relPathFix = null)
        {
            // we first integrate the relPath
            string relPath = relPathFix ?? "";

            // we identify the filename
            string filename = Path.GetFileName(subroute.Uri.IsAbsoluteUri ? subroute.Uri.LocalPath : subroute.Uri.ToString());

            if (subroute.ContentDisposition != null && !string.IsNullOrEmpty(subroute.ContentDisposition.FileName))
            {
                filename = subroute.ContentDisposition.FileName;
            }

            // if the relPath requested is null, we will build one from the origin route to the new one
            if (relPathFix == null)
            {
                if (subroute.Uri.IsAbsoluteUri)
                {
                    // Let's see if the 2 routes are relative
                    var relUri = Uri.MakeRelativeUri(subroute.Uri);
                    // If not, let's see if they have a common pattern
                    if (relUri.IsAbsoluteUri)
                    {
                        if (!string.IsNullOrEmpty(Path.GetDirectoryName(subroute.Uri.AbsolutePath)) &&
                            !string.IsNullOrEmpty(Path.GetDirectoryName(Uri.AbsolutePath)) &&
                            Path.GetDirectoryName(subroute.Uri.AbsolutePath).StartsWith(Path.GetDirectoryName(Uri.AbsolutePath)))
                        {
                            relPath = Path.GetDirectoryName(subroute.Uri.AbsolutePath).Replace(Path.GetDirectoryName(Uri.AbsolutePath), "");
                        }
                    }
                    else
                    {
                        relPath = Path.GetDirectoryName(relUri.ToString());
                    }
                }
                else
                {
                    relPath = Path.GetDirectoryName(subroute.Uri.ToString());
                }
            }
            var newFilePath = Path.Join(relPath, filename);
            Uri newUri      = new Uri(string.Format("s3://" + Path.Join(
                                                        S3UriParser.GetBucketName(s3Uri),
                                                        Path.GetDirectoryName(S3UriParser.GetKey(s3Uri)),
                                                        newFilePath)));

            return(new S3ObjectDestination(newUri, subroute));
        }
Ejemplo n.º 7
0
        public void UriParserGenericS3_2()
        {
            Uri s3 = new Uri("s3://processing_results/test");

            Assert.Equal("", s3.Host);
            Assert.Equal("", s3.LocalPath);
            Assert.Equal("processing_results/test", s3.AbsolutePath);
            Assert.Equal(-1, s3.Port);
            Assert.Equal("", s3.Authority);
            Assert.Equal("", s3.DnsSafeHost);
            Assert.Equal(true, s3.IsAbsoluteUri);
            Assert.Equal("processing_results", S3UriParser.GetBucketName(s3));
            Assert.Equal("test", S3UriParser.GetKey(s3));
            var s3f = new Uri(s3, "file.jpg");

            Assert.Equal("processing_results/file.jpg", s3f.AbsolutePath);
        }