Example #1
0
        /// <summary>
        /// Creates and returns an Cloud Storage client
        /// </summary>
        /// <param name="uri">Location of the server, supports HTTP and HTTPS</param>
        /// <param name="accessKey">Access Key for authenticated requests</param>
        /// <param name="secretKey">Secret Key for authenticated requests</param>
        /// <param name="secure">Boolean value set to true/false makes the request HTTPS/HTTP respectively</param>
        /// <returns>Client with the uri set as the server location and authentication parameters set.</returns>
        public MinioClient(string endpoint, int port, string accessKey, string secretKey, bool secure)
        {
            if (string.IsNullOrEmpty(endpoint))
            {
                throw new InvalidEndpointException("Endpoint cannot be empty.");
            }

            if (!(endpoint.StartsWith(Uri.UriSchemeHttp) || endpoint.StartsWith(Uri.UriSchemeHttps)))
            {
                var scheme = secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp;
                endpoint = string.Format("{0}://{1}", scheme, endpoint);
            }

            var uri = new Uri(endpoint);

            if (!this.isValidEndpoint(uri.Host))
            {
                throw new InvalidEndpointException(endpoint, "Invalid endpoint.");
            }

            if (!uri.AbsolutePath.Equals("/", StringComparison.CurrentCultureIgnoreCase))
            {
                throw new InvalidEndpointException(endpoint, "No path allowed in endpoint.");
            }

            if (!string.IsNullOrEmpty(uri.Query))
            {
                throw new InvalidEndpointException(endpoint, "No query parameter allowed in endpoint.");
            }

            if (!(uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps)))
            {
                throw new InvalidEndpointException(endpoint, "Invalid scheme detected in endpoint.");
            }

            string amzHost = uri.Host;

            if ((amzHost.EndsWith(".amazonaws.com", StringComparison.CurrentCultureIgnoreCase)) &&
                !(amzHost.Equals("s3.amazonaws.com", StringComparison.CurrentCultureIgnoreCase)))
            {
                throw new InvalidEndpointException(endpoint, "For Amazon S3, host should be \'s3.amazonaws.com\' in endpoint.");
            }

            client           = new RestClient(uri);
            client.UserAgent = FullUserAgent;
            if (!(string.IsNullOrEmpty(accessKey) || string.IsNullOrEmpty(secretKey)))
            {
                authenticator        = new V4Authenticator(accessKey, secretKey);
                client.Authenticator = authenticator;
            }
            return;
        }
Example #2
0
        /// <summary>
        /// Creates and returns an Cloud Storage client
        /// </summary>
        /// <param name="uri">Location of the server, supports HTTP and HTTPS</param>
        /// <param name="accessKey">Access Key for authenticated requests</param>
        /// <param name="secretKey">Secret Key for authenticated requests</param>
        /// <param name="secure">Boolean value set to true/false makes the request HTTPS/HTTP respectively</param>
        /// <returns>Client with the uri set as the server location and authentication parameters set.</returns>
        public MinioClient(string endpoint, int port, string accessKey, string secretKey, bool secure)
        {
            if (string.IsNullOrEmpty(endpoint))
            {
                throw new InvalidEndpointException("Endpoint cannot be empty.");
            }

            if(!(endpoint.StartsWith(Uri.UriSchemeHttp) || endpoint.StartsWith(Uri.UriSchemeHttps)))
            {
                var scheme = secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp;
                endpoint = string.Format("{0}://{1}", scheme, endpoint);
            }

            var uri = new Uri(endpoint);
            if (!this.isValidEndpoint(uri.Host))
            {
                throw new InvalidEndpointException(endpoint, "Invalid endpoint.");
            }

            if (!uri.AbsolutePath.Equals("/", StringComparison.CurrentCultureIgnoreCase))
            {
                 throw new InvalidEndpointException(endpoint, "No path allowed in endpoint.");
            }

            if (!string.IsNullOrEmpty(uri.Query))
            {
                 throw new InvalidEndpointException(endpoint, "No query parameter allowed in endpoint.");
            }

            if (!(uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps)))
            {
                 throw new InvalidEndpointException(endpoint, "Invalid scheme detected in endpoint.");
            }

            string amzHost = uri.Host;
            if ((amzHost.EndsWith(".amazonaws.com", StringComparison.CurrentCultureIgnoreCase))
                && !(amzHost.Equals("s3.amazonaws.com", StringComparison.CurrentCultureIgnoreCase)))
            {
                 throw new InvalidEndpointException(endpoint, "For Amazon S3, host should be \'s3.amazonaws.com\' in endpoint.");
            }

            client = new RestClient(uri);
            client.UserAgent = FullUserAgent;
            if (!(string.IsNullOrEmpty(accessKey) || string.IsNullOrEmpty(secretKey)))
            {
                authenticator = new V4Authenticator(accessKey, secretKey);
                client.Authenticator = authenticator;
            }
            return;
        }