1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00
Aleksandar Novaković f9093413ee MF-742 - Things to support single user scenario (#749)
* Add single user mode to things service

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add tests for things/users package

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update init order in main

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>
2019-05-17 16:06:21 +02:00

43 lines
916 B
Go

//
// Copyright (c) 2019
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
// Package users contains implementation for users service in
// single user scenario.
package users
import (
"context"
"github.com/mainflux/mainflux/things"
"github.com/mainflux/mainflux"
"google.golang.org/grpc"
)
var _ mainflux.UsersServiceClient = (*singleUserRepo)(nil)
type singleUserRepo struct {
email string
token string
}
// NewSingleUserService creates single user repository for constraind environments.
func NewSingleUserService(email, token string) mainflux.UsersServiceClient {
return singleUserRepo{
email: email,
token: token,
}
}
func (repo singleUserRepo) Identify(_ context.Context, token *mainflux.Token, opts ...grpc.CallOption) (*mainflux.UserID, error) {
if repo.token != token.GetValue() {
return nil, things.ErrUnauthorizedAccess
}
return &mainflux.UserID{Value: repo.email}, nil
}