From a7f4c85b660bb36a43cc7429758ac8878f13ff41 Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Fri, 5 Apr 2024 13:17:41 +0530 Subject: [PATCH] Restructure packages --- azure-auth/{src => Azure}/Auth.hs | 8 ++++---- azure-auth/{src => Azure}/Types.hs | 2 +- azure-auth/{src => Azure}/Utils.hs | 5 +++-- azure-auth/azure-auth.cabal | 11 +++-------- azure-key-vault/{src => Azure}/Secret.hs | 11 +++++------ azure-key-vault/azure-key-vault.cabal | 5 +---- 6 files changed, 17 insertions(+), 25 deletions(-) rename azure-auth/{src => Azure}/Auth.hs (97%) rename azure-auth/{src => Azure}/Types.hs (99%) rename azure-auth/{src => Azure}/Utils.hs (92%) rename azure-key-vault/{src => Azure}/Secret.hs (90%) diff --git a/azure-auth/src/Auth.hs b/azure-auth/Azure/Auth.hs similarity index 97% rename from azure-auth/src/Auth.hs rename to azure-auth/Azure/Auth.hs index cad6421..448a40e 100644 --- a/azure-auth/src/Auth.hs +++ b/azure-auth/Azure/Auth.hs @@ -4,13 +4,11 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} -module Auth +module Azure.Auth ( defaultAzureCredential , withManagedIdentity ) where -import Types (AccessToken (..), Token, readToken, updateToken) - import Control.Monad.IO.Class (MonadIO) import Data.Data (Proxy (..)) import Data.Text (Text) @@ -19,7 +17,9 @@ import Servant.API (Get, Header', JSON, Optional, QueryParam', Required, Strict, import Servant.Client (BaseUrl (..), ClientM, Scheme (..), client, mkClientEnv, runClientM) import UnliftIO (MonadIO (..), throwIO) import UnliftIO.Environment (lookupEnv) -import Utils (isExpired) + +import Azure.Utils (isExpired) +import Azure.Types (AccessToken (..), Token, readToken, updateToken) import qualified Data.Text as Text diff --git a/azure-auth/src/Types.hs b/azure-auth/Azure/Types.hs similarity index 99% rename from azure-auth/src/Types.hs rename to azure-auth/Azure/Types.hs index 0a85178..c57d541 100644 --- a/azure-auth/src/Types.hs +++ b/azure-auth/Azure/Types.hs @@ -1,4 +1,4 @@ -module Types +module Azure.Types ( ExpiresOn , AccessToken (..) , Token diff --git a/azure-auth/src/Utils.hs b/azure-auth/Azure/Utils.hs similarity index 92% rename from azure-auth/src/Utils.hs rename to azure-auth/Azure/Utils.hs index d6ffcfc..3747719 100644 --- a/azure-auth/src/Utils.hs +++ b/azure-auth/Azure/Utils.hs @@ -1,10 +1,11 @@ -module Utils where +module Azure.Utils where import Data.Time (addUTCTime, getCurrentTime, secondsToNominalDiffTime) import Data.Time.Clock.POSIX (posixSecondsToUTCTime) -import Types (ExpiresOn) import UnliftIO (MonadIO (..)) +import Azure.Types (ExpiresOn) + import qualified Text.Read as Text import qualified Data.Text as Text diff --git a/azure-auth/azure-auth.cabal b/azure-auth/azure-auth.cabal index a3c76ce..6607504 100644 --- a/azure-auth/azure-auth.cabal +++ b/azure-auth/azure-auth.cabal @@ -51,11 +51,9 @@ common common-options library import: common-options - exposed-modules: Auth - Types - Utils - -- other-modules: - -- other-extensions: + exposed-modules: Azure.Auth + Azure.Types + Azure.Utils build-depends: aeson , http-client , servant @@ -63,14 +61,11 @@ library , text , time , unliftio - hs-source-dirs: src default-language: Haskell2010 test-suite azure-auth-test import: common-options default-language: Haskell2010 - -- other-modules: - -- other-extensions: type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Main.hs diff --git a/azure-key-vault/src/Secret.hs b/azure-key-vault/Azure/Secret.hs similarity index 90% rename from azure-key-vault/src/Secret.hs rename to azure-key-vault/Azure/Secret.hs index 4437f43..6366aee 100644 --- a/azure-key-vault/src/Secret.hs +++ b/azure-key-vault/Azure/Secret.hs @@ -2,7 +2,7 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} -module Secret +module Azure.Secret ( KeyVaultResponse (..) , GetSecretFromVaultApi , getSecretFromVault @@ -18,8 +18,8 @@ import Servant.Client (BaseUrl (..), ClientM, Scheme (..), client, mkClientEnv, import UnliftIO (MonadIO (..), throwIO) import GHC.Generics (Generic) -import Auth (defaultAzureCredential) -import Types (AccessToken (..), Token) +import Azure.Auth (defaultAzureCredential) +import Azure.Types (AccessToken (..), Token) import qualified Data.Text as Text @@ -65,8 +65,7 @@ callKeyVaultClient action secretName vaultHost tokenStore = do (action secretName 7.4 ("Bearer " <> atAccessToken authHeader)) (mkClientEnv manager $ BaseUrl Https (Text.unpack vaultHost) 443 "") case res of - Left err -> do + Left err -> throwIO err - Right response -> do - liftIO $ putStrLn $ "Successfully performed request: " <> show response + Right response -> pure response diff --git a/azure-key-vault/azure-key-vault.cabal b/azure-key-vault/azure-key-vault.cabal index 11675ae..6c46080 100644 --- a/azure-key-vault/azure-key-vault.cabal +++ b/azure-key-vault/azure-key-vault.cabal @@ -53,9 +53,7 @@ common common-options library import: common-options - exposed-modules: Secret - -- other-modules: - -- other-extensions: + exposed-modules: Azure.Secret build-depends: aeson , azure-auth , http-client-tls @@ -63,7 +61,6 @@ library , servant-client , text , unliftio - hs-source-dirs: src default-language: Haskell2010 test-suite azure-key-vault-test