mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-19 16:14:39 +00:00
fix (api): api key validation
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ git clone https://github.com/mickael-kerjean/filestash
|
|||||||
cd filestash
|
cd filestash
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
npm install # frontend dependencies
|
npm install --legacy-peer-deps # frontend dependencies
|
||||||
make build_init # install the required static libraries
|
make build_init # install the required static libraries
|
||||||
mkdir -p ./dist/data/state/
|
mkdir -p ./dist/data/state/
|
||||||
cp -R config ./dist/data/state/
|
cp -R config ./dist/data/state/
|
||||||
|
|||||||
@@ -8,20 +8,20 @@ import (
|
|||||||
|
|
||||||
func VerifyApiKey(api_key string) (host string, err error) {
|
func VerifyApiKey(api_key string) (host string, err error) {
|
||||||
isApiEnabled := Config.Get("features.api.enable").Bool()
|
isApiEnabled := Config.Get("features.api.enable").Bool()
|
||||||
apiKey := Config.Get("feature.api.api_key").String()
|
allowedApiKeys := Config.Get("features.api.api_key").String()
|
||||||
|
|
||||||
if isApiEnabled == false {
|
if isApiEnabled == false {
|
||||||
return "", NewError("Api is not enabled", 503)
|
return "", NewError("Api is not enabled", 503)
|
||||||
} else if apiKey == os.Getenv("API_KEY") {
|
} else if api_key == os.Getenv("API_KEY") {
|
||||||
return "*", nil
|
return "*", nil
|
||||||
}
|
}
|
||||||
lines := strings.Split(apiKey, "\n")
|
lines := strings.Split(allowedApiKeys, "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
line = regexp.MustCompile(` #.*`).ReplaceAllString(line, "") // remove comment
|
line = regexp.MustCompile(` #.*`).ReplaceAllString(line, "") // remove comment
|
||||||
chunks := strings.SplitN(line, " ", 2)
|
chunks := strings.SplitN(line, " ", 2)
|
||||||
if len(chunks) == 0 {
|
if len(chunks) == 0 {
|
||||||
continue
|
continue
|
||||||
} else if chunks[0] != apiKey {
|
} else if chunks[0] != api_key {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(chunks) == 1 {
|
if len(chunks) == 1 {
|
||||||
|
|||||||
Reference in New Issue
Block a user