Skip to content

Commit 2299f0f

Browse files
committed
[cli] Allow for Validation without a TokenId
1 parent f3c7082 commit 2299f0f

File tree

8 files changed

+26
-24
lines changed

8 files changed

+26
-24
lines changed

cli/src/Core/Context.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Validation (Validation)
3333
-- have a type for each command
3434
data Context m = Context
3535
{ ctxMPFS :: MPFS m
36-
, ctxMkValidation :: TokenId -> Validation m
36+
, ctxMkValidation :: Maybe TokenId -> Validation m
3737
, ctxSubmit :: Wallet -> Submission m
3838
}
3939

@@ -75,7 +75,8 @@ askTestRunConfig tokenId = withConfig tokenId configTestRun
7575
askAgentPKH :: Monad m => TokenId -> WithContext m (Maybe Owner)
7676
askAgentPKH tokenId = withConfig tokenId configAgent
7777

78-
askValidation :: Monad m => TokenId -> WithContext m (Validation m)
78+
askValidation
79+
:: Monad m => Maybe TokenId -> WithContext m (Validation m)
7980
askValidation tokenId = do
8081
ctx <- WithContext ask
8182
return $ ctxMkValidation ctx tokenId
@@ -85,7 +86,7 @@ askSubmit = ctxSubmit <$> WithContext ask
8586

8687
withContext
8788
:: MPFS m
88-
-> (TokenId -> Validation m)
89+
-> (Maybe TokenId -> Validation m)
8990
-> (Wallet -> Submission m)
9091
-> WithContext m a
9192
-> m a

cli/src/Oracle/Token/Cli.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ tokenCmdCore command = do
140140
GetToken tk -> lift $ mpfsGetToken mpfs tk
141141
UpdateToken tk wallet wanted -> do
142142
Submission submit <- ($ wallet) <$> askSubmit
143-
validation <- askValidation tk
143+
validation <- askValidation $ Just tk
144144
mconfig <- askConfig tk
145145
lift $ runValidate $ do
146146
when (null wanted) $ notValidated TokenUpdateOfNoRequests

cli/src/Oracle/Validate/Cli.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ validateCmd tk command = case command of
7676
ValidateRequests -> do
7777
mpfs <- askMpfs
7878
mconfig <- askConfig tk
79-
validation <- askValidation tk
79+
validation <- askValidation $ Just tk
8080
lift $ runValidate $ case command of
8181
ValidateRequests -> do
8282
canonicalJSON <- lift $ mpfsGetToken mpfs tk

cli/src/Oracle/Validate/DownloadAssets.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ downloadFileAndWriteLocally
133133
contentE <-
134134
githubGetFile
135135
(repository testRun)
136-
(commitId testRun)
136+
(Just $ commitId testRun)
137137
(FileName $ sourceDir <> "/" <> filename)
138138
case contentE of
139139
Left err -> pure $ Just $ AssetValidationParseError err

cli/src/User/Agent/Cli.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ whiteList tokenId wallet platform repo = do
281281
, operation = Insert ()
282282
}
283283
requester = owner wallet
284-
validation <- askValidation tokenId
284+
validation <- askValidation $ Just tokenId
285285
Submission submit <- ($ wallet) <$> askSubmit
286286
mpfs <- askMpfs
287287
mconfig <- askConfig tokenId
@@ -310,7 +310,7 @@ blackList tokenId wallet platform repo = do
310310
let key = WhiteListKey platform repo
311311
change = Change (Key key) (Delete ())
312312
requester = owner wallet
313-
validation <- askValidation tokenId
313+
validation <- askValidation $ Just tokenId
314314
Submission submit <- ($ wallet) <$> askSubmit
315315
mpfs <- askMpfs
316316
mconfig <- askConfig tokenId
@@ -345,7 +345,7 @@ downloadAssets
345345
-> WithContext m (AValidationResult DownloadAssetsFailure ())
346346
downloadAssets tokenId testRunId dir = do
347347
testmap <- queryCommand tokenId
348-
validation <- askValidation tokenId
348+
validation <- askValidation $ Just tokenId
349349
lift $ runValidate $ do
350350
void $ validateDownloadAssets validation testmap testRunId dir
351351

@@ -367,7 +367,7 @@ signAndSubmitAnUpdate
367367
(AValidationResult UpdateTestRunFailure (WithTxHash new))
368368
signAndSubmitAnUpdate validate tokenId wallet testRun oldState newState = do
369369
let requester = owner wallet
370-
validation <- askValidation tokenId
370+
validation <- askValidation $ Just tokenId
371371
mconfig <- askConfig tokenId
372372
Submission submit <- ($ wallet) <$> askSubmit
373373
mpfs <- askMpfs

cli/src/User/Requester/Cli.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ createCommand
143143
testRun
144144
duration = do
145145
mconfig <- askConfig tokenId
146-
validation <- askValidation tokenId
146+
validation <- askValidation $ Just tokenId
147147
Submission submit <- ($ wallet) <$> askSubmit
148148
mpfs <- askMpfs
149149
lift $ runValidate $ do
@@ -176,7 +176,7 @@ registerUser
176176
request = do
177177
mpfs <- askMpfs
178178
Submission submit <- ($ wallet) <$> askSubmit
179-
validation <- askValidation tokenId
179+
validation <- askValidation $ Just tokenId
180180
lift $ runValidate $ do
181181
void
182182
$ validateRegisterUser validation
@@ -201,7 +201,7 @@ unregisterUser
201201
wallet
202202
request = do
203203
mpfs <- askMpfs
204-
validation <- askValidation tokenId
204+
validation <- askValidation $ Just tokenId
205205
Submission submit <- ($ wallet) <$> askSubmit
206206
lift $ runValidate $ do
207207
void
@@ -227,7 +227,7 @@ registerRole
227227
wallet
228228
request = do
229229
mpfs <- askMpfs
230-
validation <- askValidation tokenId
230+
validation <- askValidation $ Just tokenId
231231
Submission submit <- ($ wallet) <$> askSubmit
232232
lift $ runValidate $ do
233233
void
@@ -253,7 +253,7 @@ unregisterRole
253253
wallet
254254
request = do
255255
mpfs <- askMpfs
256-
validation <- askValidation tokenId
256+
validation <- askValidation $ Just tokenId
257257
Submission submit <- ($ wallet) <$> askSubmit
258258
lift $ runValidate $ do
259259
void

cli/src/Validation.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ data Validation m = Validation
7979
-> m (Maybe RepositoryRoleFailure)
8080
, githubGetFile
8181
:: Repository
82-
-> Commit
82+
-> Maybe Commit
8383
-> FileName
8484
-> m (Either DownloadedFileFailure Text)
8585
}
@@ -117,13 +117,14 @@ hoistValidation
117117
\repository commit filename -> f $ githubGetFile repository commit filename
118118
}
119119

120-
mkValidation :: Auth -> TokenId -> Validation ClientM
121-
mkValidation auth tk =
120+
mkValidation :: Auth -> Maybe TokenId -> Validation ClientM
121+
mkValidation auth tk = do
122+
let getFacts :: (FromJSON Maybe k, FromJSON Maybe v) => ClientM [Fact k v]
123+
getFacts = maybe (pure []) (fmap parseFacts . getTokenFacts) tk
122124
Validation
123-
{ mpfsGetFacts = parseFacts <$> getTokenFacts tk
124-
, mpfsGetTestRuns = do
125-
facts <- parseFacts <$> getTokenFacts tk
126-
pure $ mapMaybe (\(Fact k _ :: JSFact) -> fromJSON k) facts
125+
{ mpfsGetFacts = getFacts
126+
, mpfsGetTestRuns =
127+
mapMaybe (\(Fact k _ :: JSFact) -> fromJSON k) <$> getFacts
127128
, githubCommitExists = \repository commit ->
128129
liftIO $ GitHub.githubCommitExists auth repository commit
129130
, githubDirectoryExists = \repository commit dir ->

cli/src/Validation/DownloadFile.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ inspectDownloadedFileTemplate repo commit filename downloadFile = do
7676
inspectDownloadedFile
7777
:: Auth
7878
-> Repository
79-
-> Commit
79+
-> Maybe Commit
8080
-> FileName
8181
-> IO (Either DownloadedFileFailure Text)
8282
inspectDownloadedFile auth repo commit filename =
8383
inspectDownloadedFileTemplate
8484
repo
85-
(Just commit)
85+
commit
8686
filename
8787
$ githubGetFile auth

0 commit comments

Comments
 (0)