2024-03-15 21:38:00 +08:00
|
|
|
package confutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2024-06-24 20:32:26 +08:00
|
|
|
// MetadataProvenanceMode is the type for setting provenance in the metadata
|
|
|
|
// file
|
|
|
|
type MetadataProvenanceMode string
|
2024-03-15 21:38:00 +08:00
|
|
|
|
|
|
|
const (
|
|
|
|
// MetadataProvenanceModeMin sets minimal provenance (default)
|
2024-06-24 20:32:26 +08:00
|
|
|
MetadataProvenanceModeMin MetadataProvenanceMode = "min"
|
2024-03-15 21:38:00 +08:00
|
|
|
// MetadataProvenanceModeMax sets full provenance
|
2024-06-24 20:32:26 +08:00
|
|
|
MetadataProvenanceModeMax MetadataProvenanceMode = "max"
|
2024-03-15 21:38:00 +08:00
|
|
|
// MetadataProvenanceModeDisabled doesn't set provenance
|
2024-06-24 20:32:26 +08:00
|
|
|
MetadataProvenanceModeDisabled MetadataProvenanceMode = "disabled"
|
2024-03-15 21:38:00 +08:00
|
|
|
)
|
|
|
|
|
2024-06-24 20:32:26 +08:00
|
|
|
// MetadataProvenance returns the metadata provenance mode from
|
|
|
|
// BUILDX_METADATA_PROVENANCE environment variable
|
2024-03-15 21:38:00 +08:00
|
|
|
func MetadataProvenance() MetadataProvenanceMode {
|
2024-06-24 20:32:26 +08:00
|
|
|
return ParseMetadataProvenance(os.Getenv("BUILDX_METADATA_PROVENANCE"))
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseMetadataProvenance parses the metadata provenance mode from a string
|
|
|
|
func ParseMetadataProvenance(inp string) MetadataProvenanceMode {
|
|
|
|
switch inp {
|
2024-03-15 21:38:00 +08:00
|
|
|
case "min":
|
|
|
|
return MetadataProvenanceModeMin
|
|
|
|
case "max":
|
|
|
|
return MetadataProvenanceModeMax
|
|
|
|
case "disabled":
|
|
|
|
return MetadataProvenanceModeDisabled
|
|
|
|
}
|
2024-06-24 20:32:26 +08:00
|
|
|
if ok, err := strconv.ParseBool(inp); err == nil && !ok {
|
2024-03-15 21:38:00 +08:00
|
|
|
return MetadataProvenanceModeDisabled
|
|
|
|
}
|
|
|
|
return MetadataProvenanceModeMin
|
|
|
|
}
|
2024-06-24 22:38:09 +08:00
|
|
|
|
|
|
|
// MetadataWarningsEnabled returns whether metadata warnings are enabled from
|
|
|
|
// BUILDX_METADATA_WARNINGS environment variable (default false)
|
|
|
|
func MetadataWarningsEnabled() bool {
|
|
|
|
if ok, err := strconv.ParseBool(os.Getenv("BUILDX_METADATA_WARNINGS")); err == nil {
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|