@@ -102,6 +102,33 @@ import qualified Data.Yaml.Aeson as Y
102
102
------------------
103
103
104
104
105
+ formatURI :: URI -> T. Text
106
+ formatURI uri =
107
+ let scheme = E. decodeUtf8 $ schemeBS $ uriScheme uri
108
+ auth = case uriAuthority uri of
109
+ Just a -> " //" <> E. decodeUtf8 (hostBS $ authorityHost a)
110
+ Nothing -> " "
111
+ path = E. decodeUtf8 $ uriPath uri
112
+ in scheme <> " :" <> auth <> path
113
+
114
+ -- | Logic to check if it is an Official Channel
115
+ isOfficialURI :: URI -> Bool
116
+ isOfficialURI uri = any (`isURIPrefix` uri) officialURIs
117
+ where
118
+ officialURIs = [isGitHubMetadata]
119
+ isGitHubMetadata uri' =
120
+ schemeBS (uriScheme uri') == " https" &&
121
+ maybe False (\ a -> hostBS (authorityHost a) == " raw.githubusercontent.com" ) (uriAuthority uri') &&
122
+ pathStartsWith " /haskell/ghcup-metadata/" (uriPath uri')
123
+ pathStartsWith prefix path = prefix `B.isPrefixOf` path
124
+ isURIPrefix predicate uri' = predicate uri'
125
+
126
+ -- | Special case to check for nightlies URL
127
+ isNightliesURI :: URI -> Bool
128
+ isNightliesURI uri =
129
+ schemeBS (uriScheme uri) == " https" &&
130
+ maybe False (\ a -> hostBS (authorityHost a) == " ghc.gitlab.haskell.org" ) (uriAuthority uri) &&
131
+ uriPath uri == " /ghcup-metadata/ghcup-nightlies-0.0.7.yaml"
105
132
106
133
-- | Downloads the download information! But only if we need to ;P
107
134
getDownloadsF :: ( FromJSONKey Tool
@@ -124,6 +151,17 @@ getDownloadsF :: ( FromJSONKey Tool
124
151
GHCupInfo
125
152
getDownloadsF pfreq@ (PlatformRequest arch plat _) = do
126
153
Settings { urlSource } <- lift getSettings
154
+ forM_ urlSource $ \ src ->
155
+ case src of
156
+ NewURI uri -> do
157
+ when (not (isOfficialURI uri) || isNightliesURI uri) $
158
+ logWarn $ " Warning: Using non-official metadata source: " <> formatURI uri <>
159
+ " \n This source is not maintained or verified by the GHCup team."
160
+ NewGHCupInfo _ ->
161
+ logWarn " Warning: Using custom GHCupInfo data that is not from an official GHCup metadata source"
162
+ NewSetupInfo _ ->
163
+ logWarn " Warning: Using custom SetupInfo data that is not from an official GHCup metadata source"
164
+ _ -> pure ()
127
165
infos <- liftE $ mapM dl' urlSource
128
166
keys <- if any isRight infos
129
167
then liftE . reThrowAll @ _ @ _ @ '[StackPlatformDetectError ] StackPlatformDetectError $ getStackPlatformKey pfreq
@@ -133,7 +171,7 @@ getDownloadsF pfreq@(PlatformRequest arch plat _) = do
133
171
Right si -> pure $ fromStackSetupInfo si keys
134
172
mergeGhcupInfo ghcupInfos
135
173
where
136
-
174
+
137
175
dl' :: ( FromJSONKey Tool
138
176
, FromJSONKey Version
139
177
, FromJSON VersionInfo
@@ -162,9 +200,11 @@ getDownloadsF pfreq@(PlatformRequest arch plat _) = do
162
200
catchE @ JSONError (\ (JSONDecodeError s) -> do
163
201
logDebug $ " Couldn't decode " <> T. pack base <> " as GHCupInfo, trying as SetupInfo: " <> T. pack s
164
202
Right <$> decodeMetadata @ Stack. SetupInfo base)
165
- $ fmap Left (decodeMetadata @ GHCupInfo base >>= \ gI -> warnOnMetadataUpdate uri gI >> pure gI)
203
+ $ fmap Left (decodeMetadata @ GHCupInfo base >>= \ gI ->
204
+ warnOnMetadataUpdate uri gI >> pure gI)
205
+
166
206
167
- fromStackSetupInfo :: MonadThrow m
207
+ fromStackSetupInfo :: MonadThrow m
168
208
=> Stack. SetupInfo
169
209
-> [String ]
170
210
-> m GHCupInfo
0 commit comments