mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
cleaning up old grpc functionality
This commit is contained in:
@@ -121,7 +121,7 @@ func List(cfg config.ClientConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Uninstall(cfg config.GlobalConfig) error {
|
func Uninstall() error {
|
||||||
log.Println("Uninstalling netclient")
|
log.Println("Uninstalling netclient")
|
||||||
err := functions.Uninstall()
|
err := functions.Uninstall()
|
||||||
return err
|
return err
|
||||||
|
@@ -60,29 +60,6 @@ func Write(config *ClientConfig, network string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//reading in the env file
|
|
||||||
func WriteGlobal(config *GlobalConfig) error {
|
|
||||||
_, err := os.Stat("/etc/netclient")
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
os.Mkdir("/etc/netclient", 744)
|
|
||||||
} else if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
home := "/etc/netclient"
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
file := fmt.Sprintf(home + "/netconfig-global-001")
|
|
||||||
f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
err = yaml.NewEncoder(f).Encode(config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func WriteServer(server string, accesskey string, network string) error {
|
func WriteServer(server string, accesskey string, network string) error {
|
||||||
if network == "" {
|
if network == "" {
|
||||||
err := errors.New("No network provided. Exiting.")
|
err := errors.New("No network provided. Exiting.")
|
||||||
@@ -197,58 +174,6 @@ func (config *ClientConfig) ReadConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func ModGlobalConfig(cfg models.IntClient) error {
|
|
||||||
var modconfig GlobalConfig
|
|
||||||
var err error
|
|
||||||
if FileExists("/etc/netclient/netconfig-global-001") {
|
|
||||||
useconfig, err := ReadGlobalConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
modconfig = *useconfig
|
|
||||||
}
|
|
||||||
if cfg.ServerWGPort != "" {
|
|
||||||
modconfig.Client.ServerWGPort = cfg.ServerWGPort
|
|
||||||
}
|
|
||||||
if cfg.ServerGRPCPort != "" {
|
|
||||||
modconfig.Client.ServerGRPCPort = cfg.ServerGRPCPort
|
|
||||||
}
|
|
||||||
if cfg.ServerAPIPort != "" {
|
|
||||||
modconfig.Client.ServerAPIPort = cfg.ServerAPIPort
|
|
||||||
}
|
|
||||||
if cfg.PublicKey != "" {
|
|
||||||
modconfig.Client.PublicKey = cfg.PublicKey
|
|
||||||
}
|
|
||||||
if cfg.PrivateKey != "" {
|
|
||||||
modconfig.Client.PrivateKey = cfg.PrivateKey
|
|
||||||
}
|
|
||||||
if cfg.ServerPublicEndpoint != "" {
|
|
||||||
modconfig.Client.ServerPublicEndpoint = cfg.ServerPublicEndpoint
|
|
||||||
}
|
|
||||||
if cfg.ServerPrivateAddress != "" {
|
|
||||||
modconfig.Client.ServerPrivateAddress = cfg.ServerPrivateAddress
|
|
||||||
}
|
|
||||||
if cfg.Address != "" {
|
|
||||||
modconfig.Client.Address = cfg.Address
|
|
||||||
}
|
|
||||||
if cfg.Address6 != "" {
|
|
||||||
modconfig.Client.Address6 = cfg.Address6
|
|
||||||
}
|
|
||||||
if cfg.Network != "" {
|
|
||||||
modconfig.Client.Network = cfg.Network
|
|
||||||
}
|
|
||||||
if cfg.ServerKey != "" {
|
|
||||||
modconfig.Client.ServerKey = cfg.ServerKey
|
|
||||||
}
|
|
||||||
if cfg.AccessKey != "" {
|
|
||||||
modconfig.Client.AccessKey = cfg.AccessKey
|
|
||||||
}
|
|
||||||
if cfg.ClientID != "" {
|
|
||||||
modconfig.Client.ClientID = cfg.ClientID
|
|
||||||
}
|
|
||||||
err = WriteGlobal(&modconfig)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func ModConfig(node *models.Node) error {
|
func ModConfig(node *models.Node) error {
|
||||||
network := node.Network
|
network := node.Network
|
||||||
@@ -397,30 +322,6 @@ func ReadConfig(network string) (*ClientConfig, error) {
|
|||||||
return &cfg, err
|
return &cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadGlobalConfig() (*GlobalConfig, error) {
|
|
||||||
nofile := false
|
|
||||||
home := "/etc/netclient"
|
|
||||||
file := fmt.Sprintf(home + "/netconfig-global-001")
|
|
||||||
f, err := os.Open(file)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
nofile = true
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
var cfg GlobalConfig
|
|
||||||
|
|
||||||
if !nofile {
|
|
||||||
decoder := yaml.NewDecoder(f)
|
|
||||||
err = decoder.Decode(&cfg)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("trouble decoding file")
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &cfg, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func FileExists(f string) bool {
|
func FileExists(f string) bool {
|
||||||
info, err := os.Stat(f)
|
info, err := os.Stat(f)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
@@ -362,7 +362,7 @@ func GetNetworks() ([]string, error) {
|
|||||||
return networks, err
|
return networks, err
|
||||||
}
|
}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if strings.Contains(f.Name(), "netconfig-") && !strings.Contains(f.Name(), "global-001") {
|
if strings.Contains(f.Name(), "netconfig-") {
|
||||||
networkname := stringAfter(f.Name(), "netconfig-")
|
networkname := stringAfter(f.Name(), "netconfig-")
|
||||||
networks = append(networks, networkname)
|
networks = append(networks, networkname)
|
||||||
}
|
}
|
||||||
|
@@ -303,22 +303,6 @@ func WipeLocal(network string) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func WipeGRPCClient() error {
|
|
||||||
home := "/etc/netclient"
|
|
||||||
_ = os.Remove(home + "/netconfig-global-001")
|
|
||||||
|
|
||||||
ipExec, err := exec.LookPath("ip")
|
|
||||||
|
|
||||||
cmdIPLinkDel := &exec.Cmd{
|
|
||||||
Path: ipExec,
|
|
||||||
Args: []string{ipExec, "link", "del", "grpc-wg-001"},
|
|
||||||
Stdout: os.Stdout,
|
|
||||||
Stderr: os.Stdout,
|
|
||||||
}
|
|
||||||
err = cmdIPLinkDel.Run()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func HasNetwork(network string) bool {
|
func HasNetwork(network string) bool {
|
||||||
|
|
||||||
return FileExists("/etc/systemd/system/netclient-"+network+".timer") ||
|
return FileExists("/etc/systemd/system/netclient-"+network+".timer") ||
|
||||||
|
@@ -306,13 +306,7 @@ func main() {
|
|||||||
// the action, or code that will be executed when
|
// the action, or code that will be executed when
|
||||||
// we execute our `ns` command
|
// we execute our `ns` command
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
cfg, err := config.ReadGlobalConfig()
|
err := command.Uninstall()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var gconf config.GlobalConfig
|
|
||||||
gconf = *cfg
|
|
||||||
err = command.Uninstall(gconf)
|
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user