T-2: MySQL Factory with CA
Description
Implement custom CA usage in MySQL factory via RegisterTLSConfig. When CA is provided, register TLS config with unique name and use it in connection string.
Delivered Value
Users can connect to MySQL with corporate CA. Without CA, behavior remains identical to current.
Files to Modify
| File |
Action |
Description |
pkg/datasource/datasource_factory.go |
Modify |
newDataSourceConfigMySQL with CA support |
Implementation
func newDataSourceConfigMySQL(ctx context.Context, conn *model.Connection, ...) (*DataSourceConfig, error) {
// ... decrypt password (existente) ...
sslMode := "false"
if conn.SSL != nil && conn.SSL.Mode != "" {
sslMode = conn.SSL.Mode
}
if err := sslmode.ValidateMySQLMode(sslMode); err != nil {
return nil, err
}
// NOVO: Se CA fornecido, registrar custom TLS config
if conn.SSL != nil && conn.SSL.CA != "" && sslMode != "false" {
tlsCfg, err := tlsutil.BuildTLSConfig(conn.SSL.CA, conn.Host, derefString(conn.SSL.Cert), derefString(conn.SSL.Key))
if err != nil {
return nil, fmt.Errorf("failed to build MySQL TLS config: %w", err)
}
// Nome unico por conexao para evitar colisao global
tlsKeyName := fmt.Sprintf("fetcher-%s", conn.ID.String())
if err := mysql.RegisterTLSConfig(tlsKeyName, tlsCfg); err != nil {
return nil, fmt.Errorf("failed to register MySQL TLS config: %w", err)
}
sslMode = tlsKeyName // Usar nome registrado em vez de modo generico
}
connectionString := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?tls=%s",
conn.Username,
url.QueryEscape(password),
conn.Host,
conn.Port,
conn.DatabaseName,
sslMode,
)
// ... restante da funcao (existente) ...
}
Dependencies
Estimate
- Size: S (small)
- Complexity: Medium
Acceptance Criteria
Test Strategy
- Unit tests for factory with
RegisterTLSConfig mock
- Integration test with MySQL SSL container (Task 6)
Task gerada pelo Floki
Jira: FET-145
Link: https://lerian.atlassian.net/browse/FET-145
T-2: MySQL Factory with CA
Description
Implement custom CA usage in MySQL factory via
RegisterTLSConfig. When CA is provided, register TLS config with unique name and use it in connection string.Delivered Value
Users can connect to MySQL with corporate CA. Without CA, behavior remains identical to current.
Files to Modify
pkg/datasource/datasource_factory.gonewDataSourceConfigMySQLwith CA supportImplementation
Dependencies
Estimate
Acceptance Criteria
RegisterTLSConfigcalled with unique nametls=<nome-registrado>tls=<mode>)Test Strategy
RegisterTLSConfigmockTask gerada pelo Floki
Jira: FET-145
Link: https://lerian.atlassian.net/browse/FET-145