- help_text:
    brief: Create a Cloud Build Connection for Bitbucket Data Center.
    description: |
      Create a Cloud Build Connection for Bitbucket Data Center.

      A Bitbucket Data Center Connection can be created by using a personal access token with `REPO_ADMIN`
      scope permission. A `REPO_READ` scoped personal access token will also be required.

      If the Bitbucket Data Center can only be accessed within a VPC, a Service Directory
      service resource can be provided for connecting to it.

    examples: |
      To create a Bitbucket Data Center connection, provide all the required parameters:

        $ {command} my-bitbucket-conn \
          --project=myproj --region=us-central1 \
          --host-uri=https://bitbucket-server.net \
          --read-authorizer-token-secret-version=projects/myproj/secrets/read-pat/versions/1 \
          --authorizer-token-secret-version=projects/myproj/secrets/admin-pat/versions/1 \
          --webhook-secret-secret-version=projects/myproj/secrets/whsecret/versions/1

      To create a Bitbucket Data Center connection for a private Bitbucket Data Center server.
      Provide the service-directory-service and ssl-ca-file as well:

        $ {command} my-private-bitbucket-conn \
          --host-uri=https://my.private-bitbucket-server.net \
          --project=myproj --region=us-central1 \
          --service-directory-service=projects/myproj/namespaces/x/services/mysds \
          --ssl-ca-file=mycertificate.crt \
          --authorizer-token-secret-version=projects/myproj/secrets/admin-pat/versions/1 \
          --read-authorizer-token-secret-version=projects/myproj/secrets/read-pat/versions/1 \
          --webhook-secret-secret-version=projects/myproj/secrets/whsecret/versions/1

  command_type: CREATE
  request:
    collection: cloudbuild.projects.locations.connections
    api_version: v2
  arguments:
    resource:
      help_text: Connection to create.
      spec: !REF googlecloudsdk.command_lib.cloudbuild.resources_v2:connection
    params:
    - api_field: connection.bitbucketDataCenterConfig.hostUri
      arg_name: host-uri
      help_text: URI of the Bitbucket Data Center instance.
    - api_field: connection.bitbucketDataCenterConfig.authorizerCredential.userTokenSecretVersion
      arg_name: authorizer-token-secret-version
      help_text: Secret containing the REPO_ADMIN personal access token.
      required: true
    - api_field: connection.bitbucketDataCenterConfig.readAuthorizerCredential.userTokenSecretVersion
      arg_name: read-authorizer-token-secret-version
      help_text: Secret containing the REPO_READ personal access token.
      required: true
    - api_field: connection.bitbucketDataCenterConfig.webhookSecretSecretVersion
      arg_name: webhook-secret-secret-version
      required: true
      help_text: |-
        Secret containing the webhook secret string for validating webhook events sent by
        Bitbucket Data Center.
    - group:
        help_text: Group of arguments for configuring access through Service Directory.
        params:
        - api_field: connection.bitbucketDataCenterConfig.serviceDirectoryConfig.service
          arg_name: service-directory-service
          required: true
          help_text: Service Directory service resource to use for accessing the Bitbucket Data Center. Necessary only if the server has no public access from the internet.
        - api_field: connection.bitbucketDataCenterConfig.sslCa
          arg_name: ssl-ca-file
          help_text: File containing the SSL_CA to be used.
          processor: googlecloudsdk.core.util.files:ReadFileContents
  async:
    collection: cloudbuild.projects.locations.operations
