Skip to content

Commit

Permalink
word
Browse files Browse the repository at this point in the history
  • Loading branch information
tanfarming committed Feb 12, 2024
1 parent c966c85 commit 301d8d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions ita/internal/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,11 @@ var Restore = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
})

var RewriteAssets = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := ret_rewrite_assets(r.URL.Query().Get("old_domain"), r.URL.Query().Get("new_domain"))
err := ret_rewrite_assets(
r.URL.Query().Get("old_domain"),
r.URL.Query().Get("new_domain"))
if err != nil {
http.Error(w, "failed", http.StatusInternalServerError)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "done")
Expand Down
11 changes: 7 additions & 4 deletions ita/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func main() {
router.Handle("/api/ita/undeploy", chk_tat_hdr()(internal.Undeploy))
router.Handle("/api/ita/custom-domain", chk_tat_hdr()(internal.CustomDomain))
router.Handle("/api/ita/restore", chk_tat_hdr()(internal.Restore))
router.Handle("/api/ita/rewrite_assets", chk_tat_hdr()(internal.RewriteAssets))

go internal.StartNewServer(router, 6000, false)
internal.StartNewServer(router, 6001, true)
Expand All @@ -103,7 +104,6 @@ func chk_tat_hdr() func(http.Handler) http.Handler {
http.NotFound(w, r)
return
}

// turkeyauthHost := "http://turkeyauth.turkey-services:9001"
turkeyauthHost := "https://auth.myhubs.dev"
if strings.HasSuffix(internal.GetCfg().HubDomain, "dev.myhubs.net") {
Expand All @@ -113,19 +113,22 @@ func chk_tat_hdr() func(http.Handler) http.Handler {
resp, err := http.Get(turkeyauthHost + "/chk_token?token=" + token)
if err != nil {
internal.Logger.Sugar().Debugf("reject -- err@chk_token: %v", err)
internal.Handle_NotFound(w, r)
// internal.Handle_NotFound(w, r)
http.Error(w, "bad token?", http.StatusForbidden)
return
} else if resp.StatusCode != http.StatusOK {
internal.Logger.Sugar().Debugf("reject -- bad resp.StatusCode: %v", resp.StatusCode)
internal.Handle_NotFound(w, r)
// internal.Handle_NotFound(w, r)
http.Error(w, "bad token", http.StatusForbidden)
return
}
email := resp.Header.Get("verified-UserEmail")
rootUserEmail := internal.GetCfg().RootUserEmail
internal.Logger.Sugar().Debugf("verified-UserEmail: %v, rootUserEmail: %v", resp.StatusCode, rootUserEmail)
if email != rootUserEmail {
internal.Logger.Sugar().Debugf("reject -- bad verified-UserEmail -- has: %v, need: %v", email, rootUserEmail)
internal.Handle_NotFound(w, r)
// internal.Handle_NotFound(w, r)
http.Error(w, "unauthorized user", http.StatusForbidden)
return
}

Expand Down

0 comments on commit 301d8d4

Please sign in to comment.