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. // NewCenter creates an instance of AuthCenter.
func NewCenter(log *zap.Logger) *Center { func NewCenter(log *zap.Logger) (*Center, error) {
zstdEncoder, _ := zstd.NewWriter(nil) zstdEncoder, err := zstd.NewWriter(nil)
zstdDecoder, _ := zstd.NewReader(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{ return &Center{
log: log, log: log,
submatcher: &regexpSubmatcher{re: authorizationFieldRegexp}, submatcher: &regexpSubmatcher{re: authorizationFieldRegexp},
zstdEncoder: zstdEncoder, zstdEncoder: zstdEncoder,
zstdDecoder: zstdDecoder, zstdDecoder: zstdDecoder,
} }, nil
} }
func (center *Center) SetNeoFSKeys(key *ecdsa.PrivateKey) error { 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 { if err != nil {
return nil, errors.Wrap(err, "could not load UserAuth private key") 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.SetUserAuthKeys(userAuthPrivateKey)
center.SetNeoFSKeys(neofsPrivateKey) center.SetNeoFSKeys(neofsPrivateKey)
return center, nil return center, nil