mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Fleet] Install kibana assets when creating package policy in a space where they are not installed (#215023)
This commit is contained in:
parent
9b6d1aa35d
commit
28a27a71d4
12 changed files with 922 additions and 77 deletions
|
@ -27233,6 +27233,196 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/api/fleet/epm/packages/{pkgName}/{pkgVersion}/kibana_assets": {
|
||||
"delete": {
|
||||
"description": "[Required authorization] Route required privileges: ALL of [integrations-all, fleet-agent-policies-all].",
|
||||
"operationId": "delete-fleet-epm-packages-pkgname-pkgversion-kibana-assets",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "A required header to protect against CSRF attacks",
|
||||
"in": "header",
|
||||
"name": "kbn-xsrf",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"example": "true",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "pkgName",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "pkgVersion",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"description": "Generic Error",
|
||||
"properties": {
|
||||
"attributes": {},
|
||||
"error": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorType": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"statusCode": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"message",
|
||||
"attributes"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Delete Kibana assets for a package",
|
||||
"tags": [
|
||||
"Elastic Package Manager (EPM)"
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"description": "[Required authorization] Route required privileges: ALL of [integrations-all, fleet-agent-policies-all].",
|
||||
"operationId": "post-fleet-epm-packages-pkgname-pkgversion-kibana-assets",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "A required header to protect against CSRF attacks",
|
||||
"in": "header",
|
||||
"name": "kbn-xsrf",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"example": "true",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "pkgName",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "pkgVersion",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"nullable": true,
|
||||
"properties": {
|
||||
"force": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"description": "Generic Error",
|
||||
"properties": {
|
||||
"attributes": {},
|
||||
"error": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorType": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"statusCode": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"message",
|
||||
"attributes"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Install Kibana assets for a package",
|
||||
"tags": [
|
||||
"Elastic Package Manager (EPM)"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/fleet/epm/packages/{pkgName}/{pkgVersion}/transforms/authorize": {
|
||||
"post": {
|
||||
"operationId": "post-fleet-epm-packages-pkgname-pkgversion-transforms-authorize",
|
||||
|
|
|
@ -27233,6 +27233,196 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/api/fleet/epm/packages/{pkgName}/{pkgVersion}/kibana_assets": {
|
||||
"delete": {
|
||||
"description": "[Required authorization] Route required privileges: ALL of [integrations-all, fleet-agent-policies-all].",
|
||||
"operationId": "delete-fleet-epm-packages-pkgname-pkgversion-kibana-assets",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "A required header to protect against CSRF attacks",
|
||||
"in": "header",
|
||||
"name": "kbn-xsrf",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"example": "true",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "pkgName",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "pkgVersion",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"description": "Generic Error",
|
||||
"properties": {
|
||||
"attributes": {},
|
||||
"error": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorType": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"statusCode": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"message",
|
||||
"attributes"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Delete Kibana assets for a package",
|
||||
"tags": [
|
||||
"Elastic Package Manager (EPM)"
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"description": "[Required authorization] Route required privileges: ALL of [integrations-all, fleet-agent-policies-all].",
|
||||
"operationId": "post-fleet-epm-packages-pkgname-pkgversion-kibana-assets",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "A required header to protect against CSRF attacks",
|
||||
"in": "header",
|
||||
"name": "kbn-xsrf",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"example": "true",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "pkgName",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "pkgVersion",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"nullable": true,
|
||||
"properties": {
|
||||
"force": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"description": "Generic Error",
|
||||
"properties": {
|
||||
"attributes": {},
|
||||
"error": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorType": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"statusCode": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"message",
|
||||
"attributes"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Install Kibana assets for a package",
|
||||
"tags": [
|
||||
"Elastic Package Manager (EPM)"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/fleet/epm/packages/{pkgName}/{pkgVersion}/transforms/authorize": {
|
||||
"post": {
|
||||
"operationId": "post-fleet-epm-packages-pkgname-pkgversion-transforms-authorize",
|
||||
|
|
|
@ -25410,6 +25410,131 @@ paths:
|
|||
tags:
|
||||
- Elastic Package Manager (EPM)
|
||||
x-beta: true
|
||||
/api/fleet/epm/packages/{pkgName}/{pkgVersion}/kibana_assets:
|
||||
delete:
|
||||
description: '[Required authorization] Route required privileges: ALL of [integrations-all, fleet-agent-policies-all].'
|
||||
operationId: delete-fleet-epm-packages-pkgname-pkgversion-kibana-assets
|
||||
parameters:
|
||||
- description: A required header to protect against CSRF attacks
|
||||
in: header
|
||||
name: kbn-xsrf
|
||||
required: true
|
||||
schema:
|
||||
example: 'true'
|
||||
type: string
|
||||
- in: path
|
||||
name: pkgName
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- in: path
|
||||
name: pkgVersion
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- success
|
||||
'400':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
description: Generic Error
|
||||
type: object
|
||||
properties:
|
||||
attributes: {}
|
||||
error:
|
||||
type: string
|
||||
errorType:
|
||||
type: string
|
||||
message:
|
||||
type: string
|
||||
statusCode:
|
||||
type: number
|
||||
required:
|
||||
- message
|
||||
- attributes
|
||||
summary: Delete Kibana assets for a package
|
||||
tags:
|
||||
- Elastic Package Manager (EPM)
|
||||
x-beta: true
|
||||
post:
|
||||
description: '[Required authorization] Route required privileges: ALL of [integrations-all, fleet-agent-policies-all].'
|
||||
operationId: post-fleet-epm-packages-pkgname-pkgversion-kibana-assets
|
||||
parameters:
|
||||
- description: A required header to protect against CSRF attacks
|
||||
in: header
|
||||
name: kbn-xsrf
|
||||
required: true
|
||||
schema:
|
||||
example: 'true'
|
||||
type: string
|
||||
- in: path
|
||||
name: pkgName
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- in: path
|
||||
name: pkgVersion
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
nullable: true
|
||||
type: object
|
||||
properties:
|
||||
force:
|
||||
type: boolean
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- success
|
||||
'400':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
description: Generic Error
|
||||
type: object
|
||||
properties:
|
||||
attributes: {}
|
||||
error:
|
||||
type: string
|
||||
errorType:
|
||||
type: string
|
||||
message:
|
||||
type: string
|
||||
statusCode:
|
||||
type: number
|
||||
required:
|
||||
- message
|
||||
- attributes
|
||||
summary: Install Kibana assets for a package
|
||||
tags:
|
||||
- Elastic Package Manager (EPM)
|
||||
x-beta: true
|
||||
/api/fleet/epm/packages/{pkgName}/{pkgVersion}/transforms/authorize:
|
||||
post:
|
||||
operationId: post-fleet-epm-packages-pkgname-pkgversion-transforms-authorize
|
||||
|
|
|
@ -27425,6 +27425,129 @@ paths:
|
|||
summary: Get a package file
|
||||
tags:
|
||||
- Elastic Package Manager (EPM)
|
||||
/api/fleet/epm/packages/{pkgName}/{pkgVersion}/kibana_assets:
|
||||
delete:
|
||||
description: '[Required authorization] Route required privileges: ALL of [integrations-all, fleet-agent-policies-all].'
|
||||
operationId: delete-fleet-epm-packages-pkgname-pkgversion-kibana-assets
|
||||
parameters:
|
||||
- description: A required header to protect against CSRF attacks
|
||||
in: header
|
||||
name: kbn-xsrf
|
||||
required: true
|
||||
schema:
|
||||
example: 'true'
|
||||
type: string
|
||||
- in: path
|
||||
name: pkgName
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- in: path
|
||||
name: pkgVersion
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- success
|
||||
'400':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
description: Generic Error
|
||||
type: object
|
||||
properties:
|
||||
attributes: {}
|
||||
error:
|
||||
type: string
|
||||
errorType:
|
||||
type: string
|
||||
message:
|
||||
type: string
|
||||
statusCode:
|
||||
type: number
|
||||
required:
|
||||
- message
|
||||
- attributes
|
||||
summary: Delete Kibana assets for a package
|
||||
tags:
|
||||
- Elastic Package Manager (EPM)
|
||||
post:
|
||||
description: '[Required authorization] Route required privileges: ALL of [integrations-all, fleet-agent-policies-all].'
|
||||
operationId: post-fleet-epm-packages-pkgname-pkgversion-kibana-assets
|
||||
parameters:
|
||||
- description: A required header to protect against CSRF attacks
|
||||
in: header
|
||||
name: kbn-xsrf
|
||||
required: true
|
||||
schema:
|
||||
example: 'true'
|
||||
type: string
|
||||
- in: path
|
||||
name: pkgName
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- in: path
|
||||
name: pkgVersion
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
nullable: true
|
||||
type: object
|
||||
properties:
|
||||
force:
|
||||
type: boolean
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- success
|
||||
'400':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
additionalProperties: false
|
||||
description: Generic Error
|
||||
type: object
|
||||
properties:
|
||||
attributes: {}
|
||||
error:
|
||||
type: string
|
||||
errorType:
|
||||
type: string
|
||||
message:
|
||||
type: string
|
||||
statusCode:
|
||||
type: number
|
||||
required:
|
||||
- message
|
||||
- attributes
|
||||
summary: Install Kibana assets for a package
|
||||
tags:
|
||||
- Elastic Package Manager (EPM)
|
||||
/api/fleet/epm/packages/{pkgName}/{pkgVersion}/transforms/authorize:
|
||||
post:
|
||||
operationId: post-fleet-epm-packages-pkgname-pkgversion-transforms-authorize
|
||||
|
|
|
@ -21,6 +21,7 @@ import type {
|
|||
AssetSOObject,
|
||||
InstallResultStatus,
|
||||
PackageMetadata,
|
||||
InstallationInfo,
|
||||
} from '../models/epm';
|
||||
|
||||
export interface GetCategoriesRequest {
|
||||
|
@ -90,7 +91,7 @@ export interface GetInfoRequest {
|
|||
}
|
||||
|
||||
export interface GetInfoResponse {
|
||||
item: PackageInfo;
|
||||
item: PackageInfo & { installationInfo?: InstallationInfo };
|
||||
metadata?: PackageMetadata;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import React, { useCallback, useState, useEffect, useMemo } from 'react';
|
|||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { EuiSpacer, EuiButtonEmpty, EuiFlexItem, EuiFlexGroup } from '@elastic/eui';
|
||||
import { load } from 'js-yaml';
|
||||
|
||||
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { useConfirmForceInstall } from '../../../../../../../integrations/hooks';
|
||||
|
@ -19,7 +19,12 @@ import { isVerificationError } from '../../../../../../../../services';
|
|||
import type { MultiPageStepLayoutProps } from '../../types';
|
||||
import type { PackagePolicyFormState } from '../../../types';
|
||||
import type { NewPackagePolicy } from '../../../../../../types';
|
||||
import { sendCreatePackagePolicy, useStartServices, useUIExtension } from '../../../../../../hooks';
|
||||
import {
|
||||
sendCreatePackagePolicy,
|
||||
useFleetStatus,
|
||||
useStartServices,
|
||||
useUIExtension,
|
||||
} from '../../../../../../hooks';
|
||||
import type { RequestError } from '../../../../../../hooks';
|
||||
import { Error, ExtensionWrapper } from '../../../../../../components';
|
||||
import { sendGeneratePackagePolicy } from '../../hooks';
|
||||
|
@ -29,6 +34,7 @@ import { validatePackagePolicy, validationHasErrors } from '../../../services';
|
|||
import { NotObscuredByBottomBar } from '..';
|
||||
import { StepConfigurePackagePolicy, StepDefinePackagePolicy } from '../../../components';
|
||||
import { prepareInputPackagePolicyDataset } from '../../../services/prepare_input_pkg_policy_dataset';
|
||||
import { ensurePackageKibanaAssetsInstalled } from '../../../services/ensure_kibana_assets_installed';
|
||||
|
||||
const ExpandableAdvancedSettings: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
|
||||
const [isShowingAdvanced, setIsShowingAdvanced] = useState<boolean>(false);
|
||||
|
@ -83,6 +89,7 @@ export const AddIntegrationPageStep: React.FC<MultiPageStepLayoutProps> = (props
|
|||
const { onNext, onBack, isManaged, setIsManaged, packageInfo, integrationInfo, agentPolicy } =
|
||||
props;
|
||||
|
||||
const { spaceId } = useFleetStatus();
|
||||
const [basePolicyError, setBasePolicyError] = useState<RequestError>();
|
||||
|
||||
const { notifications } = useStartServices();
|
||||
|
@ -141,22 +148,34 @@ export const AddIntegrationPageStep: React.FC<MultiPageStepLayoutProps> = (props
|
|||
);
|
||||
|
||||
// Save package policy
|
||||
const savePackagePolicy = async ({
|
||||
newPackagePolicy,
|
||||
force,
|
||||
}: {
|
||||
newPackagePolicy: NewPackagePolicy;
|
||||
force?: boolean;
|
||||
}) => {
|
||||
setFormState('LOADING');
|
||||
const { policy, forceCreateNeeded } = await prepareInputPackagePolicyDataset(newPackagePolicy);
|
||||
const result = await sendCreatePackagePolicy({
|
||||
...policy,
|
||||
force: forceCreateNeeded || force,
|
||||
});
|
||||
setFormState('SUBMITTED');
|
||||
return result;
|
||||
};
|
||||
const savePackagePolicy = useCallback(
|
||||
async ({
|
||||
newPackagePolicy,
|
||||
force,
|
||||
}: {
|
||||
newPackagePolicy: NewPackagePolicy;
|
||||
force?: boolean;
|
||||
}) => {
|
||||
setFormState('LOADING');
|
||||
const { policy, forceCreateNeeded } = await prepareInputPackagePolicyDataset(
|
||||
newPackagePolicy
|
||||
);
|
||||
const result = await sendCreatePackagePolicy({
|
||||
...policy,
|
||||
force: forceCreateNeeded || force,
|
||||
});
|
||||
setFormState('SUBMITTED');
|
||||
if (!result.error && result.data?.item.package)
|
||||
await ensurePackageKibanaAssetsInstalled({
|
||||
currentSpaceId: spaceId ?? DEFAULT_SPACE_ID,
|
||||
pkgName: result.data.item.package.name,
|
||||
pkgVersion: result.data.item.package.version,
|
||||
toasts: notifications.toasts,
|
||||
});
|
||||
return result;
|
||||
},
|
||||
[notifications.toasts, spaceId]
|
||||
);
|
||||
|
||||
const onSubmit = useCallback(
|
||||
async ({ force = false }: { force?: boolean } = {}) => {
|
||||
|
@ -190,6 +209,7 @@ export const AddIntegrationPageStep: React.FC<MultiPageStepLayoutProps> = (props
|
|||
},
|
||||
[
|
||||
validationResults,
|
||||
savePackagePolicy,
|
||||
formState,
|
||||
packagePolicy,
|
||||
notifications.toasts,
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* 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 { toastsServiceMock } from '@kbn/core-notifications-browser-mocks/src/toasts_service.mock';
|
||||
|
||||
import {
|
||||
sendGetPackageInfoByKeyForRq,
|
||||
sendInstallKibanaAssetsForRq,
|
||||
} from '../../../../../../hooks';
|
||||
|
||||
import { ensurePackageKibanaAssetsInstalled } from './ensure_kibana_assets_installed';
|
||||
|
||||
jest.mock('../../../../../../hooks');
|
||||
|
||||
describe('ensurePackageKibanaAssetsInstalled', () => {
|
||||
beforeEach(() => {
|
||||
jest.mocked(sendInstallKibanaAssetsForRq).mockReset();
|
||||
});
|
||||
it('install assets if not installed', async () => {
|
||||
jest.mocked(sendGetPackageInfoByKeyForRq).mockResolvedValue({
|
||||
item: {
|
||||
installationInfo: {
|
||||
name: 'nginx',
|
||||
version: '1.25.1',
|
||||
installed_kibana_space_id: 'default',
|
||||
},
|
||||
},
|
||||
} as any);
|
||||
|
||||
const toasts = toastsServiceMock.createStartContract();
|
||||
|
||||
await ensurePackageKibanaAssetsInstalled({
|
||||
currentSpaceId: 'test',
|
||||
pkgName: 'nginx',
|
||||
pkgVersion: '1.25.1',
|
||||
toasts,
|
||||
});
|
||||
|
||||
expect(sendInstallKibanaAssetsForRq).toBeCalledWith({
|
||||
pkgName: 'nginx',
|
||||
pkgVersion: '1.25.1',
|
||||
});
|
||||
|
||||
expect(toasts.addSuccess).toBeCalled();
|
||||
});
|
||||
|
||||
it('does nothing if assets are already installed', async () => {
|
||||
jest.mocked(sendGetPackageInfoByKeyForRq).mockResolvedValue({
|
||||
item: {
|
||||
installationInfo: {
|
||||
name: 'nginx',
|
||||
version: '1.25.1',
|
||||
installed_kibana_space_id: 'default',
|
||||
additional_spaces_installed_kibana: {
|
||||
test: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
} as any);
|
||||
|
||||
const toasts = toastsServiceMock.createStartContract();
|
||||
|
||||
await ensurePackageKibanaAssetsInstalled({
|
||||
currentSpaceId: 'test',
|
||||
pkgName: 'nginx',
|
||||
pkgVersion: '1.25.1',
|
||||
toasts,
|
||||
});
|
||||
|
||||
expect(sendInstallKibanaAssetsForRq).not.toBeCalled();
|
||||
expect(toasts.addSuccess).not.toBeCalled();
|
||||
expect(toasts.addError).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('show an error toast if install assets failed', async () => {
|
||||
jest.mocked(sendGetPackageInfoByKeyForRq).mockResolvedValue({
|
||||
item: {
|
||||
installationInfo: {
|
||||
name: 'nginx',
|
||||
version: '1.25.1',
|
||||
installed_kibana_space_id: 'default',
|
||||
},
|
||||
},
|
||||
} as any);
|
||||
|
||||
jest.mocked(sendInstallKibanaAssetsForRq).mockRejectedValue(new Error('test123'));
|
||||
|
||||
const toasts = toastsServiceMock.createStartContract();
|
||||
|
||||
await ensurePackageKibanaAssetsInstalled({
|
||||
currentSpaceId: 'test',
|
||||
pkgName: 'nginx',
|
||||
pkgVersion: '1.25.1',
|
||||
toasts,
|
||||
});
|
||||
|
||||
expect(toasts.addSuccess).not.toBeCalled();
|
||||
expect(toasts.addError).toBeCalled();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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 type { IToasts } from '@kbn/core/public';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
|
||||
|
||||
import {
|
||||
sendGetPackageInfoByKeyForRq,
|
||||
sendInstallKibanaAssetsForRq,
|
||||
} from '../../../../../../hooks';
|
||||
|
||||
export async function ensurePackageKibanaAssetsInstalled({
|
||||
currentSpaceId,
|
||||
pkgName,
|
||||
pkgVersion,
|
||||
toasts,
|
||||
}: {
|
||||
currentSpaceId: string;
|
||||
pkgName: string;
|
||||
pkgVersion: string;
|
||||
toasts: IToasts;
|
||||
}) {
|
||||
try {
|
||||
const packageInfo = await sendGetPackageInfoByKeyForRq(pkgName, pkgVersion, {
|
||||
prerelease: true,
|
||||
});
|
||||
|
||||
const installationInfo = packageInfo.item.installationInfo;
|
||||
if (!installationInfo) {
|
||||
// Skip if package is not installed
|
||||
return;
|
||||
}
|
||||
|
||||
const kibanaAssetsSpaces = [
|
||||
installationInfo.installed_kibana_space_id ?? DEFAULT_SPACE_ID,
|
||||
...Object.keys(installationInfo.additional_spaces_installed_kibana ?? {}),
|
||||
];
|
||||
if (!kibanaAssetsSpaces.includes(currentSpaceId)) {
|
||||
await sendInstallKibanaAssetsForRq({
|
||||
pkgName: installationInfo.name,
|
||||
pkgVersion: installationInfo.version,
|
||||
});
|
||||
toasts.addSuccess(
|
||||
i18n.translate('xpack.fleet.installKibanaAssets.successNotificationTitle', {
|
||||
defaultMessage: 'Successfully installed kibana assets',
|
||||
})
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
toasts.addError(err, {
|
||||
title: i18n.translate('xpack.fleet.installKibanaAssets.errorNotificationTitle', {
|
||||
defaultMessage: 'Unable to install kibana assets',
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
|
@ -8,8 +8,8 @@
|
|||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { load } from 'js-yaml';
|
||||
|
||||
import { isEqual } from 'lodash';
|
||||
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
|
||||
|
||||
import { useSpaceSettingsContext } from '../../../../../../../hooks/use_space_settings_context';
|
||||
import {
|
||||
|
@ -28,6 +28,7 @@ import {
|
|||
sendBulkInstallPackages,
|
||||
sendGetPackagePolicies,
|
||||
useMultipleAgentPolicies,
|
||||
useFleetStatus,
|
||||
} from '../../../../../hooks';
|
||||
import { isVerificationError, packageToPackagePolicy } from '../../../../../services';
|
||||
import {
|
||||
|
@ -49,8 +50,8 @@ import {
|
|||
getCloudFormationPropsFromPackagePolicy,
|
||||
getCloudShellUrlFromPackagePolicy,
|
||||
} from '../../../../../../../components/cloud_security_posture/services';
|
||||
|
||||
import { AGENTLESS_DISABLED_INPUTS } from '../../../../../../../../common/constants';
|
||||
import { ensurePackageKibanaAssetsInstalled } from '../../services/ensure_kibana_assets_installed';
|
||||
|
||||
import { useAgentless, useSetupTechnology } from './setup_technology';
|
||||
|
||||
|
@ -160,6 +161,7 @@ export function useOnSubmit({
|
|||
setSelectedPolicyTab: (tab: SelectedPolicyTab) => void;
|
||||
}) {
|
||||
const { notifications } = useStartServices();
|
||||
const { spaceId } = useFleetStatus();
|
||||
const confirmForceInstall = useConfirmForceInstall();
|
||||
const spaceSettings = useSpaceSettingsContext();
|
||||
const { canUseMultipleAgentPolicies } = useMultipleAgentPolicies();
|
||||
|
@ -413,6 +415,15 @@ export function useOnSubmit({
|
|||
force: forceInstall,
|
||||
});
|
||||
|
||||
if (!error && data?.item.package) {
|
||||
await ensurePackageKibanaAssetsInstalled({
|
||||
currentSpaceId: spaceId ?? DEFAULT_SPACE_ID,
|
||||
pkgName: data.item.package.name,
|
||||
pkgVersion: data.item.package.version,
|
||||
toasts: notifications.toasts,
|
||||
});
|
||||
}
|
||||
|
||||
const hasAzureArmTemplate = data?.item
|
||||
? getAzureArmPropsFromPackagePolicy(data.item).templateUrl
|
||||
: false;
|
||||
|
@ -510,6 +521,7 @@ export function useOnSubmit({
|
|||
},
|
||||
[
|
||||
formState,
|
||||
spaceId,
|
||||
hasErrors,
|
||||
agentCount,
|
||||
isAgentlessIntegration,
|
||||
|
|
|
@ -209,6 +209,9 @@ export const useGetPackageVerificationKeyId = () => {
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated use sendGetPackageInfoByKeyForRq instead
|
||||
*/
|
||||
export const sendGetPackageInfoByKey = (
|
||||
pkgName: string,
|
||||
pkgVersion?: string,
|
||||
|
@ -226,6 +229,23 @@ export const sendGetPackageInfoByKey = (
|
|||
});
|
||||
};
|
||||
|
||||
export const sendGetPackageInfoByKeyForRq = (
|
||||
pkgName: string,
|
||||
pkgVersion?: string,
|
||||
options?: {
|
||||
ignoreUnverified?: boolean;
|
||||
prerelease?: boolean;
|
||||
full?: boolean;
|
||||
}
|
||||
) => {
|
||||
return sendRequestForRq<GetInfoResponse>({
|
||||
path: epmRouteService.getInfoPath(pkgName, pkgVersion),
|
||||
method: 'get',
|
||||
version: API_VERSIONS.public.v1,
|
||||
query: options,
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetFileByPath = (filePath: string) => {
|
||||
return useRequest<string>({
|
||||
path: epmRouteService.getFilePath(filePath),
|
||||
|
@ -338,17 +358,20 @@ export const useInstallKibanaAssetsMutation = () => {
|
|||
|
||||
return useMutation<any, RequestError, InstallKibanaAssetsArgs>({
|
||||
mutationFn: ({ pkgName, pkgVersion }: InstallKibanaAssetsArgs) =>
|
||||
sendRequestForRq({
|
||||
path: epmRouteService.getInstallKibanaAssetsPath(pkgName, pkgVersion),
|
||||
method: 'post',
|
||||
version: API_VERSIONS.public.v1,
|
||||
}),
|
||||
sendInstallKibanaAssetsForRq({ pkgName, pkgVersion }),
|
||||
onSuccess: (data, { pkgName, pkgVersion }) => {
|
||||
return queryClient.invalidateQueries([pkgName, pkgVersion]);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const sendInstallKibanaAssetsForRq = ({ pkgName, pkgVersion }: InstallKibanaAssetsArgs) =>
|
||||
sendRequestForRq({
|
||||
path: epmRouteService.getInstallKibanaAssetsPath(pkgName, pkgVersion),
|
||||
method: 'post',
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
|
||||
export const sendUpdatePackage = (
|
||||
pkgName: string,
|
||||
pkgVersion: string,
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
import type { RouteSecurity } from '@kbn/core-http-server';
|
||||
|
||||
import { parseExperimentalConfigValue } from '../../../common/experimental_features';
|
||||
import { API_VERSIONS } from '../../../common/constants';
|
||||
|
||||
import type { FleetAuthz } from '../../../common';
|
||||
|
@ -120,8 +119,6 @@ export const READ_PACKAGE_INFO_SECURITY: RouteSecurity = {
|
|||
};
|
||||
|
||||
export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType) => {
|
||||
const experimentalFeatures = parseExperimentalConfigValue(config.enableExperimental);
|
||||
|
||||
router.versioned
|
||||
.get({
|
||||
path: EPM_API_ROUTES.CATEGORIES_PATTERN,
|
||||
|
@ -395,61 +392,59 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
|
|||
installPackageFromRegistryHandler
|
||||
);
|
||||
|
||||
if (experimentalFeatures.useSpaceAwareness) {
|
||||
router.versioned
|
||||
.post({
|
||||
path: EPM_API_ROUTES.INSTALL_KIBANA_ASSETS_PATTERN,
|
||||
security: INSTALL_PACKAGES_SECURITY,
|
||||
summary: `Install Kibana assets for a package`,
|
||||
options: {
|
||||
tags: ['oas-tag:Elastic Package Manager (EPM)'],
|
||||
},
|
||||
})
|
||||
.addVersion(
|
||||
{
|
||||
version: API_VERSIONS.public.v1,
|
||||
validate: {
|
||||
request: InstallKibanaAssetsRequestSchema,
|
||||
response: {
|
||||
200: {
|
||||
body: () => InstallKibanaAssetsResponseSchema,
|
||||
},
|
||||
400: {
|
||||
body: genericErrorResponse,
|
||||
},
|
||||
router.versioned
|
||||
.post({
|
||||
path: EPM_API_ROUTES.INSTALL_KIBANA_ASSETS_PATTERN,
|
||||
security: INSTALL_PACKAGES_SECURITY,
|
||||
summary: `Install Kibana assets for a package`,
|
||||
options: {
|
||||
tags: ['oas-tag:Elastic Package Manager (EPM)'],
|
||||
},
|
||||
})
|
||||
.addVersion(
|
||||
{
|
||||
version: API_VERSIONS.public.v1,
|
||||
validate: {
|
||||
request: InstallKibanaAssetsRequestSchema,
|
||||
response: {
|
||||
200: {
|
||||
body: () => InstallKibanaAssetsResponseSchema,
|
||||
},
|
||||
400: {
|
||||
body: genericErrorResponse,
|
||||
},
|
||||
},
|
||||
},
|
||||
installPackageKibanaAssetsHandler
|
||||
);
|
||||
},
|
||||
installPackageKibanaAssetsHandler
|
||||
);
|
||||
|
||||
router.versioned
|
||||
.delete({
|
||||
path: EPM_API_ROUTES.DELETE_KIBANA_ASSETS_PATTERN,
|
||||
security: INSTALL_PACKAGES_SECURITY,
|
||||
summary: `Delete Kibana assets for a package`,
|
||||
options: {
|
||||
tags: ['oas-tag:Elastic Package Manager (EPM)'],
|
||||
},
|
||||
})
|
||||
.addVersion(
|
||||
{
|
||||
version: API_VERSIONS.public.v1,
|
||||
validate: {
|
||||
request: DeleteKibanaAssetsRequestSchema,
|
||||
response: {
|
||||
200: {
|
||||
body: () => InstallKibanaAssetsResponseSchema,
|
||||
},
|
||||
400: {
|
||||
body: genericErrorResponse,
|
||||
},
|
||||
router.versioned
|
||||
.delete({
|
||||
path: EPM_API_ROUTES.DELETE_KIBANA_ASSETS_PATTERN,
|
||||
security: INSTALL_PACKAGES_SECURITY,
|
||||
summary: `Delete Kibana assets for a package`,
|
||||
options: {
|
||||
tags: ['oas-tag:Elastic Package Manager (EPM)'],
|
||||
},
|
||||
})
|
||||
.addVersion(
|
||||
{
|
||||
version: API_VERSIONS.public.v1,
|
||||
validate: {
|
||||
request: DeleteKibanaAssetsRequestSchema,
|
||||
response: {
|
||||
200: {
|
||||
body: () => InstallKibanaAssetsResponseSchema,
|
||||
},
|
||||
400: {
|
||||
body: genericErrorResponse,
|
||||
},
|
||||
},
|
||||
},
|
||||
deletePackageKibanaAssetsHandler
|
||||
);
|
||||
}
|
||||
},
|
||||
deletePackageKibanaAssetsHandler
|
||||
);
|
||||
|
||||
router.versioned
|
||||
.post({
|
||||
|
|
|
@ -119,5 +119,6 @@
|
|||
"@kbn/field-formats-plugin",
|
||||
"@kbn/core-security-server",
|
||||
"@kbn/core-http-server-utils",
|
||||
"@kbn/core-notifications-browser-mocks",
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue