Skip to content

Commit

Permalink
Implemented POST request
Browse files Browse the repository at this point in the history
  • Loading branch information
alex27riva committed Oct 24, 2024
1 parent 2fe11d2 commit e0741fd
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions cmd/urlscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ See the LICENSE file for details.
package cmd

import (
"bytes"
"encoding/json"
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"net/http"
"soc-cli/internal/util"
"time"
)

Expand Down Expand Up @@ -47,30 +47,15 @@ func submitURLScan(url string) (string, error) {
return "", fmt.Errorf("API key is missing! Please set the urlscan api_key in config.yaml file")
}

requestBody, err := json.Marshal(map[string]string{"url": url, "visibility": defautVisibility})
if err != nil {
return "", fmt.Errorf("failed to create request body: %v", err)
}
requestBody := map[string]string{"url": url, "visibility": defautVisibility}

req, err := http.NewRequest("POST", urlscanScanApi, bytes.NewBuffer(requestBody))
if err != nil {
return "", fmt.Errorf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("API-Key", apiKey)
var result map[string]interface{}

err := util.MakePOSTRequest(urlscanScanApi, map[string]string{"API-Key": apiKey}, requestBody, &result)

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return "", fmt.Errorf("failed to submit URL scan request: %v", err)
}
defer resp.Body.Close()

var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return "", fmt.Errorf("failed to parse response: %v", err)
}

// Extract the scan ID to check for the scan status
scanID, ok := result["uuid"].(string)
if !ok {
Expand Down

0 comments on commit e0741fd

Please sign in to comment.