fix: keep abra working if recipe catalogue is offline (!235)
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Co-authored-by: Moritz <moritz.m@local-it.org> Reviewed-on: #235
This commit is contained in:
parent
4e78b060e0
commit
e788ac21f6
|
@ -2,6 +2,7 @@ package recipe
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -665,13 +666,21 @@ func CheckoutDefaultBranch(repo *git.Repository, recipeName string) (plumbing.Re
|
|||
return branch, nil
|
||||
}
|
||||
|
||||
type CatalogueOfflineError struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (e *CatalogueOfflineError) Error() string {
|
||||
return fmt.Sprintf("catalogue offline: %s", e.msg)
|
||||
}
|
||||
|
||||
// recipeCatalogueFSIsLatest checks whether the recipe catalogue stored locally
|
||||
// is up to date.
|
||||
func recipeCatalogueFSIsLatest() (bool, error) {
|
||||
httpClient := web.NewHTTPRetryClient()
|
||||
res, err := httpClient.Head(RecipeCatalogueURL)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, &CatalogueOfflineError{err.Error()}
|
||||
}
|
||||
|
||||
lastModified := res.Header["Last-Modified"][0]
|
||||
|
@ -712,7 +721,14 @@ func ReadRecipeCatalogue() (RecipeCatalogue, error) {
|
|||
|
||||
recipeFSIsLatest, err := recipeCatalogueFSIsLatest()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var offlineErr *CatalogueOfflineError
|
||||
if errors.As(err, &offlineErr) {
|
||||
logrus.Error(err)
|
||||
logrus.Error("unable to retrieve catalogue from internet, using local copy.")
|
||||
recipeFSIsLatest = true
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if !recipeFSIsLatest {
|
||||
|
|
Loading…
Reference in New Issue