| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- // Code scaffolded by goctl. Safe to edit.
- // goctl 1.10.2
- package application
- import (
- "context"
- "errors"
- "udeServer/internal/apierr"
- "udeServer/internal/log"
- "udeServer/internal/model"
- "udeServer/internal/svc"
- "udeServer/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type DistributeApiSecretLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- // 下发应用凭证密钥
- func NewDistributeApiSecretLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DistributeApiSecretLogic {
- return &DistributeApiSecretLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *DistributeApiSecretLogic) DistributeApiSecret(req *types.ApplicationCredentialsDistributeReq) (*types.ApplicationCredentialsDistributeResp, error) {
- if err := checkId(req.Id); err != nil {
- return nil, err
- }
- cred, err := l.svcCtx.ApplicationCredModel.FindOne(l.ctx, req.Id)
- if errors.Is(err, model.ErrNotFound) {
- return nil, apierr.NotFound("application credential", req.Id)
- }
- if err != nil {
- log.RecordError(l.ctx, err)
- return nil, apierr.New(500, "查询应用凭证失败")
- }
- // 仅此接口返回密钥原文
- return &types.ApplicationCredentialsDistributeResp{ApiSecret: cred.ApiSecret}, nil
- }
|