mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 14:26:23 -04:00
cli: use Semver type to represent microservice versions (#2125)
Previously we used strings to pass microservice versions. This invited bugs due to missing input validation.
This commit is contained in:
parent
2d3999440d
commit
1d5a8283e0
35 changed files with 612 additions and 318 deletions
|
@ -86,7 +86,7 @@ func (c *createCmd) create(cmd *cobra.Command, creator cloudCreator, fileHandler
|
|||
return err
|
||||
}
|
||||
if !flags.force {
|
||||
if err := validateCLIandConstellationVersionAreEqual(constants.VersionInfo(), conf.Image, conf.MicroserviceVersion); err != nil {
|
||||
if err := validateCLIandConstellationVersionAreEqual(constants.BinaryVersion(), conf.Image, conf.MicroserviceVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ func must(err error) {
|
|||
}
|
||||
|
||||
// validateCLIandConstellationVersionAreEqual checks if the image and microservice version are equal (down to patch level) to the CLI version.
|
||||
func validateCLIandConstellationVersionAreEqual(cliVersion, imageVersion, microserviceVersion string) error {
|
||||
func validateCLIandConstellationVersionAreEqual(cliVersion semver.Semver, imageVersion string, microserviceVersion semver.Semver) error {
|
||||
parsedImageVersion, err := versionsapi.NewVersionFromShortPath(imageVersion, versionsapi.VersionKindImage)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing image version: %w", err)
|
||||
|
@ -312,21 +312,11 @@ func validateCLIandConstellationVersionAreEqual(cliVersion, imageVersion, micros
|
|||
return fmt.Errorf("parsing image semantical version: %w", err)
|
||||
}
|
||||
|
||||
semMicro, err := semver.New(microserviceVersion)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing microservice version: %w", err)
|
||||
if !cliVersion.MajorMinorEqual(semImage) {
|
||||
return fmt.Errorf("image version %q does not match the major and minor version of the cli version %q", semImage.String(), cliVersion.String())
|
||||
}
|
||||
|
||||
semCLI, err := semver.New(cliVersion)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing binary version: %w", err)
|
||||
}
|
||||
|
||||
if !semCLI.MajorMinorEqual(semImage) {
|
||||
return fmt.Errorf("image version %q does not match the major and minor version of the cli version %q", semImage.String(), semCLI.String())
|
||||
}
|
||||
if semCLI.Compare(semMicro) != 0 {
|
||||
return fmt.Errorf("cli version %q does not match microservice version %q", semCLI.String(), semMicro.String())
|
||||
if cliVersion.Compare(microserviceVersion) != 0 {
|
||||
return fmt.Errorf("cli version %q does not match microservice version %q", cliVersion.String(), microserviceVersion.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue