Restrict custom registry URL (#64374)
This commit is contained in:
parent
18d1af24d4
commit
a00051f914
8 changed files with 51 additions and 13 deletions
|
@ -6,3 +6,4 @@
|
|||
|
||||
export const PACKAGES_SAVED_OBJECT_TYPE = 'epm-package';
|
||||
export const INDEX_PATTERN_SAVED_OBJECT_TYPE = 'index-pattern';
|
||||
export const DEFAULT_REGISTRY_URL = 'https://epr.elastic.co';
|
||||
|
|
|
@ -10,7 +10,7 @@ export interface IngestManagerConfigType {
|
|||
enabled: boolean;
|
||||
epm: {
|
||||
enabled: boolean;
|
||||
registryUrl: string;
|
||||
registryUrl?: string;
|
||||
};
|
||||
fleet: {
|
||||
enabled: boolean;
|
||||
|
|
|
@ -33,4 +33,5 @@ export {
|
|||
// Defaults
|
||||
DEFAULT_AGENT_CONFIG,
|
||||
DEFAULT_OUTPUT,
|
||||
DEFAULT_REGISTRY_URL,
|
||||
} from '../../common';
|
||||
|
|
|
@ -22,7 +22,7 @@ export const config = {
|
|||
enabled: schema.boolean({ defaultValue: false }),
|
||||
epm: schema.object({
|
||||
enabled: schema.boolean({ defaultValue: true }),
|
||||
registryUrl: schema.uri({ defaultValue: 'https://epr-staging.elastic.co' }),
|
||||
registryUrl: schema.maybe(schema.uri()),
|
||||
}),
|
||||
fleet: schema.object({
|
||||
enabled: schema.boolean({ defaultValue: true }),
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
PluginInitializerContext,
|
||||
SavedObjectsServiceStart,
|
||||
} from 'kibana/server';
|
||||
import { LicensingPluginSetup } from '../../licensing/server';
|
||||
import { LicensingPluginSetup, ILicense } from '../../licensing/server';
|
||||
import {
|
||||
EncryptedSavedObjectsPluginStart,
|
||||
EncryptedSavedObjectsPluginSetup,
|
||||
|
@ -42,8 +42,13 @@ import {
|
|||
} from './routes';
|
||||
|
||||
import { IngestManagerConfigType } from '../common';
|
||||
import { appContextService, ESIndexPatternSavedObjectService } from './services';
|
||||
import { ESIndexPatternService, AgentService } from './services';
|
||||
import {
|
||||
appContextService,
|
||||
licenseService,
|
||||
ESIndexPatternSavedObjectService,
|
||||
ESIndexPatternService,
|
||||
AgentService,
|
||||
} from './services';
|
||||
import { getAgentStatusById } from './services/agents';
|
||||
|
||||
export interface IngestManagerSetupDeps {
|
||||
|
@ -90,6 +95,7 @@ export class IngestManagerPlugin
|
|||
IngestManagerSetupDeps,
|
||||
IngestManagerStartDeps
|
||||
> {
|
||||
private licensing$!: Observable<ILicense>;
|
||||
private config$: Observable<IngestManagerConfigType>;
|
||||
private security: SecurityPluginSetup | undefined;
|
||||
|
||||
|
@ -98,6 +104,7 @@ export class IngestManagerPlugin
|
|||
}
|
||||
|
||||
public async setup(core: CoreSetup, deps: IngestManagerSetupDeps) {
|
||||
this.licensing$ = deps.licensing.license$;
|
||||
if (deps.security) {
|
||||
this.security = deps.security;
|
||||
}
|
||||
|
@ -173,6 +180,7 @@ export class IngestManagerPlugin
|
|||
config$: this.config$,
|
||||
savedObjects: core.savedObjects,
|
||||
});
|
||||
licenseService.start(this.licensing$);
|
||||
return {
|
||||
esIndexPatternService: new ESIndexPatternSavedObjectService(),
|
||||
agentService: {
|
||||
|
@ -183,5 +191,6 @@ export class IngestManagerPlugin
|
|||
|
||||
public async stop() {
|
||||
appContextService.stop();
|
||||
licenseService.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ import {
|
|||
RegistrySearchResults,
|
||||
RegistrySearchResult,
|
||||
} from '../../../types';
|
||||
import { appContextService } from '../../';
|
||||
import { cacheGet, cacheSet } from './cache';
|
||||
import { ArchiveEntry, untarBuffer } from './extract';
|
||||
import { fetchUrl, getResponse, getResponseStream } from './requests';
|
||||
import { streamToBuffer } from './streams';
|
||||
import { getRegistryUrl } from './registry_url';
|
||||
|
||||
export { ArchiveEntry } from './extract';
|
||||
|
||||
|
@ -32,7 +32,7 @@ export const pkgToPkgKey = ({ name, version }: { name: string; version: string }
|
|||
`${name}-${version}`;
|
||||
|
||||
export async function fetchList(params?: SearchParams): Promise<RegistrySearchResults> {
|
||||
const registryUrl = appContextService.getConfig()?.epm.registryUrl;
|
||||
const registryUrl = getRegistryUrl();
|
||||
const url = new URL(`${registryUrl}/search`);
|
||||
if (params && params.category) {
|
||||
url.searchParams.set('category', params.category);
|
||||
|
@ -45,7 +45,7 @@ export async function fetchFindLatestPackage(
|
|||
packageName: string,
|
||||
internal: boolean = true
|
||||
): Promise<RegistrySearchResult> {
|
||||
const registryUrl = appContextService.getConfig()?.epm.registryUrl;
|
||||
const registryUrl = getRegistryUrl();
|
||||
const url = new URL(`${registryUrl}/search?package=${packageName}&internal=${internal}`);
|
||||
const res = await fetchUrl(url.toString());
|
||||
const searchResults = JSON.parse(res);
|
||||
|
@ -57,17 +57,17 @@ export async function fetchFindLatestPackage(
|
|||
}
|
||||
|
||||
export async function fetchInfo(pkgName: string, pkgVersion: string): Promise<RegistryPackage> {
|
||||
const registryUrl = appContextService.getConfig()?.epm.registryUrl;
|
||||
const registryUrl = getRegistryUrl();
|
||||
return fetchUrl(`${registryUrl}/package/${pkgName}/${pkgVersion}`).then(JSON.parse);
|
||||
}
|
||||
|
||||
export async function fetchFile(filePath: string): Promise<Response> {
|
||||
const registryUrl = appContextService.getConfig()?.epm.registryUrl;
|
||||
const registryUrl = getRegistryUrl();
|
||||
return getResponse(`${registryUrl}${filePath}`);
|
||||
}
|
||||
|
||||
export async function fetchCategories(): Promise<CategorySummaryList> {
|
||||
const registryUrl = appContextService.getConfig()?.epm.registryUrl;
|
||||
const registryUrl = getRegistryUrl();
|
||||
return fetchUrl(`${registryUrl}/categories`).then(JSON.parse);
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ async function getOrFetchArchiveBuffer(pkgName: string, pkgVersion: string): Pro
|
|||
|
||||
async function fetchArchiveBuffer(pkgName: string, pkgVersion: string): Promise<Buffer> {
|
||||
const { download: archivePath } = await fetchInfo(pkgName, pkgVersion);
|
||||
const registryUrl = appContextService.getConfig()?.epm.registryUrl;
|
||||
const registryUrl = getRegistryUrl();
|
||||
return getResponseStream(`${registryUrl}${archivePath}`).then(streamToBuffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 { DEFAULT_REGISTRY_URL } from '../../../constants';
|
||||
import { appContextService, licenseService } from '../../';
|
||||
|
||||
export const getRegistryUrl = (): string => {
|
||||
const license = licenseService.getLicenseInformation();
|
||||
const customUrl = appContextService.getConfig()?.epm.registryUrl;
|
||||
|
||||
if (
|
||||
customUrl &&
|
||||
license &&
|
||||
license.isAvailable &&
|
||||
license.hasAtLeast('gold') &&
|
||||
license.isActive
|
||||
) {
|
||||
return customUrl;
|
||||
}
|
||||
|
||||
return DEFAULT_REGISTRY_URL;
|
||||
};
|
|
@ -6,7 +6,6 @@
|
|||
import { SavedObjectsClientContract } from 'kibana/server';
|
||||
import { AgentStatus } from '../../common/types/models';
|
||||
|
||||
export { appContextService } from './app_context';
|
||||
export { ESIndexPatternSavedObjectService } from './es_index_pattern';
|
||||
|
||||
/**
|
||||
|
@ -36,3 +35,7 @@ export interface AgentService {
|
|||
export { datasourceService } from './datasource';
|
||||
export { agentConfigService } from './agent_config';
|
||||
export { outputService } from './output';
|
||||
|
||||
// Plugin services
|
||||
export { appContextService } from './app_context';
|
||||
export { licenseService } from './license';
|
||||
|
|
Loading…
Reference in a new issue