예제 #1
0
        // Hydrate a bucket policy from JSON string
        internal static BucketPolicy GenerateBucketPolicy(string policyString, string bucketName)
        {
            var contentBytes = System.Text.Encoding.UTF8.GetBytes(policyString);
            var stream       = new MemoryStream(contentBytes);

            return(BucketPolicy.ParseJson(stream, bucketName));
        }
예제 #2
0
        public void TestIfStringIsetGetsDeSerialized_Test1()
        {
            string policyString = @"{""Version"":""2012 - 10 - 17"",""Statement"":[{""Sid"":"""",""Effect"":""Allow"",""Principal"":{""AWS"":"" * ""},""Action"":""s3: GetBucketLocation"",""Resource"":""arn: aws: s3:::miniodotnetvpn5pic718xfutt""},{""Sid"":"""",""Effect"":""Allow"",""Principal"":{""AWS"":"" * ""},""Action"":""s3: ListBucket"",""Resource"":""arn: aws: s3:::miniodotnetvpn5pic718xfutt"",""Condition"":{""StringEquals"":{""s3: prefix"":""dotnetcms1ssazhd""}}},{""Sid"":"""",""Effect"":""Allow"",""Principal"":{""AWS"":"" * ""},""Action"":""s3: GetObject"",""Resource"":""arn: aws: s3:::miniodotnetvpn5pic718xfutt / dotnetcms1ssazhd * ""}]}";


            // ConditionKeyMap ckmap = JsonConvert.DeserializeObject<ConditionKeyMap>(ckmapString);
            var          contentBytes = System.Text.Encoding.UTF8.GetBytes(policyString);
            string       bucketName   = "miniodotnetvpn5pic718xfutt";
            var          stream       = new MemoryStream(contentBytes);
            BucketPolicy policy       = BucketPolicy.ParseJson(stream, bucketName);
        }
예제 #3
0
        /// <summary>
        /// Returns current policy stored on the server for this bucket
        /// </summary>
        /// <param name="bucketName">Bucket name.</param>
        /// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
        /// <returns>Task that returns the Bucket policy</returns>
        private async Task <BucketPolicy> GetPolicyAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))
        {
            BucketPolicy  policy   = null;
            IRestResponse response = null;

            var path = bucketName + "?policy";

            var request = await this.CreateRequest(Method.GET, bucketName,
                                                   contentType : "application/json",
                                                   resourcePath : "?policy");

            try
            {
                response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken);

                var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content);

                using (var stream = new MemoryStream(contentBytes))
                {
                    policy = BucketPolicy.ParseJson(stream, bucketName);
                }
            }
            catch (ErrorResponseException e)
            {
                // Ignore if there is
                if (!e.Response.Code.Equals("NoSuchBucketPolicy"))
                {
                    throw e;
                }
            }
            finally
            {
                if (policy == null)
                {
                    policy = new BucketPolicy(bucketName);
                }
            }
            return(policy);
        }