mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 10:12:35 +00:00
* Revert "Add mount path into the default generated openapi.json spec (UI) (#17926)" This reverts commitdb8efac708. * Revert "Remove `generic_mount_paths` field (#18558)" This reverts commit79c8f626c5.
This commit is contained in:
committed by
GitHub
parent
1e356c9c7d
commit
3f073ae3ce
@@ -208,16 +208,16 @@ var (
|
||||
altRootsRe = regexp.MustCompile(`^\(([\w\-_]+(?:\|[\w\-_]+)+)\)(/.*)$`) // Pattern starting with alts, e.g. "(root1|root2)/(?P<name>regex)"
|
||||
cleanCharsRe = regexp.MustCompile("[()^$?]") // Set of regex characters that will be stripped during cleaning
|
||||
cleanSuffixRe = regexp.MustCompile(`/\?\$?$`) // Path suffix patterns that will be stripped during cleaning
|
||||
nonWordRe = regexp.MustCompile(`[^a-zA-Z0-9]+`) // Match a sequence of non-word characters
|
||||
nonWordRe = regexp.MustCompile(`[^\w]+`) // Match a sequence of non-word characters
|
||||
pathFieldsRe = regexp.MustCompile(`{(\w+)}`) // Capture OpenAPI-style named parameters, e.g. "lookup/{urltoken}",
|
||||
reqdRe = regexp.MustCompile(`\(?\?P<(\w+)>[^)]*\)?`) // Capture required parameters, e.g. "(?P<name>regex)"
|
||||
wsRe = regexp.MustCompile(`\s+`) // Match whitespace, to be compressed during cleaning
|
||||
)
|
||||
|
||||
// documentPaths parses all paths in a framework.Backend into OpenAPI paths.
|
||||
func documentPaths(backend *Backend, requestResponsePrefix string, doc *OASDocument) error {
|
||||
func documentPaths(backend *Backend, requestResponsePrefix string, genericMountPaths bool, doc *OASDocument) error {
|
||||
for _, p := range backend.Paths {
|
||||
if err := documentPath(p, backend.SpecialPaths(), requestResponsePrefix, backend.BackendType, doc); err != nil {
|
||||
if err := documentPath(p, backend.SpecialPaths(), requestResponsePrefix, genericMountPaths, backend.BackendType, doc); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func documentPaths(backend *Backend, requestResponsePrefix string, doc *OASDocum
|
||||
}
|
||||
|
||||
// documentPath parses a framework.Path into one or more OpenAPI paths.
|
||||
func documentPath(p *Path, specialPaths *logical.Paths, requestResponsePrefix string, backendType logical.BackendType, doc *OASDocument) error {
|
||||
func documentPath(p *Path, specialPaths *logical.Paths, requestResponsePrefix string, genericMountPaths bool, backendType logical.BackendType, doc *OASDocument) error {
|
||||
var sudoPaths []string
|
||||
var unauthPaths []string
|
||||
|
||||
@@ -265,21 +265,16 @@ func documentPath(p *Path, specialPaths *logical.Paths, requestResponsePrefix st
|
||||
// Body fields will be added to individual operations.
|
||||
pathFields, bodyFields := splitFields(p.Fields, path)
|
||||
|
||||
defaultMountPath := requestResponsePrefix
|
||||
if requestResponsePrefix == "kv" {
|
||||
defaultMountPath = "secret"
|
||||
}
|
||||
|
||||
if defaultMountPath != "system" && defaultMountPath != "identity" {
|
||||
if genericMountPaths && requestResponsePrefix != "system" && requestResponsePrefix != "identity" {
|
||||
// Add mount path as a parameter
|
||||
p := OASParameter{
|
||||
Name: fmt.Sprintf("%s_mount_path", defaultMountPath),
|
||||
Description: "Path where the backend was mounted; the endpoint path will be offset by the mount path",
|
||||
Name: "mountPath",
|
||||
Description: "Path that the backend was mounted at",
|
||||
In: "path",
|
||||
Schema: &OASSchema{
|
||||
Type: "string",
|
||||
Default: defaultMountPath,
|
||||
Type: "string",
|
||||
},
|
||||
Required: false,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
pi.Parameters = append(pi.Parameters, p)
|
||||
@@ -785,9 +780,6 @@ func cleanResponse(resp *logical.Response) *cleanedResponse {
|
||||
//
|
||||
// An optional user-provided suffix ("context") may also be appended.
|
||||
func (d *OASDocument) CreateOperationIDs(context string) {
|
||||
// title caser
|
||||
title := cases.Title(language.English)
|
||||
|
||||
opIDCount := make(map[string]int)
|
||||
var paths []string
|
||||
|
||||
@@ -814,12 +806,9 @@ func (d *OASDocument) CreateOperationIDs(context string) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Discard "_mount_path" from any {thing_mount_path} parameters
|
||||
path = strings.Replace(path, "_mount_path", "", 1)
|
||||
|
||||
// Space-split on non-words, title case everything, recombine
|
||||
opID := nonWordRe.ReplaceAllString(strings.ToLower(path), " ")
|
||||
opID = title.String(opID)
|
||||
opID = strings.Title(opID)
|
||||
opID = method + strings.ReplaceAll(opID, " ", "")
|
||||
|
||||
// deduplicate operationIds. This is a safeguard, since generated IDs should
|
||||
|
||||
Reference in New Issue
Block a user