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

[CM] Parse enrollment_token response correctly #11648

Merged
merged 8 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand All @@ -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*

Expand Down
11 changes: 7 additions & 4 deletions x-pack/libbeat/management/api/enrollment_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion x-pack/libbeat/management/api/enrollment_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions x-pack/libbeat/tests/system/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down