mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
a1e29ae290
The semver library we were using doesn't have support for a "pessimistic constraint" where e.g. the user wants to accept only minor or patch version upgrades. This is important for providers since users will generally want to pin their dependencies to not inadvertantly accept breaking changes. So here we switch to hashicorp's home-grown go-version library, which has the ~> constraint operator for this sort of constraint. Given how much the old version object was already intruding into the interface and creating dependency noise in callers, this also now wraps the "raw" go-version objects in package-local structs, thus keeping the details encapsulated and allowing callers to deal just with this package's own types.
27 lines
810 B
Go
27 lines
810 B
Go
package discovery
|
|
|
|
// PluginRequirements describes a set of plugins (assumed to be of a consistent
|
|
// kind) that are required to exist and have versions within the given
|
|
// corresponding sets.
|
|
//
|
|
// PluginRequirements is a map from plugin name to VersionSet.
|
|
type PluginRequirements map[string]VersionSet
|
|
|
|
// Merge takes the contents of the receiver and the other given requirements
|
|
// object and merges them together into a single requirements structure
|
|
// that satisfies both sets of requirements.
|
|
func (r PluginRequirements) Merge(other PluginRequirements) PluginRequirements {
|
|
ret := make(PluginRequirements)
|
|
for n, vs := range r {
|
|
ret[n] = vs
|
|
}
|
|
for n, vs := range other {
|
|
if existing, exists := ret[n]; exists {
|
|
ret[n] = existing.Intersection(vs)
|
|
} else {
|
|
ret[n] = vs
|
|
}
|
|
}
|
|
return ret
|
|
}
|