text: #!/usr/bin/python
  # Copyright (c) 2020, 2021 Oracle and/or its affiliates.
  # This software is made available to you under the terms of the GPL 3.0 license or the Apache 2.0 license.
  # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
  # Apache License v2.0
  # See LICENSE.TXT for details.
  # GENERATED FILE - DO NOT EDIT - MANUAL CHANGES WILL BE OVERWRITTEN
  
  
  from __future__ import absolute_import, division, print_function
  
  __metaclass__ = type
  
  ANSIBLE_METADATA = {
      "metadata_version": "1.1",
      "status": ["preview"],
      "supported_by": "community",
  }
  
  DOCUMENTATION = """
  ---
  module: oci_apigateway_certificate_actions
  short_description: Perform actions on a Certificate resource in Oracle Cloud Infrastructure
  description:
      - Perform actions on a Certificate resource in Oracle Cloud Infrastructure
      - For I(action=change_compartment), changes the certificate compartment.
  version_added: "2.9.0"
  author: Oracle (@oracle)
  options:
      certificate_id:
          description:
              - The ocid of the certificate.
          type: str
          aliases: ["id"]
          required: true
      compartment_id:
          description:
              - The L(OCID,https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm) of the compartment in which the
                resource is created.
          type: str
          required: true
      action:
          description:
              - The action to perform on the Certificate.
          type: str
          required: true
          choices:
              - "change_compartment"
  extends_documentation_fragment: [ oracle.oci.oracle ]
  """
  
  EXAMPLES = """
  - name: Perform action change_compartment on certificate
    oci_apigateway_certificate_actions:
      # required
      certificate_id: "ocid1.certificate.oc1..xxxxxxEXAMPLExxxxxx"
      compartment_id: "ocid1.compartment.oc1..xxxxxxEXAMPLExxxxxx"
      action: change_compartment
  
  """
  
  RETURN = """
  certificate:
      description:
          - Details of the Certificate resource acted upon by the current operation
      returned: on success
      type: complex
      contains:
          id:
              description:
                  - The L(OCID,https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm) of the resource.
              returned: on success
              type: str
              sample: "ocid1.resource.oc1..xxxxxxEXAMPLExxxxxx"
          display_name:
              description:
                  - A user-friendly name. Does not have to be unique, and it's changeable.
                    Avoid entering confidential information.
                  - "Example: `My new resource`"
              returned: on success
              type: str
              sample: My new resource
          compartment_id:
              description:
                  - The L(OCID,https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm) of the compartment in which the
                    resource is created.
              returned: on success
              type: str
              sample: "ocid1.compartment.oc1..xxxxxxEXAMPLExxxxxx"
          subject_names:
              description:
                  - The entity to be secured by the certificate and additional host names.
              returned: on success
              type: list
              sample: []
          time_not_valid_after:
              description:
                  - The date and time the certificate will expire.
              returned: on success
              type: str
              sample: "2013-10-20T19:20:30+01:00"
          certificate:
              description:
                  - The data of the leaf certificate in pem format.
              returned: on success
              type: str
              sample: "-----BEGIN CERTIFICATE----MIIBIjANBgkqhkiG9w0BA..-----END PUBLIC KEY-----"
          intermediate_certificates:
              description:
                  - The intermediate certificate data associated with the certificate in pem format.
              returned: on success
              type: str
              sample: intermediate_certificates_example
          time_created:
              description:
                  - The time this resource was created. An RFC3339 formatted datetime string.
              returned: on success
              type: str
              sample: "2013-10-20T19:20:30+01:00"
          time_updated:
              description:
                  - The time this resource was last updated. An RFC3339 formatted datetime string.
              returned: on success
              type: str
              sample: "2013-10-20T19:20:30+01:00"
          lifecycle_state:
              description:
                  - The current state of the certificate.
              returned: on success
              type: str
              sample: CREATING
          lifecycle_details:
              description:
                  - A message describing the current state in more detail.
                    For example, can be used to provide actionable information for a
                    resource in a Failed state.
              returned: on success
              type: str
              sample: lifecycle_details_example
          freeform_tags:
              description:
                  - Free-form tags for this resource. Each tag is a simple key-value pair
                    with no predefined name, type, or namespace. For more information, see
                    L(Resource Tags,https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm).
                  - "Example: `{\\"Department\\": \\"Finance\\"}`"
              returned: on success
              type: dict
              sample: {'Department': 'Finance'}
          defined_tags:
              description:
                  - Defined tags for this resource. Each key is predefined and scoped to a
                    namespace. For more information, see
                    L(Resource Tags,https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm).
                  - "Example: `{\\"Operations\\": {\\"CostCenter\\": \\"42\\"}}`"
              returned: on success
              type: dict
              sample: {'Operations': {'CostCenter': 'US'}}
      sample: {
          "id": "ocid1.resource.oc1..xxxxxxEXAMPLExxxxxx",
          "display_name": "My new resource",
          "compartment_id": "ocid1.compartment.oc1..xxxxxxEXAMPLExxxxxx",
          "subject_names": [],
          "time_not_valid_after": "2013-10-20T19:20:30+01:00",
          "certificate": "-----BEGIN CERTIFICATE----MIIBIjANBgkqhkiG9w0BA..-----END PUBLIC KEY-----",
          "intermediate_certificates": "intermediate_certificates_example",
          "time_created": "2013-10-20T19:20:30+01:00",
          "time_updated": "2013-10-20T19:20:30+01:00",
          "lifecycle_state": "CREATING",
          "lifecycle_details": "lifecycle_details_example",
          "freeform_tags": {'Department': 'Finance'},
          "defined_tags": {'Operations': {'CostCenter': 'US'}}
      }
  """
  
  from ansible.module_utils.basic import AnsibleModule
  from ansible_collections.oracle.oci.plugins.module_utils import (
      oci_common_utils,
      oci_wait_utils,
      oci_config_utils,
  )
  from ansible_collections.oracle.oci.plugins.module_utils.oci_resource_utils import (
      OCIActionsHelperBase,
      get_custom_class,
  )
  
  try:
      from oci.apigateway import WorkRequestsClient
      from oci.apigateway import ApiGatewayClient
      from oci.apigateway.models import ChangeCertificateCompartmentDetails
  
      HAS_OCI_PY_SDK = True
  except ImportError:
      HAS_OCI_PY_SDK = False
  
  
  class ApigatewayCertificateActionsHelperGen(OCIActionsHelperBase):
      """
      Supported actions:
          change_compartment
      """
  
      def get_waiter_client(self):
          return oci_config_utils.create_service_client(self.module, WorkRequestsClient)
  
      @staticmethod
      def get_module_resource_id_param():
          return "certificate_id"
  
      def get_module_resource_id(self):
          return self.module.params.get("certificate_id")
  
      def get_get_fn(self):
          return self.client.get_certificate
  
      def get_resource(self):
          return oci_common_utils.call_with_backoff(
              self.client.get_certificate,
              certificate_id=self.module.params.get("certificate_id"),
          )
  
      def change_compartment(self):
          action_details = oci_common_utils.convert_input_data_to_model_class(
              self.module.params, ChangeCertificateCompartmentDetails
          )
          return oci_wait_utils.call_and_wait(
              call_fn=self.client.change_certificate_compartment,
              call_fn_args=(),
              call_fn_kwargs=dict(
                  certificate_id=self.module.params.get("certificate_id"),
                  change_certificate_compartment_details=action_details,
              ),
              waiter_type=oci_wait_utils.NONE_WAITER_KEY,
              operation="{0}_{1}".format(
                  self.module.params.get("action").upper(),
                  oci_common_utils.ACTION_OPERATION_KEY,
              ),
              waiter_client=self.get_waiter_client(),
              resource_helper=self,
              wait_for_states=self.get_action_desired_states(
                  self.module.params.get("action")
              ),
          )
  
  
  ApigatewayCertificateActionsHelperCustom = get_custom_class(
      "ApigatewayCertificateActionsHelperCustom"
  )
  
  
  class ResourceHelper(
      ApigatewayCertificateActionsHelperCustom, ApigatewayCertificateActionsHelperGen
  ):
      pass
  
  
  def main():
      module_args = oci_common_utils.get_common_arg_spec(
          supports_create=False, supports_wait=False
      )
      module_args.update(
          dict(
              certificate_id=dict(aliases=["id"], type="str", required=True),
              compartment_id=dict(type="str", required=True),
              action=dict(type="str", required=True, choices=["change_compartment"]),
          )
      )
  
      module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
  
      if not HAS_OCI_PY_SDK:
          module.fail_json(msg="oci python sdk required for this module.")
  
      resource_helper = ResourceHelper(
          module=module,
          resource_type="certificate",
          service_client_class=ApiGatewayClient,
          namespace="apigateway",
      )
  
      result = resource_helper.perform_action(module.params.get("action"))
  
      module.exit_json(**result)
  
  
  if __name__ == "__main__":
      main()
  