From 1a5c07c3ea9214280c1c4a6bd897d4a45c53d2f0 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 26 Jul 2022 09:00:20 -0700 Subject: [PATCH 01/10] Add new fields for license and subscription to models --- .../fleet/common/types/models/package_spec.ts | 15 ++++++++++----- .../hooks/use_package_install.test.tsx | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 x-pack/plugins/fleet/public/applications/integrations/hooks/use_package_install.test.tsx diff --git a/x-pack/plugins/fleet/common/types/models/package_spec.ts b/x-pack/plugins/fleet/common/types/models/package_spec.ts index 90f093ffe73545..53e22edb03dda4 100644 --- a/x-pack/plugins/fleet/common/types/models/package_spec.ts +++ b/x-pack/plugins/fleet/common/types/models/package_spec.ts @@ -15,6 +15,9 @@ export interface PackageSpecManifest { description: string; version: string; license?: 'basic'; + source?: { + license: string; + }; type?: 'integration'; release?: 'experimental' | 'beta' | 'ga'; categories?: Array; @@ -52,12 +55,14 @@ export type PackageSpecCategory = | 'version_control' | 'web'; -export type PackageSpecConditions = Record< - 'kibana', - { +export interface PackageSpecConditions { + kibana: { version: string; - } ->; + }; + elastic?: { + subscription: string; + }; +} export interface PackageSpecIcon { src: string; diff --git a/x-pack/plugins/fleet/public/applications/integrations/hooks/use_package_install.test.tsx b/x-pack/plugins/fleet/public/applications/integrations/hooks/use_package_install.test.tsx new file mode 100644 index 00000000000000..c6334162ec9e73 --- /dev/null +++ b/x-pack/plugins/fleet/public/applications/integrations/hooks/use_package_install.test.tsx @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { useSetPackageInstallStatus, useGetPackageInstallStatus } from './use_package_install'; + +jest.mock('../../../hooks', () => ({ + sendInstallPackage: async () => ({}), +})); + +describe('use_package_install', () => { + test('should provide provide package installation status', async () => { + const setPackageInstallStatus = useSetPackageInstallStatus(); + const getPackageInstallStatus = useGetPackageInstallStatus(); + }); +}); From 6b72cbb51d12f724df10bf2f31fad30652041acf Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 26 Jul 2022 15:06:06 -0700 Subject: [PATCH 02/10] Use `elastic.subscription` to display license info on package details page --- .../epm/screens/detail/overview/details.tsx | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx index 83631c674f7545..523cbeece226fe 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx @@ -155,30 +155,29 @@ export const Details: React.FC = memo(({ packageInfo }) => { } // License details - if (packageInfo.license || packageInfo.notice) { - items.push({ - title: ( - - - - ), - description: ( - <> -

{packageInfo.license}

- {packageInfo.notice && ( -

- NOTICE.txt -

- )} - - ), - }); - } + items.push({ + title: ( + + + + ), + description: ( + <> +

{packageInfo.conditions?.elastic?.subscription || packageInfo.license || '-'}

+ {packageInfo.notice && ( +

+ NOTICE.txt +

+ )} + + ), + }); return items; }, [ packageCategories, packageInfo.assets, + packageInfo.conditions?.elastic?.subscription, packageInfo.data_streams, packageInfo.license, packageInfo.notice, From 0f769c41e3ca620d16ea51d4bceb0136709bc131 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Mon, 1 Aug 2022 16:15:10 -0700 Subject: [PATCH 03/10] Show subscription and license on details page --- .../epm/screens/detail/overview/details.tsx | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx index 523cbeece226fe..cb210cd1b42775 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx @@ -154,25 +154,39 @@ export const Details: React.FC = memo(({ packageInfo }) => { }); } - // License details + // Subscription details items.push({ title: ( - + ), description: ( - <> -

{packageInfo.conditions?.elastic?.subscription || packageInfo.license || '-'}

- {packageInfo.notice && ( -

- NOTICE.txt -

- )} - +

{packageInfo.conditions?.elastic?.subscription || packageInfo.license || '-'}

), }); + // License details + if (packageInfo.source?.license || packageInfo.notice) { + items.push({ + title: ( + + + + ), + description: ( + <> + {packageInfo.source?.license &&

{packageInfo.source.license}

} + {packageInfo.notice && ( +

+ NOTICE.txt +

+ )} + + ), + }); + } + return items; }, [ packageCategories, @@ -181,6 +195,7 @@ export const Details: React.FC = memo(({ packageInfo }) => { packageInfo.data_streams, packageInfo.license, packageInfo.notice, + packageInfo.source?.license, packageInfo.version, toggleNoticeModal, ]); From d0377e81127ba7b67bfeb642392a605b8d38d308 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Mon, 1 Aug 2022 16:20:25 -0700 Subject: [PATCH 04/10] Support LICENSE.txt --- x-pack/plugins/fleet/common/types/models/epm.ts | 3 ++- .../fleet/server/services/epm/archive/index.ts | 7 +++++++ .../fleet/server/services/epm/packages/get.ts | 1 + .../fleet/server/services/epm/registry/index.ts | 12 ++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/common/types/models/epm.ts b/x-pack/plugins/fleet/common/types/models/epm.ts index 2a97719c811c17..66d37200c11d32 100644 --- a/x-pack/plugins/fleet/common/types/models/epm.ts +++ b/x-pack/plugins/fleet/common/types/models/epm.ts @@ -51,7 +51,7 @@ export type EpmPackageInstallStatus = 'installed' | 'installing' | 'install_fail export type DetailViewPanelName = 'overview' | 'policies' | 'assets' | 'settings' | 'custom'; export type ServiceName = 'kibana' | 'elasticsearch'; export type AgentAssetType = typeof agentAssetTypes; -export type DocAssetType = 'doc' | 'notice'; +export type DocAssetType = 'doc' | 'notice' | 'license'; export type AssetType = | KibanaAssetType | ElasticsearchAssetType @@ -382,6 +382,7 @@ export interface EpmPackageAdditions { latestVersion: string; assets: AssetsGroupedByServiceByType; notice?: string; + license?: string; keepPoliciesUpToDate?: boolean; } diff --git a/x-pack/plugins/fleet/server/services/epm/archive/index.ts b/x-pack/plugins/fleet/server/services/epm/archive/index.ts index 4d70c62bd55d39..330839b13dba9b 100644 --- a/x-pack/plugins/fleet/server/services/epm/archive/index.ts +++ b/x-pack/plugins/fleet/server/services/epm/archive/index.ts @@ -123,6 +123,13 @@ export function getPathParts(path: string): AssetParts { service = ''; } + // To support the LICENSE asset at the root level + if (service === 'LICENSE.txt') { + file = service; + type = 'license'; + service = ''; + } + // This is to cover for the fields.yml files inside the "fields" directory if (file === undefined) { file = type; diff --git a/x-pack/plugins/fleet/server/services/epm/packages/get.ts b/x-pack/plugins/fleet/server/services/epm/packages/get.ts index 0cfdfcac255b5f..0826978d8bb38b 100644 --- a/x-pack/plugins/fleet/server/services/epm/packages/get.ts +++ b/x-pack/plugins/fleet/server/services/epm/packages/get.ts @@ -182,6 +182,7 @@ export async function getPackageInfo({ title: packageInfo.title || nameAsTitle(packageInfo.name), assets: Registry.groupPathsByService(paths || []), notice: Registry.getNoticePath(paths || []), + license: Registry.getLicensePath(paths || []), keepPoliciesUpToDate: savedObject?.attributes.keep_policies_up_to_date ?? false, }; const updated = { ...packageInfo, ...additions }; diff --git a/x-pack/plugins/fleet/server/services/epm/registry/index.ts b/x-pack/plugins/fleet/server/services/epm/registry/index.ts index 26a30f5765a1fb..33ae5a1f141174 100644 --- a/x-pack/plugins/fleet/server/services/epm/registry/index.ts +++ b/x-pack/plugins/fleet/server/services/epm/registry/index.ts @@ -380,3 +380,15 @@ export function getNoticePath(paths: string[]): string | undefined { return undefined; } + +export function getLicensePath(paths: string[]): string | undefined { + for (const path of paths) { + const parts = getPathParts(path.replace(/^\/package\//, '')); + if (parts.type === 'license') { + const { pkgName, pkgVersion } = splitPkgKey(parts.pkgkey); + return `/package/${pkgName}/${pkgVersion}/${parts.file}`; + } + } + + return undefined; +} From 5e741d2cd7fdbec13aaffa0e3c7ae3ace640b994 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Mon, 1 Aug 2022 16:24:00 -0700 Subject: [PATCH 05/10] Change property name to licensePath --- x-pack/plugins/fleet/common/types/models/epm.ts | 2 +- x-pack/plugins/fleet/server/services/epm/packages/get.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/fleet/common/types/models/epm.ts b/x-pack/plugins/fleet/common/types/models/epm.ts index 66d37200c11d32..0c748461533ae9 100644 --- a/x-pack/plugins/fleet/common/types/models/epm.ts +++ b/x-pack/plugins/fleet/common/types/models/epm.ts @@ -382,7 +382,7 @@ export interface EpmPackageAdditions { latestVersion: string; assets: AssetsGroupedByServiceByType; notice?: string; - license?: string; + licensePath?: string; keepPoliciesUpToDate?: boolean; } diff --git a/x-pack/plugins/fleet/server/services/epm/packages/get.ts b/x-pack/plugins/fleet/server/services/epm/packages/get.ts index 0826978d8bb38b..bb8a7998a27348 100644 --- a/x-pack/plugins/fleet/server/services/epm/packages/get.ts +++ b/x-pack/plugins/fleet/server/services/epm/packages/get.ts @@ -182,7 +182,7 @@ export async function getPackageInfo({ title: packageInfo.title || nameAsTitle(packageInfo.name), assets: Registry.groupPathsByService(paths || []), notice: Registry.getNoticePath(paths || []), - license: Registry.getLicensePath(paths || []), + licensePath: Registry.getLicensePath(paths || []), keepPoliciesUpToDate: savedObject?.attributes.keep_policies_up_to_date ?? false, }; const updated = { ...packageInfo, ...additions }; From dcca3652aa639d26e6fbe7bd05c769e7854c28dd Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Mon, 1 Aug 2022 16:35:04 -0700 Subject: [PATCH 06/10] Show LICENSE.txt if it exists --- .../epm/screens/detail/overview/details.tsx | 25 +++++- .../screens/detail/overview/license_modal.tsx | 79 +++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/license_modal.tsx diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx index cb210cd1b42775..493fabceb3fb8c 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx @@ -33,6 +33,7 @@ import { useGetCategories } from '../../../../../hooks'; import { AssetTitleMap, DisplayedAssets, ServiceTitleMap } from '../../../constants'; import { NoticeModal } from './notice_modal'; +import { LicenseModal } from './license_modal'; const ReplacementCard = withSuspense(LazyReplacementCard); @@ -73,6 +74,11 @@ export const Details: React.FC = memo(({ packageInfo }) => { setIsNoticeModalOpen(!isNoticeModalOpen); }, [isNoticeModalOpen]); + const [isLicenseModalOpen, setIsLicenseModalOpen] = useState(false); + const toggleLicenseModal = useCallback(() => { + setIsLicenseModalOpen(!isLicenseModalOpen); + }, [isLicenseModalOpen]); + const listItems = useMemo(() => { // Base details: version and categories const items: EuiDescriptionListProps['listItems'] = [ @@ -167,7 +173,7 @@ export const Details: React.FC = memo(({ packageInfo }) => { }); // License details - if (packageInfo.source?.license || packageInfo.notice) { + if (packageInfo.licensePath || packageInfo.source?.license || packageInfo.notice) { items.push({ title: ( @@ -176,7 +182,15 @@ export const Details: React.FC = memo(({ packageInfo }) => { ), description: ( <> - {packageInfo.source?.license &&

{packageInfo.source.license}

} + {packageInfo.licensePath ? ( +

+ + {packageInfo.source?.license || 'LICENSE.txt'} + +

+ ) : ( +

{packageInfo.source?.license || '-'}

+ )} {packageInfo.notice && (

NOTICE.txt @@ -194,9 +208,11 @@ export const Details: React.FC = memo(({ packageInfo }) => { packageInfo.conditions?.elastic?.subscription, packageInfo.data_streams, packageInfo.license, + packageInfo.licensePath, packageInfo.notice, packageInfo.source?.license, packageInfo.version, + toggleLicenseModal, toggleNoticeModal, ]); @@ -207,6 +223,11 @@ export const Details: React.FC = memo(({ packageInfo }) => { )} + + {isLicenseModalOpen && packageInfo.licensePath && ( + + )} + diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/license_modal.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/license_modal.tsx new file mode 100644 index 00000000000000..bfae8d6f352342 --- /dev/null +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/license_modal.tsx @@ -0,0 +1,79 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { useEffect, useState } from 'react'; +import { + EuiCodeBlock, + EuiLoadingContent, + EuiModal, + EuiModalBody, + EuiModalHeader, + EuiModalFooter, + EuiModalHeaderTitle, + EuiButton, +} from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n-react'; + +import { sendGetFileByPath, useStartServices } from '../../../../../hooks'; + +interface Props { + licensePath: string; + onClose: () => void; +} + +export const LicenseModal: React.FunctionComponent = ({ licensePath, onClose }) => { + const { notifications } = useStartServices(); + const [licenseText, setLicenseText] = useState(undefined); + + useEffect(() => { + async function fetchData() { + try { + const { data } = await sendGetFileByPath(licensePath); + setLicenseText(data || ''); + } catch (err) { + notifications.toasts.addError(err, { + title: i18n.translate('xpack.fleet.epm.errorLoadingLicense', { + defaultMessage: 'Error loading LICENSE.txt', + }), + }); + } + } + fetchData(); + }, [licensePath, notifications]); + return ( + + + +

LICENSE.txt

+ + + + + {licenseText ? ( + licenseText + ) : ( + // Simulate a long text while loading + <> +

+ +

+

+ +

+ + )} +
+
+ + + + + + + ); +}; From 447a6086fe1cdabe07222acf560c2ea2a31d662c Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Wed, 3 Aug 2022 16:39:16 -0700 Subject: [PATCH 07/10] Remove accidental file --- .../hooks/use_package_install.test.tsx | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 x-pack/plugins/fleet/public/applications/integrations/hooks/use_package_install.test.tsx diff --git a/x-pack/plugins/fleet/public/applications/integrations/hooks/use_package_install.test.tsx b/x-pack/plugins/fleet/public/applications/integrations/hooks/use_package_install.test.tsx deleted file mode 100644 index c6334162ec9e73..00000000000000 --- a/x-pack/plugins/fleet/public/applications/integrations/hooks/use_package_install.test.tsx +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { useSetPackageInstallStatus, useGetPackageInstallStatus } from './use_package_install'; - -jest.mock('../../../hooks', () => ({ - sendInstallPackage: async () => ({}), -})); - -describe('use_package_install', () => { - test('should provide provide package installation status', async () => { - const setPackageInstallStatus = useSetPackageInstallStatus(); - const getPackageInstallStatus = useGetPackageInstallStatus(); - }); -}); From c59fefb7b7164564ec245ee73c3681214ed17353 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Wed, 3 Aug 2022 17:13:27 -0700 Subject: [PATCH 08/10] Fix openapi spec and add new fields --- .../plugins/fleet/common/openapi/bundled.json | 129 ++++++++++++------ .../plugins/fleet/common/openapi/bundled.yaml | 94 +++++++++---- .../components/schemas/package_info.yaml | 57 ++++++-- ...epm@packages@{pkg_name}@{pkg_version}.yaml | 8 ++ 4 files changed, 198 insertions(+), 90 deletions(-) diff --git a/x-pack/plugins/fleet/common/openapi/bundled.json b/x-pack/plugins/fleet/common/openapi/bundled.json index 357ceb3192e6f6..5c15cbba77131f 100644 --- a/x-pack/plugins/fleet/common/openapi/bundled.json +++ b/x-pack/plugins/fleet/common/openapi/bundled.json @@ -557,6 +557,18 @@ ] }, "savedObject": { + "type": "object" + }, + "latestVersion": { + "type": "string" + }, + "keepPoliciesUpToDate": { + "type": "boolean" + }, + "notice": { + "type": "string" + }, + "licensePath": { "type": "string" } }, @@ -3914,6 +3926,26 @@ "version": { "type": "string" }, + "release": { + "type": "string", + "enum": [ + "experimental", + "beta", + "ga" + ] + }, + "source": { + "type": "object", + "properties": { + "license": { + "type": "string", + "enum": [ + "Apache-2.0", + "Elastic-2.0" + ] + } + } + }, "readme": { "type": "string" }, @@ -3929,34 +3961,32 @@ "type": "string" } }, - "requirement": { - "oneOf": [ - { + "conditions": { + "type": "object", + "properties": { + "kibana": { + "type": "object", "properties": { - "kibana": { - "type": "object", - "properties": { - "versions": { - "type": "string" - } - } + "versions": { + "type": "string" } } }, - { + "elasticsearch": { + "type": "object", "properties": { - "elasticsearch": { - "type": "object", - "properties": { - "versions": { - "type": "string" - } - } + "subscription": { + "type": "string", + "enum": [ + "basic", + "gold", + "platinum", + "enterprise" + ] } } } - ], - "type": "object" + } }, "screenshots": { "type": "array", @@ -4060,6 +4090,22 @@ }, "path": { "type": "string" + }, + "elasticsearch": { + "type": "object", + "properties": { + "privileges": { + "type": "object", + "properties": { + "cluster": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } } }, "required": [ @@ -4069,7 +4115,7 @@ "description", "type", "categories", - "requirement", + "conditions", "assets", "format_version", "download", @@ -4306,6 +4352,10 @@ "description": "list of agent IDs" } ] + }, + "force": { + "type": "boolean", + "description": "Force upgrade, skipping validation (should be used with caution)" } }, "required": [ @@ -4315,32 +4365,21 @@ }, "upgrade_agent": { "title": "Upgrade agent", - "oneOf": [ - { - "type": "object", - "properties": { - "version": { - "type": "string" - } - }, - "required": [ - "version" - ] + "type": "object", + "properties": { + "version": { + "type": "string" }, - { - "type": "object", - "properties": { - "version": { - "type": "string" - }, - "source_uri": { - "type": "string" - } - }, - "required": [ - "version" - ] + "source_uri": { + "type": "string" + }, + "force": { + "type": "boolean", + "description": "Force upgrade, skipping validation (should be used with caution)" } + }, + "required": [ + "version" ] }, "agent_action": { diff --git a/x-pack/plugins/fleet/common/openapi/bundled.yaml b/x-pack/plugins/fleet/common/openapi/bundled.yaml index b902f130b2e183..6279d1703a2b40 100644 --- a/x-pack/plugins/fleet/common/openapi/bundled.yaml +++ b/x-pack/plugins/fleet/common/openapi/bundled.yaml @@ -350,6 +350,14 @@ paths: - install_failed - not_installed savedObject: + type: object + latestVersion: + type: string + keepPoliciesUpToDate: + type: boolean + notice: + type: string + licensePath: type: string required: - status @@ -2442,6 +2450,20 @@ components: type: string version: type: string + release: + type: string + enum: + - experimental + - beta + - ga + source: + type: object + properties: + license: + type: string + enum: + - Apache-2.0 + - Elastic-2.0 readme: type: string description: @@ -2452,21 +2474,24 @@ components: type: array items: type: string - requirement: - oneOf: - - properties: - kibana: - type: object - properties: - versions: - type: string - - properties: - elasticsearch: - type: object - properties: - versions: - type: string + conditions: type: object + properties: + kibana: + type: object + properties: + versions: + type: string + elasticsearch: + type: object + properties: + subscription: + type: string + enum: + - basic + - gold + - platinum + - enterprise screenshots: type: array items: @@ -2537,6 +2562,16 @@ components: type: string path: type: string + elasticsearch: + type: object + properties: + privileges: + type: object + properties: + cluster: + type: array + items: + type: string required: - name - title @@ -2544,7 +2579,7 @@ components: - description - type - categories - - requirement + - conditions - assets - format_version - download @@ -2716,26 +2751,25 @@ components: items: type: string description: list of agent IDs + force: + type: boolean + description: Force upgrade, skipping validation (should be used with caution) required: - agents - version upgrade_agent: title: Upgrade agent - oneOf: - - type: object - properties: - version: - type: string - required: - - version - - type: object - properties: - version: - type: string - source_uri: - type: string - required: - - version + type: object + properties: + version: + type: string + source_uri: + type: string + force: + type: boolean + description: Force upgrade, skipping validation (should be used with caution) + required: + - version agent_action: title: Agent action oneOf: diff --git a/x-pack/plugins/fleet/common/openapi/components/schemas/package_info.yaml b/x-pack/plugins/fleet/common/openapi/components/schemas/package_info.yaml index e61c349f3f490b..80c777a07718cf 100644 --- a/x-pack/plugins/fleet/common/openapi/components/schemas/package_info.yaml +++ b/x-pack/plugins/fleet/common/openapi/components/schemas/package_info.yaml @@ -7,6 +7,20 @@ properties: type: string version: type: string + release: + type: string + enum: + - experimental + - beta + - ga + source: + type: object + properties: + license: + type: string + enum: + - Apache-2.0 + - Elastic-2.0 readme: type: string description: @@ -17,21 +31,24 @@ properties: type: array items: type: string - requirement: - oneOf: - - properties: - kibana: - type: object - properties: - versions: - type: string - - properties: - elasticsearch: - type: object - properties: - versions: - type: string + conditions: type: object + properties: + kibana: + type: object + properties: + versions: + type: string + elasticsearch: + type: object + properties: + subscription: + type: string + enum: + - basic + - gold + - platinum + - enterprise screenshots: type: array items: @@ -102,6 +119,16 @@ properties: type: string path: type: string + elasticsearch: + type: object + properties: + privileges: + type: object + properties: + cluster: + type: array + items: + type: string required: - name - title @@ -109,7 +136,7 @@ required: - description - type - categories - - requirement + - conditions - assets - format_version - download diff --git a/x-pack/plugins/fleet/common/openapi/paths/epm@packages@{pkg_name}@{pkg_version}.yaml b/x-pack/plugins/fleet/common/openapi/paths/epm@packages@{pkg_name}@{pkg_version}.yaml index 6ef61788acd62d..8164d04fc98f19 100644 --- a/x-pack/plugins/fleet/common/openapi/paths/epm@packages@{pkg_name}@{pkg_version}.yaml +++ b/x-pack/plugins/fleet/common/openapi/paths/epm@packages@{pkg_name}@{pkg_version}.yaml @@ -21,6 +21,14 @@ get: - install_failed - not_installed savedObject: + type: object + latestVersion: + type: string + keepPoliciesUpToDate: + type: boolean + notice: + type: string + licensePath: type: string required: - status From 1e339236bd938b51655745c105eca698da37731b Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 20 Sep 2022 10:35:31 -0700 Subject: [PATCH 09/10] Adjust modal heading --- .../sections/epm/screens/detail/overview/details.tsx | 6 +++++- .../epm/screens/detail/overview/license_modal.tsx | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx index 60e875d6c64ed1..729975e8e8e37e 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/details.tsx @@ -225,7 +225,11 @@ export const Details: React.FC = memo(({ packageInfo }) => { {isLicenseModalOpen && packageInfo.licensePath && ( - + )} diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/license_modal.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/license_modal.tsx index bfae8d6f352342..eafdbfb2debe25 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/license_modal.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/overview/license_modal.tsx @@ -22,11 +22,16 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { sendGetFileByPath, useStartServices } from '../../../../../hooks'; interface Props { + licenseName?: string; licensePath: string; onClose: () => void; } -export const LicenseModal: React.FunctionComponent = ({ licensePath, onClose }) => { +export const LicenseModal: React.FunctionComponent = ({ + licenseName = 'LICENSE.txt', + licensePath, + onClose, +}) => { const { notifications } = useStartServices(); const [licenseText, setLicenseText] = useState(undefined); @@ -38,7 +43,7 @@ export const LicenseModal: React.FunctionComponent = ({ licensePath, onCl } catch (err) { notifications.toasts.addError(err, { title: i18n.translate('xpack.fleet.epm.errorLoadingLicense', { - defaultMessage: 'Error loading LICENSE.txt', + defaultMessage: 'Error loading license information', }), }); } @@ -49,7 +54,7 @@ export const LicenseModal: React.FunctionComponent = ({ licensePath, onCl -

LICENSE.txt

+

{licenseName}

From a335e2bf26d4a381466ae2336f19990ae5595456 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 20 Sep 2022 10:40:45 -0700 Subject: [PATCH 10/10] Add unit test --- .../services/epm/registry/index.test.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts index e9427732d4aef7..ba309a15b04eeb 100644 --- a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts @@ -9,7 +9,12 @@ import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; import { PackageNotFoundError } from '../../../errors'; -import { splitPkgKey, fetchFindLatestPackageOrUndefined, fetchFindLatestPackageOrThrow } from '.'; +import { + splitPkgKey, + fetchFindLatestPackageOrUndefined, + fetchFindLatestPackageOrThrow, + getLicensePath, +} from '.'; const mockLoggerFactory = loggingSystemMock.create(); const mockLogger = mockLoggerFactory.get('mock logger'); @@ -143,3 +148,26 @@ describe('fetch package', () => { }); }); }); + +describe('getLicensePath', () => { + it('returns first license path if found', () => { + const path = getLicensePath([ + '/package/good-1.0.0/NOTICE.txt', + '/package/good-1.0.0/changelog.yml', + '/package/good-1.0.0/manifest.yml', + '/package/good-1.0.0/LICENSE.txt', + '/package/good-1.0.0/docs/README.md', + ]); + expect(path).toEqual('/package/good/1.0.0/LICENSE.txt'); + }); + + it('returns undefined if no license', () => { + const path = getLicensePath([ + '/package/good-1.0.0/NOTICE.txt', + '/package/good-1.0.0/changelog.yml', + '/package/good-1.0.0/manifest.yml', + '/package/good-1.0.0/docs/README.md', + ]); + expect(path).toEqual(undefined); + }); +});