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 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 CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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]
- Not hiding error in case of http failure using elastic fetcher {pull}11604[11604]
- Relax validation of the X-Pack license UID value. {issue}11640[11640]
- Fix a parsing error with the X-Pack license check on 32-bit system. {issue}11650[11650]
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/management/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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