Skip to content

Commit 6538323

Browse files
committed
[cli] fix: move ssh option from anti facts to anti facts test-runs and anti facts test-run done
1 parent 89570dc commit 6538323

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

cli/src/Cli.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ data Command a where
6464
RetractRequest
6565
:: MPFSClient -> Wallet -> RequestRefId -> Command TxHash
6666
GetFacts
67-
:: Maybe (SSHClient 'WithSelector)
68-
-> MPFSClient
67+
:: MPFSClient
6968
-> TokenId
7069
-> FactsSelection a
7170
-> Command a
@@ -123,15 +122,15 @@ cmd = \case
123122
$ submit
124123
$ \address ->
125124
retractChange address refId
126-
GetFacts ssh MPFSClient{runMPFS} tokenId factsCommand -> do
125+
GetFacts MPFSClient{runMPFS} tokenId factsCommand -> do
127126
let validation =
128127
mkValidation
129128
(error "shouldn't need this...")
130129
mpfsClient
131130
$ Just tokenId
132131
runMPFS
133132
$ factsCmd
134-
((,validation) <$> ssh)
133+
(Just validation)
135134
mpfsClient
136135
tokenId
137136
factsCommand

cli/src/Facts.hs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ data TestRunSelection a where
4848
-> All
4949
-> TestRunSelection [Fact TestRun (TestRunState 'RunningT)]
5050
TestRunDone
51-
:: [TestRunId]
51+
:: Maybe (SSHClient 'WithSelector)
52+
-> [TestRunId]
5253
-> All
5354
-> TestRunSelection [Fact TestRun (TestRunState 'DoneT)]
5455
TestRunRejected
5556
:: [TestRunId]
5657
-> All
5758
-> TestRunSelection [Fact TestRun (TestRunState 'DoneT)]
5859
AnyTestRuns
59-
:: [TestRunId]
60+
:: Maybe (SSHClient 'WithSelector)
61+
-> [TestRunId]
6062
-> All
6163
-> TestRunSelection [Fact TestRun JSValue]
6264
data FactsSelection a where
@@ -95,20 +97,20 @@ whoseFilter whose facts = filterOn facts factKey
9597
factsCmd
9698
:: forall m a
9799
. Monad m
98-
=> Maybe (SSHClient 'WithSelector, Validation m)
100+
=> Maybe (Validation m)
99101
-> MPFS m
100102
-> TokenId
101103
-> FactsSelection a
102104
-> m a
103-
factsCmd mDecrypt mpfs tokenId selection = do
104-
decrypt <- case mDecrypt of
105-
Nothing -> pure id
106-
Just (ssh, validation) -> do
107-
users :: [RegisterUserKey] <-
108-
fmap factKey <$> retrieveAnyFacts @_ @() mpfs tokenId
109-
mk <- decodePrivateSSHFile validation ssh
110-
let decrypt = tryDecryption users mk
111-
pure decrypt
105+
factsCmd mValidation mpfs tokenId selection = do
106+
let mkDecrypt mDecrypt = case (,) <$> mDecrypt <*> mValidation of
107+
Nothing -> pure id
108+
Just (ssh, validation) -> do
109+
users :: [RegisterUserKey] <-
110+
fmap factKey <$> retrieveAnyFacts @_ @() mpfs tokenId
111+
mk <- decodePrivateSSHFile validation ssh
112+
let decrypt = tryDecryption users mk
113+
pure decrypt
112114
let
113115
testRunCommon
114116
:: FromJSON Maybe x => [TestRunId] -> All -> m [Fact TestRun x]
@@ -122,7 +124,8 @@ factsCmd mDecrypt mpfs tokenId selection = do
122124
testRunCommon ids whose
123125
core (TestRunFacts (TestRunRunning ids whose)) = do
124126
testRunCommon ids whose
125-
core (TestRunFacts (TestRunDone ids whose)) = do
127+
core (TestRunFacts (TestRunDone mDecrypt ids whose)) = do
128+
decrypt <- mkDecrypt mDecrypt
126129
facts <-
127130
testRunCommon ids whose <&> fmap decrypt
128131
pure $ filterOn facts factValue $ \case
@@ -134,7 +137,8 @@ factsCmd mDecrypt mpfs tokenId selection = do
134137
pure $ filterOn facts factValue $ \case
135138
Rejected{} -> True
136139
_ -> False
137-
core (TestRunFacts (AnyTestRuns ids whose)) =
140+
core (TestRunFacts (AnyTestRuns mDecrypt ids whose)) = do
141+
decrypt <- mkDecrypt mDecrypt
138142
testRunCommon ids whose <&> fmap (parseDecrypt decrypt)
139143
core ConfigFact = retrieveAnyFacts mpfs tokenId
140144
core WhiteListedFacts = retrieveAnyFacts mpfs tokenId

cli/src/Options.hs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ commandParser =
113113
"Retract a request"
114114
retractRequestOptions
115115
, command "facts" "Get token facts"
116-
$ (\ssh c tk -> fmapBox (GetFacts ssh c tk))
117-
<$> optional sshClientOption
118-
<*> mpfsClientOption
116+
$ (\c tk -> fmapBox (GetFacts c tk))
117+
<$> mpfsClientOption
119118
<*> tokenIdOption
120119
<*> factsSelectionParser
121120
, command "token" "Get the token content"
@@ -161,13 +160,24 @@ testRunSelectionParser =
161160
, command
162161
"done"
163162
"Get done test runs"
164-
(fmap Box $ TestRunDone <$> includedTestRuns <*> whoseOption)
163+
( fmap Box
164+
$ TestRunDone
165+
<$> optional sshClientOption
166+
<*> includedTestRuns
167+
<*> whoseOption
168+
)
165169
, command
166170
"rejected"
167171
"Get rejected test runs"
168172
(fmap Box $ TestRunRejected <$> includedTestRuns <*> whoseOption)
169173
]
170-
<|> fmap Box (AnyTestRuns <$> includedTestRuns <*> whoseOption)
174+
<|> fmap
175+
Box
176+
( AnyTestRuns
177+
<$> optional sshClientOption
178+
<*> includedTestRuns
179+
<*> whoseOption
180+
)
171181

172182
whoseOption :: Parser All
173183
whoseOption =

cli/src/User/Agent/Process.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ pollTestRuns
362362
} = do
363363
allTrs <-
364364
cmd
365-
$ GetFacts Nothing poMPFSClient poTokenId
366-
$ TestRunFacts (AnyTestRuns [] All)
365+
$ GetFacts poMPFSClient poTokenId
366+
$ TestRunFacts (AnyTestRuns Nothing [] All)
367367
let typed :: FromJSON Maybe x => [Fact TestRun x]
368368
typed = mapMaybe (mapM fromJSON) allTrs
369369
etoken <- cmd $ GetToken poAuth poMPFSClient poTokenId

0 commit comments

Comments
 (0)