From 621f79f91a78ca3581d6789e7e4aaee099ca9165 Mon Sep 17 00:00:00 2001 From: Stevenson Jean-Pierre Date: Wed, 27 Jul 2016 16:47:41 -0400 Subject: [PATCH] formatting --- main.go | 27 +++++++++++++-------------- vpn_connection.go | 16 ++++++++-------- vpn_profile.go | 24 ++++++++++++------------ 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/main.go b/main.go index e409cf1..fc44dc9 100644 --- a/main.go +++ b/main.go @@ -26,21 +26,21 @@ var ( _ = hosts.Command("list", "List vpn hosts") _ = hosts.Command("refresh", "Refreshes resources") //Profile Commands - profiles = kingpin.Command("profile","Commands related to VPN connection profiles") + profiles = kingpin.Command("profile", "Commands related to VPN connection profiles") _ = profiles.Command("list", "List vpn connection profiles") - addProfilecmd = profiles.Command("add","Add new profile to existing set") - newProfile = addProfilecmd.Arg("profile","Name of profile to add").Required().String() + addProfilecmd = profiles.Command("add", "Add new profile to existing set") + newProfile = addProfilecmd.Arg("profile", "Name of profile to add").Required().String() //Command Regex Section connectRegex = regexp.MustCompile(`^connect`) hostCommadRegex = regexp.MustCompile(`^host`) profileCommandRegex = regexp.MustCompile(`^profile`) //Global Vars - resourcePath = path.Join(os.Getenv("HOME") ,".vpn_host_manager") + resourcePath = path.Join(os.Getenv("HOME"), ".vpn_host_manager") ) func permissionCheck() { - output,_ := exec.Command("id","-u").Output() - trimmedOutput := strings.Trim(string(output),"\n") + output, _ := exec.Command("id", "-u").Output() + trimmedOutput := strings.Trim(string(output), "\n") if string(trimmedOutput) != "0" { log.Fatal("Please rerun as root or with sudo") } @@ -50,7 +50,6 @@ func listVpnHosts() { printVPNHostList() } - func hostFunctions(hostMethod string) { switch hostMethod { case "host list": @@ -67,18 +66,18 @@ func profileFunctions(profileMethod string) { case "profile add": addProfile(*newProfile) default: - log.Fatalf("not sure what to do with command: %s",profileMethod) + log.Fatalf("not sure what to do with command: %s", profileMethod) } } -func connectVPN(profileName string,vpnIdentifier string) { - startConnection(vpnIdentifier,profileName) +func connectVPN(profileName string, vpnIdentifier string) { + startConnection(vpnIdentifier, profileName) } func setupDirectories() { if _, err := os.Stat(resourcePath); os.IsNotExist(err) { - error := os.Mkdir(resourcePath,0755) + error := os.Mkdir(resourcePath, 0755) if error != nil { log.Fatalf("encountered error during setup, %s", error) } @@ -87,7 +86,7 @@ func setupDirectories() { func main() { permissionCheck() - setupDirectories() + setupDirectories() parsedArg := kingpin.Parse() switch { case hostCommadRegex.MatchString(parsedArg): @@ -95,11 +94,11 @@ func main() { case profileCommandRegex.MatchString(parsedArg): profileFunctions(parsedArg) case connectRegex.MatchString(parsedArg): - connectVPN(*profile,*vpn) + connectVPN(*profile, *vpn) default: //if we are in this error block it is because we have established //a command for the provided text, but have not specified a regex //for handling it. - log.Fatalf("Command signature not recognized: %s",parsedArg) + log.Fatalf("Command signature not recognized: %s", parsedArg) } } diff --git a/vpn_connection.go b/vpn_connection.go index add0fb2..6917b3b 100644 --- a/vpn_connection.go +++ b/vpn_connection.go @@ -66,7 +66,7 @@ func updateManagedVPNHost(vpnHost vpnInstance) { addManagedVPNHost(vpnHost) } -func needsDisconnection() bool{ +func needsDisconnection() bool { var disconnect bool if connectionEstablished() { if sameConnection { @@ -194,7 +194,7 @@ func connectionEstablished() bool { func updateRouting(vpnHost vpnInstance) { print("updating route table\n") - _, err := exec.Command("route","-v", "add", "-net", vpnHost.VpcCidr, "-interface ppp0").Output() + _, err := exec.Command("route", "-v", "add", "-net", vpnHost.VpcCidr, "-interface ppp0").Output() if err != nil { if weirdRouteExitCodeRegex.MatchString(err.Error()) { return @@ -204,11 +204,11 @@ func updateRouting(vpnHost vpnInstance) { } } -func selectVPNHost(identifier string) vpnInstance{ +func selectVPNHost(identifier string) vpnInstance { vpnHostsList := readHostsJSONFile() if vpcUIDRegex.MatchString(identifier) { fmt.Println("Connecting to VPN by UID") - for _,host := range vpnHostsList { + for _, host := range vpnHostsList { if host.VpcID == identifier { return host } @@ -216,15 +216,15 @@ func selectVPNHost(identifier string) vpnInstance{ } if vpcIndexRegex.MatchString(identifier) { fmt.Println("Connecting to VPN by ID#") - for index,host := range vpnHostsList { - if strconv.Itoa(index) == identifier { + for index, host := range vpnHostsList { + if strconv.Itoa(index) == identifier { return host } } } fmt.Println("Connecting to VPN by instnace Name") - for _,host := range vpnHostsList { - if host.Name == identifier { + for _, host := range vpnHostsList { + if host.Name == identifier { return host } } diff --git a/vpn_profile.go b/vpn_profile.go index 92ebd8d..d14d407 100644 --- a/vpn_profile.go +++ b/vpn_profile.go @@ -14,9 +14,9 @@ import ( ) var ( - vpnProfileFields = []string{"ID#","Name","Username"} + vpnProfileFields = []string{"ID#", "Name", "Username"} vpnProfileFilePath = path.Join(resourcePath, "vpn_profiles.json") - vpnProfiles = loadProfileFile() + vpnProfiles = loadProfileFile() ) type vpnProfile struct { @@ -43,7 +43,7 @@ func writeProfileFile(profileList []vpnProfile) { fmt.Println(err) return } - fmt.Printf("Writing profile file to %s\n",vpnProfileFilePath) + fmt.Printf("Writing profile file to %s\n", vpnProfileFilePath) writeError := ioutil.WriteFile(vpnProfileFilePath, profileJSON, 0755) if writeError != nil { fmt.Print("Could not write profile file\n") @@ -80,16 +80,16 @@ func selectVPNProfileDetails(profileName string) vpnProfile { } func detectDuplicateName(providedName string) { - for _,profile := range vpnProfiles { + for _, profile := range vpnProfiles { if profile.Name == providedName { - log.Fatalf("profile name %s: Already present, please select another name",providedName) + log.Fatalf("profile name %s: Already present, please select another name", providedName) } } } -func detailCapture(attr string) string{ +func detailCapture(attr string) string { var response string - fmt.Printf("%s ",attr) + fmt.Printf("%s ", attr) _, err := fmt.Scanln(&response) if err != nil { if err.Error() == "unexpected newline" { @@ -100,7 +100,7 @@ func detailCapture(attr string) string{ return response } -func confirm(username string,password string,psk string) bool{ +func confirm(username string, password string, psk string) bool { var returnvar bool confirmation := detailCapture("Save Profile? [y/n]:") switch confirmation { @@ -109,20 +109,20 @@ func confirm(username string,password string,psk string) bool{ case "n": main() default: - confirm(username,password,psk) + confirm(username, password, psk) } return returnvar } func addProfile(profileName string) { detectDuplicateName(profileName) - fmt.Printf("Please enter the following values to configure VPN profile %s\n",profileName) + fmt.Printf("Please enter the following values to configure VPN profile %s\n", profileName) username := detailCapture("USERNAME:") password := detailCapture("PASSWORD:") psk := detailCapture("PSK:") - if confirm(username,password,psk) { + if confirm(username, password, psk) { var updated = []vpnProfile{} - updated = append(vpnProfiles,vpnProfile{Name:profileName,UserName:username,PassWord:password,Psk:psk}) + updated = append(vpnProfiles, vpnProfile{Name:profileName, UserName:username, PassWord:password, Psk:psk}) writeProfileFile(updated) } }