Skip to content

Commit e76f62c

Browse files
authored
chore: remove unsed cm db connection from software-value [CM-787] (#3920)
Signed-off-by: Mouad BANI <[email protected]>
1 parent bc2e323 commit e76f62c

3 files changed

Lines changed: 2 additions & 62 deletions

File tree

services/apps/git_integration/src/crowdgit/services/software_value/config.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type Config struct {
2222
TargetPath string `koanf:"target.path"`
2323
SCCPath string `koanf:"scc.path"`
2424
InsightsDatabase DBConfig `koanf:"database.insights"`
25-
CMDatabase DBConfig `koanf:"database.cm"`
2625
}
2726

2827
func getConfig(targetPath string) (Config, error) {
@@ -64,26 +63,5 @@ func getConfig(targetPath string) (Config, error) {
6463
config.InsightsDatabase.ReadOnly = readOnlyStr == "true"
6564
}
6665

67-
config.CMDatabase.User = os.Getenv("CROWD_DB_USERNAME")
68-
config.CMDatabase.Password = os.Getenv("CROWD_DB_PASSWORD")
69-
config.CMDatabase.DBName = os.Getenv("CROWD_DB_DATABASE")
70-
config.CMDatabase.Host = os.Getenv("CROWD_DB_READ_HOST")
71-
if portStr := os.Getenv("CROWD_DB_PORT"); portStr != "" {
72-
if port, err := strconv.Atoi(portStr); err == nil {
73-
config.CMDatabase.Port = port
74-
}
75-
}
76-
config.CMDatabase.SSLMode = os.Getenv("CROWD_DB_SSLMODE")
77-
if poolMaxStr := os.Getenv("CROWD_DB_POOL_MAX"); poolMaxStr != "" {
78-
if poolMax, err := strconv.Atoi(poolMaxStr); err == nil {
79-
config.CMDatabase.PoolMax = poolMax
80-
}
81-
} else {
82-
config.CMDatabase.PoolMax = 10 // Default pool max
83-
}
84-
if readOnlyStr := os.Getenv("CROWD_DB_READONLY"); readOnlyStr != "" {
85-
config.CMDatabase.ReadOnly = readOnlyStr == "true"
86-
}
87-
8866
return config, nil
8967
}

services/apps/git_integration/src/crowdgit/services/software_value/db.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@ type InsightsDB struct {
1717
config DBConfig
1818
}
1919

20-
// CMDB holds the connection pool and configuration for the CM database.
21-
type CMDB struct {
22-
pool *pgxpool.Pool
23-
config DBConfig
24-
}
25-
2620
// newDBConnection establishes a new database connection pool.
27-
// This is a helper function used by NewInsightsDB and NewCMDB.
21+
// This is a helper function used by NewInsightsDB.
2822
func newDBConnection(ctx context.Context, config DBConfig) (*pgxpool.Pool, error) {
2923
const dbConnectionStringTemplate = "user=%s password=%s host=%s port=%d dbname=%s sslmode=%s pool_max_conns=%d"
3024
dbConnectionString := fmt.Sprintf(dbConnectionStringTemplate,
@@ -81,32 +75,13 @@ func NewInsightsDB(ctx context.Context, config DBConfig) (*InsightsDB, error) {
8175
}, nil
8276
}
8377

84-
// NewCMDB creates a new CMDB instance.
85-
func NewCMDB(ctx context.Context, config DBConfig) (*CMDB, error) {
86-
pool, err := newDBConnection(ctx, config)
87-
if err != nil {
88-
return nil, err
89-
}
90-
return &CMDB{
91-
pool: pool,
92-
config: config,
93-
}, nil
94-
}
95-
9678
// Close closes the database connection pool.
9779
func (db *InsightsDB) Close() {
9880
if db.pool != nil {
9981
db.pool.Close()
10082
}
10183
}
10284

103-
// Close closes the database connection pool.
104-
func (db *CMDB) Close() {
105-
if db.pool != nil {
106-
db.pool.Close()
107-
}
108-
}
109-
11085
// saveProjectCost upserts the project cost into the database table.
11186
func (db *InsightsDB) saveProjectCost(ctx context.Context, repository Repository, estimatedCost float64) error {
11287
// From PostgreSQL 15 and newer, there's another way to do this: https://www.postgresql.org/docs/15/sql-merge.html

services/apps/git_integration/src/crowdgit/services/software_value/main.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func main() {
1616
response := processRepository()
1717
outputJSON(response)
18-
18+
1919
// Always exit with code 0 - status details are in JSON response
2020
}
2121

@@ -63,18 +63,6 @@ func processRepository() StandardResponse {
6363
}
6464
defer insightsDb.Close()
6565

66-
cmdb, err := NewCMDB(ctx, config.CMDatabase)
67-
if err != nil {
68-
errorCode := ErrorCodeDatabaseConnection
69-
errorMessage := fmt.Sprintf("Error connecting to CM database: %v", err)
70-
return StandardResponse{
71-
Status: StatusFailure,
72-
ErrorCode: &errorCode,
73-
ErrorMessage: &errorMessage,
74-
}
75-
}
76-
defer cmdb.Close()
77-
7866
// Get git URL for the repository
7967
gitUrl, err := getGitRepositoryURL(repoDir)
8068
if err != nil {
@@ -297,4 +285,3 @@ func getErrorCodeFromSCCError(err error) string {
297285
}
298286
return ErrorCodeUnknown
299287
}
300-

0 commit comments

Comments
 (0)