Repository navigation
Expand file tree
/
Copy pathengine.go
More file actions
68 lines (64 loc) · 2.39 KB
/
Copy pathengine.go
File metadata and controls
68 lines (64 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package common //nolint:revive // pkg/common is the module's core domain package (Recommendation, ProviderType, ...), imported by name (common.X) throughout this repo and by consumer-mcp; renaming would break every consumer import
import "strings"
// engineNameMap maps database engine names to a consistent normalized format.
// AWS RIs use: "aurora-postgresql", "aurora-mysql", "mysql", "postgres"
// Cost Explorer uses: "Aurora PostgreSQL", "Aurora MySQL", "MySQL", "PostgreSQL".
var engineNameMap = map[string]string{
// Cost Explorer format -> normalized
"aurora postgresql": "aurora-postgresql",
"aurora mysql": "aurora-mysql",
"mysql": "mysql",
"postgresql": "postgresql",
"mariadb": "mariadb",
"oracle": "oracle",
"sql server": "sqlserver",
// Already normalized (from AWS RIs)
"aurora-postgresql": "aurora-postgresql",
"aurora-mysql": "aurora-mysql",
"postgres": "postgresql",
"oracle-se": "oracle",
"oracle-se1": "oracle",
"oracle-se2": "oracle",
"oracle-ee": "oracle",
"sqlserver-se": "sqlserver",
"sqlserver-ee": "sqlserver",
"sqlserver-ex": "sqlserver",
"sqlserver-web": "sqlserver",
}
// NormalizeEngineName normalizes database engine names to a consistent format.
// Returns lowercase of the input as a fallback when the engine is not recognized.
func NormalizeEngineName(engine string) string {
normalized := strings.ToLower(engine)
if normalizedEngine, ok := engineNameMap[normalized]; ok {
return normalizedEngine
}
return normalized
}
// EngineFromDetails extracts and normalizes the engine name from
// recommendation details. Returns an empty string for non-database/cache
// service types. DatabaseDetails/CacheDetails are always pointers (every
// producer constructs them that way; see service_details_codec.go's
// package doc for the invariant). The nil-pointer guards are not dead
// code: the `details == nil` check above only catches an untyped nil, so a
// typed nil reaches the switch and would panic on the field read.
func EngineFromDetails(details ServiceDetails) string {
if details == nil {
return ""
}
var engine string
switch d := details.(type) {
case *DatabaseDetails:
if d == nil {
return ""
}
engine = d.Engine
case *CacheDetails:
if d == nil {
return ""
}
engine = d.Engine
default:
return ""
}
return NormalizeEngineName(engine)
}