From 272ffcb54a4075ae9d14e859fee733499c733e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Ar=C3=A1nyi?= Date: Thu, 16 May 2024 16:51:32 +0400 Subject: [PATCH] refactor(act): typos & docs (#40) refactor(act): typos, docs, removed unused import aliases --- pkg/api/bytes.go | 5 ++--- pkg/api/bzz.go | 9 ++++----- pkg/api/dynamicaccess.go | 18 ++++++++++-------- pkg/api/feed.go | 4 ++-- pkg/dynamicaccess/accesslogic.go | 5 +---- pkg/dynamicaccess/accesslogic_test.go | 14 +++++++------- pkg/dynamicaccess/controller.go | 23 +++++++---------------- 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/pkg/api/bytes.go b/pkg/api/bytes.go index 2afb1db99c0..0eefb581c1b 100644 --- a/pkg/api/bytes.go +++ b/pkg/api/bytes.go @@ -15,7 +15,7 @@ import ( "github.com/ethersphere/bee/v2/pkg/file/redundancy" "github.com/ethersphere/bee/v2/pkg/jsonhttp" "github.com/ethersphere/bee/v2/pkg/postage" - storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/gorilla/mux" @@ -124,8 +124,7 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) { return } } - // TODO: what should be the root_address ? (eref vs ref) - span.SetTag("root_address", reference) + span.SetTag("root_address", encryptedReference) err = putter.Done(reference) if err != nil { diff --git a/pkg/api/bzz.go b/pkg/api/bzz.go index b49bc89baea..dc26b26667a 100644 --- a/pkg/api/bzz.go +++ b/pkg/api/bzz.go @@ -30,8 +30,8 @@ import ( "github.com/ethersphere/bee/v2/pkg/log" "github.com/ethersphere/bee/v2/pkg/manifest" "github.com/ethersphere/bee/v2/pkg/postage" - storage "github.com/ethersphere/bee/v2/pkg/storage" - storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer" "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/ethersphere/bee/v2/pkg/topology" "github.com/ethersphere/bee/v2/pkg/tracing" @@ -281,9 +281,8 @@ func (s *Service) fileUploadHandler( ext.LogError(span, err, olog.String("action", "putter.Done")) return } - // TODO: what should be the root_address ? (eref vs ref) span.LogFields(olog.Bool("success", true)) - span.SetTag("root_address", manifestReference) + span.SetTag("root_address", encryptedReference) if tagID != 0 { w.Header().Set(SwarmTagHeader, fmt.Sprint(tagID)) @@ -291,7 +290,7 @@ func (s *Service) fileUploadHandler( } w.Header().Set(ETagHeader, fmt.Sprintf("%q", encryptedReference.String())) w.Header().Set("Access-Control-Expose-Headers", SwarmTagHeader) - // TODO: do we need to return reference as well ? + jsonhttp.Created(w, bzzUploadResponse{ Reference: encryptedReference, }) diff --git a/pkg/api/dynamicaccess.go b/pkg/api/dynamicaccess.go index 32447f905e8..b0be09fbcfa 100644 --- a/pkg/api/dynamicaccess.go +++ b/pkg/api/dynamicaccess.go @@ -21,8 +21,8 @@ import ( "github.com/ethersphere/bee/v2/pkg/file/redundancy" "github.com/ethersphere/bee/v2/pkg/jsonhttp" "github.com/ethersphere/bee/v2/pkg/postage" - storage "github.com/ethersphere/bee/v2/pkg/storage" - storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer" "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) @@ -40,7 +40,7 @@ func getAddressFromContext(ctx context.Context) swarm.Address { return swarm.ZeroAddress } -// setAddress sets the swarm address in the context +// setAddressInContext sets the swarm address in the context func setAddressInContext(ctx context.Context, address swarm.Address) context.Context { return context.WithValue(ctx, addressKey{}, address) } @@ -121,8 +121,8 @@ func (s *Service) actDecryptionHandler() func(h http.Handler) http.Handler { } } -// actEncryptionHandler is a middleware that encrypts the given address using the publisher's public key -// Uploads the encrypted reference, history and kvs to the store +// actEncryptionHandler is a middleware that encrypts the given address using the publisher's public key, +// uploads the encrypted reference, history and kvs to the store func (s *Service) actEncryptionHandler( ctx context.Context, w http.ResponseWriter, @@ -140,7 +140,7 @@ func (s *Service) actEncryptionHandler( return swarm.ZeroAddress, fmt.Errorf("act failed to encrypt reference: %w", err) } // only need to upload history and kvs if a new history is created, - // meaning that the publsher uploaded to the history for the first time + // meaning that the publisher uploaded to the history for the first time if !historyReference.Equal(historyRootHash) { err = putter.Done(storageReference) if err != nil { @@ -199,7 +199,8 @@ func (s *Service) actListGranteesHandler(w http.ResponseWriter, r *http.Request) jsonhttp.OK(w, granteeSlice) } -// TODO: actGrantRevokeHandler doc. +// actGrantRevokeHandler is a middleware that makes updates to the list of grantees, +// only the publisher is authorized to perform this action func (s *Service) actGrantRevokeHandler(w http.ResponseWriter, r *http.Request) { logger := s.logger.WithName("act_grant_revoke_handler").Build() @@ -363,7 +364,8 @@ func (s *Service) actGrantRevokeHandler(w http.ResponseWriter, r *http.Request) }) } -// TODO: actCreateGranteesHandler doc. +// actCreateGranteesHandler is a middleware that creates a new list of grantees, +// only the publisher is authorized to perform this action func (s *Service) actCreateGranteesHandler(w http.ResponseWriter, r *http.Request) { logger := s.logger.WithName("acthandler").Build() diff --git a/pkg/api/feed.go b/pkg/api/feed.go index 3d43d3d148e..552cd03ffa4 100644 --- a/pkg/api/feed.go +++ b/pkg/api/feed.go @@ -21,8 +21,8 @@ import ( "github.com/ethersphere/bee/v2/pkg/manifest/simple" "github.com/ethersphere/bee/v2/pkg/postage" "github.com/ethersphere/bee/v2/pkg/soc" - storage "github.com/ethersphere/bee/v2/pkg/storage" - storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer" "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 1cb9db8b5ba..aab18aa1174 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -9,7 +9,7 @@ import ( "crypto/ecdsa" "fmt" - encryption "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/encryption" "github.com/ethersphere/bee/v2/pkg/kvs" "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/crypto/sha3" @@ -26,13 +26,11 @@ var ( type Decryptor interface { // DecryptRef will return a decrypted reference, for given encrypted reference and grantee DecryptRef(ctx context.Context, storage kvs.KeyValueStore, encryptedRef swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) - // Embedding the Session interface Session } // Control interface for the ACT (does write operations). type Control interface { - // Embedding the Decryptor interface Decryptor // AddGrantee adds a new grantee to the ACT AddGrantee(ctx context.Context, storage kvs.KeyValueStore, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKey *encryption.Key) error @@ -122,7 +120,6 @@ func (al *ActLogic) getAccessKey(ctx context.Context, storage kvs.KeyValueStore, // Generate lookup key and access key decryption key for a given public key func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([]byte, []byte, error) { nonces := [][]byte{zeroByteArray, oneByteArray} - // keys := make([][]byte, 0, len(nonces)) keys, err := al.Session.Key(publicKey, nonces) if keys == nil { return nil, nil, err diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index 8d6c146e468..a894c90e25f 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -77,14 +77,14 @@ func TestDecryptRef_Success(t *testing.T) { t.Error(err) } - acutalRef, err := al.DecryptRef(ctx, s, encryptedRef, &id0.PublicKey) + actualRef, err := al.DecryptRef(ctx, s, encryptedRef, &id0.PublicKey) if err != nil { t.Errorf("There was an error while calling Get: ") t.Error(err) } - if expectedRef.Compare(acutalRef) != 0 { - t.Errorf("Get gave back wrong Swarm reference!") + if expectedRef.Compare(actualRef) != 0 { + t.Errorf("Get returned a wrong Swarm reference!") } } @@ -120,14 +120,14 @@ func TestDecryptRefWithGrantee_Success(t *testing.T) { diffieHellman2 := dynamicaccess.NewDefaultSession(id1) granteeAccessLogic := dynamicaccess.NewLogic(diffieHellman2) - acutalRef, err := granteeAccessLogic.DecryptRef(ctx, s, encryptedRef, &id0.PublicKey) + actualRef, err := granteeAccessLogic.DecryptRef(ctx, s, encryptedRef, &id0.PublicKey) if err != nil { t.Errorf("There was an error while calling Get: ") t.Error(err) } - if expectedRef.Compare(acutalRef) != 0 { - t.Errorf("Get gave back wrong Swarm reference!") + if expectedRef.Compare(actualRef) != 0 { + t.Errorf("Get returned a wrong Swarm reference!") } } @@ -169,7 +169,7 @@ func TestAddPublisher(t *testing.T) { decodedEncryptedAccessKey := hex.EncodeToString(encryptedAccessKey) - // A random value is returned so it is only possibly to check the length of the returned value + // A random value is returned, so it is only possible to check the length of the returned value // We know the lookup key because the generated private key is fixed if len(decodedEncryptedAccessKey) != 64 { t.Errorf("AddPublisher: expected encrypted access key length 64, got %d", len(decodedEncryptedAccessKey)) diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index a8998aa12df..911c59f3f27 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -10,18 +10,15 @@ import ( "io" "time" - encryption "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/encryption" "github.com/ethersphere/bee/v2/pkg/file" - "github.com/ethersphere/bee/v2/pkg/file/pipeline" - "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/v2/pkg/file/redundancy" "github.com/ethersphere/bee/v2/pkg/kvs" - "github.com/ethersphere/bee/v2/pkg/storage" "github.com/ethersphere/bee/v2/pkg/swarm" ) type GranteeManager interface { - // TODO: doc + // HandleGrantees manages the grantees for the given publisher, updating the list based on provided public keys to add or remove. + // Only the publisher can make changes to the grantee list. HandleGrantees(ctx context.Context, ls file.LoadSaver, gls file.LoadSaver, granteeref swarm.Address, historyref swarm.Address, publisher *ecdsa.PublicKey, addList, removeList []*ecdsa.PublicKey) (swarm.Address, swarm.Address, swarm.Address, swarm.Address, error) // GetGrantees returns the list of grantees for the given publisher. // The list is accessible only by the publisher. @@ -70,7 +67,7 @@ func (c *ControllerStruct) DownloadHandler( func (c *ControllerStruct) UploadHandler( ctx context.Context, ls file.LoadSaver, - refrefence swarm.Address, + reference swarm.Address, publisher *ecdsa.PublicKey, historyRootHash swarm.Address, ) (swarm.Address, swarm.Address, swarm.Address, error) { @@ -121,7 +118,7 @@ func (c *ControllerStruct) UploadHandler( } } - encryptedRef, err := c.accessLogic.EncryptRef(ctx, storage, publisher, refrefence) + encryptedRef, err := c.accessLogic.EncryptRef(ctx, storage, publisher, reference) return actRef, historyRef, encryptedRef, err } @@ -265,7 +262,7 @@ func (c *ControllerStruct) HandleGrantees( return glref, eglref, href, actref, nil } -func (c *ControllerStruct) GetGrantees(ctx context.Context, ls file.LoadSaver, publisher *ecdsa.PublicKey, encryptedglref swarm.Address) ([]*ecdsa.PublicKey, error) { +func (c *ControllerStruct) GetGrantees(_ context.Context, ls file.LoadSaver, publisher *ecdsa.PublicKey, encryptedglref swarm.Address) ([]*ecdsa.PublicKey, error) { granteeRef, err := c.decryptRefForPublisher(publisher, encryptedglref) if err != nil { return nil, err @@ -305,13 +302,7 @@ func (c *ControllerStruct) decryptRefForPublisher(publisherPubKey *ecdsa.PublicK return swarm.NewAddress(ref), nil } -func requestPipelineFactory(ctx context.Context, s storage.Putter, encrypt bool, rLevel redundancy.Level) func() pipeline.Interface { - return func() pipeline.Interface { - return builder.NewPipelineBuilder(ctx, s, encrypt, rLevel) - } -} - // TODO: what to do in close ? -func (s *ControllerStruct) Close() error { +func (c *ControllerStruct) Close() error { return nil }