cmd/viewer: add field comments to generated view methods
Extract field comments from AST and include them in generated view methods. Comments are preserved from the original struct fields to provide documentation for the view accessors. Fixes #16958 Signed-off-by: Maisem Ali <3953239+maisem@users.noreply.github.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
80f5a00e76
commit
882b05fff9
@@ -84,10 +84,35 @@ func (v *ResolverView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Addr is the address of the DNS resolver, one of:
|
||||
// - A plain IP address for a "classic" UDP+TCP DNS resolver.
|
||||
// This is the common format as sent by the control plane.
|
||||
// - An IP:port, for tests.
|
||||
// - "https://resolver.com/path" for DNS over HTTPS; currently
|
||||
// as of 2022-09-08 only used for certain well-known resolvers
|
||||
// (see the publicdns package) for which the IP addresses to dial DoH are
|
||||
// known ahead of time, so bootstrap DNS resolution is not required.
|
||||
// - "http://node-address:port/path" for DNS over HTTP over WireGuard. This
|
||||
// is implemented in the PeerAPI for exit nodes and app connectors.
|
||||
// - [TODO] "tls://resolver.com" for DNS over TCP+TLS
|
||||
func (v ResolverView) Addr() string { return v.ж.Addr }
|
||||
|
||||
// BootstrapResolution is an optional suggested resolution for the
|
||||
// DoT/DoH resolver, if the resolver URL does not reference an IP
|
||||
// address directly.
|
||||
// BootstrapResolution may be empty, in which case clients should
|
||||
// look up the DoT/DoH server using their local "classic" DNS
|
||||
// resolver.
|
||||
//
|
||||
// As of 2022-09-08, BootstrapResolution is not yet used.
|
||||
func (v ResolverView) BootstrapResolution() views.Slice[netip.Addr] {
|
||||
return views.SliceOf(v.ж.BootstrapResolution)
|
||||
}
|
||||
|
||||
// UseWithExitNode designates that this resolver should continue to be used when an
|
||||
// exit node is in use. Normally, DNS resolution is delegated to the exit node but
|
||||
// there are situations where it is preferable to still use a Split DNS server and/or
|
||||
// global DNS server instead of the exit node.
|
||||
func (v ResolverView) UseWithExitNode() bool { return v.ж.UseWithExitNode }
|
||||
func (v ResolverView) Equal(v2 ResolverView) bool { return v.ж.Equal(v2.ж) }
|
||||
|
||||
|
||||
@@ -86,11 +86,18 @@ func (v *PersistView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v PersistView) PrivateNodeKey() key.NodePrivate { return v.ж.PrivateNodeKey }
|
||||
func (v PersistView) PrivateNodeKey() key.NodePrivate { return v.ж.PrivateNodeKey }
|
||||
|
||||
// needed to request key rotation
|
||||
func (v PersistView) OldPrivateNodeKey() key.NodePrivate { return v.ж.OldPrivateNodeKey }
|
||||
func (v PersistView) UserProfile() tailcfg.UserProfile { return v.ж.UserProfile }
|
||||
func (v PersistView) NetworkLockKey() key.NLPrivate { return v.ж.NetworkLockKey }
|
||||
func (v PersistView) NodeID() tailcfg.StableNodeID { return v.ж.NodeID }
|
||||
|
||||
// DisallowedTKAStateIDs stores the tka.State.StateID values which
|
||||
// this node will not operate network lock on. This is used to
|
||||
// prevent bootstrapping TKA onto a key authority which was forcibly
|
||||
// disabled.
|
||||
func (v PersistView) DisallowedTKAStateIDs() views.Slice[string] {
|
||||
return views.SliceOf(v.ж.DisallowedTKAStateIDs)
|
||||
}
|
||||
|
||||
@@ -89,38 +89,68 @@ func (v *PrefsView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v PrefsView) ControlURL() prefs.Item[string] { return v.ж.ControlURL }
|
||||
func (v PrefsView) RouteAll() prefs.Item[bool] { return v.ж.RouteAll }
|
||||
func (v PrefsView) ExitNodeID() prefs.Item[tailcfg.StableNodeID] { return v.ж.ExitNodeID }
|
||||
func (v PrefsView) ExitNodeIP() prefs.Item[netip.Addr] { return v.ж.ExitNodeIP }
|
||||
func (v PrefsView) ExitNodePrior() tailcfg.StableNodeID { return v.ж.ExitNodePrior }
|
||||
func (v PrefsView) ExitNodeAllowLANAccess() prefs.Item[bool] { return v.ж.ExitNodeAllowLANAccess }
|
||||
func (v PrefsView) CorpDNS() prefs.Item[bool] { return v.ж.CorpDNS }
|
||||
func (v PrefsView) RunSSH() prefs.Item[bool] { return v.ж.RunSSH }
|
||||
func (v PrefsView) RunWebClient() prefs.Item[bool] { return v.ж.RunWebClient }
|
||||
func (v PrefsView) WantRunning() prefs.Item[bool] { return v.ж.WantRunning }
|
||||
func (v PrefsView) LoggedOut() prefs.Item[bool] { return v.ж.LoggedOut }
|
||||
func (v PrefsView) ShieldsUp() prefs.Item[bool] { return v.ж.ShieldsUp }
|
||||
func (v PrefsView) AdvertiseTags() prefs.ListView[string] { return v.ж.AdvertiseTags.View() }
|
||||
func (v PrefsView) Hostname() prefs.Item[string] { return v.ж.Hostname }
|
||||
func (v PrefsView) NotepadURLs() prefs.Item[bool] { return v.ж.NotepadURLs }
|
||||
func (v PrefsView) ForceDaemon() prefs.Item[bool] { return v.ж.ForceDaemon }
|
||||
func (v PrefsView) Egg() prefs.Item[bool] { return v.ж.Egg }
|
||||
func (v PrefsView) ControlURL() prefs.Item[string] { return v.ж.ControlURL }
|
||||
func (v PrefsView) RouteAll() prefs.Item[bool] { return v.ж.RouteAll }
|
||||
func (v PrefsView) ExitNodeID() prefs.Item[tailcfg.StableNodeID] { return v.ж.ExitNodeID }
|
||||
func (v PrefsView) ExitNodeIP() prefs.Item[netip.Addr] { return v.ж.ExitNodeIP }
|
||||
|
||||
// ExitNodePrior is an internal state rather than a preference.
|
||||
// It can be kept in the Prefs structure but should not be wrapped
|
||||
// and is ignored by the [prefs] package.
|
||||
func (v PrefsView) ExitNodePrior() tailcfg.StableNodeID { return v.ж.ExitNodePrior }
|
||||
func (v PrefsView) ExitNodeAllowLANAccess() prefs.Item[bool] { return v.ж.ExitNodeAllowLANAccess }
|
||||
func (v PrefsView) CorpDNS() prefs.Item[bool] { return v.ж.CorpDNS }
|
||||
func (v PrefsView) RunSSH() prefs.Item[bool] { return v.ж.RunSSH }
|
||||
func (v PrefsView) RunWebClient() prefs.Item[bool] { return v.ж.RunWebClient }
|
||||
func (v PrefsView) WantRunning() prefs.Item[bool] { return v.ж.WantRunning }
|
||||
func (v PrefsView) LoggedOut() prefs.Item[bool] { return v.ж.LoggedOut }
|
||||
func (v PrefsView) ShieldsUp() prefs.Item[bool] { return v.ж.ShieldsUp }
|
||||
|
||||
// AdvertiseTags is a preference whose value is a slice of strings.
|
||||
// The value is atomic, and individual items in the slice should
|
||||
// not be modified after the preference is set.
|
||||
// Since the item type (string) is immutable, we can use [prefs.List].
|
||||
func (v PrefsView) AdvertiseTags() prefs.ListView[string] { return v.ж.AdvertiseTags.View() }
|
||||
func (v PrefsView) Hostname() prefs.Item[string] { return v.ж.Hostname }
|
||||
func (v PrefsView) NotepadURLs() prefs.Item[bool] { return v.ж.NotepadURLs }
|
||||
func (v PrefsView) ForceDaemon() prefs.Item[bool] { return v.ж.ForceDaemon }
|
||||
func (v PrefsView) Egg() prefs.Item[bool] { return v.ж.Egg }
|
||||
|
||||
// AdvertiseRoutes is a preference whose value is a slice of netip.Prefix.
|
||||
// The value is atomic, and individual items in the slice should
|
||||
// not be modified after the preference is set.
|
||||
// Since the item type (netip.Prefix) is immutable, we can use [prefs.List].
|
||||
func (v PrefsView) AdvertiseRoutes() prefs.ListView[netip.Prefix] { return v.ж.AdvertiseRoutes.View() }
|
||||
func (v PrefsView) NoSNAT() prefs.Item[bool] { return v.ж.NoSNAT }
|
||||
func (v PrefsView) NoStatefulFiltering() prefs.Item[opt.Bool] { return v.ж.NoStatefulFiltering }
|
||||
func (v PrefsView) NetfilterMode() prefs.Item[preftype.NetfilterMode] { return v.ж.NetfilterMode }
|
||||
func (v PrefsView) OperatorUser() prefs.Item[string] { return v.ж.OperatorUser }
|
||||
func (v PrefsView) ProfileName() prefs.Item[string] { return v.ж.ProfileName }
|
||||
func (v PrefsView) AutoUpdate() AutoUpdatePrefs { return v.ж.AutoUpdate }
|
||||
func (v PrefsView) AppConnector() AppConnectorPrefs { return v.ж.AppConnector }
|
||||
func (v PrefsView) PostureChecking() prefs.Item[bool] { return v.ж.PostureChecking }
|
||||
func (v PrefsView) NetfilterKind() prefs.Item[string] { return v.ж.NetfilterKind }
|
||||
|
||||
// AutoUpdate contains auto-update preferences.
|
||||
// Each preference in the group can be configured and managed individually.
|
||||
func (v PrefsView) AutoUpdate() AutoUpdatePrefs { return v.ж.AutoUpdate }
|
||||
|
||||
// AppConnector contains app connector-related preferences.
|
||||
// Each preference in the group can be configured and managed individually.
|
||||
func (v PrefsView) AppConnector() AppConnectorPrefs { return v.ж.AppConnector }
|
||||
func (v PrefsView) PostureChecking() prefs.Item[bool] { return v.ж.PostureChecking }
|
||||
func (v PrefsView) NetfilterKind() prefs.Item[string] { return v.ж.NetfilterKind }
|
||||
|
||||
// DriveShares is a preference whose value is a slice of *[drive.Share].
|
||||
// The value is atomic, and individual items in the slice should
|
||||
// not be modified after the preference is set.
|
||||
// Since the item type (*drive.Share) is mutable and implements [views.ViewCloner],
|
||||
// we need to use [prefs.StructList] instead of [prefs.List].
|
||||
func (v PrefsView) DriveShares() prefs.StructListView[*drive.Share, drive.ShareView] {
|
||||
return prefs.StructListViewOf(&v.ж.DriveShares)
|
||||
}
|
||||
func (v PrefsView) AllowSingleHosts() prefs.Item[marshalAsTrueInJSON] { return v.ж.AllowSingleHosts }
|
||||
func (v PrefsView) Persist() persist.PersistView { return v.ж.Persist.View() }
|
||||
|
||||
// Persist is an internal state rather than a preference.
|
||||
// It can be kept in the Prefs structure but should not be wrapped
|
||||
// and is ignored by the [prefs] package.
|
||||
func (v PrefsView) Persist() persist.PersistView { return v.ж.Persist.View() }
|
||||
|
||||
// A compilation failure here means this code must be regenerated, with the command at the top of this file.
|
||||
var _PrefsViewNeedsRegeneration = Prefs(struct {
|
||||
|
||||
@@ -95,6 +95,9 @@ func (v TestPrefsView) AddrItem() Item[netip.Addr] { return v.ж.A
|
||||
func (v TestPrefsView) StringStringMap() MapView[string, string] { return v.ж.StringStringMap.View() }
|
||||
func (v TestPrefsView) IntStringMap() MapView[int, string] { return v.ж.IntStringMap.View() }
|
||||
func (v TestPrefsView) AddrIntMap() MapView[netip.Addr, int] { return v.ж.AddrIntMap.View() }
|
||||
|
||||
// Bundles are complex preferences that usually consist of
|
||||
// multiple parameters that must be configured atomically.
|
||||
func (v TestPrefsView) Bundle1() ItemView[*TestBundle, TestBundleView] {
|
||||
return ItemViewOf(&v.ж.Bundle1)
|
||||
}
|
||||
@@ -116,6 +119,10 @@ func (v TestPrefsView) IntBundleMap() StructMapView[int, *TestBundle, TestBundle
|
||||
func (v TestPrefsView) AddrBundleMap() StructMapView[netip.Addr, *TestBundle, TestBundleView] {
|
||||
return StructMapViewOf(&v.ж.AddrBundleMap)
|
||||
}
|
||||
|
||||
// Group is a nested struct that contains one or more preferences.
|
||||
// Each preference in a group can be configured individually.
|
||||
// Preference groups should be included directly rather than by pointers.
|
||||
func (v TestPrefsView) Group() TestPrefsGroup { return v.ж.Group }
|
||||
|
||||
// A compilation failure here means this code must be regenerated, with the command at the top of this file.
|
||||
|
||||
Reference in New Issue
Block a user