Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Separated printing and analyzes functionality for square (#3122)
Abdul Basit02fb3879eb9d
diff --git a/pkg/analyzer/analyzers/square/square.go b/pkg/analyzer/analyzers/square/square.goindex 94ece11b7..0fe7fc8d1 100644--- a/pkg/analyzer/analyzers/square/square.go+++ b/pkg/analyzer/analyzers/square/square.go@@ -30,6 +30,11 @@ type PermissionsJSON struct {MerchantID string `json:"merchant_id"`}+type SecretInfo struct {+ Permissions PermissionsJSON+ Team TeamJSON+}+func getPermissions(cfg *config.Config, key string) (PermissionsJSON, error) {var permissions PermissionsJSON@@ -96,33 +101,51 @@ func getUsers(cfg *config.Config, key string) (TeamJSON, error) {return team, nil}-func AnalyzePermissions(cfg *config.Config, key string) {+func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) {permissions, err := getPermissions(cfg, key)if err != nil {- color.Red("Error: %s", err)+ return nil, err+ }++ team, err := getUsers(cfg, key)+ if err != nil {+ return nil, err+ }++ return &SecretInfo{+ Permissions: permissions,+ Team: team,+ }, nil+}++func AnalyzeAndPrintPermissions(cfg *config.Config, key string) {+ // ToDo: Add in logging+ if cfg.LoggingEnabled {+ color.Red("[x] Logging is not supported for this analyzer.")+ return+ }++ info, err := AnalyzePermissions(cfg, key)+ if err != nil {+ color.Red("[x] Error: %s", err.Error())return}- if permissions.MerchantID == "" {+ if info.Permissions.MerchantID == "" {color.Red("[x] Invalid Square API Key")return}color.Green("[!] Valid Square API Key\n\n")- color.Yellow("Merchant ID: %s", permissions.MerchantID)- color.Yellow("Client ID: %s", permissions.ClientID)- if permissions.ExpiresAt == "" {+ color.Yellow("Merchant ID: %s", info.Permissions.MerchantID)+ color.Yellow("Client ID: %s", info.Permissions.ClientID)+ if info.Permissions.ExpiresAt == "" {color.Green("Expires: Never\n\n")} else {- color.Yellow("Expires: %s\n\n", permissions.ExpiresAt)+ color.Yellow("Expires: %s\n\n", info.Permissions.ExpiresAt)}- printPermissions(permissions.Scopes, cfg.ShowAll)+ printPermissions(info.Permissions.Scopes, cfg.ShowAll)- team, err := getUsers(cfg, key)- if err != nil {- color.Red("Error: %s", err)- return- }- printTeamMembers(team)+ printTeamMembers(info.Team)}func contains(s []string, e string) bool {diff --git a/pkg/analyzer/cli.go b/pkg/analyzer/cli.goindex d262b19ad..81130c9b1 100644--- a/pkg/analyzer/cli.go+++ b/pkg/analyzer/cli.go@@ -236,7 +236,7 @@ func Run(cmd string) {mailgun.AnalyzeAndPrintPermissions(cfg, *mailgunKey)case squareScan.FullCommand():cfg.LogFile = analyzers.CreateLogFileName("square")- square.AnalyzePermissions(cfg, *squareKey)+ square.AnalyzeAndPrintPermissions(cfg, *squareKey)case sourcegraphScan.FullCommand():cfg.LogFile = analyzers.CreateLogFileName("sourcegraph")sourcegraph.AnalyzePermissions(cfg, *sourcegraphKey)