mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
Enforce that backends use the properly resolved environment variables.
## Description This PR fixes an oversight in the implementation of the resolvers of different backends. To implement resolution from environment variables, both MSSQL and BigQuery were directly fetching the process' environment variables, instead of using the careful curated set we thread from main. It was working just fine on OSS, but is failing on Cloud. This PR fixes this by adding an additional argument to `resolveSourceConfig`, to ensure that backends always use the correct set of variables. https://github.com/hasura/graphql-engine-mono/pull/1891 GitOrigin-RevId: 58644cab7d041a8bf4235e2acfe9cf71533a92a1
This commit is contained in:
parent
76d1430703
commit
49f40a44f0
@ -3,6 +3,7 @@
|
||||
## Next release
|
||||
(Add entries below in the order of server, console, cli, docs, others)
|
||||
|
||||
- server: Fixed a bug where MSSQL and BigQuery would ignore environment variables set from the console
|
||||
- server: Fixing bug in ReplaceMetadata parser - Moving from Alternative to committed-choice.
|
||||
- server: Relax the unique operation name constraint when adding a query to a query collection
|
||||
- server/bigquery: Fix issues related to adding and querying from non-US datasets (closes [6937](https://github.com/hasura/graphql-engine/issues/6937)).
|
||||
|
@ -39,9 +39,9 @@ resolveSourceConfig ::
|
||||
MonadIO m =>
|
||||
SourceName ->
|
||||
BigQueryConnSourceConfig ->
|
||||
Env.Environment ->
|
||||
m (Either QErr BigQuerySourceConfig)
|
||||
resolveSourceConfig _name BigQueryConnSourceConfig{..} = runExceptT $ do
|
||||
env <- liftIO Env.getEnvironment
|
||||
resolveSourceConfig _name BigQueryConnSourceConfig{..} env = runExceptT $ do
|
||||
eSA <- resolveConfigurationJson env _cscServiceAccount
|
||||
case eSA of
|
||||
Left e -> throw400 Unexpected $ T.pack e
|
||||
|
@ -2,6 +2,7 @@ module Hasura.Backends.MSSQL.Connection where
|
||||
|
||||
import Hasura.Prelude
|
||||
|
||||
import qualified Data.Environment as Env
|
||||
import qualified Data.Pool as Pool
|
||||
import qualified Database.ODBC.SQLServer as ODBC
|
||||
|
||||
@ -10,11 +11,11 @@ import Data.Aeson
|
||||
import Data.Aeson.Casing
|
||||
import Data.Aeson.TH
|
||||
|
||||
import qualified Data.Environment as Env
|
||||
import Data.Text (pack, unpack)
|
||||
import Hasura.Base.Error
|
||||
import Hasura.Incremental (Cacheable (..))
|
||||
|
||||
|
||||
-- | ODBC connection string for MSSQL server
|
||||
newtype MSSQLConnectionString
|
||||
= MSSQLConnectionString {unMSSQLConnectionString :: Text}
|
||||
@ -109,9 +110,9 @@ createMSSQLPool
|
||||
:: MonadIO m
|
||||
=> QErrM m
|
||||
=> MSSQLConnectionInfo
|
||||
-> Env.Environment
|
||||
-> m (MSSQLConnectionString, MSSQLPool)
|
||||
createMSSQLPool (MSSQLConnectionInfo iConnString MSSQLPoolSettings{..}) = do
|
||||
env <- liftIO Env.getEnvironment
|
||||
createMSSQLPool (MSSQLConnectionInfo iConnString MSSQLPoolSettings{..}) env = do
|
||||
connString <- resolveInputConnectionString env iConnString
|
||||
pool <- liftIO
|
||||
$ MSSQLPool
|
||||
|
@ -7,6 +7,8 @@ where
|
||||
|
||||
import Hasura.Prelude
|
||||
|
||||
import qualified Data.Environment as Env
|
||||
|
||||
import Hasura.Backends.MSSQL.Connection
|
||||
import Hasura.Backends.MSSQL.Meta
|
||||
import Hasura.Base.Error
|
||||
@ -14,13 +16,15 @@ import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.SQL.Backend
|
||||
|
||||
|
||||
resolveSourceConfig
|
||||
:: (MonadIO m)
|
||||
=> SourceName
|
||||
-> MSSQLConnConfiguration
|
||||
-> Env.Environment
|
||||
-> m (Either QErr MSSQLSourceConfig)
|
||||
resolveSourceConfig _name (MSSQLConnConfiguration connInfo) = runExceptT do
|
||||
(connString, mssqlPool) <- createMSSQLPool connInfo
|
||||
resolveSourceConfig _name (MSSQLConnConfiguration connInfo) env = runExceptT do
|
||||
(connString, mssqlPool) <- createMSSQLPool connInfo env
|
||||
pure $ MSSQLSourceConfig connString mssqlPool
|
||||
|
||||
resolveDatabaseMetadata
|
||||
|
@ -1,21 +1,28 @@
|
||||
module Hasura.Backends.MySQL.Connection where
|
||||
|
||||
import Hasura.Prelude
|
||||
|
||||
import qualified Data.Environment as Env
|
||||
import qualified Data.Text as T
|
||||
|
||||
import Data.Pool (createPool, withResource)
|
||||
import qualified Data.Text as T
|
||||
import Database.MySQL.Base
|
||||
|
||||
import Hasura.Backends.MySQL.Meta (getMetadata)
|
||||
import Hasura.Backends.MySQL.Types
|
||||
import Hasura.Base.Error
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.SQL.Backend
|
||||
|
||||
|
||||
resolveSourceConfig :: (MonadIO m) =>
|
||||
SourceName -> ConnSourceConfig -> m (Either QErr SourceConfig)
|
||||
resolveSourceConfig _name csc@ConnSourceConfig{_cscPoolSettings = ConnPoolSettings{..}, ..} =
|
||||
resolveSourceConfig
|
||||
:: (MonadIO m)
|
||||
=> SourceName
|
||||
-> ConnSourceConfig
|
||||
-> Env.Environment
|
||||
-> m (Either QErr SourceConfig)
|
||||
resolveSourceConfig _name csc@ConnSourceConfig{_cscPoolSettings = ConnPoolSettings{..}, ..} _env = do
|
||||
let connectInfo =
|
||||
defaultConnectInfo
|
||||
{ connectHost = T.unpack _cscHost
|
||||
@ -24,15 +31,15 @@ resolveSourceConfig _name csc@ConnSourceConfig{_cscPoolSettings = ConnPoolSettin
|
||||
, connectPassword = T.unpack _cscPassword
|
||||
, connectDatabase = T.unpack _cscDatabase
|
||||
}
|
||||
in runExceptT $
|
||||
SourceConfig csc <$>
|
||||
liftIO
|
||||
(createPool
|
||||
(connect connectInfo)
|
||||
close
|
||||
1
|
||||
(fromIntegral _cscIdleTimeout)
|
||||
(fromIntegral _cscMaxConnections))
|
||||
runExceptT $
|
||||
SourceConfig csc <$>
|
||||
liftIO
|
||||
(createPool
|
||||
(connect connectInfo)
|
||||
close
|
||||
1
|
||||
(fromIntegral _cscIdleTimeout)
|
||||
(fromIntegral _cscMaxConnections))
|
||||
|
||||
|
||||
resolveDatabaseMetadata :: (MonadIO m) =>
|
||||
|
@ -11,6 +11,7 @@ module Hasura.Backends.Postgres.DDL.Source
|
||||
|
||||
import Hasura.Prelude
|
||||
|
||||
import qualified Data.Environment as Env
|
||||
import qualified Data.HashMap.Strict as Map
|
||||
import qualified Data.List.NonEmpty as NE
|
||||
import qualified Database.PG.Query as Q
|
||||
@ -50,8 +51,11 @@ instance ToMetadataFetchQuery 'Citus where
|
||||
|
||||
resolveSourceConfig
|
||||
:: (MonadIO m, MonadResolveSource m)
|
||||
=> SourceName -> PostgresConnConfiguration -> m (Either QErr (SourceConfig ('Postgres pgKind)))
|
||||
resolveSourceConfig name config = runExceptT do
|
||||
=> SourceName
|
||||
-> PostgresConnConfiguration
|
||||
-> Env.Environment
|
||||
-> m (Either QErr (SourceConfig ('Postgres pgKind)))
|
||||
resolveSourceConfig name config _env = runExceptT do
|
||||
sourceResolver <- getSourceResolver
|
||||
liftEitherM $ liftIO $ sourceResolver name config
|
||||
|
||||
|
@ -255,7 +255,7 @@ buildSchemaCacheRule env = proc (metadata, invalidationKeys) -> do
|
||||
:: forall b arr m
|
||||
. ( ArrowChoice arr, Inc.ArrowCache m arr
|
||||
, ArrowWriter (Seq CollectedInfo) arr
|
||||
, MonadIO m, MonadBaseControl IO m
|
||||
, MonadIO m
|
||||
, MonadResolveSource m
|
||||
, BackendMetadata b
|
||||
)
|
||||
@ -266,7 +266,7 @@ buildSchemaCacheRule env = proc (metadata, invalidationKeys) -> do
|
||||
let metadataObj = MetadataObject (MOSource sourceName) $ toJSON sourceName
|
||||
Inc.dependOn -< Inc.selectKeyD sourceName invalidationKeys
|
||||
(| withRecordInconsistency (
|
||||
liftEitherA <<< bindA -< resolveSourceConfig @b sourceName sourceConfig)
|
||||
liftEitherA <<< bindA -< resolveSourceConfig @b sourceName sourceConfig env)
|
||||
|) metadataObj
|
||||
|
||||
resolveSourceIfNeeded
|
||||
|
@ -47,9 +47,10 @@ class (Backend b) => BackendMetadata (b :: BackendType) where
|
||||
-- | Function that resolves the connection related source configuration, and
|
||||
-- creates a connection pool (and other related parameters) in the process
|
||||
resolveSourceConfig
|
||||
:: (MonadIO m, MonadBaseControl IO m, MonadResolveSource m)
|
||||
:: (MonadIO m, MonadResolveSource m)
|
||||
=> SourceName
|
||||
-> SourceConnConfiguration b
|
||||
-> Env.Environment
|
||||
-> m (Either QErr (SourceConfig b))
|
||||
|
||||
-- | Function that introspects a database for tables, columns, functions etc.
|
||||
|
Loading…
Reference in New Issue
Block a user