update libs
This commit is contained in:
1 parent
1b7eef2443
commit
577c1fd1a6
11 files changed
+172
-223
No files matched your search
Generated
+64
-26
@@ -7,12 +7,6 @@
|
||||
revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f"
|
||||
version = "v9"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/facebookgo/stack"
|
||||
packages = ["."]
|
||||
revision = "751773369052141c013c6e827a71e8f35c07879c"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/fsnotify/fsnotify"
|
||||
packages = ["."]
|
||||
@@ -29,14 +23,13 @@
|
||||
"orm",
|
||||
"types"
|
||||
]
|
||||
revision = "8c7fa0eed0d9e9d07fca2cc9e08e3171da0521d5"
|
||||
version = "v6.13.5"
|
||||
revision = "c0368cd6ee62269f0a5c3d6c9c02c6d192760bc6"
|
||||
version = "v6.14.3"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/golang/protobuf"
|
||||
packages = [
|
||||
"proto",
|
||||
"protoc-gen-go/descriptor",
|
||||
"ptypes",
|
||||
"ptypes/any",
|
||||
"ptypes/duration",
|
||||
@@ -119,11 +112,35 @@
|
||||
revision = "c2353362d570a7bfa228149c62842019201cfb71"
|
||||
version = "v1.8.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-colorable"
|
||||
packages = ["."]
|
||||
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
|
||||
version = "v0.0.9"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-isatty"
|
||||
packages = ["."]
|
||||
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
|
||||
version = "v0.0.3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mgutz/ansi"
|
||||
packages = ["."]
|
||||
revision = "9520e82c474b0a04dd04f8a40959027271bab992"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mitchellh/mapstructure"
|
||||
packages = ["."]
|
||||
revision = "bb74f1db0675b241733089d5a1faa5dd8b0ef57b"
|
||||
revision = "f15292f7a699fcc1a38a80977f80a046874ba8ac"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mohae/deepcopy"
|
||||
packages = ["."]
|
||||
revision = "c48cc78d482608239f6c4c92a4abd87eb8761c90"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pelletier/go-toml"
|
||||
@@ -140,8 +157,8 @@
|
||||
[[projects]]
|
||||
name = "github.com/sirupsen/logrus"
|
||||
packages = ["."]
|
||||
revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc"
|
||||
version = "v1.0.5"
|
||||
revision = "3e01752db0189b9157070a0e1668a620f9a85da2"
|
||||
version = "v1.0.6"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/spf13/afero"
|
||||
@@ -173,25 +190,40 @@
|
||||
[[projects]]
|
||||
name = "github.com/spf13/viper"
|
||||
packages = ["."]
|
||||
revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736"
|
||||
version = "v1.0.2"
|
||||
revision = "907c19d40d9a6c9bb55f040ff4ae45271a4754b9"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "gitlab8.alx/msp2.0/msp-lib"
|
||||
name = "github.com/thecodeteam/goodbye"
|
||||
packages = ["."]
|
||||
revision = "a83968bda2d37294a3541b7d2207fb6f5a3559a3"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/x-cray/logrus-prefixed-formatter"
|
||||
packages = ["."]
|
||||
revision = "bb2702d423886830dee131692131d35648c382e2"
|
||||
version = "v0.5.2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "gitlab.alx/msp2.0/msp-lib"
|
||||
packages = [
|
||||
"backend",
|
||||
"bootstrap",
|
||||
"config",
|
||||
"config/schema",
|
||||
"database",
|
||||
"logger",
|
||||
"proto/stubs",
|
||||
"socket",
|
||||
"streaming",
|
||||
"structure",
|
||||
"token-gen",
|
||||
"utils",
|
||||
"validate"
|
||||
]
|
||||
revision = "7a0d3cf1d8e6946ac04491f9c85bbc556417505b"
|
||||
revision = "b27008156c601c6d2b6b88fef9bf6000e722251d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -201,7 +233,7 @@
|
||||
"blowfish",
|
||||
"ssh/terminal"
|
||||
]
|
||||
revision = "7f39a6fea4fe9364fb61e1def6a268a51b4f3a06"
|
||||
revision = "80fca2ff14a3fb7db622c9a5462f8ce9ea026cba"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -215,7 +247,7 @@
|
||||
"internal/timeseries",
|
||||
"trace"
|
||||
]
|
||||
revision = "db08ff08e8622530d9ed3a0e8ac279f6d4c02196"
|
||||
revision = "f4c29de78a2a91c00474a2e689954305c350adf9"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -224,7 +256,7 @@
|
||||
"unix",
|
||||
"windows"
|
||||
]
|
||||
revision = "fc8bd948cf46f9c7af0f07d34151ce25fe90e477"
|
||||
revision = "2be389f392cd91df245b41638f818a1c041f0c08"
|
||||
|
||||
[[projects]]
|
||||
name = "golang.org/x/text"
|
||||
@@ -251,11 +283,10 @@
|
||||
branch = "master"
|
||||
name = "google.golang.org/genproto"
|
||||
packages = [
|
||||
"googleapis/api/annotations",
|
||||
"googleapis/rpc/errdetails",
|
||||
"googleapis/rpc/status"
|
||||
]
|
||||
revision = "32ee49c4dd805befd833990acba36cb75042378c"
|
||||
revision = "daca94659cb50e9f37c1b834680f2e46358f10b0"
|
||||
|
||||
[[projects]]
|
||||
name = "google.golang.org/grpc"
|
||||
@@ -273,7 +304,9 @@
|
||||
"internal",
|
||||
"internal/backoff",
|
||||
"internal/channelz",
|
||||
"internal/envconfig",
|
||||
"internal/grpcrand",
|
||||
"internal/transport",
|
||||
"keepalive",
|
||||
"metadata",
|
||||
"naming",
|
||||
@@ -283,11 +316,16 @@
|
||||
"resolver/passthrough",
|
||||
"stats",
|
||||
"status",
|
||||
"tap",
|
||||
"transport"
|
||||
"tap"
|
||||
]
|
||||
revision = "168a6198bcb0ef175f7dacec0b8691fc141dc9b8"
|
||||
version = "v1.13.0"
|
||||
revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455"
|
||||
version = "v1.14.0"
|
||||
|
||||
[[projects]]
|
||||
name = "gopkg.in/natefinch/lumberjack.v2"
|
||||
packages = ["."]
|
||||
revision = "a96e63847dc3c67d17befa69c303767e2f84e54f"
|
||||
version = "v2.1"
|
||||
|
||||
[[projects]]
|
||||
name = "gopkg.in/yaml.v2"
|
||||
@@ -298,6 +336,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "04d0945c7a50967a960eb1c6d16be7a0ade6783b97332859a8223423ce092fe5"
|
||||
inputs-digest = "72d03f306d9662118c26965b7d53ba4b0f5a8ad5c4316b44d8511306f82e33e2"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
+5
-12
@@ -1,18 +1,11 @@
|
||||
package conf
|
||||
|
||||
import "gitlab.alx/msp2.0/msp-lib/structure"
|
||||
|
||||
type Configuration struct {
|
||||
ConfigServiceAddress AddressConfiguration
|
||||
GrpcOuterAddress AddressConfiguration `valid:"required~Required" json:"grpcOuterAddress"`
|
||||
GrpcInnerAddress AddressConfiguration `valid:"required~Required" json:"grpcInnerAddress"`
|
||||
ConfigServiceAddress structure.AddressConfiguration
|
||||
GrpcOuterAddress structure.AddressConfiguration `valid:"required~Required" json:"grpcOuterAddress"`
|
||||
GrpcInnerAddress structure.AddressConfiguration `valid:"required~Required" json:"grpcInnerAddress"`
|
||||
ModuleName string
|
||||
InstanceUuid string
|
||||
}
|
||||
|
||||
type AddressConfiguration struct {
|
||||
Port string `valid:"required~Required"`
|
||||
IP string `valid:"required~Required"`
|
||||
}
|
||||
|
||||
func (addressConfiguration *AddressConfiguration) GetAddress() string {
|
||||
return addressConfiguration.IP + ":" + addressConfiguration.Port
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package conf
|
||||
|
||||
import "gitlab8.alx/msp2.0/msp-lib/database"
|
||||
import "gitlab.alx/msp2.0/msp-lib/database"
|
||||
|
||||
type RemoteConfig struct {
|
||||
GrpcAddress AddressConfiguration `valid:"required~Required" json:"grpcAddress"`
|
||||
Database database.DBConfiguration `valid:"required~Required" json:"database"`
|
||||
Database database.DBConfiguration `valid:"required~Required" json:"database"`
|
||||
}
|
||||
+21
-21
@@ -1,24 +1,24 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"admin-service/structure"
|
||||
"admin-service/model"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/grpc/codes"
|
||||
"gitlab8.alx/msp2.0/msp-lib/validate"
|
||||
libUtils "gitlab8.alx/msp2.0/msp-lib/utils"
|
||||
libStr "gitlab8.alx/msp2.0/msp-lib/structure"
|
||||
"gitlab8.alx/msp2.0/msp-lib/token-gen"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gitlab8.alx/msp2.0/msp-lib/utils"
|
||||
"admin-service/structure"
|
||||
"fmt"
|
||||
"gitlab.alx/msp2.0/msp-lib/logger"
|
||||
libStr "gitlab.alx/msp2.0/msp-lib/structure"
|
||||
"gitlab.alx/msp2.0/msp-lib/token-gen"
|
||||
"gitlab.alx/msp2.0/msp-lib/utils"
|
||||
libUtils "gitlab.alx/msp2.0/msp-lib/utils"
|
||||
"gitlab.alx/msp2.0/msp-lib/validate"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"gitlab8.alx/msp2.0/msp-lib/logger"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func Logout(metadata metadata.MD) error {
|
||||
token := metadata.Get(utils.ADMIN_AUTH_HEADER_NAME)
|
||||
|
||||
|
||||
if len(token) == 0 || token[0] == "" {
|
||||
logger.Errorf("Admin AUTH header: %s, not found, received: %v", utils.ADMIN_AUTH_HEADER_NAME, metadata)
|
||||
st := status.New(codes.InvalidArgument, utils.ServiceError)
|
||||
@@ -30,7 +30,7 @@ func Logout(metadata metadata.MD) error {
|
||||
|
||||
func GetProfile(metadata metadata.MD) (*structure.AdminUserShort, error) {
|
||||
token := metadata.Get(utils.ADMIN_AUTH_HEADER_NAME)
|
||||
|
||||
|
||||
if len(token) == 0 || token[0] == "" {
|
||||
logger.Errorf("Admin AUTH header: %s, not found, received: %v", utils.ADMIN_AUTH_HEADER_NAME, metadata)
|
||||
st := status.New(codes.InvalidArgument, utils.ServiceError)
|
||||
@@ -55,7 +55,7 @@ func Login(authRequest structure.AuthRequest) (*structure.Auth, error) {
|
||||
if err != nil {
|
||||
return nil, status.New(codes.Unauthenticated, "Email or password is incorrect").Err()
|
||||
}
|
||||
|
||||
|
||||
_, err = model.InvalidateOldTokens(user.Id)
|
||||
if err != nil {
|
||||
return nil, validate.CreateUnknownError(err)
|
||||
@@ -64,7 +64,7 @@ func Login(authRequest structure.AuthRequest) (*structure.Auth, error) {
|
||||
if err != nil {
|
||||
return nil, validate.CreateUnknownError(err)
|
||||
}
|
||||
|
||||
|
||||
return &structure.Auth{
|
||||
Token: token.Token,
|
||||
Expired: token.ExpiredAt.Format(libUtils.FullDateFormat),
|
||||
@@ -91,7 +91,7 @@ func CreateUpdateUser(user libStr.AdminUser) (*libStr.AdminUser, error) {
|
||||
return nil, libUtils.CreateValidationErrorDetails(codes.InvalidArgument,
|
||||
libUtils.ValidationError, validationErrors)
|
||||
}
|
||||
|
||||
|
||||
userExists, err := model.GetUserByEmail(user.Email)
|
||||
if err != nil {
|
||||
return nil, validate.CreateUnknownError(err)
|
||||
@@ -103,12 +103,12 @@ func CreateUpdateUser(user libStr.AdminUser) (*libStr.AdminUser, error) {
|
||||
return nil, libUtils.CreateValidationErrorDetails(codes.AlreadyExists,
|
||||
libUtils.ValidationError, validationErrors)
|
||||
}
|
||||
|
||||
|
||||
err = cryptPassword(&user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
user, err = model.CreateUser(user)
|
||||
} else {
|
||||
userExists, err := model.GetUserById(user.Id)
|
||||
@@ -122,14 +122,14 @@ func CreateUpdateUser(user libStr.AdminUser) (*libStr.AdminUser, error) {
|
||||
return nil, libUtils.CreateValidationErrorDetails(codes.NotFound,
|
||||
libUtils.ValidationError, validationErrors)
|
||||
}
|
||||
|
||||
|
||||
if user.Password != "" {
|
||||
err = cryptPassword(&user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
user, err = model.UpdateUser(user)
|
||||
user.CreatedAt = userExists.CreatedAt
|
||||
user.UpdatedAt = userExists.UpdatedAt
|
||||
@@ -137,9 +137,9 @@ func CreateUpdateUser(user libStr.AdminUser) (*libStr.AdminUser, error) {
|
||||
if err != nil {
|
||||
return nil, validate.CreateUnknownError(err)
|
||||
}
|
||||
|
||||
|
||||
user.Password = ""
|
||||
|
||||
|
||||
return &user, err
|
||||
}
|
||||
|
||||
|
||||
+14
-12
@@ -1,16 +1,16 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
libStr "gitlab8.alx/msp2.0/msp-lib/structure"
|
||||
"admin-service/structure"
|
||||
"admin-service/controller"
|
||||
"admin-service/structure"
|
||||
libStr "gitlab.alx/msp2.0/msp-lib/structure"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
type Handlers struct {
|
||||
// ===== AUTH =====
|
||||
Login func(structure.AuthRequest) (*structure.Auth, error) `method:"login" group:"auth" inner:"false"`
|
||||
Logout func(metadata.MD) error `method:"logout" group:"auth" inner:"true"`
|
||||
Login func(structure.AuthRequest) (*structure.Auth, error) `method:"login" group:"auth" inner:"false"`
|
||||
Logout func(metadata.MD) error `method:"logout" group:"auth" inner:"true"`
|
||||
// ===== USER =====
|
||||
GetProfile func(metadata.MD) (*structure.AdminUserShort, error) `method:"get_profile" group:"user" inner:"true"`
|
||||
GetUsers func(structure.UsersRequest) (*structure.UsersResponse, error) `method:"get_users" group:"user" inner:"true"`
|
||||
@@ -18,13 +18,15 @@ type Handlers struct {
|
||||
DeleteUser func(identities structure.IdentitiesRequest) (*structure.DeleteResponse, error) `method:"delete_user" group:"user" inner:"true"`
|
||||
}
|
||||
|
||||
func GetHandlers() *Handlers {
|
||||
return &Handlers{
|
||||
controller.Login,
|
||||
controller.Logout,
|
||||
controller.GetProfile,
|
||||
controller.GetUsers,
|
||||
controller.CreateUpdateUser,
|
||||
controller.DeleteUser,
|
||||
func GetHandlers() []interface{} {
|
||||
return []interface{}{
|
||||
&Handlers{
|
||||
Login: controller.Login,
|
||||
Logout: controller.Logout,
|
||||
GetProfile: controller.GetProfile,
|
||||
GetUsers: controller.GetUsers,
|
||||
CreateUpdateUser: controller.CreateUpdateUser,
|
||||
DeleteUser: controller.DeleteUser,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,148 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rn "runtime"
|
||||
"gitlab8.alx/msp2.0/msp-lib/backend"
|
||||
"gitlab8.alx/msp2.0/msp-lib/config"
|
||||
"gitlab8.alx/msp2.0/msp-lib/socket"
|
||||
"gitlab8.alx/msp2.0/msp-lib/logger"
|
||||
"gitlab8.alx/msp2.0/msp-lib/structure"
|
||||
"gitlab8.alx/msp2.0/msp-lib/utils"
|
||||
"admin-service/conf"
|
||||
"os"
|
||||
"path"
|
||||
"admin-service/helper"
|
||||
"time"
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/graarh/golang-socketio"
|
||||
"encoding/json"
|
||||
"os/signal"
|
||||
"gitlab8.alx/msp2.0/msp-lib/database"
|
||||
"context"
|
||||
"gitlab.alx/msp2.0/msp-lib/backend"
|
||||
"gitlab.alx/msp2.0/msp-lib/bootstrap"
|
||||
"gitlab.alx/msp2.0/msp-lib/database"
|
||||
"gitlab.alx/msp2.0/msp-lib/socket"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
configData *conf.Configuration
|
||||
executableFileDir string
|
||||
configChan = make(chan bool)
|
||||
version = "0.1.0"
|
||||
date = "undefined"
|
||||
version = "0.1.0"
|
||||
date = "undefined"
|
||||
)
|
||||
|
||||
func init() {
|
||||
config.InitConfig(&conf.Configuration{})
|
||||
validLocalConfig()
|
||||
appConfig := config.Get().(*conf.Configuration)
|
||||
createGrpcServer()
|
||||
socket.InitClient(
|
||||
socket.SocketConfiguration{
|
||||
Host: appConfig.ConfigServiceAddress.IP,
|
||||
Port: appConfig.ConfigServiceAddress.Port,
|
||||
Secure: false,
|
||||
UrlParams: map[string]string{"module_name": appConfig.ModuleName, "instance_uuid": appConfig.InstanceUuid},
|
||||
},
|
||||
func(client *gosocketio.Client) {
|
||||
subscribeSocket(client, utils.SendConfigWhenConnected)
|
||||
subscribeSocket(client, utils.SendConfigChanged)
|
||||
subscribeSocket(client, utils.SendConfigOnRequest)
|
||||
},
|
||||
)
|
||||
time.Sleep(time.Second * 3)
|
||||
for config.GetRemote() == nil {
|
||||
logger.Warnf("Remote config isn't received, module: %s, instance_uuid: %s",
|
||||
appConfig.ModuleName, appConfig.InstanceUuid)
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
ex, err := os.Executable()
|
||||
executableFileDir = path.Dir(ex)
|
||||
if err != nil {
|
||||
logger.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
if utils.DEV {
|
||||
_, filename, _, _ := rn.Caller(0)
|
||||
executableFileDir = path.Dir(filename)
|
||||
}
|
||||
listenConfigChange()
|
||||
awaitTerminate()
|
||||
bootstrap.
|
||||
ServiceBootstrap(&conf.Configuration{}, &conf.RemoteConfig{}).
|
||||
OnLocalConfigLoad(onLocalConfigLoad).
|
||||
SocketConfiguration(socketConfiguration).
|
||||
SendRemoteConfigSchemaWithVersion(version).
|
||||
SendRoutes(routesData).
|
||||
OnRemoteConfigReceive(onRemoteConfigReceive).
|
||||
OnShutdown(onShutdown).
|
||||
Run()
|
||||
}
|
||||
|
||||
// Start a GRPC server.
|
||||
func createGrpcServer() {
|
||||
appConfig := config.Get().(*conf.Configuration)
|
||||
addr := structure.AddressConfiguration{IP: appConfig.GrpcInnerAddress.IP, Port: appConfig.GrpcInnerAddress.Port}
|
||||
backend.StartBackendGrpcServer(addr, backend.GetDefaultService(appConfig.ModuleName, helper.GetHandlers()))
|
||||
}
|
||||
|
||||
func validRemoteConfig(remoteConfig *conf.RemoteConfig) {
|
||||
_, err := govalidator.ValidateStruct(remoteConfig)
|
||||
if err != nil {
|
||||
validationErrors := govalidator.ErrorsByField(err)
|
||||
logger.Fatal("Remote config int't valid", validationErrors)
|
||||
panic(err)
|
||||
func socketConfiguration(cfg interface{}) socket.SocketConfiguration {
|
||||
appConfig := cfg.(*conf.Configuration)
|
||||
return socket.SocketConfiguration{
|
||||
Host: appConfig.ConfigServiceAddress.IP,
|
||||
Port: appConfig.ConfigServiceAddress.Port,
|
||||
Secure: false,
|
||||
UrlParams: map[string]string{
|
||||
"module_name": appConfig.ModuleName,
|
||||
"instance_uuid": appConfig.InstanceUuid,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func validLocalConfig() {
|
||||
localConfig := config.Get().(*conf.Configuration)
|
||||
_, err := govalidator.ValidateStruct(localConfig)
|
||||
if err != nil {
|
||||
validationErrors := govalidator.ErrorsByField(err)
|
||||
logger.Fatal("Local config int't valid", validationErrors)
|
||||
panic(err)
|
||||
func onShutdown(_ context.Context, _ os.Signal) {
|
||||
backend.StopGrpcServer()
|
||||
}
|
||||
|
||||
func onRemoteConfigReceive(remoteConfig, _ *conf.RemoteConfig) {
|
||||
database.InitDb(remoteConfig.Database)
|
||||
}
|
||||
|
||||
func onLocalConfigLoad(cfg *conf.Configuration) {
|
||||
handlers := helper.GetHandlers()
|
||||
service := backend.GetDefaultService(cfg.ModuleName, handlers...)
|
||||
backend.StartBackendGrpcServer(cfg.GrpcInnerAddress, service)
|
||||
}
|
||||
|
||||
func routesData(localConfig interface{}) bootstrap.SendRoutesData {
|
||||
cfg := localConfig.(*conf.Configuration)
|
||||
return bootstrap.SendRoutesData{
|
||||
ModuleName: cfg.ModuleName,
|
||||
Version: version,
|
||||
GrpcOuterAddress: cfg.GrpcOuterAddress,
|
||||
Handlers: helper.GetHandlers(),
|
||||
}
|
||||
}
|
||||
|
||||
func subscribeSocket(client *gosocketio.Client, eventName string) {
|
||||
client.On(eventName, func(h *gosocketio.Channel, args string) error {
|
||||
logger.Infof("--- Got event: %s message: %s", eventName, args)
|
||||
remoteConfig := &conf.RemoteConfig{}
|
||||
config.InitRemoteConfig(remoteConfig, args)
|
||||
validRemoteConfig(remoteConfig)
|
||||
configChan <- true
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func listenConfigChange() {
|
||||
go func() {
|
||||
for {
|
||||
<-configChan
|
||||
|
||||
localConfig := config.Get().(*conf.Configuration)
|
||||
remoteConfig := config.GetRemote().(*conf.RemoteConfig)
|
||||
|
||||
database.InitDb(remoteConfig.Database)
|
||||
|
||||
addrOuter := structure.AddressConfiguration{
|
||||
IP: localConfig.GrpcOuterAddress.IP,
|
||||
Port: localConfig.GrpcOuterAddress.Port,
|
||||
}
|
||||
|
||||
methods := backend.CreateBackendConfig(
|
||||
structure.ModuleInfo{ModuleName: localConfig.ModuleName, Version: version},
|
||||
addrOuter,
|
||||
localConfig.ModuleName, helper.GetHandlers())
|
||||
|
||||
bytes, err := json.Marshal(methods)
|
||||
if err != nil {
|
||||
logger.Warn("Error when serializing Backend Routes", err)
|
||||
} else {
|
||||
logger.Infof("EXPORTED MODULE METHODS: %s", methods)
|
||||
socketClient := socket.GetClient()
|
||||
socketClient.Emit(utils.SendRoutesWhenConnected, string(bytes))
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func awaitTerminate() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
<-c
|
||||
logger.Info("Shutting down")
|
||||
os.Exit(0)
|
||||
}
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
libStr "gitlab8.alx/msp2.0/msp-lib/structure"
|
||||
"gitlab8.alx/msp2.0/msp-lib/database"
|
||||
"gitlab.alx/msp2.0/msp-lib/database"
|
||||
libStr "gitlab.alx/msp2.0/msp-lib/structure"
|
||||
"gitlab.alx/msp2.0/msp-lib/utils"
|
||||
"time"
|
||||
"gitlab8.alx/msp2.0/msp-lib/utils"
|
||||
)
|
||||
|
||||
const DELETE_TOKENS = "DELETE FROM " + utils.DB_SCHEME + ".tokens WHERE user_id=?"
|
||||
|
||||
+6
-7
@@ -1,11 +1,11 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
libStr "gitlab8.alx/msp2.0/msp-lib/structure"
|
||||
"gitlab8.alx/msp2.0/msp-lib/database"
|
||||
"github.com/go-pg/pg"
|
||||
"gitlab8.alx/msp2.0/msp-lib/utils"
|
||||
"admin-service/structure"
|
||||
"github.com/go-pg/pg"
|
||||
"gitlab.alx/msp2.0/msp-lib/database"
|
||||
libStr "gitlab.alx/msp2.0/msp-lib/structure"
|
||||
"gitlab.alx/msp2.0/msp-lib/utils"
|
||||
)
|
||||
|
||||
const DELETE_USERS = "DELETE FROM " + utils.DB_SCHEME + ".users WHERE id IN (?)"
|
||||
@@ -20,8 +20,8 @@ func GetUserByToken(token string) (*structure.AdminUserShort, error) {
|
||||
u.first_name,
|
||||
u.last_name
|
||||
FROM
|
||||
` + utils.DB_SCHEME + `.tokens
|
||||
t LEFT JOIN ` + utils.DB_SCHEME + `.users u ON t.user_id = u.ID
|
||||
`+utils.DB_SCHEME+`.tokens
|
||||
t LEFT JOIN `+utils.DB_SCHEME+`.users u ON t.user_id = u.ID
|
||||
WHERE
|
||||
token = ?`, token)
|
||||
if err != nil && err == pg.ErrNoRows {
|
||||
@@ -65,7 +65,6 @@ func GetUsers(usersRequest structure.UsersRequest) (*[]libStr.AdminUser, error)
|
||||
query.Where("phone LIKE ?", "%"+usersRequest.Phone+"%")
|
||||
}
|
||||
err := query.
|
||||
|
||||
Order("created_at DESC").
|
||||
Limit(usersRequest.Limit).
|
||||
Offset(usersRequest.Offset).
|
||||
|
||||
@@ -2,4 +2,4 @@ package structure
|
||||
|
||||
type IdentitiesRequest struct {
|
||||
Ids []int64 `json:"ids"`
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,4 @@ package structure
|
||||
|
||||
type DeleteResponse struct {
|
||||
Deleted int
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,7 +1,7 @@
|
||||
package structure
|
||||
|
||||
import (
|
||||
"gitlab8.alx/msp2.0/msp-lib/structure"
|
||||
"gitlab.alx/msp2.0/msp-lib/structure"
|
||||
)
|
||||
|
||||
type UsersResponse struct {
|
||||
@@ -17,10 +17,10 @@ type UsersRequest struct {
|
||||
}
|
||||
|
||||
type AdminUserShort struct {
|
||||
TableName string `sql:"admin_service.users" json:"-"`
|
||||
Image string `json:"image"`
|
||||
FirstName string `json:"firstName"`
|
||||
LastName string `json:"lastName"`
|
||||
Email string `json:"email" valid:"required~Required"`
|
||||
Phone string `json:"phone"`
|
||||
TableName string `sql:"admin_service.users" json:"-"`
|
||||
Image string `json:"image"`
|
||||
FirstName string `json:"firstName"`
|
||||
LastName string `json:"lastName"`
|
||||
Email string `json:"email" valid:"required~Required"`
|
||||
Phone string `json:"phone"`
|
||||
}
|
||||
Reference in new issue
Block a user