diff --git a/internal/configuration/setup/Setup.go b/internal/configuration/setup/Setup.go index 195a4bf..836929c 100644 --- a/internal/configuration/setup/Setup.go +++ b/internal/configuration/setup/Setup.go @@ -48,6 +48,8 @@ var isInitialSetup = true var username string var password string +// debugDisableAuth can be set to true for testing purposes. It will disable the +// password requirement for accessing the setup page const debugDisableAuth = false // RunIfFirstStart checks if config files exist and if not start a blocking webserver for setup @@ -576,6 +578,7 @@ type setupView struct { LocalhostOnly bool HasAwsFeature bool IsDocker bool + S3EnvProvided bool Port int OAuthUsers string OAuthGroups string @@ -613,6 +616,8 @@ func (v *setupView) loadFromConfig() { } else { v.Port = environment.DefaultPort } + env := environment.New() + v.S3EnvProvided = env.IsAwsProvided() } // Handling of /start @@ -672,12 +677,13 @@ func verifyPortNumber(port int) int { } type testAwsRequest struct { - Bucket string `json:"bucket"` - Region string `json:"region"` - ApiKey string `json:"apikey"` - ApiSecret string `json:"apisecret"` - Endpoint string `json:"endpoint"` - GokapiUrl string `json:"exturl"` + Bucket string `json:"bucket"` + Region string `json:"region"` + ApiKey string `json:"apikey"` + ApiSecret string `json:"apisecret"` + Endpoint string `json:"endpoint"` + GokapiUrl string `json:"exturl"` + EnvProvided bool `json:"isEnvProvided"` } // Handling of /testaws @@ -689,32 +695,45 @@ func handleTestAws(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Error: " + err.Error())) return } - awsconfig := models.AwsConfig{ - Bucket: t.Bucket, - Region: t.Region, - KeyId: t.ApiKey, - KeySecret: t.ApiSecret, - Endpoint: t.Endpoint, + var awsConfig models.AwsConfig + + if !t.EnvProvided { + awsConfig = models.AwsConfig{ + Bucket: t.Bucket, + Region: t.Region, + KeyId: t.ApiKey, + KeySecret: t.ApiSecret, + Endpoint: t.Endpoint, + } + } else { + env := environment.New() + awsConfig = models.AwsConfig{ + Bucket: env.AwsBucket, + Region: env.AwsRegion, + KeyId: env.AwsKeyId, + KeySecret: env.AwsKeySecret, + Endpoint: env.AwsEndpoint, + } } - ok, err := aws.IsValidLogin(awsconfig) + ok, err := aws.IsValidLogin(awsConfig) if err != nil { - w.Write([]byte("Error: " + err.Error())) + _, _ = w.Write([]byte("Error: " + err.Error())) return } if !ok { - w.Write([]byte("Error: Invalid or incomplete credentials provided")) + _, _ = w.Write([]byte("Error: Invalid or incomplete credentials provided")) return } - aws.Init(awsconfig) + aws.Init(awsConfig) ok, err = aws.IsCorsCorrectlySet(t.Bucket, t.GokapiUrl) aws.LogOut() if err != nil { - w.Write([]byte("Could not check CORS settings. Error: " + err.Error())) + _, _ = w.Write([]byte("Could not check CORS settings. Error: " + err.Error())) return } if !ok { - w.Write([]byte("Test OK, however CORS settings do not allow encrypted downloads.")) + _, _ = w.Write([]byte("Test OK, however CORS settings do not allow encrypted downloads.")) return } - w.Write([]byte("Test OK, CORS settings allow encrypted downloads.")) + _, _ = w.Write([]byte("Test OK, CORS settings allow encrypted downloads.")) } diff --git a/internal/configuration/setup/templates/setup.tmpl b/internal/configuration/setup/templates/setup.tmpl index 91d9a0d..7fb0f4b 100644 --- a/internal/configuration/setup/templates/setup.tmpl +++ b/internal/configuration/setup/templates/setup.tmpl @@ -380,6 +380,7 @@
+{{ if not .S3EnvProvided }}


@@ -399,17 +400,29 @@
+

+ +{{ else }} + Credentials have been provided with environment variables and cannot be changed.

- + + + + + +{{ end }}
@@ -720,11 +739,13 @@ function TestAWS(button) { {{ if .CloudSettings.Aws.Bucket }} document.getElementById("storage_sel").value = "cloud"; storageSelectionChanged(1); + {{ if not .S3EnvProvided }} document.getElementById("s3_bucket").value = "{{ .CloudSettings.Aws.Bucket }}"; document.getElementById("s3_region").value = "{{ .CloudSettings.Aws.Region }}"; document.getElementById("s3_api").value = "{{ .CloudSettings.Aws.KeyId }}"; document.getElementById("s3_secret").value = "{{ .CloudSettings.Aws.KeySecret }}"; document.getElementById("s3_endpoint").value = "{{ .CloudSettings.Aws.Endpoint }}"; + {{ end }} {{ end }}