Skip to content

Commit

Permalink
Add validate
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Jul 25, 2023
1 parent 9d6381d commit 1cd5c92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package common

const (
SERVICENAME = "casaos"
VERSION = "0.4.4"
VERSION = "0.4.4.1"
BODY = " "
)
30 changes: 30 additions & 0 deletions route/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ func InitV2DocRouter(docHTML string, docYAML string) http.Handler {

func InitFile() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token := r.URL.Query().Get("token")
if len(token) == 0 {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(`{"message": "token not found"}`))
return
}

valid, _, errs := jwt.Validate(token, func() (*ecdsa.PublicKey, error) { return external.GetPublicKey(config.CommonInfo.RuntimePath) })
if errs != nil || !valid {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(`{"message": "validation failure"}`))
return
}
filePath := r.URL.Query().Get("path")
fileName := path.Base(filePath)
w.Header().Add("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(fileName))
Expand All @@ -158,6 +173,21 @@ func InitFile() http.Handler {

func InitDir() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token := r.URL.Query().Get("token")
if len(token) == 0 {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(`{"message": "token not found"}`))
return
}

valid, _, errs := jwt.Validate(token, func() (*ecdsa.PublicKey, error) { return external.GetPublicKey(config.CommonInfo.RuntimePath) })
if errs != nil || !valid {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(`{"message": "validation failure"}`))
return
}
t := r.URL.Query().Get("format")
files := r.URL.Query().Get("files")

Expand Down

0 comments on commit 1cd5c92

Please sign in to comment.