Exemplo n.º 1
0
    internal virtual async Task <HttpRequestMessageBuilder> BuildRequest()
    {
        HttpRequestMessageBuilder reqBuilder = null;

        if (Client == null)
        {
            throw new InvalidOperationException("MinioClient is not set in AssumeRoleBaseProvider");
        }
        reqBuilder = await Client.CreateRequest(HttpMethod.Post);

        reqBuilder.AddQueryParameter("Action", Action);
        reqBuilder.AddQueryParameter("Version", "2011-06-15");
        if (!string.IsNullOrWhiteSpace(Policy))
        {
            reqBuilder.AddQueryParameter("Policy", Policy);
        }
        if (!string.IsNullOrWhiteSpace(RoleARN))
        {
            reqBuilder.AddQueryParameter("RoleArn", RoleARN);
        }
        if (!string.IsNullOrWhiteSpace(RoleSessionName))
        {
            reqBuilder.AddQueryParameter("RoleSessionName", RoleARN);
        }

        return(reqBuilder);
    }
Exemplo n.º 2
0
        public async Task <string> GetIamRoleNameAsync(Uri url)
        {
            this.Validate();
            string[] roleNames = null;

            var requestBuilder = new HttpRequestMessageBuilder(HttpMethod.Get, url);

            requestBuilder.AddQueryParameter("location", "");

            var response = await this.Minio_Client.ExecuteTaskAsync(Enumerable.Empty <ApiResponseErrorHandlingDelegate>(), requestBuilder);


            if (string.IsNullOrWhiteSpace(response.Content) ||
                !HttpStatusCode.OK.Equals(response.StatusCode))
            {
                throw new CredentialsProviderException("IAMAWSProvider", "Credential Get operation failed with HTTP Status code: " + response.StatusCode);
            }
            roleNames = response.Content.Split('\n');
            if (roleNames.Length <= 0)
            {
                throw new CredentialsProviderException("IAMAWSProvider", "No IAM roles are attached to AWS service at " + url.ToString());
            }
            int index = 0;

            foreach (var item in roleNames)
            {
                roleNames[index++] = item.Trim();
            }
            return(roleNames[0]);
        }
Exemplo n.º 3
0
        public async Task <AccessCredentials> GetAccessCredentials(Uri url)
        {
            this.Validate();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url.ToString());

            var requestBuilder = new HttpRequestMessageBuilder(HttpMethod.Get, url);

            requestBuilder.AddQueryParameter("location", "");

            var response = await this.Minio_Client.ExecuteTaskAsync(Enumerable.Empty <ApiResponseErrorHandlingDelegate>(), requestBuilder);

            if (string.IsNullOrWhiteSpace(response.Content) ||
                !HttpStatusCode.OK.Equals(response.StatusCode))
            {
                throw new CredentialsProviderException("IAMAWSProvider", "Credential Get operation failed with HTTP Status code: " + response.StatusCode);
            }
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
            {
                MissingMemberHandling = MissingMemberHandling.Error,
                ContractResolver      = new CamelCasePropertyNamesContractResolver(),
                Error = null,
            };
            ECSCredentials credentials = JsonConvert.DeserializeObject <ECSCredentials>(response.Content);

            if (credentials.Code != null && !credentials.Code.ToLower().Equals("success"))
            {
                throw new CredentialsProviderException("IAMAWSProvider", "Credential Get operation failed with code: " + credentials.Code + " and message " + credentials.Message);
            }
            this.Credentials = credentials.GetAccessCredentials();
            return(this.Credentials);
        }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("object-lock", "");
        var body = utils.MarshalXML(new ObjectLockConfiguration(), "http://s3.amazonaws.com/doc/2006-03-01/");

        requestMessageBuilder.AddXmlBody(body);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));
        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)

    {
        foreach (var eventType in Events)
        {
            requestMessageBuilder.AddQueryParameter("events", eventType.value);
        }
        requestMessageBuilder.AddQueryParameter("prefix", Prefix);
        requestMessageBuilder.AddQueryParameter("suffix", Suffix);

        requestMessageBuilder.ResponseWriter = async responseStream =>
        {
            using (responseStream)
            {
                var sr = new StreamReader(responseStream);
                while (!sr.EndOfStream)
                {
                    try
                    {
                        var line = await sr.ReadLineAsync();

                        if (EnableTrace)
                        {
                            Console.WriteLine("== ListenBucketNotificationsAsync read line ==");
                            Console.WriteLine(line);
                            Console.WriteLine("==============================================");
                        }

                        var trimmed = line.Trim();
                        if (trimmed.Length > 2)
                        {
                            NotificationObserver.OnNext(new MinioNotificationRaw(trimmed));
                        }
                    }
                    catch
                    {
                        break;
                    }
                }
            }
        };
        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        if (string.IsNullOrEmpty(PolicyJsonString))
        {
            new MinioException("SetPolicyArgs needs the policy to be set to the right JSON contents.");
        }

        requestMessageBuilder.AddQueryParameter("policy", "");
        requestMessageBuilder.AddJsonBody(PolicyJsonString);
        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("replication", "");
        var body = BucketReplication.MarshalXML();
        // Convert string to a byte array
        var bodyInBytes = Encoding.ASCII.GetBytes(body);

        requestMessageBuilder.BodyParameters.Add("content-type", "text/xml");
        requestMessageBuilder.SetBody(bodyInBytes);

        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("tagging", "");
        var body = BucketTags.MarshalXML();

        requestMessageBuilder.AddXmlBody(body);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));

        //
        return(requestMessageBuilder);
    }
Exemplo n.º 9
0
        internal async override Task <HttpRequestMessageBuilder> BuildRequest()
        {
            this.Validate();
            JsonWebToken jwt = this.JWTSupplier();
            HttpRequestMessageBuilder requestMessageBuilder = await base.BuildRequest();

            requestMessageBuilder = utils.GetEmptyRestRequest(requestMessageBuilder);
            requestMessageBuilder.AddQueryParameter("WebIdentityToken", jwt.AccessToken);
            await Task.Yield();

            return(requestMessageBuilder);
        }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        var config = new VersioningConfiguration(CurrentVersioningStatus == VersioningStatus.Enabled);

        var body = utils.MarshalXML(config, "http://s3.amazonaws.com/doc/2006-03-01/");

        requestMessageBuilder.AddXmlBody(body);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));

        requestMessageBuilder.AddQueryParameter("versioning", "");
        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("notification", "");
        var bucketNotificationConfiguration = new BucketNotification();
        var body = utils.MarshalXML(bucketNotificationConfiguration, "http://s3.amazonaws.com/doc/2006-03-01/");
        // Convert string to a byte array
        var bodyInBytes = Encoding.ASCII.GetBytes(body);

        requestMessageBuilder.BodyParameters.Add("content-type", "text/xml");
        requestMessageBuilder.SetBody(bodyInBytes);

        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("lifecycle", "");
        var body = BucketLifecycle.MarshalXML();
        // Convert string to a byte array
        var bodyInBytes = Encoding.ASCII.GetBytes(body);

        requestMessageBuilder.BodyParameters.Add("content-type", "text/xml");
        requestMessageBuilder.SetBody(bodyInBytes);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(bodyInBytes));

        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        if (BucketNotificationConfiguration == null)
        {
            throw new UnexpectedMinioException(
                      "Cannot BuildRequest for SetBucketNotificationsArgs. BucketNotification configuration not assigned");
        }
        requestMessageBuilder.AddQueryParameter("notification", "");
        var body = utils.MarshalXML(BucketNotificationConfiguration, "http://s3.amazonaws.com/doc/2006-03-01/");
        // Convert string to a byte array
        var bodyInBytes = Encoding.ASCII.GetBytes(body);

        requestMessageBuilder.BodyParameters.Add("content-type", "text/xml");
        requestMessageBuilder.SetBody(bodyInBytes);

        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        if (EncryptionConfig == null)
        {
            EncryptionConfig = ServerSideEncryptionConfiguration.GetSSEConfigurationWithS3Rule();
        }

        requestMessageBuilder.AddQueryParameter("encryption", "");
        var body = utils.MarshalXML(EncryptionConfig, "http://s3.amazonaws.com/doc/2006-03-01/");
        // Convert string to a byte array
        var bodyInBytes = Encoding.ASCII.GetBytes(body);

        requestMessageBuilder.BodyParameters.Add("content-type", "text/xml");
        requestMessageBuilder.SetBody(bodyInBytes);

        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("object-lock", "");
        var body = utils.MarshalXML(LockConfiguration, "http://s3.amazonaws.com/doc/2006-03-01/");

        // Convert string to a byte array
        // byte[] bodyInBytes = Encoding.ASCII.GetBytes(body);

        // requestMessageBuilder.BodyParameters.Add("content-type", "text/xml");
        // requestMessageBuilder.SetBody(bodyInBytes);
        //
        // string body = utils.MarshalXML(config, "http://s3.amazonaws.com/doc/2006-03-01/");
        requestMessageBuilder.AddXmlBody(body);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));
        //
        return(requestMessageBuilder);
    }
 internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
 {
     requestMessageBuilder.AddQueryParameter("lifecycle", "");
     return(requestMessageBuilder);
 }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        // using System.Web; Not sure if we need to add query parameters like this vs. requestMessageBuilder.AddQueryParameter()
        // var query = HttpUtility.ParseQueryString(string.Empty);
        // query["foo"] = "bar<>&-baz";
        // query["bar"] = "bazinga";
        // string queryString = query.ToString();        {


        requestMessageBuilder.AddQueryParameter("delimiter", Delimiter);
        requestMessageBuilder.AddQueryParameter("max-keys", "1000");
        requestMessageBuilder.AddQueryParameter("encoding-type", "url");
        requestMessageBuilder.AddQueryParameter("prefix", Prefix);
        if (Versions)
        {
            requestMessageBuilder.AddQueryParameter("versions", "");
            if (!string.IsNullOrWhiteSpace(Marker))
            {
                requestMessageBuilder.AddQueryParameter("key-marker", Marker);
            }
            if (!string.IsNullOrWhiteSpace(VersionIdMarker))
            {
                requestMessageBuilder.AddQueryParameter("version-id-marker", VersionIdMarker);
            }
        }
        else if (!Versions && UseV2)
        {
            requestMessageBuilder.AddQueryParameter("list-type", "2");
            if (!string.IsNullOrWhiteSpace(Marker))
            {
                requestMessageBuilder.AddQueryParameter("start-after", Marker);
            }
            if (!string.IsNullOrWhiteSpace(ContinuationToken))
            {
                requestMessageBuilder.AddQueryParameter("continuation-token", ContinuationToken);
            }
        }
        else if (!Versions && !UseV2)
        {
            requestMessageBuilder.AddQueryParameter("marker", Marker);
        }
        else
        {
            throw new InvalidOperationException("Wrong set of properties set.");
        }

        return(requestMessageBuilder);
    }
 internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
 {
     requestMessageBuilder.AddQueryParameter("object-lock", "");
     return(requestMessageBuilder);
 }
 internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
 {
     requestMessageBuilder.AddQueryParameter("replication", "");
     return(requestMessageBuilder);
 }
 internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
 {
     requestMessageBuilder.AddQueryParameter("versioning", "");
     return(requestMessageBuilder);
 }