diff --git a/.golangci.yaml b/.golangci.yaml index 62ba978671f..068969fc8bd 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -13,7 +13,6 @@ linters: - gosec # TODO: consider enabling the 'gosec' linter to inspect source code for security problems. - tagliatelle # TODO: consider enabling the 'tagliatelle' linter to check the struct tags. - stylecheck # TODO: consider enabling the 'stylecheck' linter to enforce style rules. - - gofmt # TODO: consider enabling the 'gofmt' linter to check whether code was gofmt-ed. - usestdlibvars # TODO: consider enabling the 'usestdlibvars' linter to detect the possibility to use variables/constants from the Go standard library. - thelper # TODO: consider enabling the 'thelper' linter to detect golang test helpers without t.Helper() call and check the consistency of test helpers. - staticcheck # TODO: consider enabling the 'staticcheck' linter to find bugs and performance issues, offer simplifications, and enforce style rules. diff --git a/changelog/unreleased/enhancement-gofmt.md b/changelog/unreleased/enhancement-gofmt.md new file mode 100644 index 00000000000..3ec8d191059 --- /dev/null +++ b/changelog/unreleased/enhancement-gofmt.md @@ -0,0 +1,3 @@ +Enhancement: Enable gofmt linter in golangci-lint and apply gofmt + +https://github.com/cs3org/reva/pull/3463 \ No newline at end of file diff --git a/cmd/revad/runtime/runtime.go b/cmd/revad/runtime/runtime.go index d37732eb9bb..4478b0d54ef 100644 --- a/cmd/revad/runtime/runtime.go +++ b/cmd/revad/runtime/runtime.go @@ -264,7 +264,8 @@ func getHTTPServer(conf interface{}, l *zerolog.Logger) (*rhttp.Server, error) { return s, nil } -// adjustCPU parses string cpu and sets GOMAXPROCS +// adjustCPU parses string cpu and sets GOMAXPROCS +// // according to its value. It accepts either // a number (e.g. 3) or a percent (e.g. 50%). // Default is to use all available cores. diff --git a/internal/grpc/interceptors/eventsmiddleware/events.go b/internal/grpc/interceptors/eventsmiddleware/events.go index d7603e74c52..d3a37d253dd 100644 --- a/internal/grpc/interceptors/eventsmiddleware/events.go +++ b/internal/grpc/interceptors/eventsmiddleware/events.go @@ -42,6 +42,7 @@ func init() { // NewUnary returns a new unary interceptor that emits events when needed // no lint because of the switch statement that should be extendable +// //nolint:gocritic func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error) { publisher, err := publisherFromConfig(m) diff --git a/internal/grpc/services/gateway/usershareprovider.go b/internal/grpc/services/gateway/usershareprovider.go index f2c1b515d8a..fee83561f09 100644 --- a/internal/grpc/services/gateway/usershareprovider.go +++ b/internal/grpc/services/gateway/usershareprovider.go @@ -274,8 +274,8 @@ func (s *svc) GetReceivedShare(ctx context.Context, req *collaboration.GetReceiv // When updating a received share: // if the update contains update for displayName: -// 1) if received share is mounted: we also do a rename in the storage -// 2) if received share is not mounted: we only rename in user share provider. +// 1. if received share is mounted: we also do a rename in the storage +// 2. if received share is not mounted: we only rename in user share provider. func (s *svc) UpdateReceivedShare(ctx context.Context, req *collaboration.UpdateReceivedShareRequest) (*collaboration.UpdateReceivedShareResponse, error) { log := appctx.GetLogger(ctx) diff --git a/internal/http/services/owncloud/ocdav/ocdav_test.go b/internal/http/services/owncloud/ocdav/ocdav_test.go index 9cfd2b060c9..941a4b99a8c 100644 --- a/internal/http/services/owncloud/ocdav/ocdav_test.go +++ b/internal/http/services/owncloud/ocdav/ocdav_test.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares_test.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares_test.go index d21b7e42dc3..4264ecdbfa6 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares_test.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares_test.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/mentix/key/apikey.go b/pkg/mentix/key/apikey.go index 8da609a0168..3481b293b0a 100644 --- a/pkg/mentix/key/apikey.go +++ b/pkg/mentix/key/apikey.go @@ -48,7 +48,8 @@ const ( // GenerateAPIKey generates a new (random) API key which also contains flags and a (salted) hash. // An API key has the following format: -// +// +// func GenerateAPIKey(salt string, flags int) (APIKey, error) { if len(salt) == 0 { return "", errors.Errorf("no salt specified") diff --git a/pkg/registry/config_test.go b/pkg/registry/config_test.go index d981677da9c..a065974d5c9 100644 --- a/pkg/registry/config_test.go +++ b/pkg/registry/config_test.go @@ -28,20 +28,20 @@ config example: --- services: - authprovider: - basic: - name: auth-basic - nodes: - - address: 0.0.0.0:1234 - metadata: - version: v0.1.0 - bearer: - name: auth-bearer - nodes: - - address: 0.0.0.0:5678 - metadata: - version: v0.1.0 + authprovider: + basic: + name: auth-basic + nodes: + - address: 0.0.0.0:1234 + metadata: + version: v0.1.0 + bearer: + name: auth-bearer + nodes: + - address: 0.0.0.0:5678 + metadata: + version: v0.1.0 */ func TestParseConfig(t *testing.T) { type args struct { diff --git a/pkg/storage/fs/cephfs/connections.go b/pkg/storage/fs/cephfs/connections.go index ef378704907..9450cd0a114 100644 --- a/pkg/storage/fs/cephfs/connections.go +++ b/pkg/storage/fs/cephfs/connections.go @@ -54,7 +54,7 @@ type connections struct { groupCache *ristretto.Cache } -//TODO: make configurable/add to options +// TODO: make configurable/add to options var usrLimit int64 = 1e4 func newCache() (c *connections, err error) { diff --git a/pkg/storage/fs/nextcloud/nextcloud_server_mock.go b/pkg/storage/fs/nextcloud/nextcloud_server_mock.go index db514cbb5c9..675a1e92f02 100644 --- a/pkg/storage/fs/nextcloud/nextcloud_server_mock.go +++ b/pkg/storage/fs/nextcloud/nextcloud_server_mock.go @@ -165,9 +165,9 @@ var responses = map[string]Response{ `POST /apps/sciencemesh/~tester/api/storage/GetQuota `: {200, `{"totalBytes":456,"usedBytes":123}`, serverStateEmpty}, `POST /apps/sciencemesh/~tester/api/storage/CreateReference {"path":"some/file/path.txt","url":"http://bing.com/search?q=dotnet"}`: {200, ``, serverStateEmpty}, `POST /apps/sciencemesh/~tester/api/storage/Shutdown `: {200, ``, serverStateEmpty}, - `POST /apps/sciencemesh/~tester/api/storage/SetArbitraryMetadata {"ref":{"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"some/file/path.txt"},"md":{"metadata":{"arbi":"trary","meta":"data"}}}`: {200, ``, serverStateEmpty}, - `POST /apps/sciencemesh/~tester/api/storage/UnsetArbitraryMetadata {"ref":{"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"some/file/path.txt"},"keys":["arbi"]}`: {200, ``, serverStateEmpty}, - `POST /apps/sciencemesh/~tester/api/storage/ListStorageSpaces [{"type":3,"Term":{"Owner":{"idp":"0.0.0.0:19000","opaque_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c","type":1}}},{"type":2,"Term":{"Id":{"opaque_id":"opaque-id"}}},{"type":4,"Term":{"SpaceType":"home"}}]`: {200, ` [{"opaque":{"map":{"bar":{"value":"c2FtYQ=="},"foo":{"value":"c2FtYQ=="}}},"id":{"opaque_id":"some-opaque-storage-space-id"},"owner":{"id":{"idp":"some-idp","opaque_id":"some-opaque-user-id","type":1}},"root":{"storage_id":"some-storage-ud","opaque_id":"some-opaque-root-id"},"name":"My Storage Space","quota":{"quota_max_bytes":456,"quota_max_files":123},"space_type":"home","mtime":{"seconds":1234567890}}]`, serverStateEmpty}, + `POST /apps/sciencemesh/~tester/api/storage/SetArbitraryMetadata {"ref":{"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"some/file/path.txt"},"md":{"metadata":{"arbi":"trary","meta":"data"}}}`: {200, ``, serverStateEmpty}, + `POST /apps/sciencemesh/~tester/api/storage/UnsetArbitraryMetadata {"ref":{"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"some/file/path.txt"},"keys":["arbi"]}`: {200, ``, serverStateEmpty}, + `POST /apps/sciencemesh/~tester/api/storage/ListStorageSpaces [{"type":3,"Term":{"Owner":{"idp":"0.0.0.0:19000","opaque_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c","type":1}}},{"type":2,"Term":{"Id":{"opaque_id":"opaque-id"}}},{"type":4,"Term":{"SpaceType":"home"}}]`: {200, ` [{"opaque":{"map":{"bar":{"value":"c2FtYQ=="},"foo":{"value":"c2FtYQ=="}}},"id":{"opaque_id":"some-opaque-storage-space-id"},"owner":{"id":{"idp":"some-idp","opaque_id":"some-opaque-user-id","type":1}},"root":{"storage_id":"some-storage-ud","opaque_id":"some-opaque-root-id"},"name":"My Storage Space","quota":{"quota_max_bytes":456,"quota_max_files":123},"space_type":"home","mtime":{"seconds":1234567890}}]`, serverStateEmpty}, `POST /apps/sciencemesh/~tester/api/storage/CreateStorageSpace {"opaque":{"map":{"bar":{"value":"c2FtYQ=="},"foo":{"value":"c2FtYQ=="}}},"owner":{"id":{"idp":"some-idp","opaque_id":"some-opaque-user-id","type":1}},"type":"home","name":"My Storage Space","quota":{"quota_max_bytes":456,"quota_max_files":123}}`: {200, `{"storage_space":{"opaque":{"map":{"bar":{"value":"c2FtYQ=="},"foo":{"value":"c2FtYQ=="}}},"id":{"opaque_id":"some-opaque-storage-space-id"},"owner":{"id":{"idp":"some-idp","opaque_id":"some-opaque-user-id","type":1}},"root":{"storage_id":"some-storage-ud","opaque_id":"some-opaque-root-id"},"name":"My Storage Space","quota":{"quota_max_bytes":456,"quota_max_files":123},"space_type":"home","mtime":{"seconds":1234567890}}}`, serverStateEmpty}, } diff --git a/pkg/storage/utils/ace/ace.go b/pkg/storage/utils/ace/ace.go index 0123bce3778..6db1434ccf3 100644 --- a/pkg/storage/utils/ace/ace.go +++ b/pkg/storage/utils/ace/ace.go @@ -39,31 +39,31 @@ import ( // see https://linux.die.net/man/5/nfs4_acl: // the extended attributes will look like this // "user.oc.grant.:::" -// - *type* will be limited to A for now +// - *type* will be limited to A for now // A: Allow - allow *principal* to perform actions requiring *permissions* -// In the future we can use: +// In the future we can use: // U: aUdit - log any attempted access by principal which requires -// permissions. +// permissions. // L: aLarm - generate a system alarm at any attempted access by -// principal which requires permissions +// principal which requires permissions // D: for Deny is not recommended -// - *flags* for now empty or g for group, no inheritance yet +// - *flags* for now empty or g for group, no inheritance yet // - d directory-inherit - newly-created subdirectories will inherit the -// ACE. +// ACE. // - f file-inherit - newly-created files will inherit the ACE, minus its -// inheritance flags. Newly-created subdirectories -// will inherit the ACE; if directory-inherit is not -// also specified in the parent ACE, inherit-only will -// be added to the inherited ACE. +// inheritance flags. Newly-created subdirectories +// will inherit the ACE; if directory-inherit is not +// also specified in the parent ACE, inherit-only will +// be added to the inherited ACE. // - n no-propagate-inherit - newly-created subdirectories will inherit -// the ACE, minus its inheritance flags. +// the ACE, minus its inheritance flags. // - i inherit-only - the ACE is not considered in permissions checks, -// but it is heritable; however, the inherit-only -// flag is stripped from inherited ACEs. -// - *principal* a named user, group or special principal +// but it is heritable; however, the inherit-only +// flag is stripped from inherited ACEs. +// - *principal* a named user, group or special principal // - the oidc sub@iss maps nicely to this // - 'OWNER@', 'GROUP@', and 'EVERYONE@', which are, respectively, analogous to the POSIX user/group/other -// - *permissions* +// - *permissions* // - r read-data (files) / list-directory (directories) // - w write-data (files) / create-file (directories) // - a append-data (files) / create-subdirectory (directories) @@ -78,15 +78,18 @@ import ( // - C write-ACL - write the file/directory NFSv4 ACL. // - o write-owner - change ownership of the file/directory. // - y synchronize - allow clients to use synchronous I/O with the server. +// // TODO implement OWNER@ as "user.oc.grant.A::OWNER@:rwaDxtTnNcCy" // attribute names are limited to 255 chars by the linux kernel vfs, values to 64 kb // ext3 extended attributes must fit inside a single filesystem block ... 4096 bytes // that leaves us with "user.oc.grant.A::someonewithaslightlylongersubject@whateverissuer:rwaDxtTnNcCy" ~80 chars // 4096/80 = 51 shares ... with luck we might move the actual permissions to the value, saving ~15 chars // 4096/64 = 64 shares ... still meh ... we can do better by using ints instead of strings for principals -// "user.oc.grant.u:100000" is pretty neat, but we can still do better: base64 encode the int -// "user.oc.grant.u:6Jqg" but base64 always has at least 4 chars, maybe hex is better for smaller numbers -// well use 4 chars in addition to the ace: "user.oc.grant.u:////" = 65535 -> 18 chars +// +// "user.oc.grant.u:100000" is pretty neat, but we can still do better: base64 encode the int +// "user.oc.grant.u:6Jqg" but base64 always has at least 4 chars, maybe hex is better for smaller numbers +// well use 4 chars in addition to the ace: "user.oc.grant.u:////" = 65535 -> 18 chars +// // 4096/18 = 227 shares // still ... ext attrs for this are not infinite scale ... // so .. attach shares via fileid. @@ -95,8 +98,8 @@ import ( // // whatever ... 50 shares is good enough. If more is needed we can delegate to the metadata // if "user.oc.grant.M" is present look inside the metadata app. -// - if we cannot set an ace we might get an io error. -// in that case convert all shares to metadata and try to set "user.oc.grant.m" +// - if we cannot set an ace we might get an io error. +// in that case convert all shares to metadata and try to set "user.oc.grant.m" // // what about metadata like share creator, share time, expiry? // - creator is same as owner, but can be set diff --git a/pkg/storage/utils/decomposedfs/testhelpers/helpers.go b/pkg/storage/utils/decomposedfs/testhelpers/helpers.go index 41ad8ac098e..2128a75f05a 100644 --- a/pkg/storage/utils/decomposedfs/testhelpers/helpers.go +++ b/pkg/storage/utils/decomposedfs/testhelpers/helpers.go @@ -56,9 +56,9 @@ type TestEnv struct { // NewTestEnv prepares a test environment on disk // The storage contains some directories and a file: // -// /dir1/ -// /dir1/file1 -// /dir1/subdir1/ +// /dir1/ +// /dir1/file1 +// /dir1/subdir1/ func NewTestEnv() (*TestEnv, error) { tmpRoot, err := helpers.TempDir("reva-unit-tests-*-root") if err != nil { diff --git a/pkg/utils/resourceid/owncloud_test.go b/pkg/utils/resourceid/owncloud_test.go index d23574ef588..8c8f928519e 100644 --- a/pkg/utils/resourceid/owncloud_test.go +++ b/pkg/utils/resourceid/owncloud_test.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/tests/integration/grpc/grpc_suite_test.go b/tests/integration/grpc/grpc_suite_test.go index ea8b14d7819..82cbdc2e932 100644 --- a/tests/integration/grpc/grpc_suite_test.go +++ b/tests/integration/grpc/grpc_suite_test.go @@ -62,15 +62,15 @@ type Revad struct { // Placeholders in the config files can be replaced the variables from the // `variables` map, e.g. the config // -// redis = "{{redis_address}}" +// redis = "{{redis_address}}" // // and the variables map // -// variables = map[string]string{"redis_address": "localhost:6379"} +// variables = map[string]string{"redis_address": "localhost:6379"} // // will result in the config // -// redis = "localhost:6379" +// redis = "localhost:6379" // // Special variables are created for the revad addresses, e.g. having a // `storage` and a `users` revad will make `storage_address` and