mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
allow 'this' for blockid
This commit is contained in:
parent
5165d099c2
commit
4498ca8e9d
@ -9,6 +9,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -96,6 +97,12 @@ func setTermHtmlMode() {
|
|||||||
var oidRe = regexp.MustCompile(`^[0-9a-f]{8}$`)
|
var oidRe = regexp.MustCompile(`^[0-9a-f]{8}$`)
|
||||||
|
|
||||||
func validateEasyORef(oref string) error {
|
func validateEasyORef(oref string) error {
|
||||||
|
if oref == "this" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if num, err := strconv.Atoi(oref); err == nil && num >= 1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if strings.Contains(oref, ":") {
|
if strings.Contains(oref, ":") {
|
||||||
_, err := waveobj.ParseORef(oref)
|
_, err := waveobj.ParseORef(oref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -27,6 +27,8 @@ import (
|
|||||||
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const SimpleId_This = "this"
|
||||||
|
|
||||||
func (ws *WshServer) AuthenticateCommand(ctx context.Context, data string) error {
|
func (ws *WshServer) AuthenticateCommand(ctx context.Context, data string) error {
|
||||||
w := wshutil.GetWshRpcFromContext(ctx)
|
w := wshutil.GetWshRpcFromContext(ctx)
|
||||||
if w == nil {
|
if w == nil {
|
||||||
@ -190,6 +192,17 @@ func sendWaveObjUpdate(oref waveobj.ORef) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolveSimpleId(ctx context.Context, simpleId string) (*waveobj.ORef, error) {
|
func resolveSimpleId(ctx context.Context, simpleId string) (*waveobj.ORef, error) {
|
||||||
|
if simpleId == SimpleId_This {
|
||||||
|
wshRpc := wshutil.GetWshRpcFromContext(ctx)
|
||||||
|
if wshRpc == nil {
|
||||||
|
return nil, fmt.Errorf("no wshrpc in context")
|
||||||
|
}
|
||||||
|
rpcCtx := wshRpc.GetRpcContext()
|
||||||
|
if rpcCtx.BlockId == "" {
|
||||||
|
return nil, fmt.Errorf("no blockid in rpc context")
|
||||||
|
}
|
||||||
|
return &waveobj.ORef{OType: wstore.OType_Block, OID: rpcCtx.BlockId}, nil
|
||||||
|
}
|
||||||
if strings.Contains(simpleId, ":") {
|
if strings.Contains(simpleId, ":") {
|
||||||
rtn, err := waveobj.ParseORef(simpleId)
|
rtn, err := waveobj.ParseORef(simpleId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -287,6 +287,10 @@ func ValidateAndExtractRpcContextFromToken(tokenStr string) (*wshrpc.RpcContext,
|
|||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("iss claim is missing or invalid")
|
return nil, fmt.Errorf("iss claim is missing or invalid")
|
||||||
}
|
}
|
||||||
|
return mapClaimsToRpcContext(claims), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapClaimsToRpcContext(claims jwt.MapClaims) *wshrpc.RpcContext {
|
||||||
rpcCtx := &wshrpc.RpcContext{}
|
rpcCtx := &wshrpc.RpcContext{}
|
||||||
if claims["blockid"] != nil {
|
if claims["blockid"] != nil {
|
||||||
if blockId, ok := claims["blockid"].(string); ok {
|
if blockId, ok := claims["blockid"].(string); ok {
|
||||||
@ -303,9 +307,25 @@ func ValidateAndExtractRpcContextFromToken(tokenStr string) (*wshrpc.RpcContext,
|
|||||||
rpcCtx.WindowId = windowId
|
rpcCtx.WindowId = windowId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rpcCtx, nil
|
return rpcCtx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only for use on client
|
||||||
|
func ExtractUnverifiedRpcContext(tokenStr string) (*wshrpc.RpcContext, error) {
|
||||||
|
// this happens on the client who does not have access to the secret key
|
||||||
|
// we want to read the claims without validating the signature
|
||||||
|
token, _, err := new(jwt.Parser).ParseUnverified(tokenStr, jwt.MapClaims{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error parsing token: %w", err)
|
||||||
|
}
|
||||||
|
claims, ok := token.Claims.(jwt.MapClaims)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("error getting claims from token")
|
||||||
|
}
|
||||||
|
return mapClaimsToRpcContext(claims), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// only for use on client
|
||||||
func ExtractUnverifiedSocketName(tokenStr string) (string, error) {
|
func ExtractUnverifiedSocketName(tokenStr string) (string, error) {
|
||||||
// this happens on the client who does not have access to the secret key
|
// this happens on the client who does not have access to the secret key
|
||||||
// we want to read the claims without validating the signature
|
// we want to read the claims without validating the signature
|
||||||
|
Loading…
Reference in New Issue
Block a user