Skip to content

Commit

Permalink
fixed sourcegraph analyzer (#3877)
Browse files Browse the repository at this point in the history
* use unrestricted client

* added comments
  • Loading branch information
kashifkhan0771 authored Feb 7, 2025
1 parent 4324fbf commit c05bb4d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/analyzer/analyzers/sourcegraph/sourcegraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ type SecretInfo struct {
func getUserInfo(cfg *config.Config, key string) (UserInfoJSON, error) {
var userInfo UserInfoJSON

client := analyzers.NewAnalyzeClient(cfg)
// POST request is considered as non-safe and sourcegraph has graphql APIs. They do not change any state.
// We are using unrestricted client to avoid error for non-safe API request.
client := analyzers.NewAnalyzeClientUnrestricted(cfg)
payload := "{\"query\":\"query { currentUser { username, email, siteAdmin, createdAt } }\"}"
req, err := http.NewRequest("POST", "https://sourcegraph.com/.api/graphql", strings.NewReader(payload))
if err != nil {
Expand Down Expand Up @@ -132,7 +134,9 @@ func checkSiteAdmin(cfg *config.Config, key string) (bool, error) {
}
}`

client := analyzers.NewAnalyzeClient(cfg)
// POST request is considered as non-safe and sourcegraph has graphql APIs. They do not change any state.
// We are using unrestricted client to avoid error for non-safe API request.
client := analyzers.NewAnalyzeClientUnrestricted(cfg)
req, err := http.NewRequest("POST", "https://sourcegraph.com/.api/graphql", strings.NewReader(query))
if err != nil {
return false, err
Expand Down

0 comments on commit c05bb4d

Please # to comment.