FROM confluentinc/cp-kafka-connect-base:latest

USER root

# Update and install find for determing SSL configuration in entrypoint
RUN dnf -y install findutils jq

# Install awscli to get secrets from AWS secrets manager.
RUN dnf -y module install python39
RUN python -m pip install --upgrade pip
RUN python -m pip install awscli==1.19.58

# Install Plugin

# Install JdbcSinkSource connector from ConfluentHub
ENV JDBC_CONNECTOR_VERSION='10.5.2'
RUN confluent-hub install --no-prompt confluentinc/kafka-connect-jdbc:${JDBC_CONNECTOR_VERSION}
# Copy drivers required by jdbc plugin
COPY ./drivers/ /usr/share/confluent-hub-components/confluentinc-kafka-connect-jdbc/lib/
COPY ./CONNECTION_URL_SECRET.properties /etc/kafka-connect/secrets/

# Install Neo4jSinkSource connector from ConfluentHub
ENV NEO4J_CONNECTOR_VERSION='1.0.9'
RUN confluent-hub install --no-prompt neo4j/kafka-connect-neo4j:${NEO4J_CONNECTOR_VERSION}

# Install Secret Provider
ENV SECRET_PROVIDER_VERSION='0.1.2'
RUN confluent-hub install --no-prompt jcustenborder/kafka-config-provider-aws:${SECRET_PROVIDER_VERSION}

COPY entry_point.sh /usr/local/bin/entry_point.sh
RUN chmod +x /usr/local/bin/entry_point.sh


USER appuser

ENV CONNECT_REST_PORT=8083

# Left empty to fail if not set
ENV CONNECT_GROUP_ID=

ENV CONNECT_KEY_CONVERTER='org.apache.kafka.connect.json.JsonConverter'
ENV CONNECT_VALUE_CONVERTER='org.apache.kafka.connect.json.JsonConverter'

ENV CONNECT_PLUGIN_PATH='/usr/share/java,/usr/share/confluent-hub-components/'
ENV CONNECT_SECURITY_PROTOCOL=SSL
ENV CONNECT_CONFIG_PROVIDERS=file
ENV CONNECT_CONFIG_PROVIDERS_FILE_CLASS='org.apache.kafka.common.config.provider.FileConfigProvider'
ENV CONNECT_CONSUMER_SECURITY_PROTOCOL=SSL
ENV CONNECT_PRODUCER_SECURITY_PROTOCOL=SSL
ENV CONNECT_CONSUMER_REQUEST_TIMEOUT_MS=20000
ENV CONNECT_CONSUMER_RETRY_BACKOFF_MS=500
ENV Environment=dev
ENV MAX_TASKS=1
ENV AWS_REGION=us-east-1

# Mitigate CVE-2021-44228
# https://msrc-blog.microsoft.com/2021/12/11/microsofts-response-to-cve-2021-44228-apache-log4j2/
ENV LOG4J_FORMAT_MSG_NO_LOOKUPS=true

# Configure default log levels
ENV CONNECT_LOG4J_ROOT_LOGLEVEL=ERROR
ENV CONNECT_LOG4J_LOGGERS='org.I0Itec.zkclient=ERROR,org.reflections=ERROR,org.eclipse.jetty=ERROR,kafka=ERROR,org.apache.kafka=ERROR,org.apache.zookeeper=ERROR,org.apache.kafka.connect.runtime.WorkerSourceTask=ERROR'

EXPOSE ${CONNECT_REST_PORT}

ENTRYPOINT  ["/usr/local/bin/entry_point.sh"]
