Merge pull request #816 from filecoin-project/feat/api-cleanup

Move api struct to a seprate pkg
This commit is contained in:
Łukasz Magiera
2019-12-09 18:33:13 +01:00
committed by GitHub
11 changed files with 101 additions and 93 deletions
-1
View File
@@ -2,7 +2,6 @@ package impl
import (
"context"
"github.com/gbrlsnchs/jwt/v3"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
+2 -1
View File
@@ -3,6 +3,7 @@ package impl
import (
"context"
"encoding/json"
"github.com/filecoin-project/lotus/api/apistruct"
"io"
"mime"
"net/http"
@@ -33,7 +34,7 @@ type StorageMinerAPI struct {
}
func (sm *StorageMinerAPI) ServeRemote(w http.ResponseWriter, r *http.Request) {
if !api.HasPerm(r.Context(), api.PermAdmin) {
if !apistruct.HasPerm(r.Context(), apistruct.PermAdmin) {
w.WriteHeader(401)
json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
return
+2 -2
View File
@@ -3,10 +3,10 @@ package modules
import (
"context"
"crypto/rand"
"github.com/filecoin-project/lotus/api/apistruct"
"io"
"io/ioutil"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/addrutil"
@@ -57,7 +57,7 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, err
// TODO: make this configurable
p := jwtPayload{
Allow: api.AllPermissions,
Allow: apistruct.AllPermissions,
}
cliToken, err := jwt.Sign(&p, jwt.NewHS256(key.PrivateKey))