SOS alert on ntg fail auth

This commit is contained in:
bel
2022-01-17 18:43:57 -07:00
parent a38a627f5a
commit a6d5ae606a
2 changed files with 13 additions and 13 deletions

View File

@@ -121,9 +121,6 @@ func (ntg NTGVision) searchJob(id int64) (io.ReadCloser, error) {
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
logtr.Debugf("fetch ntg job info %+v: %d: %s", request, resp.StatusCode, b)
if resp.StatusCode > 400 && resp.StatusCode < 500 && resp.StatusCode != 404 && resp.StatusCode != 410 {
return nil, ErrNoAuth
}
return io.NopCloser(bytes.NewReader(b)), nil
}
@@ -173,15 +170,10 @@ func (ntg NTGVision) WithMock() NTGVision {
func (ntg NTGVision) SearchJob(id int64) (ntgVisionJobInfo, error) {
rc, err := ntg.searcher.searchJob(id)
if err == ErrNoAuth {
if err := ntg.refreshAuth(); err != nil {
return ntgVisionJobInfo{}, err
}
rc, err = ntg.searcher.searchJob(id)
}
if err != nil {
return ntgVisionJobInfo{}, err
}
defer rc.Close()
var result ntgVisionJobInfo
err = json.NewDecoder(rc).Decode(&result)
return result, err
@@ -243,6 +235,14 @@ func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
}
func (ntg NTGVision) refreshAuth() error {
err := ntg.refreshAuth()
if err != nil {
logtr.SOSf("failed to refresh ntg auth: %v", err)
}
return err
}
func (ntg NTGVision) _refreshAuth() error {
logtr.Infof("refreshing ntg auth...")
b, _ := json.Marshal(map[string]string{
"username": config.Get().Brokers.NTG.Username,