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:
Vishal Dalwadi
2025-07-27 08:39:17 +05:30
committed by GitHub
parent 461c680099
commit 6367efc882
7 changed files with 44 additions and 3 deletions

View File

@@ -56,6 +56,7 @@ func serverHandlers(r *mux.Router) {
Methods(http.MethodPost)
r.HandleFunc("/api/server/mem_profile", logic.SecurityCheck(false, http.HandlerFunc(memProfile))).
Methods(http.MethodPost)
r.HandleFunc("/api/server/feature_flags", getFeatureFlags).Methods(http.MethodGet)
}
func cpuProfile(w http.ResponseWriter, r *http.Request) {
@@ -325,3 +326,12 @@ func reInit(curr, new models.ServerSettings, force bool) {
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(), "")
}

View File

@@ -1,7 +1,12 @@
package logic
import "github.com/gravitl/netmaker/models"
// EnterpriseCheckFuncs - can be set to run functions for EE
var EnterpriseCheckFuncs []func()
var GetFeatureFlags = func() models.FeatureFlags {
return models.FeatureFlags{}
}
// == Join, Checkin, and Leave for Server ==

View File

@@ -16,6 +16,13 @@ const (
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
type AuthParams struct {
MacAddress string `json:"macaddress"`

View File

@@ -155,7 +155,7 @@ func InitPro() {
logic.GetFwRulesForNodeAndPeerOnGw = proLogic.GetFwRulesForNodeAndPeerOnGw
logic.GetFwRulesForUserNodesOnGw = proLogic.GetFwRulesForUserNodesOnGw
logic.GetHostLocInfo = proLogic.GetHostLocInfo
logic.GetFeatureFlags = proLogic.GetFeatureFlags
}
func retrieveProLogo() string {

View File

@@ -135,6 +135,8 @@ func ValidateLicense() (err error) {
return err
}
proLogic.SetFeatureFlags(licenseResponse.FeatureFlags)
slog.Info("License validation succeeded!")
return nil
}
@@ -200,6 +202,7 @@ func validateLicenseKey(encryptedData []byte, publicKey *[32]byte) ([]byte, bool
LicenseKey: servercfg.GetLicenseKey(),
NmServerPubKey: base64encode(publicKeyBytes),
EncryptedPart: base64encode(encryptedData),
NmBaseDomain: servercfg.GetNmBaseDomain(),
}
requestBody, err := json.Marshal(msg)

13
pro/logic/server.go Normal file
View 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
}

View File

@@ -5,6 +5,7 @@ package pro
import (
"errors"
"github.com/gravitl/netmaker/models"
)
const (
@@ -34,6 +35,7 @@ type LicenseKey struct {
type ValidatedLicense struct {
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
FeatureFlags models.FeatureFlags `json:"feature_flags" binding:"required"`
}
// LicenseSecret - the encrypted struct for sending user-id
@@ -74,6 +76,7 @@ type ValidateLicenseRequest struct {
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)
EncryptedPart string `json:"secret" binding:"required"`
NmBaseDomain string `json:"nm_base_domain"`
}
type licenseResponseCache struct {