Skip to content

Commit

Permalink
feat(NET-709): add node metadata for remote gws
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceix committed Jan 25, 2024
1 parent 058338f commit 83d83f6
Show file tree
Hide file tree
Showing 4 changed files with 15 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 @@ -635,6 +635,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 @@ -174,6 +174,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 @@ -224,6 +227,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

0 comments on commit 83d83f6

Please sign in to comment.