From 422b6a2274cb3dee05ef5054afb19684c4f8d2de Mon Sep 17 00:00:00 2001 From: Brian Kassouf Date: Wed, 7 Nov 2018 09:38:48 -0800 Subject: [PATCH] Break plugins back out into two path functions (#5721) --- vault/logical_system.go | 3 +- vault/logical_system_paths.go | 109 +++++++++++++++++----------------- 2 files changed, 58 insertions(+), 54 deletions(-) diff --git a/vault/logical_system.go b/vault/logical_system.go index a0cf9d15c..24f2cceae 100644 --- a/vault/logical_system.go +++ b/vault/logical_system.go @@ -132,7 +132,8 @@ func NewSystemBackend(core *Core, logger log.Logger) *SystemBackend { b.Backend.Paths = append(b.Backend.Paths, b.configPaths()...) b.Backend.Paths = append(b.Backend.Paths, b.rekeyPaths()...) b.Backend.Paths = append(b.Backend.Paths, b.sealPaths()...) - b.Backend.Paths = append(b.Backend.Paths, b.pluginsCatalogPaths()...) + b.Backend.Paths = append(b.Backend.Paths, b.pluginsCatalogListPaths()...) + b.Backend.Paths = append(b.Backend.Paths, b.pluginsCatalogCRUDPath()) b.Backend.Paths = append(b.Backend.Paths, b.pluginsReloadPath()) b.Backend.Paths = append(b.Backend.Paths, b.auditPaths()...) b.Backend.Paths = append(b.Backend.Paths, b.mountPaths()...) diff --git a/vault/logical_system_paths.go b/vault/logical_system_paths.go index ab97aa04e..172c09c3a 100644 --- a/vault/logical_system_paths.go +++ b/vault/logical_system_paths.go @@ -558,7 +558,62 @@ func (b *SystemBackend) sealPaths() []*framework.Path { } } -func (b *SystemBackend) pluginsCatalogPaths() []*framework.Path { +func (b *SystemBackend) pluginsCatalogCRUDPath() *framework.Path { + return &framework.Path{ + Pattern: "plugins/catalog(/(?Pauth|database|secret))?/(?P.+)", + + Fields: map[string]*framework.FieldSchema{ + "name": &framework.FieldSchema{ + Type: framework.TypeString, + Description: strings.TrimSpace(sysHelp["plugin-catalog_name"][0]), + }, + "type": &framework.FieldSchema{ + Type: framework.TypeString, + Description: strings.TrimSpace(sysHelp["plugin-catalog_type"][0]), + }, + "sha256": &framework.FieldSchema{ + Type: framework.TypeString, + Description: strings.TrimSpace(sysHelp["plugin-catalog_sha-256"][0]), + }, + "sha_256": &framework.FieldSchema{ + Type: framework.TypeString, + Description: strings.TrimSpace(sysHelp["plugin-catalog_sha-256"][0]), + }, + "command": &framework.FieldSchema{ + Type: framework.TypeString, + Description: strings.TrimSpace(sysHelp["plugin-catalog_command"][0]), + }, + "args": &framework.FieldSchema{ + Type: framework.TypeStringSlice, + Description: strings.TrimSpace(sysHelp["plugin-catalog_args"][0]), + }, + "env": &framework.FieldSchema{ + Type: framework.TypeStringSlice, + Description: strings.TrimSpace(sysHelp["plugin-catalog_env"][0]), + }, + }, + + Operations: map[logical.Operation]framework.OperationHandler{ + logical.UpdateOperation: &framework.PathOperation{ + Callback: b.handlePluginCatalogUpdate, + Summary: "Register a new plugin, or updates an existing one with the supplied name.", + }, + logical.DeleteOperation: &framework.PathOperation{ + Callback: b.handlePluginCatalogDelete, + Summary: "Remove the plugin with the given name.", + }, + logical.ReadOperation: &framework.PathOperation{ + Callback: b.handlePluginCatalogRead, + Summary: "Return the configuration data for the plugin with the given name.", + }, + }, + + HelpSynopsis: strings.TrimSpace(sysHelp["plugin-catalog"][0]), + HelpDescription: strings.TrimSpace(sysHelp["plugin-catalog"][1]), + } +} + +func (b *SystemBackend) pluginsCatalogListPaths() []*framework.Path { return []*framework.Path{ { Pattern: "plugins/catalog/(?Pauth|database|secret)/?$", @@ -580,58 +635,6 @@ func (b *SystemBackend) pluginsCatalogPaths() []*framework.Path { HelpSynopsis: strings.TrimSpace(sysHelp["plugin-catalog"][0]), HelpDescription: strings.TrimSpace(sysHelp["plugin-catalog"][1]), }, - { - Pattern: "plugins/catalog(/(?Pauth|database|secret))?/(?P.+)", - - Fields: map[string]*framework.FieldSchema{ - "name": &framework.FieldSchema{ - Type: framework.TypeString, - Description: strings.TrimSpace(sysHelp["plugin-catalog_name"][0]), - }, - "type": &framework.FieldSchema{ - Type: framework.TypeString, - Description: strings.TrimSpace(sysHelp["plugin-catalog_type"][0]), - }, - "sha256": &framework.FieldSchema{ - Type: framework.TypeString, - Description: strings.TrimSpace(sysHelp["plugin-catalog_sha-256"][0]), - }, - "sha_256": &framework.FieldSchema{ - Type: framework.TypeString, - Description: strings.TrimSpace(sysHelp["plugin-catalog_sha-256"][0]), - }, - "command": &framework.FieldSchema{ - Type: framework.TypeString, - Description: strings.TrimSpace(sysHelp["plugin-catalog_command"][0]), - }, - "args": &framework.FieldSchema{ - Type: framework.TypeStringSlice, - Description: strings.TrimSpace(sysHelp["plugin-catalog_args"][0]), - }, - "env": &framework.FieldSchema{ - Type: framework.TypeStringSlice, - Description: strings.TrimSpace(sysHelp["plugin-catalog_env"][0]), - }, - }, - - Operations: map[logical.Operation]framework.OperationHandler{ - logical.UpdateOperation: &framework.PathOperation{ - Callback: b.handlePluginCatalogUpdate, - Summary: "Register a new plugin, or updates an existing one with the supplied name.", - }, - logical.DeleteOperation: &framework.PathOperation{ - Callback: b.handlePluginCatalogDelete, - Summary: "Remove the plugin with the given name.", - }, - logical.ReadOperation: &framework.PathOperation{ - Callback: b.handlePluginCatalogRead, - Summary: "Return the configuration data for the plugin with the given name.", - }, - }, - - HelpSynopsis: strings.TrimSpace(sysHelp["plugin-catalog"][0]), - HelpDescription: strings.TrimSpace(sysHelp["plugin-catalog"][1]), - }, { Pattern: "plugins/catalog/?$",