mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-13 16:44:52 +08:00
make sure auth secret is set only once
This commit is contained in:
parent
825caf4b60
commit
ba33ed02aa
2 changed files with 15 additions and 4 deletions
|
@ -32,7 +32,6 @@ const (
|
|||
github_provider_name = "github"
|
||||
oidc_provider_name = "oidc"
|
||||
verify_user = "verifyuser"
|
||||
auth_key = "netmaker_auth"
|
||||
user_signin_length = 16
|
||||
node_signin_length = 64
|
||||
headless_signin_length = 32
|
||||
|
@ -281,7 +280,7 @@ func fetchPassValue(newValue string) (string, error) {
|
|||
Value string `json:"value" bson:"value"`
|
||||
}
|
||||
newValueHolder := valueHolder{}
|
||||
var currentValue, err = logic.FetchAuthSecret(auth_key)
|
||||
var currentValue, err = logic.FetchAuthSecret()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ import (
|
|||
"github.com/gravitl/netmaker/models"
|
||||
)
|
||||
|
||||
const (
|
||||
auth_key = "netmaker_auth"
|
||||
)
|
||||
|
||||
// HasSuperAdmin - checks if server has an superadmin/owner
|
||||
func HasSuperAdmin() (bool, error) {
|
||||
|
||||
|
@ -289,6 +293,14 @@ func SetAuthSecret(key, secret string) error {
|
|||
type valueHolder struct {
|
||||
Value string `json:"value" bson:"value"`
|
||||
}
|
||||
record, err := FetchAuthSecret()
|
||||
if err == nil {
|
||||
v := valueHolder{}
|
||||
json.Unmarshal([]byte(record), &v)
|
||||
if v.Value != "" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
var b64NewValue = base64.StdEncoding.EncodeToString([]byte(secret))
|
||||
newValueHolder := valueHolder{
|
||||
Value: b64NewValue,
|
||||
|
@ -298,8 +310,8 @@ func SetAuthSecret(key, secret string) error {
|
|||
}
|
||||
|
||||
// FetchAuthSecret - manages secrets for oauth
|
||||
func FetchAuthSecret(key string) (string, error) {
|
||||
var record, err = database.FetchRecord(database.GENERATED_TABLE_NAME, key)
|
||||
func FetchAuthSecret() (string, error) {
|
||||
var record, err = database.FetchRecord(database.GENERATED_TABLE_NAME, auth_key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue