-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add manifest to package #3910
Merged
Merged
Add manifest to package #3910
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4a198df
Add manifest to package
pchila fb38692
Add tests for manifest in zip packages
pchila 29817dc
Add support for symlinks when extracting tar archives in dev-tools
pchila 563f347
Add manifest to rpm and deb packages
pchila 343bd44
Sets mappings as arrays of maps to allow precedence
pchila aec6b0c
fix lint errors
pchila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created dedicated issue for vcs removal #4138