Use user config for polochon access
This commit is contained in:
parent
f9984d8b89
commit
b4bb23056b
7
config/polochon.go
Normal file
7
config/polochon.go
Normal file
@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
// UserPolochon is polochon access parameter for a user
|
||||
type UserPolochon struct {
|
||||
URL string
|
||||
Token string
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user