mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-07 05:34:38 +08:00
fixed dns and keys
This commit is contained in:
parent
8ef885ca1d
commit
1a16e5ad25
3 changed files with 28 additions and 14 deletions
|
@ -20,8 +20,6 @@ import (
|
|||
|
||||
const ALL_NETWORK_ACCESS = "THIS_USER_HAS_ALL"
|
||||
const NO_NETWORKS_PRESENT = "THIS_USER_HAS_NONE"
|
||||
const PLACEHOLDER_KEY_TEXT = "ACCESS_KEY"
|
||||
const PLACEHOLDER_TOKEN_TEXT = "ACCESS_TOKEN"
|
||||
|
||||
func networkHandlers(r *mux.Router) {
|
||||
r.HandleFunc("/api/networks", securityCheck(false, http.HandlerFunc(getNetworks))).Methods("GET")
|
||||
|
@ -121,7 +119,11 @@ func authenticateMaster(tokenString string) bool {
|
|||
|
||||
//Consider a more secure way of setting master key
|
||||
func authenticateDNSToken(tokenString string) bool {
|
||||
return tokenString == servercfg.GetDNSKey()
|
||||
tokens := strings.Split(tokenString, " ")
|
||||
if len(tokens) < 2 {
|
||||
return false
|
||||
}
|
||||
return tokens[1] == servercfg.GetDNSKey()
|
||||
}
|
||||
|
||||
//simple get all networks function
|
||||
|
@ -150,6 +152,12 @@ func getNetworks(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if !servercfg.IsDisplayKeys() {
|
||||
for i, net := range allnetworks {
|
||||
net.AccessKeys = logic.RemoveKeySensitiveInfo(net.AccessKeys)
|
||||
allnetworks[i] = net
|
||||
}
|
||||
}
|
||||
functions.PrintUserLog(r.Header.Get("user"), "fetched networks.", 2)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(allnetworks)
|
||||
|
@ -187,6 +195,9 @@ func getNetwork(w http.ResponseWriter, r *http.Request) {
|
|||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
if !servercfg.IsDisplayKeys() {
|
||||
network.AccessKeys = logic.RemoveKeySensitiveInfo(network.AccessKeys)
|
||||
}
|
||||
functions.PrintUserLog(r.Header.Get("user"), "fetched network "+netname, 2)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(network)
|
||||
|
@ -577,7 +588,7 @@ func getAccessKeys(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if !servercfg.IsDisplayKeys() {
|
||||
keys = RemoveKeySensitiveInfo(keys)
|
||||
keys = logic.RemoveKeySensitiveInfo(keys)
|
||||
}
|
||||
functions.PrintUserLog(r.Header.Get("user"), "fetched access keys on network "+network, 2)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
@ -640,13 +651,3 @@ func DeleteKey(keyname, netname string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveKeySensitiveInfo(keys []models.AccessKey) []models.AccessKey {
|
||||
var returnKeys []models.AccessKey
|
||||
for _, key := range keys {
|
||||
key.Value = PLACEHOLDER_KEY_TEXT
|
||||
key.AccessString = PLACEHOLDER_TOKEN_TEXT
|
||||
returnKeys = append(returnKeys, key)
|
||||
}
|
||||
return returnKeys
|
||||
}
|
||||
|
|
|
@ -60,3 +60,13 @@ func IsKeyValid(networkname string, keyvalue string) bool {
|
|||
}
|
||||
return isvalid
|
||||
}
|
||||
|
||||
func RemoveKeySensitiveInfo(keys []models.AccessKey) []models.AccessKey {
|
||||
var returnKeys []models.AccessKey
|
||||
for _, key := range keys {
|
||||
key.Value = models.PLACEHOLDER_KEY_TEXT
|
||||
key.AccessString = models.PLACEHOLDER_TOKEN_TEXT
|
||||
returnKeys = append(returnKeys, key)
|
||||
}
|
||||
return returnKeys
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package models
|
|||
|
||||
import jwt "github.com/golang-jwt/jwt/v4"
|
||||
|
||||
const PLACEHOLDER_KEY_TEXT = "ACCESS_KEY"
|
||||
const PLACEHOLDER_TOKEN_TEXT = "ACCESS_TOKEN"
|
||||
|
||||
// AuthParams - struct for auth params
|
||||
type AuthParams struct {
|
||||
MacAddress string `json:"macaddress"`
|
||||
|
|
Loading…
Add table
Reference in a new issue