예제 #1
0
        internal virtual GetNamespaceResponse GetNamespace(GetNamespaceRequest request)
        {
            var marshaller   = GetNamespaceRequestMarshaller.Instance;
            var unmarshaller = GetNamespaceResponseUnmarshaller.Instance;

            return(Invoke <GetNamespaceRequest, GetNamespaceResponse>(request, marshaller, unmarshaller));
        }
예제 #2
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetNamespace operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetNamespace operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/servicediscovery-2017-03-14/GetNamespace">REST API Reference for GetNamespace Operation</seealso>
        public virtual Task <GetNamespaceResponse> GetNamespaceAsync(GetNamespaceRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = GetNamespaceRequestMarshaller.Instance;
            var unmarshaller = GetNamespaceResponseUnmarshaller.Instance;

            return(InvokeAsync <GetNamespaceRequest, GetNamespaceResponse>(request, marshaller,
                                                                           unmarshaller, cancellationToken));
        }
예제 #3
0
        internal virtual GetNamespaceResponse GetNamespace(GetNamespaceRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetNamespaceRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetNamespaceResponseUnmarshaller.Instance;

            return(Invoke <GetNamespaceResponse>(request, options));
        }
예제 #4
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetNamespace operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetNamespace operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/servicediscovery-2017-03-14/GetNamespace">REST API Reference for GetNamespace Operation</seealso>
        public virtual Task <GetNamespaceResponse> GetNamespaceAsync(GetNamespaceRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetNamespaceRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetNamespaceResponseUnmarshaller.Instance;

            return(InvokeAsync <GetNamespaceResponse>(request, options, cancellationToken));
        }
예제 #5
0
        /// <summary>
        /// Creates a waiter using the provided configuration.
        /// </summary>
        /// <param name="request">Request to send.</param>
        /// <param name="config">Wait Configuration</param>
        /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
        /// <returns>a new Oci.common.Waiter instance</returns>
        public Waiter <GetNamespaceRequest, GetNamespaceResponse> ForNamespace(GetNamespaceRequest request, WaiterConfiguration config, params LifecycleState[] targetStates)
        {
            var agent = new WaiterAgent <GetNamespaceRequest, GetNamespaceResponse>(
                request,
                request => client.GetNamespace(request),
                response => targetStates.Contains(response.Namespace.LifecycleState.Value),
                targetStates.Contains(LifecycleState.Deleted)
                );

            return(new Waiter <GetNamespaceRequest, GetNamespaceResponse>(config, agent));
        }
예제 #6
0
        /// <summary>
        /// Each Oracle Cloud Infrastructure tenant is assigned one unique and uneditable Object Storage namespace.
        /// The namespace is a system-generated string assigned during account creation. For some older tenancies,
        /// the namespace string may be the tenancy name in all lower-case letters. You cannot edit a namespace.
        ///GetNamespace returns the name of the Object Storage namespace for the user making the request.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public string GetNamespace(GetNamespaceRequest request)
        {
            var uri = new Uri($"{GetEndPointNoneVersion(ObjectStorageServices.Namespace, this.Region)}/");

            var webResponse = this.RestClient.Get(uri, new HttpRequestHeaderParam {
                OpcClientRequestId = request.OpcClientRequestId
            });

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

                    return(JsonSerializer.Deserialize <string>(response));
                }
        }
예제 #7
0
        private void HandleOutput(GetNamespaceRequest request)
        {
            var waiterConfig = new WaiterConfiguration
            {
                MaxAttempts           = MaxWaitAttempts,
                GetNextDelayInSeconds = (_) => WaitIntervalSeconds
            };

            switch (ParameterSetName)
            {
            case LifecycleStateParamSet:
                response = client.Waiters.ForNamespace(request, waiterConfig, WaitForLifecycleState).Execute();
                break;

            case Default:
                response = client.GetNamespace(request).GetAwaiter().GetResult();
                break;
            }
            WriteOutput(response, response.Namespace);
        }
예제 #8
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetNamespaceRequest request;

            try
            {
                request = new GetNamespaceRequest
                {
                    NamespaceName = NamespaceName,
                    OpcRequestId  = OpcRequestId
                };

                response = client.GetNamespace(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Namespace);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
예제 #9
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetNamespaceRequest request;

            try
            {
                request = new GetNamespaceRequest
                {
                    CatalogId    = CatalogId,
                    NamespaceId  = NamespaceId,
                    Fields       = Fields,
                    OpcRequestId = OpcRequestId
                };

                HandleOutput(request);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
예제 #10
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();
            }
        }
예제 #11
0
        public static void DisplayObjectStorage(ClientConfig config)
        {
            var client = new ObjectStorageClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            // get namespace
            GetNamespaceRequest getNamespaceRequest = new GetNamespaceRequest();
            var namespaceName = client.GetNamespace(getNamespaceRequest);

            // get namespace metadata
            GetNamespaceMetadataRequest getNamespaceMetadataRequest = new GetNamespaceMetadataRequest()
            {
                NamespaceName = namespaceName
            };
            var namespaceMetadata = client.GetNamespaceMetadata(getNamespaceMetadataRequest).NamespaceMetadata;

            Console.WriteLine("* Namespace------------------------");
            Console.WriteLine($" namespace : {namespaceMetadata.Namespace}");
            Console.WriteLine($" defaultS3CompartmentId : {namespaceMetadata.DefaultS3CompartmentId}");
            Console.WriteLine($" defaultSwiftCompartmentId : {namespaceMetadata.DefaultSwiftCompartmentId}");

            // list bucket
            ListBucketsRequest listBucketsRequest = new ListBucketsRequest()
            {
                NamespaceName = namespaceName,
                CompartmentId = config.TenancyId
            };
            var listBucket = client.ListBuckets(listBucketsRequest);

            Console.WriteLine($"* Bucket------------------------");
            Console.WriteLine($" namespace : {namespaceName}");
            Console.WriteLine($" comaprtment : {config.TenancyId}");

            listBucket.Items.ForEach(bucket => {
                HeadBucketRequest headBucketRequest = new HeadBucketRequest()
                {
                    NamespaceName = bucket.Namespace,
                    BucketName    = bucket.Name
                };
                var buckethead = client.HeadBucket(headBucketRequest);

                // get bucket details
                GetBucketRequest getBucketRequest = new GetBucketRequest()
                {
                    NamespaceName = bucket.Namespace,
                    BucketName    = bucket.Name,
                    IfMatch       = buckethead.ETag
                };
                var bucketDetail = client.GetBucket(getBucketRequest);
                Console.WriteLine($"\t|- name : {bucketDetail.Bucket.Name}");
                Console.WriteLine($"\t|  timeCreated : {bucketDetail.Bucket.TimeCreated}");

                Console.WriteLine($"\t|* Object------------------------");
                ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
                {
                    NamespaceName = bucketDetail.Bucket.Namespace,
                    BucketName    = bucketDetail.Bucket.Name
                };
                var Objs = client.ListObjects(listObjectsRequest);
                Objs.ListObjects.Objects.ForEach(obj => {
                    Console.WriteLine($"\t|\t|- name : {obj.Name}");

                    GetObjectRequest getObjectRequest = new GetObjectRequest()
                    {
                        NamespaceName = bucketDetail.Bucket.Namespace,
                        BucketName    = bucketDetail.Bucket.Name,
                        ObjectName    = obj.Name,
                    };
                    var ObjDetails = client.GetObject(getObjectRequest);
                    Console.WriteLine($"\t|\t|- contentLength : {ObjDetails.ContentLength}");

                    // download
                    if (!Directory.Exists("./ExampleDownload"))
                    {
                        Directory.CreateDirectory("./ExampleDownload");
                    }
                    if (!File.Exists($"./ExampleDownload/{obj.Name.Replace('/', '_')}"))
                    {
                        client.DownloadObject(getObjectRequest, "./ExampleDownload/", obj.Name.Replace('/', '_'));
                    }
                });
            });

            // UsageReport
            // Example policy:
            // define tenancy usage-report as ocid1.tenancy.oc1..aaaaaaaaned4fkpkisbwjlr56u7cj63lf3wffbilvqknstgtvzub7vhqkggq
            // endorse group group_name to read objects in tenancy usage-report
            try
            {
                var listORequest = new ListObjectsRequest()
                {
                    NamespaceName = "bling",
                    BucketName    = config.TenancyId
                };
                var reports = client.ListObjects(listORequest);
                Console.WriteLine($"* UsageReport------------------------");
                reports.ListObjects.Objects.ForEach(r =>
                {
                    Console.WriteLine($"  {r.Name}");
                    if (!Directory.Exists("./ExampleDownload/report"))
                    {
                        Directory.CreateDirectory("./ExampleDownload/report");
                    }

                    // download object

                    /*
                     * if (!File.Exists($"./ExampleDownload/report/{r.Name.Replace('/', '_')}"))
                     * {
                     *  var getObjectRequest = new GetObjectRequest()
                     *  {
                     *      NamespaceName = "bling",
                     *      BucketName = config.TenancyId,
                     *      ObjectName = r.Name,
                     *  };
                     *  client.DownloadObject(getObjectRequest, "./ExampleDownload/report/", r.Name.Replace('/', '_'));
                     * }*/
                });
            } catch (Exception e)
            {
                Console.WriteLine($"Does not meet UsageReport usage requirements. message:{e.Message}");
            }
        }
        public static void DisplayObjectStorage(ClientConfig config)
        {
            var client = new ObjectStorageClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            var identityClient = new IdentityClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            // get namespace
            GetNamespaceRequest getNamespaceRequest = new GetNamespaceRequest();
            var namespaceName = client.GetNamespace(getNamespaceRequest);

            // get namespace metadata
            GetNamespaceMetadataRequest getNamespaceMetadataRequest = new GetNamespaceMetadataRequest()
            {
                NamespaceName = namespaceName
            };
            var namespaceMetadata = client.GetNamespaceMetadata(getNamespaceMetadataRequest).NamespaceMetadata;

            Console.WriteLine("* Namespace------------------------");
            Console.WriteLine($" namespace : {namespaceMetadata.Namespace}");
            Console.WriteLine($" defaultS3CompartmentId : {namespaceMetadata.DefaultS3CompartmentId}");
            Console.WriteLine($" defaultSwiftCompartmentId : {namespaceMetadata.DefaultSwiftCompartmentId}");

            Console.WriteLine();
            Console.WriteLine("ObjectStorage Example Menu");
            Console.WriteLine("[1]: Display List");
            Console.WriteLine("[2]: Upload Example");
            Console.WriteLine("[3]: UsageReport Example");
            Console.WriteLine("[ESC] or [E(e)] : Back Example Menu");
            Console.WriteLine();

            var presskey = Console.ReadKey(true);

            if (presskey.Key == ConsoleKey.Escape || presskey.KeyChar == 'E' || presskey.KeyChar == 'e')
            {
                Console.WriteLine("Back Example Menu");
                return;
            }
            var select = presskey.KeyChar;

            if (!int.TryParse(select.ToString(), out int mode))
            {
                Console.WriteLine("Incorrect input...");
                return;
            }

            if (mode == 1)
            {
                DisplayBucketAndObject(config, namespaceName, client, identityClient);
            }
            else if (mode == 2)
            {
                PutObject(config, namespaceName, client);
            }
            else if (mode == 3)
            {
                DisplayUsageReport(config, client);
            }
            else
            {
                Console.WriteLine("Incorrect input...");
                return;
            }
        }
예제 #13
0
 /// <summary>
 /// Creates a waiter using default wait configuration.
 /// </summary>
 /// <param name="request">Request to send.</param>
 /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
 /// <returns>a new Oci.common.Waiter instance</returns>
 public Waiter <GetNamespaceRequest, GetNamespaceResponse> ForNamespace(GetNamespaceRequest request, params LifecycleState[] targetStates)
 {
     return(this.ForNamespace(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates));
 }