generated from PenaSide/GolangTemplate
update cfg after codeconv
This commit is contained in:
parent
e509b1bee2
commit
3640fdd415
@ -28,14 +28,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
urls := []string{
|
urls := []string{
|
||||||
config.AuthMicroservice,
|
config.AuthServiceURL,
|
||||||
config.HubadminMicroservice,
|
config.HubadminServiceURL,
|
||||||
config.CurrencyMicroservice,
|
config.CurrencyServiceURL,
|
||||||
config.DiscountMicroservice,
|
config.DiscountServiceGRPCURL,
|
||||||
config.CodewordMicroservice,
|
config.CodewordServiceGRPCURL,
|
||||||
config.PaymentMicroservice,
|
config.PaymentServiceGRPCURL,
|
||||||
config.VerificationMicroservice,
|
config.VerificationServiceURL,
|
||||||
config.TemplategenMicroserviceURL,
|
config.TemplategenServiceURL,
|
||||||
config.TrashLogHost,
|
config.TrashLogHost,
|
||||||
config.AdminURL,
|
config.AdminURL,
|
||||||
config.ExternalCfg.MailClientCfg.ApiUrl,
|
config.ExternalCfg.MailClientCfg.ApiUrl,
|
||||||
@ -46,7 +46,7 @@ func main() {
|
|||||||
|
|
||||||
// todo validate jwt
|
// todo validate jwt
|
||||||
|
|
||||||
if err = validateKafka(config.KafkaBrokers, config.KafkaTopic); err != nil {
|
if err = validateKafka(config.KafkaBrokers, config.KafkaTopicTariff); err != nil {
|
||||||
log.Fatalf("error validating kafka: %v", err)
|
log.Fatalf("error validating kafka: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +72,9 @@ func loadConfig() (*models.Config, error) {
|
|||||||
config := models.Config{
|
config := models.Config{
|
||||||
ExternalCfg: models.ExternalCfg{
|
ExternalCfg: models.ExternalCfg{
|
||||||
JwtCfg: models.JWTConfiguration{
|
JwtCfg: models.JWTConfiguration{
|
||||||
PublicKey: os.Getenv("JWT_PUBLIC_KEY"),
|
JwtPublicKey: os.Getenv("JWT_PUBLIC_KEY"),
|
||||||
Audience: os.Getenv("JWT_AUDIENCE"),
|
JwtAudience: os.Getenv("JWT_AUDIENCE"),
|
||||||
Issuer: os.Getenv("JWT_ISSUER"),
|
JwtIssuer: os.Getenv("JWT_ISSUER"),
|
||||||
},
|
},
|
||||||
Database: mongo.Configuration{
|
Database: mongo.Configuration{
|
||||||
URL: os.Getenv("MONGO_URL"),
|
URL: os.Getenv("MONGO_URL"),
|
||||||
@ -91,28 +91,25 @@ func loadConfig() (*models.Config, error) {
|
|||||||
PubKey: os.Getenv("ENCRYPT_PUBLIC_KEY"),
|
PubKey: os.Getenv("ENCRYPT_PUBLIC_KEY"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ClientHttpPort: os.Getenv("CLIENT_HTTP_PORT"),
|
ClientHttpURL: os.Getenv("CLIENT_HTTP_URL"),
|
||||||
ClientHttpHost: os.Getenv("CLIENT_HTTP_HOST"),
|
AdminHttpURL: os.Getenv("ADMIN_HTTP_URL"),
|
||||||
AdminHttpPort: os.Getenv("ADMIN_HTTP_PORT"),
|
GrpcURL: os.Getenv("GRPC_URL"),
|
||||||
AdminHttpHost: os.Getenv("ADMIN_HTTP_HOST"),
|
GrpcDomain: os.Getenv("GRPC_DOMAIN"),
|
||||||
GrpcHost: os.Getenv("GRPC_HOST"),
|
KafkaBrokers: strings.Split(os.Getenv("KAFKA_BROKERS"), ","),
|
||||||
GrpcPort: os.Getenv("GRPC_PORT"),
|
KafkaTopicTariff: os.Getenv("KAFKA_TOPIC_TARIFF"),
|
||||||
GrpcDomen: os.Getenv("GRPC_DOMEN"),
|
AuthServiceURL: os.Getenv("AUTH_SERVICE_URL"),
|
||||||
KafkaBrokers: strings.Split(os.Getenv("KAFKA_BROKERS"), ","),
|
HubadminServiceURL: os.Getenv("HUBADMIN_SERVICE_URL"),
|
||||||
KafkaTopic: os.Getenv("KAFKA_TOPIC_TARIFF"),
|
CurrencyServiceURL: os.Getenv("CURRENCY_SERVICE_URL"),
|
||||||
AuthMicroservice: os.Getenv("AUTH_MICROSERVICE_URL"),
|
DiscountServiceGRPCURL: os.Getenv("DISCOUNT_SERVICE_GRPC_URL"),
|
||||||
HubadminMicroservice: os.Getenv("HUBADMIN_MICROSERVICE_URL"),
|
PaymentServiceGRPCURL: os.Getenv("PAYMENT_SERVICE_GRPC_URL"),
|
||||||
CurrencyMicroservice: os.Getenv("CURRENCY_MICROSERVICE_URL"),
|
VerificationServiceURL: os.Getenv("VERIFICATION_SERVICE_URL"),
|
||||||
DiscountMicroservice: os.Getenv("DISCOUNT_MICROSERVICE_GRPC_HOST"),
|
TemplategenServiceURL: os.Getenv("TEMPLATEGEN_SERVICE_URL"),
|
||||||
PaymentMicroservice: os.Getenv("PAYMENT_MICROSERVICE_GRPC_HOST"),
|
CodewordServiceGRPCURL: os.Getenv("CODEWORD_SERVICE_GRPC_URL"),
|
||||||
VerificationMicroservice: os.Getenv("VERIFICATION_MICROSERVICE_URL"),
|
TrashLogHost: os.Getenv("TRASH_LOG_HOST"),
|
||||||
TemplategenMicroserviceURL: os.Getenv("TEMPLATEGEN_MICROSERVICE_URL"),
|
NotificationBotToken: os.Getenv("NOTIFICATION_BOT_TOKEN"),
|
||||||
CodewordMicroservice: os.Getenv("CODEWORD_MICROSERVICE_GRPC_HOST"),
|
NotificationRsPayChannel: envToInt64(os.Getenv("NOTIFICATION_RS_PAY_CHANNEL")),
|
||||||
TrashLogHost: os.Getenv("TRASH_LOG_HOST"),
|
NotificationChannel: envToInt64(os.Getenv("NOTIFICATION_CHANNEL")),
|
||||||
NotificationBotToken: os.Getenv("NOTIFICATION_BOT_TOKEN"),
|
AdminURL: os.Getenv("ADMIN_FRONT_URL"),
|
||||||
NotificationRsPayChannel: envToInt64(os.Getenv("NOTIFICATION_RS_PAY_CHANNEL")),
|
|
||||||
NotificationChannel: envToInt64(os.Getenv("NOTIFICATION_CHANNEL")),
|
|
||||||
AdminURL: os.Getenv("ADMIN_FRONT_URL"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &config, nil
|
return &config, nil
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
|
||||||
"gitea.pena/PenaSide/common/encrypt"
|
"gitea.pena/PenaSide/common/encrypt"
|
||||||
"gitea.pena/PenaSide/common/validate"
|
"gitea.pena/PenaSide/common/validate"
|
||||||
"gitea.pena/PenaSide/customer/internal/models"
|
"gitea.pena/PenaSide/customer/internal/models"
|
||||||
@ -87,41 +86,42 @@ func generateRSAKeys(bitSize int) (privateKey string, publicKey string, err erro
|
|||||||
|
|
||||||
func TestLoadConfig(t *testing.T) {
|
func TestLoadConfig(t *testing.T) {
|
||||||
envVars := map[string]string{
|
envVars := map[string]string{
|
||||||
"JWT_ISSUER": "pena-auth-service",
|
"JWT_ISSUER": "pena-auth-service",
|
||||||
"JWT_AUDIENCE": "pena",
|
"JWT_AUDIENCE": "pena",
|
||||||
"JWT_PUBLIC_KEY": "-----BEGIN PUBLIC KEY-----\nMIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHgnvr7O2tiApjJfid1orFnIGm69\n80fZp+Lpbjo+NC/0whMFga2Biw5b1G2Q/B2u0tpO1Fs/E8z7Lv1nYfr5jx2S8x6B\ndA4TS2kB9Kf0wn0+7wSlyikHoKhbtzwXHZl17GsyEi6wHnsqNBSauyIWhpha8i+Y\n+3GyaOY536H47qyXAgMBAAE=\n-----END PUBLIC KEY-----",
|
"JWT_PUBLIC_KEY": "-----BEGIN PUBLIC KEY-----\nMIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHgnvr7O2tiApjJfid1orFnIGm69\n80fZp+Lpbjo+NC/0whMFga2Biw5b1G2Q/B2u0tpO1Fs/E8z7Lv1nYfr5jx2S8x6B\ndA4TS2kB9Kf0wn0+7wSlyikHoKhbtzwXHZl17GsyEi6wHnsqNBSauyIWhpha8i+Y\n+3GyaOY536H47qyXAgMBAAE=\n-----END PUBLIC KEY-----",
|
||||||
"CLIENT_HTTP_HOST": "0.0.0.0",
|
"CLIENT_HTTP_URL": "0.0.0.0:8080",
|
||||||
"CLIENT_HTTP_PORT": "8080",
|
"ADMIN_HTTP_URL": "0.0.0.0:8081",
|
||||||
"ADMIN_HTTP_HOST": "0.0.0.0",
|
"GRPC_URL": "0.0.0.0:9001",
|
||||||
"ADMIN_HTTP_PORT": "8081",
|
"GRPC_DOMAIN": "customer-service:9000",
|
||||||
"GRPC_HOST": "0.0.0.0",
|
"MONGO_URL": "mongodb://test:test@localhost:27020/",
|
||||||
"GRPC_PORT": "9001",
|
"MONGO_DB_NAME": "admin",
|
||||||
"GRPC_DOMEN": "customer-service:9000",
|
"KAFKA_BROKERS": "localhost:9092",
|
||||||
"MONGO_URL": "mongodb://test:test@localhost:27020/",
|
"KAFKA_TOPIC_TARIFF": "test-topic",
|
||||||
"MONGO_DB_NAME": "admin",
|
"AUTH_SERVICE_URL": "http://localhost:8000/user",
|
||||||
"KAFKA_BROKERS": "localhost:9092",
|
"HUBADMIN_SERVICE_URL": "http://localhost:8001/tariff",
|
||||||
"KAFKA_TOPIC_TARIFF": "test-topic",
|
"CURRENCY_SERVICE_URL": "http://cbrfworker-service:8000/change",
|
||||||
"AUTH_MICROSERVICE_URL": "http://localhost:8000/user",
|
"DISCOUNT_SERVICE_GRPC_URL": "localhost:9040",
|
||||||
"HUBADMIN_MICROSERVICE_URL": "http://localhost:8001/tariff",
|
"PAYMENT_SERVICE_GRPC_URL": "treasurer-service:9085",
|
||||||
"CURRENCY_MICROSERVICE_URL": "http://cbrfworker-service:8000/change",
|
"VERIFICATION_SERVICE_URL": "http://10.8.0.8:7035/verification",
|
||||||
"DISCOUNT_MICROSERVICE_GRPC_HOST": "localhost:9040",
|
"TEMPLATEGEN_SERVICE_URL": "10.6.0.17",
|
||||||
"PAYMENT_MICROSERVICE_GRPC_HOST": "treasurer-service:9085",
|
"CODEWORD_SERVICE_GRPC_URL": "http://localhost:8000/user",
|
||||||
"VERIFICATION_MICROSERVICE_URL": "http://10.8.0.8:7035/verification",
|
"TRASH_LOG_HOST": "localhost:7113",
|
||||||
"TEMPLATEGEN_MICROSERVICE_URL": "10.6.0.17",
|
"API_URL": "https://api.smtp.bz/v1/smtp/send",
|
||||||
"CODEWORD_MICROSERVICE_GRPC_HOST": "http://localhost:8000/user",
|
"MAIL_SENDER": "noreply@mailing.pena.digital",
|
||||||
"TRASH_LOG_HOST": "localhost:7113",
|
"MAIL_API_KEY": "P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev",
|
||||||
"API_URL": "https://api.smtp.bz/v1/smtp/send",
|
"MAIL_ADDRESS": "mail@mail.com",
|
||||||
"MAIL_SENDER": "noreply@mailing.pena.digital",
|
"NOTIFICATION_BOT_TOKEN": "7127966184:AAG1steOCH4wDvHRe9QcsXJPS4dWRyRYsqg",
|
||||||
"MAIL_API_KEY": "P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev",
|
"NOTIFICATION_CHANNEL": "-1002177203276",
|
||||||
"MAIL_ADDRESS": "mail@mail.com",
|
"NOTIFICATION_RS_PAY_CHANNEL": "-1002177203276",
|
||||||
"NOTIFICATION_BOT_TOKEN": "7127966184:AAG1steOCH4wDvHRe9QcsXJPS4dWRyRYsqg",
|
"ADMIN_FRONT_URL": "https://admin-front.ru",
|
||||||
"NOTIFICATION_CHANNEL": "-1002177203276",
|
|
||||||
"NOTIFICATION_RS_PAY_CHANNEL": "-1002177203276",
|
|
||||||
"ADMIN_FRONT_URL": "https://admin-front.ru",
|
|
||||||
"ENCRYPT_PUBLIC_KEY": "1",
|
|
||||||
"ENCRYPT_PRIVATE_KEY": "2",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
priveKey, pubKey, err := generateRSAKeys(2048)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
envVars["ENCRYPT_PUBLIC_KEY"] = pubKey
|
||||||
|
envVars["ENCRYPT_PRIVATE_KEY"] = priveKey
|
||||||
|
|
||||||
for key, value := range envVars {
|
for key, value := range envVars {
|
||||||
os.Setenv(key, value)
|
os.Setenv(key, value)
|
||||||
}
|
}
|
||||||
@ -129,5 +129,48 @@ func TestLoadConfig(t *testing.T) {
|
|||||||
cfg, err := loadConfig()
|
cfg, err := loadConfig()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
fmt.Println(cfg)
|
err = validateNotEmpty(cfg)
|
||||||
|
if err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
urls := []string{
|
||||||
|
cfg.AuthServiceURL,
|
||||||
|
cfg.HubadminServiceURL,
|
||||||
|
cfg.CurrencyServiceURL,
|
||||||
|
cfg.DiscountServiceGRPCURL,
|
||||||
|
cfg.CodewordServiceGRPCURL,
|
||||||
|
cfg.PaymentServiceGRPCURL,
|
||||||
|
cfg.VerificationServiceURL,
|
||||||
|
cfg.TemplategenServiceURL,
|
||||||
|
cfg.TrashLogHost,
|
||||||
|
cfg.AdminURL,
|
||||||
|
cfg.ExternalCfg.MailClientCfg.ApiUrl,
|
||||||
|
}
|
||||||
|
if err = validateURLs(urls); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo validate jwt
|
||||||
|
|
||||||
|
if err = validateKafka(cfg.KafkaBrokers, cfg.KafkaTopicTariff); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = validateMail(cfg.ExternalCfg.MailClientCfg); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = validate.ValidateEncryptKeys(&cfg.ExternalCfg.EncryptCommon); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = validateTG(cfg.NotificationBotToken, cfg.NotificationRsPayChannel, cfg.NotificationChannel); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = validate.ValidateMongo(cfg.ExternalCfg.Database); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,11 @@ services:
|
|||||||
labels:
|
labels:
|
||||||
com.pena.allowed_headers: content-type,authorization,response-type
|
com.pena.allowed_headers: content-type,authorization,response-type
|
||||||
environment:
|
environment:
|
||||||
- CLIENT_HTTP_HOST=0.0.0.0
|
- CLIENT_HTTP_URL=0.0.0.0:8065
|
||||||
- CLIENT_HTTP_PORT=8065
|
- ADMIN_HTTP_URL=0.0.0.0:8066
|
||||||
- ADMIN_HTTP_HOST=0.0.0.0
|
|
||||||
- ADMIN_HTTP_PORT=8066
|
|
||||||
|
|
||||||
- GRPC_HOST=0.0.0.0
|
- GRPC_URL=0.0.0.0:9065
|
||||||
- GRPC_PORT=9065
|
- GRPC_DOMAIN=10.8.0.6:9060
|
||||||
- GRPC_DOMEN=10.8.0.6:9060
|
|
||||||
|
|
||||||
# - MONGO_HOST=10.7.0.4
|
# - MONGO_HOST=10.7.0.4
|
||||||
# - MONGO_PORT=27017
|
# - MONGO_PORT=27017
|
||||||
@ -30,15 +27,15 @@ services:
|
|||||||
- KAFKA_BROKERS=10.8.0.6:9092
|
- KAFKA_BROKERS=10.8.0.6:9092
|
||||||
- KAFKA_TOPIC_TARIFF=tariffs
|
- KAFKA_TOPIC_TARIFF=tariffs
|
||||||
|
|
||||||
- AUTH_MICROSERVICE_URL=http://10.8.0.6:59300
|
- AUTH_SERVICE_URL=http://10.8.0.6:59300
|
||||||
- HUBADMIN_MICROSERVICE_URL=http://10.8.0.6:59303
|
- HUBADMIN_SERVICE_URL=http://10.8.0.6:59303
|
||||||
- CURRENCY_MICROSERVICE_URL=http://10.8.0.6:3131
|
- CURRENCY_SERVICE_URL=http://10.8.0.6:3131
|
||||||
- DISCOUNT_MICROSERVICE_GRPC_HOST=10.8.0.6:9001
|
- DISCOUNT_SERVICE_GRPC_URL=10.8.0.6:9001
|
||||||
- PAYMENT_MICROSERVICE_GRPC_HOST=10.8.0.6:9085
|
- PAYMENT_SERVICE_GRPC_URL=10.8.0.6:9085
|
||||||
- VERIFICATION_MICROSERVICE_URL=http://10.8.0.6:7036
|
- VERIFICATION_SERVICE_URL=http://10.8.0.6:7036
|
||||||
- TEMPLATEGEN_MICROSERVICE_URL=http://10.6.0.17
|
- TEMPLATEGEN_SERVICE_URL=http://10.6.0.17
|
||||||
- API_URL=https://api.smtp.bz/v1/smtp/send
|
- API_URL=https://api.smtp.bz/v1/smtp/send
|
||||||
- CODEWORD_MICROSERVICE_GRPC_HOST=10.8.0.6:59665
|
- CODEWORD_SERVICE_GRPC_URL=10.8.0.6:59665
|
||||||
- MAIL_SENDER=noreply@mailing.pena.digital
|
- MAIL_SENDER=noreply@mailing.pena.digital
|
||||||
- MAIL_API_KEY=P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev
|
- MAIL_API_KEY=P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev
|
||||||
- MAIL_ADDRESS=sells@pena.digital
|
- MAIL_ADDRESS=sells@pena.digital
|
||||||
|
@ -61,7 +61,7 @@ func Run(config *models.Config, logger *zap.Logger, build Build) (appErr error)
|
|||||||
loggerHlog.Emit(app.InfoSvcStarted{})
|
loggerHlog.Emit(app.InfoSvcStarted{})
|
||||||
|
|
||||||
if err = kafka.Initialize(ctx, config.KafkaBrokers, []string{
|
if err = kafka.Initialize(ctx, config.KafkaBrokers, []string{
|
||||||
config.KafkaTopic,
|
config.KafkaTopicTariff,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("failed initialize kafka: %w", err)
|
return fmt.Errorf("failed initialize kafka: %w", err)
|
||||||
}
|
}
|
||||||
@ -77,8 +77,8 @@ func Run(config *models.Config, logger *zap.Logger, build Build) (appErr error)
|
|||||||
kafkaTariffClient, err := kgo.NewClient(
|
kafkaTariffClient, err := kgo.NewClient(
|
||||||
kgo.SeedBrokers(config.KafkaBrokers...),
|
kgo.SeedBrokers(config.KafkaBrokers...),
|
||||||
kgo.ConsumeResetOffset(kgo.NewOffset().AtStart()),
|
kgo.ConsumeResetOffset(kgo.NewOffset().AtStart()),
|
||||||
kgo.DefaultProduceTopic(config.KafkaTopic),
|
kgo.DefaultProduceTopic(config.KafkaTopicTariff),
|
||||||
kgo.ConsumeTopics(config.KafkaTopic),
|
kgo.ConsumeTopics(config.KafkaTopicTariff),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -117,15 +117,15 @@ func Run(config *models.Config, logger *zap.Logger, build Build) (appErr error)
|
|||||||
|
|
||||||
clients := initialize.NewClients(initialize.ClientsDeps{
|
clients := initialize.NewClients(initialize.ClientsDeps{
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
AuthURL: config.AuthMicroservice,
|
AuthURL: config.AuthServiceURL,
|
||||||
HubadminURL: config.HubadminMicroservice,
|
HubadminURL: config.HubadminServiceURL,
|
||||||
CurrencyURL: config.CurrencyMicroservice,
|
CurrencyURL: config.CurrencyServiceURL,
|
||||||
DiscountServiceURL: config.DiscountMicroservice,
|
DiscountServiceURL: config.DiscountServiceGRPCURL,
|
||||||
PaymentServiceURL: config.PaymentMicroservice,
|
PaymentServiceURL: config.PaymentServiceGRPCURL,
|
||||||
VerificationURL: config.VerificationMicroservice,
|
VerificationURL: config.VerificationServiceURL,
|
||||||
TemplategenURL: config.TemplategenMicroserviceURL,
|
TemplategenURL: config.TemplategenServiceURL,
|
||||||
MailClient: config.ExternalCfg.MailClientCfg,
|
MailClient: config.ExternalCfg.MailClientCfg,
|
||||||
CodewordServiceHost: config.CodewordMicroservice,
|
CodewordServiceHost: config.CodewordServiceGRPCURL,
|
||||||
Notifier: notificationBot,
|
Notifier: notificationBot,
|
||||||
NotificationRsPayChannel: config.NotificationRsPayChannel,
|
NotificationRsPayChannel: config.NotificationRsPayChannel,
|
||||||
})
|
})
|
||||||
@ -160,7 +160,7 @@ func Run(config *models.Config, logger *zap.Logger, build Build) (appErr error)
|
|||||||
Logger: logger,
|
Logger: logger,
|
||||||
Encrypt: encrypt,
|
Encrypt: encrypt,
|
||||||
Producer: brokers.TariffProducer,
|
Producer: brokers.TariffProducer,
|
||||||
GRPCDomain: config.GrpcDomen,
|
GRPCDomain: config.GrpcDomain,
|
||||||
Repositories: repositories,
|
Repositories: repositories,
|
||||||
Clients: clients,
|
Clients: clients,
|
||||||
MiddleWare: middleWare,
|
MiddleWare: middleWare,
|
||||||
@ -191,20 +191,20 @@ func Run(config *models.Config, logger *zap.Logger, build Build) (appErr error)
|
|||||||
serverGRPC.Register(rpcControllers)
|
serverGRPC.Register(rpcControllers)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := serverClientHTTP.Start(config.ClientHttpHost + ":" + config.ClientHttpPort); err != nil {
|
if err := serverClientHTTP.Start(config.ClientHttpURL); err != nil {
|
||||||
logger.Error("Server external startup error", zap.Error(err))
|
logger.Error("Server external startup error", zap.Error(err))
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := serverAdminHTTP.Start(config.AdminHttpHost + ":" + config.AdminHttpPort); err != nil {
|
if err := serverAdminHTTP.Start(config.AdminHttpURL); err != nil {
|
||||||
logger.Error("Server internal startup error", zap.Error(err))
|
logger.Error("Server internal startup error", zap.Error(err))
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go serverGRPC.Run(config.GrpcHost, config.GrpcPort)
|
go serverGRPC.Run(config.GrpcURL)
|
||||||
|
|
||||||
closer.Add(mongoDB.Client().Disconnect)
|
closer.Add(mongoDB.Client().Disconnect)
|
||||||
closer.Add(serverClientHTTP.Shutdown)
|
closer.Add(serverClientHTTP.Shutdown)
|
||||||
|
@ -55,30 +55,27 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
|
|||||||
defaultCurrencyURL := "http://www.currency.ru/change"
|
defaultCurrencyURL := "http://www.currency.ru/change"
|
||||||
|
|
||||||
defaultConfiguration := models.Config{
|
defaultConfiguration := models.Config{
|
||||||
ClientHttpHost: "localhost",
|
ClientHttpURL: "localhost:8080",
|
||||||
ClientHttpPort: "8080",
|
AdminHttpURL: "localhost:8081",
|
||||||
AdminHttpHost: "localhost",
|
GrpcURL: "localhost:8081",
|
||||||
AdminHttpPort: "8081",
|
GrpcDomain: "domain",
|
||||||
GrpcHost: "localhost",
|
AuthServiceURL: defaultAuthURL,
|
||||||
GrpcPort: "8081",
|
KafkaTopicTariff: "topic",
|
||||||
GrpcDomen: "domen",
|
KafkaBrokers: []string{"localhost:8080", "localhost:8081"},
|
||||||
AuthMicroservice: defaultAuthURL,
|
HubadminServiceURL: defaultHubAdminURL,
|
||||||
KafkaTopic: "topic",
|
CurrencyServiceURL: defaultCurrencyURL,
|
||||||
KafkaBrokers: []string{"localhost:8080", "localhost:8081"},
|
DiscountServiceGRPCURL: "domen",
|
||||||
HubadminMicroservice: defaultHubAdminURL,
|
PaymentServiceGRPCURL: "domen",
|
||||||
CurrencyMicroservice: defaultCurrencyURL,
|
VerificationServiceURL: "domen",
|
||||||
DiscountMicroservice: "domen",
|
TemplategenServiceURL: "domen",
|
||||||
PaymentMicroservice: "domen",
|
|
||||||
VerificationMicroservice: "domen",
|
|
||||||
TemplategenMicroserviceURL: "domen",
|
|
||||||
ExternalCfg: models.ExternalCfg{
|
ExternalCfg: models.ExternalCfg{
|
||||||
JwtCfg: models.JWTConfiguration{
|
JwtCfg: models.JWTConfiguration{
|
||||||
PrivateKey: "jwt private key",
|
JwtPrivateKey: "jwt private key",
|
||||||
PublicKey: "jwt public key",
|
JwtPublicKey: "jwt public key",
|
||||||
Issuer: "issuer",
|
JwtIssuer: "issuer",
|
||||||
Audience: "audience",
|
JwtAudience: "audience",
|
||||||
Algorithm: *jwt.SigningMethodRS256,
|
Algorithm: *jwt.SigningMethodRS256,
|
||||||
ExpiresIn: 15 * time.Minute,
|
ExpiresIn: 15 * time.Minute,
|
||||||
},
|
},
|
||||||
Database: mongo.Configuration{
|
Database: mongo.Configuration{
|
||||||
URL: "mongodb://test:test@localhost:27020/",
|
URL: "mongodb://test:test@localhost:27020/",
|
||||||
@ -87,25 +84,24 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Setenv("GRPC_HOST", defaultConfiguration.GrpcHost)
|
t.Setenv("GRPC_URL", defaultConfiguration.GrpcURL)
|
||||||
t.Setenv("GRPC_PORT", defaultConfiguration.GrpcPort)
|
t.Setenv("GRPC_DOMAIN", defaultConfiguration.GrpcDomain)
|
||||||
t.Setenv("GRPC_DOMEN", defaultConfiguration.GrpcDomen)
|
|
||||||
|
|
||||||
t.Setenv("JWT_PUBLIC_KEY", defaultConfiguration.ExternalCfg.JwtCfg.PublicKey)
|
t.Setenv("JWT_PUBLIC_KEY", defaultConfiguration.ExternalCfg.JwtCfg.JwtPublicKey)
|
||||||
t.Setenv("JWT_PRIVATE_KEY", defaultConfiguration.ExternalCfg.JwtCfg.PrivateKey)
|
t.Setenv("JWT_PRIVATE_KEY", defaultConfiguration.ExternalCfg.JwtCfg.JwtPrivateKey)
|
||||||
t.Setenv("JWT_ISSUER", defaultConfiguration.ExternalCfg.JwtCfg.Issuer)
|
t.Setenv("JWT_ISSUER", defaultConfiguration.ExternalCfg.JwtCfg.JwtIssuer)
|
||||||
t.Setenv("JWT_AUDIENCE", defaultConfiguration.ExternalCfg.JwtCfg.Audience)
|
t.Setenv("JWT_AUDIENCE", defaultConfiguration.ExternalCfg.JwtCfg.JwtAudience)
|
||||||
|
|
||||||
t.Setenv("KAFKA_BROKERS", "localhost:8080,localhost:8081")
|
t.Setenv("KAFKA_BROKERS", "localhost:8080,localhost:8081")
|
||||||
t.Setenv("KAFKA_TOPIC_TARIFF", defaultConfiguration.KafkaTopic)
|
t.Setenv("KAFKA_TOPIC_TARIFF", defaultConfiguration.KafkaTopicTariff)
|
||||||
|
|
||||||
t.Setenv("AUTH_MICROSERVICE_URL", defaultConfiguration.AuthMicroservice)
|
t.Setenv("AUTH_SERVICE_URL", defaultConfiguration.AuthServiceURL)
|
||||||
t.Setenv("HUBADMIN_MICROSERVICE_URL", defaultConfiguration.HubadminMicroservice)
|
t.Setenv("HUBADMIN_SERVICE_URL", defaultConfiguration.HubadminServiceURL)
|
||||||
t.Setenv("CURRENCY_MICROSERVICE_URL", defaultConfiguration.CurrencyMicroservice)
|
t.Setenv("CURRENCY_SERVICE_URL", defaultConfiguration.CurrencyServiceURL)
|
||||||
t.Setenv("DISCOUNT_MICROSERVICE_GRPC_HOST", defaultConfiguration.DiscountMicroservice)
|
t.Setenv("DISCOUNT_SERVICE_GRPC_URL", defaultConfiguration.DiscountServiceGRPCURL)
|
||||||
t.Setenv("PAYMENT_MICROSERVICE_GRPC_HOST", defaultConfiguration.PaymentMicroservice)
|
t.Setenv("PAYMENT_SERVICE_GRPC_URL", defaultConfiguration.PaymentServiceGRPCURL)
|
||||||
t.Setenv("VERIFICATION_MICROSERVICE_URL", defaultConfiguration.VerificationMicroservice)
|
t.Setenv("VERIFICATION_SERVICE_URL", defaultConfiguration.VerificationServiceURL)
|
||||||
t.Setenv("TEMPLATEGEN_MICROSERVICE_URL", defaultConfiguration.TemplategenMicroserviceURL)
|
t.Setenv("TEMPLATEGEN_SERVICE_URL", defaultConfiguration.TemplategenServiceURL)
|
||||||
|
|
||||||
t.Setenv("MONGO_URL", defaultConfiguration.ExternalCfg.Database.URL)
|
t.Setenv("MONGO_URL", defaultConfiguration.ExternalCfg.Database.URL)
|
||||||
t.Setenv("MONGO_DB_NAME", defaultConfiguration.ExternalCfg.Database.DatabaseName)
|
t.Setenv("MONGO_DB_NAME", defaultConfiguration.ExternalCfg.Database.DatabaseName)
|
||||||
|
@ -9,29 +9,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ClientHttpHost string `env:"CLIENT_HTTP_HOST,default=localhost"`
|
ClientHttpURL string `env:"CLIENT_HTTP_URL,default=localhost:8080"`
|
||||||
ClientHttpPort string `env:"CLIENT_HTTP_PORT,default=8080"`
|
AdminHttpURL string `env:"ADMIN_HTTP_URL,default=localhost:8081"`
|
||||||
AdminHttpHost string `env:"ADMIN_HTTP_HOST,default=localhost"`
|
GrpcURL string `env:"GRPC_URL,default=localhost:8081"`
|
||||||
AdminHttpPort string `env:"ADMIN_HTTP_PORT,default=8081"`
|
GrpcDomain string `env:"GRPC_DOMAIN,default=https://domen.ru"`
|
||||||
GrpcHost string `env:"GRPC_HOST,default=localhost"`
|
AuthServiceURL string `env:"AUTH_SERVICE_URL,required"` // http://10.8.0.6:59300/user
|
||||||
GrpcPort string `env:"GRPC_PORT,default=8081"`
|
HubadminServiceURL string `env:"HUBADMIN_SERVICE_URL,required"` // http://10.8.0.6:59303/tariff
|
||||||
GrpcDomen string `env:"GRPC_DOMEN,default=https://domen.ru"`
|
CurrencyServiceURL string `env:"CURRENCY_SERVICE_URL,required"` // http://10.8.0.6:3131/change
|
||||||
AuthMicroservice string `env:"AUTH_MICROSERVICE_URL,required"` // http://10.8.0.6:59300/user
|
DiscountServiceGRPCURL string `env:"DISCOUNT_SERVICE_GRPC_URL,required"`
|
||||||
HubadminMicroservice string `env:"HUBADMIN_MICROSERVICE_URL,required"` // http://10.8.0.6:59303/tariff
|
CodewordServiceGRPCURL string `env:"CODEWORD_SERVICE_GRPC_URL,required"`
|
||||||
CurrencyMicroservice string `env:"CURRENCY_MICROSERVICE_URL,required"` // http://10.8.0.6:3131/change
|
PaymentServiceGRPCURL string `env:"PAYMENT_SERVICE_GRPC_URL,required"`
|
||||||
DiscountMicroservice string `env:"DISCOUNT_MICROSERVICE_GRPC_HOST,required"`
|
VerificationServiceURL string `env:"VERIFICATION_SERVICE_URL,required"` // http://10.8.0.6:7036/verification
|
||||||
CodewordMicroservice string `env:"CODEWORD_MICROSERVICE_GRPC_HOST,required"`
|
TemplategenServiceURL string `env:"TEMPLATEGEN_SERVICE_URL,required"` // http://10.6.0.17/generator/service
|
||||||
PaymentMicroservice string `env:"PAYMENT_MICROSERVICE_GRPC_HOST,required"`
|
KafkaTopicTariff string `json:"topic" env:"KAFKA_TOPIC_TARIFF,required"`
|
||||||
VerificationMicroservice string `env:"VERIFICATION_MICROSERVICE_URL,required"` // http://10.8.0.6:7036/verification
|
KafkaBrokers []string `json:"brokers" env:"KAFKA_BROKERS,required"`
|
||||||
TemplategenMicroserviceURL string `env:"TEMPLATEGEN_MICROSERVICE_URL,required"` // http://10.6.0.17/generator/service
|
TrashLogHost string `env:"TRASH_LOG_HOST"`
|
||||||
KafkaTopic string `json:"topic" env:"KAFKA_TOPIC_TARIFF,required"`
|
NotificationBotToken string `env:"NOTIFICATION_BOT_TOKEN"`
|
||||||
KafkaBrokers []string `json:"brokers" env:"KAFKA_BROKERS,required"`
|
NotificationChannel int64 `env:"NOTIFICATION_CHANNEL"`
|
||||||
TrashLogHost string `env:"TRASH_LOG_HOST"`
|
AdminURL string `env:"ADMIN_FRONT_URL"`
|
||||||
NotificationBotToken string `env:"NOTIFICATION_BOT_TOKEN"`
|
NotificationRsPayChannel int64 `env:"NOTIFICATION_RS_PAY_CHANNEL"`
|
||||||
NotificationChannel int64 `env:"NOTIFICATION_CHANNEL"`
|
ExternalCfg ExternalCfg
|
||||||
AdminURL string `env:"ADMIN_FRONT_URL"`
|
|
||||||
NotificationRsPayChannel int64 `env:"NOTIFICATION_RS_PAY_CHANNEL"`
|
|
||||||
ExternalCfg ExternalCfg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExternalCfg struct {
|
type ExternalCfg struct {
|
||||||
@ -50,12 +47,12 @@ type MailClientCfg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type JWTConfiguration struct {
|
type JWTConfiguration struct {
|
||||||
PrivateKey string `env:"JWT_PRIVATE_KEY"`
|
JwtPrivateKey string `env:"JWT_PRIVATE_KEY"`
|
||||||
PublicKey string `env:"JWT_PUBLIC_KEY,required"`
|
JwtPublicKey string `env:"JWT_PUBLIC_KEY,required"`
|
||||||
Issuer string `env:"JWT_ISSUER,required"`
|
JwtIssuer string `env:"JWT_ISSUER,required"`
|
||||||
Audience string `env:"JWT_AUDIENCE,required"`
|
JwtAudience string `env:"JWT_AUDIENCE,required"`
|
||||||
Algorithm jwt.SigningMethodRSA
|
Algorithm jwt.SigningMethodRSA
|
||||||
ExpiresIn time.Duration
|
ExpiresIn time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
const mongoVersion uint32 = 1
|
const mongoVersion uint32 = 1
|
||||||
|
@ -2,7 +2,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -47,12 +46,10 @@ func NewGRPC(deps DepsGRPC) (*GRPC, errors.Error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver *GRPC) Run(host, port string) {
|
func (receiver *GRPC) Run(addr string) {
|
||||||
connectionString := fmt.Sprintf("%s:%s", host, port)
|
receiver.logger.Info("Starting GRPC Server", zap.String("host", addr))
|
||||||
|
|
||||||
receiver.logger.Info("Starting GRPC Server", zap.String("host", connectionString))
|
if err := receiver.listen(addr); err != nil && err != grpc.ErrServerStopped {
|
||||||
|
|
||||||
if err := receiver.listen(connectionString); err != nil && err != grpc.ErrServerStopped {
|
|
||||||
receiver.logger.Error("GRPC Listen error", zap.Error(err))
|
receiver.logger.Error("GRPC Listen error", zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@ type JWT struct {
|
|||||||
|
|
||||||
func NewJWT(configuration *models.JWTConfiguration) *JWT {
|
func NewJWT(configuration *models.JWTConfiguration) *JWT {
|
||||||
return &JWT{
|
return &JWT{
|
||||||
privateKey: []byte(configuration.PrivateKey),
|
privateKey: []byte(configuration.JwtPrivateKey),
|
||||||
publicKey: []byte(configuration.PublicKey),
|
publicKey: []byte(configuration.JwtPublicKey),
|
||||||
algorithm: &configuration.Algorithm,
|
algorithm: &configuration.Algorithm,
|
||||||
expiresIn: configuration.ExpiresIn,
|
expiresIn: configuration.ExpiresIn,
|
||||||
issuer: configuration.Issuer,
|
issuer: configuration.JwtIssuer,
|
||||||
audience: configuration.Audience,
|
audience: configuration.JwtAudience,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt/v5"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"gitea.pena/PenaSide/customer/internal/models"
|
"gitea.pena/PenaSide/customer/internal/models"
|
||||||
"gitea.pena/PenaSide/customer/internal/utils"
|
"gitea.pena/PenaSide/customer/internal/utils"
|
||||||
|
"github.com/golang-jwt/jwt/v5"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestJWT(t *testing.T) {
|
func TestJWT(t *testing.T) {
|
||||||
@ -93,12 +93,12 @@ func TestJWT(t *testing.T) {
|
|||||||
privateKey = strings.Replace(privateKey, "\t", "", -1)
|
privateKey = strings.Replace(privateKey, "\t", "", -1)
|
||||||
|
|
||||||
jwt := utils.NewJWT(&models.JWTConfiguration{
|
jwt := utils.NewJWT(&models.JWTConfiguration{
|
||||||
PrivateKey: privateKey,
|
JwtPrivateKey: privateKey,
|
||||||
PublicKey: publicKey,
|
JwtPublicKey: publicKey,
|
||||||
Algorithm: *jwt.SigningMethodRS256,
|
Algorithm: *jwt.SigningMethodRS256,
|
||||||
ExpiresIn: 15 * time.Minute,
|
ExpiresIn: 15 * time.Minute,
|
||||||
Issuer: "issuer1",
|
JwtIssuer: "issuer1",
|
||||||
Audience: "audience1",
|
JwtAudience: "audience1",
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Успешная генерация токена", func(t *testing.T) {
|
t.Run("Успешная генерация токена", func(t *testing.T) {
|
||||||
|
@ -4,9 +4,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt/v5"
|
|
||||||
"gitea.pena/PenaSide/customer/internal/models"
|
"gitea.pena/PenaSide/customer/internal/models"
|
||||||
"gitea.pena/PenaSide/customer/internal/utils"
|
"gitea.pena/PenaSide/customer/internal/utils"
|
||||||
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitializeJWT() *utils.JWT {
|
func InitializeJWT() *utils.JWT {
|
||||||
@ -33,11 +33,11 @@ func InitializeJWT() *utils.JWT {
|
|||||||
-----END RSA PRIVATE KEY-----`, "\t", "", -1)
|
-----END RSA PRIVATE KEY-----`, "\t", "", -1)
|
||||||
|
|
||||||
return utils.NewJWT(&models.JWTConfiguration{
|
return utils.NewJWT(&models.JWTConfiguration{
|
||||||
PrivateKey: privateKey,
|
JwtPrivateKey: privateKey,
|
||||||
PublicKey: publicKey,
|
JwtPublicKey: publicKey,
|
||||||
Audience: "pena",
|
JwtAudience: "pena",
|
||||||
Issuer: "pena-auth-service",
|
JwtIssuer: "pena-auth-service",
|
||||||
Algorithm: *jwt.SigningMethodRS256,
|
Algorithm: *jwt.SigningMethodRS256,
|
||||||
ExpiresIn: 15 * time.Minute,
|
ExpiresIn: 15 * time.Minute,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user