Documentation ¶
Index ¶
- Constants
- func CommentsFilter(body []string, lineComment string) []string
- func Do(cmdStr string, args ...string) ([]byte, []byte, int)
- func DoInput(input []byte, cmdStr string, args ...string) ([]byte, []byte, int)
- func FilterDSS(dsses []tc.DeliveryServiceServer, dsIDs map[int]struct{}, ...) []tc.DeliveryServiceServer
- func FilterParams(params []tc.Parameter, configFile string, name string, value string, ...) []tc.Parameter
- func GetDataFuncs() map[string]func(TCCfg, io.Writer) error
- func GetServerUpdateStatus(cfg TCCfg) (*atscfg.ServerUpdateStatus, error)
- func MakeReqHdr(md ReqMetaData) http.Header
- func NewLineFilter(str string) string
- func OwnershipCk(path string, uid int, gid int) bool
- func ParamsToMap(params []tc.Parameter) map[string]string
- func ParamsToMultiMap(params []tc.Parameter) map[string][]string
- func PermCk(path string, perm int) bool
- func ReadFile(f string) []byte
- func SetUpdateStatus(cfg TCCfg, serverName tc.CacheName, configApply, revalApply *time.Time) error
- func SetUpdateStatusCompat(cfg TCCfg, serverName tc.CacheName, configApply, revalApply *time.Time, ...) error
- func UnencodeFilter(body []string) []string
- func UserAgentStr(appName string, versionNum string, gitRevision string) string
- func ValidateURL(u *url.URL) error
- func VersionStr(appName string, versionNum string, gitRevision string) string
- func WriteChkconfig(cfg TCCfg, output io.Writer) error
- func WriteConfig(cfg TCCfg, output io.Writer) error
- func WriteData(cfg TCCfg) error
- func WritePackages(cfg TCCfg, output io.Writer) error
- func WriteServerUpdateStatus(cfg TCCfg, output io.Writer) error
- func WriteStatuses(cfg TCCfg, output io.Writer) error
- func WriteSystemInfo(cfg TCCfg, output io.Writer) error
- type ATSConfigFile
- type ATSConfigFiles
- type ApplyFilesFlag
- type ApplyServiceActionFlag
- type ChkConfigEntry
- type ConfigData
- type ConfigDataMetaData
- type Mode
- type Package
- type ReqMetaData
- type ServiceNeeds
- type TCCfg
- type UseStrategiesFlag
Constants ¶
const ApplyCachePath = `/var/lib/trafficcontrol-cache-config/config-data.json`
const SystemInfoParamConfigFile = `global`
const TrafficOpsProxyParameterName = `tm.rev_proxy.url`
Variables ¶
This section is empty.
Functions ¶
func CommentsFilter ¶
CommentsFilter is used to remove comment lines from config files while making comparisons.
func Do ¶
This is a convenience wrapper around os/exec. Since t3c only needs to make simple calls and get the stdout, stderr, and code, this provides a simpler and terser interface.
If you need anything more complex, or don't find this simpler, you should probably use os/exec directly.
Each arg must be passed as its own string. Unfortunately, Go doesn't have a way to pass multiple args as a single string, and splitting on spaces would require complex quote parsing.
Note each arg must be passed without quotes. Go calls the app with args as if they were quoted. if you add quotes, they'll be passed to the command literally, as if you called 'mycommand "\"escaped-quotes\""`.
Note if Go fails to run the command, the error from Go will be returned as the stderr and the code -1, which will differ from what would have been returned by a command line.
func FilterParams ¶
func FilterParams(params []tc.Parameter, configFile string, name string, value string, omitName string) []tc.Parameter
FilterParams filters params and returns only the parameters which match configFile, name, and value. If configFile, name, or value is the empty string, it is not filtered. Returns a slice of parameters.
func GetServerUpdateStatus ¶
func MakeReqHdr ¶
func MakeReqHdr(md ReqMetaData) http.Header
func NewLineFilter ¶
NewLineFilter removes carriage returns from config files while making comparisons.
func OwnershipCk ¶
OwnershipCk will compare owner and group settings against existing file and owner/group settings provided.
func ParamsToMap ¶
ParamsToMap converts a []tc.Parameter to a map[paramName]paramValue. If multiple params have the same value, the first one in params will be used an an error will be logged. See ParamArrToMultiMap.
func ParamsToMultiMap ¶
ParamArrToMultiMap converts a []tc.Parameter to a map[paramName][]paramValue.
func PermCk ¶
PermCk will compare file permissions against existing file and octal permission provided.
func SetUpdateStatus ¶
SetUpdateStatus sets the queue and reval status of serverName in Traffic Ops.
func SetUpdateStatusCompat ¶
func SetUpdateStatusCompat(cfg TCCfg, serverName tc.CacheName, configApply, revalApply *time.Time, configApplyBool, revalApplyBool *bool) error
SetUpdateStatusCompat sets the queue and reval status of serverName in Traffic Ops. *** Compatability requirement until ATC (v7.0+) is deployed with the timestamp features
func UnencodeFilter ¶
UnencodeFilter translates HTML escape sequences while making config file comparisons.
func ValidateURL ¶
func VersionStr ¶
VersionStr returns a common version string format for all t3c apps. The appName is the command itself, e.g. t3c-apply. The versionNum is the version number from the build system. It should include the major, minor, git revision, and a monotonically increasing number, e.g. '4.2.1234.abc123'.
func WriteChkconfig ¶
WriteChkconfig writes the chkconfig for cfg.CacheHostName to output. Note this is identical to /ort/serverName/chkconfig.
func WriteConfig ¶
WriteConfig writes the Traffic Ops data necessary to generate config to output.
func WritePackages ¶
WriteORTServerPackages writes the packages for serverName to output. Note this is identical to /ort/serverName/packages.
func WriteServerUpdateStatus ¶
WriteServerUpdateStatus writes the Traffic Ops server update status to output. Note this is identical to the Traffic Ops API's /servers/{{host name}}/update_status endpoint except it omits the '[]' wrapper.
func WriteStatuses ¶
WriteStatuses writes the Traffic Ops statuses to output. Note this is identical to /statuses except it omits the '{response:' wrapper.
func WriteSystemInfo ¶
WriteSystemInfo writes the "system info" to output.
This is the same info as the Traffic Ops API's /system/info endpoint, which is actually just all Parameters with the config_file 'global'. Note this is different than the more common "global parameters", which usually refers to all Parameters on the Profile named 'GLOBAL'.
This is identical to the /system/info endpoint, except it does not include a
'{response: {parameters:' wrapper.
Types ¶
type ATSConfigFile ¶
type ATSConfigFiles ¶
type ATSConfigFiles []ATSConfigFile
ATSConfigFiles implements sort.Interface and sorts by the Location and then FileNameOnDisk, i.e. the full file path.
func (ATSConfigFiles) Len ¶
func (fs ATSConfigFiles) Len() int
func (ATSConfigFiles) Less ¶
func (fs ATSConfigFiles) Less(i, j int) bool
func (ATSConfigFiles) Swap ¶
func (fs ATSConfigFiles) Swap(i, j int)
type ApplyFilesFlag ¶
type ApplyFilesFlag string
const ( ApplyFilesFlagInvalid ApplyFilesFlag = "" ApplyFilesFlagAll ApplyFilesFlag = "all" ApplyFilesFlagReval ApplyFilesFlag = "reval" )
func StrToApplyFilesFlag ¶
func StrToApplyFilesFlag(str string) ApplyFilesFlag
func (ApplyFilesFlag) String ¶
func (ff ApplyFilesFlag) String() string
type ApplyServiceActionFlag ¶
type ApplyServiceActionFlag string
const ( ApplyServiceActionFlagNone ApplyServiceActionFlag = "none" ApplyServiceActionFlagReload ApplyServiceActionFlag = "reload" ApplyServiceActionFlagRestart ApplyServiceActionFlag = "restart" ApplyServiceActionFlagInvalid ApplyServiceActionFlag = "" )
func StrToApplyServiceActionFlag ¶
func StrToApplyServiceActionFlag(str string) ApplyServiceActionFlag
func (ApplyServiceActionFlag) String ¶
func (af ApplyServiceActionFlag) String() string
type ChkConfigEntry ¶
func GetChkconfig ¶
func GetChkconfig(cfg TCCfg) ([]ChkConfigEntry, error)
type ConfigData ¶
type ConfigData struct { // Version is the version of the application which created the config data, // primarily used for cache invalidation. Version string `json:"version"` // Servers must be all the servers from Traffic Ops. May include servers not on the current cdn. Servers []atscfg.Server `json:"servers,omitempty"` // CacheGroups must be all cachegroups in Traffic Ops with Servers on the current server's cdn. May also include CacheGroups without servers on the current cdn. CacheGroups []tc.CacheGroupNullable `json:"cache_groups,omitempty"` // GlobalParams must be all Parameters in Traffic Ops on the tc.GlobalProfileName Profile. Must not include other parameters. GlobalParams []tc.Parameter `json:"global_parameters,omitempty"` // ServerProfilesParams must be all Parameters on the Profiles of the current server. Must not include other Parameters. ServerProfilesParams map[atscfg.ProfileName][]tc.Parameter `json:"server_profiles_parameters,omitempty"` // ServerParams is constructed from Server and ServerParams. Must not include other Parameters. // It's ok for other apps using this data to serialize and deserialize this to pass it around, // but t3c-request must always use ServerProfilesParams to re-populate this, and do If-Modified-Since requests from that. // This must never be used in an If-Modified-Since check, or populated wholesale from a single profile's endpoint. ServerParams []tc.Parameter `json:"server_params,omitempty"` // CacheKeyConfigParams must be all Parameters with the "cachekey.config" (compat) CacheKeyConfigParams []tc.Parameter `json:"cachekey_config_parameters,omitempty"` // RemapConfigParams must be all Parameters with the ConfigFile "remap.config" RemapConfigParams []tc.Parameter `json:"remap_config_parameters,omitempty"` // ParentConfigParams must be all Parameters with the ConfigFile "parent.config. ParentConfigParams []tc.Parameter `json:"parent_config_parameters,omitempty"` // DeliveryServices must include all Delivery Services on the current server's cdn, including those not assigned to the server. Must not include delivery services on other cdns. DeliveryServices []atscfg.DeliveryService `json:"delivery_services,omitempty"` // DeliveryServiceServers must include all delivery service servers in Traffic Ops for all delivery services on the current cdn, including those not assigned to the current server. DeliveryServiceServers []atscfg.DeliveryServiceServer `json:"delivery_service_servers,omitempty"` // Server must be the server we're fetching configs from Server *atscfg.Server `json:"server,omitempty"` // Jobs must be all Jobs on the server's CDN. May include jobs on other CDNs. Jobs []atscfg.InvalidationJob `json:"jobs,omitempty"` // CDN must be the CDN of the server. CDN *tc.CDN `json:"cdn,omitempty"` // DeliveryServiceRegexes must be all regexes on all delivery services on this server's cdn. DeliveryServiceRegexes []tc.DeliveryServiceRegexes `json:"delivery_service_regexes,omitempty"` // URISigningKeys must be a map of every delivery service which is URI Signed, to its keys. URISigningKeys map[tc.DeliveryServiceName][]byte `json:"uri_signing_keys,omitempty"` // URLSigKeys must be a map of every delivery service which uses URL Sig, to its keys. URLSigKeys map[tc.DeliveryServiceName]tc.URLSigKeys `json:"url_sig_keys,omitempty"` // ServerCapabilities must be a map of all server IDs on this server's CDN, to a set of their capabilities. May also include servers from other cdns. ServerCapabilities map[int]map[atscfg.ServerCapability]struct{} `json:"server_capabilities,omitempty"` // DSRequiredCapabilities must be a map of all delivery service IDs on this server's CDN, to a set of their required capabilities. Delivery Services with no required capabilities may not have an entry in the map. DSRequiredCapabilities map[int]map[atscfg.ServerCapability]struct{} `json:"delivery_service_required_capabilities,omitempty"` // SSLKeys must be all the ssl keys for the server's cdn. SSLKeys []tc.CDNSSLKeys `json:"ssl_keys,omitempty"` // Topologies must be all the topologies for the server's cdn. // May incude topologies of other cdns. Topologies []tc.Topology `json:"topologies,omitempty"` // TrafficOpsAddresses is the list of IP addresses used to request data. Because of proxies and load balancers, // multiple addresses may be used for the multiple requests necessary to fetch all data. TrafficOpsAddresses []string `json:"traffic_ops_addresses,omitempty"` TrafficOpsURL string `json:"traffic_ops_url,omitempty"` MetaData ConfigDataMetaData `json:"metadata"` }
func GetConfigData ¶
func GetConfigData(toClient *toreq.TOClient, disableProxy bool, cacheHostName string, revalOnly bool, oldCfg *ConfigData, version string) (*ConfigData, error)
GetTOData gets all the data from Traffic Ops needed to generate config. Returns the data, the addresses of all Traffic Ops' requested, and any error.
The toClient is the Traffic Ops client, which should already be initialized and connected.
The disableProxy arg is whether to disable using any Traffic Ops proxy configured via the global TrafficOpsProxyParameterName. If the Parameter exists, this will connect to Traffic Ops to get the global parameters, get the Parameter, and then change the toClient to use it.
The cacheHostName is the hostname of the cache to get config generation data for.
The oldCfg is previous config data which was cached. May be nil, if the caller has no previous data. If it exists and is usable, If-Modified-Since requests will be made and the cache re-used where possible.
The version is a unique version of the application, which should change with any compatibility changes. Old config with a different version than the current won't be used (though in the future, smarter compatibility could be added).
The revalOnly arg is whether to only get data necessary to revalidate, versus all data necessary to generate cache config.
type ConfigDataMetaData ¶
type ConfigDataMetaData struct { CacheHostName string `json:"cache_host_name"` Servers ReqMetaData `json:"servers"` CacheGroups ReqMetaData `json:"cache_groups"` GlobalParams ReqMetaData `json:"global_parameters"` ServerProfilesParams map[atscfg.ProfileName]ReqMetaData `json:"server_profiles_parameters"` CacheKeyConfigParams ReqMetaData `json:"cachekey_config_parameters"` RemapConfigParams ReqMetaData `json:"remap_config_parameters"` ParentConfigParams ReqMetaData `json:"parent_config_parameters"` DeliveryServices ReqMetaData `json:"delivery_services"` DeliveryServiceServers ReqMetaData `json:"delivery_service_servers"` Jobs ReqMetaData `json:"jobs"` CDN ReqMetaData `json:"cdn"` DeliveryServiceRegexes ReqMetaData `json:"delivery_service_regexes"` URISigningKeys map[tc.DeliveryServiceName]ReqMetaData `json:"uri_signing_keys"` URLSigKeys map[tc.DeliveryServiceName]ReqMetaData `json:"url_sig_keys"` ServerCapabilities ReqMetaData `json:"server_capabilities"` DSRequiredCapabilities ReqMetaData `json:"delivery_service_required_capabilities"` SSLKeys ReqMetaData `json:"ssl_keys"` Topologies ReqMetaData `json:"topologies"` }
type Package ¶
func GetPackages ¶
type ReqMetaData ¶
type ReqMetaData struct { LastModified string `json:"last_modified"` Date string `json:"date"` ETag string `json:"etag"` }
ReqMetaData has response headers for Conditional Requests.
func MakeReqMetaData ¶
func MakeReqMetaData(respHdr http.Header) ReqMetaData
type ServiceNeeds ¶
type ServiceNeeds string
ServiceNeeds represents whether we need to reload or restart Traffic Server, as returned by t3c-check-reload.
Note the default is success, not invalid. With enums, typically invalid should be the default, but in this case, this represents the return of an app which returns nothing on successes (which is typical of POSIX apps), so we want the default empty string to represent that. Hence, the default value of ServiceNeeds is success, not invalid
const ( ServiceNeedsNothing ServiceNeeds = "" // default is nothing, and print nothing if nothing needs done ServiceNeedsRestart ServiceNeeds = "restart" ServiceNeedsReload ServiceNeeds = "reload" ServiceNeedsInvalid ServiceNeeds = "invalid" )
func StrToServiceNeeds ¶
func StrToServiceNeeds(str string) ServiceNeeds
func (ServiceNeeds) String ¶
func (sn ServiceNeeds) String() string
type TCCfg ¶
type TCCfg struct { CacheHostName string GetData string TOClient *toreq.TOClient TOInsecure bool TOTimeoutMS time.Duration TOPass string TOUser string TOURL *url.URL UserAgent string // TODisableProxy is whether to not use a configured Traffic Ops Proxy. // This is only used by WriteConfig, which is the only command that makes enough requests to matter. TODisableProxy bool // RevalOnly is whether to only fetch config data necessary to revalidate, versus all data necessary to generate config. This is only used by WriteConfig RevalOnly bool // OldCfg is the previously fetched ConfigData, for 'config' requests. May be nil. OldCfg *ConfigData // T3CVersion is the version of the t3c app ecosystem // This value will be the same for any t3c app. T3CVersion string }
type UseStrategiesFlag ¶
type UseStrategiesFlag string
const ( UseStrategiesFlagTrue UseStrategiesFlag = "true" UseStrategiesFlagCore UseStrategiesFlag = "core" UseStrategiesFlagFalse UseStrategiesFlag = "false" UseStrategiesFlagInvalid UseStrategiesFlag = "" )
func StrToUseStrategiesFlag ¶
func StrToUseStrategiesFlag(str string) UseStrategiesFlag
func (UseStrategiesFlag) String ¶
func (fl UseStrategiesFlag) String() string
Directories ¶
Path | Synopsis |
---|---|
toreq implements a Traffic Ops client for features in the latest version.
|
toreq implements a Traffic Ops client for features in the latest version. |
toreqold
Package toreqold calls the previous Traffic Ops API major version.
|
Package toreqold calls the previous Traffic Ops API major version. |
torequtil
torequtil has utility functions used by toreq and toreqnew which don't require the Traffic Ops client, and thus can be shared.
|
torequtil has utility functions used by toreq and toreqnew which don't require the Traffic Ops client, and thus can be shared. |