error_log /dev/stdout info;
worker_processes 1;

events { worker_connections 1024; }

http {

   server {
    listen  0.0.0.0:9081;

    root /tmp/argo-e2e;

    location ~ ^/helm-repo/(.*) {
      # Set chunks to unlimited, as the body's can be huge
      client_max_body_size			0;
      alias /app/config/testdata/helm-repo/$1;
    }

    location ~ /argo-e2e/testdata.git/helm-repo/(.*) {
      # Set chunks to unlimited, as the body's can be huge
      client_max_body_size			0;

      alias /tmp/argo-e2e/testdata.git/helm-repo/$1;
    }
 
    location ~ /argo-e2e(/.*) {
      # Set chunks to unlimited, as the body's can be huge
  	  client_max_body_size			0;

  	  fastcgi_param	SCRIPT_FILENAME		/usr/lib/git-core/git-http-backend;
  	  include		/etc/nginx/fastcgi_params;
  	  fastcgi_param	GIT_HTTP_EXPORT_ALL	"";
  	  fastcgi_param	GIT_PROJECT_ROOT	/tmp/argo-e2e;
  	  fastcgi_param	PATH_INFO		$1;
    	
  	  # Hard-coded credentials for Git in this case
  	  fastcgi_param	REMOTE_USER		"admin";
  	  fastcgi_pass	unix:/var/run/fcgiwrap.socket;
    }
  }
  
  server {
    listen 9080;
    listen  0.0.0.0:9443 ssl http2;

    auth_basic            "Restricted";
    auth_basic_user_file  .htpasswd;
    root /tmp/argo-e2e;

    ssl_certificate ../certs/argocd-test-server.crt;
    ssl_certificate_key ../certs/argocd-test-server.key;
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

    location ~ /argo-e2e/testdata.git/helm-repo(/.*) {
      # Set chunks to unlimited, as the body's can be huge
      client_max_body_size			0;

      root /tmp/;
    }

    location ~ /helm-repo/(.*) {
      # Set chunks to unlimited, as the body's can be huge
      client_max_body_size			0;
      alias /app/config/testdata/helm-repo/$1;
    }
 
    location ~ /argo-e2e/testdata.git/helm-repo/(.*) {
      # Set chunks to unlimited, as the body's can be huge
      client_max_body_size			0;

      alias /tmp/argo-e2e/testdata.git/helm-repo/$1;
    }
 
    location ~ /argo-e2e(/.*) {
      # Set chunks to unlimited, as the body's can be huge
  	  client_max_body_size			0;

  	  fastcgi_param	SCRIPT_FILENAME		/usr/lib/git-core/git-http-backend;
  	  include		/etc/nginx/fastcgi_params;
  	  fastcgi_param	GIT_HTTP_EXPORT_ALL	"";
  	  fastcgi_param	GIT_PROJECT_ROOT	/tmp/argo-e2e;
  	  fastcgi_param	PATH_INFO		$1;
    	
  	  # Forward REMOTE_USER as we want to know when we are authenticated
  	  fastcgi_param	REMOTE_USER		$remote_user;
  	  fastcgi_pass	unix:/var/run/fcgiwrap.socket;
    }
  }

  # server block for strict verification of client certs
  server {
    listen  0.0.0.0:9444 ssl http2;

    auth_basic            "Restricted";
    auth_basic_user_file  .htpasswd;
    root /tmp/argo-e2e;

    ssl_certificate ../certs/argocd-test-server.crt;
    ssl_certificate_key ../certs/argocd-test-server.key;
    ssl_client_certificate ../certs/argocd-test-ca.crt;
    ssl_verify_client on;
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

    # /helm-repo is used by cluster-e2e tests only
    location ~ ^/helm-repo/(.*) {
      client_max_body_size			0;
      alias /app/config/testdata/helm-repo/$1;
    }
 
    location ~ /argo-e2e/testdata.git/helm-repo/(.*) {
      # Set chunks to unlimited, as the body's can be huge
      client_max_body_size			0;

      alias /tmp/argo-e2e/testdata.git/helm-repo/$1;
    }
   
    location ~ /argo-e2e(/.*) {
      # Set chunks to unlimited, as the body's can be huge
  	  client_max_body_size			0;

  	  fastcgi_param	SCRIPT_FILENAME		/usr/lib/git-core/git-http-backend;
  	  include		/etc/nginx/fastcgi_params;
  	  fastcgi_param	GIT_HTTP_EXPORT_ALL	"";
  	  fastcgi_param	GIT_PROJECT_ROOT	/tmp/argo-e2e;
  	  fastcgi_param	PATH_INFO		$1;
    	
  	  # Forward REMOTE_USER as we want to know when we are authenticated
  	  fastcgi_param	REMOTE_USER		$remote_user;
  	  fastcgi_pass	unix:/var/run/fcgiwrap.socket;
    }

  }
}
