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);
api
.invoke("DELETE", `/api/v1/policies/${selectedPolicy}`)
.invoke("DELETE", `/api/v1/policy?name=${selectedPolicy}`)
.then((res: PolicyList) => {
setDeleteLoading(false);

View File

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

View File

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

View File

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

View File

@@ -26,7 +26,6 @@ import (
"errors"
"net/url"
golangswaggerpaths "path"
"strings"
)
// 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) {
var _result url.URL
var _path = "/policies/{name}"
name := o.Name
if name != "" {
_path = strings.Replace(_path, "{name}", name, -1)
} else {
return nil, errors.New("name is required on PolicyInfoURL")
}
var _path = "/policy"
_basePath := o._basePath
if _basePath == "" {
@@ -72,6 +64,15 @@ func (o *PolicyInfoURL) Build() (*url.URL, error) {
}
_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
}

View File

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

View File

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

View File

@@ -26,7 +26,6 @@ import (
"errors"
"net/url"
golangswaggerpaths "path"
"strings"
)
// 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) {
var _result url.URL
var _path = "/policies/{name}"
name := o.Name
if name != "" {
_path = strings.Replace(_path, "{name}", name, -1)
} else {
return nil, errors.New("name is required on RemovePolicyURL")
}
var _path = "/policy"
_basePath := o._basePath
if _basePath == "" {
@@ -72,6 +64,15 @@ func (o *RemovePolicyURL) Build() (*url.URL, error) {
}
_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
}

View File

@@ -1225,7 +1225,7 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["GET"] == nil {
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 {
o.handlers["POST"] = make(map[string]http.Handler)
}
@@ -1261,7 +1261,7 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["DELETE"] == nil {
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 {
o.handlers["DELETE"] = make(map[string]http.Handler)
}

View File

@@ -1234,30 +1234,13 @@ paths:
tags:
- AdminAPI
/policies/{name}:
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
/policy:
get:
summary: Policy info
operationId: PolicyInfo
parameters:
- name: name
in: path
in: query
required: true
type: string
responses:
@@ -1271,6 +1254,23 @@ paths:
$ref: "#/definitions/error"
tags:
- 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:
get: