-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add addpeer cmd to add a remote Wireguard peer
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cmd | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/wiretrustee/wiretrustee/connection" | ||
"os" | ||
) | ||
|
||
var ( | ||
key string | ||
allowedIPs string | ||
|
||
addPeerCmd = &cobra.Command{ | ||
Use: "add-peer", | ||
Short: "add remote peer", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
InitLog(logLevel) | ||
|
||
if _, err := os.Stat(configPath); os.IsNotExist(err) { | ||
log.Error("config doesn't exist, please run 'wiretrustee init' first") | ||
os.Exit(ExitSetupFailed) | ||
} | ||
|
||
config, _ := Read(configPath) | ||
config.Peers = append(config.Peers, connection.Peer{ | ||
WgPubKey: key, | ||
WgAllowedIps: allowedIPs, | ||
}) | ||
|
||
err := config.Write(configPath) | ||
if err != nil { | ||
log.Errorf("failed writing config to %s: %s", config, err.Error()) | ||
os.Exit(ExitSetupFailed) | ||
} | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
addPeerCmd.PersistentFlags().StringVar(&key, "key", "", "Wireguard public key of the remote peer") | ||
addPeerCmd.PersistentFlags().StringVar(&allowedIPs, "allowedIPs", "", "Wireguard Allowed IPs for the remote peer, e.g 10.30.30.2/32") | ||
addPeerCmd.MarkPersistentFlagRequired("key") | ||
addPeerCmd.MarkPersistentFlagRequired("allowedIPs") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters