Skip to content

Commit

Permalink
updated privileges. fixed ui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisecheng committed Oct 15, 2020
1 parent c337198 commit 8eb4cc2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 77 deletions.
6 changes: 2 additions & 4 deletions x-pack/plugins/logstash/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ export class LogstashPlugin implements Plugin {
},
privileges: [
{
requiredClusterPrivileges: [],
requiredIndexPrivileges: {
['.logstash']: ['read'],
},
requiredClusterPrivileges: ['manage_logstash_pipelines'],
requiredIndexPrivileges: {},
ui: [],
},
],
Expand Down
24 changes: 11 additions & 13 deletions x-pack/plugins/logstash/server/routes/pipeline/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ export function registerPipelineLoadRoute(router: IRouter) {
router.handleLegacyErrors(async (context, request, response) => {
const client = context.logstash!.esClient;

try {
const result = await client.callAsCurrentUser('transport.request', {
path: '/_logstash/pipeline/' + encodeURIComponent(request.params.id),
method: 'GET',
});
return response.ok({
body: Pipeline.fromUpstreamJSON(result).downstreamJSON,
});
} catch (err) {
if (err.statusCode === 404) {
return response.notFound();
}
const result = await client.callAsCurrentUser('transport.request', {
path: '/_logstash/pipeline/' + encodeURIComponent(request.params.id),
method: 'GET',
ignore: [404],
});

throw err;
if (result[request.params.id] === undefined) {
return response.notFound();
}

return response.ok({
body: Pipeline.fromUpstreamJSON(result).downstreamJSON,
});
})
)
);
Expand Down
23 changes: 8 additions & 15 deletions x-pack/plugins/logstash/server/routes/pipelines/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ async function fetchPipelines(callWithRequest: LegacyAPICaller) {
const params = {
path: '/_logstash/pipeline',
method: 'GET',
ignore: [404],
};

try {
return await callWithRequest('transport.request', params);
} catch (err) {
if (err.statusCode === 404) {
return {};
}
throw err;
}
return await callWithRequest('transport.request', params);
}

export function registerPipelinesListRoute(router: IRouter) {
Expand All @@ -37,14 +31,13 @@ export function registerPipelinesListRoute(router: IRouter) {
router.handleLegacyErrors(async (context, request, response) => {
try {
const client = context.logstash!.esClient;
const pipelinesRecord = (await fetchPipelines(client.callAsCurrentUser)) as Record<
string,
any
>;
const pipelinesRecord = (await fetchPipelines(client.callAsCurrentUser)) as Record<string, any>;

const pipelines = Object.keys(pipelinesRecord).map((key) => {
return PipelineListItem.fromUpstreamJSON(key, pipelinesRecord).downstreamJSON;
});
const pipelines = Object.keys(pipelinesRecord)
.sort()
.map((key) => {
return PipelineListItem.fromUpstreamJSON(key, pipelinesRecord).downstreamJSON;
});

return response.ok({ body: { pipelines } });
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,136 +1,136 @@
{
"pipelines": [
{
"id": "tweets_and_beats",
"description": "ingest tweets and beats",
"last_modified": "2017-08-02T18:59:07.724Z",
"username": "elastic"
},
{
"id": "empty_pipeline_1",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_2",
"id": "empty_pipeline_10",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_3",
"id": "empty_pipeline_11",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_4",
"id": "empty_pipeline_12",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_5",
"id": "empty_pipeline_13",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_6",
"id": "empty_pipeline_14",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_7",
"id": "empty_pipeline_15",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_8",
"id": "empty_pipeline_16",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_9",
"id": "empty_pipeline_17",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_10",
"id": "empty_pipeline_18",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_11",
"id": "empty_pipeline_19",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_12",
"id": "empty_pipeline_2",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_13",
"id": "empty_pipeline_20",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_14",
"id": "empty_pipeline_21",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_15",
"id": "empty_pipeline_3",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_16",
"id": "empty_pipeline_4",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_17",
"id": "empty_pipeline_5",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_18",
"id": "empty_pipeline_6",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_19",
"id": "empty_pipeline_7",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_20",
"id": "empty_pipeline_8",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "empty_pipeline_21",
"id": "empty_pipeline_9",
"description": "an empty pipeline",
"last_modified": "2017-08-02T18:57:32.907Z",
"username": "elastic"
},
{
"id": "tweets_and_beats",
"description": "ingest tweets and beats",
"last_modified": "2017-08-02T18:59:07.724Z",
"username": "elastic"
}
]
}
22 changes: 9 additions & 13 deletions x-pack/test/functional/apps/logstash/pipeline_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,19 @@ export default function ({ getService, getPageObjects }) {
expect(time).to.be.a('string').match(/ ago$/);
}

const expectedRows = [
{
selected: false,
id: 'tweets_and_beats',
description: 'ingest tweets and beats',
username: 'elastic',
},
];

for (let emptyPipelineId = 1; emptyPipelineId <= 19; ++emptyPipelineId) {
let expectedRows = [];
for (let emptyPipelineId = 1; emptyPipelineId <= 21; ++emptyPipelineId) {
expectedRows.push({
selected: false,
id: `empty_pipeline_${emptyPipelineId}`,
description: 'an empty pipeline',
username: 'elastic',
});
}
expectedRows = expectedRows.sort((a, b) => {
return a.id.localeCompare(b.id);
});
expectedRows.pop();

expect(rowsWithoutTime).to.eql(expectedRows);
});
Expand Down Expand Up @@ -145,14 +141,14 @@ export default function ({ getService, getPageObjects }) {
expect(rowsWithoutTime).to.eql([
{
selected: false,
id: 'empty_pipeline_20',
id: 'empty_pipeline_9',
description: 'an empty pipeline',
username: 'elastic',
},
{
selected: false,
id: 'empty_pipeline_21',
description: 'an empty pipeline',
id: 'tweets_and_beats',
description: 'ingest tweets and beats',
username: 'elastic',
},
]);
Expand Down
7 changes: 1 addition & 6 deletions x-pack/test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,7 @@ export default async function ({ readConfigFile }) {

logstash_read_user: {
elasticsearch: {
indices: [
{
names: ['.logstash*'],
privileges: ['read'],
},
],
cluster: ['manage_logstash_pipelines'],
},
},

Expand Down

0 comments on commit 8eb4cc2

Please sign in to comment.