Skip to content

Commit

Permalink
fix some type errors (incomplete)
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Sep 25, 2019
1 parent 14dc066 commit 729bf2e
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-config-schema/src/errors/schema_type_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { SchemaError } from '.';

export class SchemaTypeError extends SchemaError {
constructor(error: Error | string, public readonly path: string[]) {
constructor(error: Error | string, public readonly path: Array<string | number>) {
super(typeof error === 'string' ? error : error.message);

// Set the prototype explicitly, see:
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-config-schema/src/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export abstract class Type<V> {
protected handleError(
type: string,
context: Record<string, any>,
path: string[]
path: Array<string | number>
): string | SchemaTypeError | void {
return undefined;
}
Expand Down
11 changes: 11 additions & 0 deletions src/core/server/elasticsearch/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ enum ErrorCode {

export interface ElasticsearchError extends Boom {
[code]?: string;

output: {
statusCode: number;
payload: {
statusCode: number;
error: string;
message: string;
[key: string]: any;
};
headers: Record<string, string | string[] | undefined>;
};
}

function isElasticsearchError(error: any): error is ElasticsearchError {
Expand Down
6 changes: 4 additions & 2 deletions src/core/server/http/cookie_session_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ScopedCookieSessionStorage<T extends Record<string, any>> implements Sessi
const session = await this.server.auth.test('security-cookie', this.request);
// A browser can send several cookies, if it's not an array, just return the session value
if (!Array.isArray(session)) {
return session as T;
return (session as unknown) as T;
}

// If we have an array with one value, we're good also
Expand Down Expand Up @@ -103,7 +103,9 @@ export async function createCookieSessionStorageFactory<T>(
server.auth.strategy('security-cookie', 'cookie', {
cookie: cookieOptions.name,
password: cookieOptions.encryptionKey,
validateFunc: async (req, session: T) => ({ valid: await cookieOptions.validate(session) }),
validateFunc: async (req: Request, session: T) => ({
valid: await cookieOptions.validate(session),
}),
isSecure: cookieOptions.isSecure,
path: basePath,
clearInvalid: true,
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/http/router/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export class KibanaRequest<Params = unknown, Query = unknown, Body = unknown> {
path: request.path,
method: request.method,
options: {
authRequired: request.route.settings.auth !== false,
// type def limits settings.auth to AuthSettings | undefined
authRequired: (request.route.settings.auth as any) !== false,
tags: request.route.settings.tags || [],
},
};
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/http/router/response_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export class HapiResponseAdapter {
});

error.output.payload.message = getErrorMessage(payload);
error.output.payload.attributes = getErrorAttributes(payload);
// Boom.output.payload is type limited to the default properties
(error.output.payload as any).attributes = getErrorAttributes(payload);

const headers = kibanaResponse.options.headers;
if (headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ async function fetchObjectsToExport({
const erroredObjects = bulkGetResult.saved_objects.filter(obj => !!obj.error);
if (erroredObjects.length) {
const err = Boom.badRequest();
err.output.payload.attributes = {
// Boom.output.payload is type limited to the default properties
(err.output.payload as any).attributes = {
objects: erroredObjects,
};
throw err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export async function injectNestedDependencies(
const erroredObjects = bulkGetResponse.saved_objects.filter(obj => !!obj.error);
if (erroredObjects.length) {
const err = Boom.badRequest();
err.output.payload.attributes = {
// Boom.output.payload is type limited to the default properties
(err.output.payload as any).attributes = {
objects: erroredObjects,
};
throw err;
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/saved_objects/import/validate_references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export async function getNonExistingReferenceAsKeys(
);
if (erroredObjects.length) {
const err = Boom.badRequest();
err.output.payload.attributes = {
// Boom.output.payload is type limited to the default properties
(err.output.payload as any).attributes = {
objects: erroredObjects,
};
throw err;
Expand Down
7 changes: 5 additions & 2 deletions src/core/server/saved_objects/service/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ export class SavedObjectsErrorHelpers {

public static createEsAutoCreateIndexError() {
const error = Boom.serverUnavailable('Automatic index creation failed');
error.output.payload.attributes = error.output.payload.attributes || {};
error.output.payload.attributes.code = 'ES_AUTO_CREATE_INDEX_ERROR';
// Boom.output.payload is type limited to the default properties
(error.output.payload as any).attributes = {
...(error.output.payload as any).attributes,
code: 'ES_AUTO_CREATE_INDEX_ERROR',
};

return decorate(error, CODE_ES_AUTO_CREATE_INDEX_ERROR, 503);
}
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/kbn_server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface UiApp {
}

// Extend the defaults with the plugins and server methods we need.
declare module 'hapi' {
declare module '@hapi/hapi' {
interface PluginProperties {
elasticsearch: ElasticsearchPlugin;
kibana: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class ClusterNodeAdapter implements ServiceHandlerAdapter {
path,
handler: async (req: Request) => {
const { context, params } = req.payload as RequestPayload;
this.log.debug(`Receiving RPC call ${req.url.path} ${util.inspect(params)}`);
this.log.debug(`Receiving RPC call ${req.url.pathname} ${util.inspect(params)}`);
try {
const data = await localHandler(params, context);
return { data };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class CodeNodeAdapter implements ServiceHandlerAdapter {
path,
handler: async (req: Request) => {
const { context, params } = req.payload as RequestPayload;
this.log.debug(`Receiving RPC call ${req.url.path} ${util.inspect(params)}`);
this.log.debug(`Receiving RPC call ${req.url.pathname} ${util.inspect(params)}`);
const endpoint: Endpoint = {
toContext(): RequestContext {
return context;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/reporting/server/routes/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function registerLegacy(
method: 'POST',
config: getStaticFeatureConfig(getRouteConfig, exportTypeId),
handler: async (request: Request, h: ResponseToolkit) => {
const message = `The following URL is deprecated and will stop working in the next major version: ${request.url.path}`;
const message = `The following URL is deprecated and will stop working in the next major version: ${request.url.pathname}`;
server.log(['warning', 'reporting', 'deprecation'], message);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ export class KerberosAuthenticationProvider extends BaseAuthenticationProvider {
* @param error Error to extract challenges from.
*/
private getNegotiateChallenge(error: ElasticsearchError) {
const challenges = ([] as string[]).concat(error.output.headers[WWWAuthenticateHeaderName]);
const challenges = ([] as string[]).concat(
error.output.headers[WWWAuthenticateHeaderName] || []
);

const negotiateChallenge = challenges.find(challenge =>
challenge.toLowerCase().startsWith('negotiate')
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/typings/hapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ActionsPlugin, ActionsClient } from '../../legacy/plugins/actions';
import { TaskManager } from '../../legacy/plugins/task_manager';
import { AlertingPlugin, AlertsClient } from '../../legacy/plugins/alerting';

declare module 'hapi' {
declare module '@hapi/hapi' {
interface Request {
getActionsClient?: () => ActionsClient;
getAlertsClient?: () => AlertsClient;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/typings/hapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ActionsPlugin, ActionsClient } from '../legacy/plugins/actions';
import { TaskManager } from '../legacy/plugins/task_manager';
import { AlertingPlugin, AlertsClient } from '../legacy/plugins/alerting';

declare module 'hapi' {
declare module '@hapi/hapi' {
interface Request {
getActionsClient?: () => ActionsClient;
getAlertsClient?: () => AlertsClient;
Expand Down

0 comments on commit 729bf2e

Please sign in to comment.