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
|
## Next release
|
||||||
(Add entries below in the order of server, console, cli, docs, others)
|
(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: 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: 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)).
|
- 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 =>
|
MonadIO m =>
|
||||||
SourceName ->
|
SourceName ->
|
||||||
BigQueryConnSourceConfig ->
|
BigQueryConnSourceConfig ->
|
||||||
|
Env.Environment ->
|
||||||
m (Either QErr BigQuerySourceConfig)
|
m (Either QErr BigQuerySourceConfig)
|
||||||
resolveSourceConfig _name BigQueryConnSourceConfig{..} = runExceptT $ do
|
resolveSourceConfig _name BigQueryConnSourceConfig{..} env = runExceptT $ do
|
||||||
env <- liftIO Env.getEnvironment
|
|
||||||
eSA <- resolveConfigurationJson env _cscServiceAccount
|
eSA <- resolveConfigurationJson env _cscServiceAccount
|
||||||
case eSA of
|
case eSA of
|
||||||
Left e -> throw400 Unexpected $ T.pack e
|
Left e -> throw400 Unexpected $ T.pack e
|
||||||
|
@ -2,6 +2,7 @@ module Hasura.Backends.MSSQL.Connection where
|
|||||||
|
|
||||||
import Hasura.Prelude
|
import Hasura.Prelude
|
||||||
|
|
||||||
|
import qualified Data.Environment as Env
|
||||||
import qualified Data.Pool as Pool
|
import qualified Data.Pool as Pool
|
||||||
import qualified Database.ODBC.SQLServer as ODBC
|
import qualified Database.ODBC.SQLServer as ODBC
|
||||||
|
|
||||||
@ -10,11 +11,11 @@ import Data.Aeson
|
|||||||
import Data.Aeson.Casing
|
import Data.Aeson.Casing
|
||||||
import Data.Aeson.TH
|
import Data.Aeson.TH
|
||||||
|
|
||||||
import qualified Data.Environment as Env
|
|
||||||
import Data.Text (pack, unpack)
|
import Data.Text (pack, unpack)
|
||||||
import Hasura.Base.Error
|
import Hasura.Base.Error
|
||||||
import Hasura.Incremental (Cacheable (..))
|
import Hasura.Incremental (Cacheable (..))
|
||||||
|
|
||||||
|
|
||||||
-- | ODBC connection string for MSSQL server
|
-- | ODBC connection string for MSSQL server
|
||||||
newtype MSSQLConnectionString
|
newtype MSSQLConnectionString
|
||||||
= MSSQLConnectionString {unMSSQLConnectionString :: Text}
|
= MSSQLConnectionString {unMSSQLConnectionString :: Text}
|
||||||
@ -109,9 +110,9 @@ createMSSQLPool
|
|||||||
:: MonadIO m
|
:: MonadIO m
|
||||||
=> QErrM m
|
=> QErrM m
|
||||||
=> MSSQLConnectionInfo
|
=> MSSQLConnectionInfo
|
||||||
|
-> Env.Environment
|
||||||
-> m (MSSQLConnectionString, MSSQLPool)
|
-> m (MSSQLConnectionString, MSSQLPool)
|
||||||
createMSSQLPool (MSSQLConnectionInfo iConnString MSSQLPoolSettings{..}) = do
|
createMSSQLPool (MSSQLConnectionInfo iConnString MSSQLPoolSettings{..}) env = do
|
||||||
env <- liftIO Env.getEnvironment
|
|
||||||
connString <- resolveInputConnectionString env iConnString
|
connString <- resolveInputConnectionString env iConnString
|
||||||
pool <- liftIO
|
pool <- liftIO
|
||||||
$ MSSQLPool
|
$ MSSQLPool
|
||||||
|
@ -7,6 +7,8 @@ where
|
|||||||
|
|
||||||
import Hasura.Prelude
|
import Hasura.Prelude
|
||||||
|
|
||||||
|
import qualified Data.Environment as Env
|
||||||
|
|
||||||
import Hasura.Backends.MSSQL.Connection
|
import Hasura.Backends.MSSQL.Connection
|
||||||
import Hasura.Backends.MSSQL.Meta
|
import Hasura.Backends.MSSQL.Meta
|
||||||
import Hasura.Base.Error
|
import Hasura.Base.Error
|
||||||
@ -14,13 +16,15 @@ import Hasura.RQL.Types.Common
|
|||||||
import Hasura.RQL.Types.Source
|
import Hasura.RQL.Types.Source
|
||||||
import Hasura.SQL.Backend
|
import Hasura.SQL.Backend
|
||||||
|
|
||||||
|
|
||||||
resolveSourceConfig
|
resolveSourceConfig
|
||||||
:: (MonadIO m)
|
:: (MonadIO m)
|
||||||
=> SourceName
|
=> SourceName
|
||||||
-> MSSQLConnConfiguration
|
-> MSSQLConnConfiguration
|
||||||
|
-> Env.Environment
|
||||||
-> m (Either QErr MSSQLSourceConfig)
|
-> m (Either QErr MSSQLSourceConfig)
|
||||||
resolveSourceConfig _name (MSSQLConnConfiguration connInfo) = runExceptT do
|
resolveSourceConfig _name (MSSQLConnConfiguration connInfo) env = runExceptT do
|
||||||
(connString, mssqlPool) <- createMSSQLPool connInfo
|
(connString, mssqlPool) <- createMSSQLPool connInfo env
|
||||||
pure $ MSSQLSourceConfig connString mssqlPool
|
pure $ MSSQLSourceConfig connString mssqlPool
|
||||||
|
|
||||||
resolveDatabaseMetadata
|
resolveDatabaseMetadata
|
||||||
|
@ -1,21 +1,28 @@
|
|||||||
module Hasura.Backends.MySQL.Connection where
|
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 Data.Pool (createPool, withResource)
|
||||||
import qualified Data.Text as T
|
|
||||||
import Database.MySQL.Base
|
import Database.MySQL.Base
|
||||||
|
|
||||||
import Hasura.Backends.MySQL.Meta (getMetadata)
|
import Hasura.Backends.MySQL.Meta (getMetadata)
|
||||||
import Hasura.Backends.MySQL.Types
|
import Hasura.Backends.MySQL.Types
|
||||||
import Hasura.Base.Error
|
import Hasura.Base.Error
|
||||||
import Hasura.Prelude
|
|
||||||
import Hasura.RQL.Types.Common
|
import Hasura.RQL.Types.Common
|
||||||
import Hasura.RQL.Types.Source
|
import Hasura.RQL.Types.Source
|
||||||
import Hasura.SQL.Backend
|
import Hasura.SQL.Backend
|
||||||
|
|
||||||
|
|
||||||
resolveSourceConfig :: (MonadIO m) =>
|
resolveSourceConfig
|
||||||
SourceName -> ConnSourceConfig -> m (Either QErr SourceConfig)
|
:: (MonadIO m)
|
||||||
resolveSourceConfig _name csc@ConnSourceConfig{_cscPoolSettings = ConnPoolSettings{..}, ..} =
|
=> SourceName
|
||||||
|
-> ConnSourceConfig
|
||||||
|
-> Env.Environment
|
||||||
|
-> m (Either QErr SourceConfig)
|
||||||
|
resolveSourceConfig _name csc@ConnSourceConfig{_cscPoolSettings = ConnPoolSettings{..}, ..} _env = do
|
||||||
let connectInfo =
|
let connectInfo =
|
||||||
defaultConnectInfo
|
defaultConnectInfo
|
||||||
{ connectHost = T.unpack _cscHost
|
{ connectHost = T.unpack _cscHost
|
||||||
@ -24,15 +31,15 @@ resolveSourceConfig _name csc@ConnSourceConfig{_cscPoolSettings = ConnPoolSettin
|
|||||||
, connectPassword = T.unpack _cscPassword
|
, connectPassword = T.unpack _cscPassword
|
||||||
, connectDatabase = T.unpack _cscDatabase
|
, connectDatabase = T.unpack _cscDatabase
|
||||||
}
|
}
|
||||||
in runExceptT $
|
runExceptT $
|
||||||
SourceConfig csc <$>
|
SourceConfig csc <$>
|
||||||
liftIO
|
liftIO
|
||||||
(createPool
|
(createPool
|
||||||
(connect connectInfo)
|
(connect connectInfo)
|
||||||
close
|
close
|
||||||
1
|
1
|
||||||
(fromIntegral _cscIdleTimeout)
|
(fromIntegral _cscIdleTimeout)
|
||||||
(fromIntegral _cscMaxConnections))
|
(fromIntegral _cscMaxConnections))
|
||||||
|
|
||||||
|
|
||||||
resolveDatabaseMetadata :: (MonadIO m) =>
|
resolveDatabaseMetadata :: (MonadIO m) =>
|
||||||
|
@ -11,6 +11,7 @@ module Hasura.Backends.Postgres.DDL.Source
|
|||||||
|
|
||||||
import Hasura.Prelude
|
import Hasura.Prelude
|
||||||
|
|
||||||
|
import qualified Data.Environment as Env
|
||||||
import qualified Data.HashMap.Strict as Map
|
import qualified Data.HashMap.Strict as Map
|
||||||
import qualified Data.List.NonEmpty as NE
|
import qualified Data.List.NonEmpty as NE
|
||||||
import qualified Database.PG.Query as Q
|
import qualified Database.PG.Query as Q
|
||||||
@ -50,8 +51,11 @@ instance ToMetadataFetchQuery 'Citus where
|
|||||||
|
|
||||||
resolveSourceConfig
|
resolveSourceConfig
|
||||||
:: (MonadIO m, MonadResolveSource m)
|
:: (MonadIO m, MonadResolveSource m)
|
||||||
=> SourceName -> PostgresConnConfiguration -> m (Either QErr (SourceConfig ('Postgres pgKind)))
|
=> SourceName
|
||||||
resolveSourceConfig name config = runExceptT do
|
-> PostgresConnConfiguration
|
||||||
|
-> Env.Environment
|
||||||
|
-> m (Either QErr (SourceConfig ('Postgres pgKind)))
|
||||||
|
resolveSourceConfig name config _env = runExceptT do
|
||||||
sourceResolver <- getSourceResolver
|
sourceResolver <- getSourceResolver
|
||||||
liftEitherM $ liftIO $ sourceResolver name config
|
liftEitherM $ liftIO $ sourceResolver name config
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ buildSchemaCacheRule env = proc (metadata, invalidationKeys) -> do
|
|||||||
:: forall b arr m
|
:: forall b arr m
|
||||||
. ( ArrowChoice arr, Inc.ArrowCache m arr
|
. ( ArrowChoice arr, Inc.ArrowCache m arr
|
||||||
, ArrowWriter (Seq CollectedInfo) arr
|
, ArrowWriter (Seq CollectedInfo) arr
|
||||||
, MonadIO m, MonadBaseControl IO m
|
, MonadIO m
|
||||||
, MonadResolveSource m
|
, MonadResolveSource m
|
||||||
, BackendMetadata b
|
, BackendMetadata b
|
||||||
)
|
)
|
||||||
@ -266,7 +266,7 @@ buildSchemaCacheRule env = proc (metadata, invalidationKeys) -> do
|
|||||||
let metadataObj = MetadataObject (MOSource sourceName) $ toJSON sourceName
|
let metadataObj = MetadataObject (MOSource sourceName) $ toJSON sourceName
|
||||||
Inc.dependOn -< Inc.selectKeyD sourceName invalidationKeys
|
Inc.dependOn -< Inc.selectKeyD sourceName invalidationKeys
|
||||||
(| withRecordInconsistency (
|
(| withRecordInconsistency (
|
||||||
liftEitherA <<< bindA -< resolveSourceConfig @b sourceName sourceConfig)
|
liftEitherA <<< bindA -< resolveSourceConfig @b sourceName sourceConfig env)
|
||||||
|) metadataObj
|
|) metadataObj
|
||||||
|
|
||||||
resolveSourceIfNeeded
|
resolveSourceIfNeeded
|
||||||
|
@ -47,9 +47,10 @@ class (Backend b) => BackendMetadata (b :: BackendType) where
|
|||||||
-- | Function that resolves the connection related source configuration, and
|
-- | Function that resolves the connection related source configuration, and
|
||||||
-- creates a connection pool (and other related parameters) in the process
|
-- creates a connection pool (and other related parameters) in the process
|
||||||
resolveSourceConfig
|
resolveSourceConfig
|
||||||
:: (MonadIO m, MonadBaseControl IO m, MonadResolveSource m)
|
:: (MonadIO m, MonadResolveSource m)
|
||||||
=> SourceName
|
=> SourceName
|
||||||
-> SourceConnConfiguration b
|
-> SourceConnConfiguration b
|
||||||
|
-> Env.Environment
|
||||||
-> m (Either QErr (SourceConfig b))
|
-> m (Either QErr (SourceConfig b))
|
||||||
|
|
||||||
-- | Function that introspects a database for tables, columns, functions etc.
|
-- | Function that introspects a database for tables, columns, functions etc.
|
||||||
|
Loading…
Reference in New Issue
Block a user