Skip to content

Commit

Permalink
[Ingest Manager] Download asc from artifact store specified in spec (#…
Browse files Browse the repository at this point in the history
…21488)

[Ingest Manager] Download asc from artifact store specified in spec (#21488)
  • Loading branch information
michalpristas committed Oct 5, 2020
1 parent d987d10 commit eb119c9
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (u *Upgrader) downloadArtifact(ctx context.Context, version, sourceURI stri
return "", errors.New(err, "failed upgrade of agent binary")
}

matches, err := verifier.Verify(agentName, version)
matches, err := verifier.Verify(agentName, version, agentArtifactName)
if err != nil {
return "", errors.New(err, "failed verification of agent binary")
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/agent/operation/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var _ download.Downloader = &DummyDownloader{}

type DummyVerifier struct{}

func (*DummyVerifier) Verify(p, v string) (bool, error) {
func (*DummyVerifier) Verify(p, v, _ string) (bool, error) {
return true, nil
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/agent/operation/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (o *Operator) generateMonitoringSteps(version string, output interface{}) [
ProgramSpec: program.Spec{
Name: metricsProcessName,
Cmd: metricsProcessName,
Artifact: fmt.Sprintf("%s/%s", artifactPrefix, logsProcessName),
Artifact: fmt.Sprintf("%s/%s", artifactPrefix, metricsProcessName),
},
Meta: map[string]interface{}{
configrequest.MetaConfigKey: mbConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (o *operationVerify) Run(_ context.Context, application Application) (err e
}
}()

isVerified, err := o.verifier.Verify(o.program.BinaryName(), o.program.Version())
isVerified, err := o.verifier.Verify(o.program.BinaryName(), o.program.Version(), o.program.ArtifactName())
if err != nil {
return errors.New(err,
fmt.Sprintf("operation '%s' failed to verify %s.%s", o.Name(), o.program.BinaryName(), o.program.Version()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func NewVerifier(verifiers ...download.Verifier) *Verifier {
}

// Verify checks the package from configured source.
func (e *Verifier) Verify(programName, version string) (bool, error) {
func (e *Verifier) Verify(programName, version, artifactName string) (bool, error) {
var err error

for _, v := range e.vv {
b, e := v.Verify(programName, version)
b, e := v.Verify(programName, version, artifactName)
if e == nil {
return b, nil
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/artifact/download/fs/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewVerifier(config *artifact.Config, allowEmptyPgp bool, pgp []byte) (*Veri

// Verify checks downloaded package on preconfigured
// location agains a key stored on elastic.co website.
func (v *Verifier) Verify(programName, version string) (bool, error) {
func (v *Verifier) Verify(programName, version, artifactName string) (bool, error) {
filename, err := artifact.GetArtifactName(programName, version, v.config.OS(), v.config.Arch())
if err != nil {
return false, errors.New(err, "retrieving package name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestFetchVerify(t *testing.T) {
// first download verify should fail:
// download skipped, as invalid package is prepared upfront
// verify fails and cleans download
matches, err := verifier.Verify(programName, version)
matches, err := verifier.Verify(programName, version, artifactName)
assert.NoError(t, err)
assert.Equal(t, false, matches)

Expand All @@ -88,7 +88,7 @@ func TestFetchVerify(t *testing.T) {
_, err = os.Stat(hashTargetFilePath)
assert.NoError(t, err)

matches, err = verifier.Verify(programName, version)
matches, err = verifier.Verify(programName, version, artifactName)
assert.NoError(t, err)
assert.Equal(t, true, matches)
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestVerify(t *testing.T) {
t.Fatal(err)
}

isOk, err := testVerifier.Verify(beatName, version)
isOk, err := testVerifier.Verify(beatName, version, artifactName)
if err != nil {
t.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestVerify(t *testing.T) {
t.Fatal(err)
}

isOk, err := testVerifier.Verify(beatName, version)
isOk, err := testVerifier.Verify(beatName, version, artifactName)
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions x-pack/elastic-agent/pkg/artifact/download/http/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewVerifier(config *artifact.Config, allowEmptyPgp bool, pgp []byte) (*Veri

// Verify checks downloaded package on preconfigured
// location agains a key stored on elastic.co website.
func (v *Verifier) Verify(programName, version string) (bool, error) {
func (v *Verifier) Verify(programName, version, artifactName string) (bool, error) {
// TODO: think about verifying asc for prepacked beats

filename, err := artifact.GetArtifactName(programName, version, v.config.OS(), v.config.Arch())
Expand All @@ -81,7 +81,7 @@ func (v *Verifier) Verify(programName, version string) (bool, error) {
return isMatch, err
}

return v.verifyAsc(programName, version)
return v.verifyAsc(programName, version, artifactName)
}

func (v *Verifier) verifyHash(filename, fullPath string) (bool, error) {
Expand Down Expand Up @@ -127,7 +127,7 @@ func (v *Verifier) verifyHash(filename, fullPath string) (bool, error) {
return expectedHash == computedHash, nil
}

func (v *Verifier) verifyAsc(programName, version string) (bool, error) {
func (v *Verifier) verifyAsc(programName, version, artifactName string) (bool, error) {
if len(v.pgpBytes) == 0 {
// no pgp available skip verification process
return true, nil
Expand All @@ -143,7 +143,7 @@ func (v *Verifier) verifyAsc(programName, version string) (bool, error) {
return false, errors.New(err, "retrieving package path")
}

ascURI, err := v.composeURI(programName, filename)
ascURI, err := v.composeURI(filename, artifactName)
if err != nil {
return false, errors.New(err, "composing URI for fetching asc file", errors.TypeNetwork)
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func (v *Verifier) verifyAsc(programName, version string) (bool, error) {

}

func (v *Verifier) composeURI(programName, filename string) (string, error) {
func (v *Verifier) composeURI(filename, artifactName string) (string, error) {
upstream := v.config.SourceURI
if !strings.HasPrefix(upstream, "http") && !strings.HasPrefix(upstream, "file") && !strings.HasPrefix(upstream, "/") {
// always default to https
Expand All @@ -190,7 +190,7 @@ func (v *Verifier) composeURI(programName, filename string) (string, error) {
return "", errors.New(err, "invalid upstream URI", errors.TypeNetwork, errors.M(errors.MetaKeyURI, upstream))
}

uri.Path = path.Join(uri.Path, "beats", programName, filename+ascSuffix)
uri.Path = path.Join(uri.Path, artifactName, filename+ascSuffix)
return uri.String(), nil
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/artifact/download/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ package download

// Verifier is an interface verifying GPG key of a downloaded artifact
type Verifier interface {
Verify(programName, version string) (bool, error)
Verify(programName, version, artifactName string) (bool, error)
}

0 comments on commit eb119c9

Please sign in to comment.