|
|
@ -8,7 +8,6 @@ package setting |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/base64" |
|
|
|
"encoding/base64" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
|
|
|
|
"math" |
|
|
|
"math" |
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
@ -1082,28 +1081,22 @@ func loadInternalToken(sec *ini.Section) string { |
|
|
|
} |
|
|
|
} |
|
|
|
switch tempURI.Scheme { |
|
|
|
switch tempURI.Scheme { |
|
|
|
case "file": |
|
|
|
case "file": |
|
|
|
fp, err := os.OpenFile(tempURI.RequestURI(), os.O_RDWR, 0o600) |
|
|
|
buf, err := os.ReadFile(tempURI.RequestURI()) |
|
|
|
if err != nil { |
|
|
|
if err != nil && !os.IsNotExist(err) { |
|
|
|
log.Fatal("Failed to open InternalTokenURI (%s): %v", uri, err) |
|
|
|
log.Fatal("Failed to open InternalTokenURI (%s): %v", uri, err) |
|
|
|
} |
|
|
|
} |
|
|
|
defer fp.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf, err := io.ReadAll(fp) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatal("Failed to read InternalTokenURI (%s): %v", uri, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// No token in the file, generate one and store it.
|
|
|
|
// No token in the file, generate one and store it.
|
|
|
|
if len(buf) == 0 { |
|
|
|
if len(buf) == 0 { |
|
|
|
token, err := generate.NewInternalToken() |
|
|
|
token, err := generate.NewInternalToken() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal("Error generate internal token: %v", err) |
|
|
|
log.Fatal("Error generate internal token: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, err := io.WriteString(fp, token); err != nil { |
|
|
|
err = os.WriteFile(tempURI.RequestURI(), []byte(token), 0o600) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Fatal("Error writing to InternalTokenURI (%s): %v", uri, err) |
|
|
|
log.Fatal("Error writing to InternalTokenURI (%s): %v", uri, err) |
|
|
|
} |
|
|
|
} |
|
|
|
return token |
|
|
|
return token |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return strings.TrimSpace(string(buf)) |
|
|
|
return strings.TrimSpace(string(buf)) |
|
|
|
default: |
|
|
|
default: |
|
|
|
log.Fatal("Unsupported URI-Scheme %q (INTERNAL_TOKEN_URI = %q)", tempURI.Scheme, uri) |
|
|
|
log.Fatal("Unsupported URI-Scheme %q (INTERNAL_TOKEN_URI = %q)", tempURI.Scheme, uri) |
|
|
|