// This is an automatically generated code sample.
// To make this code sample work in your Oracle Cloud tenancy,
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
// boolean, number, and enum parameters with values not fitting your use case).

import * as certificatesmanagement from "oci-certificatesmanagement";
import common = require("oci-common");

// Create a default authentication provider that uses the DEFAULT
// profile in the configuration file.
// Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file.

const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider();

(async () => {
  try {
    // Create a service client
    const client = new certificatesmanagement.CertificatesManagementClient({
      authenticationDetailsProvider: provider
    });

    // Create a request and dependent object(s).
    const updateCertificateAuthorityDetails = {
      description: "EXAMPLE-description-Value",
      currentVersionNumber: 650,
      certificateAuthorityConfig: {
        configType: "ROOT_CA_GENERATED_INTERNALLY",
        validity: {
          timeOfValidityNotBefore: new Date("Sat May 15 17:40:42 UTC 2021"),
          timeOfValidityNotAfter: new Date("Sat Nov 19 10:40:29 UTC 2005")
        },
        versionName: "EXAMPLE-versionName-Value",
        stage: certificatesmanagement.models.UpdateCertificateAuthorityConfigDetails.Stage.Current
      },
      certificateRevocationListDetails: {
        objectStorageConfig: {
          objectStorageNamespace: "EXAMPLE-objectStorageNamespace-Value",
          objectStorageBucketName: "EXAMPLE-objectStorageBucketName-Value",
          objectStorageObjectNameFormat: "EXAMPLE-objectStorageObjectNameFormat-Value"
        },
        customFormattedUrls: ["EXAMPLE--Value"]
      },
      freeformTags: {
        EXAMPLE_KEY_qXzP6: "EXAMPLE_VALUE_PvC4n8eoZ5B4wkElNiGH"
      },
      definedTags: {
        EXAMPLE_KEY_Mcnze: {
          EXAMPLE_KEY_POxhC: "EXAMPLE--Value"
        }
      },
      certificateAuthorityRules: [
        {
          ruleType: "CERTIFICATE_AUTHORITY_ISSUANCE_EXPIRY_RULE",
          leafCertificateMaxValidityDuration: "EXAMPLE-leafCertificateMaxValidityDuration-Value",
          certificateAuthorityMaxValidityDuration:
            "EXAMPLE-certificateAuthorityMaxValidityDuration-Value"
        }
      ]
    };

    const updateCertificateAuthorityRequest: certificatesmanagement.requests.UpdateCertificateAuthorityRequest = {
      certificateAuthorityId: "ocid1.test.oc1..<unique_ID>EXAMPLE-certificateAuthorityId-Value",
      updateCertificateAuthorityDetails: updateCertificateAuthorityDetails,
      opcRequestId: "AQWFSR0GIQCUMRFNENBI<unique_ID>",
      ifMatch: "EXAMPLE-ifMatch-Value"
    };

    // Send request to the Client.
    const updateCertificateAuthorityResponse = await client.updateCertificateAuthority(
      updateCertificateAuthorityRequest
    );
  } catch (error) {
    console.log("updateCertificateAuthority Failed with error  " + error);
  }
})();