Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions cmd/create_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ const createPackageLongDescription = `Use this command to create a new package.
The command can bootstrap the first draft of a package using embedded package template and wizard.`

type newPackageAnswers struct {
Name string
Version string
Title string
Description string
Categories []string
KibanaVersion string `survey:"kibana_version"`
GithubOwner string `survey:"github_owner"`
Name string
Version string
Title string
Description string
Categories []string
KibanaVersion string `survey:"kibana_version"`
ElasticSubscription string `survey:"elastic_subscription"`
GithubOwner string `survey:"github_owner"`
}

func createPackageCommandAction(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -81,10 +82,19 @@ func createPackageCommandAction(cmd *cobra.Command, args []string) error {
Name: "kibana_version",
Prompt: &survey.Input{
Message: "Kibana version constraint:",
Default: surveyext.DefaultConstraintValue(),
Default: surveyext.DefaultKibanaVersionConditionValue(),
},
Validate: survey.ComposeValidators(survey.Required, surveyext.ConstraintValidator),
},
{
Name: "elastic_subscription",
Prompt: &survey.Select{
Message: "Required Elastic subscription:",
Options: []string{"basic", "gold", "platinum", "enterprise"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would change the order to be shown like here

Suggested change
Options: []string{"basic", "gold", "platinum", "enterprise"},
Options: []string{"basic", "platinum", "enterprise", "gold"},

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I didn't know that gold is discontinued, I guess that this is the only reason why it appears later there. But technically platinum > gold, we have been using this order everywhere. See the spec for example: https://github.com/elastic/package-spec/blob/0456e4f000a5bf85130d4e5e9c6d329a627523ec/versions/1/integration/manifest.spec.yml#L54

Default: "basic",
},
Validate: survey.Required,
},
{
Name: "github_owner",
Prompt: &survey.Input{
Expand Down Expand Up @@ -122,12 +132,15 @@ func createPackageDescriptorFromAnswers(answers newPackageAnswers) archetype.Pac
Kibana: packages.KibanaConditions{
Version: answers.KibanaVersion,
},
Elastic: packages.ElasticConditions{
Subscription: answers.ElasticSubscription,
},
},
Owner: packages.Owner{
Github: answers.GithubOwner,
},
License: answers.ElasticSubscription,
Description: answers.Description,
License: "basic",
Categories: answers.Categories,
},
}
Expand Down
1 change: 1 addition & 0 deletions internal/packages/archetype/package_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ categories:{{range $category := .Manifest.Categories}}
{{- end}}
conditions:
kibana.version: "{{.Manifest.Conditions.Kibana.Version}}"
elastic.subscription: "{{.Manifest.Conditions.Elastic.Subscription}}"
screenshots:
- src: /img/sample-screenshot.png
title: Sample screenshot
Expand Down
3 changes: 3 additions & 0 deletions internal/packages/archetype/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func createPackageDescriptorForTest() PackageDescriptor {
Kibana: packages.KibanaConditions{
Version: "^7.13.0",
},
Elastic: packages.ElasticConditions{
Subscription: "basic",
},
},
Owner: packages.Owner{
Github: "mtojek",
Expand Down
8 changes: 7 additions & 1 deletion internal/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ type KibanaConditions struct {
Version string `config:"version" json:"version" yaml:"version"`
}

// ElasticConditions defines conditions related to Elastic subscriptions or partnerships.
type ElasticConditions struct {
Subscription string `config:"subscription" json:"subscription" yaml:"subscription"`
}

// Conditions define requirements for different parts of the Elastic stack.
type Conditions struct {
Kibana KibanaConditions `config:"kibana" json:"kibana" yaml:"kibana"`
Kibana KibanaConditions `config:"kibana" json:"kibana" yaml:"kibana"`
Elastic ElasticConditions `config:"elastic" json:"elastic" yaml:"elastic"`
}

// PolicyTemplate is a configuration of inputs responsible for collecting log or metric data.
Expand Down
4 changes: 2 additions & 2 deletions internal/surveyext/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/elastic/elastic-package/internal/install"
)

// DefaultConstraintValue function returns a constraint
func DefaultConstraintValue() string {
// DefaultKibanaVersionConditionValue function returns a constraint
func DefaultKibanaVersionConditionValue() string {
ver := semver.MustParse(install.DefaultStackVersion)
v, _ := ver.SetPrerelease("")
return "^" + v.String()
Expand Down
2 changes: 1 addition & 1 deletion internal/surveyext/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestDefaultConstraintValue(t *testing.T) {
val := DefaultConstraintValue()
val := DefaultKibanaVersionConditionValue()

_, err := semver.NewConstraint(val)
require.NoError(t, err)
Expand Down