Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

updates retrieve command to read from cache#33

Merged
brunocalza merged 2 commits intomainfrom
bcalza/uptretrieve
Jan 19, 2024
Merged

updates retrieve command to read from cache#33
brunocalza merged 2 commits intomainfrom
bcalza/uptretrieve

Conversation

@brunocalza
Copy link
Contributor

@brunocalza brunocalza commented Jan 16, 2024

This PR updates the retrieve command to download the file from the cache. I took the opportunity to do some refactoring as well.

Changes:

  • It adds a --cache flag that defaults to true. The only way of retrieval right now.
  • It passes the filename when writing the event to the provider, and when retrieving gets it back
  • Adds optional timeout to the retrieve command in case the client needs an upper bound limit on that request (defaults to zero)

Signed-off-by: Bruno Calza <brunoangelicalza@gmail.com>
@brunocalza brunocalza self-assigned this Jan 16, 2024
return nil
}

type coldStore struct{} // nolint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused code, but keeping for future

provider VaultsProvider
}

func (cs *cacheStore) retrieveStdout(ctx context.Context, cid cid.Cid) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

writing to stdout, we simply pass stdout as the io.Writer

return nil
}

func (cs *cacheStore) retrieveFile(ctx context.Context, cid cid.Cid, output string, name string) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

writing to file, we must ensure the dir exists, then we open the file, and pass as the io.writer

)

// Retriever is responsible for retrieving file from the network.
type Retriever struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new component, that has two modes of retrieval, only the cache is being used right now

if err != nil {
return fmt.Errorf("failed to write to stdout: %s", err)
}
retriever := app.NewRetriever(vaultsprovider.New(provider))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did a bit of refactoring and created a new component

DefaultText: "current directory",
Destination: &output,
},
&cli.StringFlag{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added this flag to make it easier to test on other providers

"github.com/ipfs/go-cid"
"github.com/stretchr/testify/require"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

one test for stdout and another for file

return nil
}

func (bp *vaultsProviderMock) RetrieveEvent(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the mocked implementation used in tests

@brunocalza brunocalza marked this pull request as ready for review January 16, 2024 20:46
Copy link
Contributor

@avichalp avichalp left a comment

Choose a reason for hiding this comment

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

Looks good!

}

client := &http.Client{
Timeout: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this timeout to be configurable? Maybe we can address that later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean, to let the client choose the timeout? The problem is which value to put. There's no way to know how long the download will last, that's very dependent on the client's internet connection and file size. but yeah, maybe we could add that extra flexibility if clients want to put an upper bound

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, i meant an upper bound. Maybe something for later.


type coldStore struct{} // nolint

func (cs *coldStore) retrieve(ctx context.Context, c cid.Cid, path string) error { // nolint
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


func (cs *cacheStore) retrieveFile(ctx context.Context, cid cid.Cid, output string, name string) error {
// Write to the provided path or current directory
if output == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. But curious why not use output == "" for "stdout" instead of hyphen and output == "." for current directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because "-" as stdout is a convention commonly used in command-line programs

Signed-off-by: Bruno Calza <brunoangelicalza@gmail.com>
@brunocalza brunocalza merged commit 0e2ce0e into main Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants