Skip to content

Commit

Permalink
added outputfile feature to more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JayBeale committed May 14, 2024
1 parent a09351a commit a8efa07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
8 changes: 4 additions & 4 deletions peirates.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var UseAuthCanI bool = true
// Main starts Peirates[]
func Main() {
// Peirates version string
var version = "1.1.21"
var version = "1.1.22a"

var err error

Expand Down Expand Up @@ -356,11 +356,11 @@ func Main() {

// [1] List, maintain, or switch service account contexts [sa-menu] (try: list-sa *, switch-sa, get-sa)
case "switchsa", "saswitch", "switch-sa", "sa-switch":
switchServiceAccounts(serviceAccounts, &connectionString)
switchServiceAccounts(serviceAccounts, &connectionString, logToFile, outputFileName)
case "listsa", "list-sa", "salist", "sa-list", "get-sa":
listServiceAccounts(serviceAccounts, connectionString)
listServiceAccounts(serviceAccounts, connectionString, logToFile, outputFileName)
case "1", "sa-menu", "service-account-menu", "sa", "service-account":
saMenu(&serviceAccounts, &connectionString, interactive)
saMenu(&serviceAccounts, &connectionString, interactive, logToFile, outputFileName)

// [2] List and/or change namespaces [ns-menu] (try: list-ns, switch-ns, get-ns)
case "list-ns", "listns", "nslist", "ns-list", "get-ns", "getns":
Expand Down
8 changes: 4 additions & 4 deletions samenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func setUpCompletionSaMenu() *readline.PrefixCompleter {
return completer
}

func saMenu(serviceAccounts *[]ServiceAccount, connectionString *ServerInfo, interactive bool) {
func saMenu(serviceAccounts *[]ServiceAccount, connectionString *ServerInfo, interactive bool, logToFile bool, outputFileName string) {

// Set up main menu tab completion
var completer *readline.PrefixCompleter = setUpCompletionSaMenu()
Expand Down Expand Up @@ -84,9 +84,9 @@ func saMenu(serviceAccounts *[]ServiceAccount, connectionString *ServerInfo, int

switch strings.ToLower(input) {
case "1", "list":
listServiceAccounts(*serviceAccounts, *connectionString)
listServiceAccounts(*serviceAccounts, *connectionString, logToFile, outputFileName)
case "2", "switch":
switchServiceAccounts(*serviceAccounts, connectionString)
switchServiceAccounts(*serviceAccounts, connectionString, logToFile, outputFileName)
case "3", "add":
serviceAccount, err := acceptServiceAccountFromUser()
if err != nil {
Expand Down Expand Up @@ -198,7 +198,7 @@ func saMenu(serviceAccounts *[]ServiceAccount, connectionString *ServerInfo, int
}
}
case "7", "display":
displayServiceAccountTokenInteractive(*serviceAccounts, connectionString)
displayServiceAccountTokenInteractive(*serviceAccounts, connectionString, logToFile, outputFileName)

}
}
18 changes: 11 additions & 7 deletions service_account_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,23 @@ func assignAuthenticationCertificateAndKeyToConnection(keypair ClientCertificate

}

func listServiceAccounts(serviceAccounts []ServiceAccount, connectionString ServerInfo) {
func listServiceAccounts(serviceAccounts []ServiceAccount, connectionString ServerInfo, logToFile bool, outputFileName string) {
println("\nAvailable Service Accounts:")
// Build a string of the service accounts, with the current one marked.
var output string
for i, account := range serviceAccounts {
if account.Name == connectionString.TokenName {
fmt.Printf("> [%d] %s\n", i, account.Name)
output += fmt.Sprintf("> [%d] %s\n", i, account.Name)
} else {
fmt.Printf(" [%d] %s\n", i, account.Name)
output += fmt.Sprintf(" [%d] %s\n", i, account.Name)
}
}
outputToUser(output, logToFile, outputFileName)
}

func switchServiceAccounts(serviceAccounts []ServiceAccount, connectionString *ServerInfo) {
func switchServiceAccounts(serviceAccounts []ServiceAccount, connectionString *ServerInfo, logToFile bool, outputFileName string) {
var err error
listServiceAccounts(serviceAccounts, *connectionString)
listServiceAccounts(serviceAccounts, *connectionString, logToFile, outputFileName)
println("\nEnter service account number or exit to abort: ")
var tokNum int
var input string
Expand All @@ -187,9 +190,10 @@ func switchServiceAccounts(serviceAccounts []ServiceAccount, connectionString *S
return
}

func displayServiceAccountTokenInteractive(serviceAccounts []ServiceAccount, connectionString *ServerInfo) {
func displayServiceAccountTokenInteractive(serviceAccounts []ServiceAccount, connectionString *ServerInfo, logToFile bool, outputFileName string) {
var err error
listServiceAccounts(serviceAccounts, *connectionString)
listServiceAccounts(serviceAccounts, *connectionString, false, outputFileName)

println("\nEnter service account number or exit to abort: ")
var tokNum int
var input string
Expand Down

0 comments on commit a8efa07

Please sign in to comment.