-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the log event trigger to match the schema. (#15035)
* Fix the log event trigger to match the schema. * Decode the bytes instead and add an 0x prefix * Fix wrapping the log.Data as values.Map and ensure working tests * Fixed lint errors * Fixed more lint errors --------- Co-authored-by: Sri Kidambi <[email protected]>
- Loading branch information
1 parent
4d14533
commit cf726db
Showing
4 changed files
with
134 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 18 additions & 5 deletions
23
core/capabilities/triggers/logevent/logeventcap/event_trigger_generated.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
core/scripts/gateway/web_api_trigger/test_server/test_server.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
// Log request method and URL | ||
fmt.Printf("Received %s request for %s\n", r.Method, r.URL.Path) | ||
|
||
// Handle GET requests | ||
if r.Method == http.MethodGet { | ||
fmt.Println("GET request received") | ||
w.WriteHeader(http.StatusOK) | ||
_, err := w.Write([]byte("GET request received")) | ||
if err != nil { | ||
http.Error(w, "could not write request body", http.StatusInternalServerError) | ||
return | ||
} | ||
} | ||
|
||
// Handle POST requests | ||
if r.Method == http.MethodPost { | ||
body, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
http.Error(w, "Could not read request body", http.StatusInternalServerError) | ||
return | ||
} | ||
fmt.Printf("POST request body: %s\n", string(body)) | ||
|
||
w.WriteHeader(http.StatusOK) | ||
} | ||
} | ||
|
||
func lockHandler(w http.ResponseWriter, r *http.Request) { | ||
// Log request method and URL | ||
fmt.Printf("Received %s request for %s\n", r.Method, r.URL.Path) | ||
|
||
// Handle POST requests | ||
if r.Method == http.MethodPost { | ||
body, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
http.Error(w, "Could not read request body", http.StatusInternalServerError) | ||
return | ||
} | ||
fmt.Printf("Assets locked. E2E ID: %s\n", string(body)) | ||
|
||
w.WriteHeader(http.StatusOK) | ||
} | ||
} | ||
|
||
func unlockHandler(w http.ResponseWriter, r *http.Request) { | ||
// Log request method and URL | ||
fmt.Printf("Received %s request for %s\n", r.Method, r.URL.Path) | ||
|
||
// Handle POST requests | ||
if r.Method == http.MethodPost { | ||
body, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
http.Error(w, "Could not read request body", http.StatusInternalServerError) | ||
return | ||
} | ||
fmt.Printf("Assets unlocked. Settlement E2E ID: %s\n", string(body)) | ||
|
||
w.WriteHeader(http.StatusOK) | ||
} | ||
} | ||
|
||
func main() { | ||
// Register the handler for all incoming requests | ||
http.HandleFunc("/", handler) | ||
http.HandleFunc("/lock", lockHandler) | ||
http.HandleFunc("/unlock", unlockHandler) | ||
|
||
// Listen on port 1000 | ||
port := ":1000" | ||
fmt.Printf("Server listening on port %s\n", port) | ||
server := &http.Server{ | ||
Addr: port, | ||
ReadHeaderTimeout: 30 * time.Second, | ||
} | ||
err := server.ListenAndServe() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |