Remove Staticcheck warnings (#5394)

* remove deprecated ioutil imports

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* remove duplicate imports

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* remove unused values

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* remove some unused types

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* remove deprecated ioutil import

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2023-01-13 15:29:14 +01:00
committed by GitHub
parent 544189b039
commit 3aa864aecc
17 changed files with 48 additions and 98 deletions

View File

@@ -2,7 +2,6 @@ package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -58,7 +57,7 @@ func GetRogueEnvs() {
re := regexp.MustCompile(`os.Getenv\(([^\)]+)\)`)
vars := &ConfigVars{}
fmt.Printf("Reading existing variable definitions from %s\n", fullYamlPath)
yfile, err := ioutil.ReadFile(fullYamlPath)
yfile, err := os.ReadFile(fullYamlPath)
if err == nil {
err := yaml.Unmarshal(yfile, &vars)
if err != nil {
@@ -129,7 +128,7 @@ func GetRogueEnvs() {
log.Fatal(err)
}
fmt.Printf("Writing new variable definitions to %s\n", fullYamlPath)
err = ioutil.WriteFile(fullYamlPath, output, 0666)
err = os.WriteFile(fullYamlPath, output, 0666)
if err != nil {
log.Fatalf("could not write %s", fullYamlPath)
}
@@ -146,7 +145,7 @@ func RenderGlobalVarsTemplate() {
}
fullYamlPath := filepath.Join(curdir, yamlSource)
content, err := ioutil.ReadFile("../../docs/templates/ADOC_extended.tmpl")
content, err := os.ReadFile("../../docs/templates/ADOC_extended.tmpl")
if err != nil {
log.Fatal(err)
}
@@ -155,7 +154,7 @@ func RenderGlobalVarsTemplate() {
vars := &ConfigVars{}
fmt.Printf("Reading existing variable definitions from %s\n", fullYamlPath)
yfile, err := ioutil.ReadFile(fullYamlPath)
yfile, err := os.ReadFile(fullYamlPath)
if err != nil {
log.Fatal(err)
}

View File

@@ -80,7 +80,7 @@ type testConfigOverride struct {
}
type testNoExportedFields struct {
// folowing unexported fields are used for tests
// following unexported fields are used for tests
aString string `env:"TEST_STRING"` //nolint:structcheck,unused
anInt64 int64 `env:"TEST_INT64"` //nolint:structcheck,unused
aUint16 uint16 `env:"TEST_UINT16"` //nolint:structcheck,unused

View File

@@ -1,24 +0,0 @@
package log
import (
mdlog "go-micro.dev/v4/debug/log"
)
type logStream struct {
stream <-chan mdlog.Record
stop chan bool
}
func (l *logStream) Chan() <-chan mdlog.Record {
return l.stream
}
func (l *logStream) Stop() error {
select {
case <-l.stop:
return nil
default:
close(l.stop)
}
return nil
}

View File

@@ -9,47 +9,37 @@ import (
"go-micro.dev/v4/store"
)
var (
storeEnv = "OCIS_STORE"
storeAddressEnv = "OCIS_STORE_ADDRESS"
storeOCMemSize = "OCIS_STORE_OCMEM_SIZE"
)
var ocMemStore *store.Store
type OcisStoreOptions struct {
Type string
// Type determines the implementation:
// * "noop", for a noop store (it does nothing)
// * "etcd", for etcd
// * "ocmem", custom in-memory implementation, with fixed size and optimized prefix
// and suffix search
// * "memory", for a in-memory implementation, which is the default if noone matches
Type string
// Address is a comma-separated list of nodes that the store
// will use. This is currently usable only with the etcd implementation. If it
// isn't provided, "127.0.0.1:2379" will be the only node used.
Address string
Size int
// Size configures the maximum capacity of the cache for
// the "ocmem" implementation, in number of items that the cache can hold per table.
// You can use 5000 to make the cache hold up to 5000 elements.
// The parameter only affects to the "ocmem" implementation, the rest will ignore it.
// If an invalid value is used, the default of 512 will be used instead.
Size int
}
// Get the configured key-value store to be used.
// GetStore returns a configured key-value store
//
// Each microservice (or whatever piece is using the store) should use the
// options available in the interface's operations to choose the right database
// and table to prevent collisions with other microservices.
// Recommended approach is to use "services" or "ocis-pkg" for the database,
// and "services/<service-name>/" or "ocis-pkg/<pkg>/" for the package name.
//
// So far, only the name of the store and the node addresses are configurable
// via environment variables.
// Available options for "OCIS_STORE" are:
// * "noop", for a noop store (it does nothing)
// * "etcd", for etcd
// * "ocmem", custom in-memory implementation, with fixed size and optimized prefix
// and suffix search
// * "memory", for a in-memory implementation, which is the default if noone matches
//
// "OCIS_STORE_ADDRESS" is a comma-separated list of nodes that the store
// will use. This is currently usable only with the etcd implementation. If it
// isn't provided, "127.0.0.1:2379" will be the only node used.
//
// "OCIS_STORE_OCMEM_SIZE" will configure the maximum capacity of the cache for
// the "ocmem" implementation, in number of items that the cache can hold per table.
// You can use "OCIS_STORE_OCMEM_SIZE=5000" so the cache will hold up to 5000 elements.
// The parameter only affects to the "ocmem" implementation, the rest will ignore it.
// If an invalid value is used, the default will be used instead, so up to 512 elements
// the cache will hold.
func GetStore(ocisOpts OcisStoreOptions) store.Store {
var s store.Store

View File

@@ -370,7 +370,7 @@ func TestGetEducationSchoolUsers(t *testing.T) {
lm := &mocks.Client{}
lm.On("Search", schoolByIDSearch1).Return(&ldap.SearchResult{Entries: []*ldap.Entry{schoolEntry, schoolEntry1}}, nil)
lm.On("Search", usersBySchoolIDSearch).Return(&ldap.SearchResult{Entries: []*ldap.Entry{eduUserEntryWithSchool}}, nil)
b, err := getMockedBackend(lm, eduConfig, &logger)
b, _ := getMockedBackend(lm, eduConfig, &logger)
users, err := b.GetEducationSchoolUsers(context.Background(), "abcd-defg")
assert.Nil(t, err)
assert.Equal(t, 1, len(users))

View File

@@ -120,7 +120,7 @@ func TestGetEducationUser(t *testing.T) {
assert.Equal(t, "Test User", user.GetDisplayName())
assert.Equal(t, "abcd-defg", user.GetId())
user, err = b.GetEducationUser(context.Background(), "xxxx-xxxx", nil)
_, err = b.GetEducationUser(context.Background(), "xxxx-xxxx", nil)
lm.AssertNumberOfCalls(t, "Search", 2)
assert.NotNil(t, err)
assert.Equal(t, "itemNotFound", err.Error())

View File

@@ -255,7 +255,7 @@ func TestGetUser(t *testing.T) {
nil)
b, _ = getMockedBackend(lm, lconfig, &logger)
u, err = b.GetUser(context.Background(), "invalid", nil)
_, err = b.GetUser(context.Background(), "invalid", nil)
if err == nil || err.Error() != "itemNotFound" {
t.Errorf("Expected 'itemNotFound' got '%s'", err.Error())
}

View File

@@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
@@ -301,7 +300,7 @@ var _ = Describe("EducationClass", func() {
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
svc.PatchEducationClass(rr, r)
resp, err := ioutil.ReadAll(rr.Body)
resp, err := io.ReadAll(rr.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(resp)).To(ContainSubstring("Request is limited to 20"))
@@ -332,7 +331,7 @@ var _ = Describe("EducationClass", func() {
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
svc.PatchEducationClass(rr, r)
resp, err := ioutil.ReadAll(rr.Body)
resp, err := io.ReadAll(rr.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(resp)).To(ContainSubstring("Error parsing member@odata.bind values"))

View File

@@ -12,7 +12,6 @@ import (
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userprovider "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
@@ -46,8 +45,8 @@ var _ = Describe("Graph", func() {
cfg *config.Config
rr *httptest.ResponseRecorder
currentUser = &userv1beta1.User{
Id: &userv1beta1.UserId{
currentUser = &userprovider.User{
Id: &userprovider.UserId{
OpaqueId: "user",
},
}

View File

@@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
@@ -298,7 +297,7 @@ var _ = Describe("Groups", func() {
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
svc.PatchGroup(rr, r)
resp, err := ioutil.ReadAll(rr.Body)
resp, err := io.ReadAll(rr.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(resp)).To(ContainSubstring("Request is limited to 20"))
@@ -329,7 +328,7 @@ var _ = Describe("Groups", func() {
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
svc.PatchGroup(rr, r)
resp, err := ioutil.ReadAll(rr.Body)
resp, err := io.ReadAll(rr.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(resp)).To(ContainSubstring("Error parsing member@odata.bind values"))

View File

@@ -25,13 +25,6 @@ import (
"github.com/stretchr/testify/mock"
)
type changePwTest struct {
desc string
currentpw string
newpw string
expected int
}
var _ = Describe("Users changing their own password", func() {
var (
svc service.Service

View File

@@ -11,7 +11,6 @@ import (
"github.com/owncloud/ocis/v2/services/ocs/pkg/service/v0/data"
"github.com/owncloud/ocis/v2/services/ocs/pkg/service/v0/response"
settings "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0"
settingsService "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0"
)
// RequireSelfOrAdmin middleware is used to require the requesting user to be an admin or the requested user himself
@@ -48,7 +47,7 @@ func RequireSelfOrAdmin(opts ...Option) func(next http.Handler) http.Handler {
return
}
if len(roleIDs) == 0 {
roleIDs = append(roleIDs, settingsService.BundleUUIDRoleUser, settingsService.SelfManagementPermissionID)
roleIDs = append(roleIDs, settings.BundleUUIDRoleUser, settings.SelfManagementPermissionID)
// if roles are empty, assume we haven't seen the user before and assign a default user role. At least until
// proper roles are provided. See https://github.com/owncloud/ocis/v2/issues/1825 for more context.
//return user, nil

View File

@@ -17,7 +17,6 @@ import (
"github.com/owncloud/ocis/v2/ocis-pkg/log"
pkgmiddleware "github.com/owncloud/ocis/v2/ocis-pkg/middleware"
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/v2/ocis-pkg/version"
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
storesvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/store/v0"
@@ -51,7 +50,7 @@ func Server(cfg *config.Config) *cli.Command {
if err != nil {
return err
}
err = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...)
err = grpc.Configure(grpc.GetClientOptions(cfg.GRPCClientTLS)...)
if err != nil {
return err
}

View File

@@ -5,7 +5,6 @@ import (
"time"
"github.com/go-chi/chi/v5/middleware"
chimiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
)
@@ -19,7 +18,7 @@ func AccessLog(logger log.Logger) func(http.Handler) http.Handler {
logger.Info().
Str("proto", r.Proto).
Str(log.RequestIDString, chimiddleware.GetReqID(r.Context())).
Str(log.RequestIDString, middleware.GetReqID(r.Context())).
Str("remote-addr", r.RemoteAddr).
Str("method", r.Method).
Int("status", wrap.Status()).

View File

@@ -6,14 +6,13 @@ import (
pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto"
"github.com/owncloud/ocis/v2/ocis-pkg/service/http"
svc "github.com/owncloud/ocis/v2/ocis-pkg/service/http"
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
"github.com/owncloud/ocis/v2/ocis-pkg/version"
"go-micro.dev/v4"
)
// Server initializes the http service and server.
func Server(opts ...Option) (svc.Service, error) {
func Server(opts ...Option) (http.Service, error) {
options := newOptions(opts...)
l := options.Logger
httpCfg := options.Config.HTTP
@@ -33,19 +32,19 @@ func Server(opts ...Option) (svc.Service, error) {
}
chain := options.Middlewares.Then(options.Handler)
service, err := svc.NewService(
svc.Name(options.Config.Service.Name),
svc.Version(version.GetString()),
service, err := http.NewService(
http.Name(options.Config.Service.Name),
http.Version(version.GetString()),
http.TLSConfig(shared.HTTPServiceTLS{
Enabled: options.Config.HTTP.TLS,
Cert: options.Config.HTTP.TLSCert,
Key: options.Config.HTTP.TLSKey,
}),
svc.Logger(options.Logger),
svc.Address(options.Config.HTTP.Addr),
svc.Namespace(options.Config.HTTP.Namespace),
svc.Context(options.Context),
svc.Flags(options.Flags...),
http.Logger(options.Logger),
http.Address(options.Config.HTTP.Addr),
http.Namespace(options.Config.HTTP.Namespace),
http.Context(options.Context),
http.Flags(options.Flags...),
)
if err != nil {
options.Logger.Error().
@@ -55,7 +54,7 @@ func Server(opts ...Option) (svc.Service, error) {
}
if err := micro.RegisterHandler(service.Server(), chain); err != nil {
return svc.Service{}, err
return http.Service{}, err
}
return service, nil

View File

@@ -189,7 +189,7 @@ func (c *cs3backend) CreateUserFromClaims(ctx context.Context, claims map[string
if reread {
c.logger.Debug().Msg("User already exist, re-reading via libregraph")
gureq := lgClient.UserApi.GetUser(newctx, newUser.GetOnPremisesSamAccountName())
created, resp, err = gureq.Execute()
created, _, err = gureq.Execute()
if err != nil {
c.logger.Error().Err(err).Msg("Error trying to re-read user from graphAPI")
return nil, err

View File

@@ -11,7 +11,6 @@ import (
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/events/stream"
@@ -145,7 +144,7 @@ func (s Service) Search(ctx context.Context, in *searchsvc.SearchRequest, out *s
}
ctx = grpcmetadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t)
u, _ := ctxpkg.ContextGetUser(ctx)
u, _ := revactx.ContextGetUser(ctx)
key := cacheKey(in.Query, in.PageSize, in.Ref, u)
res, ok := s.FromCache(key)
if !ok {