mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-01-04 16:00:08 -06:00
Don't show S3 credential input if already supplied by env variables #151, removed debug output
This commit is contained in:
@@ -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."))
|
||||
}
|
||||
|
||||
@@ -380,6 +380,7 @@
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8">
|
||||
{{ if not .S3EnvProvided }}
|
||||
<label for="s3_bucket">Bucket Name:</label>
|
||||
<input type="text" class="form-control" id="s3_bucket" name="s3_bucket" placeholder="Bucket Name" data-min="1" data-validate="validateMinLength">
|
||||
</div><br><br>
|
||||
@@ -399,17 +400,29 @@
|
||||
<div class="col-sm-8">
|
||||
<label for="s3_endpoint">Endpoint:</label>
|
||||
<input type="text" class="form-control" id="s3_endpoint" name="s3_endpoint" placeholder="Endpoint (leave blank if AWS S3)">
|
||||
<br><br>
|
||||
<button id="downloadbutton" class="btn btn-light" type="button" onclick="TestAWS(this, true);">
|
||||
Test configuration
|
||||
</button>
|
||||
{{ else }}
|
||||
Credentials have been provided with environment variables and cannot be changed.
|
||||
<br><br>
|
||||
<button id="downloadbutton" class="btn btn-light" type="button" onclick="TestAWS(this);">
|
||||
<button id="downloadbutton" class="btn btn-light" type="button" onclick="TestAWS(this, false);">
|
||||
Test configuration
|
||||
</button>
|
||||
<input type="hidden" id="s3_bucket" name="s3_bucket">
|
||||
<input type="hidden" id="s3_region" name="s3_region" >
|
||||
<input type="hidden" id="s3_api" name="s3_api">
|
||||
<input type="hidden" id="s3_secret" name="s3_secret">
|
||||
<input type="hidden" id="s3_endpoint" name="s3_endpoint">
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function TestAWS(button) {
|
||||
function TestAWS(button, isManual) {
|
||||
button.disabled=true;
|
||||
button.innerHTML="Connecting...";
|
||||
|
||||
@@ -421,21 +434,27 @@ function TestAWS(button) {
|
||||
button.disabled=false;
|
||||
alert(xhr.responseText);
|
||||
} else {
|
||||
alert("ey");
|
||||
// Server Error
|
||||
alert("Unable to connect to Gokapi server");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open("POST", "./testaws", true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify({
|
||||
bucket: document.getElementById("s3_bucket").value,
|
||||
region: document.getElementById("s3_region").value,
|
||||
apikey: document.getElementById("s3_api").value,
|
||||
apisecret: document.getElementById("s3_secret").value,
|
||||
endpoint: document.getElementById("s3_endpoint").value
|
||||
}));
|
||||
if (isManual) {
|
||||
xhr.send(JSON.stringify({
|
||||
bucket: document.getElementById("s3_bucket").value,
|
||||
region: document.getElementById("s3_region").value,
|
||||
apikey: document.getElementById("s3_api").value,
|
||||
apisecret: document.getElementById("s3_secret").value,
|
||||
endpoint: document.getElementById("s3_endpoint").value,
|
||||
isEnvProvided: false
|
||||
}));
|
||||
} else {
|
||||
xhr.send(JSON.stringify({
|
||||
isEnvProvided: true
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
@@ -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 }}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user