Example #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            UpdateBucketRequest request;

            try
            {
                request = new UpdateBucketRequest
                {
                    NamespaceName       = NamespaceName,
                    BucketName          = BucketName,
                    UpdateBucketDetails = UpdateBucketDetails,
                    IfMatch             = IfMatch,
                    OpcClientRequestId  = OpcClientRequestId
                };

                response = client.UpdateBucket(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Bucket);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Example #2
0
        /// <summary>
        /// 设置Bucket的属性
        /// </summary>
        /// <param name="requestParams">请求参数.</param>
        /// <returns>返回对象<see cref="UCloudSDK.Models.UpdateBucketResponse"/></returns>
        public UpdateBucketResponse UpdateBucket(UpdateBucketRequest requestParams)
        {
            var request = new RestRequest(Method.GET);

            request.AddUObject(requestParams);
            return(Execute <UpdateBucketResponse>(request));
        }
        /// <summary>
        /// Performs a partial or full update of a bucket's user-defined metadata.
        ///
        /// Use UpdateBucket to move a bucket from one compartment to another within the same tenancy.
        /// Supply the compartmentID of the compartment that you want to move the bucket to.
        /// For more information about moving resources between compartments, see Moving Resources to a Different Compartment.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <UpdateBucketResponse> UpdateBucket(UpdateBucketRequest request)
        {
            var uri = new Uri(GetEndPointNoneVersion(ObjectStorageServices.Bucket(request.NamespaceName, request.BucketName), this.Region));

            var httpRequestHeaderParam = new HttpRequestHeaderParam()
            {
                IfMatch            = request.IfMatch,
                OpcClientRequestId = request.OpcClientRequestId
            };
            var webResponse = await this.RestClientAsync.Post(uri, request.UpdateBucketDetails, httpRequestHeaderParam);

            using (var stream = webResponse.GetResponseStream())
                using (var reader = new StreamReader(stream))
                {
                    var response = reader.ReadToEnd();

                    return(new UpdateBucketResponse()
                    {
                        Bucket = JsonSerializer.Deserialize <Bucket>(response),
                        ETag = webResponse.Headers.Get("ETag"),
                        OpcRequestId = webResponse.Headers.Get("opc-request-id"),
                        OpcClientRequestId = webResponse.Headers.Get("opc-client-request-id")
                    });
                }
        }
Example #4
0
        /// <summary>
        /// Update an existing bucket.
        /// </summary>
        /// <param name="bucketId">The buckete id to update.</param>
        /// <param name="bucketType">The bucket secuirty authorization type.</param>
        /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception>
        /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception>
        async Task <IApiResults <UpdateBucketResponse> > IStorageBuckets.UpdateAsync
            (string bucketId, BucketType bucketType)
        {
            var request = new UpdateBucketRequest(AccountId, bucketId, bucketType);

            return(await _client.UpdateBucketAsync(request, _cancellationToken));
        }
Example #5
0
        public void UpdateBucketTest()
        {
            var entity = new UpdateBucketRequest(Config.Bucket);

            entity.Type = "public";
            var response = ufile.UpdateBucket(entity);

            Assert.AreEqual(response.RetCode, 0);
        }
Example #6
0
        public static async Task MainOSBucketTagging()
        {
            string compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");
            string bucketName    = Environment.GetEnvironmentVariable("BUCKET_NAME");
            string tagNamespace  = Environment.GetEnvironmentVariable("TAG_NAMESPACE");
            string tagName       = Environment.GetEnvironmentVariable("TAG_NAME");

            logger.Info("Starting example");
            // Create Object Storage Client
            var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
            var osClient = new ObjectStorageClient(provider, new ClientConfiguration());

            logger.Info("Object Storage client created.");

            GetNamespaceRequest getNamespaceRequest = new GetNamespaceRequest
            {
                CompartmentId = compartmentId
            };
            GetNamespaceResponse getNamespaceResponse = await osClient.GetNamespace(getNamespaceRequest);

            string nSpace = getNamespaceResponse.Value.Trim('"');

            logger.Info($"namespace is {nSpace}");

            /*
             * We can assign tags to a bucket at creation time. Like other taggable resources, we can
             * assign freeform and defined tags to a bucket. Freeform tags are a dictionary of
             * string-to-string, where the key is the tag name and the value is the tag value.
             *
             * Defined tags are a dictionary where the key is the tag namespace (string) and the value is another dictionary. In
             * this second dictionary, the key is the tag name (string) and the value is the tag value. The tag names have to
             * correspond to the name of a tag within the specified namespace (and the namespace must exist).
             */
            try
            {
                Dictionary <string, string> freeformTags = new Dictionary <string, string>()
                {
                    { "free", "form" },
                    { "another", "item" }
                };

                Dictionary <string, object> definedTagsMap = new Dictionary <string, object>()
                {
                    { tagName, "original value" }
                };

                Dictionary <string, Dictionary <string, object> > definedTags = new Dictionary <string, Dictionary <string, object> >()
                {
                    { tagNamespace, definedTagsMap }
                };

                CreateBucketDetails createBucketDetails = new CreateBucketDetails
                {
                    Name                = bucketName,
                    CompartmentId       = compartmentId,
                    FreeformTags        = freeformTags,
                    DefinedTags         = definedTags,
                    ObjectEventsEnabled = false
                };
                CreateBucketRequest createBucketRequest = new CreateBucketRequest
                {
                    CreateBucketDetails = createBucketDetails,
                    NamespaceName       = nSpace
                };
                CreateBucketResponse createBucketResponse = await osClient.CreateBucket(createBucketRequest);

                logger.Info($"Created a bucket with tags Bucket name: {createBucketResponse.Bucket.Name}");
                logger.Info("========================================");
                definedTags = createBucketResponse.Bucket.DefinedTags;
                foreach (KeyValuePair <string, Dictionary <string, object> > kvp in definedTags)
                {
                    foreach (KeyValuePair <string, object> tags in kvp.Value)
                    {
                        logger.Info($"tag key name: {tags.Key} and tag value is {tags.Value}");
                    }
                }

                // Tags come back when retrieving the bucket
                GetBucketRequest getBucketRequest = new GetBucketRequest
                {
                    NamespaceName = nSpace,
                    BucketName    = bucketName
                };
                GetBucketResponse getBucketResponse = await osClient.GetBucket(getBucketRequest);

                logger.Info($"Retrieved a bucket with tags Bucket name: {getBucketResponse.Bucket.Name}");
                logger.Info("==========================================");
                definedTags = getBucketResponse.Bucket.DefinedTags;
                foreach (KeyValuePair <string, Dictionary <string, object> > kvp in definedTags)
                {
                    foreach (KeyValuePair <string, object> tags in kvp.Value)
                    {
                        logger.Info($"tag key name: {tags.Key} and tag value is {tags.Value}");
                    }
                }

                /*
                 * Unlike other resources (e.g. instances, VCNs, and block volumes), when listing buckets
                 * tags are not returned by default. Instead, you need to provide a value to the fields
                 * parameter when listing buckets in order to have those tags returned.
                 *
                 * Here we can see the result of providing and not providing that parameter.
                 */
                ListBucketsRequest listBucketsRequest = new ListBucketsRequest
                {
                    CompartmentId = compartmentId,
                    NamespaceName = nSpace
                };
                IEnumerable <BucketSummary> bucketSummaries = osClient.Paginators.ListBucketsRecordEnumerator(listBucketsRequest);
                foreach (BucketSummary bucketSummary in bucketSummaries)
                {
                    if (bucketSummary.Name.Equals(bucketName))
                    {
                        logger.Info($"Bucket summary without tags: Bucket Name: {bucketSummary.Name}");
                        logger.Info("=========================================");
                        if (bucketSummary.DefinedTags != null)
                        {
                            logger.Error($"expected tags to be zero but got: {bucketSummary.DefinedTags.Count}");
                        }
                        break;
                    }
                }

                List <ListBucketsRequest.FieldsEnum> fields = new List <ListBucketsRequest.FieldsEnum>()
                {
                    ListBucketsRequest.FieldsEnum.Tags
                };

                listBucketsRequest = new ListBucketsRequest
                {
                    CompartmentId = compartmentId,
                    NamespaceName = nSpace,
                    Fields        = fields
                };
                bucketSummaries = osClient.Paginators.ListBucketsRecordEnumerator(listBucketsRequest);
                foreach (BucketSummary bucketSummary in bucketSummaries)
                {
                    if (bucketSummary.Name.Equals(bucketName))
                    {
                        logger.Info($"Bucket summary with tags: Bucket Name: {bucketSummary.Name}");
                        logger.Info("======================================");
                        definedTags = bucketSummary.DefinedTags;
                        foreach (KeyValuePair <string, Dictionary <string, object> > kvp in definedTags)
                        {
                            foreach (KeyValuePair <string, object> tags in kvp.Value)
                            {
                                logger.Info($"tag key name: {tags.Key} and tag value is {tags.Value}");
                            }
                        }
                    }
                }

                /*
                 * We can also update tags on a bucket. Note that this is a total replacement for any
                 * previously set freeform or defined tags.
                 */
                Dictionary <string, string> updateFreeformTags = new Dictionary <string, string>()
                {
                    { "new", "freeform" }
                };

                Dictionary <string, object> updateDefinedTagsMap = new Dictionary <string, object>()
                {
                    { tagName, "replaced" }
                };
                Dictionary <string, Dictionary <string, object> > updateDefinedTags = new Dictionary <string, Dictionary <string, object> >()
                {
                    { tagNamespace, updateDefinedTagsMap }
                };

                UpdateBucketDetails updateBucketDetails = new UpdateBucketDetails
                {
                    Name         = bucketName,
                    FreeformTags = updateFreeformTags,
                    DefinedTags  = updateDefinedTags
                };
                UpdateBucketRequest updateBucketRequest = new UpdateBucketRequest
                {
                    NamespaceName       = nSpace,
                    BucketName          = bucketName,
                    UpdateBucketDetails = updateBucketDetails
                };
                UpdateBucketResponse updateBucketResponse = await osClient.UpdateBucket(updateBucketRequest);

                logger.Info($"Updated the bucket with new tags Bucket name: {updateBucketResponse.Bucket.Name}");
                logger.Info("==============================================");
                definedTags = updateBucketResponse.Bucket.DefinedTags;
                foreach (KeyValuePair <string, Dictionary <string, object> > kvp in definedTags)
                {
                    foreach (KeyValuePair <string, object> tags in kvp.Value)
                    {
                        logger.Info($"tag key name: {tags.Key} and tag value is {tags.Value}");
                    }
                }

                updateBucketDetails = new UpdateBucketDetails
                {
                    Name         = bucketName,
                    FreeformTags = new Dictionary <string, string>(),
                    DefinedTags  = new Dictionary <string, Dictionary <string, object> >()
                };
                updateBucketRequest = new UpdateBucketRequest
                {
                    NamespaceName       = nSpace,
                    BucketName          = bucketName,
                    UpdateBucketDetails = updateBucketDetails
                };
                updateBucketResponse = await osClient.UpdateBucket(updateBucketRequest);

                logger.Info($"cleared the tags for the bucket: {updateBucketResponse.Bucket.Name}");
                logger.Info("=================================");

                // Clean up
                DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest
                {
                    NamespaceName = nSpace,
                    BucketName    = bucketName
                };
                await osClient.DeleteBucket(deleteBucketRequest);

                logger.Info("Deleted the bucket");
                logger.Info("Ending example.");
            }
            catch (Exception e)
            {
                logger.Error($"Failed Object Storage example: {e.Message}");
            }
            finally
            {
                osClient.Dispose();
            }
        }
Example #7
0
 /// <summary>
 /// Update an existing bucket.
 /// </summary>
 /// <param name="request">The <see cref="UpdateBucketRequest"/> to send.</param>
 /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception>
 /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception>
 async Task <IApiResults <UpdateBucketResponse> > IStorageBuckets.UpdateAsync
     (UpdateBucketRequest request)
 {
     return(await _client.UpdateBucketAsync(request, _cancellationToken));
 }