-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Beats Management] APIs: List beats #19086
Merged
ycombinator
merged 10 commits into
elastic:feature/x-pack/management/beats
from
ycombinator:x-pack/management/beats/apis/list-beats
May 16, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eac12d3
WIP checkin
ycombinator ab5f7c5
Add API integration test
ycombinator 4b8d07a
Converting to Jest test
ycombinator bc36b71
WIP checkin
ycombinator 8767446
Fixing API for default case + adding test for it
ycombinator 99d0133
Fixing copy pasta typos
ycombinator cb8bf7d
Fixing variable name
ycombinator b529175
Using a single index
ycombinator df299c2
Implementing GET /api/beats/agents API
ycombinator 9ed50d1
Updating mapping
ycombinator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/beats/server/routes/api/register_list_beats_route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { | ||
get, | ||
omit | ||
} from "lodash"; | ||
import { INDEX_NAMES } from "../../../common/constants"; | ||
import { callWithRequestFactory } from '../../lib/client'; | ||
import { wrapEsError } from "../../lib/error_wrappers"; | ||
|
||
async function getBeats(callWithRequest) { | ||
const params = { | ||
index: INDEX_NAMES.BEATS, | ||
type: '_doc', | ||
q: 'type:beat' | ||
}; | ||
|
||
const response = await callWithRequest('search', params); | ||
return get(response, 'hits.hits', []); | ||
} | ||
|
||
// TODO: add license check pre-hook | ||
export function registerListBeatsRoute(server) { | ||
server.route({ | ||
method: 'GET', | ||
path: '/api/beats/agents', | ||
handler: async (request, reply) => { | ||
const callWithRequest = callWithRequestFactory(server, request); | ||
let beats; | ||
|
||
try { | ||
beats = await getBeats(callWithRequest); | ||
} catch (err) { | ||
return reply(wrapEsError(err)); | ||
} | ||
|
||
const response = { | ||
beats: beats.map(beat => omit(beat._source.beat, ['access_token'])) | ||
}; | ||
reply(response); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import expect from 'expect.js'; | ||
|
||
export default function ({ getService }) { | ||
const supertest = getService('supertest'); | ||
const esArchiver = getService('esArchiver'); | ||
|
||
describe('list_beats', () => { | ||
const archive = 'beats/list'; | ||
|
||
beforeEach('load beats archive', () => esArchiver.load(archive)); | ||
afterEach('unload beats archive', () => esArchiver.unload(archive)); | ||
|
||
it('should return all beats', async () => { | ||
const { body: apiResponse } = await supertest | ||
.get( | ||
'/api/beats/agents' | ||
) | ||
.expect(200); | ||
|
||
const beatsFromApi = apiResponse.beats; | ||
|
||
expect(beatsFromApi.length).to.be(3); | ||
expect(beatsFromApi.filter(beat => beat.hasOwnProperty('verified_on')).length).to.be(1); | ||
expect(beatsFromApi.find(beat => beat.hasOwnProperty('verified_on')).id).to.be('foo'); | ||
}); | ||
|
||
it('should not return access tokens', async () => { | ||
const { body: apiResponse } = await supertest | ||
.get( | ||
'/api/beats/agents' | ||
) | ||
.expect(200); | ||
|
||
const beatsFromApi = apiResponse.beats; | ||
|
||
expect(beatsFromApi.length).to.be(3); | ||
expect(beatsFromApi.filter(beat => beat.hasOwnProperty('access_token')).length).to.be(0); | ||
}); | ||
}); | ||
} |
Binary file not shown.
82 changes: 82 additions & 0 deletions
82
x-pack/test/functional/es_archives/beats/list/mappings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"type": "index", | ||
"value": { | ||
"index": ".management-beats", | ||
"settings": { | ||
"index": { | ||
"codec": "best_compression", | ||
"number_of_shards": "1", | ||
"auto_expand_replicas": "0-1", | ||
"number_of_replicas": "0" | ||
} | ||
}, | ||
"mappings": { | ||
"_doc": { | ||
"dynamic": "strict", | ||
"properties": { | ||
"type": { | ||
"type": "keyword" | ||
}, | ||
"enrollment_token": { | ||
"properties": { | ||
"token": { | ||
"type": "keyword" | ||
}, | ||
"expires_on": { | ||
"type": "date" | ||
} | ||
} | ||
}, | ||
"configuration_block": { | ||
"properties": { | ||
"tag": { | ||
"type": "keyword" | ||
}, | ||
"type": { | ||
"type": "keyword" | ||
}, | ||
"block_yml": { | ||
"type": "text" | ||
} | ||
} | ||
}, | ||
"beat": { | ||
"properties": { | ||
"id": { | ||
"type": "keyword" | ||
}, | ||
"access_token": { | ||
"type": "keyword" | ||
}, | ||
"verified_on": { | ||
"type": "date" | ||
}, | ||
"type": { | ||
"type": "keyword" | ||
}, | ||
"host_ip": { | ||
"type": "ip" | ||
}, | ||
"host_name": { | ||
"type": "keyword" | ||
}, | ||
"ephemeral_id": { | ||
"type": "keyword" | ||
}, | ||
"local_configuration_yml": { | ||
"type": "text" | ||
}, | ||
"central_configuration_yml": { | ||
"type": "text" | ||
}, | ||
"metadata": { | ||
"dynamic": "true", | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!