mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Make categories configurable in provider
This commit is contained in:
parent
da4dda9042
commit
14fc9cdc61
1 changed files with 60 additions and 0 deletions
|
|
@ -56,6 +56,7 @@ type config struct {
|
||||||
UploadLimit *int64 `toml:"upload_limit"`
|
UploadLimit *int64 `toml:"upload_limit"`
|
||||||
Issuer *string `toml:"issuer"`
|
Issuer *string `toml:"issuer"`
|
||||||
RemoteValidator *csaf.RemoteValidatorOptions `toml:"remote_validator"`
|
RemoteValidator *csaf.RemoteValidatorOptions `toml:"remote_validator"`
|
||||||
|
Categories *[]string `toml:"categories"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pmdc *providerMetadataConfig) apply(pmd *csaf.ProviderMetadata) {
|
func (pmdc *providerMetadataConfig) apply(pmd *csaf.ProviderMetadata) {
|
||||||
|
|
@ -145,6 +146,65 @@ func (cfg *config) checkPassword(hash string) bool {
|
||||||
bcrypt.CompareHashAndPassword([]byte(hash), []byte(*cfg.Password)) == nil
|
bcrypt.CompareHashAndPassword([]byte(hash), []byte(*cfg.Password)) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasCategories tells if categories are configured.
|
||||||
|
func (cfg *config) HasCategories() bool {
|
||||||
|
return cfg.Categories != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasDynamicCategories tells if dynamic categories are configured.
|
||||||
|
func (cfg *config) HasDynamicCategories() bool {
|
||||||
|
if !cfg.HasCategories() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cat := range *cfg.Categories {
|
||||||
|
if strings.HasPrefix(cat, "dynamic:") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasStaticCategories tells if static categories are configured.
|
||||||
|
func (cfg *config) HasStaticCategories() bool {
|
||||||
|
if !cfg.HasCategories() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cat := range *cfg.Categories {
|
||||||
|
if !strings.HasPrefix(cat, "expr:") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaticCategories returns a list on the configured static categories.
|
||||||
|
func (cfg *config) StaticCategories() []string {
|
||||||
|
if !cfg.HasCategories() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cats := make([]string, 0, len(*cfg.Categories))
|
||||||
|
for _, cat := range *cfg.Categories {
|
||||||
|
if !strings.HasPrefix(cat, "expr:") {
|
||||||
|
cats = append(cats, cat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cats
|
||||||
|
}
|
||||||
|
|
||||||
|
// DynamicCategories returns a list on the configured dynamic categories.
|
||||||
|
func (cfg *config) DynamicCategories() []string {
|
||||||
|
if !cfg.HasCategories() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cats := make([]string, 0, len(*cfg.Categories))
|
||||||
|
for _, cat := range *cfg.Categories {
|
||||||
|
if strings.HasPrefix(cat, "expr:") {
|
||||||
|
cats = append(cats, cat[len("expr:"):])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cats
|
||||||
|
}
|
||||||
|
|
||||||
// loadConfig extracts the config values from the config file. The path to the
|
// loadConfig extracts the config values from the config file. The path to the
|
||||||
// file is taken either from environment variable "CSAF_CONFIG" or from the
|
// file is taken either from environment variable "CSAF_CONFIG" or from the
|
||||||
// defined default path in "defaultConfigPath".
|
// defined default path in "defaultConfigPath".
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue