예제 #1
0
        // Set bucket policy
        public async static Task Run(MinioClient minio,
                                     string bucketName = "my-bucket-name")
        {
            try
            {
                Console.WriteLine("Running example for API: DeletePolicyAsync");
                var args = new RemovePolicyArgs()
                           .WithBucket(bucketName);
                await minio.RemovePolicyAsync(args);

                Console.WriteLine($"Policy previously set for the bucket {bucketName} removed.");
                try
                {
                    var getArgs = new GetPolicyArgs()
                                  .WithBucket(bucketName);
                    string policy = await minio.GetPolicyAsync(getArgs);
                }
                catch (UnexpectedMinioException e)
                {
                    Console.WriteLine($"GetPolicy operation for {bucketName} result: {e.ServerMessage}");
                }
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
예제 #2
0
        // Get bucket policy
        public async static Task Run(MinioClient minio,
                                     string bucketName = "my-bucket-name",
                                     string prefix     = "")
        {
            try
            {
                var args = new GetPolicyArgs()
                           .WithBucket(bucketName);
                Console.WriteLine("Running example for API: GetPolicyAsync");
                string policyJson = await minio.GetPolicyAsync(args);

                Console.WriteLine($"Current Policy is {policyJson} for bucket {bucketName}");
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
예제 #3
0
        /// <summary>
        /// 获取存储桶的权限
        /// </summary>
        /// <param name="bucketName">存储桶名称。</param>
        /// <returns></returns>
        public async Task <PolicyInfo> GetPolicyAsync(string bucketName)
        {
            try
            {
                if (string.IsNullOrEmpty(bucketName))
                {
                    throw new ArgumentNullException(nameof(bucketName));
                }

                var args = new GetPolicyArgs()
                           .WithBucket(bucketName);
                string policyJson = await _client.GetPolicyAsync(args);

                if (string.IsNullOrEmpty(policyJson))
                {
                    throw new Exception("Result policy json is null.");
                }
                return(JsonUtil.DeserializeObject <PolicyInfo>(policyJson));
            }
            catch (MinioException ex)
            {
                if (!string.IsNullOrEmpty(ex.Message) && ex.Message.ToLower().Contains("the bucket policy does not exist"))
                {
                    return(new PolicyInfo()
                    {
                        Version = _defaultPolicyVersion,
                        Statement = new List <StatementItem>()
                    });
                }
                else
                {
                    throw;
                }
            }
            catch
            {
                throw;
            }
        }