Skip to content

Commit

Permalink
Prevent exporting dashboards from 8.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Jul 17, 2023
1 parent c2d974d commit e42e627
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/export/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ package export

import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/Masterminds/semver/v3"

"github.com/elastic/elastic-package/internal/common"
"github.com/elastic/elastic-package/internal/kibana"
"github.com/elastic/elastic-package/internal/logger"
Expand All @@ -30,6 +33,14 @@ func Dashboards(kibanaClient *kibana.Client, dashboardsIDs []string) error {
return fmt.Errorf("reading package manifest failed (path: %s): %w", packageRoot, err)
}

versionInfo, err := kibanaClient.Version()
if err != nil {
return fmt.Errorf("getting Kibana version information: %w", err)
}
if err := checkKibanaVersion(versionInfo); err != nil {
return fmt.Errorf("cannot import from this Kibana version: %w", err)
}

objects, err := kibanaClient.Export(dashboardsIDs)
if err != nil {
return fmt.Errorf("exporting dashboards using Kibana client failed: %w", err)
Expand All @@ -51,6 +62,23 @@ func Dashboards(kibanaClient *kibana.Client, dashboardsIDs []string) error {
return nil
}

func checkKibanaVersion(info kibana.VersionInfo) error {
version, err := semver.NewVersion(info.Number)
if err != nil {
return fmt.Errorf("cannot parse version %s: %w", info.Number, err)
}

minVersion := semver.MustParse("8.8.0")
maxVersion := semver.MustParse("8.10.0")
if version.LessThan(maxVersion) && !version.LessThan(minVersion) {
// See:
// - https://github.com/elastic/elastic-package/issues/1354
// - https://github.com/elastic/kibana/pull/161969
return errors.New("packages with dashboards exported since Kibana 8.8 may not be installed till 8.10, please export the dashboard/s from a different version")
}
return nil
}

func applyTransformations(ctx *transformationContext, objects []common.MapStr) ([]common.MapStr, error) {
return newObjectTransformer().
withContext(ctx).
Expand Down

0 comments on commit e42e627

Please sign in to comment.