diff --git a/server/graphql-engine.cabal b/server/graphql-engine.cabal index f0e6c359ee5..d989eb47b9a 100644 --- a/server/graphql-engine.cabal +++ b/server/graphql-engine.cabal @@ -721,6 +721,7 @@ library , Hasura.LogicalModel.Schema , Hasura.LogicalModel.Types + , Hasura.ClientCredentials , Hasura.EncJSON , Hasura.Function.API diff --git a/server/src-lib/Hasura/App.hs b/server/src-lib/Hasura/App.hs index 887b35fd2d5..d03dd5b4cbb 100644 --- a/server/src-lib/Hasura/App.hs +++ b/server/src-lib/Hasura/App.hs @@ -90,6 +90,7 @@ import Hasura.App.State import Hasura.Backends.MSSQL.Connection import Hasura.Backends.Postgres.Connection import Hasura.Base.Error +import Hasura.ClientCredentials (getEEClientCredentialsTx, setEEClientCredentialsTx) import Hasura.Eventing.Common import Hasura.Eventing.EventTrigger import Hasura.Eventing.ScheduledTrigger @@ -125,7 +126,6 @@ import Hasura.RQL.DDL.Schema.Catalog import Hasura.RQL.Types.Allowlist import Hasura.RQL.Types.Backend import Hasura.RQL.Types.Common -import Hasura.RQL.Types.EECredentials import Hasura.RQL.Types.Eventing.Backend import Hasura.RQL.Types.Metadata import Hasura.RQL.Types.ResizePool diff --git a/server/src-lib/Hasura/ClientCredentials.hs b/server/src-lib/Hasura/ClientCredentials.hs new file mode 100644 index 00000000000..ebf85c7be80 --- /dev/null +++ b/server/src-lib/Hasura/ClientCredentials.hs @@ -0,0 +1,45 @@ +{-# LANGUAGE QuasiQuotes #-} + +module Hasura.ClientCredentials + ( EEClientCredentials (..), + EEClientId (..), + getEEClientCredentialsTx, + setEEClientCredentialsTx, + ) +where + +import Database.PG.Query qualified as PG +import Hasura.Backends.Postgres.Execute.Types +import Hasura.Base.Error +import Hasura.Prelude +import Hasura.RQL.Types.EECredentials (EEClientCredentials (..), EEClientId (..)) + +getEEClientCredentialsTx :: PG.TxE QErr (Maybe EEClientCredentials) +getEEClientCredentialsTx = + makeClientCredentials . PG.getRow + <$> PG.withQE + defaultTxErrorHandler + [PG.sql| + SELECT ee_client_id::text, ee_client_secret + FROM hdb_catalog.hdb_version + |] + () + False + where + makeClientCredentials :: (Maybe Text, Maybe Text) -> Maybe EEClientCredentials + makeClientCredentials (clientIdMaybe, clientSecretMaybe) = do + eccClientId <- EEClientId <$> clientIdMaybe + eccClientSecret <- clientSecretMaybe + pure EEClientCredentials {..} + +setEEClientCredentialsTx :: EEClientCredentials -> PG.TxE QErr () +setEEClientCredentialsTx EEClientCredentials {..} = + PG.unitQE + defaultTxErrorHandler + [PG.sql| + UPDATE hdb_catalog.hdb_version + SET ee_client_id = $1, + ee_client_secret = $2 + |] + (_getEEClientId eccClientId, eccClientSecret) + True diff --git a/server/src-lib/Hasura/RQL/Types/EECredentials.hs b/server/src-lib/Hasura/RQL/Types/EECredentials.hs index 4aa3aa07f15..ec5acae0f1a 100644 --- a/server/src-lib/Hasura/RQL/Types/EECredentials.hs +++ b/server/src-lib/Hasura/RQL/Types/EECredentials.hs @@ -1,18 +1,11 @@ -{-# LANGUAGE QuasiQuotes #-} - module Hasura.RQL.Types.EECredentials ( EEClientCredentials (..), EEClientId (..), - getEEClientCredentialsTx, - setEEClientCredentialsTx, ) where import Data.Aeson (FromJSON, (.:)) import Data.Aeson qualified as Aeson -import Database.PG.Query qualified as PG -import Hasura.Backends.Postgres.Execute.Types -import Hasura.Base.Error import Hasura.Prelude data EEClientCredentials = EEClientCredentials @@ -28,33 +21,3 @@ instance FromJSON EEClientCredentials where eccClientId <- o .: "client_id" eccClientSecret <- o .: "client_secret" pure EEClientCredentials {..} - -getEEClientCredentialsTx :: PG.TxE QErr (Maybe EEClientCredentials) -getEEClientCredentialsTx = - makeClientCredentials . PG.getRow - <$> PG.withQE - defaultTxErrorHandler - [PG.sql| - SELECT ee_client_id::text, ee_client_secret - FROM hdb_catalog.hdb_version - |] - () - False - where - makeClientCredentials :: (Maybe Text, Maybe Text) -> Maybe EEClientCredentials - makeClientCredentials (clientIdMaybe, clientSecretMaybe) = do - eccClientId <- EEClientId <$> clientIdMaybe - eccClientSecret <- clientSecretMaybe - pure EEClientCredentials {..} - -setEEClientCredentialsTx :: EEClientCredentials -> PG.TxE QErr () -setEEClientCredentialsTx EEClientCredentials {..} = - PG.unitQE - defaultTxErrorHandler - [PG.sql| - UPDATE hdb_catalog.hdb_version - SET ee_client_id = $1, - ee_client_secret = $2 - |] - (_getEEClientId eccClientId, eccClientSecret) - True