syspolicy.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build !ts_omit_syspolicy
  4. package local
  5. import (
  6. "context"
  7. "net/http"
  8. "tailscale.com/util/syspolicy/setting"
  9. )
  10. // GetEffectivePolicy returns the effective policy for the specified scope.
  11. func (lc *Client) GetEffectivePolicy(ctx context.Context, scope setting.PolicyScope) (*setting.Snapshot, error) {
  12. scopeID, err := scope.MarshalText()
  13. if err != nil {
  14. return nil, err
  15. }
  16. body, err := lc.get200(ctx, "/localapi/v0/policy/"+string(scopeID))
  17. if err != nil {
  18. return nil, err
  19. }
  20. return decodeJSON[*setting.Snapshot](body)
  21. }
  22. // ReloadEffectivePolicy reloads the effective policy for the specified scope
  23. // by reading and merging policy settings from all applicable policy sources.
  24. func (lc *Client) ReloadEffectivePolicy(ctx context.Context, scope setting.PolicyScope) (*setting.Snapshot, error) {
  25. scopeID, err := scope.MarshalText()
  26. if err != nil {
  27. return nil, err
  28. }
  29. body, err := lc.send(ctx, "POST", "/localapi/v0/policy/"+string(scopeID), 200, http.NoBody)
  30. if err != nil {
  31. return nil, err
  32. }
  33. return decodeJSON[*setting.Snapshot](body)
  34. }