From 96371ed0a53b65fc7e0fa07f17f9cd80bc4b9a55 Mon Sep 17 00:00:00 2001 From: Violet Hynes Date: Fri, 17 Jun 2022 08:52:43 -0400 Subject: [PATCH] Small refactor of mount entry manipulation (#16024) --- vault/logical_system_quotas.go | 12 +++--------- vault/mount.go | 9 +++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/vault/logical_system_quotas.go b/vault/logical_system_quotas.go index 435e0ad62..2c6822044 100644 --- a/vault/logical_system_quotas.go +++ b/vault/logical_system_quotas.go @@ -193,15 +193,9 @@ func (b *SystemBackend) handleRateLimitQuotasUpdate() framework.OperationFunc { return logical.ErrorResponse("invalid mount path %q", mountPath), nil } - var newMountPath string - if me.Table == mountTableType { - newMountPath = me.Path - } else { - newMountPath = me.Table + "/" + me.Path - } - - pathSuffix = strings.TrimSuffix(strings.TrimPrefix(mountPath, newMountPath), "/") - mountPath = newMountPath + mountAPIPath := me.APIPathNoNamespace() + pathSuffix = strings.TrimSuffix(strings.TrimPrefix(mountPath, mountAPIPath), "/") + mountPath = mountAPIPath } // Disallow creation of new quota that has properties similar to an // existing quota. diff --git a/vault/mount.go b/vault/mount.go index ea51a707c..db2d50b5b 100644 --- a/vault/mount.go +++ b/vault/mount.go @@ -391,6 +391,15 @@ func (e *MountEntry) APIPath() string { return e.namespace.Path + path } +// APIPathNoNamespace returns the API Path without the namespace for the given mount entry +func (e *MountEntry) APIPathNoNamespace() string { + path := e.Path + if e.Table == credentialTableType { + path = credentialRoutePrefix + path + } + return path +} + // SyncCache syncs tunable configuration values to the cache. In the case of // cached values, they should be retrieved via synthesizedConfigCache.Load() // instead of accessing them directly through MountConfig.