Skip to content

Commit

Permalink
variant with either
Browse files Browse the repository at this point in the history
  • Loading branch information
nitinprakash96 committed Aug 18, 2024
1 parent 1c3c423 commit d88eeda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions azure-blob-storage/src/Azure/Blob.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Azure.Blob

-- ** Generating a Shared Access Signature URI
, generateSas
, generateSasEither

-- ** Types for dealing with Blob storage functions
, AccountName (..)
Expand Down
23 changes: 20 additions & 3 deletions azure-blob-storage/src/Azure/Blob/SharedAccessSignature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Azure.Blob.SharedAccessSignature
( generateSas
, generateSasEither
) where

import Azure.Auth (defaultAzureCredential)
Expand All @@ -27,23 +28,39 @@ import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Data.Time (UTCTime (..), addUTCTime, formatTime, getCurrentTime)
import Data.Time.Format (defaultTimeLocale)
import Network.HTTP.Types.URI (urlEncode)
import UnliftIO (MonadIO (..))
import UnliftIO (MonadIO (..), throwString)

import qualified Azure.Types as Auth
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Char8 as C8
import qualified Data.Text as Text

-- TODO: We need to add support for empty fields here. Eg: signedAuthorizedUserObjectId
generateSas ::
MonadIO m =>
AccountName ->
ContainerName ->
BlobName ->
SasTokenExpiry ->
Auth.Token ->
m Url
generateSas accountName containerName blobName expiry tokenStore = do
eUrl <- liftIO $ generateSasEither accountName containerName blobName expiry tokenStore
case eUrl of
Left err ->
throwString $ show err
Right url ->
pure url

-- TODO: We need to add support for empty fields here. Eg: signedAuthorizedUserObjectId
generateSasEither ::
MonadIO m =>
AccountName ->
ContainerName ->
BlobName ->
SasTokenExpiry ->
Auth.Token ->
m (Either Text Url)
generateSas accountName containerName blobName (SasTokenExpiry expiry) tokenStore = do
generateSasEither accountName containerName blobName (SasTokenExpiry expiry) tokenStore = do
accessToken <- liftIO $ defaultAzureCredential Nothing blobStorageResourceUrl tokenStore
now <- liftIO getCurrentTime
let isoStartTime = formatToAzureTime now
Expand Down

0 comments on commit d88eeda

Please sign in to comment.