Exemple #1
0
        /// <summary>
        /// Get a list of DB Systems in the specified compartment.
        /// The default sort order is by timeUpdated, descending.
        ///
        /// </summary>
        /// <param name="request">The request object containing the details to send. Required.</param>
        /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param>
        /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param>
        /// <returns>A response object containing details about the completed operation</returns>
        /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/mysql/ListDbSystems.cs.html">here</a> to see an example of how to use ListDbSystems API.</example>
        public async Task <ListDbSystemsResponse> ListDbSystems(ListDbSystemsRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called listDbSystems");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/dbSystems".Trim('/')));
            HttpMethod         method         = new HttpMethod("GET");
            HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request);

            requestMessage.Headers.Add("Accept", "application/json");
            GenericRetrier      retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration);
            HttpResponseMessage responseMessage;

            try
            {
                if (retryingClient != null)
                {
                    responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false);
                }
                this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage);

                return(Converter.FromHttpResponseMessage <ListDbSystemsResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"ListDbSystems failed with error: {e.Message}");
                throw;
            }
        }
Exemple #2
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListDbSystemsRequest request;

            try
            {
                request = new ListDbSystemsRequest
                {
                    CompartmentId      = CompartmentId,
                    Limit              = Limit,
                    Page               = Page,
                    BackupId           = BackupId,
                    SortBy             = SortBy,
                    SortOrder          = SortOrder,
                    LifecycleState     = LifecycleState,
                    AvailabilityDomain = AvailabilityDomain,
                    DisplayName        = DisplayName
                };
                IEnumerable <ListDbSystemsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
 /// <summary>
 /// Creates a new enumerable which will iterate over the responses received from the ListDbSystems operation. This enumerable
 /// will fetch more data from the server as needed.
 /// </summary>
 /// <param name="request">The request object containing the details to send</param>
 /// <param name="retryConfiguration">The configuration for retrying, may be null</param>
 /// <param name="cancellationToken">The cancellation token object</param>
 /// <returns>The enumerator, which supports a simple iteration over a collection of a specified type</returns>
 public IEnumerable <ListDbSystemsResponse> ListDbSystemsResponseEnumerator(ListDbSystemsRequest request, Common.Retry.RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
 {
     return(new Common.Utils.ResponseEnumerable <ListDbSystemsRequest, ListDbSystemsResponse>(
                response => response.OpcNextPage,
                input =>
     {
         if (!string.IsNullOrEmpty(input))
         {
             request.Page = input;
         }
         return request;
     },
                request => client.ListDbSystems(request, retryConfiguration, cancellationToken)
                ));
 }
Exemple #4
0
        /// <summary>
        /// Gets a list of the DB systems in the specified compartment.
        /// You can specify a backupId to list only the DB systems that support creating a database using this backup in this compartment.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ListDbSystemsResponse> ListDbSystems(ListDbSystemsRequest request)
        {
            var uri = new Uri($"{GetEndPoint(DatabaseServices.DbSystems, this.Region)}?{request.GetOptionQuery()}");

            using (var webResponse = await this.RestClientAsync.Get(uri))
                using (var stream = webResponse.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        var response = await reader.ReadToEndAsync();

                        return(new ListDbSystemsResponse()
                        {
                            Items = this.JsonSerializer.Deserialize <List <DbSystemSummary> >(response),
                            OpcRequestId = webResponse.Headers.Get("opc-request-id"),
                            OpcNextPage = webResponse.Headers.Get("opc-next-page")
                        });
                    }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListDbSystemsRequest request;

            try
            {
                request = new ListDbSystemsRequest
                {
                    CompartmentId = CompartmentId,
                    OpcRequestId  = OpcRequestId,
                    IsAnalyticsClusterAttached = IsAnalyticsClusterAttached,
                    IsHeatWaveClusterAttached  = IsHeatWaveClusterAttached,
                    DbSystemId      = DbSystemId,
                    DisplayName     = DisplayName,
                    LifecycleState  = LifecycleState,
                    ConfigurationId = ConfigurationId,
                    IsUpToDate      = IsUpToDate,
                    SortBy          = SortBy,
                    SortOrder       = SortOrder,
                    Limit           = Limit,
                    Page            = Page
                };
                IEnumerable <ListDbSystemsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
        static async Task MainEncryptedKeyAuthentication(string[] args)
        {
            string         compartmentId  = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");
            DatabaseClient databaseClient = null;

            logger.Info("Starting example");

            try
            {
                // Instead of hardcoding the values here,
                // keyPath and passPhrase should be obtained through environment variables or
                // parameters to this function.
                // The caller is responsible for securely providing the values.
                string       keyPath    = "/path/to/some/api_key_with_passphrase.pem";
                char[]       chars      = { 's', 'o', 'm', 'e', 'p', 'a', 's', 's', 'p', 'h', 'r', 'a', 's', 'e' };
                SecureString passPhrase = new SecureString();
                foreach (char c in chars)
                {
                    passPhrase.AppendChar(c);
                }

                // Build FileSecurePrivateKeySupplier
                // It ensures that private key length is at least 2048,
                // private key is encrypted with a passphrase, and
                // only CBC chaining mode is allowed
                FileSecurePrivateKeySupplier keySupplier = new FileSecurePrivateKeySupplier(keyPath, passPhrase);

                // There are a few ways to provide config information.
                // 1. In addition to normal profile parameter, also provide the keySupplier.
                var providerFromFileAndSupplier = new ConfigFileAuthenticationDetailsProvider(OciConfigProfileName, keySupplier);
                // 2. Provide a custom config path plus keySupplier.
                var providerFromCustomFileAndSupplier = new ConfigFileAuthenticationDetailsProvider("/some/custom/path/to/config", OciConfigProfileName, keySupplier);
                // 3. Build a ConfigFile object plus keySupplier.
                ConfigFile.ConfigAccumulator accumulator = new ConfigFile.ConfigAccumulator();
                Dictionary <string, string>  entries     = new Dictionary <string, string>();
                entries.Add("user", "ocid1.user.oc1..somefakeuserocid");
                entries.Add("fingerprint", "somefakefingerprint");
                entries.Add("tenancy", "ocid1.tenancy.oc1..somefaketenancyocid");
                entries.Add("region", "us-phoenix-1");
                accumulator.configurationByProfile.Add(OciConfigProfileName, entries);;
                ConfigFile configFile = new ConfigFile(accumulator, OciConfigProfileName);
                var        providerFromConfigAndSupplier = new ConfigFileAuthenticationDetailsProvider(configFile, keySupplier);

                // Create Database service client with any of the authentication details providers above
                databaseClient = new DatabaseClient(providerFromFileAndSupplier);
                // databaseClient = new DatabaseClient(providerFromCustomFileAndSupplier);
                // databaseClient = new DatabaseClient(providerFromConfigAndSupplier);

                // Call ListDbSystems Operation
                ListDbSystemsRequest listDbSystemsRequest = new ListDbSystemsRequest
                {
                    CompartmentId = compartmentId
                };
                ListDbSystemsResponse listDbSystemsResponse = await databaseClient.ListDbSystems(listDbSystemsRequest);

                logger.Info($"Found {listDbSystemsResponse.Items.Count} DbSystems");
                foreach (var dbSystem in listDbSystemsResponse.Items)
                {
                    logger.Info($"DbSystem Name: {dbSystem.DisplayName}");
                }
            }
            catch (Exception e)
            {
                logger.Error($"Got exception: {e.Message}");
            }
            finally
            {
                if (databaseClient != null)
                {
                    databaseClient.Dispose();
                }
            }
            logger.Info("End Example");
        }