# Coder Environment Configuration
# Generated by provisioning system

CODER_VERSION={{ coder.version }}
CODER_RUN_USER={{ coder.run_user.name }}
CODER_RUN_GROUP={{ coder.run_user.group }}
CODER_RUN_USER_HOME={{ coder.run_user.home }}
CODER_WORK_PATH={{ coder.work_path }}
CODER_CONFIG_PATH={{ coder.config_path }}
CODER_RUN_PATH={{ coder.run_path }}

# Server Configuration
CODER_ACCESS_URL={{ coder.access_url }}
{% if coder.wildcard_access_url is defined %}
CODER_WILDCARD_ACCESS_URL={{ coder.wildcard_access_url }}
{% endif %}
CODER_HTTP_ADDRESS={{ coder.http_address }}
CODER_LOG_LEVEL={{ coder.log_level }}
CODER_TELEMETRY={{ coder.telemetry_enabled | lower }}
CODER_UPDATE_CHECK={{ coder.update_check_enabled | lower }}
CODER_REDIRECT_TO_ACCESS_URL={{ coder.redirect_to_access_url | lower }}
CODER_SECURE_AUTH_COOKIE={{ coder.secure_auth_cookie | lower }}
CODER_MAX_SESSION_TOKEN_LIFETIME={{ coder.max_session_token_lifetime }}
CODER_DISABLE_PASSWORD_AUTH={{ coder.disable_password_auth | lower }}

{% if coder.proxy_trusted_headers %}
CODER_PROXY_TRUSTED_HEADERS="{{ coder.proxy_trusted_headers | join(',') }}"
{% endif %}
{% if coder.proxy_trusted_origins %}
CODER_PROXY_TRUSTED_ORIGINS="{{ coder.proxy_trusted_origins | join(',') }}"
{% endif %}

# Database Configuration
{% if coder.database.typ == "sqlite" %}
CODER_PG_CONNECTION_URL=sqlite3://{{ coder.database.path }}
{% else %}
CODER_PG_CONNECTION_URL=postgresql://{{ coder.database.username }}:{{ coder.database.password }}@{{ coder.database.host }}:{{ coder.database.port }}/{{ coder.database.database }}?sslmode={{ coder.database.ssl_mode }}
{% endif %}

# TLS Configuration
{% if coder.tls.enabled %}
CODER_TLS_ENABLE=true
CODER_TLS_ADDRESS={{ coder.tls.address }}
CODER_TLS_CERT_FILE={{ coder.tls.cert_file }}
CODER_TLS_KEY_FILE={{ coder.tls.key_file }}
{% else %}
CODER_TLS_ENABLE=false
{% endif %}

# OAuth Configuration  
{% if coder.oauth.enabled %}
{% if coder.oauth.provider == "github" %}
CODER_OAUTH2_GITHUB_CLIENT_ID={{ coder.oauth.client_id }}
CODER_OAUTH2_GITHUB_CLIENT_SECRET={{ coder.oauth.client_secret }}
CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS=true
{% elif coder.oauth.provider == "oidc" %}
CODER_OIDC_ISSUER_URL={{ coder.oauth.issuer_url }}
CODER_OIDC_CLIENT_ID={{ coder.oauth.client_id }}
CODER_OIDC_CLIENT_SECRET={{ coder.oauth.client_secret }}
CODER_OIDC_SCOPES="{{ coder.oauth.scopes | join(',') }}"
CODER_OIDC_ALLOW_SIGNUPS=true
{% elif coder.oauth.provider == "google" %}
CODER_OAUTH2_GOOGLE_CLIENT_ID={{ coder.oauth.client_id }}
CODER_OAUTH2_GOOGLE_CLIENT_SECRET={{ coder.oauth.client_secret }}
CODER_OAUTH2_GOOGLE_ALLOW_SIGNUPS=true
{% endif %}
{% endif %}