-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use https://github.com/nikhilsbhat/gocd-sdk-go while interacting with…
… GoCD.
- Loading branch information
1 parent
85a4260
commit 4ec61da
Showing
26 changed files
with
182 additions
and
1,056 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,23 @@ | ||
package gocd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/nikhilsbhat/gocd-prometheus-exporter/pkg/common" | ||
|
||
"github.com/go-kit/log/level" | ||
) | ||
|
||
// GetAdminsInfo fetches information of all system admins present in GoCD server. | ||
func (conf *client) GetAdminsInfo() (SystemAdmins, error) { | ||
conf.client.SetHeaders(map[string]string{ | ||
"Accept": common.GoCdHeaderVersionTwo, | ||
}) | ||
level.Debug(conf.logger).Log(common.LogCategoryMsg, getTryMessages("admins")) //nolint:errcheck | ||
func (conf *client) updateAdminsInfo() { | ||
conf.lock.Lock() | ||
client := conf.getCronClient() | ||
|
||
var adminsConf SystemAdmins | ||
resp, err := conf.client.R().SetResult(&adminsConf).Get(common.GoCdSystemAdminEndpoint) | ||
admins, err := client.GetSystemAdmins() | ||
if err != nil { | ||
return SystemAdmins{}, fmt.Errorf("call made to get system admin errored with: %w", err) | ||
} | ||
if resp.StatusCode() != http.StatusOK { | ||
return SystemAdmins{}, apiWithCodeError(resp.StatusCode()) | ||
level.Error(conf.logger).Log(common.LogCategoryErr, apiError("system admin", err.Error())) //nolint:errcheck | ||
} | ||
|
||
level.Debug(conf.logger).Log(common.LogCategoryMsg, getSuccessMessages("admins")) //nolint:errcheck | ||
|
||
return adminsConf, nil | ||
} | ||
|
||
func (conf *client) updateAdminsInfo() { | ||
newConf := conf.getCronClient() | ||
newConf.lock.Lock() | ||
admins, err := newConf.GetAdminsInfo() | ||
if err != nil { | ||
level.Error(newConf.logger).Log(common.LogCategoryErr, apiError("system admin", err.Error())) //nolint:errcheck | ||
} | ||
if err == nil { | ||
CurrentSystemAdmins = admins | ||
} | ||
defer newConf.lock.Unlock() | ||
|
||
defer conf.lock.Unlock() | ||
} |
Oops, something went wrong.