Skip to content

Commit

Permalink
Merge pull request #2780 from gravitl/kwesi/net-709-add-metadata-fiel…
Browse files Browse the repository at this point in the history
…d-to-gateway-node

feat(NET-709): add node metadata for remote gateways
  • Loading branch information
abhishek9686 authored Feb 6, 2024
2 parents e685e3c + 5882b86 commit ecd769e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions controllers/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ func updateNode(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
if len(newData.Metadata) > 255 {
logic.ReturnErrorResponse(w, r, logic.FormatError(fmt.Errorf("metadata cannot be longer than 255 characters"), "badrequest"))
return
}
newNode := newData.ConvertToServerNode(&currentNode)
relayUpdate := logic.RelayUpdates(&currentNode, newNode)
_, err = logic.GetHost(newNode.HostID.String())
Expand Down
4 changes: 4 additions & 0 deletions logic/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func CreateIngressGateway(netid string, nodeid string, ingress models.IngressReq
node.IngressGatewayRange6 = network.AddressRange6
node.IngressDNS = ingress.ExtclientDNS
node.SetLastModified()
if node.Metadata == "" {
node.Metadata = "This host can be used for remote access"
}
err = UpsertNode(&node)
if err != nil {
return models.Node{}, err
Expand Down Expand Up @@ -225,6 +228,7 @@ func DeleteIngressGateway(nodeid string) (models.Node, []models.ExtClient, error
node.IsIngressGateway = false
node.IsInternetGateway = false
node.IngressGatewayRange = ""
node.Metadata = ""
err = UpsertNode(&node)
if err != nil {
return models.Node{}, removedClients, err
Expand Down
9 changes: 6 additions & 3 deletions models/api_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
type ApiNode struct {
ID string `json:"id,omitempty" validate:"required,min=5,id_unique"`
HostID string `json:"hostid,omitempty" validate:"required,min=5,id_unique"`
Address string `json:"address" validate:"omitempty,ipv4"`
Address6 string `json:"address6" validate:"omitempty,ipv6"`
LocalAddress string `json:"localaddress" validate:"omitempty,ipv4"`
Address string `json:"address" validate:"omitempty,cidrv4"`
Address6 string `json:"address6" validate:"omitempty,cidrv6"`
LocalAddress string `json:"localaddress" validate:"omitempty,cidr"`
AllowedIPs []string `json:"allowedips"`
LastModified int64 `json:"lastmodified"`
ExpirationDateTime int64 `json:"expdatetime"`
Expand All @@ -37,6 +37,7 @@ type ApiNode struct {
InternetGateway string `json:"internetgateway"`
Connected bool `json:"connected"`
PendingDelete bool `json:"pendingdelete"`
Metadata string `json:"metadata" validate:"max=256"`
// == PRO ==
DefaultACL string `json:"defaultacl,omitempty" validate:"checkyesornoorunset"`
IsFailOver bool `json:"is_fail_over"`
Expand Down Expand Up @@ -104,6 +105,7 @@ func (a *ApiNode) ConvertToServerNode(currentNode *Node) *Node {
convertedNode.LastCheckIn = time.Unix(a.LastCheckIn, 0)
convertedNode.LastPeerUpdate = time.Unix(a.LastPeerUpdate, 0)
convertedNode.ExpirationDateTime = time.Unix(a.ExpirationDateTime, 0)
convertedNode.Metadata = a.Metadata
return &convertedNode
}

Expand Down Expand Up @@ -158,6 +160,7 @@ func (nm *Node) ConvertToAPINode() *ApiNode {
apiNode.IsFailOver = nm.IsFailOver
apiNode.FailOverPeers = nm.FailOverPeers
apiNode.FailedOverBy = nm.FailedOverBy
apiNode.Metadata = nm.Metadata
return &apiNode
}

Expand Down
1 change: 1 addition & 0 deletions models/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Node struct {
EgressGatewayRequest EgressGatewayRequest `json:"egressgatewayrequest" bson:"egressgatewayrequest" yaml:"egressgatewayrequest"`
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
IngressGatewayRange6 string `json:"ingressgatewayrange6" bson:"ingressgatewayrange6" yaml:"ingressgatewayrange6"`
Metadata string `json:"metadata"`
// == PRO ==
DefaultACL string `json:"defaultacl,omitempty" bson:"defaultacl,omitempty" yaml:"defaultacl,omitempty" validate:"checkyesornoorunset"`
OwnerID string `json:"ownerid,omitempty" bson:"ownerid,omitempty" yaml:"ownerid,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions models/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type UserRemoteGws struct {
IsInternetGateway bool `json:"is_internet_gateway"`
GwClient ExtClient `json:"gw_client"`
GwPeerPublicKey string `json:"gw_peer_public_key"`
Metadata string `json:"metadata"`
}

// UserRemoteGwsReq - struct to hold user remote acccess gws req
Expand Down
4 changes: 4 additions & 0 deletions pro/controllers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func getUserRemoteAccessGws(w http.ResponseWriter, r *http.Request) {
Connected: true,
IsInternetGateway: node.IsInternetGateway,
GwPeerPublicKey: host.PublicKey.String(),
Metadata: node.Metadata,
})
userGws[node.Network] = gws
delete(user.RemoteGwIDs, node.ID.String())
Expand All @@ -226,6 +227,7 @@ func getUserRemoteAccessGws(w http.ResponseWriter, r *http.Request) {
Connected: true,
IsInternetGateway: node.IsInternetGateway,
GwPeerPublicKey: host.PublicKey.String(),
Metadata: node.Metadata,
})
userGws[node.Network] = gws
processedAdminNodeIds[node.ID.String()] = struct{}{}
Expand Down Expand Up @@ -258,6 +260,7 @@ func getUserRemoteAccessGws(w http.ResponseWriter, r *http.Request) {
Network: node.Network,
IsInternetGateway: node.IsInternetGateway,
GwPeerPublicKey: host.PublicKey.String(),
Metadata: node.Metadata,
})
userGws[node.Network] = gws
}
Expand All @@ -284,6 +287,7 @@ func getUserRemoteAccessGws(w http.ResponseWriter, r *http.Request) {
Network: node.Network,
IsInternetGateway: node.IsInternetGateway,
GwPeerPublicKey: host.PublicKey.String(),
Metadata: node.Metadata,
})
userGws[node.Network] = gws
}
Expand Down

0 comments on commit ecd769e

Please sign in to comment.