mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
34 lines
918 B
Go
34 lines
918 B
Go
|
|
package services
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||
|
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||
|
|
)
|
||
|
|
|
||
|
|
// ACME认证相关
|
||
|
|
type ACMEAuthenticationService struct {
|
||
|
|
BaseService
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取Key
|
||
|
|
func (this *ACMEAuthenticationService) FindACMEAuthenticationKeyWithToken(ctx context.Context, req *pb.FindACMEAuthenticationKeyWithTokenRequest) (*pb.FindACMEAuthenticationKeyWithTokenResponse, error) {
|
||
|
|
_, err := this.ValidateNode(ctx)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if len(req.Token) == 0 {
|
||
|
|
return nil, errors.New("'token' should not be empty")
|
||
|
|
}
|
||
|
|
|
||
|
|
auth, err := models.SharedACMEAuthenticationDAO.FindAuthWithToken(req.Token)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if auth == nil {
|
||
|
|
return &pb.FindACMEAuthenticationKeyWithTokenResponse{Key: ""}, nil
|
||
|
|
}
|
||
|
|
return &pb.FindACMEAuthenticationKeyWithTokenResponse{Key: auth.Key}, nil
|
||
|
|
}
|