{{if .ShowIf}}
{{if eq (index .ShowIf "postgresql.source") "true"}}
---
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnector
metadata:
  name: "{{ .Name }}-kafka-postgresql"
  namespace: $kafka_cluster_namespace
  labels:
    strimzi.io/cluster: $kafka_cluster_namespace
spec:
  class: io.debezium.connector.postgresql.PostgresConnector
  tasksMax: 6
  config:
    database.hostname: "$database.host"
    database.port: "5432"
    database.user: "$database.user"
    database.password: "$database.password"
    database.dbname: "$database.db"
    table.include.list: "$database.table.include"
    plugin.name: pgoutput
    snapshot.mode: "initial"
    slot.name: "$database.slot"
    publication.autocreate.mode: filtered
    topic.prefix: "{{ .ClusterProjectName }}"
    producer.override.security.protocol: "SASL_PLAINTEXT"
    producer.override.sasl.mechanism: "OAUTHBEARER"
    producer.override.sasl.jaas.config: |
      org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required
        oauth.token.endpoint.uri="$KEYCLOAK_URL/realms/$KEYCLOAK_REALM/protocol/openid-connect/token"
        oauth.client.id="$KAFKA_CLIENT_ID"
        oauth.client.secret="$KAFKA_CLIENT_SECRET"
{{end}}

{{if eq (index .ShowIf "s3.target") "true"}}
---
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnector
metadata:
  name: "{{ .Name }}-kafka-s3"
  namespace: $kafka_cluster_namespace
  labels:
    strimzi.io/cluster: $kafka_cluster_namespace
spec:
  class: io.confluent.connect.s3.S3SinkConnector
  tasksMax: 6
  config:
    topics: "{{ .ClusterProjectName }}.$config.topics"
    store.url: "$s3.url"
    s3.region: us-east-1
    aws.access.key.id: "$s3.accesskey"
    aws.secret.access.key: "$s3.secretkey"
    s3.bucket.name: "$s3.bucket"
    s3.part.size: 5242880
    flush.size: 3
    format.class: io.confluent.connect.s3.format.json.JsonFormat
    storage.class: io.confluent.connect.s3.storage.S3Storage
    schema.compatibility: NONE
    consumer.override.security.protocol: "SASL_PLAINTEXT"
    consumer.override.sasl.mechanism: "OAUTHBEARER"
    consumer.override.sasl.jaas.config: |
      org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required
        oauth.token.endpoint.uri="$KEYCLOAK_URL/realms/$KEYCLOAK_REALM/protocol/openid-connect/token"
        oauth.client.id="$KAFKA_CLIENT_ID"
        oauth.client.secret="$KAFKA_CLIENT_SECRET"
{{end}}

{{if eq (index .ShowIf "star.target") "true"}}
---
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnector
metadata:
  name: "{{ .Name }}-kafka-starrocks"
  namespace: $kafka_cluster_namespace
  labels:
    strimzi.io/cluster: $kafka_cluster_namespace
spec:
  class: com.starrocks.connector.kafka.StarRocksSinkConnector
  tasksMax: 6
  config:
    topics: "{{ .ClusterProjectName }}.$star.config.topics"
    starrocks.http.url: kube-starrocks-fe-service.$star.namespace.svc.cluster.local:8030
    starrocks.database.name: "$star.database.name"
    starrocks.username: "$star.username"
    starrocks.password: "$star.password"
    sink.properties.strip_outer_array: true
    connect.timeoutms: "30000"
    starrocks.topic2table.map: "$star.topic2table"
    transforms: addfield,unwrap
    transforms.addfield.type: com.starrocks.connector.kafka.transforms.AddOpFieldForDebeziumRecord
    transforms.unwrap.type: io.debezium.transforms.ExtractNewRecordState
    transforms.unwarp.drop.tombstones: true
    transforms.unwarp.delete.handling.mode: rewrite 
{{end}}

{{if eq (index .ShowIf "starjson.target") "true"}}
---
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnector
metadata:
  name: "{{ .Name }}-kafka-starrocks"
  namespace: $kafka_cluster_namespace
  labels:
    strimzi.io/cluster: $kafka_cluster_namespace
spec:
  class: com.starrocks.connector.kafka.StarRocksSinkConnector
  tasksMax: 6
  config:
    topics: "{{ .ClusterProjectName }}.$starjson.config.topics"
    starrocks.http.url: kube-starrocks-fe-service.$starjson.namespace.svc.cluster.local:8030
    starrocks.database.name: "$starjson.database.name"
    starrocks.username: "$starjson.username"
    starrocks.password: "$starjson.password"
    sink.properties.strip_outer_array: true
    connect.timeoutms: "30000"
    starrocks.topic2table.map: "$starjson.topic2table"
    key.converter: "org.apache.kafka.connect.json.JsonConverter"
    value.converter: "org.apache.kafka.connect.json.JsonConverter"
    key.converter.schemas.enable: "true"
    value.converter.schemas.enable: "false"
{{end}}
{{end}}