Пример #1
0
        internal static Uri GetEndpointURL(string endPoint, bool secure)
        {
            if (endPoint.Contains(":"))
            {
                string[] parts = endPoint.Split(':');
                string   host  = parts[0];
                string   port  = parts[1];
                if (!s3utils.IsValidIP(host) && !IsValidEndpoint(host))
                {
                    throw new InvalidEndpointException("Endpoint: " + endPoint + " does not follow ip address or domain name standards.");
                }
            }
            else
            {
                if (!s3utils.IsValidIP(endPoint) && !IsValidEndpoint(endPoint))
                {
                    throw new InvalidEndpointException("Endpoint: " + endPoint + " does not follow ip address or domain name standards.");
                }
            }

            Uri uri = TryCreateUri(endPoint, secure);

            RequestUtil.ValidateEndpoint(uri, endPoint);
            return(uri);
        }
Пример #2
0
        /// <summary>
        /// This method initializes a new RESTClient. The host URI for Amazon is set to virtual hosted style
        /// if usePathStyle is false. Otherwise path style URL is constructed.
        /// </summary>
        internal void InitClient()
        {
            if (string.IsNullOrEmpty(this.BaseUrl))
            {
                throw new InvalidEndpointException("Endpoint cannot be empty.");
            }

            string host = this.BaseUrl;

            var scheme = this.Secure ? utils.UrlEncode("https") : utils.UrlEncode("http");

            // This is the actual url pointed to for all HTTP requests
            this.Endpoint = string.Format("{0}://{1}", scheme, host);
            this.uri      = RequestUtil.GetEndpointURL(this.BaseUrl, this.Secure);
            RequestUtil.ValidateEndpoint(this.uri, this.Endpoint);

            // Initialize a new REST client. This uri will be modified if region specific endpoint/virtual style request
            // is decided upon while constructing a request for Amazon.
            restClient = new RestSharp.RestClient(this.uri)
            {
                UserAgent = this.FullUserAgent
            };

            authenticator            = new V4Authenticator(this.Secure, this.AccessKey, this.SecretKey, this.Region, this.SessionToken);
            restClient.Authenticator = authenticator;
            restClient.UseUrlEncoder(s => HttpUtility.UrlEncode(s));
        }
Пример #3
0
        /// <summary>
        /// Creates and returns an Cloud Storage client
        /// </summary>
        /// <param name="endpoint">Location of the server, supports HTTP and HTTPS</param>
        /// <param name="accessKey">Access Key for authenticated requests (Optional, can be omitted for anonymous requests)</param>
        /// <param name="secretKey">Secret Key for authenticated requests (Optional, can be omitted for anonymous requests)</param>
        /// <param name="region">Optional custom region</param>
        /// <param name="sessionToken">Optional session token</param>
        /// <returns>Client initialized with user credentials</returns>
        public MinioClient(string endpoint, string accessKey = "", string secretKey = "", string region = "",
                           string sessionToken = "")
        {
            this.Secure = false;

            // Save user entered credentials
            this.BaseUrl      = endpoint;
            this.AccessKey    = accessKey;
            this.SecretKey    = secretKey;
            this.SessionToken = sessionToken;
            this.Region       = region;
            // Instantiate a region cache
            this.regionCache = BucketRegionCache.Instance;

            if (string.IsNullOrEmpty(this.BaseUrl))
            {
                throw new InvalidEndpointException("Endpoint cannot be empty.");
            }

            string host   = this.BaseUrl;
            var    scheme = this.Secure ? utils.UrlEncode("https") : utils.UrlEncode("http");

            // This is the actual url pointed to for all HTTP requests
            this.Endpoint = string.Format("{0}://{1}", scheme, host);
            this.uri      = RequestUtil.GetEndpointURL(this.BaseUrl, this.Secure);
            RequestUtil.ValidateEndpoint(this.uri, this.Endpoint);

            this.HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", this.FullUserAgent);
        }
Пример #4
0
        /// <summary>
        /// This method initializes a new RESTClient. It is called by other Inits
        /// </summary>

        internal void Init()
        {
            this.uri = RequestUtil.GetEndpointURL(this.BaseUrl, this.Secure);
            RequestUtil.ValidateEndpoint(this.uri, this.Endpoint);

            // Initialize a new REST client. This uri will be modified if region specific endpoint/virtual style request
            // is decided upon while constructing a request for Amazon.
            restClient = new RestSharp.RestClient(this.uri)
            {
                UserAgent = this.FullUserAgent
            };

            authenticator            = new V4Authenticator(this.Secure, this.AccessKey, this.SecretKey, this.Region, this.SessionToken);
            restClient.Authenticator = authenticator;
            restClient.UseUrlEncoder(s => HttpUtility.UrlEncode(s));
        }