This is an automated email from the ASF dual-hosted git repository.
ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 7ee3195 fixes credential handling in the tm-health-client (#6178)
7ee3195 is described below
commit 7ee31952f3c4a766b91175c2deb9f6c1f2897f0c
Author: John J. Rushford <[email protected]>
AuthorDate: Thu Sep 9 11:46:46 2021 -0600
fixes credential handling in the tm-health-client (#6178)
---
cache-config/tm-health-client/config/config.go | 29 +++++++++++++++++---------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/cache-config/tm-health-client/config/config.go
b/cache-config/tm-health-client/config/config.go
index f46d618..63f40b5 100644
--- a/cache-config/tm-health-client/config/config.go
+++ b/cache-config/tm-health-client/config/config.go
@@ -23,6 +23,7 @@ import (
"bufio"
"encoding/json"
"errors"
+ "fmt"
"io/ioutil"
"net/url"
"os"
@@ -50,14 +51,14 @@ const (
)
type Cfg struct {
- CDNName string `json:"cdn-name"`
- EnableActiveMarkdowns bool `json:"enable-active-markdowns"`
- ReasonCode string `json:"reason-code"`
- TOCredentialFile string `json:"to-credential-file"`
- TORequestTimeOutSeconds string `json:"to-request-timeout-seconds"`
- TOPass string
- TOUrl string
- TOUser string
+ CDNName string `json:"cdn-name"`
+ EnableActiveMarkdowns bool `json:"enable-active-markdowns"`
+ ReasonCode string `json:"reason-code"`
+ TOCredentialFile string `json:"to-credential-file"`
+ TORequestTimeOutSeconds string
`json:"to-request-timeout-seconds"`
+ TOPass string `json:"to-pass"`
+ TOUrl string `json:"to-url"`
+ TOUser string `json:"to-user"`
TmPollIntervalSeconds string
`json:"tm-poll-interval-seconds"`
TmUpdateCycles int `json:"tm-update-cycles"`
TrafficServerConfigDir string
`json:"trafficserver-config-dir"`
@@ -196,8 +197,13 @@ func GetConfig() (Cfg, error, bool) {
return Cfg{}, errors.New(err.Error() + "\n"), false
}
- if err = ReadCredentials(&cfg); err != nil {
- return cfg, err, false
+ if cfg.TOPass == "" || cfg.TOUser == "" || cfg.TOUrl == "" {
+ if cfg.TOCredentialFile == "" {
+ return Cfg{}, errors.New("cannot continue, no TO
credentials have been specified"), false
+ }
+ if err = ReadCredentials(&cfg); err != nil {
+ return cfg, err, false
+ }
}
err = GetTrafficMonitors(&cfg)
@@ -219,6 +225,9 @@ func GetTrafficMonitors(cfg *Cfg) error {
// login to traffic ops.
session, _, err := toclient.LoginWithAgent(cfg.TOUrl, cfg.TOUser,
cfg.TOPass, true, "tm-health-client", false, GetRequestTimeout())
+ if err != nil {
+ return fmt.Errorf("could not establish a TrafficOps session:
%w", err)
+ }
srvs, _, err := session.GetServers(&qry)
if err != nil {
return errors.New("error fetching Trafficmonitor server list: "
+ err.Error())