Expose JWT permission error

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-02-12 21:25:29 +01:00
parent c7ffaad763
commit 49167cc55f
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
2 changed files with 8 additions and 3 deletions

View File

@ -3,10 +3,12 @@ package modules
import (
"context"
"crypto/rand"
"github.com/filecoin-project/lotus/api/apistruct"
"errors"
"io"
"io/ioutil"
"github.com/filecoin-project/lotus/api/apistruct"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/addrutil"
@ -38,7 +40,8 @@ type jwtPayload struct {
func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, error) {
key, err := keystore.Get(JWTSecretName)
if err != nil {
if errors.Is(err, types.ErrKeyInfoNotFound) {
log.Warn("Generating new API secret")
sk, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 32))
@ -68,6 +71,8 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, err
if err := lr.SetAPIToken(cliToken); err != nil {
return nil, err
}
} else if err != nil {
return nil, xerrors.Errorf("could not get JWT Token: %w", err)
}
return (*dtypes.APIAlg)(jwt.NewHS256(key.PrivateKey)), nil

View File

@ -346,7 +346,7 @@ func (fsr *fsLockedRepo) Get(name string) (types.KeyInfo, error) {
}
if fstat.Mode()&0077 != 0 {
return types.KeyInfo{}, xerrors.Errorf(kstrPermissionMsg, name, err)
return types.KeyInfo{}, xerrors.Errorf(kstrPermissionMsg, name, fstat.Mode())
}
file, err := os.Open(keyPath)