Skip to content

Commit

Permalink
fixup! Add Workspace name validation (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackheaven committed Oct 2, 2023
1 parent 52e4289 commit b5cc53a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Monocle/Api/Jwt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import Data.ByteString.Base64 qualified as B64
import Data.ByteString.Lazy qualified as BSL
import Data.Map.Strict qualified as HM
import Monocle.Config (OIDCProviderConfig (..))
import Monocle.Config qualified as Config
import Monocle.Prelude hiding (Error)
import qualified Monocle.Config as Config
import Network.HTTP.Client (Manager)
import Servant.Auth.Server (
FromJWT,
Expand Down
3 changes: 2 additions & 1 deletion src/Monocle/Backend/Provisioner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ runProvisioner :: FilePath -> Text -> Text -> Int -> IO ()
runProvisioner configPath elasticUrl tenantName docCount = do
indexName <-
either
(\e -> fail $ "Invalid tenantName " <> show tenantName <> " (" <> show e <> ")") return
(\e -> fail $ "Invalid tenantName " <> show tenantName <> " (" <> show e <> ")")
return
$ mkIndexName tenantName
runEff . runMonoConfig configPath . runLoggerEffect $ do
conf <- csConfig <$> getReloadConfig
Expand Down
17 changes: 8 additions & 9 deletions src/Monocle/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import Dhall.YamlToDhall qualified as Dhall
import Effectful.Env
import Monocle.Config.Generated
import Monocle.Prelude
import Servant.API (FromHttpApiData(..))
import Servant.API (FromHttpApiData (..))
import System.Directory (getModificationTime)
import Witch qualified

Expand All @@ -126,8 +126,7 @@ data Index = Index
deriving stock (Eq, Show, Generic)
deriving anyclass (Dhall.FromDhall, Dhall.ToDhall)

newtype IndexName
= IndexName { getIndexName :: Text }
newtype IndexName = IndexName {getIndexName :: Text}
deriving stock (Eq, Ord, Show)
deriving newtype (Semigroup, Dhall.ToDhall, Aeson.ToJSON, Aeson.ToJSONKey, Aeson.FromJSONKey)

Expand All @@ -137,12 +136,12 @@ instance Aeson.FromJSON IndexName where

instance Dhall.FromDhall IndexName where
autoWith _ = Dhall.Decoder {..}
where
expected = pure Dhall.Core.Text
extract =
\case
Dhall.Core.TextLit (Dhall.Core.Chunks [] t) -> either Dhall.extractError pure $ mkIndexName t
expr -> Dhall.typeError expected expr
where
expected = pure Dhall.Core.Text
extract =
\case
Dhall.Core.TextLit (Dhall.Core.Chunks [] t) -> either Dhall.extractError pure $ mkIndexName t
expr -> Dhall.typeError expected expr

deriving anyclass instance Witch.From Text IndexName

Expand Down
3 changes: 2 additions & 1 deletion src/Monocle/Effects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -593,5 +593,6 @@ subDemo = fail "Toto"
hardcodedIndexName :: Text -> IndexName
hardcodedIndexName x =
either
(\e -> error $ "hardcodedIndexName: cannot make IndexName from " <> show x <> " (" <> show e <> ")") id
(\e -> error $ "hardcodedIndexName: cannot make IndexName from " <> show x <> " (" <> show e <> ")")
id
$ mkIndexName x
4 changes: 2 additions & 2 deletions test/JsonDecode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ aesonDecodeData dat =
getJsonData :: IO LBS.ByteString
getJsonData = do
xs <-
Faker.generateWithSettings (Faker.setRandomGen stdGen $ Faker.setNonDeterministic Faker.defaultFakerSettings) $
Faker.Combinators.listOf total (fakeChangeEvent minDate maxDate)
Faker.generateWithSettings (Faker.setRandomGen stdGen $ Faker.setNonDeterministic Faker.defaultFakerSettings)
$ Faker.Combinators.listOf total (fakeChangeEvent minDate maxDate)
pure $ Aeson.encode $ mkObj xs
where
minDate = [utctime|1970-01-01 00:00:00|]
Expand Down

0 comments on commit b5cc53a

Please sign in to comment.