Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import {
actionTaskParamsModelVersions,
connectorModelVersions,
connectorTokenModelVersions,
getConnectorTokenModelVersions,
oauthStateModelVersions,
} from './model_versions';

Expand Down Expand Up @@ -131,7 +131,7 @@ export function setupSavedObjects(
management: {
importableAndExportable: false,
},
modelVersions: connectorTokenModelVersions,
modelVersions: getConnectorTokenModelVersions(encryptedSavedObjects),
});

encryptedSavedObjects.registerType({
Expand Down Expand Up @@ -175,12 +175,8 @@ export function setupSavedObjects(
'state',
'connectorId',
'redirectUri',
Comment thread
lorenabalan marked this conversation as resolved.
Outdated
'authorizationUrl',
'scope',
'spaceId',
'createdAt',
'expiresAt',
'createdBy',
]),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ export const oauthStateMappings: SavedObjectsTypeMappingDefinition = {
// redirectUri: {
// type: 'keyword',
// },
// authorizationUrl: {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field doesn't actually look like it exists anymore looking at the schema, must've been a leftover from a refactoring.

// type: 'keyword',
// },
// scope: {
// type: 'keyword',
// },
Expand All @@ -135,5 +132,8 @@ export const oauthStateMappings: SavedObjectsTypeMappingDefinition = {
// kibanaReturnUrl: {
// type: 'keyword',
// },
// spaceId: {
// type: 'keyword',
// },
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,60 @@
*/

import type { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server';
import type { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server';
import {
rawConnectorTokenSchemaV1,
rawConnectorTokenSchemaV2,
} from '../schemas/raw_connector_token';
import { CONNECTOR_TOKEN_SAVED_OBJECT_TYPE } from '../../constants/saved_objects';

export const connectorTokenModelVersions: SavedObjectsModelVersionMap = {
// ESO type registration for V1 (before refreshToken was added)
const connectorTokenTypeRegistrationV1 = {
type: CONNECTOR_TOKEN_SAVED_OBJECT_TYPE,
attributesToEncrypt: new Set(['token']),
attributesToIncludeInAAD: new Set([
'connectorId',
'tokenType',
'expiresAt',
'createdAt',
'updatedAt',
]),
};

// ESO type registration for V2 (with refreshToken and refreshTokenExpiresAt)
const connectorTokenTypeRegistrationV2 = {
type: CONNECTOR_TOKEN_SAVED_OBJECT_TYPE,
attributesToEncrypt: new Set(['token', 'refreshToken']),
attributesToIncludeInAAD: new Set([
'connectorId',
'tokenType',
'expiresAt',
'createdAt',
'updatedAt',
'refreshTokenExpiresAt',
]),
};

export const getConnectorTokenModelVersions = (
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup
): SavedObjectsModelVersionMap => ({
'1': {
changes: [],
schemas: {
forwardCompatibility: rawConnectorTokenSchemaV1.extends({}, { unknowns: 'ignore' }),
create: rawConnectorTokenSchemaV1,
},
},
'2': {
changes: [], // backwards-compatible schema evolution
schemas: {
forwardCompatibility: rawConnectorTokenSchemaV2.extends({}, { unknowns: 'ignore' }),
create: rawConnectorTokenSchemaV2,
'2': encryptedSavedObjects.createModelVersion({
Comment thread
lorenabalan marked this conversation as resolved.
modelVersion: {
changes: [],
schemas: {
forwardCompatibility: rawConnectorTokenSchemaV2.extends({}, { unknowns: 'ignore' }),
create: rawConnectorTokenSchemaV2,
},
},
},
};
inputType: connectorTokenTypeRegistrationV1,
outputType: connectorTokenTypeRegistrationV2,
shouldTransformIfDecryptionFails: true,
}),
});
Comment thread
lorenabalan marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/

export { connectorModelVersions } from './connector_model_versions';
export { connectorTokenModelVersions } from './connector_token_model_versions';
export { getConnectorTokenModelVersions } from './connector_token_model_versions';
export { actionTaskParamsModelVersions } from './action_task_params_model_versions';
export { oauthStateModelVersions } from './oauth_state_model_versions';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const rawOAuthStateSchema = schema.object({
redirectUri: schema.string(),
scope: schema.maybe(schema.string()),
kibanaReturnUrl: schema.string(), // in case of OAuth success, redirect to this URL
spaceId: schema.string(), // the space where the connector exists
spaceId: schema.string(), // the space where the connector exists and the authz was initiated from
createdAt: schema.string(),
expiresAt: schema.string(),
createdBy: schema.maybe(schema.string()),
Expand Down