Skip to content

Commit

Permalink
Merge pull request #2899 from gravitl/NET-1146
Browse files Browse the repository at this point in the history
NET-1146: add user id check on RAG config creation, track failover usage
  • Loading branch information
abhishek9686 authored Apr 17, 2024
2 parents 8b08ad1 + 001d078 commit 23359ae
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions controllers/ext_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
}
for _, extclient := range extclients {
if extclient.RemoteAccessClientID != "" &&
extclient.RemoteAccessClientID == customExtClient.RemoteAccessClientID && nodeid == extclient.IngressGatewayID {
extclient.RemoteAccessClientID == customExtClient.RemoteAccessClientID && extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
// extclient on the gw already exists for the remote access client
err = errors.New("remote client config already exists on the gateway. it may have been created by another user with this same remote client machine")
err = errors.New("remote client config already exists on the gateway")
slog.Error("failed to create extclient", "user", userName, "error", err)
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
Expand Down
5 changes: 5 additions & 0 deletions controllers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func getUsage(w http.ResponseWriter, _ *http.Request) {
Egresses int `json:"egresses"`
Relays int `json:"relays"`
InternetGateways int `json:"internet_gateways"`
FailOvers int `json:"fail_overs"`
}
var serverUsage usage
hosts, err := logic.GetAllHosts()
Expand Down Expand Up @@ -90,6 +91,10 @@ func getUsage(w http.ResponseWriter, _ *http.Request) {
if err == nil {
serverUsage.InternetGateways = len(gateways)
}
failOvers, err := logic.GetAllFailOvers()
if err == nil {
serverUsage.FailOvers = len(failOvers)
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(models.SuccessResponse{
Code: http.StatusOK,
Expand Down
15 changes: 15 additions & 0 deletions logic/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,18 @@ func ValidateParams(nodeid, netid string) (models.Node, error) {
}
return node, nil
}

// GetAllFailOvers - gets all the nodes that are failovers
func GetAllFailOvers() ([]models.Node, error) {
nodes, err := GetAllNodes()
if err != nil {
return nil, err
}
igs := make([]models.Node, 0)
for _, node := range nodes {
if node.IsFailOver {
igs = append(igs, node)
}
}
return igs, nil
}
1 change: 1 addition & 0 deletions pro/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Usage struct {
Egresses int `json:"egresses"`
Relays int `json:"relays"`
InternetGateways int `json:"internet_gateways"`
FailOvers int `json:"fail_overs"`
}

// Usage.SetDefaults - sets the default values for usage
Expand Down
4 changes: 4 additions & 0 deletions pro/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@ func getCurrentServerUsage() (limits Usage) {
if err == nil {
limits.InternetGateways = len(gateways)
}
failovers, err := logic.GetAllFailOvers()
if err == nil {
limits.FailOvers = len(failovers)
}
return
}

0 comments on commit 23359ae

Please sign in to comment.