Add error checking while creating auth center

This commit is contained in:
Pavel Korotkov 2020-07-21 13:21:03 +03:00
parent c6b6076544
commit b5bd835cd5
2 changed files with 14 additions and 5 deletions

View file

@ -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: &regexpSubmatcher{re: authorizationFieldRegexp},
zstdEncoder: zstdEncoder,
zstdDecoder: zstdDecoder,
}
}, nil
}
func (center *Center) SetNeoFSKeys(key *ecdsa.PrivateKey) error {

View file

@ -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