From b5bd835cd57d528a62b29221b990f3f95c2a34cf Mon Sep 17 00:00:00 2001 From: Pavel Korotkov Date: Tue, 21 Jul 2020 13:21:03 +0300 Subject: [PATCH] Add error checking while creating auth center --- auth/center.go | 14 ++++++++++---- cmd/gate/app-settings.go | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/auth/center.go b/auth/center.go index 83bfc6f44..5400ec469 100644 --- a/auth/center.go +++ b/auth/center.go @@ -45,15 +45,21 @@ type Center struct { } // NewCenter creates an instance of AuthCenter. -func NewCenter(log *zap.Logger) *Center { - zstdEncoder, _ := zstd.NewWriter(nil) - zstdDecoder, _ := zstd.NewReader(nil) +func NewCenter(log *zap.Logger) (*Center, error) { + zstdEncoder, err := zstd.NewWriter(nil) + if err != nil { + return nil, errors.Wrap(err, "failed to create zstd encoder") + } + zstdDecoder, err := zstd.NewReader(nil) + if err != nil { + return nil, errors.Wrap(err, "failed to create zstd decoder") + } return &Center{ log: log, submatcher: ®expSubmatcher{re: authorizationFieldRegexp}, zstdEncoder: zstdEncoder, zstdDecoder: zstdDecoder, - } + }, nil } func (center *Center) SetNeoFSKeys(key *ecdsa.PrivateKey) error { diff --git a/cmd/gate/app-settings.go b/cmd/gate/app-settings.go index 5461f512f..323338f70 100644 --- a/cmd/gate/app-settings.go +++ b/cmd/gate/app-settings.go @@ -110,7 +110,10 @@ func fetchAuthCenter(l *zap.Logger, v *viper.Viper) (*auth.Center, error) { if err != nil { return nil, errors.Wrap(err, "could not load UserAuth private key") } - center := auth.NewCenter(l) + center, err := auth.NewCenter(l) + if err != nil { + return nil, errors.Wrap(err, "failed to create auth center") + } center.SetUserAuthKeys(userAuthPrivateKey) center.SetNeoFSKeys(neofsPrivateKey) return center, nil