Skip to content

Commit

Permalink
[Ingest Manager] Do not allow empty namespace (#67492) (#67532)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored May 27, 2020
1 parent dfface2 commit 7bf18c4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const CreateAgentConfigFlyout: React.FunctionComponent<Props> = ({ onClos
const [agentConfig, setAgentConfig] = useState<NewAgentConfig>({
name: '',
description: '',
namespace: '',
namespace: 'default',
is_default: undefined,
monitoring_enabled: ['logs', 'metrics'],
});
Expand Down Expand Up @@ -102,6 +102,7 @@ export const CreateAgentConfigFlyout: React.FunctionComponent<Props> = ({ onClos
setIsLoading(true);
try {
const { data, error } = await createAgentConfig();
setIsLoading(false);
if (data?.success) {
notifications.toasts.addSuccess(
i18n.translate(
Expand All @@ -112,6 +113,7 @@ export const CreateAgentConfigFlyout: React.FunctionComponent<Props> = ({ onClos
}
)
);
onClose();
} else {
notifications.toasts.addDanger(
error
Expand All @@ -125,14 +127,13 @@ export const CreateAgentConfigFlyout: React.FunctionComponent<Props> = ({ onClos
);
}
} catch (e) {
setIsLoading(false);
notifications.toasts.addDanger(
i18n.translate('xpack.ingestManager.createAgentConfig.errorNotificationTitle', {
defaultMessage: 'Unable to create agent config',
})
);
}
setIsLoading(false);
onClose();
}}
>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AgentConfigStatus } from '../../../common';

const AgentConfigBaseSchema = {
name: schema.string(),
namespace: schema.maybe(schema.string()),
namespace: schema.string({ minLength: 1 }),
description: schema.maybe(schema.string()),
monitoring_enabled: schema.maybe(
schema.arrayOf(schema.oneOf([schema.literal('logs'), schema.literal('metrics')]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ConfigRecordSchema = schema.recordOf(
const DatasourceBaseSchema = {
name: schema.string(),
description: schema.maybe(schema.string()),
namespace: schema.maybe(schema.string()),
namespace: schema.string({ minLength: 1 }),
config_id: schema.string(),
enabled: schema.boolean(),
package: schema.maybe(
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ loadTestFile }) {
loadTestFile(require.resolve('./short_urls'));
loadTestFile(require.resolve('./lens'));
loadTestFile(require.resolve('./fleet'));
loadTestFile(require.resolve('./ingest'));
loadTestFile(require.resolve('./ingest_manager'));
loadTestFile(require.resolve('./endpoint'));
loadTestFile(require.resolve('./ml'));
});
Expand Down
59 changes: 0 additions & 59 deletions x-pack/test/api_integration/apis/ingest/policies.ts

This file was deleted.

40 changes: 40 additions & 0 deletions x-pack/test/api_integration/apis/ingest_manager/agent_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

describe('ingest_manager_agent_configs', () => {
describe('POST /api/ingest_manager/agent_configs', () => {
it('should work with valid values', async () => {
const { body: apiResponse } = await supertest
.post(`/api/ingest_manager/agent_configs`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'TEST',
namespace: 'default',
})
.expect(200);

expect(apiResponse.success).to.be(true);
});

it('should return a 400 with an invalid namespace', async () => {
await supertest
.post(`/api/ingest_manager/agent_configs`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'TEST',
namespace: '',
})
.expect(400);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

export default function loadTests({ loadTestFile }) {
describe('Ingest Endpoints', () => {
loadTestFile(require.resolve('./policies'));
describe('Ingest Manager Endpoints', () => {
loadTestFile(require.resolve('./agent_config'));
});
}

0 comments on commit 7bf18c4

Please sign in to comment.