mirror of
https://github.com/tailscale/tailscale.git
synced 2025-09-21 05:31:36 +02:00
Fixes #16998 Updates #12614 Change-Id: Idf2b1657898111df4be31f356091b2376d0d7f0b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !ts_omit_syspolicy
|
|
|
|
package local
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"tailscale.com/util/syspolicy/setting"
|
|
)
|
|
|
|
// GetEffectivePolicy returns the effective policy for the specified scope.
|
|
func (lc *Client) GetEffectivePolicy(ctx context.Context, scope setting.PolicyScope) (*setting.Snapshot, error) {
|
|
scopeID, err := scope.MarshalText()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
body, err := lc.get200(ctx, "/localapi/v0/policy/"+string(scopeID))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return decodeJSON[*setting.Snapshot](body)
|
|
}
|
|
|
|
// ReloadEffectivePolicy reloads the effective policy for the specified scope
|
|
// by reading and merging policy settings from all applicable policy sources.
|
|
func (lc *Client) ReloadEffectivePolicy(ctx context.Context, scope setting.PolicyScope) (*setting.Snapshot, error) {
|
|
scopeID, err := scope.MarshalText()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
body, err := lc.send(ctx, "POST", "/localapi/v0/policy/"+string(scopeID), 200, http.NoBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return decodeJSON[*setting.Snapshot](body)
|
|
}
|