Changed policy API to receive name param in query instead or URL (#591)

Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
Alex
2021-02-04 17:57:10 -06:00
committed by GitHub
parent 1c6a29bc20
commit ee1a6718d7
10 changed files with 80 additions and 58 deletions

View File

@@ -49,7 +49,7 @@ const DeletePolicy = ({
} }
setDeleteLoading(true); setDeleteLoading(true);
api api
.invoke("DELETE", `/api/v1/policies/${selectedPolicy}`) .invoke("DELETE", `/api/v1/policy?name=${selectedPolicy}`)
.then((res: PolicyList) => { .then((res: PolicyList) => {
setDeleteLoading(false); setDeleteLoading(false);

View File

@@ -2263,7 +2263,7 @@ func init() {
} }
} }
}, },
"/policies/{name}": { "/policy": {
"get": { "get": {
"tags": [ "tags": [
"AdminAPI" "AdminAPI"
@@ -2274,7 +2274,7 @@ func init() {
{ {
"type": "string", "type": "string",
"name": "name", "name": "name",
"in": "path", "in": "query",
"required": true "required": true
} }
], ],
@@ -2303,7 +2303,7 @@ func init() {
{ {
"type": "string", "type": "string",
"name": "name", "name": "name",
"in": "path", "in": "query",
"required": true "required": true
} }
], ],
@@ -7735,7 +7735,7 @@ func init() {
} }
} }
}, },
"/policies/{name}": { "/policy": {
"get": { "get": {
"tags": [ "tags": [
"AdminAPI" "AdminAPI"
@@ -7746,7 +7746,7 @@ func init() {
{ {
"type": "string", "type": "string",
"name": "name", "name": "name",
"in": "path", "in": "query",
"required": true "required": true
} }
], ],
@@ -7775,7 +7775,7 @@ func init() {
{ {
"type": "string", "type": "string",
"name": "name", "name": "name",
"in": "path", "in": "query",
"required": true "required": true
} }
], ],

View File

@@ -48,7 +48,7 @@ func NewPolicyInfo(ctx *middleware.Context, handler PolicyInfoHandler) *PolicyIn
return &PolicyInfo{Context: ctx, Handler: handler} return &PolicyInfo{Context: ctx, Handler: handler}
} }
/*PolicyInfo swagger:route GET /policies/{name} AdminAPI policyInfo /*PolicyInfo swagger:route GET /policy AdminAPI policyInfo
Policy info Policy info

View File

@@ -26,8 +26,10 @@ import (
"net/http" "net/http"
"github.com/go-openapi/errors" "github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware" "github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
"github.com/go-openapi/validate"
) )
// NewPolicyInfoParams creates a new PolicyInfoParams object // NewPolicyInfoParams creates a new PolicyInfoParams object
@@ -48,7 +50,7 @@ type PolicyInfoParams struct {
/* /*
Required: true Required: true
In: path In: query
*/ */
Name string Name string
} }
@@ -62,8 +64,10 @@ func (o *PolicyInfoParams) BindRequest(r *http.Request, route *middleware.Matche
o.HTTPRequest = r o.HTTPRequest = r
rName, rhkName, _ := route.Params.GetOK("name") qs := runtime.Values(r.URL.Query())
if err := o.bindName(rName, rhkName, route.Formats); err != nil {
qName, qhkName, _ := qs.GetOK("name")
if err := o.bindName(qName, qhkName, route.Formats); err != nil {
res = append(res, err) res = append(res, err)
} }
@@ -73,15 +77,21 @@ func (o *PolicyInfoParams) BindRequest(r *http.Request, route *middleware.Matche
return nil return nil
} }
// bindName binds and validates parameter Name from path. // bindName binds and validates parameter Name from query.
func (o *PolicyInfoParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { func (o *PolicyInfoParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("name", "query", rawData)
}
var raw string var raw string
if len(rawData) > 0 { if len(rawData) > 0 {
raw = rawData[len(rawData)-1] raw = rawData[len(rawData)-1]
} }
// Required: true // Required: true
// Parameter is provided by construction from the route // AllowEmptyValue: false
if err := validate.RequiredString("name", "query", raw); err != nil {
return err
}
o.Name = raw o.Name = raw

View File

@@ -26,7 +26,6 @@ import (
"errors" "errors"
"net/url" "net/url"
golangswaggerpaths "path" golangswaggerpaths "path"
"strings"
) )
// PolicyInfoURL generates an URL for the policy info operation // PolicyInfoURL generates an URL for the policy info operation
@@ -57,14 +56,7 @@ func (o *PolicyInfoURL) SetBasePath(bp string) {
func (o *PolicyInfoURL) Build() (*url.URL, error) { func (o *PolicyInfoURL) Build() (*url.URL, error) {
var _result url.URL var _result url.URL
var _path = "/policies/{name}" var _path = "/policy"
name := o.Name
if name != "" {
_path = strings.Replace(_path, "{name}", name, -1)
} else {
return nil, errors.New("name is required on PolicyInfoURL")
}
_basePath := o._basePath _basePath := o._basePath
if _basePath == "" { if _basePath == "" {
@@ -72,6 +64,15 @@ func (o *PolicyInfoURL) Build() (*url.URL, error) {
} }
_result.Path = golangswaggerpaths.Join(_basePath, _path) _result.Path = golangswaggerpaths.Join(_basePath, _path)
qs := make(url.Values)
nameQ := o.Name
if nameQ != "" {
qs.Set("name", nameQ)
}
_result.RawQuery = qs.Encode()
return &_result, nil return &_result, nil
} }

View File

@@ -48,7 +48,7 @@ func NewRemovePolicy(ctx *middleware.Context, handler RemovePolicyHandler) *Remo
return &RemovePolicy{Context: ctx, Handler: handler} return &RemovePolicy{Context: ctx, Handler: handler}
} }
/*RemovePolicy swagger:route DELETE /policies/{name} AdminAPI removePolicy /*RemovePolicy swagger:route DELETE /policy AdminAPI removePolicy
Remove policy Remove policy

View File

@@ -26,8 +26,10 @@ import (
"net/http" "net/http"
"github.com/go-openapi/errors" "github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware" "github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
"github.com/go-openapi/validate"
) )
// NewRemovePolicyParams creates a new RemovePolicyParams object // NewRemovePolicyParams creates a new RemovePolicyParams object
@@ -48,7 +50,7 @@ type RemovePolicyParams struct {
/* /*
Required: true Required: true
In: path In: query
*/ */
Name string Name string
} }
@@ -62,8 +64,10 @@ func (o *RemovePolicyParams) BindRequest(r *http.Request, route *middleware.Matc
o.HTTPRequest = r o.HTTPRequest = r
rName, rhkName, _ := route.Params.GetOK("name") qs := runtime.Values(r.URL.Query())
if err := o.bindName(rName, rhkName, route.Formats); err != nil {
qName, qhkName, _ := qs.GetOK("name")
if err := o.bindName(qName, qhkName, route.Formats); err != nil {
res = append(res, err) res = append(res, err)
} }
@@ -73,15 +77,21 @@ func (o *RemovePolicyParams) BindRequest(r *http.Request, route *middleware.Matc
return nil return nil
} }
// bindName binds and validates parameter Name from path. // bindName binds and validates parameter Name from query.
func (o *RemovePolicyParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { func (o *RemovePolicyParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("name", "query", rawData)
}
var raw string var raw string
if len(rawData) > 0 { if len(rawData) > 0 {
raw = rawData[len(rawData)-1] raw = rawData[len(rawData)-1]
} }
// Required: true // Required: true
// Parameter is provided by construction from the route // AllowEmptyValue: false
if err := validate.RequiredString("name", "query", raw); err != nil {
return err
}
o.Name = raw o.Name = raw

View File

@@ -26,7 +26,6 @@ import (
"errors" "errors"
"net/url" "net/url"
golangswaggerpaths "path" golangswaggerpaths "path"
"strings"
) )
// RemovePolicyURL generates an URL for the remove policy operation // RemovePolicyURL generates an URL for the remove policy operation
@@ -57,14 +56,7 @@ func (o *RemovePolicyURL) SetBasePath(bp string) {
func (o *RemovePolicyURL) Build() (*url.URL, error) { func (o *RemovePolicyURL) Build() (*url.URL, error) {
var _result url.URL var _result url.URL
var _path = "/policies/{name}" var _path = "/policy"
name := o.Name
if name != "" {
_path = strings.Replace(_path, "{name}", name, -1)
} else {
return nil, errors.New("name is required on RemovePolicyURL")
}
_basePath := o._basePath _basePath := o._basePath
if _basePath == "" { if _basePath == "" {
@@ -72,6 +64,15 @@ func (o *RemovePolicyURL) Build() (*url.URL, error) {
} }
_result.Path = golangswaggerpaths.Join(_basePath, _path) _result.Path = golangswaggerpaths.Join(_basePath, _path)
qs := make(url.Values)
nameQ := o.Name
if nameQ != "" {
qs.Set("name", nameQ)
}
_result.RawQuery = qs.Encode()
return &_result, nil return &_result, nil
} }

View File

@@ -1225,7 +1225,7 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["GET"] == nil { if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler) o.handlers["GET"] = make(map[string]http.Handler)
} }
o.handlers["GET"]["/policies/{name}"] = admin_api.NewPolicyInfo(o.context, o.AdminAPIPolicyInfoHandler) o.handlers["GET"]["/policy"] = admin_api.NewPolicyInfo(o.context, o.AdminAPIPolicyInfoHandler)
if o.handlers["POST"] == nil { if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler) o.handlers["POST"] = make(map[string]http.Handler)
} }
@@ -1261,7 +1261,7 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["DELETE"] == nil { if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler) o.handlers["DELETE"] = make(map[string]http.Handler)
} }
o.handlers["DELETE"]["/policies/{name}"] = admin_api.NewRemovePolicy(o.context, o.AdminAPIRemovePolicyHandler) o.handlers["DELETE"]["/policy"] = admin_api.NewRemovePolicy(o.context, o.AdminAPIRemovePolicyHandler)
if o.handlers["DELETE"] == nil { if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler) o.handlers["DELETE"] = make(map[string]http.Handler)
} }

View File

@@ -1234,30 +1234,13 @@ paths:
tags: tags:
- AdminAPI - AdminAPI
/policies/{name}: /policy:
delete:
summary: Remove policy
operationId: RemovePolicy
parameters:
- name: name
in: path
required: true
type: string
responses:
204:
description: A successful response.
default:
description: Generic error response.
schema:
$ref: "#/definitions/error"
tags:
- AdminAPI
get: get:
summary: Policy info summary: Policy info
operationId: PolicyInfo operationId: PolicyInfo
parameters: parameters:
- name: name - name: name
in: path in: query
required: true required: true
type: string type: string
responses: responses:
@@ -1271,6 +1254,23 @@ paths:
$ref: "#/definitions/error" $ref: "#/definitions/error"
tags: tags:
- AdminAPI - AdminAPI
delete:
summary: Remove policy
operationId: RemovePolicy
parameters:
- name: name
in: query
required: true
type: string
responses:
204:
description: A successful response.
default:
description: Generic error response.
schema:
$ref: "#/definitions/error"
tags:
- AdminAPI
/configs: /configs:
get: get: