44 lines
		
	
	
		
			1005 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			44 lines
		
	
	
		
			1005 B
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package secretlogic | ||
|  | 
 | ||
|  | import ( | ||
|  | 	"context" | ||
|  | 	"errors" | ||
|  | 	"tianyuan-api/apps/sentinel/internal/model" | ||
|  | 	"tianyuan-api/apps/sentinel/internal/svc" | ||
|  | 	"tianyuan-api/apps/sentinel/sentinel" | ||
|  | 
 | ||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||
|  | ) | ||
|  | 
 | ||
|  | type GetSecretBySecretIdLogic struct { | ||
|  | 	ctx    context.Context | ||
|  | 	svcCtx *svc.ServiceContext | ||
|  | 	logx.Logger | ||
|  | } | ||
|  | 
 | ||
|  | func NewGetSecretBySecretIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSecretBySecretIdLogic { | ||
|  | 	return &GetSecretBySecretIdLogic{ | ||
|  | 		ctx:    ctx, | ||
|  | 		svcCtx: svcCtx, | ||
|  | 		Logger: logx.WithContext(ctx), | ||
|  | 	} | ||
|  | } | ||
|  | 
 | ||
|  | func (l *GetSecretBySecretIdLogic) GetSecretBySecretId(in *sentinel.GetSecretBySecretIdRequest) (*sentinel.Secret, error) { | ||
|  | 	secret, err := l.svcCtx.SecretsModel.FindOneBySecretId(l.ctx, in.SecretId) | ||
|  | 	if err != nil { | ||
|  | 		if errors.Is(err, model.ErrNotFound) { | ||
|  | 			return nil, nil | ||
|  | 		} else { | ||
|  | 			return nil, err | ||
|  | 
 | ||
|  | 		} | ||
|  | 	} | ||
|  | 	return &sentinel.Secret{ | ||
|  | 		Id:       secret.Id, | ||
|  | 		UserId:   secret.UserId, | ||
|  | 		SecretId: secret.SecretId, | ||
|  | 		AesKey:   secret.AesKey, | ||
|  | 	}, nil | ||
|  | } |