1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 05:40:11 +01:00

add enumerate function to ProviderMetadataLoader

This commit is contained in:
Kunz, Immanuel 2024-04-22 17:48:11 +02:00
parent d909e9de15
commit 73aef07063

View file

@ -108,6 +108,42 @@ func NewProviderMetadataLoader(client util.Client) *ProviderMetadataLoader {
}
}
func (pmdl *ProviderMetadataLoader) Enumerate(domain string) []*LoadedProviderMetadata {
// Our array of PMDs to be found
var resPMDs []*LoadedProviderMetadata
// TODO check direct path?
// First try the well-known path.
wellknownURL := "https://" + domain + "/.well-known/csaf/provider-metadata.json"
wellknownResult := pmdl.loadFromURL(wellknownURL)
// Validate the candidate and add to the result array
if wellknownResult.Valid() {
resPMDs = append(resPMDs, wellknownResult)
}
// Next load the PMDs from security.txt
secResults := pmdl.loadFromSecurity(domain)
for _, result := range secResults {
if result.Valid() {
resPMDs = append(resPMDs, result)
}
}
// According to the spec, only if no PMDs have been found, should the DNS URL be used
if len(resPMDs) > 0 {
return resPMDs
} else {
dnsURL := "https://csaf.data.security." + domain
return []*LoadedProviderMetadata{pmdl.loadFromURL(dnsURL)}
}
}
// Load loads a provider metadata for a given path.
// If the domain starts with `https://` it only attemps to load
// the data from that URL.