//go:build ios package NetBirdSDK import ( "github.com/netbirdio/netbird/client/internal/profilemanager" "github.com/netbirdio/netbird/client/mdm" ) // PolicyFetcher is implemented by the native layer to return the current // managed configuration as a JSON-encoded object string; "" means no MDM // source is present. type PolicyFetcher interface { FetchJSON() string } // SetMDMPolicyFetcher registers the native-provided MDM policy fetcher on // this Client; passing nil disables MDM enforcement. func (c *Client) SetMDMPolicyFetcher(p PolicyFetcher) { c.mdmLoader = loaderFor(p) c.mdmDetector = mdm.NewChangeDetector(c.mdmLoader) } // HasMDMPolicyChanged re-reads the managed configuration and reports whether // it changed since the last observation; call it from the native OS-change // notification and restart the engine only on true. func (c *Client) HasMDMPolicyChanged() bool { if c.mdmDetector == nil { return false } return c.mdmDetector.Changed() } // GetRestrictionsJSON returns the UI enforcement snapshot derived from the // active MDM policy, in the JSON shape shared with the desktop frontend. func (c *Client) GetRestrictionsJSON() (string, error) { return mdm.BuildRestrictions(c.mdmLoader.Load()).JSON() } func (c *Client) applyMDMOverlay(cfg *profilemanager.Config) { if cfg == nil || c.mdmLoader == nil { return } cfg.ApplyMDMPolicy(c.mdmLoader.Load()) } func loaderFor(p PolicyFetcher) *mdm.Loader { if p == nil { return mdm.NewJSONLoader(nil) } return mdm.NewJSONLoader(p.FetchJSON) }