예제 #1
0
        static void DeleteBucketPolicy()
        {
            try
            {
                DeleteBucketPolicyRequest request = new DeleteBucketPolicyRequest()
                {
                    BucketName = bucketName,
                };
                DeleteBucketPolicyResponse response = client.DeleteBucketPolicy(request);

                Console.WriteLine("Delete bucket policy response: {0}", response.StatusCode);
            }
            catch (ObsException ex)
            {
                Console.WriteLine("Exception errorcode: {0}, when delete bucket policy.", ex.ErrorCode);
                Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage);
            }
        }
예제 #2
0
 private void DeleteBucketPolicyButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         S3Common.client.OnS3Response += DeleteBucketPolicyWebResponse;
         DeleteBucketPolicyRequest request = new DeleteBucketPolicyRequest();
         request.BucketName = SelectedBucketName;
         S3Common.client.DeleteBucketPolicy(request);
     }
     catch (Exception ex)
     {
         S3Common.client.OnS3Response -= DeleteBucketPolicyWebResponse;
         this.Dispatcher.BeginInvoke(() =>
         {
             MessageBox.Show(ex.Message);
         });
     }
 }
예제 #3
0
 public void DeleteBucketPolicy(DeleteBucketPolicyRequest request, Callback.OnSuccessCallback <CosResult> successCallback, Callback.OnFailedCallback failCallback)
 {
     Schedue(request, new DeleteBucketPolicyResult(), successCallback, failCallback);
 }
예제 #4
0
 public DeleteBucketPolicyResult DeleteBucketPolicy(DeleteBucketPolicyRequest request)
 {
     return((Model.Bucket.DeleteBucketPolicyResult)Excute(request, new Model.Bucket.DeleteBucketPolicyResult()));
 }
예제 #5
0
 public Task <DeleteBucketPolicyResponse> DeleteBucketPolicyAsync(DeleteBucketPolicyRequest request, CancellationToken cancellationToken = default)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 /// <summary>
 /// 删除桶策略。
 /// </summary>
 /// <param name="request">删除桶策略的请求参数。</param>
 /// <returns>删除桶策略的响应结果。</returns>
 public DeleteBucketPolicyResponse DeleteBucketPolicy(DeleteBucketPolicyRequest request)
 {
     return(this.DoRequest <DeleteBucketPolicyRequest, DeleteBucketPolicyResponse>(request));
 }
예제 #7
0
        public void BucketSamples()
        {
            {
                #region ListBuckets Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Issue call
                ListBucketsResponse response = client.ListBuckets();

                // View response data
                Console.WriteLine("Buckets owner - {0}", response.Owner.DisplayName);
                foreach (S3Bucket bucket in response.Buckets)
                {
                    Console.WriteLine("Bucket {0}, Created on {1}", bucket.BucketName, bucket.CreationDate);
                }

                #endregion
            }

            {
                #region BucketPolicy Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Put sample bucket policy (overwrite an existing policy)
                string newPolicy = @"{ 
    ""Statement"":[{ 
    ""Sid"":""BasicPerms"", 
    ""Effect"":""Allow"", 
    ""Principal"": ""*"", 
    ""Action"":[""s3:PutObject"",""s3:GetObject""], 
    ""Resource"":[""arn:aws:s3:::samplebucketname/*""] 
}]}";
                PutBucketPolicyRequest putRequest = new PutBucketPolicyRequest
                {
                    BucketName = "SampleBucket",
                    Policy     = newPolicy
                };
                client.PutBucketPolicy(putRequest);


                // Retrieve current policy
                GetBucketPolicyRequest getRequest = new GetBucketPolicyRequest
                {
                    BucketName = "SampleBucket"
                };
                string policy = client.GetBucketPolicy(getRequest).Policy;

                Console.WriteLine(policy);
                Debug.Assert(policy.Contains("BasicPerms"));


                // Delete current policy
                DeleteBucketPolicyRequest deleteRequest = new DeleteBucketPolicyRequest
                {
                    BucketName = "SampleBucket"
                };
                client.DeleteBucketPolicy(deleteRequest);


                // Retrieve current policy and verify that it is null
                policy = client.GetBucketPolicy(getRequest).Policy;
                Debug.Assert(policy == null);

                #endregion
            }

            {
                #region GetBucketLocation Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Construct request
                GetBucketLocationRequest request = new GetBucketLocationRequest
                {
                    BucketName = "SampleBucket"
                };

                // Issue call
                GetBucketLocationResponse response = client.GetBucketLocation(request);

                // View response data
                Console.WriteLine("Bucket location - {0}", response.Location);

                #endregion
            }

            {
                #region PutBucket Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Construct request
                PutBucketRequest request = new PutBucketRequest
                {
                    BucketName   = "SampleBucket",
                    BucketRegion = S3Region.EU,           // set region to EU
                    CannedACL    = S3CannedACL.PublicRead // make bucket publicly readable
                };

                // Issue call
                PutBucketResponse response = client.PutBucket(request);

                #endregion
            }

            {
                #region DeleteBucket Sample 1

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Construct request
                DeleteBucketRequest request = new DeleteBucketRequest
                {
                    BucketName = "SampleBucket"
                };

                // Issue call
                DeleteBucketResponse response = client.DeleteBucket(request);

                #endregion
            }

            {
                #region DeleteBucket Sample 2

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // List and delete all objects
                ListObjectsRequest listRequest = new ListObjectsRequest
                {
                    BucketName = "SampleBucket"
                };

                ListObjectsResponse listResponse;
                do
                {
                    // Get a list of objects
                    listResponse = client.ListObjects(listRequest);
                    foreach (S3Object obj in listResponse.S3Objects)
                    {
                        // Delete each object
                        client.DeleteObject(new DeleteObjectRequest
                        {
                            BucketName = "SampleBucket",
                            Key        = obj.Key
                        });
                    }

                    // Set the marker property
                    listRequest.Marker = listResponse.NextMarker;
                } while (listResponse.IsTruncated);

                // Construct DeleteBucket request
                DeleteBucketRequest request = new DeleteBucketRequest
                {
                    BucketName = "SampleBucket"
                };

                // Issue call
                DeleteBucketResponse response = client.DeleteBucket(request);

                #endregion
            }

            {
                #region LifecycleConfiguration Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();


                // Put sample lifecycle configuration (overwrite an existing configuration)
                LifecycleConfiguration newConfiguration = new LifecycleConfiguration
                {
                    Rules = new List <LifecycleRule>
                    {
                        // Rule to delete keys with prefix "Test-" after 5 days
                        new LifecycleRule
                        {
                            Prefix     = "Test-",
                            Expiration = new LifecycleRuleExpiration {
                                Days = 5
                            }
                        },
                        // Rule to delete keys in subdirectory "Logs" after 2 days
                        new LifecycleRule
                        {
                            Prefix     = "Logs/",
                            Expiration = new LifecycleRuleExpiration  {
                                Days = 2
                            },
                            Id = "log-file-removal"
                        }
                    }
                };
                PutLifecycleConfigurationRequest putRequest = new PutLifecycleConfigurationRequest
                {
                    BucketName    = "SampleBucket",
                    Configuration = newConfiguration
                };
                client.PutLifecycleConfiguration(putRequest);


                // Retrieve current configuration
                GetLifecycleConfigurationRequest getRequest = new GetLifecycleConfigurationRequest
                {
                    BucketName = "SampleBucket"
                };
                LifecycleConfiguration configuration = client.GetLifecycleConfiguration(getRequest).Configuration;

                Console.WriteLine("Configuration contains {0} rules", configuration.Rules.Count);
                foreach (LifecycleRule rule in configuration.Rules)
                {
                    Console.WriteLine("Rule");
                    Console.WriteLine(" Prefix = " + rule.Prefix);
                    Console.WriteLine(" Expiration (days) = " + rule.Expiration.Days);
                    Console.WriteLine(" Id = " + rule.Id);
                    Console.WriteLine(" Status = " + rule.Status);
                }


                // Put a new configuration and overwrite the existing configuration
                configuration.Rules.RemoveAt(0);    // remove first rule
                client.PutLifecycleConfiguration(putRequest);

                // Delete current configuration
                DeleteLifecycleConfigurationRequest deleteRequest = new DeleteLifecycleConfigurationRequest
                {
                    BucketName = "SampleBucket"
                };
                client.DeleteLifecycleConfiguration(deleteRequest);


                // Retrieve current configuration and verify that it is null
                configuration = client.GetLifecycleConfiguration(getRequest).Configuration;
                Debug.Assert(configuration == null);

                #endregion
            }
        }
 public DeleteBucketPolicyResponse DeleteBucketPolicy(DeleteBucketPolicyRequest request)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Start the asynchronous request for deleting bucket policies.
 /// </summary>
 /// <param name="request">Parameters in a request for deleting bucket policies</param>
 /// <param name="callback">Asynchronous request callback function</param>
 /// <param name="state">Asynchronous request status object</param>
 /// <returns>Response to the asynchronous request</returns>
 public IAsyncResult BeginDeleteBucketPolicy(DeleteBucketPolicyRequest request, AsyncCallback callback, object state)
 {
     return(this.BeginDoRequest <DeleteBucketPolicyRequest>(request, callback, state));
 }
예제 #10
0
 public void DeleteBucketPolicyAsync(DeleteBucketPolicyRequest request, AmazonServiceCallback <DeleteBucketPolicyRequest, DeleteBucketPolicyResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }