Skip to content

Commit

Permalink
Merge branch 'main' into telemtry-use-pit
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Feb 8, 2022
2 parents f306b24 + 6f71ffc commit 4b309c7
Show file tree
Hide file tree
Showing 99 changed files with 3,876 additions and 526 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/cloud/purge.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ for (const deployment of prDeployments) {
const lastCommit = pullRequest.commits.slice(-1)[0];
const lastCommitTimestamp = new Date(lastCommit.committedDate).getTime() / 1000;

if (pullRequest.state !== 'open') {
if (pullRequest.state !== 'OPEN') {
console.log(`Pull Request #${prNumber} is no longer open, will delete associated deployment`);
deploymentsToPurge.push(deployment);
} else if (!pullRequest.labels.filter((label) => label.name === 'ci:deploy-cloud')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [IExternalUrl](./kibana-plugin-core-public.iexternalurl.md) &gt; [isInternalUrl](./kibana-plugin-core-public.iexternalurl.isinternalurl.md)

## IExternalUrl.isInternalUrl() method

Determines if the provided URL is an internal url.

<b>Signature:</b>

```typescript
isInternalUrl(relativeOrAbsoluteUrl: string): boolean;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| relativeOrAbsoluteUrl | string | |

<b>Returns:</b>

boolean

Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export interface IExternalUrl

| Method | Description |
| --- | --- |
| [isInternalUrl(relativeOrAbsoluteUrl)](./kibana-plugin-core-public.iexternalurl.isinternalurl.md) | Determines if the provided URL is an internal url. |
| [validateUrl(relativeOrAbsoluteUrl)](./kibana-plugin-core-public.iexternalurl.validateurl.md) | Determines if the provided URL is a valid location to send users. Validation is based on the configured allow list in kibana.yml.<!-- -->If the URL is valid, then a URL will be returned. Otherwise, this will return null. |

17 changes: 17 additions & 0 deletions src/core/public/http/external_url_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ const internalRequestScenarios = [
];

describe('External Url Service', () => {
describe('#isInternalUrl', () => {
const { setup } = setupService({
location: new URL('https://example.com/app/management?q=1&bar=false#some-hash'),
serverBasePath: '',
policy: [],
});

it('internal request', () => {
expect(setup.isInternalUrl('/')).toBeTruthy();
expect(setup.isInternalUrl('https://example.com/')).toBeTruthy();
});

it('external request', () => {
expect(setup.isInternalUrl('https://elastic.co/')).toBeFalsy();
});
});

describe('#validateUrl', () => {
describe('internal requests with a server base path', () => {
const serverBasePath = '/base-path';
Expand Down
24 changes: 19 additions & 5 deletions src/core/public/http/external_url_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,33 @@ function normalizeProtocol(protocol: string) {
return protocol.endsWith(':') ? protocol.slice(0, -1).toLowerCase() : protocol.toLowerCase();
}

const createIsInternalUrlValidation = (
location: Pick<Location, 'href'>,
serverBasePath: string
) => {
return function isInternallUrl(next: string) {
const base = new URL(location.href);
const url = new URL(next, base);

return (
url.origin === base.origin &&
(!serverBasePath || url.pathname.startsWith(`${serverBasePath}/`))
);
};
};

const createExternalUrlValidation = (
rules: IExternalUrlPolicy[],
location: Pick<Location, 'href'>,
serverBasePath: string
) => {
const isInternalUrl = createIsInternalUrlValidation(location, serverBasePath);

return function validateExternalUrl(next: string) {
const base = new URL(location.href);
const url = new URL(next, base);

const isInternalURL =
url.origin === base.origin &&
(!serverBasePath || url.pathname.startsWith(`${serverBasePath}/`));

if (isInternalURL) {
if (isInternalUrl(next)) {
return url;
}

Expand All @@ -90,6 +103,7 @@ export class ExternalUrlService implements CoreService<IExternalUrl> {
const { policy } = injectedMetadata.getExternalUrlConfig();

return {
isInternalUrl: createIsInternalUrlValidation(location, serverBasePath),
validateUrl: createExternalUrlValidation(policy, location, serverBasePath),
};
}
Expand Down
1 change: 1 addition & 0 deletions src/core/public/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const createServiceMock = ({
isAnonymous: jest.fn(),
},
externalUrl: {
isInternalUrl: jest.fn(),
validateUrl: jest.fn(),
},
addLoadingCountSource: jest.fn(),
Expand Down
7 changes: 7 additions & 0 deletions src/core/public/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ export interface IBasePath {
* @public
*/
export interface IExternalUrl {
/**
* Determines if the provided URL is an internal url.
*
* @param relativeOrAbsoluteUrl
*/
isInternalUrl(relativeOrAbsoluteUrl: string): boolean;

/**
* Determines if the provided URL is a valid location to send users.
* Validation is based on the configured allow list in kibana.yml.
Expand Down
1 change: 1 addition & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ export interface IBasePath {

// @public
export interface IExternalUrl {
isInternalUrl(relativeOrAbsoluteUrl: string): boolean;
validateUrl(relativeOrAbsoluteUrl: string): URL | null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,15 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
yAxisLabelName={yAxisColumn?.name}
xAxisTitle={args.gridConfig.isXAxisTitleVisible ? xAxisTitle : undefined}
yAxisTitle={args.gridConfig.isYAxisTitleVisible ? yAxisTitle : undefined}
xAxisLabelFormatter={(v) => `${xValuesFormatter.convert(v) ?? ''}`}
xAxisLabelFormatter={(v) =>
args.gridConfig.isXAxisLabelVisible ? `${xValuesFormatter.convert(v)}` : ''
}
yAxisLabelFormatter={
yAxisColumn
? (v) => `${formatFactory(yAxisColumn.meta.params).convert(v) ?? ''}`
? (v) =>
args.gridConfig.isYAxisLabelVisible
? `${formatFactory(yAxisColumn.meta.params).convert(v) ?? ''}`
: ''
: undefined
}
/>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/plugins/vis_types/timeseries/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ export class AggNotSupportedError extends UIError {
}
}

export class TimeFieldNotSpecifiedError extends UIError {
constructor() {
super(
i18n.translate('visTypeTimeseries.errors.timeFieldNotSpecifiedError', {
defaultMessage: 'Time field is required to visualize the data',
})
);
}
}

export const filterCannotBeAppliedErrorMessage = i18n.translate(
'visTypeTimeseries.filterCannotBeAppliedError',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import moment from 'moment';
import { AUTO_INTERVAL } from '../../../common/constants';
import { validateField } from '../../../common/fields_utils';
import { validateInterval } from '../../../common/validate_interval';
import { TimeFieldNotSpecifiedError } from '../../../common/errors';

import type { FetchedIndexPattern, Panel, Series } from '../../../common/types';

Expand All @@ -34,7 +35,11 @@ export function getIntervalAndTimefield(
}

if (panel.use_kibana_indexes) {
validateField(timeField!, index);
if (timeField) {
validateField(timeField, index);
} else {
throw new TimeFieldNotSpecifiedError();
}
}

let interval = panel.interval;
Expand Down
Loading

0 comments on commit 4b309c7

Please sign in to comment.