<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 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.
-->

<!--
    This is the configuration file for internal APIs
-->
<internalApis xmlns:svns="http://org.wso2.securevault/configuration">
    <apis>
        <api name="PrometheusApi" protocol="{{prometheus_api.protocols}}" class="org.wso2.micro.integrator.observability.metric.publisher.MetricAPI">
            {% if prometheus_api.basic_security_handler.enable == true
                or prometheus_api.authorization_handler.enable == true or prometheus_api.custom_handlers is defined %}
            <handlers>
                {% if prometheus_api.basic_security_handler.enable == true %}
                <handler name="BasicSecurityHandler" class="org.wso2.micro.integrator.management.apis.security.handler.BasicSecurityHandler"/>
                {% endif %}
                {% if prometheus_api.authorization_handler.enable == true %}
                <handler name="AuthorizationHandler" class="org.wso2.micro.integrator.management.apis.security.handler.AuthorizationHandler">
                    {% if prometheus_api.authorization_handler.resources is defined %}
                    <resources>
                        {% for resource in prometheus_api.authorization_handler.resources %}
                        <resource>{{resource.path}}</resource>
                        {% endfor %}
                    </resources>
                    {% endif %}
                </handler>
                {% endif %}
                {% if prometheus_api.custom_handlers is defined %}
                {% for handler in prometheus_api.custom_handlers %}
                <handler name="{{handler.name}}" class="{{handler.class}}">
                    {% if handler.resources is defined %}
                    <resources>
                        {% for resource in handler.resources %}
                        <resource>{{resource.path}}</resource>
                        {% endfor %}
                    </resources>
                    {% endif %}
                </handler>
                {% endfor %}
                {% endif %}
            </handlers>
            {% endif %}
        </api>
        <api name="ReadinessProbe" protocol="{{readiness_probe.protocols}}" class="org.wso2.micro.integrator.probes.ReadinessProbe"/>
        <api name="LivenessProbe" protocol="{{liveness_probe.protocols}}" class="org.wso2.micro.integrator.probes.LivenessProbe"/>
        <api name="ManagementApi" protocol="{{management_api.protocols}}" class="org.wso2.micro.integrator.management.apis.ManagementInternalApi">
            <handlers>
                {% if management_api.basic_security_handler.enable == true %}
                <handler name="BasicSecurityHandler" class="org.wso2.micro.integrator.management.apis.security.handler.BasicSecurityHandler"/>
                {% endif %}
                {% if management_api.jwt_token_security_handler.enable == true %}
                <handler name="JWTTokenSecurityHandler" class="org.wso2.micro.integrator.management.apis.security.handler.JWTTokenSecurityHandler">
                    <TokenStoreConfig>
                        <MaxSize>{{management_api.jwt_token_security_handler.token_store_config.max_size}}</MaxSize>
                        <TokenCleanupTaskInterval>{{management_api.jwt_token_security_handler.token_store_config.clean_up_interval}}</TokenCleanupTaskInterval><!--Seconds /-->
                        <RemoveOldestTokenOnOverflow>{{management_api.jwt_token_security_handler.token_store_config.remove_oldest_token_on_overflow}}</RemoveOldestTokenOnOverflow>
                    </TokenStoreConfig>
                    <TokenConfig>
                        <expiry>{{management_api.jwt_token_security_handler.token_config.expiry}}</expiry><!--Seconds /-->
                        <size>{{management_api.jwt_token_security_handler.token_config.size}}</size>
                    </TokenConfig>
                </handler>
                {% endif %}
                {% if management_api.authorization_handler.enable == true %}
                <handler name="AuthorizationHandler" class="org.wso2.micro.integrator.management.apis.security.handler.AuthorizationHandler">
                    {% if management_api.authorization_handler.resources is defined %}
                    <resources>
                        {% for resource in management_api.authorization_handler.resources %}
                        <resource>{{resource.path}}</resource>
                        {% endfor %}
                    </resources>
                    {% endif %}
                </handler>
                {% endif %}
                {% if management_api.custom_handlers is defined %}
                {% for handler in management_api.custom_handlers %}
                <handler name="{{handler.name}}" class="{{handler.class}}">
                    {% if handler.resources is defined %}
                    <resources>
                        {% for resource in handler.resources %}
                        <resource>{{resource.path}}</resource>
                        {% endfor %}
                    </resources>
                    {% endif %}
                </handler>
                {% endfor %}
                {% endif %}
            </handlers>
            <cors>
                <enabled>{{management_api.cors.enable}}</enabled>
                <allowedOrigins>{{management_api.cors.allowed_origins}}</allowedOrigins>
                <allowedHeaders>{{management_api.cors.allowed_headers}}</allowedHeaders>
            </cors>
        </api>
    </apis>
    {% if internal_apis.file_user_store.enable == true %}
    <userStore>
        <users>
            {% for user in internal_apis.users %}
            <user>
                <username>{{user.user.name}}</username>
                <password>{{user.user.password}}</password>
                <isAdmin>{{user.user.is_admin}}</isAdmin>
            </user>
            {% endfor %}
        </users>
    </userStore>
    {% endif %}
    <sslConfig>
        {% for parameter_key,parameter_value in internal_api_ssl_config.parameter.items() %}
        <parameter name="{{parameter_key}}">{{parameter_value}}</parameter>
        {% endfor %}
        <parameter name="keystore">
            <KeyStore>
                <Location>{{internal_api_ssl_config.key_store.location}}</Location>
                <Type>{{internal_api_ssl_config.key_store.type}}</Type>
                <Password>{{internal_api_ssl_config.key_store.password}}</Password>
                <KeyPassword>{{internal_api_ssl_config.key_store.key_password}}</KeyPassword>
            </KeyStore>
        </parameter>
        <parameter name="truststore">
            <TrustStore>
                <Location>{{internal_api_ssl_config.trust_store.location}}</Location>
                <Type>{{internal_api_ssl_config.trust_store.type}}</Type>
                <Password>{{internal_api_ssl_config.trust_store.password}}</Password>
            </TrustStore>
        </parameter>
        <parameter name="certificateRevocationVerifier">
            <CertificateRevocationVerifier enable="{{internal_api_ssl_config.certificate_revocation_verifier_enabled}}">
                <CacheSize>{{internal_api_ssl_config.certificate_revocation_verifier.cache_size}}</CacheSize>
                <CacheDelay>{{internal_api_ssl_config.certificate_revocation_verifier.cache_delay}}</CacheDelay>
            </CertificateRevocationVerifier>
        </parameter>
    </sslConfig>
</internalApis>
