Documentation ¶
Index ¶
- Constants
- func CombineOwnedFilePaths(am *ApplyMetaData, bm *ApplyMetaData) []string
- 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 InstallDir() string
- func MakeReqHdr(md ReqMetaData) http.Header
- func NewLineFilter(str string) string
- func OwnershipCk(path string, uid int, gid int) bool
- func PackagesToMetaData(pkg map[string]bool) []string
- 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 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 WriteActionLog(action ActionLogAction, status ActionLogStatus, metaData *ApplyMetaData)
- 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 ActionLogAction
- type ActionLogStatus
- type ApplyFilesFlag
- type ApplyMetaData
- type ApplyMetaDataAction
- type ApplyServiceActionFlag
- type CheckRefsInputFileAndAdding
- type ChkConfigEntry
- type ConfigData
- type ConfigDataMetaData
- type Mode
- type Package
- type ReqMetaData
- type ServiceNeeds
- type TCCfg
- type UseStrategiesFlag
Constants ¶
const ( // ActionLogActionApplyStart is the start of the t3c-apply run. // The status of this should always be success. ActionLogActionApplyStart = ActionLogAction("apply-start") // ActionLogActionGitInit is creating a git repo in the ATS config directory. ActionLogActionGitInit = ActionLogAction("git-init") // ActionLogActionGitCommitInitial is the initial commit at the start of the run. ActionLogActionGitCommitInitial = ActionLogAction("create-git-commit-initial") // ActionLogActionGitCommitInitial is the final commit at the end of the run. ActionLogActionGitCommitFinal = ActionLogAction("create-git-commit-final") // ActionLogActionUpdateFilesAll is writing and updating ATS config files. ActionLogActionUpdateFilesAll = ActionLogAction("update-files-all") // ActionLogActionUpdateFilesReval is writing and updating only revalidate ATS config files. ActionLogActionUpdateFilesReval = ActionLogAction("update-files-reval") // ActionLogActionATSReload is calling service reload on ATS. ActionLogActionATSReload = ActionLogAction("ats-reload") // ActionLogActionATSReload is calling service restart on ATS. ActionLogActionATSRestart = ActionLogAction("ats-restart") // ActionLogActionApplyEnd is the end of the t3c-apply run. ActionLogActionApplyEnd = ActionLogAction("apply-end") )
const ( ActionLogStatusSuccess = ActionLogStatus("success") ActionLogStatusFailure = ActionLogStatus("failure") )
const ApplyCachePath = `/var/lib/trafficcontrol-cache-config/config-data.json`
const MetaDataVersion = "1.0"
MetaDataVersion is the version of the metadata file. This should update the major version with breaking changes, and t3c versions should strive to maintain compatibility at least one major version back, so features like tracking t3c-owned files continue to work through upgrades.
const SystemInfoParamConfigFile = `global`
const TrafficOpsProxyParameterName = `tm.rev_proxy.url`
Variables ¶
This section is empty.
Functions ¶
func CombineOwnedFilePaths ¶
func CombineOwnedFilePaths(am *ApplyMetaData, bm *ApplyMetaData) []string
CombineOwnedFilePaths combines the owned file paths of two metadata objects.
This is primarily useful when a config run, such as revalidate, adds owned files, but not all owned files, but we don't want to write metadata incidating we don't own existing files, so this can be used to combine the new files with the previous metadata.
Both am and bm are may be nil, in which case the files from the non-nil object is returned, or an empty array if both are nil.
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 InstallDir ¶
func InstallDir() string
initializes InstallDir to executable dir If error, returns "/usr/bin" as default.
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 PackagesToMetaData ¶
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 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 WriteActionLog ¶
func WriteActionLog(action ActionLogAction, status ActionLogStatus, metaData *ApplyMetaData)
WriteActionLog writes the given action and status to both the info log and the given metadata object.
The metaData may be nil, and should be if this is being called after the final git commit, to prevent modifying the file after the commit.
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 ActionLogAction ¶
type ActionLogAction string
ActionLogAction is an action t3c performs which affects the state of the machine. Things that don't affect the state of the machine are not considered actions.
For example, requesting Traffic Ops is not an 'action', but restarting ATS or modifying a config file is.
Actions also include the t3c-apply run starting and finishing, to help delineate the actions of different runs in the log.
type ActionLogStatus ¶
type ActionLogStatus string
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 ApplyMetaData ¶
type ApplyMetaData struct { // Version is the metadata version of this metadata object or file. See MetaDataVersion. Version string `json:"version"` // ServerFQDN is the FQDN of this server. // The primary purpose of this field is to allow distinguishing // metadata files from different servers. ServerHostName string `json:"server-hostname"` // ReloadedATS is whether this run restarted ATS. // Note this is whether ATS was actually restarted, not whether it would have been, // e.g. because of --report-only or --service-action. ReloadedATS bool `json:"reloaded-ats"` // RestartedATS is whether this run restarted ATS. // Note this is whether ATS was actually restarted, not whether it would have been, // e.g. because of --report-only or --service-action. RestartedATS bool `json:"restarted-ats"` // UnsetUpdateFlag is whether this t3c-apply run unset the update flag for this server. // Note this is whether the flag was actually unset, not whether it would have been e.g. // because of --no-unset-update-flag or --report-only. UnsetUpdateFlag bool `json:"unset-update-flag"` // UnsetRevalFlag is whether this t3c-apply run unset the revalidate flag for this server. // Note this is whether the flag was actually unset, not whether it would have been e.g. // because of --no-unset-reval-flag or --report-only. UnsetRevalFlag bool `json:"unset-reval-flag"` // InstalledPackages is which yum packages are installed. // Note this packages currently installed, not what would have been e.g. // because of --install-packages=false or --report-only. InstalledPackages []string `json:"installed-packages"` // OwnedFilePaths is the list of files t3c-apply produced in this run. // // This can be used to know which files in the ATS config directory were produced by t3c, // and which were produced by some other means. // // Note this is all files produced, not necessarily all files written to disk. This // will include files generated, but not changed on disk because they had no // semantic diff from the existing file. // // This may be used in the future for t3c-apply to delete files produced by a previous // run which no longer exist (for example, Header Rewrites from a Delivery Service // no longer assigned to this server). // // Files are the full path and file name. OwnedFilePaths []string `json:"owned-files"` // Succeeded is whether this t3c-apply run generally succeeded. // // Note not all scenarios are black or white success-or-fail. // For example, files may be successfully created, but reloading ATS may fail. // In these scenarios, t3c-apply will attempt to set Succeeded to false, // but also attempt to set other metadata about what was actually performed. // // But when partial failure occurrs, nothing is guaranteed in the metadata. // Operators should consider the logs authoritative over the metadata. Succeeded bool `json:"succeeded"` // PartialSuccess indicates that some actions were successful, but // later actions failed. // // This is a bad place to be, because it means some things were changed, // but not everything that needed to be. This is often not fatal, because, // for example, if config files were changed by ATS failed to reload, // those config files typically needed placed anyway. // // But nevertheless, partial success is potentially catastrophic, and operators // are strongly encouraged to set alarms and read logs in the event it occurs, // to determine what was changed, what failed, and what actions need taken. PartialSuccess bool `json:"partial-success"` Actions []ApplyMetaDataAction `json:"actions"` }
ApplyMetaData is metadata about a t3c-apply run. Always use NewApplyMetaData, don't use a literal to construct a new object.
func NewApplyMetaData ¶
func NewApplyMetaData() *ApplyMetaData
NewApplyMetaData creates a new, empty ApplyMetaData object.
func (*ApplyMetaData) Format ¶
func (md *ApplyMetaData) Format() ([]byte, error)
Format prints the ApplyMetaData in a format designed to be written to a file, and structured but pretty-printed to work well with line-based diffs (e.g. in git).
type ApplyMetaDataAction ¶
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 CheckRefsInputFileAndAdding ¶
type CheckRefsInputFileAndAdding struct { File []byte `json:"file"` Adding []string `json:"adding"` }
CheckRefsInputFileAndAdding is the input (stdin or file) for t3c-check-refs if --files-adding=input. If not, the input is simply the raw file to check.
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.CacheGroupNullableV5 `json:"cache_groups,omitempty"` // GlobalParams must be all Parameters in Traffic Ops on the tc.GlobalProfileName Profile. Must not include other parameters. GlobalParams []tc.ParameterV5 `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.ParameterV5 `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.ParameterV5 `json:"server_params,omitempty"` // CacheKeyConfigParams must be all Parameters with the "cachekey.config" (compat) CacheKeyConfigParams []tc.ParameterV5 `json:"cachekey_config_parameters,omitempty"` // RemapConfigParams must be all Parameters with the ConfigFile "remap.config" RemapConfigParams []tc.ParameterV5 `json:"remap_config_parameters,omitempty"` // ParentConfigParams must be all Parameters with the ConfigFile "parent.config. ParentConfigParams []tc.ParameterV5 `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.CDNV5 `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.TopologyV5 `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. |