# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- release_tracks: [ALPHA]
  help_text:
    brief: Creates a Cloud DLP job trigger.
    description: |
      Creates a Cloud DLP job trigger.
    examples: |
      The following command creates a job trigger named `my_job_trigger`:

        $ {command} my_job_trigger --display-name Daily_Inspect_Trigger --description 'My New Trigger' --input-table myproject.mydataset.input --output-topics my-topic --max-findings-per-item 3 --max-findings 1000 --info-types PHONE_NUMBER,US_DRIVERS_LICENSE --min-likelihood very-likely --include-quote --exclude-info-types --trigger-schedule 8400s

  request:
    collection: dlp.projects.jobTriggers
    api_version: v2
    static_fields:
      googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.status: HEALTHY
    modify_request_hooks:
    - googlecloudsdk.command_lib.dlp.hooks:UpdateDataStoreOptions
    - googlecloudsdk.command_lib.util.hooks.request_modifiers:SetFieldFromArg:api_field=googlePrivacyDlpV2CreateJobTriggerRequest.triggerId,arg_name=job_trigger
    - googlecloudsdk.command_lib.dlp.hooks:SetRequestParent

  arguments:
    params:
    - arg_name: description
      api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.description
      is_positional: false
      required: false
      help_text: |
        User provided description (maximum 256 characters)
    - arg_name: display-name
      api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.displayName
      is_positional: false
      required: false
      help_text: |
        Display name of the job trigger (maximum 100 characters)
    - api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.inspectJob.inspectConfig.limits.maxFindingsPerItem
      arg_name: max-findings-per-item
      type: int
      is_positional: false
      required: false
      help_text: |
        Maximum number of findings that will be returned for each item
        scanned.

        If not specified, no limits are applied.
    - api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.triggers.schedule.recurrencePeriodDuration
      arg_name: trigger-schedule
      type: 'googlecloudsdk.calliope.arg_parsers:Duration:'
      processor: googlecloudsdk.command_lib.dlp.hooks:GetJobScheduleDurationString
      is_positional: false
      repeated: false
      required: true
      help_text: |
        Duration specifying how often the triggered job will be run. A
        scheduled start time will be skipped if the previous execution has
        not ended when its scheduled time occurs. Value must be a time
        duration greater than or equal to 1 day and can be no longer
        than 60 days.

        See `$ gcloud topic datetimes for information on duration formats.`
    - group:
        mutex: true
        required: true
        params:
        - arg_name: output-topics
          api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.inspectJob.actions
          type: googlecloudsdk.command_lib.dlp.hooks:PubSubTopicAction
          help_text: |
            Publishes the results of a Cloud DLP job to one or more Cloud Pub/Sub
            topics.

            Note: The topic must have given publishing access rights to the
            DLP API service account executing the Cloud DLP job.
        - arg_name: output-table
          api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.inspectJob.actions
          type: googlecloudsdk.command_lib.dlp.hooks:BigQueryTableAction
          help_text: |
            Publishes results of a Cloud DLP job a BigQuery table.
            BigQuery tables are uniquely identified by their project_id,
            dataset_id, and table_id in the format
            `<project_id>.<dataset_id>.<table_id>`.
    - group:
        mutex: true
        required: true
        params:
        - _REF_: googlecloudsdk.command_lib.dlp.flags:datastore_kind
        - _REF_: googlecloudsdk.command_lib.dlp.flags:gcs_path
        - _REF_: googlecloudsdk.command_lib.dlp.flags:big_query_table
    - _REF_: googlecloudsdk.command_lib.dlp.flags:info_type
      api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.inspectJob.inspectConfig.infoTypes
    - _REF_: googlecloudsdk.command_lib.dlp.flags:min_likelihood
      api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.inspectJob.inspectConfig.minLikelihood
    - _REF_: googlecloudsdk.command_lib.dlp.flags:include_quote
      api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.inspectJob.inspectConfig.includeQuote
    - _REF_: googlecloudsdk.command_lib.dlp.flags:max_findings
      api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.inspectJob.inspectConfig.limits.maxFindingsPerRequest
    - _REF_: googlecloudsdk.command_lib.dlp.flags:exclude_info_types
      api_field: googlePrivacyDlpV2CreateJobTriggerRequest.jobTrigger.inspectJob.inspectConfig.excludeInfoTypes
    resource:
      help_text: |
        The Cloud DLP job trigger to create. The job trigger name can contain
        uppercase and lowercase letters, numbers, and hyphens -- that is, it
        must match the regular expression:`[a-zA-Z\\d-]+`. The maximum length
        is 100 characters. If not supplied, the system generates one.
      spec: !REF googlecloudsdk.command_lib.dlp.resources:job_trigger
