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

Start refactoring for new linter rules #39

Merged
merged 20 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0e4fa62
implement grantee management
Kexort Apr 22, 2024
953ad35
Add POST endpoint + fixes
Kexort Apr 22, 2024
4697a2e
Save grantees as pubkey list and fix remove error; CHG: act-handler l…
bosi95 Apr 22, 2024
8df33ec
Refactor: pass getter, putter to controller functions
bosi95 Apr 23, 2024
5f219fe
Refactor: error handling in dynamicaccess; Read cache header only for…
bosi95 Apr 23, 2024
17b09e4
CHG: grantees ref is encrypted and added to history ref + tests
bosi95 Apr 26, 2024
e49e4a2
Fix nil pointer dereference panic
Kexort Apr 29, 2024
d0f9ddd
CHG: put actref in handlegrantees; Add: pin, tag,deferred headers
bosi95 Apr 29, 2024
5ae2d9d
CHG: pass loadsave to handlers; check if history address is nil
bosi95 May 6, 2024
f7b7560
FIX: re-init history so that it can be saved; only add publisher if h…
bosi95 May 7, 2024
6fa9c4e
make act timestamp optional
Kexort May 7, 2024
933c5f8
fix revoke grantees
Kexort May 7, 2024
7960a49
Fix: Act timestamp header nil check; Uploadhandler UT
bosi95 May 7, 2024
2ec0977
refactor: start refactoring for now linter rules
kopi-solarpunk May 13, 2024
2098dc0
refactor: revert non ACT related files
kopi-solarpunk May 13, 2024
896e9b9
CHG: accesslogic getkeys refactor
bosi95 May 14, 2024
143cbbf
Merge branch 'act' into refactor
kopi-solarpunk May 15, 2024
9c9289a
refactor: fix errcheck and ineffassign linter errors in most cases
kopi-solarpunk May 15, 2024
c61a4b1
refactor: add headers, and change error handling
kopi-solarpunk May 16, 2024
424c816
refactor: add headers
kopi-solarpunk May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/api/accounting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func TestAccountingInfo(t *testing.T) {
if !reflect.DeepEqual(got, expected) {
t.Errorf("got accounting: %v, expected: %v", got, expected)
}

}

func TestAccountingInfoError(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ type Service struct {
feedFactory feeds.Factory
signer crypto.Signer
post postage.Service
dac dynamicaccess.Service
dac dynamicaccess.Controller
postageContract postagecontract.Interface
probe *Probe
metricsRegistry *prometheus.Registry
Expand Down Expand Up @@ -253,7 +253,7 @@ type ExtraOptions struct {
Pss pss.Interface
FeedFactory feeds.Factory
Post postage.Service
Dac dynamicaccess.Service
Dac dynamicaccess.Controller
PostageContract postagecontract.Interface
Staking staking.Contract
Steward steward.Interface
Expand Down
10 changes: 4 additions & 6 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type testServerOptions struct {
PostageContract postagecontract.Interface
StakingContract staking.Contract
Post postage.Service
Dac dynamicaccess.Service
Dac dynamicaccess.Controller
Steward steward.Interface
WsHeaders http.Header
Authenticator auth.Authenticator
Expand Down Expand Up @@ -190,7 +190,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.
erc20 := erc20mock.New(o.Erc20Opts...)
backend := backendmock.New(o.BackendOpts...)

var extraOpts = api.ExtraOptions{
extraOpts := api.ExtraOptions{
TopologyDriver: topologyDriver,
Accounting: acc,
Pseudosettle: recipient,
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestParseName(t *testing.T) {
const bzzHash = "89c17d0d8018a19057314aa035e61c9d23c47581a61dd3a79a7839692c617e4d"
log := log.Noop

var errInvalidNameOrAddress = errors.New("invalid name or bzz address")
errInvalidNameOrAddress := errors.New("invalid name or bzz address")

testCases := []struct {
desc string
Expand Down Expand Up @@ -531,9 +531,7 @@ func TestPostageHeaderError(t *testing.T) {
func TestOptions(t *testing.T) {
t.Parallel()

var (
client, _, _, _ = newTestServer(t, testServerOptions{})
)
client, _, _, _ := newTestServer(t, testServerOptions{})
for _, tc := range []struct {
endpoint string
expectedMethods string // expectedMethods contains HTTP methods like GET, POST, HEAD, PATCH, DELETE, OPTIONS. These are in alphabetical sorted order
Expand Down
1 change: 0 additions & 1 deletion pkg/api/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func TestConsumedBalances(t *testing.T) {
if !equalBalances(got, expected) {
t.Errorf("got balances: %v, expected: %v", got, expected)
}

}

func TestConsumedError(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) {

encryptedReference := reference
if headers.Act {
encryptedReference, err = s.actEncryptionHandler(r.Context(), logger, w, putter, reference, headers.HistoryAddress)
encryptedReference, err = s.actEncryptionHandler(r.Context(), w, putter, reference, headers.HistoryAddress)
if err != nil {
jsonhttp.InternalServerError(w, errActUpload)
return
Expand Down
1 change: 0 additions & 1 deletion pkg/api/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ func TestBytesInvalidStamp(t *testing.T) {
jsonhttptest.WithRequestBody(bytes.NewReader(content)),
)
})

}

func TestBytesUploadHandlerInvalidInputs(t *testing.T) {
Expand Down
11 changes: 5 additions & 6 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"strings"
"time"

"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
olog "github.com/opentracing/opentracing-go/log"

"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/v2/pkg/feeds"
"github.com/ethersphere/bee/v2/pkg/file/joiner"
Expand All @@ -37,6 +33,9 @@ import (
"github.com/ethersphere/bee/v2/pkg/tracing"
"github.com/ethersphere/langos"
"github.com/gorilla/mux"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
olog "github.com/opentracing/opentracing-go/log"
)

// The size of buffer used for prefetching content with Langos when not using erasure coding
Expand Down Expand Up @@ -266,7 +265,7 @@ func (s *Service) fileUploadHandler(

encryptedReference := manifestReference
if act {
encryptedReference, err = s.actEncryptionHandler(r.Context(), logger, w, putter, manifestReference, historyAddress)
encryptedReference, err = s.actEncryptionHandler(r.Context(), w, putter, manifestReference, historyAddress)
if err != nil {
jsonhttp.InternalServerError(w, errActUpload)
return
Expand Down Expand Up @@ -394,7 +393,7 @@ FETCH:
// go on normally.
if !feedDereferenced {
if l, err := s.manifestFeed(ctx, m); err == nil {
//we have a feed manifest here
// we have a feed manifest here
ch, cur, _, err := l.At(ctx, time.Now().Unix(), 0)
if err != nil {
logger.Debug("bzz download: feed lookup failed", "error", err)
Expand Down
3 changes: 0 additions & 3 deletions pkg/api/bzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,6 @@ func TestInvalidBzzParams(t *testing.T) {
jsonhttptest.WithRequestBody(tr),
jsonhttptest.WithRequestHeader(api.ContentTypeHeader, api.ContentTypeTar),
)

})

t.Run("batch exists", func(t *testing.T) {
Expand Down Expand Up @@ -962,7 +961,6 @@ func TestInvalidBzzParams(t *testing.T) {
jsonhttptest.WithRequestBody(tr),
jsonhttptest.WithRequestHeader(api.ContentTypeHeader, api.ContentTypeTar),
)

})

t.Run("batch not found", func(t *testing.T) {
Expand Down Expand Up @@ -1057,7 +1055,6 @@ func TestInvalidBzzParams(t *testing.T) {
address := "f30c0aa7e9e2a0ef4c9b1b750ebfeaeb7c7c24da700bb089da19a46e3677824b"
jsonhttptest.Request(t, client, http.MethodGet, fmt.Sprintf("/bzz/%s/", address), http.StatusNotFound)
})

}

// TestDirectUploadBzz tests that the direct upload endpoint give correct error message in dev mode
Expand Down
1 change: 0 additions & 1 deletion pkg/api/chequebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ethersphere/bee/v2/pkg/postage/postagecontract"
"github.com/ethersphere/bee/v2/pkg/settlement/swap"
"github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook"

"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/gorilla/mux"
)
Expand Down
6 changes: 0 additions & 6 deletions pkg/api/chequebook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook"
"github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook/mock"
swapmock "github.com/ethersphere/bee/v2/pkg/settlement/swap/mock"

"github.com/ethersphere/bee/v2/pkg/swarm"
)

Expand Down Expand Up @@ -427,7 +426,6 @@ func TestChequebookLastCheques(t *testing.T) {
if !LastChequesEqual(got, expected) {
t.Fatalf("Got: \n %+v \n\n Expected: \n %+v \n\n", got, expected)
}

}

func TestChequebookLastChequesPeer(t *testing.T) {
Expand All @@ -442,7 +440,6 @@ func TestChequebookLastChequesPeer(t *testing.T) {
sig := make([]byte, 65)

lastSentChequeFunc := func(swarm.Address) (*chequebook.SignedCheque, error) {

sig := make([]byte, 65)

lastSentCheque := &chequebook.SignedCheque{
Expand All @@ -458,7 +455,6 @@ func TestChequebookLastChequesPeer(t *testing.T) {
}

lastReceivedChequeFunc := func(swarm.Address) (*chequebook.SignedCheque, error) {

lastReceivedCheque := &chequebook.SignedCheque{
Cheque: chequebook.Cheque{
Beneficiary: beneficiary0,
Expand Down Expand Up @@ -498,7 +494,6 @@ func TestChequebookLastChequesPeer(t *testing.T) {
if !reflect.DeepEqual(got, expected) {
t.Fatalf("Got: \n %+v \n\n Expected: \n %+v \n\n", got, expected)
}

}

func TestChequebookCashout(t *testing.T) {
Expand Down Expand Up @@ -780,7 +775,6 @@ func Test_chequebookLastPeerHandler_invalidInputs(t *testing.T) {
}

func LastChequesEqual(a, b *api.ChequebookLastChequesResponse) bool {

var state bool

for akeys := range a.LastCheques {
Expand Down
5 changes: 2 additions & 3 deletions pkg/api/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (
"strconv"

"github.com/ethersphere/bee/v2/pkg/cac"
"github.com/ethersphere/bee/v2/pkg/soc"

"github.com/ethersphere/bee/v2/pkg/jsonhttp"
"github.com/ethersphere/bee/v2/pkg/postage"
"github.com/ethersphere/bee/v2/pkg/soc"
"github.com/ethersphere/bee/v2/pkg/storage"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -143,7 +142,7 @@ func (s *Service) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {

encryptedReference := chunk.Address()
if headers.Act {
encryptedReference, err = s.actEncryptionHandler(r.Context(), logger, w, putter, chunk.Address(), headers.HistoryAddress)
encryptedReference, err = s.actEncryptionHandler(r.Context(), w, putter, chunk.Address(), headers.HistoryAddress)
if err != nil {
jsonhttp.InternalServerError(w, errActUpload)
return
Expand Down
9 changes: 4 additions & 5 deletions pkg/api/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import (
"testing"
"time"

"github.com/ethersphere/bee/v2/pkg/api"
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
"github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/v2/pkg/log"
mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock"
mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock"
"github.com/ethersphere/bee/v2/pkg/spinlock"
mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"

"github.com/ethersphere/bee/v2/pkg/api"
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
"github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest"
testingc "github.com/ethersphere/bee/v2/pkg/storage/testing"
mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"
"github.com/ethersphere/bee/v2/pkg/swarm"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func TestCORSHeaders(t *testing.T) {
}
})
}

}

// TestCors tests whether CORs work correctly with OPTIONS method
Expand All @@ -135,7 +134,8 @@ func TestCors(t *testing.T) {
{
endpoint: "bzz",
expectedMethods: "POST",
}, {
},
{
endpoint: "bzz/0101011",
expectedMethods: "GET, HEAD",
},
Expand Down
1 change: 0 additions & 1 deletion pkg/api/debugstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ func TestDebugStorage(t *testing.T) {
jsonhttptest.WithExpectedJSONResponse(want),
)
})

}
3 changes: 1 addition & 2 deletions pkg/api/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *Service) dirUploadHandler(

encryptedReference := reference
if act {
encryptedReference, err = s.actEncryptionHandler(r.Context(), logger, w, putter, reference, historyAddress)
encryptedReference, err = s.actEncryptionHandler(r.Context(), w, putter, reference, historyAddress)
if err != nil {
jsonhttp.InternalServerError(w, errActUpload)
return
Expand Down Expand Up @@ -141,7 +141,6 @@ func storeDir(
errorFilename string,
rLevel redundancy.Level,
) (swarm.Address, error) {

logger := tracing.NewLoggerWithTraceID(ctx, log)
loggerV1 := logger.V(1).Build()

Expand Down
7 changes: 2 additions & 5 deletions pkg/api/dirs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ func TestDirs(t *testing.T) {
// check error document
validateAltPath(t, "_non_existent_file_path_", errorDocumentPath)
}

}
t.Run(tc.name, func(t *testing.T) {
t.Run("tar_upload", func(t *testing.T) {
Expand Down Expand Up @@ -542,7 +541,7 @@ func tarFiles(t *testing.T, files []f) *bytes.Buffer {
// create tar header and write it
hdr := &tar.Header{
Name: filePath,
Mode: 0600,
Mode: 0o600,
Size: int64(len(file.data)),
}
if err := tw.WriteHeader(hdr); err != nil {
Expand Down Expand Up @@ -571,7 +570,7 @@ func tarEmptyDir(t *testing.T) *bytes.Buffer {

hdr := &tar.Header{
Name: "empty/",
Mode: 0600,
Mode: 0o600,
}

if err := tw.WriteHeader(hdr); err != nil {
Expand Down Expand Up @@ -604,11 +603,9 @@ func multipartFiles(t *testing.T, files []f) (*bytes.Buffer, string) {
contentType := file.header.Get(api.ContentTypeHeader)
if contentType != "" {
hdr.Set(api.ContentTypeHeader, contentType)

}
if len(file.data) > 0 {
hdr.Set(api.ContentLengthHeader, strconv.Itoa(len(file.data)))

}
part, err := mw.CreatePart(hdr)
if err != nil {
Expand Down
Loading
Loading