// 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 createCertificateAuthorityDetails = {
      name: "EXAMPLE-name-Value",
      description: "EXAMPLE-description-Value",
      compartmentId: "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
      certificateAuthorityRules: [
        {
          ruleType: "CERTIFICATE_AUTHORITY_ISSUANCE_EXPIRY_RULE",
          leafCertificateMaxValidityDuration: "EXAMPLE-leafCertificateMaxValidityDuration-Value",
          certificateAuthorityMaxValidityDuration:
            "EXAMPLE-certificateAuthorityMaxValidityDuration-Value"
        }
      ],
      certificateAuthorityConfig: {
        configType: "SUBORDINATE_CA_ISSUED_BY_INTERNAL_CA",
        issuerCertificateAuthorityId:
          "ocid1.test.oc1..<unique_ID>EXAMPLE-issuerCertificateAuthorityId-Value",
        validity: {
          timeOfValidityNotBefore: new Date("Sat Jan 14 02:20:35 UTC 2023"),
          timeOfValidityNotAfter: new Date("Thu Jun 17 05:02:24 UTC 2004")
        },
        signingAlgorithm: certificatesmanagement.models.SignatureAlgorithm.Sha384WithRsa,
        subject: {
          commonName: "EXAMPLE-commonName-Value",
          country: "EXAMPLE-country-Value",
          domainComponent: "EXAMPLE-domainComponent-Value",
          distinguishedNameQualifier: "EXAMPLE-distinguishedNameQualifier-Value",
          generationQualifier: "EXAMPLE-generationQualifier-Value",
          givenName: "EXAMPLE-givenName-Value",
          initials: "EXAMPLE-initials-Value",
          localityName: "EXAMPLE-localityName-Value",
          organization: "EXAMPLE-organization-Value",
          organizationalUnit: "EXAMPLE-organizationalUnit-Value",
          pseudonym: "EXAMPLE-pseudonym-Value",
          serialNumber: "EXAMPLE-serialNumber-Value",
          stateOrProvinceName: "EXAMPLE-stateOrProvinceName-Value",
          street: "EXAMPLE-street-Value",
          surname: "EXAMPLE-surname-Value",
          title: "EXAMPLE-title-Value",
          userId: "ocid1.test.oc1..<unique_ID>EXAMPLE-userId-Value"
        },
        versionName: "EXAMPLE-versionName-Value"
      },
      certificateRevocationListDetails: {
        objectStorageConfig: {
          objectStorageNamespace: "EXAMPLE-objectStorageNamespace-Value",
          objectStorageBucketName: "EXAMPLE-objectStorageBucketName-Value",
          objectStorageObjectNameFormat: "EXAMPLE-objectStorageObjectNameFormat-Value"
        },
        customFormattedUrls: ["EXAMPLE--Value"]
      },
      kmsKeyId: "ocid1.test.oc1..<unique_ID>EXAMPLE-kmsKeyId-Value",
      freeformTags: {
        EXAMPLE_KEY_y06ZH: "EXAMPLE_VALUE_WVc6tXxyDiGsQ6uDXJSp"
      },
      definedTags: {
        EXAMPLE_KEY_dacUV: {
          EXAMPLE_KEY_hqZr9: "EXAMPLE--Value"
        }
      }
    };

    const createCertificateAuthorityRequest: certificatesmanagement.requests.CreateCertificateAuthorityRequest = {
      createCertificateAuthorityDetails: createCertificateAuthorityDetails,
      opcRequestId: "BX2STEDED2FGNJ7NJWSZ<unique_ID>",
      opcRetryToken: "EXAMPLE-opcRetryToken-Value"
    };

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