mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-13 11:53:34 +08:00
30 lines
729 B
Go
30 lines
729 B
Go
|
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||
|
|
|
||
|
|
package keys
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/base64"
|
||
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||
|
|
"github.com/iwind/TeaGo/rands"
|
||
|
|
)
|
||
|
|
|
||
|
|
type GenerateSecretAction struct {
|
||
|
|
actionutils.ParentAction
|
||
|
|
}
|
||
|
|
|
||
|
|
func (this *GenerateSecretAction) RunPost(params struct {
|
||
|
|
SecretType string
|
||
|
|
}) {
|
||
|
|
switch params.SecretType {
|
||
|
|
case dnsconfigs.NSKeySecretTypeClear:
|
||
|
|
this.Data["secret"] = rands.HexString(128)
|
||
|
|
case dnsconfigs.NSKeySecretTypeBase64:
|
||
|
|
this.Data["secret"] = base64.StdEncoding.EncodeToString([]byte(rands.HexString(128)))
|
||
|
|
default:
|
||
|
|
this.Data["secret"] = rands.HexString(128)
|
||
|
|
}
|
||
|
|
|
||
|
|
this.Success()
|
||
|
|
}
|