mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-27 05:08:11 +08:00
NET-2077: Add support for Feature Flags. (#3528)
* feat(go): add support for feature flags; * feat(go): store feature flags in code; * feat(go): report base domain on license validation; * feat(go): remove nm base domain required binding; * feat(go): add a flag for oauth support;
This commit is contained in:
@@ -56,6 +56,7 @@ func serverHandlers(r *mux.Router) {
|
|||||||
Methods(http.MethodPost)
|
Methods(http.MethodPost)
|
||||||
r.HandleFunc("/api/server/mem_profile", logic.SecurityCheck(false, http.HandlerFunc(memProfile))).
|
r.HandleFunc("/api/server/mem_profile", logic.SecurityCheck(false, http.HandlerFunc(memProfile))).
|
||||||
Methods(http.MethodPost)
|
Methods(http.MethodPost)
|
||||||
|
r.HandleFunc("/api/server/feature_flags", getFeatureFlags).Methods(http.MethodGet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cpuProfile(w http.ResponseWriter, r *http.Request) {
|
func cpuProfile(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -325,3 +326,12 @@ func reInit(curr, new models.ServerSettings, force bool) {
|
|||||||
go mq.PublishPeerUpdate(false)
|
go mq.PublishPeerUpdate(false)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Summary Get feature flags for this server.
|
||||||
|
// @Router /api/server/feature_flags [get]
|
||||||
|
// @Tags Server
|
||||||
|
// @Security oauth2
|
||||||
|
// @Success 200 {object} config.ServerSettings
|
||||||
|
func getFeatureFlags(w http.ResponseWriter, r *http.Request) {
|
||||||
|
logic.ReturnSuccessResponseWithJson(w, r, logic.GetFeatureFlags(), "")
|
||||||
|
}
|
||||||
|
@@ -1,7 +1,12 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
|
import "github.com/gravitl/netmaker/models"
|
||||||
|
|
||||||
// EnterpriseCheckFuncs - can be set to run functions for EE
|
// EnterpriseCheckFuncs - can be set to run functions for EE
|
||||||
var EnterpriseCheckFuncs []func()
|
var EnterpriseCheckFuncs []func()
|
||||||
|
var GetFeatureFlags = func() models.FeatureFlags {
|
||||||
|
return models.FeatureFlags{}
|
||||||
|
}
|
||||||
|
|
||||||
// == Join, Checkin, and Leave for Server ==
|
// == Join, Checkin, and Leave for Server ==
|
||||||
|
|
||||||
|
@@ -16,6 +16,13 @@ const (
|
|||||||
PLACEHOLDER_TOKEN_TEXT = "ACCESS_TOKEN"
|
PLACEHOLDER_TOKEN_TEXT = "ACCESS_TOKEN"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type FeatureFlags struct {
|
||||||
|
EnableNetworkActivity bool `json:"enable_network_activity"`
|
||||||
|
EnableOAuth bool `json:"enable_oauth"`
|
||||||
|
EnableIDPIntegration bool `json:"enable_idp_integration"`
|
||||||
|
AllowMultiServerLicense bool `json:"allow_multi_server_license"`
|
||||||
|
}
|
||||||
|
|
||||||
// AuthParams - struct for auth params
|
// AuthParams - struct for auth params
|
||||||
type AuthParams struct {
|
type AuthParams struct {
|
||||||
MacAddress string `json:"macaddress"`
|
MacAddress string `json:"macaddress"`
|
||||||
|
@@ -155,7 +155,7 @@ func InitPro() {
|
|||||||
logic.GetFwRulesForNodeAndPeerOnGw = proLogic.GetFwRulesForNodeAndPeerOnGw
|
logic.GetFwRulesForNodeAndPeerOnGw = proLogic.GetFwRulesForNodeAndPeerOnGw
|
||||||
logic.GetFwRulesForUserNodesOnGw = proLogic.GetFwRulesForUserNodesOnGw
|
logic.GetFwRulesForUserNodesOnGw = proLogic.GetFwRulesForUserNodesOnGw
|
||||||
logic.GetHostLocInfo = proLogic.GetHostLocInfo
|
logic.GetHostLocInfo = proLogic.GetHostLocInfo
|
||||||
|
logic.GetFeatureFlags = proLogic.GetFeatureFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrieveProLogo() string {
|
func retrieveProLogo() string {
|
||||||
|
@@ -135,6 +135,8 @@ func ValidateLicense() (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proLogic.SetFeatureFlags(licenseResponse.FeatureFlags)
|
||||||
|
|
||||||
slog.Info("License validation succeeded!")
|
slog.Info("License validation succeeded!")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -200,6 +202,7 @@ func validateLicenseKey(encryptedData []byte, publicKey *[32]byte) ([]byte, bool
|
|||||||
LicenseKey: servercfg.GetLicenseKey(),
|
LicenseKey: servercfg.GetLicenseKey(),
|
||||||
NmServerPubKey: base64encode(publicKeyBytes),
|
NmServerPubKey: base64encode(publicKeyBytes),
|
||||||
EncryptedPart: base64encode(encryptedData),
|
EncryptedPart: base64encode(encryptedData),
|
||||||
|
NmBaseDomain: servercfg.GetNmBaseDomain(),
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBody, err := json.Marshal(msg)
|
requestBody, err := json.Marshal(msg)
|
||||||
|
13
pro/logic/server.go
Normal file
13
pro/logic/server.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import "github.com/gravitl/netmaker/models"
|
||||||
|
|
||||||
|
var featureFlagsCache models.FeatureFlags
|
||||||
|
|
||||||
|
func SetFeatureFlags(featureFlags models.FeatureFlags) {
|
||||||
|
featureFlagsCache = featureFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFeatureFlags() models.FeatureFlags {
|
||||||
|
return featureFlagsCache
|
||||||
|
}
|
@@ -5,6 +5,7 @@ package pro
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/gravitl/netmaker/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -32,8 +33,9 @@ type LicenseKey struct {
|
|||||||
|
|
||||||
// ValidatedLicense - the validated license struct
|
// ValidatedLicense - the validated license struct
|
||||||
type ValidatedLicense struct {
|
type ValidatedLicense struct {
|
||||||
LicenseValue string `json:"license_value" binding:"required"` // license that validation is being requested for
|
LicenseValue string `json:"license_value" binding:"required"` // license that validation is being requested for
|
||||||
EncryptedLicense string `json:"encrypted_license" binding:"required"` // to be decrypted by Netmaker using Netmaker server's private key
|
EncryptedLicense string `json:"encrypted_license" binding:"required"` // to be decrypted by Netmaker using Netmaker server's private key
|
||||||
|
FeatureFlags models.FeatureFlags `json:"feature_flags" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LicenseSecret - the encrypted struct for sending user-id
|
// LicenseSecret - the encrypted struct for sending user-id
|
||||||
@@ -74,6 +76,7 @@ type ValidateLicenseRequest struct {
|
|||||||
LicenseKey string `json:"license_key" binding:"required"`
|
LicenseKey string `json:"license_key" binding:"required"`
|
||||||
NmServerPubKey string `json:"nm_server_pub_key" binding:"required"` // Netmaker server public key used to send data back to Netmaker for the Netmaker server to decrypt (eg output from validating license)
|
NmServerPubKey string `json:"nm_server_pub_key" binding:"required"` // Netmaker server public key used to send data back to Netmaker for the Netmaker server to decrypt (eg output from validating license)
|
||||||
EncryptedPart string `json:"secret" binding:"required"`
|
EncryptedPart string `json:"secret" binding:"required"`
|
||||||
|
NmBaseDomain string `json:"nm_base_domain"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type licenseResponseCache struct {
|
type licenseResponseCache struct {
|
||||||
|
Reference in New Issue
Block a user