# Purpose of this instance
# Use "production", "devel", "local" or "test"
ENV="{% if devel %}devel{% else %}{{ env }}{% endif %}"

# Directory and files where is stored Copr database files
DATA_DIR = '/var/lib/copr/data'
DATABASE = '/var/lib/copr/data/copr.db'

# Stage runs against staging FAS/OpenID
OPENID_PROVIDER_URL = "https://id{% if devel %}.stg{% endif %}.fedoraproject.org"
OPENID_STORE = '/var/lib/copr/data/openid_store'

WHOOSHEE_DIR = '/var/lib/copr/data/whooshee'
WHOOSHEE_MIN_STRING_LEN = 2
WHOOSHEE_WRITER_TIMEOUT = 10

SECRET_KEY = '{{ copr_secret_key }}'
{% if env == 'production' %}
BACKEND_PASSWORD = '{{ copr_backend_password  }}'
{% elif devel %}
BACKEND_PASSWORD = '{{ copr_backend_password_dev }}'
{% else %}
BACKEND_PASSWORD = '{{ copr_backend_password_stg }}'
{% endif %}

BACKEND_BASE_URL = '{{ backend_base_url }}'

BACKEND_STATS_URI = "/stats/index.html"

RESALLOC_URL = "{{ backend_base_url }}/resalloc"

# restrict access to a set of users
#USE_ALLOWED_USERS = False
#ALLOWED_USERS = ['bonnie', 'clyde']

SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://copr-fe:{{ copr_database_password }}@/coprdb'

# Token length, defaults to 30 (max 255)
#API_TOKEN_LENGTH = 30

# Expiration of API token in days
#API_TOKEN_EXPIRATION = 180

# logging options
#SEND_LOGS_TO = ['root@localhost']
{% if devel %}
LOGGING_LEVEL = 'debug'
{% endif %}

DEBUG = False
SQLALCHEMY_ECHO = False

CSRF_ENABLED = True
WTF_CSRF_ENABLED = True

# send emails when user's perms change in project?
SEND_EMAILS = True

{% if copr_kerberos_auth_enabled %}
KRB5_LOGIN = {
   'log_text':     "gssapi-login",
   'email_domain': "fedoraproject.org",
}
{% endif %}

PUBLIC_COPR_HOSTNAME = "{{ copr_frontend_public_hostname }}"

# When running the website through apache,
# this variable is automatically set from ServerName
# in the httpd config. Setting it in this file is needed
# for manage.py purposes
SERVER_NAME = "{{ copr_frontend_public_hostname }}"


LOG_FILENAME = "/var/log/copr-frontend/frontend.log"
LOG_DIR = "/var/log/copr-frontend/"

# to accept stat events from logstash
INTRANET_IPS = {{ copr_backend_ips }}

REPO_GPGCHECK = 1

{% if env == 'staging' %}
PUBLIC_COPR_BASE_URL = "https://copr.stg.fedoraproject.org"
{% else %}
PUBLIC_COPR_BASE_URL = "https://copr.fedorainfracloud.org"
{% endif %}

{% if env == 'staging' %}
# Staging URLs for fedmenu
FEDMENU_URL = "https://apps.stg.fedoraproject.org/fedmenu/"
FEDMENU_DATA_URL = "https://apps.stg.fedoraproject.org/js/data.js"
{% else %}
# Production URLs for fedmenu
FEDMENU_URL = "https://apps.fedoraproject.org/fedmenu/"
FEDMENU_DATA_URL = "https://apps.fedoraproject.org/js/data.js"
{% endif %}

# todo: check that ansible variable is used correctly
{% if env == 'staging' %}
ENFORCE_PROTOCOL_FOR_BACKEND_URL = "https"
ENFORCE_PROTOCOL_FOR_FRONTEND_URL = "https"
{% else %}
ENFORCE_PROTOCOL_FOR_BACKEND_URL = "https"
ENFORCE_PROTOCOL_FOR_FRONTEND_URL = "https"
{% endif %}

DIST_GIT_URL="https://{{ dist_git_base_url }}/cgit"
DIST_GIT_CLONE_URL="https://{{ dist_git_base_url }}/git"
COPR_DIST_GIT_LOGS_URL = "https://{{ dist_git_base_url }}/per-task-logs"

# no need to filter cla_* groups, they are already filtered by fedora openid
GROUP_DENYLIST = ['fedorabugs', 'packager', 'provenpackager', 'ipausers', 'signed_fpca', 'fedora-contributor']
# TODO: remove BLACKLISTED_GROUPS once # https://pagure.io/copr/copr/pull-request/1960 is released
BLACKLISTED_GROUPS = GROUP_DENYLIST

DEFER_BUILD_SECONDS = 300

ENABLE_DISCUSSION = True
DISCOURSE_URL = "https://discussion.fedoraproject.org/"

# We may have a (temporary) chroot that doesn't correspond with /etc/os-release
# on a client system, e.g. "rhelbeta-8" chroots in Copr which doesn't match to
# any real system, instead it is a temporary alias for "epel-8". In such case,
# set this to {"epel-8": "rhelbeta-8"}
CHROOT_NAME_RELEASE_ALIAS = {"epel-8": "rhelbeta-8"}
{% if allowlist_emails is defined %}

ALLOWLIST_EMAILS = [
{% for recipient in allowlist_emails %}
  "{{ recipient }}",
{% endfor %}
]
{% endif %}

PAGURE_EVENTS = {
{% if copr_pagure_events is defined %}
{% for instance, url in copr_pagure_events.items() %}
{% for topic in [
  'git.receive',
  'pull-request.new',
  'pull-request.rebased',
  'pull-request.updated',
  'pull-request.comment.added'] %}
  '{{ instance }}.{{ topic }}' : '{{ url }}',
{% endfor %}
{% endfor %}
{% endif %}
}

# Increased build timeout to 50h
# Requested by @lantw44 for chromium, later by @kkleine
MAX_BUILD_TIMEOUT = 180000
{% if copr_kerberos_auth_enabled %}
API_GSSAPI_AUTH = True
{% else %}
API_GSSAPI_AUTH = False
{% endif %}

{% if env == 'production' %}
FAS_SIGNUP_URL = "https://accounts.fedoraproject.org"
{% else %}
FAS_SIGNUP_URL = "https://accounts.stg.fedoraproject.org"
{% endif %}

{% if devel %}
# On stage we only ever start powerful builders in this project.  Note that we
# also start s390x instances in IBM Cloud on-demand , even without the extra
# BuildChroot tags here!  The reason is that the `arch_s390x` tag is named in
# the `tags_on_demand` section in resalloc's pools.yaml file.  But the
# difference is that `s390x` can be started by anyone.
#
# We have prepared those projects on stage:
# $ copr create @copr/measure-hypervisor   --chroot fedora-rawhide-x86_64 --chroot fedora-rawhide-ppc64le
# $ copr create @copr/measure-aws          --chroot fedora-rawhide-x86_64 --chroot fedora-rawhide-aarch64
# $ copr create @copr/measure-aws-powerful --chroot fedora-rawhide-x86_64 --chroot fedora-rawhide-aarch64
# $ copr create @copr/measure-ibm-cloud    --chroot fedora-rawhide-s390x
# $ copr create @copr/measure-hv-p08       --chroot fedora-rawhide-ppc64le
# Measure like:
# $ for project in @copr/measure-hypervisor @copr/measure-aws @copr/measure-aws-powerful @copr/measure-ibm-cloud @copr/measure-hv-p08; do
#   copr build $project https://...
# done
EXTRA_BUILDCHROOT_TAGS = [{
    "pattern": "@copr/powerful-test/fedora-rawhide-(x86_64|aarch64|s390x)/.*",
    "tags": ["on_demand_powerful"],
}, {
    "pattern": "@copr/measure-hypervisor.*/.*x86_64/.*",
    "tags": ["hypervisor"],
}, {
    "pattern": "@copr/measure-hypervisor.*/.*ppc64le/.*",
    "tags": ["hypervisor", "arch_power9"],
}, {
    "pattern": "@copr/measure-aws.*/.*/.*",
    "tags": ["aws"],
}, {
    "pattern": "@copr/measure-aws-powerful.*/.*/.*",
    "tags": ["on_demand_powerful"],
}, {
    "pattern": "@copr/measure-hv-p08.*/.*/.*",
    "tags": ["arch_power8"],
}]
{% else %}
EXTRA_BUILDCHROOT_TAGS = [{
    # https://github.com/fedora-copr/copr/issues/2966
    "pattern": "@asahi/kernel/.*(x86_64|aarch64)/kernel",
    "tags": ["on_demand_powerful"],
}, {
    # https://github.com/fedora-copr/copr/issues/2966
    "pattern": "ngompa/fedora-asahi-dev/.*(x86_64|aarch64)/kernel",
    "tags": ["on_demand_powerful"],
}, {
    # https://github.com/fedora-copr/copr/issues/2985
    "pattern": "ngompa/kernel-ark-exp-dev/.*(x86_64|aarch64)/kernel",
    "tags": ["on_demand_powerful"],
}, {
    # https://github.com/fedora-copr/copr/issues/2986
    "pattern": "@centoshyperscale/kernel/.*(x86_64|aarch64)/kernel",
    "tags": ["on_demand_powerful"],
}, {
    # https://github.com/fedora-copr/copr/issues/2987
    "pattern": "@fedora-llvm-team/llvm-snapshots[^/]*/.*x86_64/(llvm|clang)",
    "tags": ["on_demand_powerful"],
}]
{% endif %}
