Skip to content

Commit

Permalink
Rename URL => hosts to reflect the agent policy
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Mar 26, 2021
1 parent 2e52470 commit ae350b8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { SavedObjectAttributes } from 'src/core/public';

export interface BaseSettings {
has_seen_add_data_notice?: boolean;
fleet_server_urls: string[];
fleet_server_hosts: string[];
// TODO remove as part of https://github.com/elastic/kibana/issues/94303
kibana_urls: string[];
kibana_ca_sha256?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
import type { EnrollmentAPIKey } from '../../../types';

interface Props {
fleetServerUrls: string[];
fleetServerHosts: string[];
kibanaUrl: string;
apiKey: EnrollmentAPIKey;
kibanaCASha256?: string;
Expand All @@ -24,8 +24,8 @@ const CommandCode = styled.pre({
overflow: 'scroll',
});

function getFleetServerUrlsEnrollArgs(apiKey: EnrollmentAPIKey, fleetServerUrls: string[]) {
return `--url=${fleetServerUrls[0]} --enrollment-token=${apiKey.api_key}`;
function getfleetServerHostsEnrollArgs(apiKey: EnrollmentAPIKey, fleetServerHosts: string[]) {
return `--url=${fleetServerHosts[0]} --enrollment-token=${apiKey.api_key}`;
}

function getKibanaUrlEnrollArgs(
Expand All @@ -42,12 +42,12 @@ export const ManualInstructions: React.FunctionComponent<Props> = ({
kibanaUrl,
apiKey,
kibanaCASha256,
fleetServerUrls,
fleetServerHosts,
}) => {
const fleetServerUrlsNotEmpty = fleetServerUrls.length > 0;
const fleetServerHostsNotEmpty = fleetServerHosts.length > 0;

const enrollArgs = fleetServerUrlsNotEmpty
? getFleetServerUrlsEnrollArgs(apiKey, fleetServerUrls)
const enrollArgs = fleetServerHostsNotEmpty
? getfleetServerHostsEnrollArgs(apiKey, fleetServerHosts)
: // TODO remove as part of https://github.com/elastic/kibana/issues/94303
getKibanaUrlEnrollArgs(apiKey, kibanaUrl, kibanaCASha256);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,25 @@ const TABLE_COLUMNS: EuiBasicTableProps<Change>['columns'] = [
function getLabel(change: Change) {
if (change.type === 'elasticsearch' && change.direction === 'removed') {
return i18n.translate('xpack.fleet.settingsConfirmModal.elasticsearchRemovedLabel', {
defaultMessage: 'Elasticsearch URL (old)',
defaultMessage: 'Elasticsearch hosts (old)',
});
}

if (change.type === 'elasticsearch' && change.direction === 'added') {
return i18n.translate('xpack.fleet.settingsConfirmModal.elasticsearchAddedLabel', {
defaultMessage: 'Elasticsearch URL (new)',
defaultMessage: 'Elasticsearch hosts (new)',
});
}

if (change.type === 'fleet_server' && change.direction === 'removed') {
return i18n.translate('xpack.fleet.settingsConfirmModal.fleetServerRemovedLabel', {
defaultMessage: 'Fleet Server URL (old)',
defaultMessage: 'Fleet Server hosts (old)',
});
}

if (change.type === 'fleet_server' && change.direction === 'added') {
return i18n.translate('xpack.fleet.settingsConfirmModal.fleetServerAddedLabel', {
defaultMessage: 'Fleet Server URL (new)',
defaultMessage: 'Fleet Server hosts (new)',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ function useSettingsForm(outputId: string | undefined, onSuccess: () => void) {
];
}
});
const fleetServerUrlsInput = useComboInput([], (value) => {
const fleetServerHostsInput = useComboInput([], (value) => {
// TODO enable as part of https://github.com/elastic/kibana/issues/94303
// if (value.length === 0) {
// return [
// i18n.translate('xpack.fleet.settings.fleetServerUrlsEmptyError', {
// i18n.translate('xpack.fleet.settings.fleetServerHostsEmptyError', {
// defaultMessage: 'At least one URL is required',
// }),
// ];
// }
if (value.some((v) => !v.match(URL_REGEX))) {
return [
i18n.translate('xpack.fleet.settings.fleetServerUrlsError', {
i18n.translate('xpack.fleet.settings.fleetServerHostsError', {
defaultMessage: 'Invalid URL',
}),
];
}
if (value.length && isDiffPathProtocol(value)) {
return [
i18n.translate('xpack.fleet.settings.fleetServerUrlsDifferentPathOrProtocolError', {
i18n.translate('xpack.fleet.settings.fleetServerHostsDifferentPathOrProtocolError', {
defaultMessage: 'Protocol and path must be the same for each URL',
}),
];
Expand Down Expand Up @@ -130,15 +130,15 @@ function useSettingsForm(outputId: string | undefined, onSuccess: () => void) {
const validate = useCallback(() => {
if (
!kibanaUrlsInput.validate() ||
!fleetServerUrlsInput.validate() ||
!fleetServerHostsInput.validate() ||
!elasticsearchUrlInput.validate() ||
!additionalYamlConfigInput.validate()
) {
return false;
}

return true;
}, [kibanaUrlsInput, fleetServerUrlsInput, elasticsearchUrlInput, additionalYamlConfigInput]);
}, [kibanaUrlsInput, fleetServerHostsInput, elasticsearchUrlInput, additionalYamlConfigInput]);

return {
isLoading,
Expand All @@ -158,7 +158,7 @@ function useSettingsForm(outputId: string | undefined, onSuccess: () => void) {
}
const settingsResponse = await sendPutSettings({
kibana_urls: kibanaUrlsInput.value,
fleet_server_urls: fleetServerUrlsInput.value,
fleet_server_hosts: fleetServerHostsInput.value,
});
if (settingsResponse.error) {
throw settingsResponse.error;
Expand All @@ -178,7 +178,7 @@ function useSettingsForm(outputId: string | undefined, onSuccess: () => void) {
}
},
inputs: {
fleetServerUrls: fleetServerUrlsInput,
fleetServerHosts: fleetServerHostsInput,
kibanaUrls: kibanaUrlsInput,
elasticsearchUrl: elasticsearchUrlInput,
additionalYamlConfig: additionalYamlConfigInput,
Expand Down Expand Up @@ -221,7 +221,7 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {
useEffect(() => {
if (settings) {
inputs.kibanaUrls.setValue([...settings.kibana_urls]);
inputs.fleetServerUrls.setValue([...settings.fleet_server_urls]);
inputs.fleetServerHosts.setValue([...settings.fleet_server_hosts]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [settings]);
Expand All @@ -232,7 +232,7 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {
}
return (
!isSameArrayValue(settings.kibana_urls, inputs.kibanaUrls.value) ||
!isSameArrayValue(settings.fleet_server_urls, inputs.fleetServerUrls.value) ||
!isSameArrayValue(settings.fleet_server_hosts, inputs.fleetServerHosts.value) ||
!isSameArrayValue(output.hosts, inputs.elasticsearchUrl.value) ||
(output.config_yaml || '') !== inputs.additionalYamlConfig.value
);
Expand All @@ -259,17 +259,17 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {
);
}

if (!isSameArrayValue(settings.fleet_server_urls, inputs.fleetServerUrls.value)) {
if (!isSameArrayValue(settings.fleet_server_hosts, inputs.fleetServerHosts.value)) {
tmpChanges.push(
{
type: 'fleet_server',
direction: 'removed',
urls: settings.fleet_server_urls,
urls: settings.fleet_server_hosts,
},
{
type: 'fleet_server',
direction: 'added',
urls: inputs.fleetServerUrls.value,
urls: inputs.fleetServerHosts.value,
}
);
}
Expand Down Expand Up @@ -301,12 +301,12 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {

<EuiFormRow
fullWidth
label={i18n.translate('xpack.fleet.settings.fleetServerUrlsLabel', {
defaultMessage: 'Fleet Server URL',
label={i18n.translate('xpack.fleet.settings.fleetServerHostsLabel', {
defaultMessage: 'Fleet Server hosts',
})}
helpText={
<FormattedMessage
id="xpack.fleet.settings.fleetServerUrlsHelpTect"
id="xpack.fleet.settings.fleetServerHostsHelpTect"
defaultMessage="Specify the URLs that your agents will use to connect to a Fleet Server. If multiple URLs exist, Fleet will show the first provided URL for enrollment purposes. For more information, see the {link}.'"
values={{
link: (
Expand All @@ -324,17 +324,17 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {
}}
/>
}
{...inputs.fleetServerUrls.formRowProps}
{...inputs.fleetServerHosts.formRowProps}
>
<EuiComboBox fullWidth noSuggestions {...inputs.fleetServerUrls.props} />
<EuiComboBox fullWidth noSuggestions {...inputs.fleetServerHosts.props} />
</EuiFormRow>

<EuiSpacer size="m" />
{/* // TODO remove as part of https://github.com/elastic/kibana/issues/94303 */}
<EuiFormRow
fullWidth
label={i18n.translate('xpack.fleet.settings.kibanaUrlLabel', {
defaultMessage: 'Kibana URL',
defaultMessage: 'Kibana hosts',
})}
{...inputs.kibanaUrls.formRowProps}
>
Expand All @@ -344,7 +344,7 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {
<EuiFormRow
fullWidth
label={i18n.translate('xpack.fleet.settings.elasticsearchUrlLabel', {
defaultMessage: 'Elasticsearch URL',
defaultMessage: 'Elasticsearch hosts',
})}
helpText={i18n.translate('xpack.fleet.settings.elasticsearchUrlsHelpTect', {
defaultMessage: 'Specify the Elasticsearch URLs where agents will send data.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const ManagedInstructions = React.memo<Props>(({ agentPolicies }) => {
apiKey={apiKey.data.item}
kibanaUrl={kibanaUrl}
kibanaCASha256={kibanaCASha256}
fleetServerUrls={settings.data?.item?.fleet_server_urls || []}
fleetServerHosts={settings.data?.item?.fleet_server_hosts || []}
/>
),
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const getSavedObjectTypes = (
},
mappings: {
properties: {
fleet_server_urls: { type: 'keyword' },
fleet_server_hosts: { type: 'keyword' },
has_seen_add_data_notice: { type: 'boolean', index: false },
// TODO remove as part of https://github.com/elastic/kibana/issues/94303
kibana_urls: { type: 'keyword' },
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ class AgentPolicyService {
} catch (error) {
throw new Error('Default settings is not setup');
}
if (settings.fleet_server_urls && settings.fleet_server_urls.length) {
if (settings.fleet_server_hosts && settings.fleet_server_hosts.length) {
fullAgentPolicy.fleet = {
hosts: settings.fleet_server_urls,
hosts: settings.fleet_server_hosts,
};
} // TODO remove as part of https://github.com/elastic/kibana/issues/94303
else {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/fleet/server/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function getSettings(soClient: SavedObjectsClientContract): Promise
return {
id: settingsSo.id,
...settingsSo.attributes,
fleet_server_urls: settingsSo.attributes.fleet_server_urls || [],
fleet_server_hosts: settingsSo.attributes.fleet_server_hosts || [],
};
}

Expand Down Expand Up @@ -82,10 +82,10 @@ export function createDefaultSettings(): BaseSettings {
pathname: basePath.serverBasePath,
});

const fleetServerUrls = appContextService.getConfig()?.agents?.fleet_server?.hosts ?? [];
const fleetServerHosts = appContextService.getConfig()?.agents?.fleet_server?.hosts ?? [];

return {
kibana_urls: [cloudUrl || flagsUrl || defaultUrl].flat(),
fleet_server_urls: fleetServerUrls,
fleet_server_hosts: fleetServerHosts,
};
}
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/types/rest_spec/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const GetSettingsRequestSchema = {};

export const PutSettingsRequestSchema = {
body: schema.object({
fleet_server_urls: schema.maybe(
fleet_server_hosts: schema.maybe(
schema.arrayOf(schema.uri({ scheme: ['http', 'https'] }), {
validate: (value) => {
if (value.length && isDiffPathProtocol(value)) {
Expand Down

0 comments on commit ae350b8

Please sign in to comment.