@@ -10,6 +10,7 @@ import (
10
10
"net/http"
11
11
"os"
12
12
"strconv"
13
+ "strings"
13
14
14
15
"github.com/fatih/color"
15
16
"github.com/jedib0t/go-pretty/table"
@@ -138,7 +139,9 @@ func AnalyzeAndPrintPermissions(cfg *config.Config, apiKey string) {
138
139
}
139
140
color .Green ("[!] Valid OpenAI Token\n \n " )
140
141
141
- printUserData (data .me )
142
+ printAPIKeyType (apiKey )
143
+ printData (data .me )
144
+
142
145
if data .isAdmin {
143
146
color .Green ("[!] Admin API Key. All permissions available." )
144
147
} else if data .isRestricted {
@@ -255,19 +258,39 @@ func getUserData(cfg *config.Config, key string) (MeJSON, error) {
255
258
return meJSON , nil
256
259
}
257
260
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
+ }
263
281
264
282
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" })
266
287
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 } )
268
289
}
290
+ orgTable .Render ()
291
+ } else {
292
+ color .Yellow ("[!] No Organizations Information Available" )
269
293
}
270
- fmt .Print ("\n \n " )
271
294
}
272
295
273
296
func stringifyPermissionStatus (scope OpenAIScope ) ([]Permission , analyzers.PermissionType ) {
0 commit comments