Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to check for localised error messages, add localised … #610

Merged
merged 1 commit into from
Aug 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions server/ec2alias_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,39 @@ import (
"strings"
)

var alreadyRegisteredLocalised = []string{
"The object already exists",
"Das Objekt ist bereits vorhanden",
}

var runAsAdministratorLocalised = []string{
"Run as administrator",
// truncate before 'Umlaut' to avoid encoding problems coming from Windows cmd
"Als Administrator ausf",
}

func installEc2EndpointNetworkAlias() ([]byte, error) {
out, err := exec.Command("netsh", "interface", "ipv4", "add", "address", "Loopback Pseudo-Interface 1", "169.254.169.254", "255.255.0.0").CombinedOutput()

if err == nil || strings.Contains(string(out), "The object already exists") {
outMsg := string(out)

if err == nil || msgFound(alreadyRegisteredLocalised, outMsg) {
return []byte{}, nil
}

if strings.Contains(string(out), "Run as administrator") {
if msgFound(runAsAdministratorLocalised, outMsg) {
fmt.Println("Creation of network alias for server mode requires elevated permissions (Run as administrator).")
}

return out, err
}

func msgFound(localised []string, toTest string) bool {
for _, value := range localised {
if strings.Contains(toTest, value) {
return true
}
}

return false
}