From d4ebdef0a69498441a6442b0d0345b4bfc329411 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 4 Apr 2019 14:49:36 +0200 Subject: [PATCH 1/4] fixed enroll response parsing --- x-pack/libbeat/management/api/enrollment_token.go | 11 +++++++---- x-pack/libbeat/tests/system/test_management.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/x-pack/libbeat/management/api/enrollment_token.go b/x-pack/libbeat/management/api/enrollment_token.go index dec537d1d52..cf20a075a73 100644 --- a/x-pack/libbeat/management/api/enrollment_token.go +++ b/x-pack/libbeat/management/api/enrollment_token.go @@ -14,16 +14,19 @@ func (c *Client) CreateEnrollmentToken() (string, error) { headers := http.Header{} resp := struct { - Tokens []string `json:"tokens"` + Results []struct { + Token string `json:"item"` + } `json:"results"` }{} + _, err := c.request("POST", "/api/beats/enrollment_tokens", nil, headers, &resp) if err != nil { return "", err } - if len(resp.Tokens) != 1 { - return "", fmt.Errorf("Unexpected number of tokens, got %d, only one expected", len(resp.Tokens)) + if tokensCount := len(resp.Results); tokensCount != 1 { + return "", fmt.Errorf("Unexpected number of tokens, got %d, only one expected", tokensCount) } - return resp.Tokens[0], nil + return resp.Results[0].Token, nil } diff --git a/x-pack/libbeat/tests/system/test_management.py b/x-pack/libbeat/tests/system/test_management.py index 0be0ea03b78..fc9f70b6331 100644 --- a/x-pack/libbeat/tests/system/test_management.py +++ b/x-pack/libbeat/tests/system/test_management.py @@ -15,8 +15,8 @@ # Disable because waiting artifacts from https://github.com/elastic/kibana/pull/31660 -# INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False) -INTEGRATION_TESTS = False +INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False) +# INTEGRATION_TESTS = False TIMEOUT = 2 * 60 From ec13e227acb193a30da4a2ff3311d59d49f4ec5d Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 4 Apr 2019 14:52:47 +0200 Subject: [PATCH 2/4] changelog --- CHANGELOG.next.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index a7ba9d9be53..7b89e30694c 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -45,6 +45,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Report faulting file when config reload fails. {pull}[11304]11304 - Fix a typo in libbeat/outputs/transport/client.go by updating `c.conn.LocalAddr()` to `c.conn.RemoteAddr()`. {pull}11242[11242] - Management configuration backup file will now have a timestamps in their name. {pull}11034[11034] +- [CM] Parse enrollment_token response correctly {pull}11648[11648] *Auditbeat* @@ -58,7 +59,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Improve detection of file deletion on Windows. {pull}10747[10747] - Fix goroutine leak happening when harvesters are dynamically stopped. {pull}11263[11263] - Fix `add_docker_metadata` source matching, using `log.file.path` field now. {pull}11577[11577] -- Add missing Kubernetes metadata fields to Filebeat CoreDNS module, and fix a documentation error. {pull}11591[11591] +- Add missing Kubernetes metadata fields to Filebeat CoreDNS module, and fix a documentation error. {pull}11591[11591] *Heartbeat* From d031c6e60dd65ac24962f6b2176d03b8afb3d376 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 4 Apr 2019 16:01:02 +0200 Subject: [PATCH 3/4] unit test: response updated to match new format --- x-pack/libbeat/management/api/enrollment_token_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/libbeat/management/api/enrollment_token_test.go b/x-pack/libbeat/management/api/enrollment_token_test.go index 2e4ce156849..2b5241e8f31 100644 --- a/x-pack/libbeat/management/api/enrollment_token_test.go +++ b/x-pack/libbeat/management/api/enrollment_token_test.go @@ -16,7 +16,7 @@ func TestEnrollmentToken(t *testing.T) { server, client := newServerClientPair(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Check correct path is used assert.Equal(t, "/api/beats/enrollment_tokens", r.URL.Path) - fmt.Fprintf(w, `{"tokens":["65074ff8639a4661ba7e1bd5ccc209ed"]}`) + fmt.Fprintf(w, `{"results": [{"item":"65074ff8639a4661ba7e1bd5ccc209ed"}]}`) })) defer server.Close() From d6b1a86f2f10c85d2605cf7b54d27947e8369d14 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 5 Apr 2019 16:11:03 +0200 Subject: [PATCH 4/4] fix time string --- x-pack/libbeat/management/enroll.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/libbeat/management/enroll.go b/x-pack/libbeat/management/enroll.go index 1265d57fc46..0a2bda29b27 100644 --- a/x-pack/libbeat/management/enroll.go +++ b/x-pack/libbeat/management/enroll.go @@ -53,10 +53,10 @@ func Enroll( configFile := cfgfile.GetDefaultCfgfile() - ts := time.Now().Unix() + ts := time.Now() // backup current settings: - backConfigFile := configFile + "." + string(ts) + ".bak" + backConfigFile := configFile + "." + ts.Format(time.RFC3339) + ".bak" fmt.Println("Saving a copy of current settings to " + backConfigFile) err = file.SafeFileRotate(backConfigFile, configFile) if err != nil {