forked from elastic/elastic-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add manifest to package (elastic#3910)
* Add manifest to package * Add tests for manifest in zip packages * Add manifest to rpm and deb packages
- Loading branch information
Showing
7 changed files
with
248 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// Package v1 contains definitions for elastic-agent/v1 objects | ||
package v1 | ||
|
||
const VERSION = "co.elastic.agent/v1" | ||
|
||
type apiObject struct { | ||
Version string `yaml:"version" json:"version"` | ||
Kind string `yaml:"kind" json:"kind"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
const ManifestKind = "PackageManifest" | ||
|
||
type PackageDesc struct { | ||
Version string `yaml:"version,omitempty" json:"version,omitempty"` | ||
Snapshot bool `yaml:"snapshot,omitempty" json:"snapshot,omitempty"` | ||
VersionedHome string `yaml:"versioned-home,omitempty" json:"versionedHome,omitempty"` | ||
PathMappings []map[string]string `yaml:"path-mappings,omitempty" json:"pathMappings,omitempty"` | ||
} | ||
|
||
type PackageManifest struct { | ||
apiObject `yaml:",inline"` | ||
Package PackageDesc `yaml:"package" json:"package"` | ||
} | ||
|
||
func NewManifest() *PackageManifest { | ||
return &PackageManifest{ | ||
apiObject: apiObject{ | ||
Version: VERSION, | ||
Kind: ManifestKind, | ||
}, | ||
} | ||
} | ||
|
||
func ParseManifest(r io.Reader) (*PackageManifest, error) { | ||
m := new(PackageManifest) | ||
err := yaml.NewDecoder(r).Decode(m) | ||
if err != nil { | ||
return nil, fmt.Errorf("decoding package manifest: %w", err) | ||
} | ||
|
||
return m, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package v1 | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEmptyManifest(t *testing.T) { | ||
m := NewManifest() | ||
assert.Equal(t, VERSION, m.Version) | ||
assert.Equal(t, ManifestKind, m.Kind) | ||
} | ||
|
||
func TestParseManifest(t *testing.T) { | ||
|
||
manifest := ` | ||
# version and kind to uniquely identify the schema | ||
version: co.elastic.agent/v1 | ||
kind: PackageManifest | ||
# description of the package itself | ||
package: | ||
version: 8.12.0 | ||
snapshot: false | ||
versioned-home: data/elastic-agent-4f2d39/ | ||
# generic path mapping: | ||
# - key is a prefix representing a path relative to the top of the archive | ||
# - value is the substitution to be applied when extracting the files | ||
path-mappings: | ||
- data/elastic-agent-4f2d39/ : data/elastic-agent-8.12.0/ | ||
foo: bar | ||
- manifest.yaml : data/elastic-agent-8.12.0/manifest.yaml | ||
` | ||
m, err := ParseManifest(strings.NewReader(manifest)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, VERSION, m.Version) | ||
assert.Equal(t, ManifestKind, m.Kind) | ||
|
||
assert.Equal(t, m.Package.Version, "8.12.0") | ||
assert.Equal(t, m.Package.Snapshot, false) | ||
assert.Equal(t, m.Package.VersionedHome, "data/elastic-agent-4f2d39/") | ||
assert.Equal(t, m.Package.PathMappings, []map[string]string{{"data/elastic-agent-4f2d39/": "data/elastic-agent-8.12.0/", "foo": "bar"}, {"manifest.yaml": "data/elastic-agent-8.12.0/manifest.yaml"}}) | ||
} |