2020-12-22 02:06:46 +00:00
|
|
|
package tunnel
|
|
|
|
|
|
|
|
import (
|
2020-12-29 17:51:42 +00:00
|
|
|
"net"
|
|
|
|
|
2020-12-22 02:06:46 +00:00
|
|
|
"github.com/cloudflare/cloudflared/teamnet"
|
2020-12-29 17:51:42 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-12-22 02:06:46 +00:00
|
|
|
)
|
|
|
|
|
2020-12-29 17:51:42 +00:00
|
|
|
const noClientMsg = "error while creating backend client"
|
|
|
|
|
2020-12-22 02:06:46 +00:00
|
|
|
func (sc *subcommandContext) listRoutes(filter *teamnet.Filter) ([]*teamnet.Route, error) {
|
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
2020-12-29 17:51:42 +00:00
|
|
|
return nil, errors.Wrap(err, noClientMsg)
|
2020-12-22 02:06:46 +00:00
|
|
|
}
|
|
|
|
return client.ListRoutes(filter)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sc *subcommandContext) addRoute(newRoute teamnet.NewRoute) (teamnet.Route, error) {
|
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
2020-12-29 17:51:42 +00:00
|
|
|
return teamnet.Route{}, errors.Wrap(err, noClientMsg)
|
2020-12-22 02:06:46 +00:00
|
|
|
}
|
|
|
|
return client.AddRoute(newRoute)
|
|
|
|
}
|
2020-12-29 17:51:42 +00:00
|
|
|
|
|
|
|
func (sc *subcommandContext) deleteRoute(network net.IPNet) error {
|
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, noClientMsg)
|
|
|
|
}
|
|
|
|
return client.DeleteRoute(network)
|
|
|
|
}
|