Skip to content

Commit c05bb4d

Browse files
fixed sourcegraph analyzer (#3877)
* use unrestricted client * added comments
1 parent 4324fbf commit c05bb4d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/analyzer/analyzers/sourcegraph/sourcegraph.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ type SecretInfo struct {
9898
func getUserInfo(cfg *config.Config, key string) (UserInfoJSON, error) {
9999
var userInfo UserInfoJSON
100100

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

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

0 commit comments

Comments
 (0)