Skip to content

Commit

Permalink
Make Kibana API guess host IP instead of requiring it in payload
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed May 16, 2018
1 parent 26c3bed commit fc1f88f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ function deleteUsedEnrollmentToken(callWithInternalUser, enrollmentToken) {
return callWithInternalUser('delete', params);
}

function persistBeat(callWithInternalUser, beat, beatId, accessToken) {
function persistBeat(callWithInternalUser, beat, beatId, accessToken, remoteAddress) {
const body = {
type: 'beat',
beat: {
...omit(beat, 'enrollment_token'),
id: beatId,
access_token: accessToken
access_token: accessToken,
host_ip: remoteAddress
}
};

Expand All @@ -68,8 +69,7 @@ export function registerEnrollBeatRoute(server) {
payload: Joi.object({
enrollment_token: Joi.string().required(),
type: Joi.string().required(),
host_name: Joi.string().required(),
host_ip: Joi.string().required()
host_name: Joi.string().required()
}).required()
},
auth: false
Expand All @@ -89,7 +89,8 @@ export function registerEnrollBeatRoute(server) {
}

accessToken = uuid.v4().replace(/-/g, "");
await persistBeat(callWithInternalUser, request.payload, request.params.beatId, accessToken);
const remoteAddress = request.info.remoteAddress;
await persistBeat(callWithInternalUser, request.payload, request.params.beatId, accessToken, remoteAddress);

await deleteUsedEnrollmentToken(callWithInternalUser, enrollmentToken);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/beats/enroll_beat.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function ({ getService }) {
beat = {
enrollment_token: validEnrollmentToken,
type: 'filebeat',
host_ip: '11.22.33.44',
host_name: 'foo.bar.com',
};

Expand Down Expand Up @@ -61,6 +60,7 @@ export default function ({ getService }) {
});

expect(esResponse._source.beat).to.not.have.property('verified_on');
expect(esResponse._source.beat).to.have.property('host_ip');
});

it('should contain an access token in the response', async () => {
Expand Down

0 comments on commit fc1f88f

Please sign in to comment.