Skip to content

Commit

Permalink
Improve error handling on validateLicense function
Browse files Browse the repository at this point in the history
  • Loading branch information
guicaulada committed Jul 7, 2023
1 parent c8f7040 commit ccd30ab
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pipelines/package_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,19 @@ func validateTarball(ctx context.Context, d *dagger.Client, pkg *dagger.File, sr
// validateLicense uses the given container and license path to validate the license for each edition (enterprise or oss)
func validateLicense(ctx context.Context, service *dagger.Container, licensePath string, taropts TarFileOpts) error {
license, err := service.File(licensePath).Contents(ctx)
if err != nil {
return err
}

if taropts.Edition == "enterprise" {
if err != nil || !strings.Contains(license, "Grafana Enterprise") {
return fmt.Errorf("failed to validate enterprise license")
if !strings.Contains(license, "Grafana Enterprise") {
return fmt.Errorf("license in package does not match edition in package name")
}
}

if taropts.Edition == "" {
if err != nil || !strings.Contains(license, "GNU AFFERO GENERAL PUBLIC LICENSE") {
return fmt.Errorf("failed to validate open-source license")
if !strings.Contains(license, "GNU AFFERO GENERAL PUBLIC LICENSE") {
return fmt.Errorf("license in package does not match edition in package name")
}
}

Expand Down

0 comments on commit ccd30ab

Please sign in to comment.