Changed viper to normal json
package oauth
import (
+ "encoding/json"
"io/ioutil"
"net/url"
"path/filepath"
+ "strings"
"sync"
log "github.com/Sirupsen/logrus"
- "github.com/fsnotify/fsnotify"
- "github.com/spf13/viper"
)
// FileSystemRepository represents a mongodb repository
@@ -27,33 +27,21 @@ func NewFileSystemRepository(dir string) (*FileSystemRepository, error) {
}
for _, f := range files {
+ if strings.Contains(f.Name(), ".json") {
filePath := filepath.Join(dir, f.Name())
- definition := new(OAuth)
-
- v := viper.New()
- v.SetConfigFile(filePath)
- v.WatchConfig()
- v.OnConfigChange(func(e fsnotify.Event) {
- log.WithFields(log.Fields{"name": e.Name, "op": e.Op.String()}).Debug("OAauth2 configuration changed, reloading...")
- if err := v.Unmarshal(definition); err != nil {
- log.WithError(err).Error("Can't unmarshal the OAauth2 configuration")
- }
- })
-
- if err := v.ReadInConfig(); err != nil {
- log.WithError(err).Error("Couldn't load the OAauth2 definition file")
- return nil, err
- }
-
- if err := v.Unmarshal(definition); err != nil {
+ oauthServerRaw, err := ioutil.ReadFile(filePath)
+ if err != nil {
+ log.WithError(err).WithField("path", filePath).Error("Couldn't load the oauth server file")
return nil, err
}
- if err = repo.Add(definition); err != nil {
+ oauthServer := repo.parseOAuthServer(oauthServerRaw)
+ if err = repo.Add(oauthServer); err != nil {
log.WithError(err).Error("Can't add the definition to the repository")
return nil, err
}
}
+ }
return repo, nil
}
@@ -107,3 +95,12 @@ func (r *FileSystemRepository) FindByTokenURL(url url.URL) (*OAuth, error) {
return nil, ErrOauthServerNotFound
}
+
+func (r *FileSystemRepository) parseOAuthServer(oauthServerRaw []byte) *OAuth {
+ oauthServer := new(OAuth)
+ if err := json.Unmarshal(oauthServerRaw, oauthServer); err != nil {
+ log.WithError(err).Error("[RPC] --> Couldn't unmarshal oauth server configuration")
+ }
+
+ return oauthServer
+}
