-
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.
- Loading branch information
1 parent
52471df
commit 33a55c4
Showing
2 changed files
with
51 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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
package chplendpointquerier | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"encoding/json" | ||
|
||
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) | ||
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) | ||
|
||
defer res.Body.Close() | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
log.Fatalf("Error reading response body: %v", err) | ||
} | ||
|
||
var resources []map[string]interface{} | ||
if err := json.Unmarshal(body, &resources); err != nil { | ||
log.Fatalf("Error parsing JSON: %v", err) | ||
} | ||
|
||
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.Fatal(err) | ||
} | ||
} |