mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-04 22:17:59 +08:00
Ensure service interface is properly implemented
Signed-off-by: Dejan Mijic <dejan@mainflux.com>
This commit is contained in:
parent
eb99ef97e3
commit
da3089cf87
@ -45,6 +45,19 @@ func (ls *loggingService) Login(user manager.User) (token string, err error) {
|
||||
return ls.Service.Login(user)
|
||||
}
|
||||
|
||||
func (ls *loggingService) Identity(key string) (id string, err error) {
|
||||
defer func(begin time.Time) {
|
||||
ls.logger.Log(
|
||||
"method", "identity",
|
||||
"id", id,
|
||||
"error", err,
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
|
||||
return ls.Service.Identity(key)
|
||||
}
|
||||
|
||||
func (ls *loggingService) AddClient(key string, client manager.Client) (id string, err error) {
|
||||
defer func(begin time.Time) {
|
||||
ls.logger.Log(
|
||||
|
@ -43,6 +43,15 @@ func (ms *metricService) Login(user manager.User) (string, error) {
|
||||
return ms.Service.Login(user)
|
||||
}
|
||||
|
||||
func (ms *metricService) Identity(key string) (string, error) {
|
||||
defer func(begin time.Time) {
|
||||
ms.counter.With("method", "identity").Add(1)
|
||||
ms.latency.With("method", "identity").Observe(time.Since(begin).Seconds())
|
||||
}(time.Now())
|
||||
|
||||
return ms.Service.Identity(key)
|
||||
}
|
||||
|
||||
func (ms *metricService) AddClient(key string, client manager.Client) (string, error) {
|
||||
defer func(begin time.Time) {
|
||||
ms.counter.With("method", "add_client").Add(1)
|
||||
|
@ -20,13 +20,6 @@ func MakeHandler(svc manager.Service) http.Handler {
|
||||
|
||||
r := bone.New()
|
||||
|
||||
r.Post("/identity", kithttp.NewServer(
|
||||
identityEndpoint(svc),
|
||||
decodeIdentity,
|
||||
encodeResponse,
|
||||
opts...,
|
||||
))
|
||||
|
||||
r.Post("/users", kithttp.NewServer(
|
||||
registrationEndpoint(svc),
|
||||
decodeCredentials,
|
||||
@ -41,6 +34,13 @@ func MakeHandler(svc manager.Service) http.Handler {
|
||||
opts...,
|
||||
))
|
||||
|
||||
r.Post("/identity", kithttp.NewServer(
|
||||
identityEndpoint(svc),
|
||||
decodeIdentity,
|
||||
encodeResponse,
|
||||
opts...,
|
||||
))
|
||||
|
||||
r.Post("/clients", kithttp.NewServer(
|
||||
addClientEndpoint(svc),
|
||||
decodeClient,
|
||||
|
@ -49,6 +49,15 @@ func (ms *managerService) Login(user User) (string, error) {
|
||||
return ms.idp.TemporaryKey(user.Email)
|
||||
}
|
||||
|
||||
func (ms *managerService) Identity(key string) (string, error) {
|
||||
client, err := ms.idp.Identity(key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func (ms *managerService) AddClient(key string, client Client) (string, error) {
|
||||
if err := client.validate(); err != nil {
|
||||
return "", err
|
||||
@ -203,12 +212,3 @@ func (ms *managerService) CanAccess(key, channel string) bool {
|
||||
|
||||
return ms.channels.HasClient(channel, client)
|
||||
}
|
||||
|
||||
func (ms *managerService) Identity(key string) (string, error) {
|
||||
client, err := ms.idp.Identity(key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
@ -33,6 +33,9 @@ type Service interface {
|
||||
// identified by the non-nil error values in the response.
|
||||
Login(User) (string, error)
|
||||
|
||||
// Identity retrieves Client ID for a given client token
|
||||
Identity(string) (string, error)
|
||||
|
||||
// AddClient adds new client to the user identified by the provided key.
|
||||
AddClient(string, Client) (string, error)
|
||||
|
||||
@ -74,7 +77,4 @@ type Service interface {
|
||||
// CanAccess determines whether or not the channel can be accessed with the
|
||||
// provided key.
|
||||
CanAccess(string, string) bool
|
||||
|
||||
// Identity retrieves Client ID for a given client token
|
||||
Identity(string) (string, error)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user