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

Feat/act #408

Merged
merged 4 commits into from
Aug 6, 2024
Merged

Feat/act #408

merged 4 commits into from
Aug 6, 2024

Conversation

ferencsarai
Copy link
Member

No description provided.

@ferencsarai ferencsarai reopened this Jul 19, 2024
@ferencsarai ferencsarai marked this pull request as ready for review July 22, 2024 08:51
@istae istae requested review from acha-bill and martinconic July 22, 2024 12:23
Copy link
Contributor

@acha-bill acha-bill left a comment

Choose a reason for hiding this comment

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

Nice! Could we also include tests to ensure that after updating the grantee list (whether adding or revoking access), the nodes either can or cannot download the file as expected?

Also, you should update https://github.com/ethersphere/bee/blob/master/.github/workflows/beekeeper.yml#L17 in the ACT PR to point to this beekeeper branch so that we see the tests in action.

return a.client.requestData(ctx, http.MethodGet, "/"+apiVersion+"/grantee/"+addr.String(), nil, nil)
}

func (a *ActService) PatchGrantees(ctx context.Context, name string, data io.Reader, addr swarm.Address, haddr swarm.Address, batchID string) (ActGranteesResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

name is not used

Copy link
Member Author

Choose a reason for hiding this comment

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

if err = responseErrorHandler(r); err != nil {
return err
}

if v != nil && strings.Contains(r.Header.Get("Content-Type"), "application/json") {
_ = json.NewDecoder(r.Body).Decode(&v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use err = json.NewDecoder(r.Body).Decode(&v) and return if not nil , else we do the for and return nil , right?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is done in responseErrorHandler

if err != nil {
return 0, nil, fmt.Errorf("download file %s: %w", a, err)
}
defer r.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

If an error occurs and r is not nil then this line will not be called and 'r' will not close.

Copy link
Contributor

Choose a reason for hiding this comment

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

'r' is of type io.ReadCloser. In case of an error, r will be nil, so Close should not be called to avoid a potential panic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@gacevicljubisa gacevicljubisa Aug 2, 2024

Choose a reason for hiding this comment

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

@ferencsarai sorry for misunderstanding, "defer r.Close()" should be there (like you placed it). I was trying to reply on @martinconic message, but I forgot to tag him. Please, revert like it was.

Copy link
Member Author

Choose a reason for hiding this comment

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

defer r.Close() added


func (c *Client) AddActGrantees(ctx context.Context, f *File, o api.UploadOptions) (err error) {
h := fileHasher()
r, err := c.api.Act.AddGrantees(ctx, f.Name(), io.TeeReader(f.DataReader(), h), o)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have also some defer r.Close() ? Also in below similar situations?

Copy link
Member Author

Choose a reason for hiding this comment

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

r is ActGranteesResponse struct

@@ -750,6 +767,54 @@ func (c *Client) UploadFile(ctx context.Context, f *File, o api.UploadOptions) (
return
}

func (c *Client) UploadActFile(ctx context.Context, f *File, o api.UploadOptions) (err error) {
h := fileHasher()
r, err := c.api.Act.Upload(ctx, f.Name(), io.TeeReader(f.DataReader(), h), o)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have also some defer r.Close()

Copy link
Member Author

Choose a reason for hiding this comment

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

r is ActUploadResponse struct

@gacevicljubisa
Copy link
Contributor

Nice! Could we also include tests to ensure that after updating the grantee list (whether adding or revoking access), the nodes either can or cannot download the file as expected?

Also, you should update https://github.com/ethersphere/bee/blob/master/.github/workflows/beekeeper.yml#L17 in the ACT PR to point to this beekeeper branch so that we see the tests in action.

Also in the same beekeeper.yaml (bee repoistory), if new "act" check should be used, in Integration tests new step should be added(something like this):

      - name: Test act
        id: act
        run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks=ci-act


// Run executes act check
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
c.logger.Info("ACT test started")
Copy link
Contributor

Choose a reason for hiding this comment

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

this log is redundant and can be removed, every check it is already printed here

c.log.Infof("running check: %s", checkName)

Copy link
Member Author

Choose a reason for hiding this comment

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

)

// Options represents check options
type Options struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

options could be configurable in config.yaml and local.yaml, and then mapped in pkg/config/check.go where "act" is defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

if err != nil {
return 0, nil, fmt.Errorf("download file %s: %w", a, err)
}
defer r.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

'r' is of type io.ReadCloser. In case of an error, r will be nil, so Close should not be called to avoid a potential panic.

return fmt.Errorf("node %s: GetActGrantees after patch: addresses length is not 2", upNodeName)
}

c.logger.Info("ACT test completed")
Copy link
Contributor

Choose a reason for hiding this comment

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

also redundant log.Info

c.log.Infof("%s check completed successfully", checkName)

Copy link
Member Author

Choose a reason for hiding this comment

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


c.logger.Info("ACT grantees added")

time.Sleep(3 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why there is a sleep of 3 seconds, maybe some retry logic is needed as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

without this GetActGrantees return 404

@istae istae requested a review from janos July 24, 2024 10:26
Comment on lines 159 to 161
gPublisher, _ := swarm.ParseHexAddress(str)
history := file.HistroryAddress()
gSize, gHash, gPErr := upClient.DownloadActFile(ctx, file.Address(), &api.DownloadOptions{Act: &act, ActPublicKey: &gPublisher, ActHistoryAddress: &history, ActTimestamp: &timestamp})
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Doesn't the file have only 1 publisher (the original uploader)?
  • Shouldn't this be testing that every grantee can download the file? i.e granteeClient.DownloadActFile
  • Test that revoked clients cannot download the file is missing

Copy link
Member Author

Choose a reason for hiding this comment

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

@ferencsarai
Copy link
Member Author

@istae istae merged commit 7fe190f into ethersphere:master Aug 6, 2024
3 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
Development

Successfully merging this pull request may close these issues.

5 participants