add requester to api
This commit is contained in:
parent
3301098aa1
commit
da4110a47b
4 changed files with 41 additions and 19 deletions
|
|
@ -36,13 +36,13 @@
|
||||||
|
|
||||||
<!-- Output path -->
|
<!-- Output path -->
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<label class="flex-1 bg-yellow-100 font-bold rounded text-center" for="output_path">Output Path</label>
|
<label class="flex-1 bg-yellow-100 font-bold rounded text-center" for="output_path">Output Path (.json)</label>
|
||||||
<input class="flex-1 mx-1 bg-slate-300 hover:bg-blue-400 text-center border border-collapse rounded-md" id="output_path" formControlName="output_path" type="text" required>
|
<input class="flex-1 mx-1 bg-slate-300 hover:bg-blue-400 text-center border border-collapse rounded-md" id="output_path" formControlName="output_path" type="text" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Changelog path -->
|
<!-- Changelog path -->
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<label class="flex-1 bg-yellow-100 font-bold rounded text-center" for="changelog_path">Changelog Path</label>
|
<label class="flex-1 bg-yellow-100 font-bold rounded text-center" for="changelog_path">Changelog Path (.json)</label>
|
||||||
<input class="flex-1 mx-1 bg-slate-300 hover:bg-blue-400 text-center border border-collapse rounded-md" id="changelog_path" formControlName="changelog_path" type="text" required>
|
<input class="flex-1 mx-1 bg-slate-300 hover:bg-blue-400 text-center border border-collapse rounded-md" id="changelog_path" formControlName="changelog_path" type="text" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,22 @@ export class MergeComponent<T> {
|
||||||
changelog_path: ""
|
changelog_path: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mergeLogs: Map<string, string> | void | undefined
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private targets: MergeServiceService,
|
private targets: MergeServiceService,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private httpClient: HttpClient,
|
private httpClient: HttpClient,
|
||||||
){}
|
){
|
||||||
|
// Default fetching logs
|
||||||
|
|
||||||
|
// fetch html
|
||||||
|
// this.fetchLogsToDisplay("", true, false);
|
||||||
|
// // fetch log file
|
||||||
|
// this.fetchLogsToDisplay("", false, false);
|
||||||
|
// // fetch json
|
||||||
|
// this.mergeLogs = this.fetchLogsToDisplay("", false, true);
|
||||||
|
}
|
||||||
|
|
||||||
private isException(value: any){
|
private isException(value: any){
|
||||||
return this.exceptionValues.includes(value)
|
return this.exceptionValues.includes(value)
|
||||||
|
|
@ -46,7 +56,6 @@ export class MergeComponent<T> {
|
||||||
this.targets.changelog_path = this.mergeForm.value.changelog_path!;
|
this.targets.changelog_path = this.mergeForm.value.changelog_path!;
|
||||||
|
|
||||||
// TODO: Fetch merge. Modify this to websocket
|
// TODO: Fetch merge. Modify this to websocket
|
||||||
let mergeLogs;
|
|
||||||
this.httpClient.post<T>(environment.api+"/merge", {
|
this.httpClient.post<T>(environment.api+"/merge", {
|
||||||
master: this.targets.master_version,
|
master: this.targets.master_version,
|
||||||
dev: this.targets.dev_version,
|
dev: this.targets.dev_version,
|
||||||
|
|
@ -64,14 +73,14 @@ export class MergeComponent<T> {
|
||||||
// fetch log file
|
// fetch log file
|
||||||
this.fetchLogsToDisplay("", false, false);
|
this.fetchLogsToDisplay("", false, false);
|
||||||
// fetch json
|
// fetch json
|
||||||
mergeLogs = this.fetchLogsToDisplay("", false, true);
|
this.mergeLogs = this.fetchLogsToDisplay("", false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchLogsToDisplay(query: string, isDisplayOnly: boolean, requestJson: boolean){
|
fetchLogsToDisplay(query: string, isDisplayOnly: boolean, requestJson: boolean) : Map<string, string> | void{
|
||||||
let additionalParams:string = "?query=";
|
let additionalParams:string = "?query=";
|
||||||
if(query != ""){
|
if(query != ""){
|
||||||
additionalParams += query
|
additionalParams += query
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,10 @@ def merge(args):
|
||||||
global debug
|
global debug
|
||||||
debug = args[4] if args[4] != None else False
|
debug = args[4] if args[4] != None else False
|
||||||
|
|
||||||
|
if len(args) > 5:
|
||||||
|
global requester
|
||||||
|
requester = args[5] if args[5] != None else ""
|
||||||
|
|
||||||
#
|
#
|
||||||
if (os.path.exists(master_path) == False) and str(master_path).isdigit():
|
if (os.path.exists(master_path) == False) and str(master_path).isdigit():
|
||||||
master_path = CoffeeRecipeDirectory + "/coffeethai02_" + str(master_path) + ".json"
|
master_path = CoffeeRecipeDirectory + "/coffeethai02_" + str(master_path) + ".json"
|
||||||
|
|
@ -135,6 +139,17 @@ def merge(args):
|
||||||
print("Master file size => ",os.stat(master_path).st_size)
|
print("Master file size => ",os.stat(master_path).st_size)
|
||||||
print("Dev file size => ",os.stat(dev_path).st_size)
|
print("Dev file size => ",os.stat(dev_path).st_size)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Requester
|
||||||
|
events_json.append(create_map(
|
||||||
|
events_action="REQUESTER",
|
||||||
|
log="GetRequestFrom",
|
||||||
|
additional=[{
|
||||||
|
"timestamp": GetDateTimeString(),
|
||||||
|
"requester": requester
|
||||||
|
}]))
|
||||||
|
events.append(GetDateTimeString()+"\t[REQUEST]\t\tget request from \""+requester+"\"\n")
|
||||||
|
|
||||||
events_json.append(create_map(events_action="MERGE", log=devName.split("/")[-1]+" into "+masterName.split("/")[-1]))
|
events_json.append(create_map(events_action="MERGE", log=devName.split("/")[-1]+" into "+masterName.split("/")[-1]))
|
||||||
events.append(GetDateTimeString()+"\t[MERGE]\t\tMerging "+devName.split("/")[-1]+" into "+masterName.split("/")[-1]+"\n")
|
events.append(GetDateTimeString()+"\t[MERGE]\t\tMerging "+devName.split("/")[-1]+" into "+masterName.split("/")[-1]+"\n")
|
||||||
# print(GetDateTimeString()+"\tMerging "+dev_file.name.split("/")[-1]+" into "+master_file.name.split("/")[-1]+"\n")
|
# print(GetDateTimeString()+"\tMerging "+dev_file.name.split("/")[-1]+" into "+master_file.name.split("/")[-1]+"\n")
|
||||||
|
|
@ -187,7 +202,7 @@ def merge(args):
|
||||||
|
|
||||||
# log json file
|
# log json file
|
||||||
|
|
||||||
if os.stat(file_path+".json").st_size == 0:
|
if not os.path.exists(file_path+".json") or os.stat(file_path+".json").st_size == 0:
|
||||||
with open(file_path+".json", "w+",encoding="utf-8") as outlogfile:
|
with open(file_path+".json", "w+",encoding="utf-8") as outlogfile:
|
||||||
json.dump({"logs"+GetDateTimeString()+"*": events_json}, outlogfile, indent=2, ensure_ascii=False)
|
json.dump({"logs"+GetDateTimeString()+"*": events_json}, outlogfile, indent=2, ensure_ascii=False)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ func (s *Server) createHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify token by request to google api
|
// 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 {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
|
@ -112,11 +112,12 @@ func (s *Server) createHandler() {
|
||||||
|
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
log.Println("res: ", res)
|
||||||
var tokenInfo map[string]interface{}
|
var tokenInfo map[string]interface{}
|
||||||
json.NewDecoder(res.Body).Decode(&tokenInfo)
|
json.NewDecoder(res.Body).Decode(&tokenInfo)
|
||||||
|
|
||||||
context := context.WithValue(r.Context(), "user", tokenInfo)
|
context := context.WithValue(r.Context(), "user", tokenInfo)
|
||||||
|
log.Println("decode res: ", tokenInfo["email"])
|
||||||
next.ServeHTTP(w, r.WithContext(context))
|
next.ServeHTTP(w, r.WithContext(context))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -152,13 +153,9 @@ func (s *Server) createHandler() {
|
||||||
master_path := repo_path + master_version + ".json"
|
master_path := repo_path + master_version + ".json"
|
||||||
dev_path := repo_path + dev_version + ".json"
|
dev_path := repo_path + dev_version + ".json"
|
||||||
|
|
||||||
// // output path
|
// Get who's requesting
|
||||||
// output_path := ""
|
user := r.Context().Value("user").(map[string]interface{})
|
||||||
|
log.Println("User: ", user["email"].(string))
|
||||||
// // changelog path
|
|
||||||
// changelog_path := ""
|
|
||||||
|
|
||||||
// TODO: Call merge api if found
|
|
||||||
|
|
||||||
// lookup for python exec
|
// lookup for python exec
|
||||||
py_exec, err := exec.LookPath("python")
|
py_exec, err := exec.LookPath("python")
|
||||||
|
|
@ -176,7 +173,7 @@ func (s *Server) createHandler() {
|
||||||
}
|
}
|
||||||
defer merge_api.Close()
|
defer merge_api.Close()
|
||||||
log.Println("Locate python api", merge_api.Name())
|
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)
|
log.Println("Run merge command", cmd)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
|
|
@ -206,12 +203,13 @@ func (s *Server) createHandler() {
|
||||||
if rj, ok := postRequest["requestJson"].(bool); ok {
|
if rj, ok := postRequest["requestJson"].(bool); ok {
|
||||||
if rj {
|
if rj {
|
||||||
file_ext = ".json"
|
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
|
changelog_path := "cofffeemachineConfig/changelog/testlog" + file_ext
|
||||||
logFile, err := os.Open(changelog_path)
|
logFile, err := os.Open(changelog_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue