Use user config for polochon access

This commit is contained in:
Nicolas Duhamel 2016-04-27 20:45:19 +02:00
parent f9984d8b89
commit b4bb23056b
3 changed files with 26 additions and 5 deletions

7
config/polochon.go Normal file
View File

@ -0,0 +1,7 @@
package config
// UserPolochon is polochon access parameter for a user
type UserPolochon struct {
URL string
Token string
}

View File

@ -1,22 +1,33 @@
package movies
import (
"fmt"
"net/http"
"github.com/odwrtw/polochon/lib"
"github.com/odwrtw/polochon/modules/mock"
"gitlab.quimbo.fr/odwrtw/canape-sql/auth"
"gitlab.quimbo.fr/odwrtw/canape-sql/config"
"gitlab.quimbo.fr/odwrtw/canape-sql/users"
"gitlab.quimbo.fr/odwrtw/canape-sql/web"
"gitlab.quimbo.fr/odwrtw/papi"
)
func PolochonMovies(env *web.Env, w http.ResponseWriter, r *http.Request) error {
//TODO use user params
URL := "http://polochon.quimbo.fr"
token := "ShaeGieheiPhue8ohM5t"
v := auth.GetCurrentUser(r)
user, ok := v.(*users.User)
if !ok {
return fmt.Errorf("invalid user type")
}
var polochonConfig config.UserPolochon
err := user.GetConfig("polochon", &polochonConfig)
if err != nil {
return err
}
client, err := papi.New(URL, token)
client, err := papi.New(polochonConfig.URL, polochonConfig.Token)
if err != nil {
return err
}

View File

@ -46,7 +46,10 @@ func (u *User) GetConfig(key string, v interface{}) error {
if err != nil {
return err
}
return json.Unmarshal(*configMap[key], v)
if raw, ok := configMap[key]; ok {
return json.Unmarshal(*raw, v)
}
return nil
}
// SetConfig marshal v into json for specified config key