Movatterモバイル変換


[0]ホーム

URL:


setting

package
v1.92.3Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2025 License:BSD-3-ClauseImports:21Imported by:6

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package setting contains types for defining and representing policy settings.It facilitates the registration of setting definitions usingRegister andRegisterDefinition,and the retrieval of registered setting definitions viaDefinitions andDefinitionOf.This package is intended for use primarily within the syspolicy package hierarchy.

Index

Constants

View Source
const (// DeviceSetting indicates a policy setting that applies to a device, regardless of// which OS user or Tailscale profile is currently active, if any.// It can only be configured at a [DeviceScope].DeviceSettingScope =iota// ProfileSetting indicates a policy setting that applies to a Tailscale profile.// It can only be configured for a specific profile or at a [DeviceScope],// in which case it applies to all profiles on the device.ProfileSetting// UserSetting indicates a policy setting that applies to users.// It can be configured for a user, profile, or the entire device.UserSetting// NumScopes is the number of possible [Scope] values.NumScopesint =iota// must be the last value in the const block.)

Variables

View Source
var (// ErrNotConfigured is returned when the requested policy setting is not configured.ErrNotConfigured =errors.New("not configured")// ErrTypeMismatch is returned when there's a type mismatch between the actual type// of the setting value and the expected type.ErrTypeMismatch =errors.New("type mismatch")// ErrNoSuchKey is returned by [DefinitionOf] when no policy setting// has been registered with the specified key.//// Until 2024-08-02, this error was also returned by a [Handler] when the specified// key did not have a value set. While the package maintains compatibility with this// usage of ErrNoSuchKey, it is recommended to return [ErrNotConfigured] from newer// [source.Store] implementations.ErrNoSuchKey =errors.New("no such key"))
View Source
var (// DeviceScope indicates a scope containing device-global policies.DeviceScope =PolicyScope{/* contains filtered or unexported fields */}// CurrentProfileScope indicates a scope containing policies that apply to the// currently active Tailscale profile.CurrentProfileScope =PolicyScope{/* contains filtered or unexported fields */}// CurrentUserScope indicates a scope containing policies that apply to the// current user, for whatever that means on the current platform and// in the current application context.CurrentUserScope =PolicyScope{/* contains filtered or unexported fields */})

Functions

funcRegister

func Register(kpkey.Key, sScope, tType, platforms ...string)

Register registers a policy setting with the specified key, scope, value type,and an optional list of supported platforms. All policy settings must beregistered before any of them can be used. Register panics if called afterinvoking any functions that use the registered policy definitions. Thisincludes callingDefinitions orDefinitionOf directly, or reading anypolicy settings via syspolicy.

funcRegisterDefinition

func RegisterDefinition(d *Definition)

RegisterDefinition is likeRegister, but accepts aDefinition.

funcSetDefaultScope

func SetDefaultScope(scopePolicyScope)bool

SetDefaultScope attempts to set the specified scope as the default scopeto be used by a program when querying policy settings.It fails and returns false if called more than once, or if theDefaultScopehas already been used.

funcSetDefinitionsForTest

func SetDefinitionsForTest(tbtestenv.TB, ds ...*Definition)error

SetDefinitionsForTest allows to register the specified setting definitionsfor the test duration. It is not concurrency-safe, but unlikeRegister,it does not panic and can be called anytime.It returns an error if ds contains two different settings with the same [Key].

Types

typeDefinition

type Definition struct {// contains filtered or unexported fields}

Definition defines policy key, scope and value type.

funcDefinitionOf

func DefinitionOf(kpkey.Key) (*Definition,error)

DefinitionOf returns a setting definition by key,orErrNoSuchKey if the specified key does not exist,or an error if there are conflicting policy definitions.

funcDefinitions

func Definitions() ([]*Definition,error)

Definitions returns all registered setting definitions,or an error if different policies were registered under the same name.

funcNewDefinition

func NewDefinition(kpkey.Key, sScope, tType, platforms ...string) *Definition

NewDefinition returns a newDefinition with the specifiedkey, scope, type and supported platforms (seePlatformList).

func (*Definition)Equal

func (d *Definition) Equal(d2 *Definition)bool

Equal reports whether d and d2 have the same key, type and scope.It does not check whether both s and s2 are supported on the same platforms.

func (*Definition)IsSupported

func (d *Definition) IsSupported()bool

IsSupported reports whether the policy setting is supported on the current OS.

func (*Definition)Key

func (d *Definition) Key()pkey.Key

Key returns a policy setting's identifier.

func (*Definition)Scope

func (d *Definition) Scope()Scope

Scope reports the broadestScope the policy setting may apply to.

func (*Definition)String

func (d *Definition) String()string

String implementsfmt.Stringer.

func (*Definition)SupportedPlatforms

func (d *Definition) SupportedPlatforms()PlatformList

SupportedPlatforms reports platforms on which the policy setting is supported.An emptyPlatformList indicates that s is available on all platforms.

func (*Definition)Type

func (d *Definition) Type()Type

Type reports the underlying value type of the policy setting.

typeDefinitionMap

type DefinitionMap map[pkey.Key]*Definition

DefinitionMap is a map of settingDefinition by [Key].

funcDefinitionMapOf

func DefinitionMapOf(settings []*Definition) (DefinitionMap,error)

DefinitionMapOf returns aDefinitionMap with the specified settings,or an error if any settings have the same key but different type or scope.

typeErrorText

type ErrorTextstring

ErrorText represents an error that occurs when reading or parsing a policy setting.This includes errors due to permissions issues, value type and format mismatches,and other platform- or source-specific errors. It does not includeErrNotConfigured andErrNoSuchKey, as those correspond to unconfiguredpolicy settings rather than settings that cannot be read or parseddue to an error.

ErrorText is used to marshal errors when a policy setting is sent over the wire,allowing the error to be logged or displayed. It does not preserve thetype information of the underlying error.

funcMaybeErrorTextadded inv1.74.0

func MaybeErrorText(errerror) *ErrorText

MaybeErrorText returns anErrorText with the text of the specified error,or nil if err is nil,ErrNotConfigured, orErrNoSuchKey.

funcNewErrorText

func NewErrorText(textstring) *ErrorText

NewErrorText returns aErrorText with the specified error message.

func (ErrorText)Error

func (eErrorText) Error()string

Error implements error.

func (ErrorText)MarshalText

func (eErrorText) MarshalText() (text []byte, errerror)

MarshalText implementsencoding.TextMarshaler.

func (*ErrorText)UnmarshalText

func (e *ErrorText) UnmarshalText(text []byte)error

UnmarshalText implementsencoding.TextUnmarshaler.

typeOrigin

type Origin struct {// contains filtered or unexported fields}

Origin describes where a policy or a policy setting is configured.

funcNewNamedOrigin

func NewNamedOrigin(namestring, scopePolicyScope) *Origin

NewNamedOrigin returns a newOrigin with the specified scope and name.

funcNewOrigin

func NewOrigin(scopePolicyScope) *Origin

NewOrigin returns a newOrigin with the specified scope.

func (Origin)MarshalJSON

func (sOrigin) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (Origin)MarshalJSONToadded inv1.82.0

func (sOrigin) MarshalJSONTo(out *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (Origin)Name

func (sOrigin) Name()string

Name returns the name of the policy source where the setting is configured,or "" if not available.

func (Origin)Scope

func (sOrigin) Scope()PolicyScope

Scope reports the policyPolicyScope where the setting is configured.

func (Origin)String

func (sOrigin) String()string

String implementsfmt.Stringer.

func (*Origin)UnmarshalJSON

func (s *Origin) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*Origin)UnmarshalJSONFromadded inv1.82.0

func (s *Origin) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.

typePlatformList

type PlatformList []string

PlatformList is a list of OSes.An empty list indicates that all possible platforms are supported.

func (PlatformList)Has

func (lsPlatformList) Has(targetstring)bool

Has reports whether l contains the target platform.

func (PlatformList)HasCurrent

func (lsPlatformList) HasCurrent()bool

HasCurrent is like Has, but for the current platform.

typePolicyScope

type PolicyScope struct {// contains filtered or unexported fields}

PolicyScope is a management scope.

funcDefaultScope

func DefaultScope()PolicyScope

DefaultScope returns the defaultPolicyScope to be used by a programwhen querying policy settings.It returnsDeviceScope, unless explicitly changed withSetDefaultScope.

funcUserScopeOf

func UserScopeOf(uidstring)PolicyScope

UserScopeOf returns a policyPolicyScope of the user with the specified id.

func (PolicyScope)Contains

func (sPolicyScope) Contains(s2PolicyScope)bool

Contains reports whether policy settings that apply to s also apply to s2.For example, policy settings that apply to theDeviceScope also apply totheCurrentUserScope.

func (PolicyScope)IsApplicableSetting

func (sPolicyScope) IsApplicableSetting(setting *Definition)bool

IsApplicableSetting reports whether the specified setting applies toand can be retrieved for this scope. Policy settings are applicableto their own scopes as well as more specific scopes. For example,device settings are applicable to device, profile and user scopes,but user settings are only applicable to user scopes.For instance, a menu visibility setting is inherently a user settingand only makes sense in the context of a specific user.

func (PolicyScope)IsConfigurableSetting

func (sPolicyScope) IsConfigurableSetting(setting *Definition)bool

IsConfigurableSetting reports whether the specified setting can be configuredby a policy at this scope. Policy settings are configurable at their own scopesas well as broader scopes. For example, [UserSetting]s are configurable inuser, profile, and device scopes, but [DeviceSetting]s are only configurablein theDeviceScope. For instance, the InstallUpdates policy settingcan only be configured in the device scope, as it controls whether updateswill be installed automatically on the device, rather than for specific users.

func (PolicyScope)Kind

func (sPolicyScope) Kind()Scope

Kind reports the scope kind of s.

func (PolicyScope)MarshalText

func (sPolicyScope) MarshalText() ([]byte,error)

MarshalText implementsencoding.TextMarshaler.

func (PolicyScope)StrictlyContains

func (sPolicyScope) StrictlyContains(s2PolicyScope)bool

StrictlyContains is likePolicyScope.Contains, but returns falsewhen s and s2 is the same scope.

func (PolicyScope)String

func (sPolicyScope) String()string

String implementsfmt.Stringer.

func (*PolicyScope)UnmarshalText

func (s *PolicyScope) UnmarshalText(b []byte)error

MarshalText implementsencoding.TextUnmarshaler.

typeRawItem

type RawItem struct {// contains filtered or unexported fields}

RawItem contains a raw policy setting value as read from a policy store, or anerror if the requested setting could not be read from the store. As a specialcase, it may also hold a value of the [Visibility], [PreferenceOption],ortime.Duration types. While the policy store interface does not supportthese types natively, and the values of these types have to be unmarshalledor converted from strings, these setting types predate the typed policyhierarchies, and must be supported at this layer.

funcRawItemOf

func RawItemOf(valueany)RawItem

RawItemOf returns aRawItem with the specified value.

funcRawItemWith

func RawItemWith(valueany, err *ErrorText, origin *Origin)RawItem

RawItemWith returns aRawItem with the specified value, error and origin.

func (RawItem)Error

func (iRawItem) Error()error

Error returns the error that occurred when reading the policy setting,or nil if no error occurred.

func (RawItem)MarshalJSONadded inv1.78.0

func (iRawItem) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (RawItem)MarshalJSONToadded inv1.82.0

func (iRawItem) MarshalJSONTo(out *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (RawItem)Origin

func (iRawItem) Origin() *Origin

Origin returns an optionalOrigin indicating where the policy setting isconfigured.

func (RawItem)String

func (iRawItem) String()string

String implementsfmt.Stringer.

func (*RawItem)UnmarshalJSONadded inv1.78.0

func (i *RawItem) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*RawItem)UnmarshalJSONFromadded inv1.82.0

func (i *RawItem) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.

func (RawItem)Value

func (iRawItem) Value()any

Value returns the value of the policy setting, or nil if the policy settingis not configured, or an error occurred while reading it.

typeRawValueadded inv1.78.0

type RawValue struct {opt.Value[any]}

RawValue represents a raw policy setting value read from a policy store.It is JSON-marshallable and facilitates unmarshalling of JSON valuesinto corresponding policy setting types, with special handling for JSON numbers(unmarshalled as float64) and JSON string arrays (unmarshalled as []string).See alsoRawValue.UnmarshalJSONFrom.

funcRawValueOfadded inv1.78.0

func RawValueOf[TRawValueType](v T)RawValue

RawValueOf returns a newRawValue holding the specified value.

func (RawValue)MarshalJSONadded inv1.78.0

func (vRawValue) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (RawValue)MarshalJSONToadded inv1.82.0

func (vRawValue) MarshalJSONTo(out *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (*RawValue)UnmarshalJSONadded inv1.78.0

func (v *RawValue) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*RawValue)UnmarshalJSONFromadded inv1.82.0

func (v *RawValue) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom by attempting to unmarshala JSON value as one of the supported policy setting value types (bool, string, uint64, or []string),based on the JSON value type. It fails if the JSON value is an object, if it's a JSON number thatcannot be represented as a uint64, or if a JSON array contains anything other than strings.

typeRawValueTypeadded inv1.78.0

type RawValueType interface {bool |uint64 |string | []string}

RawValueType is a constraint that permits raw setting value types.

typeRawValuesadded inv1.78.0

type RawValues map[pkey.Key]RawValue

RawValues is a map of keyed setting values that can be read from a JSON.

typeScope

type Scopeint8

Scope indicates the broadest scope at which a policy setting may apply,and the narrowest scope at which it may be configured.

func (Scope)MarshalText

func (sScope) MarshalText() (text []byte, errerror)

MarshalText implementsencoding.TextMarshaler.

func (Scope)String

func (sScope) String()string

String implementsfmt.Stringer.

func (*Scope)UnmarshalText

func (s *Scope) UnmarshalText(text []byte)error

UnmarshalText implementsencoding.TextUnmarshaler.

typeSnapshot

type Snapshot struct {// contains filtered or unexported fields}

Snapshot is an immutable collection of ([Key],RawItem) pairs, representinga set of policy settings applied at a specific moment in time.A nil pointer toSnapshot is valid.

funcMergeSnapshots

func MergeSnapshots(snapshot1, snapshot2 *Snapshot) *Snapshot

MergeSnapshots returns aSnapshot that contains all [RawItem]sfrom snapshot1 and snapshot2 and theSummary with the narrowerPolicyScope.If there's a conflict between policy settings in the two snapshots,the policy settings from the snapshot with the broader scope take precedence.In other words, policy settings configured for theDeviceScope winover policy settings configured for a user scope.

funcNewSnapshot

func NewSnapshot(items map[pkey.Key]RawItem, opts ...SummaryOption) *Snapshot

NewSnapshot returns a newSnapshot with the specified items and options.

func (*Snapshot)All

func (s *Snapshot) All()iter.Seq2[pkey.Key,RawItem]

All returns an iterator over policy settings in s. The iteration order is notspecified and is not guaranteed to be the same from one call to the next.

func (*Snapshot)Equal

func (s *Snapshot) Equal(s2 *Snapshot)bool

Equal reports whether s and s2 are equal.

func (*Snapshot)EqualItems

func (s *Snapshot) EqualItems(s2 *Snapshot)bool

EqualItems reports whether items in s and s2 are equal.

func (*Snapshot)Get

func (s *Snapshot) Get(kpkey.Key)any

Get returns the value of the policy setting with the specified keyor nil if it is not configured or has an error.

func (*Snapshot)GetErr

func (s *Snapshot) GetErr(kpkey.Key) (any,error)

GetErr returns the value of the policy setting with the specified key,ErrNotConfigured if it is not configured, or an error returned bythe policy Store if the policy setting could not be read.

func (*Snapshot)GetSetting

func (s *Snapshot) GetSetting(kpkey.Key) (settingRawItem, okbool)

GetSetting returns the untyped policy setting with the specified key and trueif a policy setting with such key has been configured;otherwise, it returns zero, false.

func (*Snapshot)Keys

func (s *Snapshot) Keys()iter.Seq[pkey.Key]

Keys return an iterator over keys in s. The iteration order is not specifiedand is not guaranteed to be the same from one call to the next.

func (*Snapshot)Len

func (s *Snapshot) Len()int

Len reports the number of [RawItem]s in s.

func (*Snapshot)MarshalJSONadded inv1.78.0

func (s *Snapshot) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (*Snapshot)MarshalJSONToadded inv1.82.0

func (s *Snapshot) MarshalJSONTo(out *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (*Snapshot)String

func (s *Snapshot) String()string

String implementsfmt.Stringer

func (*Snapshot)Summary

func (s *Snapshot) Summary()Summary

Summary returns information about s as a whole rather than about specific [RawItem]s in it.

func (*Snapshot)UnmarshalJSONadded inv1.78.0

func (s *Snapshot) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*Snapshot)UnmarshalJSONFromadded inv1.82.0

func (s *Snapshot) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.

typeSummary

type Summary struct {// contains filtered or unexported fields}

Summary is an immutablePolicyScope andOrigin.

funcSummaryWith

func SummaryWith(opts ...SummaryOption)Summary

SummaryWith returns aSummary with the specified options.

func (Summary)IsEmpty

func (sSummary) IsEmpty()bool

IsEmpty reports whether s is empty.

func (Summary)MarshalJSON

func (sSummary) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (Summary)MarshalJSONToadded inv1.82.0

func (sSummary) MarshalJSONTo(out *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (Summary)Origin

func (sSummary) Origin()opt.Value[Origin]

Origin reports theOrigin in s.

func (Summary)Scope

func (sSummary) Scope()opt.Value[PolicyScope]

Scope reports thePolicyScope in s.

func (Summary)String

func (sSummary) String()string

String implementsfmt.Stringer.

func (*Summary)UnmarshalJSON

func (s *Summary) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*Summary)UnmarshalJSONFromadded inv1.82.0

func (s *Summary) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.

typeSummaryOption

type SummaryOption interface {// contains filtered or unexported methods}

SummaryOption is an option that configuresSummaryThe following are allowed options:

typeType

type Typeint

Type is a policy setting value type.Except forInvalidValue, which represents an invalid policy setting type,andPreferenceOptionValue,VisibilityValue, andDurationValue,which have special handling due to their legacy status in the package,SettingTypes represent the raw value types readable from policy stores.

const (// InvalidValue indicates an invalid policy setting value type.InvalidValueType =iota// BooleanValue indicates a policy setting whose underlying type is a bool.BooleanValue// IntegerValue indicates a policy setting whose underlying type is a uint64.IntegerValue// StringValue indicates a policy setting whose underlying type is a string.StringValue// StringListValue indicates a policy setting whose underlying type is a []string.StringListValue// PreferenceOptionValue indicates a three-state policy setting whose// underlying type is a string, but the actual value is a [PreferenceOption].PreferenceOptionValue// VisibilityValue indicates a two-state boolean-like policy setting whose// underlying type is a string, but the actual value is a [Visibility].VisibilityValue// DurationValue indicates an interval/period/duration policy setting whose// underlying type is a string, but the actual value is a [time.Duration].DurationValue)

func (Type)String

func (tType) String()string

String returns a string representation of t.

typeValueType

ValueType is a constraint that allows Go types corresponding toType.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp