merge: merge refactor into main

This commit is contained in:
王性驊 2025-03-12 19:07:57 +08:00
commit 97f0d9bbb3
7 changed files with 65 additions and 10 deletions

View File

@ -6,7 +6,8 @@ GOFMT ?= gofmt "-s"
GOFILES := $(shell find . -name "*.go")
LDFLAGS := -s -w
VERSION="v1.0.1"
DOCKER_REPO="container.wang/app-cloudep-permission-service"
DOCKER_REPO="reg.wang/app-cloudep-permission-service"
.PHONY: test
test: # 進行測試

View File

@ -7,7 +7,6 @@ FROM golang:1.24.0 as builder
ARG VERSION
ARG BUILT
ARG GIT_COMMIT
ARG SSH_PRV_KEY
# private go packages
ENV GOPRIVATE=code.30cm.net
@ -17,15 +16,12 @@ COPY . .
RUN apt-get update && \
apt-get install git
apt-get install -y git && \
mkdir /root/.ssh
# Make the root foler for our ssh
RUN mkdir -p /root/.ssh && \
chmod 0700 /root/.ssh && \
ssh-keyscan git.30cm.net > /root/.ssh/known_hosts && \
echo "$SSH_PRV_KEY" > /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/id_rsa
RUN --mount=type=secret,id=ssh_key,dst=/root/.ssh/id_rsa \
ssh-keyscan git.30cm.net >> /root/.ssh/known_hosts
RUN --mount=type=ssh go mod download

View File

@ -121,6 +121,15 @@ message Tokens{
repeated TokenResp token = 1;
}
message GetSystemClaimReq{
string access_token=1;
bool is_expired=2;
}
message GetSystemClaimResp {
map<string,string> data = 1;
}
// Token
// Biz GW
// access_token -> token , refresh_token -> one_time_token
@ -141,6 +150,8 @@ service TokenService {
rpc GetUserTokensByDeviceID(DoTokenByDeviceIDReq) returns(Tokens);
// GetUserTokensByUID UID Tokens
rpc GetUserTokensByUID(QueryTokenByUIDReq) returns(Tokens);
// Claim
rpc GetSystemClaimByAccessToken(GetSystemClaimReq) returns(GetSystemClaimResp);
}

View File

@ -0,0 +1,36 @@
package tokenservicelogic
import (
"context"
"code.30cm.net/digimon/app-cloudep-permission-server/gen_result/pb/permission"
"code.30cm.net/digimon/app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetSystemClaimByAccessTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetSystemClaimByAccessTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSystemClaimByAccessTokenLogic {
return &GetSystemClaimByAccessTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetSystemClaimByAccessToken 取得 Claim
func (l *GetSystemClaimByAccessTokenLogic) GetSystemClaimByAccessToken(in *permission.GetSystemClaimReq) (*permission.GetSystemClaimResp, error) {
claim, err := l.svcCtx.TokenUseCase.ParseSystemClaimsByAccessToken(in.GetAccessToken(), l.svcCtx.Config.Token.Secret, in.GetIsExpired())
if err != nil {
return nil, err
}
return &permission.GetSystemClaimResp{
Data: claim,
}, nil
}

View File

@ -70,3 +70,9 @@ func (s *TokenServiceServer) GetUserTokensByUID(ctx context.Context, in *permiss
l := tokenservicelogic.NewGetUserTokensByUIDLogic(ctx, s.svcCtx)
return l.GetUserTokensByUID(in)
}
// 取得 Claim
func (s *TokenServiceServer) GetSystemClaimByAccessToken(ctx context.Context, in *permission.GetSystemClaimReq) (*permission.GetSystemClaimResp, error) {
l := tokenservicelogic.NewGetSystemClaimByAccessTokenLogic(ctx, s.svcCtx)
return l.GetSystemClaimByAccessToken(in)
}

View File

@ -18,7 +18,7 @@ func (use *additional) Set(key token.Additional, val string) {
if use.additional == nil {
use.additional = make(map[string]string)
}
use.additional[key.String()] = val
}

View File

@ -452,6 +452,11 @@ func (use *TokenUseCase) newToken(ctx context.Context, req *usecase.GenerateToke
}
// 故意 data 裡面不會有那些已經有的欄位資訊
data := NewAdditional(req.Data)
initData := make(map[string]string, 0)
for k, v := range req.Data {
initData[k] = v
}
data.Set(dt.ID, token.ID)
data.Set(dt.Role, req.Role)
data.Set(dt.Scope, req.Scope)