file.go

  1package config
  2
  3import (
  4	"bytes"
  5	"text/template"
  6)
  7
  8var configFileTmpl = template.Must(template.New("config").Parse(`# Soft Serve Server configurations
  9
 10# The name of the server.
 11# This is the name that will be displayed in the UI.
 12name: "{{ .Name }}"
 13
 14# Logging configuration.
 15log:
 16  # Log format to use. Valid values are "json", "logfmt", and "text".
 17  format: "{{ .Log.Format }}"
 18  # Time format for the log "timestamp" field.
 19  # Should be described in Golang's time format.
 20  time_format: "{{ .Log.TimeFormat }}"
 21  # Path to the log file. Leave empty to write to stderr.
 22  #path: "{{ .Log.Path }}"
 23
 24# The SSH server configuration.
 25ssh:
 26  # Enable SSH.
 27  enabled: {{ .SSH.Enabled }}
 28
 29  # The address on which the SSH server will listen.
 30  listen_addr: "{{ .SSH.ListenAddr }}"
 31
 32  # The public URL of the SSH server.
 33  # This is the address that will be used to clone repositories.
 34  public_url: "{{ .SSH.PublicURL }}"
 35
 36  # The path to the SSH server's private key.
 37  key_path: {{ .SSH.KeyPath }}
 38
 39  # The path to the server's client private key. This key will be used to
 40  # authenticate the server to make git requests to ssh remotes.
 41  client_key_path: {{ .SSH.ClientKeyPath }}
 42
 43  # The maximum number of seconds a connection can take.
 44  # A value of 0 means no timeout.
 45  max_timeout: {{ .SSH.MaxTimeout }}
 46
 47  # The number of seconds a connection can be idle before it is closed.
 48  # A value of 0 means no timeout.
 49  idle_timeout: {{ .SSH.IdleTimeout }}
 50
 51# The Git daemon configuration.
 52git:
 53  # Enable the Git daemon.
 54  enabled: {{ .Git.Enabled }}
 55
 56  # The address on which the Git daemon will listen.
 57  listen_addr: "{{ .Git.ListenAddr }}"
 58
 59  # The public URL of the Git daemon server.
 60  # This is the address that will be used to clone repositories.
 61  public_url: "{{ .Git.PublicURL }}"
 62
 63  # The maximum number of seconds a connection can take.
 64  # A value of 0 means no timeout.
 65  max_timeout: {{ .Git.MaxTimeout }}
 66
 67  # The number of seconds a connection can be idle before it is closed.
 68  idle_timeout: {{ .Git.IdleTimeout }}
 69
 70  # The maximum number of concurrent connections.
 71  max_connections: {{ .Git.MaxConnections }}
 72
 73# The HTTP server configuration.
 74http:
 75  # Enable the HTTP server.
 76  enabled: {{ .HTTP.Enabled }}
 77
 78  # The address on which the HTTP server will listen.
 79  listen_addr: "{{ .HTTP.ListenAddr }}"
 80
 81  # The path to the TLS private key.
 82  tls_key_path: {{ .HTTP.TLSKeyPath }}
 83
 84  # The path to the TLS certificate.
 85  tls_cert_path: {{ .HTTP.TLSCertPath }}
 86
 87  # The public URL of the HTTP server.
 88  # This is the address that will be used to clone repositories.
 89  # Make sure to use https:// if you are using TLS.
 90  public_url: "{{ .HTTP.PublicURL }}"
 91
 92  # The cross-origin request security options
 93  cors:
 94    # The allowed cross-origin headers
 95    allowed_headers:
 96       - "Accept"
 97       - "Accept-Language"
 98       - "Content-Language"
 99       - "Content-Type"
100       - "Origin"
101       - "X-Requested-With"
102       - "User-Agent"
103       - "Authorization"
104       - "Access-Control-Request-Method"
105       - "Access-Control-Allow-Origin"
106    # The allowed cross-origin URLs
107    allowed_origins:
108       - "{{ .HTTP.PublicURL }}" # always allowed
109       # - "https://example.com"
110    # The allowed cross-origin methods
111    allowed_methods:
112       - "GET"
113       - "HEAD"
114       - "POST"
115       - "PUT"
116       - "OPTIONS"
117
118# The stats server configuration.
119stats:
120  # Enable the stats server.
121  enabled: {{ .Stats.Enabled }}
122
123  # The address on which the stats server will listen.
124  listen_addr: "{{ .Stats.ListenAddr }}"
125
126# The database configuration.
127db:
128  # The database driver to use.
129  # Valid values are "sqlite" and "postgres".
130  driver: "{{ .DB.Driver }}"
131  # The database data source name.
132  # This is driver specific and can be a file path or connection string.
133  # Make sure foreign key support is enabled when using SQLite.
134  data_source: "{{ .DB.DataSource }}"
135
136# Git LFS configuration.
137lfs:
138  # Enable Git LFS.
139  enabled: {{ .LFS.Enabled }}
140  # Enable Git SSH transfer.
141  ssh_enabled: {{ .LFS.SSHEnabled }}
142
143# Cron job configuration
144jobs:
145  mirror_pull: "{{ .Jobs.MirrorPull }}"
146
147# Additional admin keys.
148#initial_admin_keys:
149#  - "ssh-rsa AAAAB3NzaC1yc2..."
150`))
151
152func newConfigFile(cfg *Config) string {
153	var b bytes.Buffer
154	configFileTmpl.Execute(&b, cfg) // nolint: errcheck
155	return b.String()
156}