add requester to api

This commit is contained in:
pakintada@gmail.com 2023-09-21 13:52:00 +07:00
parent 3301098aa1
commit da4110a47b
4 changed files with 41 additions and 19 deletions

View file

@ -103,7 +103,7 @@ func (s *Server) createHandler() {
}
// verify token by request to google api
res, err := http.Get("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + url.QueryEscape(cookie.Value))
res, err := http.Get("https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=" + url.QueryEscape(cookie.Value))
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
@ -112,11 +112,12 @@ func (s *Server) createHandler() {
defer res.Body.Close()
log.Println("res: ", res)
var tokenInfo map[string]interface{}
json.NewDecoder(res.Body).Decode(&tokenInfo)
context := context.WithValue(r.Context(), "user", tokenInfo)
log.Println("decode res: ", tokenInfo["email"])
next.ServeHTTP(w, r.WithContext(context))
})
})
@ -152,13 +153,9 @@ func (s *Server) createHandler() {
master_path := repo_path + master_version + ".json"
dev_path := repo_path + dev_version + ".json"
// // output path
// output_path := ""
// // changelog path
// changelog_path := ""
// TODO: Call merge api if found
// Get who's requesting
user := r.Context().Value("user").(map[string]interface{})
log.Println("User: ", user["email"].(string))
// lookup for python exec
py_exec, err := exec.LookPath("python")
@ -176,7 +173,7 @@ func (s *Server) createHandler() {
}
defer merge_api.Close()
log.Println("Locate python api", merge_api.Name())
cmd := exec.Command(py_exec, merge_api.Name(), "merge", master_path, dev_path, output_path, changelog_path)
cmd := exec.Command(py_exec, merge_api.Name(), "merge", master_path, dev_path, output_path, changelog_path, "", user["email"].(string))
log.Println("Run merge command", cmd)
out, err := cmd.CombinedOutput()
@ -206,12 +203,13 @@ func (s *Server) createHandler() {
if rj, ok := postRequest["requestJson"].(bool); ok {
if rj {
file_ext = ".json"
} else if !rb && !rj {
file_ext = ".log"
}
} else if !rb {
file_ext = ".log"
}
}
log.Println("Log file ext: ", file_ext)
changelog_path := "cofffeemachineConfig/changelog/testlog" + file_ext
logFile, err := os.Open(changelog_path)
if err != nil {