Skip to content

Commit

Permalink
create separate value for minimum required version
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch committed Aug 10, 2021
1 parent 978336e commit ff1ca85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions libbeat/dashboards/kibana_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func getKibanaClient(ctx context.Context, cfg *common.Config, retryCfg *Retry, r

// ImportIndexFile imports an index pattern from a file
func (loader KibanaLoader) ImportIndexFile(file string) error {
if loader.version.LessThanOrEqual(true, common.MustNewVersion("7.14.0")) {
return fmt.Errorf("Kibana version must be newer than 7.14")
if loader.version.LessThan(kibana.MinimumRequiredVersionSavedObjects) {
return fmt.Errorf("Kibana version must be at least " + kibana.MinimumRequiredVersionSavedObjects.String())
}

loader.statusMsg("Importing index file from %s", file)
Expand All @@ -114,8 +114,8 @@ func (loader KibanaLoader) ImportIndexFile(file string) error {

// ImportIndex imports the passed index pattern to Kibana
func (loader KibanaLoader) ImportIndex(pattern common.MapStr) error {
if loader.version.LessThanOrEqual(true, common.MustNewVersion("7.14.0")) {
return fmt.Errorf("Kibana version must be newer than 7.14")
if loader.version.LessThan(kibana.MinimumRequiredVersionSavedObjects) {
return fmt.Errorf("Kibana version must be at least " + kibana.MinimumRequiredVersionSavedObjects.String())
}

var errs multierror.Errors
Expand All @@ -135,8 +135,8 @@ func (loader KibanaLoader) ImportIndex(pattern common.MapStr) error {

// ImportDashboard imports the dashboard file
func (loader KibanaLoader) ImportDashboard(file string) error {
if loader.version.LessThanOrEqual(true, common.MustNewVersion("7.14.0")) {
return fmt.Errorf("Kibana version must be newer than 7.14")
if loader.version.LessThan(kibana.MinimumRequiredVersionSavedObjects) {
return fmt.Errorf("Kibana version must be at least " + kibana.MinimumRequiredVersionSavedObjects.String())
}

loader.statusMsg("Importing dashboard from %s", file)
Expand Down
8 changes: 6 additions & 2 deletions libbeat/kibana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import (
"github.com/elastic/beats/v7/libbeat/logp"
)

var (
MinimumRequiredVersionSavedObjects = common.MustNewVersion("7.15.0")
)

type Connection struct {
URL string
Username string
Expand Down Expand Up @@ -315,8 +319,8 @@ func (client *Client) Close() error { return nil }

// GetDashboard returns the dashboard with the given id with the index pattern removed
func (client *Client) GetDashboard(id string) ([]byte, error) {
if client.Version.LessThanOrEqual(true, common.MustNewVersion("7.14.0")) {
return nil, fmt.Errorf("Kibana version must be newer than 7.14")
if client.Version.LessThan(MinimumRequiredVersionSavedObjects) {
return nil, fmt.Errorf("Kibana version must be at least " + MinimumRequiredVersionSavedObjects.String())
}

body := fmt.Sprintf(`{"objects": [{"type": "dashboard", "id": "%s" }], "includeReferencesDeep": true, "excludeExportDetails": true}`, id)
Expand Down

0 comments on commit ff1ca85

Please sign in to comment.