Skip to content

Commit d5f9242

Browse files
updated openai analyzer output (#3902)
1 parent f3237c5 commit d5f9242

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

pkg/analyzer/analyzers/openai/openai.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"os"
1212
"strconv"
13+
"strings"
1314

1415
"github.com/fatih/color"
1516
"github.com/jedib0t/go-pretty/table"
@@ -138,7 +139,9 @@ func AnalyzeAndPrintPermissions(cfg *config.Config, apiKey string) {
138139
}
139140
color.Green("[!] Valid OpenAI Token\n\n")
140141

141-
printUserData(data.me)
142+
printAPIKeyType(apiKey)
143+
printData(data.me)
144+
142145
if data.isAdmin {
143146
color.Green("[!] Admin API Key. All permissions available.")
144147
} else if data.isRestricted {
@@ -255,19 +258,39 @@ func getUserData(cfg *config.Config, key string) (MeJSON, error) {
255258
return meJSON, nil
256259
}
257260

258-
func printUserData(meJSON MeJSON) {
259-
color.Green("[i] User: %v", meJSON.Name)
260-
color.Green("[i] Email: %v", meJSON.Email)
261-
color.Green("[i] Phone: %v", meJSON.Phone)
262-
color.Green("[i] MFA Enabled: %v", meJSON.MfaEnabled)
261+
func printAPIKeyType(apiKey string) {
262+
if strings.Contains(apiKey, "-svcacct-") {
263+
color.Yellow("[i] Service Account API Key\n")
264+
} else if strings.Contains(apiKey, "-admin-") {
265+
color.Yellow("[i] Admin API Key\n")
266+
} else {
267+
color.Yellow("[i] Project/Org API Key\n")
268+
}
269+
}
270+
func printData(meJSON MeJSON) {
271+
if meJSON.Name != "" && meJSON.Email != "" {
272+
userTable := table.NewWriter()
273+
userTable.SetOutputMirror(os.Stdout)
274+
color.Green("[i] User Information")
275+
userTable.AppendHeader(table.Row{"UserID", "User", "Email", "Phone", "MFA Enabled"})
276+
userTable.AppendRow(table.Row{meJSON.ID, meJSON.Name, meJSON.Email, meJSON.Phone, meJSON.MfaEnabled})
277+
userTable.Render()
278+
} else {
279+
color.Yellow("[!] No User Information Available")
280+
}
263281

264282
if len(meJSON.Orgs.Data) > 0 {
265-
color.Green("[i] Organizations:")
283+
orgTable := table.NewWriter()
284+
orgTable.SetOutputMirror(os.Stdout)
285+
color.Green("[i] Organizations Information")
286+
orgTable.AppendHeader(table.Row{"Org ID", "Title", "User", "Default", "Role"})
266287
for _, org := range meJSON.Orgs.Data {
267-
color.Green(" - %v", org.Title)
288+
orgTable.AppendRow(table.Row{org.ID, fmt.Sprintf("%s (%s)", org.Title, org.Description), org.User, org.Default, org.Role})
268289
}
290+
orgTable.Render()
291+
} else {
292+
color.Yellow("[!] No Organizations Information Available")
269293
}
270-
fmt.Print("\n\n")
271294
}
272295

273296
func stringifyPermissionStatus(scope OpenAIScope) ([]Permission, analyzers.PermissionType) {

0 commit comments

Comments
 (0)