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

[Ingest Manager] Do not allow empty namespace #67492

Merged
merged 2 commits into from
May 27, 2020
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
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 }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nchaulet Can we use this to also do some validation? For example namespace should not contain - as an example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can provide a validate function, where we can add all the custom logic we want

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'));
});
}