Skip to content

Commit

Permalink
Use status service.
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin committed Feb 5, 2021
1 parent 23777af commit 045755d
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 67 deletions.
14 changes: 3 additions & 11 deletions x-pack/plugins/encrypted_saved_objects/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('config schema', () => {

expect(ConfigSchema.validate({}, { dist: true })).toMatchInlineSnapshot(`
Object {
"enabled": false,
"enabled": true,
"keyRotation": Object {
"decryptionOnlyKeys": Array [],
},
Expand All @@ -54,15 +54,15 @@ describe('config schema', () => {
expect(
ConfigSchema.validate(
{
encryptionKey: 'z'.repeat(32),
encryptionKey: 'a'.repeat(32),
keyRotation: { decryptionOnlyKeys: ['b'.repeat(32), 'c'.repeat(32)] },
},
{ dist: true }
)
).toMatchInlineSnapshot(`
Object {
"enabled": true,
"encryptionKey": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"keyRotation": Object {
"decryptionOnlyKeys": Array [
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
Expand All @@ -87,14 +87,6 @@ describe('config schema', () => {
);
});

it('should throw error if `enabled` is set to `true`, but xpack.encryptedSavedObjects.encryptionKey is not specified', () => {
expect(() =>
ConfigSchema.validate({ enabled: true }, { dist: true })
).toThrowErrorMatchingInlineSnapshot(
`"\`enabled\` cannot be set to \`true\` until \`encryptionKey\` is specified."`
);
});

it('should throw error if any of the xpack.encryptedSavedObjects.keyRotation.decryptionOnlyKeys is less than 32 characters', () => {
expect(() =>
ConfigSchema.validate({
Expand Down
15 changes: 2 additions & 13 deletions x-pack/plugins/encrypted_saved_objects/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@

import { schema, TypeOf } from '@kbn/config-schema';

export type ConfigType = Omit<TypeOf<typeof ConfigSchema>, 'encryptionKey'> & {
encryptionKey: string;
};
export type ConfigType = TypeOf<typeof ConfigSchema>;

export const ConfigSchema = schema.object(
{
enabled: schema.conditional(
schema.siblingRef('encryptionKey'),
schema.string({ minLength: 32 }),
schema.boolean({ defaultValue: true }),
schema.boolean({ defaultValue: false })
),
enabled: schema.boolean({ defaultValue: true }),
encryptionKey: schema.conditional(
schema.contextRef('dist'),
true,
Expand All @@ -35,10 +28,6 @@ export const ConfigSchema = schema.object(
if (value.encryptionKey && decryptionOnlyKeys.includes(value.encryptionKey)) {
return '`keyRotation.decryptionOnlyKeys` cannot contain primary encryption key specified in `encryptionKey`.';
}

if (value.enabled && !value.encryptionKey) {
return '`enabled` cannot be set to `true` until `encryptionKey` is specified.';
}
},
}
);
Loading

0 comments on commit 045755d

Please sign in to comment.