Add AdminService (#176)

* add admin service

* go mod tidy

* fix linter: grpc.Dial

* fix ocean get balance

* fix linter

* add .vscode to gitignore

* rework admin balance API

* fix mockedwallet in covenantless pkg

* make proto
This commit is contained in:
Louis Singer
2024-05-31 15:46:46 +02:00
committed by GitHub
parent 329ba555db
commit 9fc49d9f08
27 changed files with 2510 additions and 73 deletions

View File

@@ -0,0 +1,42 @@
package interceptors
import (
"context"
"encoding/base64"
"fmt"
"strings"
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func unaryAuthenticator(user, pass string) grpc.UnaryServerInterceptor {
adminToken := fmt.Sprintf("%s:%s", user, pass)
adminTokenEncoded := base64.StdEncoding.EncodeToString([]byte(adminToken))
return func(
ctx context.Context,
req interface{},
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (interface{}, error) {
// whitelist the ArkService
if strings.Contains(info.FullMethod, arkv1.ArkService_ServiceDesc.ServiceName) {
return handler(ctx, req)
}
token, err := grpc_auth.AuthFromMD(ctx, "basic")
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, "no basic header found: %v", err)
}
if token != adminTokenEncoded {
return nil, status.Errorf(codes.Unauthenticated, "invalid auth credentials: %v", err)
}
return handler(ctx, req)
}
}

View File

@@ -6,8 +6,11 @@ import (
)
// UnaryInterceptor returns the unary interceptor
func UnaryInterceptor() grpc.ServerOption {
return grpc.UnaryInterceptor(middleware.ChainUnaryServer(unaryLogger))
func UnaryInterceptor(user, pass string) grpc.ServerOption {
return grpc.UnaryInterceptor(middleware.ChainUnaryServer(
unaryAuthenticator(user, pass),
unaryLogger,
))
}
// StreamInterceptor returns the stream interceptor with a logrus log