2020-12-22 02:06:46 +00:00
|
|
|
package tunnel
|
|
|
|
|
|
|
|
import (
|
2020-12-29 17:51:42 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-03-23 14:30:43 +00:00
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/teamnet"
|
2020-12-22 02:06:46 +00:00
|
|
|
)
|
|
|
|
|
2020-12-29 17:51:42 +00:00
|
|
|
const noClientMsg = "error while creating backend client"
|
|
|
|
|
2021-01-05 23:55:18 +00:00
|
|
|
func (sc *subcommandContext) listRoutes(filter *teamnet.Filter) ([]*teamnet.DetailedRoute, error) {
|
2020-12-22 02:06:46 +00:00
|
|
|
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
|
|
|
|
2021-11-29 12:00:31 +00:00
|
|
|
func (sc *subcommandContext) deleteRoute(params teamnet.DeleteRouteParams) error {
|
2020-12-29 17:51:42 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, noClientMsg)
|
|
|
|
}
|
2021-11-29 12:00:31 +00:00
|
|
|
return client.DeleteRoute(params)
|
2020-12-29 17:51:42 +00:00
|
|
|
}
|
2021-01-05 23:55:18 +00:00
|
|
|
|
2021-11-29 12:00:31 +00:00
|
|
|
func (sc *subcommandContext) getRouteByIP(params teamnet.GetRouteByIpParams) (teamnet.DetailedRoute, error) {
|
2021-01-05 23:55:18 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
|
|
|
return teamnet.DetailedRoute{}, errors.Wrap(err, noClientMsg)
|
|
|
|
}
|
2021-11-29 12:00:31 +00:00
|
|
|
return client.GetByIP(params)
|
2021-01-05 23:55:18 +00:00
|
|
|
}
|