diff --git a/DB/migrations/000002_init_roles.up.sql b/DB/migrations/000002_init_roles.up.sql index 9ffc16cb..6e6fae63 100644 --- a/DB/migrations/000002_init_roles.up.sql +++ b/DB/migrations/000002_init_roles.up.sql @@ -3,20 +3,17 @@ ALTER ROLE admin SUPERUSER; CREATE ROLE profile_service WITH LOGIN PASSWORD 'profile_password'; GRANT CONNECT ON DATABASE mydbvk TO profile_service; -GRANT SELECT, INSERT, DELETE, UPDATE ON profile, friend TO profile_service; +GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES, TRUNCATE, TRIGGER, MAINTAIN ON profile, friend TO profile_service; CREATE ROLE community_service WITH LOGIN PASSWORD 'community_password'; GRANT CONNECT ON DATABASE mydbvk TO community_service; GRANT USAGE ON SCHEMA public TO community_service; -GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES, TRUNCATE, TRIGGER, MAINTAIN ON community, community_profile TO community_service; -GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO community_service; -GRANT ALL PRIVILEGES ON community, community_profile, admin TO community_service; -GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO community_service; +GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES, TRUNCATE, TRIGGER, MAINTAIN ON community, community_profile, admin TO community_service; CREATE ROLE post_service WITH LOGIN PASSWORD 'post_password'; GRANT CONNECT ON DATABASE mydbvk TO post_service; -GRANT SELECT, INSERT, DELETE, UPDATE ON post, comment, reaction TO post_service; +GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES, TRUNCATE, TRIGGER, MAINTAIN ON post, comment, reaction TO post_service; CREATE ROLE message_service WITH LOGIN PASSWORD 'message_password'; GRANT CONNECT ON DATABASE mydbvk TO message_service; -GRANT SELECT, INSERT, DELETE ON message TO message_service; \ No newline at end of file +GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES, TRUNCATE, TRIGGER, MAINTAIN ON message TO message_service; \ No newline at end of file diff --git a/internal/app/chat/app.go b/internal/app/chat/app.go index 67fd463f..0b9ecdfb 100644 --- a/internal/app/chat/app.go +++ b/internal/app/chat/app.go @@ -28,12 +28,12 @@ func GetServer(cfg *config.Config, chatMetrics *metrics.HttpMetrics) (*http.Serv } connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", - cfg.DB.Host, - cfg.DB.Port, - cfg.DB.User, - cfg.DB.Pass, - cfg.DB.DBName, - cfg.DB.SSLMode, + cfg.MESSAGEDB.Host, + cfg.MESSAGEDB.Port, + cfg.MESSAGEDB.User, + cfg.MESSAGEDB.Pass, + cfg.MESSAGEDB.DBName, + cfg.MESSAGEDB.SSLMode, ) postgresDB, err := start_postgres.StartPostgres(connStr, logger) diff --git a/internal/app/community/app.go b/internal/app/community/app.go index 85992454..a887d80b 100644 --- a/internal/app/community/app.go +++ b/internal/app/community/app.go @@ -38,12 +38,12 @@ func GetServers(cfg *config.Config, grpcMetrics *metrics.GrpcMetrics, communityM } connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", - cfg.DB.Host, - cfg.DB.Port, - cfg.DB.User, - cfg.DB.Pass, - cfg.DB.DBName, - cfg.DB.SSLMode, + cfg.COMMUNITYDB.Host, + cfg.COMMUNITYDB.Port, + cfg.COMMUNITYDB.User, + cfg.COMMUNITYDB.Pass, + cfg.COMMUNITYDB.DBName, + cfg.COMMUNITYDB.SSLMode, ) postgresDB, err := start_postgres.StartPostgres(connStr, logger) diff --git a/internal/app/post/app.go b/internal/app/post/app.go index b53298a4..617a3c3f 100644 --- a/internal/app/post/app.go +++ b/internal/app/post/app.go @@ -39,12 +39,12 @@ func GetHTTPServer(cfg *config.Config, postMetric *metrics.HttpMetrics) (*http.S } connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", - cfg.DB.Host, - cfg.DB.Port, - cfg.DB.User, - cfg.DB.Pass, - cfg.DB.DBName, - cfg.DB.SSLMode, + cfg.POSTDB.Host, + cfg.POSTDB.Port, + cfg.POSTDB.User, + cfg.POSTDB.Pass, + cfg.POSTDB.DBName, + cfg.POSTDB.SSLMode, ) postgresDB, err := start_postgres.StartPostgres(connStr, logger) @@ -102,12 +102,12 @@ func GetGRPCServer(cfg *config.Config, grpcMetrics *metrics.GrpcMetrics) (*grpc. } connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", - cfg.DB.Host, - cfg.DB.Port, - cfg.DB.User, - cfg.DB.Pass, - cfg.DB.DBName, - cfg.DB.SSLMode, + cfg.POSTDB.Host, + cfg.POSTDB.Port, + cfg.POSTDB.User, + cfg.POSTDB.Pass, + cfg.POSTDB.DBName, + cfg.POSTDB.SSLMode, ) postgresDB, err := start_postgres.StartPostgres(connStr, logger) diff --git a/internal/app/profile/app.go b/internal/app/profile/app.go index 289af921..f7fa78c8 100644 --- a/internal/app/profile/app.go +++ b/internal/app/profile/app.go @@ -41,12 +41,12 @@ func GetHTTPServer(cfg *config.Config, metric *metrics.HttpMetrics) (*http.Serve } connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", - cfg.DB.Host, - cfg.DB.Port, - cfg.DB.User, - cfg.DB.Pass, - cfg.DB.DBName, - cfg.DB.SSLMode, + cfg.PROFILEDB.Host, + cfg.PROFILEDB.Port, + cfg.PROFILEDB.User, + cfg.PROFILEDB.Pass, + cfg.PROFILEDB.DBName, + cfg.PROFILEDB.SSLMode, ) postgresDB, err := start_postgres.StartPostgres(connStr, logger) @@ -98,12 +98,12 @@ func GetGRPCServer(cfg *config.Config, grpcMetrics *metrics.GrpcMetrics) (*grpc. } connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", - cfg.DB.Host, - cfg.DB.Port, - cfg.DB.User, - cfg.DB.Pass, - cfg.DB.DBName, - cfg.DB.SSLMode, + cfg.PROFILEDB.Host, + cfg.PROFILEDB.Port, + cfg.PROFILEDB.User, + cfg.PROFILEDB.Pass, + cfg.PROFILEDB.DBName, + cfg.PROFILEDB.SSLMode, ) postgresDB, err := start_postgres.StartPostgres(connStr, logger) diff --git a/internal/config/config.go b/internal/config/config.go index 2170e24f..92272dad 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -37,7 +37,10 @@ type GRPCServer struct { } type Config struct { - DB DBConnect + PROFILEDB DBConnect + COMMUNITYDB DBConnect + POSTDB DBConnect + MESSAGEDB DBConnect REDIS Redis AUTH Server FILE Server @@ -58,11 +61,35 @@ func GetConfig(configFilePath string) (*Config, error) { } return &Config{ - DB: DBConnect{ + PROFILEDB: DBConnect{ Port: os.Getenv("DB_PORT"), Host: os.Getenv("DB_HOST"), - User: os.Getenv("DB_USER"), - Pass: os.Getenv("DB_PASSWORD"), + User: os.Getenv("DB_PROFILE_USER"), + Pass: os.Getenv("DB_PROFILE_PASSWORD"), + DBName: os.Getenv("DB_NAME"), + SSLMode: os.Getenv("DB_SSLMODE"), + }, + COMMUNITYDB: DBConnect{ + Port: os.Getenv("DB_PORT"), + Host: os.Getenv("DB_HOST"), + User: os.Getenv("DB_COMMUNITY_USER"), + Pass: os.Getenv("DB_COMMUNITY_PASSWORD"), + DBName: os.Getenv("DB_NAME"), + SSLMode: os.Getenv("DB_SSLMODE"), + }, + POSTDB: DBConnect{ + Port: os.Getenv("DB_PORT"), + Host: os.Getenv("DB_HOST"), + User: os.Getenv("DB_POST_USER"), + Pass: os.Getenv("DB_POST_PASSWORD"), + DBName: os.Getenv("DB_NAME"), + SSLMode: os.Getenv("DB_SSLMODE"), + }, + MESSAGEDB: DBConnect{ + Port: os.Getenv("DB_PORT"), + Host: os.Getenv("DB_HOST"), + User: os.Getenv("DB_MESSAGE_USER"), + Pass: os.Getenv("DB_MESSAGE_PASSWORD"), DBName: os.Getenv("DB_NAME"), SSLMode: os.Getenv("DB_SSLMODE"), },