From 777c22cf62e9a1821e88b053efd69b8369cf76c4 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 4 Feb 2025 20:35:24 +1100 Subject: [PATCH] [9.0] [Snapshot and restore] Avoid duplicated error messages (#209316) (#209455) # Backport This will backport the following commits from `main` to `9.0`: - [[Snapshot and restore] Avoid duplicated error messages (#209316)](https://github.com/elastic/kibana/pull/209316) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Sonia Sanz Vivas --- .../server/routes/api/validate_schemas.ts | 68 +++++-------------- 1 file changed, 16 insertions(+), 52 deletions(-) diff --git a/x-pack/platform/plugins/private/snapshot_restore/server/routes/api/validate_schemas.ts b/x-pack/platform/plugins/private/snapshot_restore/server/routes/api/validate_schemas.ts index 4167c0d972a48..d0861babb1fb4 100644 --- a/x-pack/platform/plugins/private/snapshot_restore/server/routes/api/validate_schemas.ts +++ b/x-pack/platform/plugins/private/snapshot_restore/server/routes/api/validate_schemas.ts @@ -65,31 +65,13 @@ export const policySchema = schema.object({ // Only validate required settings, everything else is optional const fsRepositorySettings = schema.object({ location: schema.string() }, { unknowns: 'allow' }); -const fsRepositorySchema = schema.object({ - name: schema.string({ maxLength: 1000 }), - type: schema.string(), - settings: fsRepositorySettings, -}); - const readOnlyRepositorySettings = schema.object({ url: schema.string(), }); -const readOnlyRepository = schema.object({ - name: schema.string({ maxLength: 1000 }), - type: schema.string(), - settings: readOnlyRepositorySettings, -}); - // Only validate required settings, everything else is optional const s3RepositorySettings = schema.object({ bucket: schema.string() }, { unknowns: 'allow' }); -const s3Repository = schema.object({ - name: schema.string({ maxLength: 1000 }), - type: schema.string(), - settings: s3RepositorySettings, -}); - // Only validate required settings, everything else is optional const hdsRepositorySettings = schema.object( { @@ -99,30 +81,27 @@ const hdsRepositorySettings = schema.object( { unknowns: 'allow' } ); -const hdsfRepository = schema.object({ - name: schema.string({ maxLength: 1000 }), - type: schema.string(), - settings: hdsRepositorySettings, -}); - const azureRepositorySettings = schema.object({}, { unknowns: 'allow' }); -const azureRepository = schema.object({ - name: schema.string({ maxLength: 1000 }), - type: schema.string(), - settings: azureRepositorySettings, -}); - // Only validate required settings, everything else is optional const gcsRepositorySettings = schema.object({ bucket: schema.string() }, { unknowns: 'allow' }); -const gcsRepository = schema.object({ - name: schema.string({ maxLength: 1000 }), - type: schema.string(), - settings: gcsRepositorySettings, -}); +const sourceRepositorySettings = schema.oneOf([ + fsRepositorySettings, + readOnlyRepositorySettings, + s3RepositorySettings, + hdsRepositorySettings, + azureRepositorySettings, + gcsRepositorySettings, + schema.object( + { + delegateType: schema.string(), + }, + { unknowns: 'allow' } + ), +]); -const sourceRepository = schema.object({ +export const repositorySchema = schema.object({ name: schema.string({ maxLength: 1000 }), type: schema.string(), settings: schema.oneOf([ @@ -132,25 +111,10 @@ const sourceRepository = schema.object({ hdsRepositorySettings, azureRepositorySettings, gcsRepositorySettings, - schema.object( - { - delegateType: schema.string(), - }, - { unknowns: 'allow' } - ), + sourceRepositorySettings, ]), }); -export const repositorySchema = schema.oneOf([ - fsRepositorySchema, - readOnlyRepository, - sourceRepository, - s3Repository, - hdsfRepository, - azureRepository, - gcsRepository, -]); - export const restoreSettingsSchema = schema.object({ indices: schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())])), renamePattern: schema.maybe(schema.string()),