-
Notifications
You must be signed in to change notification settings - Fork 23
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
Feat/act #408
Conversation
There was a problem hiding this 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.
pkg/bee/api/act.go
Outdated
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name is not used
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer r.Close removed
https://github.com/Solar-Punk-Ltd/beekeeper/blob/feat/act/pkg/bee/client.go#L233
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer r.Close()
added
pkg/bee/client.go
Outdated
|
||
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r is ActUploadResponse struct
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):
|
pkg/check/act/act.go
Outdated
|
||
// Run executes act check | ||
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) { | ||
c.logger.Info("ACT test started") |
There was a problem hiding this comment.
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
beekeeper/cmd/beekeeper/cmd/check.go
Line 123 in b017aef
c.log.Infof("running check: %s", checkName) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
pkg/check/act/act.go
Outdated
return fmt.Errorf("node %s: GetActGrantees after patch: addresses length is not 2", upNodeName) | ||
} | ||
|
||
c.logger.Info("ACT test completed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also redundant log.Info
beekeeper/cmd/beekeeper/cmd/check.go
Line 142 in b017aef
c.log.Infof("%s check completed successfully", checkName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/check/act/act.go
Outdated
|
||
c.logger.Info("ACT grantees added") | ||
|
||
time.Sleep(3 * time.Second) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
pkg/check/act/act.go
Outdated
gPublisher, _ := swarm.ParseHexAddress(str) | ||
history := file.HistroryAddress() | ||
gSize, gHash, gPErr := upClient.DownloadActFile(ctx, file.Address(), &api.DownloadOptions{Act: &act, ActPublicKey: &gPublisher, ActHistoryAddress: &history, ActTimestamp: ×tamp}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the file have only 1 publisher. Fixed
https://github.com/Solar-Punk-Ltd/beekeeper/blob/feat/act/pkg/check/act/act.go#L186
fix: rearrage stake api (ethersphere#410)
No description provided.