Skip to content

Commit

Permalink
trim whitespace from input
Browse files Browse the repository at this point in the history
  • Loading branch information
JayBeale committed Jun 24, 2021
1 parent 1887d65 commit d8dd1d2
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions peirates.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ func GetGCPBearerTokenFromMetadataAPI(account string) string {
func SwitchNamespace(connectionString *ServerInfo, namespacesList []string) bool {

println("\nEnter namespace to switch to or hit enter to maintain current namespace: ")
input, _ := readLine()
input = strings.TrimSpace(input)
input, _ := readLineStripWhitespace()

if input != "" {
// Make sure input is in the existing namespace list.
Expand All @@ -172,6 +171,13 @@ func SwitchNamespace(connectionString *ServerInfo, namespacesList []string) bool
return true
}

func readLineStripWhitespace() (string, error) {
line, err := readLine()

return strings.TrimSpace(line), err

}

// readLine reads up through the next \n from stdin. The returned string does
// not include the \n.
func readLine() (string, error) {
Expand Down Expand Up @@ -579,9 +585,9 @@ func acceptServiceAccountFromUser() ServiceAccount {
DiscoveryMethod: "User Input",
}
println("\nWhat do you want to name this service account?")
serviceAccount.Name, _ = readLine()
serviceAccount.Name, _ = readLineStripWhitespace()
println("\nPaste the service account token and hit ENTER:")
serviceAccount.Token, _ = readLine()
serviceAccount.Token, _ = readLineStripWhitespace()

return serviceAccount
}
Expand Down Expand Up @@ -902,7 +908,7 @@ Leave off the "kubectl" part of the command. For example:
`)

fmt.Printf("Please enter a kubectl command: ")
input, _ = readLine()
input, _ = readLineStripWhitespace()

arguments := strings.Fields(input)

Expand Down Expand Up @@ -1496,7 +1502,7 @@ Leave off the "kubectl" part of the command. For example:
fmt.Scanln(&input)
println("[+] Please provide the command to run in the pods: ")

cmdOpts.commandToRunInPods, _ = readLine()
cmdOpts.commandToRunInPods, _ = readLineStripWhitespace()

switch input {
case "1":
Expand Down Expand Up @@ -1593,9 +1599,7 @@ Leave off the "kubectl" part of the command. For example:
// Request a parameter name

fmt.Println("[+] Enter a parameter or a blank line to finish entering parameters: ")
input, _ = readLine()

inputParameter = strings.TrimSpace(input)
inputParameter, _ = readLineStripWhitespace()

if inputParameter != "" {
// Request a parameter value
Expand All @@ -1618,14 +1622,14 @@ Leave off the "kubectl" part of the command. For example:
// Request a header name

fmt.Println("[+] Enter a header name or a blank line if done: ")
input, _ = readLine()
input, _ = readLineStripWhitespace()

inputHeader = strings.TrimSpace(input)

if inputHeader != "" {
// Request a header rhs (value)
fmt.Println("[+] Enter a value for " + inputHeader + ":")
input, _ = readLine()
input, _ = readLineStripWhitespace()

// Add the header value to the list
var header HeaderLine
Expand Down

0 comments on commit d8dd1d2

Please sign in to comment.