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

[#106] Backend-agnostic listDirectoryContents #107

Merged
merged 1 commit into from
May 24, 2022

Conversation

DK318
Copy link
Member

@DK318 DK318 commented May 12, 2022

Description

Problem

At this moment the listDirectoryContents function returns [Text]
and in getEntryOrDir we rely on the fact that vault adds a '/'
to the directory. But other backends might not behave like this.

Solution

Created new data DirectoryContents which stores 2 lists:

  1. list with directories
  2. list with entries
    and changed return type from Maybe [Text] to Maybe DirectoryContents
    in listDirectoryContents function.

Related issue(s)

Fixed #

✅ Checklist for your Pull Request

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:

Stylistic guide (mandatory)

@DK318 DK318 requested review from dcastro and sancho20021 May 12, 2022 14:41
Copy link
Member

@dcastro dcastro left a comment

Choose a reason for hiding this comment

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

Good job! 👍

lib/Backend/Vault/Kv.hs Outdated Show resolved Hide resolved
@DK318 DK318 force-pushed the dk318/#106-backend-agnostic-listsecrets branch from 565e0aa to 4857a8b Compare May 17, 2022 11:34
@DK318 DK318 changed the title [#106] Backend-agnostic listSecrets [#106] Backend-agnostic listDirectoryContents May 17, 2022
Copy link
Contributor

@sancho20021 sancho20021 left a comment

Choose a reason for hiding this comment

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

LGTM, except that pure () situation needs to be revisited :) (Maybe add TODO or fix it in this PR)

entry <- lift $ readEntry backend (Path.appendEntryName rootPath entryName)
case entry of
Just entry -> modify' (Dir.insertEntry entry)
Nothing -> pure ()
Copy link
Contributor

Choose a reason for hiding this comment

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

@dcastro If I remember correctly, when we discussed line 528

Nothing -> pure ()

you said it is not correct to just ignore unexpected Nothing.

Maybe we can throw some internalError, cause contents ^. entryNames returned an entryName that couldn't be read properly by readEntry, which is unexpected.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just copy-pasted that code). Maybe we should really throw something here

Copy link
Member

@dcastro dcastro May 18, 2022

Choose a reason for hiding this comment

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

Yeah I remember saying that. I've been thinking about it a bit more, and maybe pure () is right after all 🤔

So, we're traversing a directory, listDirectoryContents gave us a list of entry names, and then readEntry returned 404 for one of those entry names.

That, to me, suggests that some other user deleted an entry from vault (or whatever backend) while we were traversing the directory.

There's two things we can do here:

  1. ignore this entry that has been concurrently deleted
  2. throw and crash

(2) would imply that coffer can only traverse a vault directory if no one else is messing with it. I don't think we want to do this, we want to allow multiple people to interact with vault at the same time. So ignoring the entry is the sensible thing to do here, IMO.

Copy link
Member

Choose a reason for hiding this comment

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

I do think we should add a comment explaining what this branch means.

Nothing ->
  -- This entry has been concurrently deleted (e.g. by some other user) _while_ we're traversing the directory.
  -- We should just ignore it.
  pure ()

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@dcastro dcastro requested a review from Kariel-Myrr May 20, 2022 17:48
Copy link
Contributor

@Kariel-Myrr Kariel-Myrr left a comment

Choose a reason for hiding this comment

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

LGTM 🌚

@@ -30,17 +30,10 @@ class (Buildable err) => BackendError err

-- | Internal errors that can be thrown if backend is in illegal state.
data InternalCommandsError
= InvalidEntry Text
| EntryPathDoesntHavePrefix EntryPath Path
= EntryPathDoesntHavePrefix EntryPath Path

instance Buildable InternalCommandsError where
build = \case
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we can get rid of \case, because InternalCommandError have only one way now.
But it will add work to person how will add new InternalCommandError and make code more inconsistent(look at CofferError instance).

Copy link
Contributor

@sancho20021 sancho20021 left a comment

Choose a reason for hiding this comment

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

Lgtm

Problem: at this moment the `listDirectoryContents` function returns `[Text]`
and in `getEntryOrDir` we rely on the fact that `vault` adds a '/'
to the directory. But other backends might not behave like this.

Solution: created new data `DirectoryContents` which stores 2 lists:
1. list with directories
2. list with entries
and changed return type from `Maybe [Text]` to `Maybe DirectoryContents`
in `listDirectoryContents` function.
@DK318 DK318 force-pushed the dk318/#106-backend-agnostic-listsecrets branch from 634bfc2 to c2afa9d Compare May 24, 2022 10:13
@DK318 DK318 merged commit 6823b9e into main May 24, 2022
@DK318 DK318 deleted the dk318/#106-backend-agnostic-listsecrets branch May 24, 2022 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hide listSecrets's implementation details
4 participants