kind: ConfigMap
apiVersion: v1
metadata:
  name: "{{name}}-config"
  namespace: '{{ meta.namespace }}'
  labels:
    app: "{{name}}"
    container: spring
    group: microcks
data:
  features.properties: |-
    features.feature.repository-filter.enabled={{features.repositoryFilter.enabled|default(features.repository_filter.enabled) | bool | lower}}
    features.feature.repository-filter.label-key={{features.repositoryFilter.labelKey|default(features.repository_filter.label_key)}}
    features.feature.repository-filter.label-label={{features.repositoryFilter.labelLabel|default(features.repository_filter.label_label)}}
    features.feature.repository-filter.label-list={{features.repositoryFilter.labelList|default(features.repository_filter.label_list)}}

    features.feature.async-api.enabled={{features.async.enabled | bool | lower}}
    features.feature.async-api.default-binding={{features.async.defaultBinding|default(features.async.default_binding)}}
    {%- if features.async.kafka.install and 'url' not in features.async.kafka %}
    
    features.feature.async-api.endpoint-KAFKA={{name}}-kafka-kafka-bootstrap.<apps-subdomain>:443
    {%- elif features.async.kafka.install and 'url' in features.async.kafka %}
    
    features.feature.async-api.endpoint-KAFKA={{name}}-kafka-kafka-bootstrap.{{features.async.kafka.url}}:443

    {%- elif not features.async.kafka.install and 'url' in features.async.kafka %}
    
    features.feature.async-api.endpoint-KAFKA={{features.async.kafka.url}}
    {% endif %}

    {%- if features.async.mqtt.url is defined %}

    features.feature.async-api.endpoint-MQTT={{features.async.mqtt.url}}
    {% endif %}
    
    features.feature.async-api.endpoint-WS={{microcks_url|regex_replace('^('~(name|regex_escape())~')(.*)','\\1-ws\\2')}}

  application.properties: |-
    # Application configuration properties
    tests-callback.url=http://{{name}}:8080
    postman-runner.url=http://{{name}}-postman-runtime:8080
    async-minion.url=http://{{name}}-async-minion:8080

    network.username=
    network.password=

    validation.resourceUrl=https://{{microcks.url|default(microcks_url)}}/api/resources/
    services.update.interval=${SERVICES_UPDATE_INTERVAL:0 0 0/2 * * *}
    mocks.rest.enable-cors-policy=${ENABLE_CORS_POLICY:true}

    # Logging configuration properties
    logging.config=/deployments/config/logback.xml

    # Keycloak configuration properties
    keycloak.auth-server-url=${KEYCLOAK_URL:http://localhost:8180/auth}
    keycloak.realm={{keycloak.realm}}
    keycloak.resource=microcks-app
    keycloak.use-resource-role-mappings=true
    keycloak.bearer-only=true
    keycloak.ssl-required=external
    keycloak.disable-trust-manager=true

    keycloak.security-constraints[0].authRoles[0]=admin
    keycloak.security-constraints[0].authRoles[1]=manager
    keycloak.security-constraints[0].authRoles[2]=user
    keycloak.security-constraints[0].securityCollections[0].name=Insecure stuffs
    keycloak.security-constraints[0].securityCollections[0].patterns[0]=/api/services
    keycloak.security-constraints[0].securityCollections[0].patterns[1]=/api/services/count
    keycloak.security-constraints[0].securityCollections[0].patterns[2]=/api/jobs
    keycloak.security-constraints[0].securityCollections[0].patterns[3]=/api/jobs/count

    # Keycloak access configuration properties
    sso.public-url=${KEYCLOAK_PUBLIC_URL:${keycloak.auth-server-url}}

    # Async mocking support.
    async-api.enabled={{ features.async.enabled | bool | lower }}
    async-api.default-binding={{features.async.defaultBinding|default(features.async.default_binding)}}
    async-api.default-frequency={{features.async.defaultFrequency|default(features.async.default_frequency)}}

    # Kafka configuration properties
    spring.kafka.producer.bootstrap-servers=${KAFKA_BOOTSTRAP_SERVER:localhost:9092}

    # Grpc server properties
    grpc.server.certChainFilePath=/deployments/config/grpc/tls.crt
    grpc.server.privateKeyFilePath=/deployments/config/grpc/tls.key
  logback.xml: |-
    <?xml version="1.0" encoding="UTF-8"?>

    <configuration scan="true">
      <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
          <charset>utf-8</charset>
          <Pattern>%d{HH:mm:ss.SSS} [%p] %c - %m%n</Pattern>
        </encoder>
      </appender>

      <logger name="io.github.microcks" level="{{ microcks.log_level }}"/>
      <!-- Change com.mongodb to org.mongodb so that com.mongodb.FongoDBCollection is ignored, set to debug and tests do not fail... -->
      <logger name="org.mongodb" level="INFO"/>
      <logger name="org.springframework.data.mongodb" level="INFO"/>
      <logger name="org.keycloak" level="INFO"/>
      <logger name="class org.keycloak.adapters.tomcat.CatalinaRequestAuthenticator" level="INFO"/>
      <logger name="com.eviware.soapui.impl.wsdl.support.http" level="WARN"/>
      <logger name="org.reflections" level="WARN"/>
      <logger name="com.jayway.jsonpath" level="INFO"/>
      <logger name="sun.net.www.protocol.http" level="INFO"/>

      <logger name="jdk.event.security" level="WARN"/>
      <logger name="javax.activation" level="WARN"/>
      <logger name="javax.mail" level="WARN"/>
      <logger name="javax.xml.bind" level="WARN"/>
      <logger name="ch.qos.logback" level="WARN"/>
      <logger name="com.codahale.metrics" level="WARN"/>
      <logger name="com.ryantenney" level="WARN"/>
      <logger name="com.sun.xml.internal.bind" level="WARN"/>
      <logger name="com.zaxxer" level="WARN"/>
      <logger name="io.undertow" level="WARN"/>
      <logger name="org.apache" level="WARN"/>
      <logger name="org.apache.catalina.startup.DigesterFactory" level="OFF"/>
      <logger name="org.bson" level="WARN"/>
      <logger name="org.hibernate.validator" level="WARN"/>
      <logger name="org.hibernate" level="WARN"/>
      <logger name="org.hibernate.ejb.HibernatePersistence" level="OFF"/>
      <logger name="org.springframework" level="WARN"/>
      <logger name="org.springframework.aop" level="WARN"/>
      <logger name="org.springframework.web" level="WARN"/>
      <logger name="org.springframework.security" level="WARN"/>
      <logger name="org.springframework.cache" level="WARN"/>
      <logger name="org.springframework.scheduling" level="WARN"/>
      <logger name="org.thymeleaf" level="WARN"/>
      <logger name="org.xnio" level="WARN"/>
      <logger name="com.mangofactory.swagger" level="WARN"/>
      <logger name="com.wordnik.swagger" level="WARN"/>
      <logger name="sun.rmi.transport" level="WARN"/>

      <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
        <resetJUL>true</resetJUL>
      </contextListener>

      <root level="INFO">
        <appender-ref ref="CONSOLE"/>
      </root>
    </configuration>