github-vet / github-vet/rangeloop-pointer-findings
fionera/TeamDriveManager: cmd/combinations/regenerate_keys.go; 64 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [fionera/TeamDriveManager](https://www.github.com/fionera/TeamDriveManager) at [cmd/combinations/regenerate_keys.go](https://github.com/fionera/TeamDriveManager/blob/31683549236f3ea088f813d584aae2007eba739e/cmd/combinations/regenerate_keys.go#L93-L156)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable serviceAccount used in defer or goroutine at line 145
[Click here to see the code in its original context.](https://github.com/fionera/TeamDriveManager/blob/31683549236f3ea088f813d584aae2007eba739e/cmd/combinations/regenerate_keys.go#L93-L156)
Click here to show the 64 line(s) of Go which triggered the analyzer.
```go
for _, serviceAccount := range serviceAccounts {
serviceAccountRequests.Add(1)
running++
go func(account *iam2.ServiceAccount) {
defer serviceAccountRequests.Done()
getServiceAccount:
serviceAccountObject, err := api.GetServiceAccount(iamApi, projectId, account.Email)
if err != nil {
logrus.Error(err)
goto getServiceAccount
}
deleteApiKey:
logrus.Infof("Deleting key for `%s`", account.Email)
_, err = api.DeleteServiceAccountKey(iamApi, projectId, account.Email)
if err != nil {
logrus.Error(err)
goto deleteApiKey
}
createApiKey:
logrus.Infof("Creating new key for `%s`", account.Email)
serviceAccountKey, err := api.CreateServiceAccountKey(iamApi, serviceAccountObject)
if err != nil {
logrus.Error(err)
goto createApiKey
}
json, err := serviceAccountKey.MarshalJSON()
if err != nil {
logrus.Panic(err)
return
}
container, err := gabs.ParseJSON(json)
if err != nil {
logrus.Panicf("Error parsing JSON: %s", err)
return
}
privateKeyData := container.Path("privateKeyData").String()
jsonData, err := base64.StdEncoding.DecodeString(privateKeyData[1 : len(privateKeyData)-1])
if err != nil {
logrus.Panicf("Error reading key: %s", err)
return
}
err = os.Mkdir(App.AppConfig.ServiceAccountFolder, 0755)
if err != nil && !os.IsExist(err) {
logrus.Panicf("Error changing type: %s", err)
return
}
err = ioutil.WriteFile(App.AppConfig.ServiceAccountFolder+"/"+serviceAccount.ProjectId+"_"+strings.ReplaceAll(serviceAccount.DisplayName, " ", "_")+".json", jsonData, 0755)
if err != nil {
logrus.Panic(err)
return
}
}(serviceAccount)
if running > App.Flags.Concurrency {
serviceAccountRequests.Wait()
running = 0
}
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 31683549236f3ea088f813d584aae2007eba739e
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with cmd/combinations/regenerate_keys.go at lines 93-156 and inspect the range loop, goroutine argument, deferred call, and later file path construction. Compare the analyzer warning with the captured values and determine whether each goroutine uses the intended service account; done means classifying the finding as a bug, mitigated issue, or desirable behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100