# Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) 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.

apiVersion: v1
kind: ConfigMap
metadata:
  name: wso2am-p4-am-external-gateway-conf
  namespace : wso2-system
data:
  deployment.toml: |-
    [server]
    hostname = "ext.gateway.am.wso2.com"
    node_ip = "$env{NODE_IP}"
    server_role = "gateway-worker"

    [user_store]
    type = "database_unique_id"

    [super_admin]
    username = "admin"
    password = "admin"
    create_admin_account = true

    [database.shared_db]
    type = "h2"
    url = "jdbc:h2:./repository/database/WSO2SHARED_DB;DB_CLOSE_ON_EXIT=FALSE"
    username = "wso2carbon"
    password = "wso2carbon"

    [apim.sync_runtime_artifacts.gateway]
    gateway_labels =["Production and Sandbox", "Production and Sandbox 2"]
    artifact_retriever = "DBRetriever"
    deployment_retry_duration = 5000
    data_retrieval_mode = "sync"
    event_waiting_time = 5000

    [keystore.tls]
    file_name =  "wso2carbon.jks"
    type =  "JKS"
    password =  "wso2carbon"
    alias =  "wso2carbon"
    key_password =  "wso2carbon"

    [truststore]
    file_name = "client-truststore.jks"
    type = "JKS"
    password = "wso2carbon"

    # key manager implementation
    [apim.key_manager]
    service_url = "https://wso2-am-km-svc:${mgt.transport.https.port}/services/"
    username= "$ref{super_admin.username}"
    password= "$ref{super_admin.password}"

    # JWT Generation
    [apim.jwt]
    enable = true
    encoding = "base64" # base64,base64url
    #generator_impl = "org.wso2.carbon.apimgt.keymgt.token.JWTGenerator"
    claim_dialect = "http://wso2.org/claims"
    header = "X-JWT-Assertion"
    signing_algorithm = "SHA256withRSA"
    #enable_user_claims = true
    #claims_extractor_impl = "org.wso2.carbon.apimgt.impl.token.DefaultClaimsRetriever"

    # Traffic Manager configurations
    [apim.throttling]
    username= "$ref{super_admin.username}"
    password= "$ref{super_admin.password}"
    service_url = "https://wso2-am-svc:${mgt.transport.https.port}/services/"
    throttle_decision_endpoints = ["tcp://wso2-am-1-svc:5672","tcp://wso2-am-2-svc:5672"]
    enable_unlimited_tier = true
    enable_header_based_throttling = false
    enable_jwt_claim_based_throttling = false
    enable_query_param_based_throttling = false

    [[apim.throttling.url_group]]
    traffic_manager_urls = ["tcp://wso2-am-1-svc:9611"]
    traffic_manager_auth_urls = ["ssl://wso2-am-1-svc:9711"]
    type = "loadbalance"

    [[apim.throttling.url_group]]
    traffic_manager_urls = ["tcp://wso2-am-2-svc:9611"]
    traffic_manager_auth_urls = ["ssl://wso2-am-2-svc:9711"]
    type = "loadbalance"

    [apim.analytics]
    enable = "$env{ENABLE_ANALYTICS}"
    username= "$ref{super_admin.username}"
    password= "$ref{super_admin.password}"
    store_api_url = "https://wso2-am-analytics-worker-svc:7444"

    [[apim.analytics.url_group]]
    analytics_url =["tcp://wso2-am-analytics-worker-statefulset-0.wso2-am-analytics-worker-headless-svc:7612","tcp://wso2-am-analytics-worker-statefulset-1.wso2-am-analytics-worker-headless-svc:7612"]
    analytics_auth_url =["ssl://wso2-am-analytics-worker-statefulset-0.wso2-am-analytics-worker-headless-svc:7712","ssl://wso2-am-analytics-worker-statefulset-1.wso2-am-analytics-worker-headless-svc:7712"]
    type = "failover"

    # Caches
    [apim.cache.gateway_token]
    enable = true
    expiry_time = 15

    [apim.cache.resource]
    enable = true

    [apim.cache.jwt_claim]
    enable = true
    expiry_time = 900

    [apim.oauth_config]
    remove_outbound_auth_header = true
    auth_header = "Authorization"

    [apim.cors]
    allow_origins = "*"
    allow_methods = ["GET","PUT","POST","DELETE","PATCH","OPTIONS"]
    allow_headers = ["authorization","Access-Control-Allow-Origin","Content-Type","SOAPAction"]
    allow_credentials = false

    [transport.https.properties]
    proxyPort = 443

    [transport.passthru_https.sender.parameters]
    HostnameVerifier = "AllowAll"

    [apim.event_hub]
    enable = true
    service_url = "https://wso2-am-svc:9443"
    event_listening_endpoints = ["tcp://wso2-am-1-svc:5672","tcp://wso2-am-2-svc:5672"]

    [[apim.event_hub.publish.url_group]]
    urls = ["tcp://wso2-am-1-svc:9611"]
    auth_urls = ["ssl://wso2-am-1-svc:9711"]

    [[apim.event_hub.publish.url_group]]
    urls = ["tcp://wso2-am-2-svc:9611"]
    auth_urls = ["ssl://wso2-am-2-svc:9711"]
