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