mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-10 18:38:22 +00:00
Add Static Route API
This commit is contained in:
parent
4770ac7384
commit
a737ac4d9d
1 changed files with 59 additions and 0 deletions
59
internal/api/network/static_routes.go
Normal file
59
internal/api/network/static_routes.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"nfsense.net/nfsense/internal/definitions"
|
||||
)
|
||||
|
||||
type GetStaticRoutesResult struct {
|
||||
StaticRoutes []definitions.StaticRoute
|
||||
}
|
||||
|
||||
func (f *Network) GetStaticRoutes(ctx context.Context, params struct{}) (GetStaticRoutesResult, error) {
|
||||
return GetStaticRoutesResult{
|
||||
StaticRoutes: f.ConfigManager.GetPendingConfig().Network.StaticRoutes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *Network) CreateStaticRoute(ctx context.Context, params definitions.StaticRoute) (struct{}, error) {
|
||||
t, conf := f.ConfigManager.StartTransaction()
|
||||
defer t.Discard()
|
||||
|
||||
conf.Network.StaticRoutes = append(conf.Network.StaticRoutes, params)
|
||||
return struct{}{}, t.Commit()
|
||||
}
|
||||
|
||||
type UpdateStaticRouteParameters struct {
|
||||
Index uint
|
||||
definitions.StaticRoute
|
||||
}
|
||||
|
||||
func (f *Network) UpdateStaticRoute(ctx context.Context, params UpdateStaticRouteParameters) (struct{}, error) {
|
||||
if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.DestinationNATRules) {
|
||||
return struct{}{}, fmt.Errorf("StaticRoute does not Exist")
|
||||
}
|
||||
|
||||
t, conf := f.ConfigManager.StartTransaction()
|
||||
defer t.Discard()
|
||||
|
||||
conf.Network.StaticRoutes = append(conf.Network.StaticRoutes, params.StaticRoute)
|
||||
return struct{}{}, t.Commit()
|
||||
}
|
||||
|
||||
type DeleteStaticRouteParameters struct {
|
||||
Index uint
|
||||
}
|
||||
|
||||
func (f *Network) DeleteStaticRoute(ctx context.Context, params DeleteStaticRouteParameters) (struct{}, error) {
|
||||
if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.DestinationNATRules) {
|
||||
return struct{}{}, fmt.Errorf("StaticRoute does not Exist")
|
||||
}
|
||||
|
||||
t, conf := f.ConfigManager.StartTransaction()
|
||||
defer t.Discard()
|
||||
|
||||
conf.Network.StaticRoutes = append(conf.Network.StaticRoutes[:params.Index], conf.Network.StaticRoutes[params.Index+1:]...)
|
||||
return struct{}{}, t.Commit()
|
||||
}
|
Loading…
Add table
Reference in a new issue