diff --git a/changelog.go b/changelog.go new file mode 100644 index 0000000..b43f616 --- /dev/null +++ b/changelog.go @@ -0,0 +1,76 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package fleetpkg + +import "gopkg.in/yaml.v3" + +type Changelog struct { + Releases []Release `json:"releases,omitempty" yaml:"releases,omitempty"` + + sourceFile string +} + +func (c *Changelog) UnmarshalYAML(value *yaml.Node) error { + return value.Decode(&c.Releases) +} + +// Path returns the path to the changelog file. +func (c *Changelog) Path() string { + return c.sourceFile +} + +type Release struct { + Version string `json:"version,omitempty" yaml:"version,omitempty"` + Changes []Change `json:"changes,omitempty" yaml:"changes,omitempty"` + + FileMetadata `json:"-" yaml:"-"` +} + +func (r *Release) UnmarshalYAML(value *yaml.Node) error { + // Prevent recursion by creating a new type that does not implement Unmarshaler. + type notRelease Release + x := (*notRelease)(r) + + if err := value.Decode(&x); err != nil { + return err + } + r.FileMetadata.line = value.Line + r.FileMetadata.column = value.Column + return nil +} + +type Change struct { + Description string `json:"description,omitempty" yaml:"description,omitempty"` + Type string `json:"type,omitempty" yaml:"type,omitempty"` + Link string `json:"link,omitempty" yaml:"link,omitempty"` + + FileMetadata `json:"-" yaml:"-"` +} + +func (c *Change) UnmarshalYAML(value *yaml.Node) error { + // Prevent recursion by creating a new type that does not implement Unmarshaler. + type notChange Change + x := (*notChange)(c) + + if err := value.Decode(&x); err != nil { + return err + } + c.FileMetadata.line = value.Line + c.FileMetadata.column = value.Column + return nil +} diff --git a/fleetpkg.go b/fleetpkg.go index 90a6123..f851607 100644 --- a/fleetpkg.go +++ b/fleetpkg.go @@ -31,6 +31,7 @@ type Integration struct { Build *BuildManifest `json:"build,omitempty" yaml:"build,omitempty"` Manifest Manifest `json:"manifest,omitempty" yaml:"manifest,omitempty"` DataStreams map[string]*DataStream `json:"data_streams,omitempty" yaml:"data_streams,omitempty"` + Changelog Changelog `json:"changelog,omitempty" yaml:"changelog,omitempty"` sourceFile string } @@ -414,6 +415,13 @@ func Read(path string) (*Integration, error) { integration.Manifest.sourceFile = sourceFile annotateFileMetadata(integration.Manifest.sourceFile, &integration.Manifest) + sourceFile = filepath.Join(path, "changelog.yml") + if err := readYAML(sourceFile, &integration.Changelog, true); err != nil { + return nil, err + } + integration.Changelog.sourceFile = sourceFile + annotateFileMetadata(integration.Changelog.sourceFile, &integration.Changelog) + sourceFile = filepath.Join(path, "_dev/build/build.yml") if err := readYAML(sourceFile, &integration.Build, true); err != nil { // Optional file. diff --git a/metadata.go b/metadata.go index 38997b0..dabc23c 100644 --- a/metadata.go +++ b/metadata.go @@ -20,9 +20,9 @@ package fleetpkg import "reflect" type FileMetadata struct { - file string `json:"-"` // file from which field was read. - line int `json:"-"` // line from which field was read. - column int `json:"-"` // column from which field was read. + file string // file from which field was read. + line int // line from which field was read. + column int // column from which field was read. } func (m FileMetadata) Path() string { return m.file } diff --git a/testdata/cel.golden.json b/testdata/cel.golden.json index bfbe92f..d57d6cc 100644 --- a/testdata/cel.golden.json +++ b/testdata/cel.golden.json @@ -361,5 +361,49 @@ "owner": { "github": "elastic/security-external-integrations" } + }, + "changelog": { + "releases": [ + { + "version": "0.3.0", + "changes": [ + { + "description": "Update package-spec version to 2.7.0.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/6135" + } + ] + }, + { + "version": "0.2.0", + "changes": [ + { + "description": "Change resource tracer filename", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/5922" + } + ] + }, + { + "version": "0.1.1", + "changes": [ + { + "description": "Added build manifest to indicate the ECS reference.", + "type": "bugfix", + "link": "https://github.com/elastic/integrations/pull/5937" + } + ] + }, + { + "version": "0.1.0", + "changes": [ + { + "description": "Initial Implementation", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/5539" + } + ] + } + ] } } diff --git a/testdata/cel.golden.yml b/testdata/cel.golden.yml index fe91da2..194ba02 100644 --- a/testdata/cel.golden.yml +++ b/testdata/cel.golden.yml @@ -297,3 +297,25 @@ manifest: show_user: false owner: github: elastic/security-external-integrations +changelog: + releases: + - version: 0.3.0 + changes: + - description: Update package-spec version to 2.7.0. + type: enhancement + link: https://github.com/elastic/integrations/pull/6135 + - version: 0.2.0 + changes: + - description: Change resource tracer filename + type: enhancement + link: https://github.com/elastic/integrations/pull/5922 + - version: 0.1.1 + changes: + - description: Added build manifest to indicate the ECS reference. + type: bugfix + link: https://github.com/elastic/integrations/pull/5937 + - version: 0.1.0 + changes: + - description: Initial Implementation + type: enhancement + link: https://github.com/elastic/integrations/pull/5539 diff --git a/testdata/hashicorp_vault.golden.json b/testdata/hashicorp_vault.golden.json index 7558cfe..6da3a1e 100644 --- a/testdata/hashicorp_vault.golden.json +++ b/testdata/hashicorp_vault.golden.json @@ -1925,5 +1925,239 @@ } } } + }, + "changelog": { + "releases": [ + { + "version": "1.10.0", + "changes": [ + { + "description": "Update package to ECS 8.7.0.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/5765" + } + ] + }, + { + "version": "1.9.1", + "changes": [ + { + "description": "Added categories and/or subcategories.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/5123" + } + ] + }, + { + "version": "1.9.0", + "changes": [ + { + "description": "Update package to ECS 8.6.0.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/4576" + } + ] + }, + { + "version": "1.8.0", + "changes": [ + { + "description": "Update package to ECS 8.5.0.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/4285" + } + ] + }, + { + "version": "1.7.0", + "changes": [ + { + "description": "Update mappings for Hashicorp Vault 1.11.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/4036" + } + ] + }, + { + "version": "1.6.0", + "changes": [ + { + "description": "Update package to ECS 8.4.0", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/3865" + } + ] + }, + { + "version": "1.5.0", + "changes": [ + { + "description": "Update package to ECS 8.3.0.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/3353" + } + ] + }, + { + "version": "1.4.0", + "changes": [ + { + "description": "Update to ECS 8.2", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/2779" + } + ] + }, + { + "version": "1.3.3", + "changes": [ + { + "description": "Use dynamic mappings for all hashicorp_vault.metrics fields.", + "type": "bugfix", + "link": "https://github.com/elastic/integrations/pull/2994" + } + ] + }, + { + "version": "1.3.2", + "changes": [ + { + "description": "Add documentation for multi-fields", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/2916" + } + ] + }, + { + "version": "1.3.1", + "changes": [ + { + "description": "Update docs to use markdown code blocks", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/2655" + } + ] + }, + { + "version": "1.3.0", + "changes": [ + { + "description": "Update to ECS 8.0", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/2409" + } + ] + }, + { + "version": "1.2.3", + "changes": [ + { + "description": "Make hashicorp_vault.audit.request.id optional in the audit pipeline to prevent errors.", + "type": "bugfix", + "link": "https://github.com/elastic/integrations/pull/2471" + } + ] + }, + { + "version": "1.2.2", + "changes": [ + { + "description": "Regenerate test files using the new GeoIP database", + "type": "bugfix", + "link": "https://github.com/elastic/integrations/pull/2339" + } + ] + }, + { + "version": "1.2.1", + "changes": [ + { + "description": "Change test public IPs to the supported subset", + "type": "bugfix", + "link": "https://github.com/elastic/integrations/pull/2327" + } + ] + }, + { + "version": "1.2.0", + "changes": [ + { + "description": "Add 8.0.0 version constraint", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/2238" + } + ] + }, + { + "version": "1.1.4", + "changes": [ + { + "description": "Uniform with guidelines", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/2105" + } + ] + }, + { + "version": "1.1.3", + "changes": [ + { + "description": "Update Title and Description.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/1967" + } + ] + }, + { + "version": "1.1.2", + "changes": [ + { + "description": "Add missing fields to metrics", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/1889" + } + ] + }, + { + "version": "1.1.1", + "changes": [ + { + "description": "Fix logic that checks for the 'forwarded' tag", + "type": "bugfix", + "link": "https://github.com/elastic/integrations/pull/1821" + } + ] + }, + { + "version": "1.1.0", + "changes": [ + { + "description": "Update to ECS 1.12.0", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/1662" + } + ] + }, + { + "version": "1.0.0", + "changes": [ + { + "description": "make GA", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/1735" + } + ] + }, + { + "version": "0.0.1", + "changes": [ + { + "description": "Initial package with audit, log, and metrics.", + "type": "enhancement", + "link": "https://github.com/elastic/integrations/pull/1346" + } + ] + } + ] } } diff --git a/testdata/hashicorp_vault.golden.yml b/testdata/hashicorp_vault.golden.yml index 91730b7..a1305e8 100644 --- a/testdata/hashicorp_vault.golden.yml +++ b/testdata/hashicorp_vault.golden.yml @@ -1204,3 +1204,120 @@ data_streams: type: keyword - name: version type: keyword +changelog: + releases: + - version: 1.10.0 + changes: + - description: Update package to ECS 8.7.0. + type: enhancement + link: https://github.com/elastic/integrations/pull/5765 + - version: 1.9.1 + changes: + - description: Added categories and/or subcategories. + type: enhancement + link: https://github.com/elastic/integrations/pull/5123 + - version: 1.9.0 + changes: + - description: Update package to ECS 8.6.0. + type: enhancement + link: https://github.com/elastic/integrations/pull/4576 + - version: 1.8.0 + changes: + - description: Update package to ECS 8.5.0. + type: enhancement + link: https://github.com/elastic/integrations/pull/4285 + - version: 1.7.0 + changes: + - description: Update mappings for Hashicorp Vault 1.11. + type: enhancement + link: https://github.com/elastic/integrations/pull/4036 + - version: 1.6.0 + changes: + - description: Update package to ECS 8.4.0 + type: enhancement + link: https://github.com/elastic/integrations/pull/3865 + - version: 1.5.0 + changes: + - description: Update package to ECS 8.3.0. + type: enhancement + link: https://github.com/elastic/integrations/pull/3353 + - version: 1.4.0 + changes: + - description: Update to ECS 8.2 + type: enhancement + link: https://github.com/elastic/integrations/pull/2779 + - version: 1.3.3 + changes: + - description: Use dynamic mappings for all hashicorp_vault.metrics fields. + type: bugfix + link: https://github.com/elastic/integrations/pull/2994 + - version: 1.3.2 + changes: + - description: Add documentation for multi-fields + type: enhancement + link: https://github.com/elastic/integrations/pull/2916 + - version: 1.3.1 + changes: + - description: Update docs to use markdown code blocks + type: enhancement + link: https://github.com/elastic/integrations/pull/2655 + - version: 1.3.0 + changes: + - description: Update to ECS 8.0 + type: enhancement + link: https://github.com/elastic/integrations/pull/2409 + - version: 1.2.3 + changes: + - description: Make hashicorp_vault.audit.request.id optional in the audit pipeline to prevent errors. + type: bugfix + link: https://github.com/elastic/integrations/pull/2471 + - version: 1.2.2 + changes: + - description: Regenerate test files using the new GeoIP database + type: bugfix + link: https://github.com/elastic/integrations/pull/2339 + - version: 1.2.1 + changes: + - description: Change test public IPs to the supported subset + type: bugfix + link: https://github.com/elastic/integrations/pull/2327 + - version: 1.2.0 + changes: + - description: Add 8.0.0 version constraint + type: enhancement + link: https://github.com/elastic/integrations/pull/2238 + - version: 1.1.4 + changes: + - description: Uniform with guidelines + type: enhancement + link: https://github.com/elastic/integrations/pull/2105 + - version: 1.1.3 + changes: + - description: Update Title and Description. + type: enhancement + link: https://github.com/elastic/integrations/pull/1967 + - version: 1.1.2 + changes: + - description: Add missing fields to metrics + type: enhancement + link: https://github.com/elastic/integrations/pull/1889 + - version: 1.1.1 + changes: + - description: Fix logic that checks for the 'forwarded' tag + type: bugfix + link: https://github.com/elastic/integrations/pull/1821 + - version: 1.1.0 + changes: + - description: Update to ECS 1.12.0 + type: enhancement + link: https://github.com/elastic/integrations/pull/1662 + - version: 1.0.0 + changes: + - description: make GA + type: enhancement + link: https://github.com/elastic/integrations/pull/1735 + - version: 0.0.1 + changes: + - description: Initial package with audit, log, and metrics. + type: enhancement + link: https://github.com/elastic/integrations/pull/1346