c41777dcd2
* mostly working api proxy gen * api: Consistent api names * fix docsgen * regenerate api struct * api: expand external interfaces * Add missing gen files * apigen: fix perm detection * api: Move perm tags to the interface * gofmt * worker perms * docsgen * docsgen: ignore tag comments * apigen: add codegen warning * gofmt * missing actor type * docsgen * make linter happy * fix lint * apigen: use directives for tags * docsgen * regen openrpc docs
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package impl
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/filecoin-project/go-jsonrpc"
|
|
"github.com/filecoin-project/go-jsonrpc/auth"
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
"github.com/filecoin-project/lotus/api/client"
|
|
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
|
|
)
|
|
|
|
type remoteWorker struct {
|
|
api.Worker
|
|
closer jsonrpc.ClientCloser
|
|
}
|
|
|
|
func (r *remoteWorker) NewSector(ctx context.Context, sector abi.SectorID) error {
|
|
return xerrors.New("unsupported")
|
|
}
|
|
|
|
func connectRemoteWorker(ctx context.Context, fa api.Common, url string) (*remoteWorker, error) {
|
|
token, err := fa.AuthNew(ctx, []auth.Permission{"admin"})
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("creating auth token for remote connection: %w", err)
|
|
}
|
|
|
|
headers := http.Header{}
|
|
headers.Add("Authorization", "Bearer "+string(token))
|
|
|
|
wapi, closer, err := client.NewWorkerRPC(context.TODO(), url, headers)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
|
|
}
|
|
|
|
return &remoteWorker{wapi, closer}, nil
|
|
}
|
|
|
|
func (r *remoteWorker) Close() error {
|
|
r.closer()
|
|
return nil
|
|
}
|
|
|
|
var _ sectorstorage.Worker = &remoteWorker{}
|