t3cutil

package
v7.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 25 Imported by: 74

Documentation

Index

Constants

View Source
const ApplyCachePath = `/var/lib/trafficcontrol-cache-config/config-data.json`
View Source
const SystemInfoParamConfigFile = `global`
View Source
const TrafficOpsProxyParameterName = `tm.rev_proxy.url`

Variables

This section is empty.

Functions

func CommentsFilter

func CommentsFilter(body []string, lineComment string) []string

CommentsFilter is used to remove comment lines from config files while making comparisons.

func Do

func Do(cmdStr string, args ...string) ([]byte, []byte, int)

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 DoInput

func DoInput(input []byte, cmdStr string, args ...string) ([]byte, []byte, int)

DoInput is like Do but takes the stdin to pass to the command.

func FilterDSS

func FilterDSS(dsses []tc.DeliveryServiceServer, dsIDs map[int]struct{}, serverIDs map[int]struct{}) []tc.DeliveryServiceServer

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 GetDataFuncs

func GetDataFuncs() map[string]func(TCCfg, io.Writer) error

func GetServerUpdateStatus

func GetServerUpdateStatus(cfg TCCfg) (*atscfg.ServerUpdateStatus, error)

func MakeReqHdr

func MakeReqHdr(md ReqMetaData) http.Header

func NewLineFilter

func NewLineFilter(str string) string

NewLineFilter removes carriage returns from config files while making comparisons.

func OwnershipCk

func OwnershipCk(path string, uid int, gid int) bool

OwnershipCk will compare owner and group settings against existing file and owner/group settings provided.

func ParamsToMap

func ParamsToMap(params []tc.Parameter) map[string]string

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

func ParamsToMultiMap(params []tc.Parameter) map[string][]string

ParamArrToMultiMap converts a []tc.Parameter to a map[paramName][]paramValue.

func PermCk

func PermCk(path string, perm int) bool

PermCk will compare file permissions against existing file and octal permission provided.

func ReadFile

func ReadFile(f string) []byte

ReadFile reads a file and returns the file contents.

func SetUpdateStatus

func SetUpdateStatus(cfg TCCfg, serverName tc.CacheName, configApply, revalApply *time.Time) error

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

func UnencodeFilter(body []string) []string

UnencodeFilter translates HTML escape sequences while making config file comparisons.

func UserAgentStr

func UserAgentStr(appName string, versionNum string, gitRevision string) string

func ValidateURL

func ValidateURL(u *url.URL) error

func VersionStr

func VersionStr(appName string, versionNum string, gitRevision string) string

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

func WriteChkconfig(cfg TCCfg, output io.Writer) error

WriteChkconfig writes the chkconfig for cfg.CacheHostName to output. Note this is identical to /ort/serverName/chkconfig.

func WriteConfig

func WriteConfig(cfg TCCfg, output io.Writer) error

WriteConfig writes the Traffic Ops data necessary to generate config to output.

func WriteData

func WriteData(cfg TCCfg) error

func WritePackages

func WritePackages(cfg TCCfg, output io.Writer) error

WriteORTServerPackages writes the packages for serverName to output. Note this is identical to /ort/serverName/packages.

func WriteServerUpdateStatus

func WriteServerUpdateStatus(cfg TCCfg, output io.Writer) error

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

func WriteStatuses(cfg TCCfg, output io.Writer) error

WriteStatuses writes the Traffic Ops statuses to output. Note this is identical to /statuses except it omits the '{response:' wrapper.

func WriteSystemInfo

func WriteSystemInfo(cfg TCCfg, output io.Writer) error

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 ATSConfigFile struct {
	Name        string   `json:"name"`
	Path        string   `json:"path"`
	ContentType string   `json:"content_type"`
	LineComment string   `json:"line_comment"`
	Secure      bool     `json:"secure"`
	Text        string   `json:"text"`
	Warnings    []string `json:"warnings"`
}

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

type ChkConfigEntry struct {
	Name string `json:"name"`
	Val  string `json:"value"`
}

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 Mode

type Mode string

Mode is the t3c run mode - syncds, badass, etc.

const (
	ModeInvalid    Mode = ""
	ModeBadAss     Mode = "badass"
	ModeReport     Mode = "report"
	ModeRevalidate Mode = "revalidate"
	ModeSyncDS     Mode = "syncds"
)

func StrToMode

func StrToMode(str string) Mode

func (Mode) String

func (md Mode) String() string

type Package

type Package struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

func GetPackages

func GetPackages(cfg TCCfg) ([]Package, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL