mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Fixed comments for PR
This commit is contained in:
parent
7395ff4e71
commit
47b06bd894
5 changed files with 45 additions and 14 deletions
|
@ -32,6 +32,7 @@ import { parseTestFileConfig, retrieveIntegrations } from './utils';
|
|||
import { prefixedOutputLogger } from '../endpoint/common/utils';
|
||||
|
||||
import type { ProductType, Credentials, ProjectHandler } from './project_handler/project_handler';
|
||||
import { Environment } from './project_handler/project_handler';
|
||||
import { CloudHandler } from './project_handler/cloud_project_handler';
|
||||
import { ProxyHandler } from './project_handler/proxy_project_handler';
|
||||
|
||||
|
@ -58,12 +59,12 @@ const PROVIDERS = Object.freeze({
|
|||
providerName: 'cloud-basic',
|
||||
});
|
||||
|
||||
export const getApiKeyFromElasticCloudJsonFile = (environment: string): string | undefined => {
|
||||
export const getApiKeyFromElasticCloudJsonFile = (environment: Environment): string | undefined => {
|
||||
const userHomeDir = os.homedir();
|
||||
try {
|
||||
const jsonString = fs.readFileSync(path.join(userHomeDir, '.elastic/cloud.json'), 'utf-8');
|
||||
const jsonData = JSON.parse(jsonString);
|
||||
return environment === 'prod' ? jsonData.api_key.prod : jsonData.api_key.qa;
|
||||
return environment === Environment.Production ? jsonData.api_key.prod : jsonData.api_key.qa;
|
||||
} catch (e) {
|
||||
log.info('API KEY could not be found in .elastic/cloud.json');
|
||||
}
|
||||
|
@ -244,18 +245,29 @@ const getProductTypes = (
|
|||
return productTypes;
|
||||
};
|
||||
|
||||
/**
|
||||
* Testing against MKI is only enabled for QA. So Environment (process.env.ENVIRONMENT) should only reflect to QA
|
||||
* environment anyway. There is only one scenario that would potentially require production so far which is testing
|
||||
* against the already deployed production image for multiple project regions (aws-eu-west "aws-us-west-2",
|
||||
* "aws-eu-west-1" and "aws-ap-southeast-1". The Production testing is not applicable to Quality Gates or any scheduled
|
||||
* pipeline execution or release process. It runs only on Demand, required by the Product Team. Also the functionality to
|
||||
* execute some tests against a production project is now introduced for future use.
|
||||
*/
|
||||
export const cli = () => {
|
||||
run(
|
||||
async (context) => {
|
||||
const environment = process.env.ENVIRONMENT ?? : 'qa';
|
||||
const environment = process.env.ENVIRONMENT
|
||||
? (process.env.ENVIRONMENT.toLowerCase() as Environment)
|
||||
: Environment.QA;
|
||||
|
||||
const PROXY_URL = process.env.PROXY_URL;
|
||||
const PROXY_SECRET = process.env.PROXY_SECRET;
|
||||
const PROXY_CLIENT_ID = process.env.PROXY_CLIENT_ID;
|
||||
|
||||
const apiKeyFromCloudJsonFile = getApiKeyFromElasticCloudJsonFile(environment);
|
||||
// Checking if API key is either provided via env variable or in ~/.elastic.cloud.json
|
||||
// This works for either local executions or fallback in case proxy service is unavailable.
|
||||
if (!process.env.CLOUD_API_KEY && !getApiKeyFromElasticCloudJsonFile(environment)) {
|
||||
if (!process.env.CLOUD_API_KEY && !apiKeyFromCloudJsonFile) {
|
||||
log.error(
|
||||
'The API key for the environment needs to be provided with the env var CLOUD_API_KEY.'
|
||||
);
|
||||
|
@ -267,7 +279,7 @@ export const cli = () => {
|
|||
}
|
||||
const API_KEY = process.env.CLOUD_API_KEY
|
||||
? process.env.CLOUD_API_KEY
|
||||
: getApiKeyFromElasticCloudJsonFile(environment);
|
||||
: apiKeyFromCloudJsonFile;
|
||||
|
||||
log.info(`PROXY_URL is defined : ${PROXY_URL !== undefined}`);
|
||||
log.info(`PROXY_CLIENT_ID is defined : ${PROXY_CLIENT_ID !== undefined}`);
|
||||
|
@ -279,8 +291,9 @@ export const cli = () => {
|
|||
PROXY_URL &&
|
||||
PROXY_CLIENT_ID &&
|
||||
PROXY_SECRET &&
|
||||
environment.toUpperCase() !== 'prod'.toUpperCase() &&
|
||||
environment !== Environment.Production &&
|
||||
(await proxyHealthcheck(PROXY_URL));
|
||||
|
||||
if (proxyServiceUse) {
|
||||
log.info('Proxy service is up and running, so the tests will run using the proxyHandler.');
|
||||
cloudHandler = new ProxyHandler(PROXY_URL, PROXY_CLIENT_ID, PROXY_SECRET);
|
||||
|
|
|
@ -31,10 +31,10 @@ export class CloudHandler extends ProjectHandler {
|
|||
productTypes?: ProductType[],
|
||||
commit?: string
|
||||
): Promise<Project | undefined> {
|
||||
const region = process.env.REGION ? process.env.REGION : DEFAULT_REGION;
|
||||
const regionId = process.env.REGION ?? DEFAULT_REGION;
|
||||
const body: CreateProjectRequestBody = {
|
||||
name: projectName,
|
||||
region_id: region,
|
||||
region_id: regionId,
|
||||
};
|
||||
|
||||
if (productTypes) {
|
||||
|
|
|
@ -47,6 +47,11 @@ export interface Credentials {
|
|||
password: string;
|
||||
}
|
||||
|
||||
export enum Environment {
|
||||
Production = 'prod',
|
||||
QA = 'qa',
|
||||
}
|
||||
|
||||
export class ProjectHandler {
|
||||
private readonly DEFAULT_ERROR_MSG: string =
|
||||
'The method needs to be overriden when the class is inherited!';
|
||||
|
|
|
@ -31,10 +31,10 @@ export class ProxyHandler extends ProjectHandler {
|
|||
productTypes?: ProductType[],
|
||||
commit?: string
|
||||
): Promise<Project | undefined> {
|
||||
const region = process.env.REGION ? process.env.REGION : DEFAULT_REGION;
|
||||
const regionId = process.env.REGION ?? DEFAULT_REGION;
|
||||
const body: CreateProjectRequestBody = {
|
||||
name: projectName,
|
||||
region_id: region,
|
||||
region_id: regionId,
|
||||
};
|
||||
|
||||
if (productTypes) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import type {
|
|||
ProductType,
|
||||
ProjectHandler,
|
||||
} from '@kbn/security-solution-plugin/scripts/run_cypress/project_handler/project_handler';
|
||||
import { Environment } from '@kbn/security-solution-plugin/scripts/run_cypress/project_handler/project_handler';
|
||||
import { CloudHandler } from '@kbn/security-solution-plugin/scripts/run_cypress/project_handler/cloud_project_handler';
|
||||
import { ProxyHandler } from '@kbn/security-solution-plugin/scripts/run_cypress/project_handler/proxy_project_handler';
|
||||
import {
|
||||
|
@ -82,6 +83,14 @@ async function parseProductTypes(log: ToolingLog): Promise<ProductType[] | undef
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing against MKI is only enabled for QA. So Environment (process.env.ENVIRONMENT) should only reflect to QA
|
||||
* environment anyway. There is only one scenario that would potentially require production so far which is testing
|
||||
* against the already deployed production image for multiple project regions (aws-eu-west "aws-us-west-2",
|
||||
* "aws-eu-west-1" and "aws-ap-southeast-1". The Production testing is not applicable to Quality Gates or any scheduled
|
||||
* pipeline execution or release process. It runs only on Demand, required by the Product Team. Also the functionality to
|
||||
* execute some tests against a production project is now introduced for future use.
|
||||
*/
|
||||
export const cli = () => {
|
||||
run(
|
||||
async (context) => {
|
||||
|
@ -89,15 +98,18 @@ export const cli = () => {
|
|||
level: 'info',
|
||||
writeTo: process.stdout,
|
||||
});
|
||||
const environment = process.env.ENVIRONMENT ? `${process.env.ENVIRONMENT}` : 'qa';
|
||||
const environment = process.env.ENVIRONMENT
|
||||
? (process.env.ENVIRONMENT.toLowerCase() as Environment)
|
||||
: Environment.QA;
|
||||
|
||||
const PROXY_URL = process.env.PROXY_URL ? process.env.PROXY_URL : undefined;
|
||||
const PROXY_SECRET = process.env.PROXY_SECRET ? process.env.PROXY_SECRET : undefined;
|
||||
const PROXY_CLIENT_ID = process.env.PROXY_CLIENT_ID ? process.env.PROXY_CLIENT_ID : undefined;
|
||||
|
||||
const apiKeyFromCloudJsonFile = getApiKeyFromElasticCloudJsonFile(environment);
|
||||
// Checking if API key is either provided via env variable or in ~/.elastic.cloud.json
|
||||
// This works for either local executions or fallback in case proxy service is unavailable.
|
||||
if (!process.env.CLOUD_API_KEY && !getApiKeyFromElasticCloudJsonFile(environment)) {
|
||||
if (!process.env.CLOUD_API_KEY && !apiKeyFromCloudJsonFile) {
|
||||
log.error(
|
||||
'The API key for the environment needs to be provided with the env var CLOUD_API_KEY.'
|
||||
);
|
||||
|
@ -110,7 +122,7 @@ export const cli = () => {
|
|||
|
||||
const API_KEY = process.env.CLOUD_API_KEY
|
||||
? process.env.CLOUD_API_KEY
|
||||
: getApiKeyFromElasticCloudJsonFile(environment);
|
||||
: apiKeyFromCloudJsonFile;
|
||||
|
||||
log.info(`PROXY_URL is defined : ${PROXY_URL !== undefined}`);
|
||||
log.info(`PROXY_CLIENT_ID is defined : ${PROXY_CLIENT_ID !== undefined}`);
|
||||
|
@ -122,8 +134,9 @@ export const cli = () => {
|
|||
PROXY_URL &&
|
||||
PROXY_CLIENT_ID &&
|
||||
PROXY_SECRET &&
|
||||
environment.toUpperCase() !== 'prod'.toUpperCase() &&
|
||||
environment !== Environment.Production &&
|
||||
(await proxyHealthcheck(PROXY_URL));
|
||||
|
||||
if (proxyServiceUse) {
|
||||
log.info('Proxy service is up and running, so the tests will run using the proxyHandler.');
|
||||
cloudHandler = new ProxyHandler(PROXY_URL, PROXY_CLIENT_ID, PROXY_SECRET);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue