Exemple #1
0
        /// <inheritdoc/>
        public bool DoesBucketExist(string bucketName)
        {
            if (string.IsNullOrEmpty(bucketName))
            {
                throw new ArgumentException(Resources.ExceptionIfArgumentStringIsNullOrEmpty, "bucketName");
            }
            if (!OssUtils.IsBucketNameValid(bucketName))
            {
                throw new ArgumentException(Resources.BucketNameInvalid, "bucketName");
            }

            try
            {
                GetBucketAcl(bucketName);
            }
            catch (OssException e)
            {
                if (e.ErrorCode.Equals(OssErrorCode.NoSuchBucket))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
 internal ObjectListing(string bucketName)
 {
     if (string.IsNullOrEmpty(bucketName))
     {
         throw new ArgumentException(OssResources.ExceptionIfArgumentStringIsNullOrEmpty, "bucketName");
     }
     if (!OssUtils.IsBucketNameValid(bucketName))
     {
         throw new ArgumentException(OssResources.BucketNameInvalid, "bucketName");
     }
     this.BucketName = bucketName;
 }
 public GetObjectRequest(string bucketName, string key)
 {
     if (string.IsNullOrEmpty(bucketName))
     {
         throw new ArgumentException(OssResources.ExceptionIfArgumentStringIsNullOrEmpty, "bucketName");
     }
     if (string.IsNullOrEmpty(key))
     {
         throw new ArgumentException(OssResources.ExceptionIfArgumentStringIsNullOrEmpty, "key");
     }
     if (!OssUtils.IsBucketNameValid(bucketName))
     {
         throw new ArgumentException(OssResources.BucketNameInvalid, "bucketName");
     }
     if (!OssUtils.IsObjectKeyValid(key))
     {
         throw new ArgumentException(OssResources.ObjectKeyInvalid, "key");
     }
     this.BucketName = bucketName;
     this.Key        = key;
 }
        public OssHttpRequestMessage(Uri endpoint, string bucketName, string key, IDictionary <string, string> _parameters = null)
        {
            if (bucketName != NONEEDBUKETNAME)
            {
                if (string.IsNullOrEmpty(bucketName))
                {
                    throw new ArgumentException(OssResources.ExceptionIfArgumentStringIsNullOrEmpty, "bucketName");
                }

                if (!string.IsNullOrEmpty(bucketName) && !OssUtils.IsBucketNameValid(bucketName))
                {
                    throw new ArgumentException(OssResources.BucketNameInvalid, "bucketName");
                }
            }
            else
            {
                bucketName = "";
            }
            Endpoint        = endpoint;
            ResourcePath    = "/" + ((bucketName != null) ? bucketName : "") + ((key != null) ? ("/" + key) : "");
            ResourcePathUrl = OssUtils.MakeResourcePath(bucketName, key);
            parameters      = _parameters;
            RequestUri      = new Uri(BuildRequestUri());
        }
        public void OssUtilsTest()
        {
            var conf = new ClientConfiguration();

            Assert.AreEqual(OssUtils.IsBucketNameValid(""), false);

            var str = OssUtils.MakeResourcePath(new Uri("http://192.168.1.1"), "bucket", "key/abc/");

            Assert.AreEqual(str, "bucket/key/abc/");

            //cname
            conf.IsCname = true;
            var uri = OssUtils.MakeBucketEndpoint(new Uri("http://endpoint"), "bucket", conf);

            Assert.AreEqual(uri.ToString(), "http://endpoint/");

            //ip endpoint & endpoint port
            conf.IsCname = false;
            uri          = OssUtils.MakeBucketEndpoint(new Uri("http://192.168.1.1"), "bucket", conf);
            Assert.AreEqual(uri.ToString(), "http://192.168.1.1/");

            uri = OssUtils.MakeBucketEndpoint(new Uri("http://192.168.1.1:3128"), "bucket", conf);
            Assert.AreEqual(uri.ToString(), "http://192.168.1.1:3128/");

            //bucket
            conf.IsCname = false;
            uri          = OssUtils.MakeBucketEndpoint(new Uri("http://endpoint"), null, conf);
            Assert.AreEqual(uri.ToString(), "http://endpoint/");

            conf.IsCname = false;
            uri          = OssUtils.MakeBucketEndpoint(new Uri("http://endpoint"), "bucket", conf);
            Assert.AreEqual(uri.ToString(), "http://bucket.endpoint/");

            //TrimQuotes
            Assert.AreEqual(OssUtils.TrimQuotes("\"test\""), "test");
            Assert.AreEqual(OssUtils.TrimQuotes("test\""), "test");
            Assert.AreEqual(OssUtils.TrimQuotes("\"test"), "test");
            Assert.AreEqual(OssUtils.TrimQuotes(null), null);

            //ComputeContentCrc64
            var content = new MemoryStream(Encoding.ASCII.GetBytes(""));

            str = OssUtils.ComputeContentCrc64(content, 1);
            Assert.AreEqual(str, string.Empty);

            //JoinETag
            var etagList = new List <string>();

            etagList.Add("etag1");
            etagList.Add("etag2");
            str = OssUtils.JoinETag(etagList);
            Assert.AreEqual(str, "etag1, etag2");

            //GetResourcePathFromSignedUrl
            str = OssUtils.GetResourcePathFromSignedUrl(new Uri("http://endpoint/key"));
            Assert.AreEqual(str, "key");

            str = OssUtils.GetResourcePathFromSignedUrl(new Uri("http://endpoint"));
            Assert.AreEqual(str, "");

            //GetParametersFromSignedUrl
        }