GetDataSourceDriver returns the database driver for a data source.
(ctx context.Context, instance *store.InstanceMessage, dataSource *storepb.DataSource, connectionContext db.ConnectionContext)
| 44 | |
| 45 | // GetDataSourceDriver returns the database driver for a data source. |
| 46 | func (d *DBFactory) GetDataSourceDriver(ctx context.Context, instance *store.InstanceMessage, dataSource *storepb.DataSource, connectionContext db.ConnectionContext) (db.Driver, error) { |
| 47 | password := dataSource.GetPassword() |
| 48 | if err := d.licenseService.IsFeatureEnabledForInstance(ctx, instance.Workspace, v1pb.PlanFeature_FEATURE_EXTERNAL_SECRET_MANAGER, instance); err == nil { |
| 49 | p, err := secretlib.ReplaceExternalSecret(ctx, dataSource.GetPassword(), dataSource.GetExternalSecret()) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | password = p |
| 54 | } |
| 55 | connectionContext.InstanceID = instance.ResourceID |
| 56 | connectionContext.EngineVersion = instance.Metadata.GetVersion() |
| 57 | |
| 58 | resolvedDataSource, err := dbutil.ResolveTLSMaterial(dataSource) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | |
| 63 | driver, err := db.Open( |
| 64 | ctx, |
| 65 | instance.Metadata.GetEngine(), |
| 66 | db.ConnectionConfig{ |
| 67 | DataSource: resolvedDataSource, |
| 68 | ConnectionContext: connectionContext, |
| 69 | Password: password, |
| 70 | }, |
| 71 | ) |
| 72 | if err != nil { |
| 73 | return nil, err |
| 74 | } |
| 75 | |
| 76 | return driver, nil |
| 77 | } |
no test coverage detected