Fix ACL, host and node swagger API definitions (#2864)

* Fix get all hosts response swagger type

* Remove body parameter from GET ACL request

* Use ApiNode response in requests that return it

* Redact net.Address field from API Iface

This field doesn't get declared correctly in the swagger file, and seems to break clients

* Re-generate swagger

swagger generate spec -t ee -o swagger.yml
This commit is contained in:
Jonathan Roth 2024-04-03 12:37:20 +03:00 committed by GitHub
parent 0d4552db5e
commit 80e775d5b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 185 additions and 35 deletions

View file

@ -49,6 +49,12 @@ type hasAdmin struct {
Admin bool Admin bool
} }
// swagger:response apiHostSliceResponse
type apiHostSliceResponse struct {
// in: body
Host []models.ApiHost
}
// swagger:response apiHostResponse // swagger:response apiHostResponse
type apiHostResponse struct { type apiHostResponse struct {
// in: body // in: body
@ -251,7 +257,7 @@ type networkBodyResponse struct {
Network models.Network `json:"network"` Network models.Network `json:"network"`
} }
// swagger:parameters updateNetworkACL getNetworkACL // swagger:parameters updateNetworkACL
type aclContainerBodyParam struct { type aclContainerBodyParam struct {
// ACL Container // ACL Container
// in: body // in: body
@ -269,7 +275,7 @@ type aclContainerResponse struct {
type nodeSliceResponse struct { type nodeSliceResponse struct {
// Nodes // Nodes
// in: body // in: body
Nodes []models.LegacyNode `json:"nodes"` Nodes []models.ApiNode `json:"nodes"`
} }
// swagger:response nodeResponse // swagger:response nodeResponse
@ -453,6 +459,7 @@ func useUnused() bool {
_ = userAuthBodyParam{} _ = userAuthBodyParam{}
_ = usernamePathParam{} _ = usernamePathParam{}
_ = hasAdmin{} _ = hasAdmin{}
_ = apiHostSliceResponse{}
_ = apiHostResponse{} _ = apiHostResponse{}
_ = fileResponse{} _ = fileResponse{}
_ = extClientConfParams{} _ = extClientConfParams{}

View file

@ -62,7 +62,7 @@ func upgradeHost(w http.ResponseWriter, r *http.Request) {
// oauth // oauth
// //
// Responses: // Responses:
// 200: apiHostResponse // 200: apiHostSliceResponse
func getHosts(w http.ResponseWriter, r *http.Request) { func getHosts(w http.ResponseWriter, r *http.Request) {
currentHosts, err := logic.GetAllHosts() currentHosts, err := logic.GetAllHosts()
if err != nil { if err != nil {

View file

@ -8,27 +8,34 @@ import (
// ApiHost - the host struct for API usage // ApiHost - the host struct for API usage
type ApiHost struct { type ApiHost struct {
ID string `json:"id"` ID string `json:"id"`
Verbosity int `json:"verbosity"` Verbosity int `json:"verbosity"`
FirewallInUse string `json:"firewallinuse"` FirewallInUse string `json:"firewallinuse"`
Version string `json:"version"` Version string `json:"version"`
Name string `json:"name"` Name string `json:"name"`
OS string `json:"os"` OS string `json:"os"`
Debug bool `json:"debug"` Debug bool `json:"debug"`
IsStatic bool `json:"isstatic"` IsStatic bool `json:"isstatic"`
ListenPort int `json:"listenport"` ListenPort int `json:"listenport"`
WgPublicListenPort int `json:"wg_public_listen_port" yaml:"wg_public_listen_port"` WgPublicListenPort int `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
MTU int `json:"mtu" yaml:"mtu"` MTU int `json:"mtu" yaml:"mtu"`
Interfaces []Iface `json:"interfaces" yaml:"interfaces"` Interfaces []ApiIface `json:"interfaces" yaml:"interfaces"`
DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"` DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
EndpointIP string `json:"endpointip" yaml:"endpointip"` EndpointIP string `json:"endpointip" yaml:"endpointip"`
PublicKey string `json:"publickey"` PublicKey string `json:"publickey"`
MacAddress string `json:"macaddress"` MacAddress string `json:"macaddress"`
Nodes []string `json:"nodes"` Nodes []string `json:"nodes"`
IsDefault bool `json:"isdefault" yaml:"isdefault"` IsDefault bool `json:"isdefault" yaml:"isdefault"`
NatType string `json:"nat_type" yaml:"nat_type"` NatType string `json:"nat_type" yaml:"nat_type"`
PersistentKeepalive int `json:"persistentkeepalive" yaml:"persistentkeepalive"` PersistentKeepalive int `json:"persistentkeepalive" yaml:"persistentkeepalive"`
AutoUpdate bool `json:"autoupdate" yaml:"autoupdate"` AutoUpdate bool `json:"autoupdate" yaml:"autoupdate"`
}
// ApiIface - the interface struct for API usage
// The original Iface struct contains a net.Address, which does not get marshalled correctly
type ApiIface struct {
Name string `json:"name"`
AddressString string `json:"addressString"`
} }
// Host.ConvertNMHostToAPI - converts a Netmaker host to an API editable host // Host.ConvertNMHostToAPI - converts a Netmaker host to an API editable host
@ -38,9 +45,12 @@ func (h *Host) ConvertNMHostToAPI() *ApiHost {
a.EndpointIP = h.EndpointIP.String() a.EndpointIP = h.EndpointIP.String()
a.FirewallInUse = h.FirewallInUse a.FirewallInUse = h.FirewallInUse
a.ID = h.ID.String() a.ID = h.ID.String()
a.Interfaces = h.Interfaces a.Interfaces = make([]ApiIface, len(h.Interfaces))
for i := range a.Interfaces { for i := range a.Interfaces {
a.Interfaces[i].AddressString = a.Interfaces[i].Address.String() a.Interfaces[i] = ApiIface{
Name: h.Interfaces[i].Name,
AddressString: h.Interfaces[i].Address.String(),
}
} }
a.DefaultInterface = h.DefaultInterface a.DefaultInterface = h.DefaultInterface
a.IsStatic = h.IsStatic a.IsStatic = h.IsStatic

View file

@ -69,7 +69,7 @@ definitions:
x-go-name: ID x-go-name: ID
interfaces: interfaces:
items: items:
$ref: '#/definitions/Iface' $ref: '#/definitions/ApiIface'
type: array type: array
x-go-name: Interfaces x-go-name: Interfaces
isdefault: isdefault:
@ -123,6 +123,139 @@ definitions:
x-go-name: WgPublicListenPort x-go-name: WgPublicListenPort
type: object type: object
x-go-package: github.com/gravitl/netmaker/models x-go-package: github.com/gravitl/netmaker/models
ApiIface:
description: |-
ApiIface - the interface struct for API usage
The original Iface struct contains a net.Address, which does not get marshalled correctly
properties:
addressString:
type: string
x-go-name: AddressString
name:
type: string
x-go-name: Name
type: object
x-go-package: github.com/gravitl/netmaker/models
ApiNode:
description: ApiNode is a stripped down Node DTO that exposes only required fields to external systems
properties:
address:
type: string
x-go-name: Address
address6:
type: string
x-go-name: Address6
allowedips:
items:
type: string
type: array
x-go-name: AllowedIPs
connected:
type: boolean
x-go-name: Connected
defaultacl:
description: == PRO ==
type: string
x-go-name: DefaultACL
dnson:
type: boolean
x-go-name: DNSOn
egressgatewaynatenabled:
type: boolean
x-go-name: EgressGatewayNatEnabled
egressgatewayranges:
items:
type: string
type: array
x-go-name: EgressGatewayRanges
expdatetime:
format: int64
type: integer
x-go-name: ExpirationDateTime
fail_over_peers:
additionalProperties:
type: object
type: object
x-go-name: FailOverPeers
failed_over_by:
format: uuid
type: string
x-go-name: FailedOverBy
hostid:
type: string
x-go-name: HostID
id:
type: string
x-go-name: ID
inet_node_req:
$ref: '#/definitions/InetNodeReq'
ingressdns:
type: string
x-go-name: IngressDns
internetgw_node_id:
type: string
x-go-name: InternetGwID
is_fail_over:
type: boolean
x-go-name: IsFailOver
isegressgateway:
type: boolean
x-go-name: IsEgressGateway
isingressgateway:
type: boolean
x-go-name: IsIngressGateway
isinternetgateway:
type: boolean
x-go-name: IsInternetGateway
isrelay:
type: boolean
x-go-name: IsRelay
isrelayed:
type: boolean
x-go-name: IsRelayed
lastcheckin:
format: int64
type: integer
x-go-name: LastCheckIn
lastmodified:
format: int64
type: integer
x-go-name: LastModified
lastpeerupdate:
format: int64
type: integer
x-go-name: LastPeerUpdate
localaddress:
type: string
x-go-name: LocalAddress
metadata:
type: string
x-go-name: Metadata
network:
type: string
x-go-name: Network
networkrange:
type: string
x-go-name: NetworkRange
networkrange6:
type: string
x-go-name: NetworkRange6
pendingdelete:
type: boolean
x-go-name: PendingDelete
relayedby:
type: string
x-go-name: RelayedBy
relaynodes:
items:
type: string
type: array
x-go-name: RelayedNodes
server:
type: string
x-go-name: Server
type: object
x-go-package: github.com/gravitl/netmaker/models
AuthParams: AuthParams:
description: AuthParams - struct for auth params description: AuthParams - struct for auth params
properties: properties:
@ -1642,7 +1775,7 @@ paths:
operationId: getHosts operationId: getHosts
responses: responses:
"200": "200":
$ref: '#/responses/apiHostResponse' $ref: '#/responses/apiHostSliceResponse'
schemes: schemes:
- https - https
summary: Lists all hosts. summary: Lists all hosts.
@ -1902,12 +2035,6 @@ paths:
required: true required: true
type: string type: string
x-go-name: Networkname x-go-name: Networkname
- description: ACL Container
in: body
name: acl_container
schema:
$ref: '#/definitions/ACLContainer'
x-go-name: ACLContainer
responses: responses:
"200": "200":
$ref: '#/responses/aclContainerResponse' $ref: '#/responses/aclContainerResponse'
@ -2725,6 +2852,12 @@ responses:
description: "" description: ""
schema: schema:
$ref: '#/definitions/ApiHost' $ref: '#/definitions/ApiHost'
apiHostSliceResponse:
description: ""
schema:
items:
$ref: '#/definitions/ApiHost'
type: array
byteArrayResponse: byteArrayResponse:
description: "" description: ""
schema: schema:
@ -2776,7 +2909,7 @@ responses:
description: "" description: ""
schema: schema:
items: items:
$ref: '#/definitions/LegacyNode' $ref: '#/definitions/ApiNode'
type: array type: array
okResponse: okResponse:
description: "" description: ""