Skip to content

Commit

Permalink
Expose policy_templates_behavior and deployment modes for policy temp…
Browse files Browse the repository at this point in the history
…lates in search and package endpoints (#1244)

Expose policy_templates_behavior field and the deployment_modes
for the policy templates (if any) in both search and package endpoints.
  • Loading branch information
mrodm authored Oct 30, 2024
1 parent 4508d72 commit 5692478
Show file tree
Hide file tree
Showing 18 changed files with 808 additions and 40 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Add new `discovery` parameter to search and category endpoints. [#1235](https://github.com/elastic/package-registry/pull/1235)
* Expose `policy_templates.*.deployment_modes` field in both search and package endpoints. [#1244](https://github.com/elastic/package-registry/pull/1244)
* Expose `policy_templates_behavior` field in both search and package endpoints. [#1244](https://github.com/elastic/package-registry/pull/1244)

### Deprecated

Expand Down
85 changes: 49 additions & 36 deletions packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,47 @@ type FileSystemBuilder func(*Package) (PackageFileSystem, error)

// BasePackage is used for the output of the package info in the /search endpoint
type BasePackage struct {
Name string `config:"name" json:"name"`
Title *string `config:"title,omitempty" json:"title,omitempty" yaml:"title,omitempty"`
Version string `config:"version" json:"version"`
Release string `config:"release,omitempty" json:"release,omitempty"`
Source *Source `config:"source,omitempty" json:"source,omitempty" yaml:"source,omitempty"`
Description string `config:"description" json:"description"`
Type string `config:"type" json:"type"`
Download string `json:"download" yaml:"download,omitempty"`
Path string `json:"path" yaml:"path,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
BasePolicyTemplates []BasePolicyTemplate `json:"policy_templates,omitempty"`
Conditions *Conditions `config:"conditions,omitempty" json:"conditions,omitempty" yaml:"conditions,omitempty"`
Owner *Owner `config:"owner,omitempty" json:"owner,omitempty" yaml:"owner,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
SignaturePath string `config:"signature_path,omitempty" json:"signature_path,omitempty" yaml:"signature_path,omitempty"`
Discovery *Discovery `config:"discovery,omitempty" json:"discovery,omitempty" yaml:"discovery,omitempty"`
Name string `config:"name" json:"name"`
Title *string `config:"title,omitempty" json:"title,omitempty" yaml:"title,omitempty"`
Version string `config:"version" json:"version"`
Release string `config:"release,omitempty" json:"release,omitempty"`
Source *Source `config:"source,omitempty" json:"source,omitempty" yaml:"source,omitempty"`
Description string `config:"description" json:"description"`
Type string `config:"type" json:"type"`
Download string `json:"download" yaml:"download,omitempty"`
Path string `json:"path" yaml:"path,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
PolicyTemplatesBehavior string `config:"policy_templates_behavior,omitempty" json:"policy_templates_behavior,omitempty" yaml:"policy_templates_behavior,omitempty"`
BasePolicyTemplates []BasePolicyTemplate `json:"policy_templates,omitempty"`
Conditions *Conditions `config:"conditions,omitempty" json:"conditions,omitempty" yaml:"conditions,omitempty"`
Owner *Owner `config:"owner,omitempty" json:"owner,omitempty" yaml:"owner,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
SignaturePath string `config:"signature_path,omitempty" json:"signature_path,omitempty" yaml:"signature_path,omitempty"`
Discovery *Discovery `config:"discovery,omitempty" json:"discovery,omitempty" yaml:"discovery,omitempty"`
}

// BasePolicyTemplate is used for the package policy templates in the /search endpoint
type BasePolicyTemplate struct {
Name string `config:"name" json:"name" validate:"required"`
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
Name string `config:"name" json:"name" validate:"required"`
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
DeploymentModes *DeploymentModes `config:"deployment_modes,omitempty" json:"deployment_modes,omitempty" yaml:"deployment_modes,omitempty"`
}

type PolicyTemplate struct {
Name string `config:"name" json:"name" validate:"required"`
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
DataStreams []string `config:"data_streams,omitempty" json:"data_streams,omitempty" yaml:"data_streams,omitempty"`
Inputs []Input `config:"inputs" json:"inputs,omitempty" yaml:"inputs,omitempty"`
Multiple *bool `config:"multiple" json:"multiple,omitempty" yaml:"multiple,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
Screenshots []Image `config:"screenshots,omitempty" json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
Readme *string `config:"readme,omitempty" json:"readme,omitempty" yaml:"readme,omitempty"`
Name string `config:"name" json:"name" validate:"required"`
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
DataStreams []string `config:"data_streams,omitempty" json:"data_streams,omitempty" yaml:"data_streams,omitempty"`
Inputs []Input `config:"inputs" json:"inputs,omitempty" yaml:"inputs,omitempty"`
Multiple *bool `config:"multiple" json:"multiple,omitempty" yaml:"multiple,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
Screenshots []Image `config:"screenshots,omitempty" json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
Readme *string `config:"readme,omitempty" json:"readme,omitempty" yaml:"readme,omitempty"`
DeploymentModes *DeploymentModes `config:"deployment_modes,omitempty" json:"deployment_modes,omitempty" yaml:"deployment_modes,omitempty"`

// For purposes of "input packages"
Type string `config:"type,omitempty" json:"type,omitempty" yaml:"type,omitempty"`
Expand Down Expand Up @@ -184,6 +187,15 @@ type Download struct {
Type string `config:"type" json:"type" validate:"required"`
}

type DeploymentModes struct {
Default *DeploymentMode `config:"default,omitempty" json:"default,omitempty" yaml:"default,omitempty"`
Agentless *DeploymentMode `config:"agentless,omitempty" json:"agentless,omitempty" yaml:"agentless,omitempty"`
}

type DeploymentMode struct {
Enabled bool `config:"enabled" json:"enabled" yaml:"enabled" validate:"required"`
}

func NewDownload(p Package, t string) Download {
return Download{
Path: getDownloadPath(p, t),
Expand Down Expand Up @@ -378,11 +390,12 @@ func (p *Package) setRuntimeFields() error {
func (p *Package) setBasePolicyTemplates() {
for _, t := range p.PolicyTemplates {
baseT := BasePolicyTemplate{
Name: t.Name,
Title: t.Title,
Description: t.Description,
Categories: t.Categories,
Icons: t.Icons,
Name: t.Name,
Title: t.Title,
Description: t.Description,
Categories: t.Categories,
Icons: t.Icons,
DeploymentModes: t.DeploymentModes,
}

p.BasePolicyTemplates = append(p.BasePolicyTemplates, baseT)
Expand Down
118 changes: 118 additions & 0 deletions packages/testdata/marshaler/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,124 @@
"/package/defaultrelease/0.0.1/docs/README.md"
]
},
{
"name": "deployment_modes",
"title": "Deployment Modes",
"version": "0.0.1",
"release": "beta",
"source": {
"license": "Elastic-2.0"
},
"description": "Package containing policy templates with different deployment modes",
"type": "integration",
"download": "/epr/deployment_modes/deployment_modes-0.0.1.zip",
"path": "/package/deployment_modes/0.0.1",
"icons": [
{
"src": "/img/sample-logo.svg",
"path": "/package/deployment_modes/0.0.1/img/sample-logo.svg",
"title": "Sample logo",
"size": "32x32",
"type": "image/svg+xml"
}
],
"policy_templates_behavior": "combined_policy",
"conditions": {
"kibana": {
"version": "^8.15.2"
},
"elastic": {
"subscription": "basic"
}
},
"owner": {
"type": "elastic",
"github": "elastic/integrations"
},
"categories": [
"custom"
],
"format_version": "3.3.0",
"readme": "/package/deployment_modes/0.0.1/docs/README.md",
"license": "basic",
"screenshots": [
{
"src": "/img/sample-screenshot.png",
"path": "/package/deployment_modes/0.0.1/img/sample-screenshot.png",
"title": "Sample screenshot",
"size": "600x600",
"type": "image/png"
}
],
"assets": [
"/package/deployment_modes/0.0.1/LICENSE.txt",
"/package/deployment_modes/0.0.1/changelog.yml",
"/package/deployment_modes/0.0.1/manifest.yml",
"/package/deployment_modes/0.0.1/docs/README.md",
"/package/deployment_modes/0.0.1/img/sample-logo.svg",
"/package/deployment_modes/0.0.1/img/sample-screenshot.png"
],
"policy_templates": [
{
"name": "agentless",
"title": "Sample logs",
"description": "Collect sample logs",
"inputs": [
{
"type": "logfile",
"vars": [
{
"name": "path",
"type": "text",
"multi": false,
"required": false,
"show_user": true
},
{
"name": "tags",
"type": "text",
"multi": true,
"required": false,
"show_user": false
}
],
"title": "Collect sample logs from instances",
"description": "Collecting sample logs"
}
],
"multiple": false,
"deployment_modes": {
"default": {
"enabled": false
},
"agentless": {
"enabled": true
}
}
},
{
"name": "default",
"title": "Sample logs",
"description": "Collect sample logs",
"inputs": [
{
"type": "logfile",
"title": "Collect sample logs from instances",
"description": "Collecting sample logs"
}
],
"multiple": false,
"deployment_modes": {
"default": {
"enabled": true
},
"agentless": {
"enabled": false
}
}
}
]
},
{
"name": "ecs_style_dataset",
"title": "Default pipeline Integration",
Expand Down
2 changes: 1 addition & 1 deletion testdata/generated/categories-experimental.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"id": "custom",
"title": "Custom",
"count": 17
"count": 18
},
{
"id": "datastore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"id": "custom",
"title": "Custom",
"count": 16
"count": 17
},
{
"id": "datastore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"id": "custom",
"title": "Custom",
"count": 16
"count": 17
},
{
"id": "datastore",
Expand Down
2 changes: 1 addition & 1 deletion testdata/generated/categories-prerelease.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"id": "custom",
"title": "Custom",
"count": 17
"count": 18
},
{
"id": "datastore",
Expand Down
Loading

0 comments on commit 5692478

Please sign in to comment.