from datetime import timedelta

INSTANCE_NAME= '{{ pagure_instance_name }}'

THEME_TEMPLATE_FOLDER='{{ pagure_theme_template_dir }}'
THEME_STATIC_FOLDER='{{ pagure_theme_static_dir }}'

### Set the time after which the admin session expires
# There are two sessions on pagure, login that holds for 31 days and
# the session defined here after which an user has to re-login.
# This session is used when accessing all administrative parts of pagure
# (ie: changing a project's or a user's settings)
ADMIN_SESSION_LIFETIME = timedelta(minutes=20)

# Make the CSRF token not-time limited, this way it is valid for the entire
# duration of the session.
WTF_CSRF_TIME_LIMIT=None

### Secret key for the Flask application
SECRET_KEY='{{ pagure_secret_key }}'
SALT_EMAIL='{{ pagure_secret_salt_email }}'

EMAIL_SEND = True

# This is required so that login specifies https
PREFERRED_URL_SCHEME='https'

### url to the database server:
#DB_URL=mysql://user:pass@host/db_name
#DB_URL=postgres://user:pass@host/db_name
# removing host for local postgres connection
DB_URL = 'postgresql://{{ new_pagure_db_user }}:{{ new_pagure_db_pass }}@{{ new_pagure_db_host }}/{{ new_pagure_db_name }}'

### The FAS group in which the admin of pagure are
ADMIN_GROUP = {{ new_pagure_admin_groups }}

# The publicly visible admin email address
ADMIN_EMAIL = 'admin@fedoraproject.org'

### The email address to which the flask.log will send the errors (tracebacks)
EMAIL_ERROR = '{{ pagure_admin_email }}'

### Default SMTP server to use for sending emails
SMTP_SERVER = 'localhost'

### Email used to sent emails
FROM_EMAIL = 'pagure@{{ external_hostname }}'
DOMAIN_EMAIL_NOTIFICATIONS = '{{ external_hostname }}'

### The URL at which the project is available.
APP_URL = 'https://{{ external_hostname }}/'
DOC_APP_URL = 'https://docs.{{ external_hostname }}'

### Datagrepper info for the user profile
DATAGREPPER_URL = 'https://apps.fedoraproject.org/datagrepper'
DATAGREPPER_CATEGORY = 'pagure'

### The URL to use to clone git repositories.
GIT_URL_SSH = 'ssh://git@{{ external_hostname }}/'
GIT_URL_GIT = 'https://{{ external_hostname }}/'

### The IP addresses allowed for the internal endpoints
IP_ALLOWED_INTERNAL = ['127.0.0.1', 'localhost', '::1', '{{ public_ip }}']

# Redis configuration
EVENTSOURCE_SOURCE = 'https://{{ external_hostname }}:8088'
REDIS_HOST = '0.0.0.0'
REDIS_PORT = 6379
REDIS_DB = 0

EV_STATS_PORT = '8888'

WEBHOOK = True

### Folder containing to the git repos
GIT_FOLDER = '/srv/git/repositories'

### Folder containing the forks repos
FORK_FOLDER = '/srv/git/repositories/forks'

### Folder containing the docs repos
DOCS_FOLDER = '/srv/git/repositories/docs'

### Folder containing the pull-requests repos
REQUESTS_FOLDER = '/srv/git/repositories/requests'

### Folder containing the tickets repos
TICKETS_FOLDER = '/srv/git/repositories/tickets'

### Folder containing the clones of the remotes git repo
REMOTE_GIT_FOLDER = '/srv/git/remotes'

### Configuration file for gitolite
GITOLITE_CONFIG = '/srv/git/.gitolite/conf/gitolite.conf'

### Path of the release folder
UPLOAD_FOLDER_URL = 'https://releases.{{ external_hostname }}/'
UPLOAD_FOLDER_PATH = '/var/www/releases/'


### Home folder of the gitolite user
### Folder where to run gl-compile-conf from
GITOLITE_HOME = '/srv/git/'

### Folder containing all the public ssh keys for gitolite
GITOLITE_KEYDIR = '/srv/git/.gitolite/keydir/'

### Path to the gitolite.rc file
GL_RC = '/srv/git/.gitolite.rc'

### Path to the /bin directory where the gitolite tools can be found
GL_BINDIR = '/usr/bin/'


### Temp folder to be used to make the clones to work around bug in libgit2:
## refs: https://github.com/libgit2/libgit2/issues/2965
## and   https://github.com/libgit2/libgit2/issues/2797
TMP_FOLDER = '/srv/tmp'

# Optional configuration

### Number of items displayed per page
# Used when listing items
ITEM_PER_PAGE = 50

### Maximum size of the uploaded content
# Used to limit the size of file attached to a ticket for example
MAX_CONTENT_LENGTH = 60 * 1024 * 1024  # 60 megabytes

### Lenght for short commits ids or file hex
SHORT_LENGTH = 7

### List of blacklisted project names that can conflicts for pagure's URLs
### or other
BLACKLISTED_PROJECTS = [
    'static', 'pv', 'releases', 'new', 'api', 'settings',
    'logout', 'login', 'users', 'groups', 'projects', 'ssh_info'
    'issues', 'pull-requests', 'commits', 'tree', 'forks',
]

DISABLED_PLUGINS = ['IRC']


# Authentication related configuration option

### Switch the authentication method
# Specify which authentication method to use, defaults to `fas` can be or
# `local`
# Default: ``fas``.
PAGURE_AUTH = 'openid'

# When this is set to True, the session cookie will only be returned to the
# server via ssl (https). If you connect to the server via plain http, the
# cookie will not be sent. This prevents sniffing of the cookie contents.
# This may be set to False when testing your application but should always
# be set to True in production.
# Default: ``True``.
SESSION_COOKIE_SECURE = True

# The name of the cookie used to store the session id.
# Default: ``.pagure``.
SESSION_COOKIE_NAME = 'upstreamfirstpagure'

# Boolean specifying wether to check the user's IP address when retrieving
# its session. This make things more secure (thus is on by default) but
# under certain setup it might not work (for example is there are proxies
# in front of the application).
CHECK_SESSION_IP = True

# Used by SESSION_COOKIE_PATH
APPLICATION_ROOT = '/'

# Set the SSH certs/keys
SSH_KEYS = {
    'RSA': {
        'fingerprint': '2048 69:50:46:24:c7:94:44:f8:8d:83:05:5c:eb:73:fb:c4   (RSA)',
        'pubkey': '{{ external_hostname }},{{ public_ip }} {{ pagure_ssh_host_pubkey }}',
        'SHA256': '{{ pagure_ssh_host_sha256 }}',
    }
}

# Allow the backward compatiblity endpoints for the old URLs schema to
# see the commits of a repo. This is only interesting if you pagure instance
# was running since before version 1.3 and if you care about backward
# compatibility in your URLs.
OLD_VIEW_COMMIT_ENABLED = False

#PAGURE_CI_SERVICES=['jenkins']
PAGURE_CI_SERVICES=[]

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'formatter': 'standard',
            'class': 'logging.StreamHandler',
            'stream': 'ext://sys.stdout',
        },
    },
    # The root logger configuration; this is a catch-all configuration
    # that applies to all log messages not handled by a different logger
    'root': {
        'level': 'INFO',
        'handlers': ['console'],
    },
    'loggers': {
        'pagure': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': True
        },
        'pagure.lib.encoding_utils': {
            'handlers': ['console'],
            'level': 'WARN',
            'propagate': False
        },
        'flask': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': False
        },
        'sqlalchemy': {
            'handlers': ['console'],
            'level': 'WARN',
            'propagate': False
        },
        'binaryornot': {
            'handlers': ['console'],
            'level': 'WARN',
            'propagate': True
        },
    }
}

