module Ecluse.Core.Registry.Sweep.Outcome (
SweepTally (..),
CycleHalt (..),
CycleOutcome (..),
outcomeComplete,
latches,
renderCycleHalt,
renderGeneration,
renderTally,
renderStoreFault,
storeSubject,
TargetPrerequisites (..),
PrerequisiteStatus (..),
prerequisitesMet,
renderPrerequisites,
EvidenceGaps (..),
unloadedGeneration,
unreadManifest,
evidenceComplete,
renderEvidenceGaps,
) where
import Data.Text qualified as T
import Ecluse.Core.Cve.Types (DbEtag (DbEtag))
import Ecluse.Core.Ecosystem (Ecosystem, ecosystemName)
import Ecluse.Core.Fault (renderTransportCause, tfCause, tfDetail)
import Ecluse.Core.Registry.Maintenance (StoreFault (faultTransport))
data SweepTally = SweepTally
{ SweepTally -> Int
tallyExamined :: Int
, SweepTally -> Int
tallyDeleted :: Int
, SweepTally -> Int
tallyKept :: Int
, SweepTally -> Int
tallyGuardSkipped :: Int
}
deriving stock (SweepTally -> SweepTally -> Bool
(SweepTally -> SweepTally -> Bool)
-> (SweepTally -> SweepTally -> Bool) -> Eq SweepTally
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SweepTally -> SweepTally -> Bool
== :: SweepTally -> SweepTally -> Bool
$c/= :: SweepTally -> SweepTally -> Bool
/= :: SweepTally -> SweepTally -> Bool
Eq, Int -> SweepTally -> ShowS
[SweepTally] -> ShowS
SweepTally -> String
(Int -> SweepTally -> ShowS)
-> (SweepTally -> String)
-> ([SweepTally] -> ShowS)
-> Show SweepTally
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SweepTally -> ShowS
showsPrec :: Int -> SweepTally -> ShowS
$cshow :: SweepTally -> String
show :: SweepTally -> String
$cshowList :: [SweepTally] -> ShowS
showList :: [SweepTally] -> ShowS
Show)
instance Semigroup SweepTally where
SweepTally
left <> :: SweepTally -> SweepTally -> SweepTally
<> SweepTally
right =
SweepTally
{ tallyExamined :: Int
tallyExamined = SweepTally -> Int
tallyExamined SweepTally
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ SweepTally -> Int
tallyExamined SweepTally
right
, tallyDeleted :: Int
tallyDeleted = SweepTally -> Int
tallyDeleted SweepTally
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ SweepTally -> Int
tallyDeleted SweepTally
right
, tallyKept :: Int
tallyKept = SweepTally -> Int
tallyKept SweepTally
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ SweepTally -> Int
tallyKept SweepTally
right
, tallyGuardSkipped :: Int
tallyGuardSkipped = SweepTally -> Int
tallyGuardSkipped SweepTally
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ SweepTally -> Int
tallyGuardSkipped SweepTally
right
}
instance Monoid SweepTally where
mempty :: SweepTally
mempty = Int -> Int -> Int -> Int -> SweepTally
SweepTally Int
0 Int
0 Int
0 Int
0
data CycleHalt
=
HaltConsentWithheld Ecosystem Text Text
|
HaltStorePreserved Ecosystem Text Text
|
HaltDeletionCap Int Int (Maybe DbEtag)
|
HaltStoreFault Ecosystem Text Text
|
HaltBucketUnsplittable Ecosystem Text Text
deriving stock (CycleHalt -> CycleHalt -> Bool
(CycleHalt -> CycleHalt -> Bool)
-> (CycleHalt -> CycleHalt -> Bool) -> Eq CycleHalt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CycleHalt -> CycleHalt -> Bool
== :: CycleHalt -> CycleHalt -> Bool
$c/= :: CycleHalt -> CycleHalt -> Bool
/= :: CycleHalt -> CycleHalt -> Bool
Eq, Int -> CycleHalt -> ShowS
[CycleHalt] -> ShowS
CycleHalt -> String
(Int -> CycleHalt -> ShowS)
-> (CycleHalt -> String)
-> ([CycleHalt] -> ShowS)
-> Show CycleHalt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CycleHalt -> ShowS
showsPrec :: Int -> CycleHalt -> ShowS
$cshow :: CycleHalt -> String
show :: CycleHalt -> String
$cshowList :: [CycleHalt] -> ShowS
showList :: [CycleHalt] -> ShowS
Show)
data CycleOutcome = CycleOutcome
{ CycleOutcome -> Maybe CycleHalt
outcomeHalt :: Maybe CycleHalt
, CycleOutcome -> SweepTally
outcomeTally :: SweepTally
, CycleOutcome -> [TargetPrerequisites]
outcomePrerequisites :: [TargetPrerequisites]
, CycleOutcome -> EvidenceGaps
outcomeEvidence :: EvidenceGaps
}
deriving stock (CycleOutcome -> CycleOutcome -> Bool
(CycleOutcome -> CycleOutcome -> Bool)
-> (CycleOutcome -> CycleOutcome -> Bool) -> Eq CycleOutcome
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CycleOutcome -> CycleOutcome -> Bool
== :: CycleOutcome -> CycleOutcome -> Bool
$c/= :: CycleOutcome -> CycleOutcome -> Bool
/= :: CycleOutcome -> CycleOutcome -> Bool
Eq, Int -> CycleOutcome -> ShowS
[CycleOutcome] -> ShowS
CycleOutcome -> String
(Int -> CycleOutcome -> ShowS)
-> (CycleOutcome -> String)
-> ([CycleOutcome] -> ShowS)
-> Show CycleOutcome
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CycleOutcome -> ShowS
showsPrec :: Int -> CycleOutcome -> ShowS
$cshow :: CycleOutcome -> String
show :: CycleOutcome -> String
$cshowList :: [CycleOutcome] -> ShowS
showList :: [CycleOutcome] -> ShowS
Show)
outcomeComplete :: CycleOutcome -> Bool
outcomeComplete :: CycleOutcome -> Bool
outcomeComplete CycleOutcome
outcome =
Maybe CycleHalt -> Bool
forall a. Maybe a -> Bool
isNothing (CycleOutcome -> Maybe CycleHalt
outcomeHalt CycleOutcome
outcome) Bool -> Bool -> Bool
&& EvidenceGaps -> Bool
evidenceComplete (CycleOutcome -> EvidenceGaps
outcomeEvidence CycleOutcome
outcome)
latches :: CycleHalt -> Bool
latches :: CycleHalt -> Bool
latches = \case
HaltDeletionCap{} -> Bool
True
HaltConsentWithheld{} -> Bool
False
HaltStorePreserved{} -> Bool
False
HaltStoreFault{} -> Bool
False
HaltBucketUnsplittable{} -> Bool
False
renderCycleHalt :: CycleHalt -> Text
renderCycleHalt :: CycleHalt -> Text
renderCycleHalt = \case
HaltConsentWithheld Ecosystem
eco Text
backend Text
descriptor ->
Ecosystem -> Text -> Text
storeSubject Ecosystem
eco Text
backend Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" carries no deletion consent marker: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
descriptor
HaltStorePreserved Ecosystem
eco Text
backend Text
why ->
Ecosystem -> Text -> Text
storeSubject Ecosystem
eco Text
backend Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" refills itself, so a delete changes nothing: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
why
HaltDeletionCap Int
cap Int
issued Maybe DbEtag
etag ->
Text
"the cycle handed over "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
issued
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" versions and reached its deletion cap of "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
cap
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" under advisory generation "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Maybe DbEtag -> Text
renderGeneration Maybe DbEtag
etag
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
", so the Dredger runs no further cycle until it is restarted deliberately"
HaltStoreFault Ecosystem
eco Text
backend Text
fault ->
Text
"a call against " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Ecosystem -> Text -> Text
storeSubject Ecosystem
eco Text
backend Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" produced no answer: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
fault
HaltBucketUnsplittable Ecosystem
eco Text
backend Text
bucket ->
Text
"the walk over "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Ecosystem -> Text -> Text
storeSubject Ecosystem
eco Text
backend
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" cannot read the bucket of names beginning \""
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
bucket
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\": it holds more names than one bucket may, and no narrower bucket divides them"
renderGeneration :: Maybe DbEtag -> Text
renderGeneration :: Maybe DbEtag -> Text
renderGeneration = Text -> (DbEtag -> Text) -> Maybe DbEtag -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"none" (\(DbEtag Text
etag) -> Text
etag)
renderTally :: SweepTally -> Text
renderTally :: SweepTally -> Text
renderTally SweepTally
tally =
Text
"examined "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (SweepTally -> Int
tallyExamined SweepTally
tally)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
", deleted "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (SweepTally -> Int
tallyDeleted SweepTally
tally)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
", kept "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (SweepTally -> Int
tallyKept SweepTally
tally)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
", guard-skipped "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (SweepTally -> Int
tallyGuardSkipped SweepTally
tally)
renderStoreFault :: StoreFault -> Text
renderStoreFault :: StoreFault -> Text
renderStoreFault StoreFault
fault = TransportCause -> Text
renderTransportCause (TransportFault -> TransportCause
tfCause TransportFault
transport) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
": " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TransportFault -> Text
tfDetail TransportFault
transport
where
transport :: TransportFault
transport = StoreFault -> TransportFault
faultTransport StoreFault
fault
storeSubject :: Ecosystem -> Text -> Text
storeSubject :: Ecosystem -> Text -> Text
storeSubject Ecosystem
eco Text
backend = Text
"the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Ecosystem -> Text
ecosystemName Ecosystem
eco Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" store on " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
backend
data TargetPrerequisites = TargetPrerequisites
{ TargetPrerequisites -> Ecosystem
tpEcosystem :: Ecosystem
, TargetPrerequisites -> Text
tpBackend :: Text
, TargetPrerequisites -> PrerequisiteStatus
tpConsent :: PrerequisiteStatus
, TargetPrerequisites -> PrerequisiteStatus
tpClassification :: PrerequisiteStatus
}
deriving stock (TargetPrerequisites -> TargetPrerequisites -> Bool
(TargetPrerequisites -> TargetPrerequisites -> Bool)
-> (TargetPrerequisites -> TargetPrerequisites -> Bool)
-> Eq TargetPrerequisites
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TargetPrerequisites -> TargetPrerequisites -> Bool
== :: TargetPrerequisites -> TargetPrerequisites -> Bool
$c/= :: TargetPrerequisites -> TargetPrerequisites -> Bool
/= :: TargetPrerequisites -> TargetPrerequisites -> Bool
Eq, Int -> TargetPrerequisites -> ShowS
[TargetPrerequisites] -> ShowS
TargetPrerequisites -> String
(Int -> TargetPrerequisites -> ShowS)
-> (TargetPrerequisites -> String)
-> ([TargetPrerequisites] -> ShowS)
-> Show TargetPrerequisites
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TargetPrerequisites -> ShowS
showsPrec :: Int -> TargetPrerequisites -> ShowS
$cshow :: TargetPrerequisites -> String
show :: TargetPrerequisites -> String
$cshowList :: [TargetPrerequisites] -> ShowS
showList :: [TargetPrerequisites] -> ShowS
Show)
data PrerequisiteStatus
=
PrerequisiteMet
|
PrerequisiteUnmet Text
|
PrerequisiteUnread Text
deriving stock (PrerequisiteStatus -> PrerequisiteStatus -> Bool
(PrerequisiteStatus -> PrerequisiteStatus -> Bool)
-> (PrerequisiteStatus -> PrerequisiteStatus -> Bool)
-> Eq PrerequisiteStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PrerequisiteStatus -> PrerequisiteStatus -> Bool
== :: PrerequisiteStatus -> PrerequisiteStatus -> Bool
$c/= :: PrerequisiteStatus -> PrerequisiteStatus -> Bool
/= :: PrerequisiteStatus -> PrerequisiteStatus -> Bool
Eq, Int -> PrerequisiteStatus -> ShowS
[PrerequisiteStatus] -> ShowS
PrerequisiteStatus -> String
(Int -> PrerequisiteStatus -> ShowS)
-> (PrerequisiteStatus -> String)
-> ([PrerequisiteStatus] -> ShowS)
-> Show PrerequisiteStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PrerequisiteStatus -> ShowS
showsPrec :: Int -> PrerequisiteStatus -> ShowS
$cshow :: PrerequisiteStatus -> String
show :: PrerequisiteStatus -> String
$cshowList :: [PrerequisiteStatus] -> ShowS
showList :: [PrerequisiteStatus] -> ShowS
Show)
prerequisitesMet :: TargetPrerequisites -> Bool
prerequisitesMet :: TargetPrerequisites -> Bool
prerequisitesMet TargetPrerequisites
target = (PrerequisiteStatus -> Bool) -> [PrerequisiteStatus] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (PrerequisiteStatus -> PrerequisiteStatus -> Bool
forall a. Eq a => a -> a -> Bool
== PrerequisiteStatus
PrerequisiteMet) [TargetPrerequisites -> PrerequisiteStatus
tpConsent TargetPrerequisites
target, TargetPrerequisites -> PrerequisiteStatus
tpClassification TargetPrerequisites
target]
renderPrerequisites :: TargetPrerequisites -> Text
renderPrerequisites :: TargetPrerequisites -> Text
renderPrerequisites TargetPrerequisites
target =
Ecosystem -> Text -> Text
storeSubject (TargetPrerequisites -> Ecosystem
tpEcosystem TargetPrerequisites
target) (TargetPrerequisites -> Text
tpBackend TargetPrerequisites
target)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
": deletion consent "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> PrerequisiteStatus -> Text
renderPrerequisite (TargetPrerequisites -> PrerequisiteStatus
tpConsent TargetPrerequisites
target)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
", and store classification "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> PrerequisiteStatus -> Text
renderPrerequisite (TargetPrerequisites -> PrerequisiteStatus
tpClassification TargetPrerequisites
target)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". This preview deleted nothing, so it proves no authority to delete"
renderPrerequisite :: PrerequisiteStatus -> Text
renderPrerequisite :: PrerequisiteStatus -> Text
renderPrerequisite = \case
PrerequisiteStatus
PrerequisiteMet -> Text
"is met"
PrerequisiteUnmet Text
detail -> Text
"is not met: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
detail
PrerequisiteUnread Text
detail -> Text
"could not be read: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
detail
data EvidenceGaps = EvidenceGaps
{ EvidenceGaps -> Int
gapAdvisoryGeneration :: Int
, EvidenceGaps -> Int
gapManifests :: Int
}
deriving stock (EvidenceGaps -> EvidenceGaps -> Bool
(EvidenceGaps -> EvidenceGaps -> Bool)
-> (EvidenceGaps -> EvidenceGaps -> Bool) -> Eq EvidenceGaps
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EvidenceGaps -> EvidenceGaps -> Bool
== :: EvidenceGaps -> EvidenceGaps -> Bool
$c/= :: EvidenceGaps -> EvidenceGaps -> Bool
/= :: EvidenceGaps -> EvidenceGaps -> Bool
Eq, Int -> EvidenceGaps -> ShowS
[EvidenceGaps] -> ShowS
EvidenceGaps -> String
(Int -> EvidenceGaps -> ShowS)
-> (EvidenceGaps -> String)
-> ([EvidenceGaps] -> ShowS)
-> Show EvidenceGaps
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EvidenceGaps -> ShowS
showsPrec :: Int -> EvidenceGaps -> ShowS
$cshow :: EvidenceGaps -> String
show :: EvidenceGaps -> String
$cshowList :: [EvidenceGaps] -> ShowS
showList :: [EvidenceGaps] -> ShowS
Show)
instance Semigroup EvidenceGaps where
EvidenceGaps
left <> :: EvidenceGaps -> EvidenceGaps -> EvidenceGaps
<> EvidenceGaps
right =
EvidenceGaps
{ gapAdvisoryGeneration :: Int
gapAdvisoryGeneration = EvidenceGaps -> Int
gapAdvisoryGeneration EvidenceGaps
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ EvidenceGaps -> Int
gapAdvisoryGeneration EvidenceGaps
right
, gapManifests :: Int
gapManifests = EvidenceGaps -> Int
gapManifests EvidenceGaps
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ EvidenceGaps -> Int
gapManifests EvidenceGaps
right
}
instance Monoid EvidenceGaps where
mempty :: EvidenceGaps
mempty = Int -> Int -> EvidenceGaps
EvidenceGaps Int
0 Int
0
unloadedGeneration :: EvidenceGaps
unloadedGeneration :: EvidenceGaps
unloadedGeneration = EvidenceGaps
forall a. Monoid a => a
mempty{gapAdvisoryGeneration = 1}
unreadManifest :: EvidenceGaps
unreadManifest :: EvidenceGaps
unreadManifest = EvidenceGaps
forall a. Monoid a => a
mempty{gapManifests = 1}
evidenceComplete :: EvidenceGaps -> Bool
evidenceComplete :: EvidenceGaps -> Bool
evidenceComplete EvidenceGaps
gaps = EvidenceGaps
gaps EvidenceGaps -> EvidenceGaps -> Bool
forall a. Eq a => a -> a -> Bool
== EvidenceGaps
forall a. Monoid a => a
mempty
renderEvidenceGaps :: EvidenceGaps -> Text
renderEvidenceGaps :: EvidenceGaps -> Text
renderEvidenceGaps EvidenceGaps
gaps =
Text -> [Text] -> Text
T.intercalate
Text
", "
( [Maybe Text] -> [Text]
forall a. [Maybe a] -> [a]
catMaybes
[ Int -> Text -> Text -> Maybe Text
forall {a} {a}.
(Ord a, Num a, Semigroup a, IsString a, Show a) =>
a -> a -> a -> Maybe a
counted (EvidenceGaps -> Int
gapAdvisoryGeneration EvidenceGaps
gaps) Text
"mount" Text
"decided without an advisory generation"
, Int -> Text -> Text -> Maybe Text
forall {a} {a}.
(Ord a, Num a, Semigroup a, IsString a, Show a) =>
a -> a -> a -> Maybe a
counted (EvidenceGaps -> Int
gapManifests EvidenceGaps
gaps) Text
"package" Text
"decided without the store's own metadata"
]
)
where
counted :: a -> a -> a -> Maybe a
counted a
count a
noun a
what
| a
count a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 = Maybe a
forall a. Maybe a
Nothing
| a
count a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1 = a -> Maybe a
forall a. a -> Maybe a
Just (a
"1 " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
noun a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
" " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
what)
| Bool
otherwise = a -> Maybe a
forall a. a -> Maybe a
Just (a -> a
forall b a. (Show a, IsString b) => a -> b
show a
count a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
" " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
noun a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"s " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
what)