-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into LANTERN-782-curemd-webscraper
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 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
56 changes: 56 additions & 0 deletions
56
endpointmanager/pkg/chplendpointquerier/emdscloudwebscraper.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,56 @@ | ||
package chplendpointquerier | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func EmdsCloudWebscraper(CHPLURL string, fileToWriteTo string) { | ||
var entry LanternEntry | ||
var lanternEntryList []LanternEntry | ||
var endpointEntryList EndpointList | ||
|
||
client := &http.Client{} | ||
req, err := http.NewRequest("GET", CHPLURL, nil) | ||
if err != nil { | ||
log.Fatalf("Error creating HTTP request: %v", err) | ||
return | ||
} | ||
|
||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36") | ||
|
||
res, err := client.Do(req) | ||
if err != nil { | ||
log.Fatalf("Error making HTTP request: %v", err) | ||
return | ||
} | ||
defer res.Body.Close() | ||
|
||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
log.Fatalf("Error reading response body: %v", err) | ||
return | ||
} | ||
|
||
var resources []map[string]interface{} | ||
if err := json.Unmarshal(body, &resources); err != nil { | ||
log.Fatalf("Error parsing JSON: %v", err) | ||
return | ||
} | ||
|
||
for _, resource := range resources { | ||
if url, ok := resource["ResourceUrl"].(string); ok { | ||
entry.URL = url | ||
lanternEntryList = append(lanternEntryList, entry) | ||
} | ||
} | ||
endpointEntryList.Endpoints = lanternEntryList | ||
|
||
err = WriteCHPLFile(endpointEntryList, fileToWriteTo) | ||
if err != nil { | ||
log.Fatalf("Error writing to file: %v", err) | ||
} | ||
} |