Skip to content

Commit

Permalink
Unify Security and EncryptedSavedObjects public contract names accord…
Browse files Browse the repository at this point in the history
…ing to NP migration guide. (#56597)
  • Loading branch information
azasypkin authored Feb 3, 2020
1 parent 598968f commit 8def60e
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 65 deletions.
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/alerting/server/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
CreateAPIKeyResult as SecurityPluginCreateAPIKeyResult,
InvalidateAPIKeyResult as SecurityPluginInvalidateAPIKeyResult,
} from '../../../../plugins/security/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../../plugins/encrypted_saved_objects/server';
import { EncryptedSavedObjectsPluginStart } from '../../../../plugins/encrypted_saved_objects/server';
import { TaskManagerStartContract } from '../../../../plugins/task_manager/server';

type NormalizedAlertAction = Omit<AlertAction, 'actionTypeId'>;
Expand All @@ -45,7 +45,7 @@ interface ConstructorOptions {
taskManager: TaskManagerStartContract;
savedObjectsClient: SavedObjectsClientContract;
alertTypeRegistry: AlertTypeRegistry;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsStartContract;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;
spaceId?: string;
namespace?: string;
getUserName: () => Promise<string | null>;
Expand Down Expand Up @@ -120,7 +120,7 @@ export class AlertsClient {
private readonly invalidateAPIKey: (
params: InvalidateAPIKeyParams
) => Promise<InvalidateAPIKeyResult>;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsStartContract;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;

constructor({
alertTypeRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AlertTypeRegistry, SpaceIdToNamespaceFunction } from './types';
import { SecurityPluginStartContract } from './shim';
import { KibanaRequest, Logger } from '../../../../../src/core/server';
import { InvalidateAPIKeyParams } from '../../../../plugins/security/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../../plugins/encrypted_saved_objects/server';
import { EncryptedSavedObjectsPluginStart } from '../../../../plugins/encrypted_saved_objects/server';
import { TaskManagerStartContract } from '../../../../plugins/task_manager/server';

export interface ConstructorOpts {
Expand All @@ -21,7 +21,7 @@ export interface ConstructorOpts {
securityPluginSetup?: SecurityPluginStartContract;
getSpaceId: (request: Hapi.Request) => string | undefined;
spaceIdToNamespace: SpaceIdToNamespaceFunction;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsStartContract;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;
}

export class AlertsClientFactory {
Expand All @@ -31,7 +31,7 @@ export class AlertsClientFactory {
private readonly securityPluginSetup?: SecurityPluginStartContract;
private readonly getSpaceId: (request: Hapi.Request) => string | undefined;
private readonly spaceIdToNamespace: SpaceIdToNamespaceFunction;
private readonly encryptedSavedObjectsPlugin: EncryptedSavedObjectsStartContract;
private readonly encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;

constructor(options: ConstructorOpts) {
this.logger = options.logger;
Expand Down
18 changes: 9 additions & 9 deletions x-pack/legacy/plugins/alerting/server/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { getTaskManagerSetup, getTaskManagerStart } from '../../task_manager/ser
import { XPackMainPlugin } from '../../xpack_main/server/xpack_main';
import KbnServer from '../../../../../src/legacy/server/kbn_server';
import {
PluginSetupContract as EncryptedSavedObjectsSetupContract,
PluginStartContract as EncryptedSavedObjectsStartContract,
EncryptedSavedObjectsPluginSetup,
EncryptedSavedObjectsPluginStart,
} from '../../../../plugins/encrypted_saved_objects/server';
import { PluginSetupContract as SecurityPlugin } from '../../../../plugins/security/server';
import { SecurityPluginSetup } from '../../../../plugins/security/server';
import {
CoreSetup,
LoggerFactory,
Expand All @@ -44,8 +44,8 @@ export interface Server extends Legacy.Server {
/**
* Shim what we're thinking setup and start contracts will look like
*/
export type SecurityPluginSetupContract = Pick<SecurityPlugin, '__legacyCompat'>;
export type SecurityPluginStartContract = Pick<SecurityPlugin, 'authc'>;
export type SecurityPluginSetupContract = Pick<SecurityPluginSetup, '__legacyCompat'>;
export type SecurityPluginStartContract = Pick<SecurityPluginSetup, 'authc'>;
export type XPackMainPluginSetupContract = Pick<XPackMainPlugin, 'registerFeature'>;

/**
Expand All @@ -71,14 +71,14 @@ export interface AlertingPluginsSetup {
taskManager: TaskManagerSetupContract;
actions: ActionsPluginSetupContract;
xpack_main: XPackMainPluginSetupContract;
encryptedSavedObjects: EncryptedSavedObjectsSetupContract;
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup;
licensing: LicensingPluginSetup;
}
export interface AlertingPluginsStart {
actions: ActionsPluginStartContract;
security?: SecurityPluginStartContract;
spaces: () => SpacesPluginStartContract | undefined;
encryptedSavedObjects: EncryptedSavedObjectsStartContract;
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
taskManager: TaskManagerStartContract;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ export function shim(
actions: newPlatform.setup.plugins.actions as ActionsPluginSetupContract,
xpack_main: server.plugins.xpack_main,
encryptedSavedObjects: newPlatform.setup.plugins
.encryptedSavedObjects as EncryptedSavedObjectsSetupContract,
.encryptedSavedObjects as EncryptedSavedObjectsPluginSetup,
licensing: newPlatform.setup.plugins.licensing as LicensingPluginSetup,
};

Expand All @@ -131,7 +131,7 @@ export function shim(
// initializes after this function is called
spaces: () => server.plugins.spaces,
encryptedSavedObjects: newPlatform.start.plugins
.encryptedSavedObjects as EncryptedSavedObjectsStartContract,
.encryptedSavedObjects as EncryptedSavedObjectsPluginStart,
taskManager: getTaskManagerStart(server)!,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { Logger } from '../../../../../../src/core/server';
import { RunContext } from '../../../../../plugins/task_manager/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../../../plugins/encrypted_saved_objects/server';
import { EncryptedSavedObjectsPluginStart } from '../../../../../plugins/encrypted_saved_objects/server';
import { PluginStartContract as ActionsPluginStartContract } from '../../../../../plugins/actions/server';
import {
AlertType,
Expand All @@ -19,7 +19,7 @@ export interface TaskRunnerContext {
logger: Logger;
getServices: GetServicesFunction;
executeAction: ActionsPluginStartContract['execute'];
encryptedSavedObjectsPlugin: EncryptedSavedObjectsStartContract;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;
spaceIdToNamespace: SpaceIdToNamespaceFunction;
getBasePath: GetBasePathFunction;
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/encrypted_saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Root } from 'joi';
import { Legacy } from 'kibana';
import { PluginSetupContract } from '../../../plugins/encrypted_saved_objects/server';
import { EncryptedSavedObjectsPluginSetup } from '../../../plugins/encrypted_saved_objects/server';
// @ts-ignore
import { AuditLogger } from '../../server/lib/audit_logger';

Expand All @@ -29,7 +29,7 @@ export const encryptedSavedObjects = (kibana: {

init(server: Legacy.Server) {
const encryptedSavedObjectsPlugin = (server.newPlatform.setup.plugins
.encryptedSavedObjects as unknown) as PluginSetupContract;
.encryptedSavedObjects as unknown) as EncryptedSavedObjectsPluginSetup;
if (!encryptedSavedObjectsPlugin) {
throw new Error('New Platform XPack EncryptedSavedObjects plugin is not available.');
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/reporting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Legacy } from 'kibana';
import { IUiSettingsClient } from 'kibana/server';
import { resolve } from 'path';
import { PluginStart as DataPluginStart } from '../../../../src/plugins/data/server';
import { PluginSetupContract as SecurityPluginSetup } from '../../../plugins/security/server';
import { SecurityPluginSetup } from '../../../plugins/security/server';
import { PLUGIN_ID, UI_SETTINGS_CUSTOM_PDF_LOGO } from './common/constants';
import { config as reportingConfig } from './config';
import { LegacySetup, ReportingPlugin, reportingPluginFactory } from './server/plugin';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/reporting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { PluginStart as DataPluginStart } from '../../../../../src/plugins/data/server';
import { PluginSetupContract as SecurityPluginSetup } from '../../../../plugins/security/server';
import { SecurityPluginSetup } from '../../../../plugins/security/server';
// @ts-ignore
import { mirrorPluginStatus } from '../../../server/lib/mirror_plugin_status';
import { XPackMainPlugin } from '../../xpack_main/server/xpack_main';
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/siem/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import { CoreSetup, PluginInitializerContext, Logger } from 'src/core/server';
import { PluginSetupContract as SecurityPlugin } from '../../../../plugins/security/server';
import { SecurityPluginSetup } from '../../../../plugins/security/server';
import { PluginSetupContract as FeaturesSetupContract } from '../../../../plugins/features/server';
import { initServer } from './init_server';
import { compose } from './lib/compose/kibana';
Expand All @@ -17,7 +17,7 @@ import {
ruleStatusSavedObjectType,
} from './saved_objects';

export type SiemPluginSecurity = Pick<SecurityPlugin, 'authc'>;
export type SiemPluginSecurity = Pick<SecurityPluginSetup, 'authc'>;

export interface PluginsSetup {
features: FeaturesSetupContract;
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
GetServicesFunction,
RawAction,
} from '../types';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../encrypted_saved_objects/server';
import { EncryptedSavedObjectsPluginStart } from '../../../encrypted_saved_objects/server';
import { SpacesServiceSetup } from '../../../spaces/server';
import { EVENT_LOG_ACTIONS } from '../plugin';
import { IEvent, IEventLogger } from '../../../event_log/server';
Expand All @@ -21,7 +21,7 @@ export interface ActionExecutorContext {
logger: Logger;
spaces?: SpacesServiceSetup;
getServices: GetServicesFunction;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsStartContract;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;
actionTypeRegistry: ActionTypeRegistryContract;
eventLogger: IEventLogger;
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/server/lib/task_runner_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { ActionExecutorContract } from './action_executor';
import { ExecutorError } from './executor_error';
import { Logger, CoreStart } from '../../../../../src/core/server';
import { RunContext } from '../../../task_manager/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../encrypted_saved_objects/server';
import { EncryptedSavedObjectsPluginStart } from '../../../encrypted_saved_objects/server';
import { ActionTaskParams, GetBasePathFunction, SpaceIdToNamespaceFunction } from '../types';

export interface TaskRunnerContext {
logger: Logger;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsStartContract;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;
spaceIdToNamespace: SpaceIdToNamespaceFunction;
getBasePath: GetBasePathFunction;
getScopedSavedObjectsClient: CoreStart['savedObjects']['getScopedClient'];
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
} from '../../../../src/core/server';

import {
PluginSetupContract as EncryptedSavedObjectsSetupContract,
PluginStartContract as EncryptedSavedObjectsStartContract,
EncryptedSavedObjectsPluginSetup,
EncryptedSavedObjectsPluginStart,
} from '../../encrypted_saved_objects/server';
import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server';
import { LicensingPluginSetup } from '../../licensing/server';
Expand Down Expand Up @@ -67,13 +67,13 @@ export interface PluginStartContract {

export interface ActionsPluginsSetup {
taskManager: TaskManagerSetupContract;
encryptedSavedObjects: EncryptedSavedObjectsSetupContract;
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup;
licensing: LicensingPluginSetup;
spaces?: SpacesPluginSetup;
event_log: IEventLogService;
}
export interface ActionsPluginsStart {
encryptedSavedObjects: EncryptedSavedObjectsStartContract;
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
taskManager: TaskManagerStartContract;
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/case/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CoreSetup, Logger, PluginInitializerContext } from 'kibana/server';
import { ConfigType } from './config';
import { initCaseApi } from './routes/api';
import { CaseService } from './services';
import { PluginSetupContract as SecurityPluginSetup } from '../../security/server';
import { SecurityPluginSetup } from '../../security/server';

function createConfig$(context: PluginInitializerContext) {
return context.config.create<ConfigType>().pipe(map(config => config));
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/case/server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import {
UpdatedCaseType,
UpdatedCommentType,
} from '../routes/api/types';
import {
AuthenticatedUser,
PluginSetupContract as SecurityPluginSetup,
} from '../../../security/server';
import { AuthenticatedUser, SecurityPluginSetup } from '../../../security/server';

interface ClientArgs {
client: SavedObjectsClientContract;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/encrypted_saved_objects/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ConfigSchema } from './config';
import { Plugin } from './plugin';

export { EncryptedSavedObjectTypeRegistration, EncryptionError } from './crypto';
export { PluginSetupContract, PluginStartContract } from './plugin';
export { EncryptedSavedObjectsPluginSetup, EncryptedSavedObjectsPluginStart } from './plugin';

export const config = { schema: ConfigSchema };
export const plugin = (initializerContext: PluginInitializerContext) =>
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/encrypted_saved_objects/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginSetupContract, PluginStartContract } from './plugin';
import { EncryptedSavedObjectsPluginSetup, EncryptedSavedObjectsPluginStart } from './plugin';

function createEncryptedSavedObjectsSetupMock() {
return {
registerType: jest.fn(),
__legacyCompat: { registerLegacyAPI: jest.fn() },
usingEphemeralEncryptionKey: true,
} as jest.Mocked<PluginSetupContract>;
} as jest.Mocked<EncryptedSavedObjectsPluginSetup>;
}

function createEncryptedSavedObjectsStartMock() {
return {
isEncryptionError: jest.fn(),
getDecryptedAsInternalUser: jest.fn(),
} as jest.Mocked<PluginStartContract>;
} as jest.Mocked<EncryptedSavedObjectsPluginStart>;
}

export const encryptedSavedObjectsMock = {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/encrypted_saved_objects/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import {
import { EncryptedSavedObjectsAuditLogger } from './audit';
import { SavedObjectsSetup, setupSavedObjects } from './saved_objects';

export interface PluginSetupContract {
export interface EncryptedSavedObjectsPluginSetup {
registerType: (typeRegistration: EncryptedSavedObjectTypeRegistration) => void;
__legacyCompat: { registerLegacyAPI: (legacyAPI: LegacyAPI) => void };
usingEphemeralEncryptionKey: boolean;
}

export interface PluginStartContract extends SavedObjectsSetup {
export interface EncryptedSavedObjectsPluginStart extends SavedObjectsSetup {
isEncryptionError: (error: Error) => boolean;
}

Expand Down Expand Up @@ -59,7 +59,7 @@ export class Plugin {
this.logger = this.initializerContext.logger.get();
}

public async setup(core: CoreSetup): Promise<PluginSetupContract> {
public async setup(core: CoreSetup): Promise<EncryptedSavedObjectsPluginSetup> {
const { config, usingEphemeralEncryptionKey } = await createConfig$(this.initializerContext)
.pipe(first())
.toPromise();
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/security/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
RecursiveReadonly,
} from '../../../../src/core/server';
import { ConfigSchema } from './config';
import { Plugin, PluginSetupContract, PluginSetupDependencies } from './plugin';
import { Plugin, SecurityPluginSetup, PluginSetupDependencies } from './plugin';

// These exports are part of public Security plugin contract, any change in signature of exported
// functions or removal of exports should be considered as a breaking change.
Expand All @@ -24,7 +24,7 @@ export {
InvalidateAPIKeyParams,
InvalidateAPIKeyResult,
} from './authentication';
export { PluginSetupContract };
export { SecurityPluginSetup };
export { AuthenticatedUser } from '../common/model';

export const config: PluginConfigDescriptor<TypeOf<typeof ConfigSchema>> = {
Expand All @@ -35,7 +35,7 @@ export const config: PluginConfigDescriptor<TypeOf<typeof ConfigSchema>> = {
],
};
export const plugin: PluginInitializer<
RecursiveReadonly<PluginSetupContract>,
RecursiveReadonly<SecurityPluginSetup>,
void,
PluginSetupDependencies
> = (initializerContext: PluginInitializerContext) => new Plugin(initializerContext);
4 changes: 2 additions & 2 deletions x-pack/plugins/security/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginSetupContract } from './plugin';
import { SecurityPluginSetup } from './plugin';

import { authenticationMock } from './authentication/index.mock';
import { authorizationMock } from './authorization/index.mock';
Expand All @@ -19,7 +19,7 @@ function createSetupMock() {
mode: mockAuthz.mode,
},
registerSpacesService: jest.fn(),
__legacyCompat: {} as PluginSetupContract['__legacyCompat'],
__legacyCompat: {} as SecurityPluginSetup['__legacyCompat'],
};
}

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface LegacyAPI {
/**
* Describes public Security plugin contract returned at the `setup` stage.
*/
export interface PluginSetupContract {
export interface SecurityPluginSetup {
authc: Authentication;
authz: Pick<Authorization, 'actions' | 'checkPrivilegesWithRequest' | 'mode'>;

Expand Down Expand Up @@ -166,7 +166,7 @@ export class Plugin {
csp: core.http.csp,
});

return deepFreeze<PluginSetupContract>({
return deepFreeze<SecurityPluginSetup>({
authc,

authz: {
Expand Down
Loading

0 comments on commit 8def60e

Please sign in to comment.