first commit
This commit is contained in:
46
apps/sentinel/internal/logic/secret/createsecretlogic.go
Normal file
46
apps/sentinel/internal/logic/secret/createsecretlogic.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package secretlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateSecretLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateSecretLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSecretLogic {
|
||||
return &CreateSecretLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// Secret methods
|
||||
func (l *CreateSecretLogic) CreateSecret(in *sentinel.CreateSecretRequest) (*sentinel.Secret, error) {
|
||||
secretId, err := crypto.GenerateSecretId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aesKey, err := crypto.GenerateSecretKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = l.svcCtx.SecretsModel.Insert(l.ctx, &model.Secrets{
|
||||
UserId: in.UserId,
|
||||
SecretId: secretId,
|
||||
AesKey: aesKey,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &sentinel.Secret{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user