summaryrefslogtreecommitdiff
path: root/pkg/ui/views/api.go
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-13 13:24:08 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-13 13:24:28 +0200
commit76f46e54175253d4b2ba61b9cb8f2525a48c15d8 (patch)
tree8664af77e9bd66ae578fa83870026c2d6bca6065 /pkg/ui/views/api.go
parent72382e2dd9e509e6467dab9bfd11b7c7ddcf918a (diff)
Create adversary's server
Diffstat (limited to 'pkg/ui/views/api.go')
-rw-r--r--pkg/ui/views/api.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkg/ui/views/api.go b/pkg/ui/views/api.go
new file mode 100644
index 0000000..3788f91
--- /dev/null
+++ b/pkg/ui/views/api.go
@@ -0,0 +1,44 @@
+package views
+
+import (
+ "bufio"
+ "bytes"
+ "fmt"
+ "net/http"
+ "os"
+)
+
+// getAuthorizationToken reads the authentication token from the .rahannarc file
+func getAuthorizationToken() (string, error) {
+ f, err := os.Open(".rahannarc")
+ if err != nil {
+ return "", err
+ }
+ defer f.Close()
+
+ scanner := bufio.NewScanner(f)
+ var authorization string
+ for scanner.Scan() {
+ authorization = scanner.Text()
+ }
+
+ if err := scanner.Err(); err != nil {
+ return "", fmt.Errorf("error reading auth token: %v", err)
+ }
+
+ return authorization, nil
+}
+
+// sendAPIRequest sends an HTTP request to the API with the given parameters
+func sendAPIRequest(method, url string, payload []byte, authorization string) (*http.Response, error) {
+ req, err := http.NewRequest(method, url, bytes.NewReader(payload))
+ if err != nil {
+ return nil, err
+ }
+
+ req.Header.Set("Content-Type", "application/json")
+ req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", authorization))
+
+ client := &http.Client{}
+ return client.Do(req)
+}