merge: merge refactor into main
This commit is contained in:
commit
97f0d9bbb3
3
Makefile
3
Makefile
|
@ -6,7 +6,8 @@ GOFMT ?= gofmt "-s"
|
||||||
GOFILES := $(shell find . -name "*.go")
|
GOFILES := $(shell find . -name "*.go")
|
||||||
LDFLAGS := -s -w
|
LDFLAGS := -s -w
|
||||||
VERSION="v1.0.1"
|
VERSION="v1.0.1"
|
||||||
DOCKER_REPO="container.wang/app-cloudep-permission-service"
|
DOCKER_REPO="reg.wang/app-cloudep-permission-service"
|
||||||
|
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: # 進行測試
|
test: # 進行測試
|
||||||
|
|
|
@ -7,7 +7,6 @@ FROM golang:1.24.0 as builder
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
ARG BUILT
|
ARG BUILT
|
||||||
ARG GIT_COMMIT
|
ARG GIT_COMMIT
|
||||||
ARG SSH_PRV_KEY
|
|
||||||
|
|
||||||
# private go packages
|
# private go packages
|
||||||
ENV GOPRIVATE=code.30cm.net
|
ENV GOPRIVATE=code.30cm.net
|
||||||
|
@ -17,15 +16,12 @@ COPY . .
|
||||||
|
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install git
|
apt-get install -y git && \
|
||||||
|
mkdir /root/.ssh
|
||||||
|
|
||||||
# Make the root foler for our ssh
|
# Make the root foler for our ssh
|
||||||
RUN mkdir -p /root/.ssh && \
|
RUN --mount=type=secret,id=ssh_key,dst=/root/.ssh/id_rsa \
|
||||||
chmod 0700 /root/.ssh && \
|
ssh-keyscan git.30cm.net >> /root/.ssh/known_hosts
|
||||||
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=ssh go mod download
|
RUN --mount=type=ssh go mod download
|
||||||
|
|
|
@ -121,6 +121,15 @@ message Tokens{
|
||||||
repeated TokenResp token = 1;
|
repeated TokenResp token = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message GetSystemClaimReq{
|
||||||
|
string access_token=1;
|
||||||
|
bool is_expired=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSystemClaimResp {
|
||||||
|
map<string,string> data = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// 跟 Token 相關的大小事,這次只回應錯誤,以及結果,不統一規範
|
// 跟 Token 相關的大小事,這次只回應錯誤,以及結果,不統一規範
|
||||||
// 錯誤碼應該在 Biz GW 在做回應,另外我這邊取名字比較通用,
|
// 錯誤碼應該在 Biz GW 在做回應,另外我這邊取名字比較通用,
|
||||||
// access_token -> token , refresh_token -> one_time_token
|
// access_token -> token , refresh_token -> one_time_token
|
||||||
|
@ -141,6 +150,8 @@ service TokenService {
|
||||||
rpc GetUserTokensByDeviceID(DoTokenByDeviceIDReq) returns(Tokens);
|
rpc GetUserTokensByDeviceID(DoTokenByDeviceIDReq) returns(Tokens);
|
||||||
// GetUserTokensByUID 取得目前所對應的 UID 所存在的 Tokens
|
// GetUserTokensByUID 取得目前所對應的 UID 所存在的 Tokens
|
||||||
rpc GetUserTokensByUID(QueryTokenByUIDReq) returns(Tokens);
|
rpc GetUserTokensByUID(QueryTokenByUIDReq) returns(Tokens);
|
||||||
|
// 取得 Claim
|
||||||
|
rpc GetSystemClaimByAccessToken(GetSystemClaimReq) returns(GetSystemClaimResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -70,3 +70,9 @@ func (s *TokenServiceServer) GetUserTokensByUID(ctx context.Context, in *permiss
|
||||||
l := tokenservicelogic.NewGetUserTokensByUIDLogic(ctx, s.svcCtx)
|
l := tokenservicelogic.NewGetUserTokensByUIDLogic(ctx, s.svcCtx)
|
||||||
return l.GetUserTokensByUID(in)
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ func (use *additional) Set(key token.Additional, val string) {
|
||||||
if use.additional == nil {
|
if use.additional == nil {
|
||||||
use.additional = make(map[string]string)
|
use.additional = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
use.additional[key.String()] = val
|
use.additional[key.String()] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -452,6 +452,11 @@ func (use *TokenUseCase) newToken(ctx context.Context, req *usecase.GenerateToke
|
||||||
}
|
}
|
||||||
// 故意 data 裡面不會有那些已經有的欄位資訊
|
// 故意 data 裡面不會有那些已經有的欄位資訊
|
||||||
data := NewAdditional(req.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.ID, token.ID)
|
||||||
data.Set(dt.Role, req.Role)
|
data.Set(dt.Role, req.Role)
|
||||||
data.Set(dt.Scope, req.Scope)
|
data.Set(dt.Scope, req.Scope)
|
||||||
|
|
Loading…
Reference in New Issue