apiVersion: v1
kind: ConfigMap
metadata:
  name: gateway
data:
  default.conf: |
    log_format main_json escape=json '{'
      '"msec": "$msec", ' # request unixtime in seconds with a milliseconds resolution
      '"connection": "$connection", ' # connection serial number
      '"connection_requests": "$connection_requests", ' # number of requests made in connection
      '"pid": "$pid", ' # process pid
      '"request_id": "$request_id", ' # the unique request id
      '"request_length": "$request_length", ' # request length (including headers and body)
      '"remote_addr": "$remote_addr", ' # client IP
      '"remote_user": "$remote_user", ' # client HTTP username
      '"remote_port": "$remote_port", ' # client port
      '"time_local": "$time_local", '
      '"time_iso8601": "$time_iso8601", ' # local time in the ISO 8601 standard format
      '"request": "$request", ' # full path no arguments if the request
      '"request_uri": "$request_uri", ' # full path and arguments if the request
      '"args": "$args", ' # args
      '"status": "$status", ' # response status code
      '"body_bytes_sent": "$body_bytes_sent", ' # the number of body bytes exclude headers sent to a client
      '"bytes_sent": "$bytes_sent", ' # the number of bytes sent to a client
      '"http_referer": "$http_referer", ' # HTTP referer
      '"http_user_agent": "$http_user_agent", ' # user agent
      '"http_x_forwarded_for": "$http_x_forwarded_for", ' # http_x_forwarded_for
      '"http_host": "$http_host", ' # the request Host: header
      '"server_name": "$server_name", ' # the name of the vhost serving the request
      '"request_time": "$request_time", ' # request processing time in seconds with msec resolution
      '"request_method": "$request_method", ' # request method
      '"gzip_ratio": "$gzip_ratio"'
    '}';

    server {
      listen 80;
      server_name apt.fullstaqruby.org;
      access_log /dev/stdout main_json;

      location / {
        if ($http_user_agent ~* "GoogleHC") {
          # Satisfy Google Cloud Balancer health check
          return 200 'OK';
        }
        if ($http_user_agent ~* "Kubernetes Readiness Probe") {
          return 200 'OK';
        }
        rewrite ^/(.*)$ https://storage.googleapis.com/fullstaq-ruby-server-edition-apt-repo/versions/{APT_LATEST_VERSION}/public/$1 redirect;
      }
    }

    server {
      listen 80;
      server_name yum.fullstaqruby.org;
      access_log /dev/stdout main_json;

      location / {
        if ($http_user_agent ~* "GoogleHC") {
          # Satisfy Google Cloud Balancer health check
          return 200 'OK';
        }
        if ($http_user_agent ~* "Kubernetes Readiness Probe") {
          return 200 'OK';
        }
        rewrite ^/(.*)$ https://storage.googleapis.com/fullstaq-ruby-server-edition-yum-repo/versions/{YUM_LATEST_VERSION}/public/$1 redirect;
      }
    }
