2021-11-26 12:37:54 +00:00
|
|
|
package tunnel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
"github.com/cloudflare/cloudflared/cfapi"
|
2021-11-26 12:37:54 +00:00
|
|
|
)
|
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
func (sc *subcommandContext) addVirtualNetwork(newVnet cfapi.NewVirtualNetwork) (cfapi.VirtualNetwork, error) {
|
2021-11-26 12:37:54 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
2021-12-27 14:56:50 +00:00
|
|
|
return cfapi.VirtualNetwork{}, errors.Wrap(err, noClientMsg)
|
2021-11-26 12:37:54 +00:00
|
|
|
}
|
|
|
|
return client.CreateVirtualNetwork(newVnet)
|
|
|
|
}
|
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
func (sc *subcommandContext) listVirtualNetworks(filter *cfapi.VnetFilter) ([]*cfapi.VirtualNetwork, error) {
|
2021-11-26 12:37:54 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, noClientMsg)
|
|
|
|
}
|
|
|
|
return client.ListVirtualNetworks(filter)
|
|
|
|
}
|
|
|
|
|
2023-01-20 11:52:56 +00:00
|
|
|
func (sc *subcommandContext) deleteVirtualNetwork(vnetId uuid.UUID, force bool) error {
|
2021-11-26 12:37:54 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, noClientMsg)
|
|
|
|
}
|
2023-01-20 11:52:56 +00:00
|
|
|
return client.DeleteVirtualNetwork(vnetId, force)
|
2021-11-26 12:37:54 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
func (sc *subcommandContext) updateVirtualNetwork(vnetId uuid.UUID, updates cfapi.UpdateVirtualNetwork) error {
|
2021-11-26 12:37:54 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, noClientMsg)
|
|
|
|
}
|
|
|
|
return client.UpdateVirtualNetwork(vnetId, updates)
|
|
|
|
}
|