1
0
forked from extern/smegmesh

Refactored client and server and interfaced out dependencies

This commit is contained in:
Tim Beatham
2023-10-02 16:03:41 +01:00
parent 52e5e3d33c
commit a069b89a9a
15 changed files with 426 additions and 203 deletions

View File

@@ -4,13 +4,14 @@ import (
"context"
"errors"
"github.com/tim-beatham/wgmesh/pkg/ctrlserver"
"github.com/tim-beatham/wgmesh/pkg/auth"
logging "github.com/tim-beatham/wgmesh/pkg/log"
"github.com/tim-beatham/wgmesh/pkg/rpc"
)
type AuthRpcProvider struct {
rpc.UnimplementedAuthenticationServer
server *ctrlserver.MeshCtrlServer
Manager *auth.JwtManager
}
func (a *AuthRpcProvider) JoinMesh(ctx context.Context, in *rpc.JoinAuthMeshRequest) (*rpc.JoinAuthMeshReply, error) {
@@ -20,7 +21,8 @@ func (a *AuthRpcProvider) JoinMesh(ctx context.Context, in *rpc.JoinAuthMeshRequ
return nil, errors.New("Must specify the meshId")
}
token, err := a.server.JwtManager.CreateClaims(in.MeshId, "sharedSecret")
logging.InfoLog.Println("MeshID: " + in.MeshId)
token, err := a.Manager.CreateClaims(in.MeshId, in.Alias)
if err != nil {
return nil, err
@@ -28,7 +30,3 @@ func (a *AuthRpcProvider) JoinMesh(ctx context.Context, in *rpc.JoinAuthMeshRequ
return &rpc.JoinAuthMeshReply{Success: true, Token: token}, nil
}
func NewAuthProvider(ctrlServer *ctrlserver.MeshCtrlServer) *AuthRpcProvider {
return &AuthRpcProvider{server: ctrlServer}
}