Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] some minor fixes #201

Merged
merged 6 commits into from
Jun 10, 2024
Merged

[fix] some minor fixes #201

merged 6 commits into from
Jun 10, 2024

Conversation

MangoIV
Copy link
Contributor

@MangoIV MangoIV commented May 31, 2024

  • introduce Exception instance for ParseAdvisoryError
  • display if parsing out of band git attributes failed
  • also try to parse into a UTCTime instead of a ZonedTime

resolves #203
resolves #202
resolves #200


hsec-tools

  • Previous advisories are still valid

MangoIV added 2 commits May 31, 2024 17:52
- introduce Exception instance for ParseAdvisoryError
- display if parsing out of band git attributes failed
Left _ -> emptyOutOfBandAttributes
liftIO (getAdvisoryGitInfo advisoryPath) >>= \case
Left gitErr ->
liftIO (hPutStrLn stderr ("obtaining out of band attributes failed: \n" <> explainGitError gitErr))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May we return a validation error instead of a warning on the stderr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chesterton's fence: why's the error ignoed in the first place, are there valid reasons to not abort here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not, then this was an actual bug but it seems too obvious to be one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is that we don't want to fail if there's no git information as there might still be one supplied by the advisory itself. I think this is an issue with the structure of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have decided to bubble the error up instead of using this oobValue with optional fields. I think it was just not very fortunately designed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that looks reasonable to me. Though I worry this is a complicated API for downstream users, perhaps we could do instead:

  • Make the oob attributes explicit in the advisory document, and/or
  • Publish a static version of the advisories with the oob attributes pre resolved.

What do you think @frasertweedale ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Publishing a version with the oob pre resolved would be a good idea anyways. That would make testing without git possible and generally would allow distribution without git. I don’t think the interface for downstream users is more complicated now, tbh it was quite complicated with these fields that could independently be Nothing when in reality I don’t see a reason why they should be able to. Not attaching a reason for why the oob attributes being missing was problematic as well, imo, this caused the Git errors to never be shown.

@MangoIV MangoIV requested a review from TristanCacqueray May 31, 2024 16:49
@MangoIV
Copy link
Contributor Author

MangoIV commented May 31, 2024

something else I was wondering. Do we really want ZonedTime? It has some really awful properties like it missing an Ord instance. What do you think about changing everything to UTCTime, @TristanCacqueray?

@MangoIV
Copy link
Contributor Author

MangoIV commented May 31, 2024

… it seems like this is an endeavour for another day, toml-parser doesn’t support it (though it should)

@MangoIV MangoIV force-pushed the mangoiv/fixes branch 2 times, most recently from dbf5de8 to 8e8b11e Compare May 31, 2024 19:53
@MangoIV
Copy link
Contributor Author

MangoIV commented May 31, 2024

I have refactored the out of band stuff such that we can bubble up information on why it failed. This is important if git doesn't work as expected.

MangoIV added a commit to MangoIV/cabal-audit that referenced this pull request May 31, 2024
- OutOfBandAttributes now have two mandatory fields
- the git error is bubbled up until it can be handled in validation
@MangoIV
Copy link
Contributor Author

MangoIV commented Jun 1, 2024

I can backport 4b and fe to the minor version if you don’t want breaking changes but I don’t know if it’d be too helpful.

@telser
Copy link

telser commented Jun 7, 2024

I believe this will resolve an issue that currently causes https://github.com/MangoIV/cabal-audit to break for me. Though @MangoIV can correct me if that is incorrect.

@MangoIV
Copy link
Contributor Author

MangoIV commented Jun 7, 2024

Yes @frasertweedale already knows :)

Copy link
Collaborator

@blackheaven blackheaven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick note aside: I'm not a fan of BlockArguments

@MangoIV can you check whether forcing git date format fixes the issue please?

code/hsec-tools/app/Main.hs Show resolved Hide resolved
parseTime :: String -> Either GitError ZonedTime
parseTime s = maybe (Left $ GitTimeParseError s) Right $
iso8601ParseM s
<|> utcToZonedTime utc <$> iso8601ParseM s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it does preserve the date

Copy link
Contributor Author

@MangoIV MangoIV Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just validated that the osv files are not changed by this PR with:

mkdir osvs
for i in $(find advisories/ -name "*.md" | grep -v reserved); do cabal run exe:hsec-tools -- osv $i > osvs/$(basename $i); done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that obvious, we get a time and day without time zone, assuming UTC seems audacious.

IMO, we should rely only on UTCTime, enforcing it in the git command.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, yes I'm on UTC. Then I remove my approval. Perhaps we could just parse an epoch timestamp if possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hsec-tools already does this several times (assuming UTC when there's not enough information) That's why I opened the issue about removing ZonedTime from hsec-tools. It makes stuff harder as well. It is however the correct time to assume, it's not wrong, it's just not semantically as nice. See #203 cc @frasertweedale who commented on #203

parseTime s = maybe (Left $ GitTimeParseError s) Right $ iso8601ParseM s
parseTime :: String -> Either GitError ZonedTime
parseTime s = maybe (Left $ GitTimeParseError s) Right $
iso8601ParseM s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should force the format at git level: https://stackoverflow.com/a/7651782

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to pass --date=local and it didn't work. This is in general not really ideal, we shouldn't depend on the git installation if git itself doesn't guarantee a stable interface to these things and/ or this is not documented.

There's also haskell/time#257 which I don't know whether it's the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/MangoIV/cabal-audit/actions/runs/9321254777/job/25659857545

here's a run. the build step is Test git which uses the date format local and it still outputs a non-zoned iso8601. I wouldn't have done the separate parse try without trying that first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume (read "guess") that it is valid to output a non-zoned iso8601 even with local if the computer is itself in UTC which is why I'm not sure whether parsing an unzoned time into a UTCTime should just work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this, it seems to be the lesser bad solution we have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, setting it in git is a non-solution because it doesn't work. We have to do it like this, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, I thought that, requiring a ZonedTime from git wasn't working, requiring a UTCTime doesn't work either?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh but then we always lose zone information, what does that improve? should we do #203 then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frasertweedale was talking of a flag few minutes ago (at ZuriHac), maybe we can have a try

@MangoIV MangoIV requested a review from blackheaven June 7, 2024 15:26
@frasertweedale frasertweedale self-requested a review June 7, 2024 15:32
@MangoIV
Copy link
Contributor Author

MangoIV commented Jun 9, 2024

I have replaced ZonedTime with UTCTime; there's now not a single place where ZonedTime occurs anymore

@MangoIV
Copy link
Contributor Author

MangoIV commented Jun 9, 2024

how do I check if the advisories are still valid btw? :3

@MangoIV
Copy link
Contributor Author

MangoIV commented Jun 9, 2024

don't wanna break your stuff :3

@MangoIV
Copy link
Contributor Author

MangoIV commented Jun 9, 2024

thank you for your review @blackheaven @TristanCacqueray <3

@blackheaven
Copy link
Collaborator

how do I check if the advisories are still valid btw? :3

the CI handles it :)

@frasertweedale
Copy link
Collaborator

Thank you @MangoIV! Merging now.

@frasertweedale frasertweedale merged commit c2960f7 into haskell:main Jun 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants