Skip to content
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

[Elastic-Agent] Correctly unmarshal Protocol #17843

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Remove the kbn-version on each request to the Kibana API. {pull}17764[17764]
- Fixed process spawning on Windows {pull}17751[17751]
- Fixed injected log path to monitoring beat {pull}17833[17833]
- Make sure that the Elastic Agent connect over TLS in cloud. {pull}xx[xxx]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ph Can you fix this in a follow up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 one day we wont need this.


==== New features

Expand Down
2 changes: 2 additions & 0 deletions x-pack/elastic-agent/pkg/kibana/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func (p *Protocol) Unpack(from string) error {
if from != "https" && from != "http" {
return fmt.Errorf("invalid protocol %s, accepted values are 'http' and 'https'", from)
}

*p = Protocol(from)
return nil
}

Expand Down
37 changes: 37 additions & 0 deletions x-pack/elastic-agent/pkg/kibana/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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 kibana

import (
"reflect"
"testing"
"time"

"gopkg.in/yaml.v2"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPackUnpack(t *testing.T) {
c := Config{
Protocol: Protocol("https"),
SpaceID: "123",
Username: "foo",
Password: "bar",
Path: "/ok",
Timeout: 10 * time.Second,
}

b, err := yaml.Marshal(&c)
require.NoError(t, err)

c2 := Config{}

err = yaml.Unmarshal(b, &c2)
require.NoError(t, err)

assert.True(t, reflect.DeepEqual(c, c2))
}