mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-19 13:19:06 +02:00
[client] UI refactor (#6069)
Refactor UI --------- Co-authored-by: Eduard Gert <kontakt@eduardgert.de> Co-authored-by: braginini <bangvalo@gmail.com> Co-authored-by: Pascal Fischer <32096965+pascal-fischer@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: riccardom <riccardomanfrin@gmail.com>
This commit is contained in:
co-authored by
Eduard Gert
braginini
Pascal Fischer
Claude
riccardom
parent
679c7182a4
commit
8b7ce337d8
@@ -0,0 +1,88 @@
|
||||
//go:build !android && !ios && !freebsd && !js
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/netbirdio/netbird/client/proto"
|
||||
)
|
||||
|
||||
type Network struct {
|
||||
ID string `json:"id"`
|
||||
Range string `json:"range"`
|
||||
Selected bool `json:"selected"`
|
||||
Domains []string `json:"domains"`
|
||||
ResolvedIPs map[string][]string `json:"resolvedIps"`
|
||||
}
|
||||
|
||||
// SelectNetworksParams: All targets every available network; Append merges IDs into the existing selection.
|
||||
type SelectNetworksParams struct {
|
||||
NetworkIDs []string `json:"networkIds"`
|
||||
Append bool `json:"append"`
|
||||
All bool `json:"all"`
|
||||
}
|
||||
|
||||
type Networks struct {
|
||||
conn DaemonConn
|
||||
}
|
||||
|
||||
func NewNetworks(conn DaemonConn) *Networks {
|
||||
return &Networks{conn: conn}
|
||||
}
|
||||
|
||||
func (s *Networks) List(ctx context.Context) ([]Network, error) {
|
||||
cli, err := s.conn.Client()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := cli.ListNetworks(ctx, &proto.ListNetworksRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]Network, 0, len(resp.GetRoutes()))
|
||||
for _, n := range resp.GetRoutes() {
|
||||
out = append(out, networkFromProto(n))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *Networks) Select(ctx context.Context, p SelectNetworksParams) error {
|
||||
cli, err := s.conn.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = cli.SelectNetworks(ctx, &proto.SelectNetworksRequest{
|
||||
NetworkIDs: p.NetworkIDs,
|
||||
Append: p.Append,
|
||||
All: p.All,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Networks) Deselect(ctx context.Context, p SelectNetworksParams) error {
|
||||
cli, err := s.conn.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = cli.DeselectNetworks(ctx, &proto.SelectNetworksRequest{
|
||||
NetworkIDs: p.NetworkIDs,
|
||||
Append: p.Append,
|
||||
All: p.All,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func networkFromProto(n *proto.Network) Network {
|
||||
resolved := make(map[string][]string, len(n.GetResolvedIPs()))
|
||||
for k, v := range n.GetResolvedIPs() {
|
||||
resolved[k] = append([]string{}, v.GetIps()...)
|
||||
}
|
||||
return Network{
|
||||
ID: n.GetID(),
|
||||
Range: n.GetRange(),
|
||||
Selected: n.GetSelected(),
|
||||
Domains: append([]string{}, n.GetDomains()...),
|
||||
ResolvedIPs: resolved,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user