diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-08 20:21:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-08 20:21:02 +0900 |
| commit | 6b74e3853ff183f63b6cd9b94331446a39d562a6 (patch) | |
| tree | 27719c95313cc500eae01ca3ee2a1a007836599c /backend/taskqueue/processor.go | |
| parent | f766fae6c0fb10b906224660c61c9693cf74c426 (diff) | |
| download | iosdc-japan-2025-albatross-6b74e3853ff183f63b6cd9b94331446a39d562a6.tar.gz iosdc-japan-2025-albatross-6b74e3853ff183f63b6cd9b94331446a39d562a6.tar.zst iosdc-japan-2025-albatross-6b74e3853ff183f63b6cd9b94331446a39d562a6.zip | |
feat(worker): re-enable authentication between api-server and worker
Diffstat (limited to 'backend/taskqueue/processor.go')
| -rw-r--r-- | backend/taskqueue/processor.go | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/backend/taskqueue/processor.go b/backend/taskqueue/processor.go index cf90cbc..149ab67 100644 --- a/backend/taskqueue/processor.go +++ b/backend/taskqueue/processor.go @@ -7,6 +7,7 @@ import ( "fmt" "net/http" + "github.com/nsfisis/iosdc-japan-2024-albatross/backend/auth" "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" ) @@ -62,10 +63,24 @@ func (p *processor) doProcessTaskCompileSwiftToWasm( if err != nil { return nil, fmt.Errorf("json.Marshal failed: %v", err) } - res, err := http.Post("http://worker:80/api/swiftc", "application/json", bytes.NewBuffer(reqJSON)) + req, err := http.NewRequest("POST", "http://worker:80/api/swiftc", bytes.NewBuffer(reqJSON)) if err != nil { - return nil, fmt.Errorf("http.Post failed: %v", err) + return nil, fmt.Errorf("http.NewRequest failed: %v", err) } + req.Header.Set("Content-Type", "application/json") + jwt, err := auth.NewAnonymousJWT() + if err != nil { + return nil, fmt.Errorf("auth.NewAnonymousJWT failed: %v", err) + } + req.Header.Set("Authorization", "Bearer "+jwt) + + client := &http.Client{} + res, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("client.Do failed: %v", err) + } + defer res.Body.Close() + resData := swiftcResponseData{} if err := json.NewDecoder(res.Body).Decode(&resData); err != nil { return nil, fmt.Errorf("json.Decode failed: %v", err) @@ -99,10 +114,24 @@ func (p *processor) doProcessTaskCompileWasmToNativeExecutable( if err != nil { return nil, fmt.Errorf("json.Marshal failed: %v", err) } - res, err := http.Post("http://worker:80/api/wasmc", "application/json", bytes.NewBuffer(reqJSON)) + req, err := http.NewRequest("POST", "http://worker:80/api/wasmc", bytes.NewBuffer(reqJSON)) + if err != nil { + return nil, fmt.Errorf("http.NewRequest failed: %v", err) + } + req.Header.Set("Content-Type", "application/json") + jwt, err := auth.NewAnonymousJWT() + if err != nil { + return nil, fmt.Errorf("auth.NewAnonymousJWT failed: %v", err) + } + req.Header.Set("Authorization", "Bearer "+jwt) + + client := &http.Client{} + res, err := client.Do(req) if err != nil { - return nil, fmt.Errorf("http.Post failed: %v", err) + return nil, fmt.Errorf("client.Do failed: %v", err) } + defer res.Body.Close() + resData := wasmcResponseData{} if err := json.NewDecoder(res.Body).Decode(&resData); err != nil { return nil, fmt.Errorf("json.Decode failed: %v", err) @@ -138,10 +167,24 @@ func (p *processor) doProcessTaskRunTestcase( if err != nil { return nil, fmt.Errorf("json.Marshal failed: %v", err) } - res, err := http.Post("http://worker:80/api/testrun", "application/json", bytes.NewBuffer(reqJSON)) + req, err := http.NewRequest("POST", "http://worker:80/api/testrun", bytes.NewBuffer(reqJSON)) + if err != nil { + return nil, fmt.Errorf("http.NewRequest failed: %v", err) + } + req.Header.Set("Content-Type", "application/json") + jwt, err := auth.NewAnonymousJWT() if err != nil { - return nil, fmt.Errorf("http.Post failed: %v", err) + return nil, fmt.Errorf("auth.NewAnonymousJWT failed: %v", err) } + req.Header.Set("Authorization", "Bearer "+jwt) + + client := &http.Client{} + res, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("client.Do failed: %v", err) + } + defer res.Body.Close() + resData := testrunResponseData{} if err := json.NewDecoder(res.Body).Decode(&resData); err != nil { return nil, fmt.Errorf("json.Decode failed: %v", err) |
