toreq

package
v7.0.0+incompatible Latest Latest
Warning

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

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

Documentation

Overview

toreq implements a Traffic Ops client for features in the latest version.

This should only be used if an endpoint or field needed for config gen is in the latest.

Users should always check the returned bool, and if it's false, call the vendored toreq client and set the proper defaults for the new feature(s).

All TOClient functions should check for 404 or 503 and return a bool false if so.

Index

Constants

View Source
const DeliveryServiceServersAlwaysGetAll = true

DeliveryServiceServersAlwaysGetAll indicates whether to always get all delivery service servers from Traffic Ops, and cache all in a file (but still return to the caller only the objects they requested). This exists and is currently true, because with an ORT run, it's typically more efficient to get them all in a single request, and re-use that cache; than for every config file to get and cache its own unique set. If your use case is more efficient to only get the needed objects, for example if you're frequently requesting one file, set this false to get and cache the specific needed delivery services and servers.

Variables

This section is empty.

Functions

func GetCDNByName

func GetCDNByName(toClient *toclient.Session, name tc.CDNName, opts *toclient.RequestOptions) (tc.CDN, toclientlib.ReqInf, error)

func GetDeliveryServiceURLSigKeys

func GetDeliveryServiceURLSigKeys(toClient *toclient.Session, dsName string, opts *toclient.RequestOptions) (tc.URLSigKeys, toclientlib.ReqInf, error)

GetDeliveryServiceURLSigKeys gets the URL Sig keys from Traffic Ops for the given delivery service. It is a helper function that calls traffic_ops/v4-client.Session.GetDeliveryServiceURLSignatureKeys to avoid confusion around the protocol named URL Sig.

func GetParametersByConfigFile

func GetParametersByConfigFile(toClient *toclient.Session, configFile string, opts *toclient.RequestOptions) ([]tc.Parameter, toclientlib.ReqInf, error)

GetParametersByConfigFile returns the parameters with the given config file from Traffic Ops. It is a helper function equivalent to calling GetParameters with RequestOptions with the Values (query string) with the key configFile set to the config file. If opts.Values[configFile] exists, it is overwritten with name.

func GetParametersByName

func GetParametersByName(toClient *toclient.Session, name string, opts *toclient.RequestOptions) ([]tc.Parameter, toclientlib.ReqInf, error)

GetParametersByName returns the parameters with the given name from Traffic Ops. It is a helper function equivalent to calling GetParameters with RequestOptions with the Values (query string) with the key name set to the name. If opts.Values[name] exists, it is overwritten with name.

func GetProfileByName

func GetProfileByName(toClient *toclient.Session, name string, opts *toclient.RequestOptions) (tc.Profile, toclientlib.ReqInf, error)

GetProfileByName returns the profile with the given name from Traffic Ops. It is a helper function equivalent to calling GetProfiles with RequestOptions with the Values (query string) with the key name set to the Profile name. If opts.Values[name] exists, it is overwritten with name.

func InvalidationJobV4FromLegacy

func InvalidationJobV4FromLegacy(job InvalidationJobV4PlusLegacy) (tc.InvalidationJobV4, error)

func IsLatestSupported

func IsLatestSupported(toClient *toclient.Session) (bool, net.Addr, error)

IsLatestSupported returns whether toClient supports the latest API, the address of the Traffic Ops connected to (which may be nil), and any error.

A nil toClient may be passed, in which case it will be assumed that there was an error creating it and the latest isn't supported, and false will be returned with no address and no error.

func LatestKnownAPIVersion

func LatestKnownAPIVersion() string

func ReqOpts

func ReqOpts(hdr http.Header) *toclient.RequestOptions

ReqOpts takes an http.Header and returns a traffic_ops/v4-client.RequestOptions with that header. This is a helper function, for brevity.

func RequestInfoStr

func RequestInfoStr(inf toclientlib.ReqInf, reqPath string) string

RequestInfoStr returns a loggable string with info about the Traffic Ops request.

The returned string does not have a trailing newline, nor anything in the standard logger prefix (time, level, etc). If the string isn't going to be logged via lib/go-log, it's advisable to add a timestamp.

This is safe to call even if the function returning a ReqInf returned an error; it checks for nil values in all cases, and the TO Client guarantees even if a non-nil error is returned, all ReqInf values are either nil or valid.

func ServerV40FromLegacy

func ServerV40FromLegacy(old ServerV40PlusLegacy) (tc.ServerV40, error)

Types

type InvalidationJobV4ForLegacy

type InvalidationJobV4ForLegacy tc.InvalidationJobV4

InvalidationJobV4ForLegacy is a type alias to prevent MarshalJSON recursion.

type InvalidationJobV4Legacy

type InvalidationJobV4Legacy struct {
	Keyword    *string `json:"keyword"`
	Parameters *string `json:"parameters"`
}

type InvalidationJobV4PlusLegacy

type InvalidationJobV4PlusLegacy struct {
	// StartTime overrides the StartTime in InvalidationJobV4 in order to unmarshal any string format.
	//
	// A json.Unmarshal will place a 'startTime' value in this field,
	// rather than the anonymous embedded InvalidationJobV4ForLegacy (tc.InvalidationJobV4).
	//
	// InvalidationJobV4FromLegacy will then parse multiple time formats that different Traffic Ops servers may return,
	// and put the parsed time in tc.InvalidationJobV4.StartTime.
	StartTime *string `json:"startTime"`
	InvalidationJobV4ForLegacy
	InvalidationJobV4Legacy
}

InvalidationJobV4PlusLegacy has the data to deserialize both the latest and older versions that Traffic Ops could return.

type ServerV40PlusLegacy

type ServerV40PlusLegacy struct {
	tc.ServerV40
	Profile     string `json:"profile" db:"profile"`
	ProfileDesc string `json:"profileDesc" db:"profile_desc"`
	ProfileID   int    `json:"profileId" db:"profile_id"`
}

type TOClient

type TOClient struct {

	// NumRetries is the number of times to retry Traffic Ops server failures
	// before giving up and returning an error to the caller.
	NumRetries int
	// contains filtered or unexported fields
}

func New

func New(url *url.URL, user string, pass string, insecure bool, timeout time.Duration, userAgent string) (*TOClient, error)

New logs into Traffic Ops, returning the TOClient which contains the logged-in client.

func (*TOClient) FellBack

func (cl *TOClient) FellBack() bool

FellBack() returns whether the client fell back to the previous major version, because Traffic Ops didn't support the latest.

func (*TOClient) GetCDN

func (cl *TOClient) GetCDN(cdnName tc.CDNName, reqHdr http.Header) (tc.CDN, toclientlib.ReqInf, error)

func (*TOClient) GetCDNDeliveryServices

func (cl *TOClient) GetCDNDeliveryServices(cdnID int, reqHdr http.Header) ([]atscfg.DeliveryService, toclientlib.ReqInf, error)

GetCDNDeliveryServices returns the data, the Traffic Ops address, and any error.

func (*TOClient) GetCDNSSLKeys

func (cl *TOClient) GetCDNSSLKeys(cdnName tc.CDNName, reqHdr http.Header) ([]tc.CDNSSLKeys, toclientlib.ReqInf, error)

func (*TOClient) GetCDNs

func (cl *TOClient) GetCDNs(reqHdr http.Header) ([]tc.CDN, toclientlib.ReqInf, error)

func (*TOClient) GetCacheGroups

func (cl *TOClient) GetCacheGroups(reqHdr http.Header) ([]tc.CacheGroupNullable, toclientlib.ReqInf, error)

func (*TOClient) GetConfigFileParameters

func (cl *TOClient) GetConfigFileParameters(configFile string, reqHdr http.Header) ([]tc.Parameter, toclientlib.ReqInf, error)

func (*TOClient) GetDeliveryServiceRegexes

func (cl *TOClient) GetDeliveryServiceRegexes(reqHdr http.Header) ([]tc.DeliveryServiceRegexes, toclientlib.ReqInf, error)

func (*TOClient) GetDeliveryServiceRequiredCapabilitiesByID

func (cl *TOClient) GetDeliveryServiceRequiredCapabilitiesByID(dsIDs []int, reqHdr http.Header) (map[int]map[atscfg.ServerCapability]struct{}, toclientlib.ReqInf, error)

func (*TOClient) GetDeliveryServiceServers

func (cl *TOClient) GetDeliveryServiceServers(dsIDs []int, serverIDs []int, cdnName string, reqHdr http.Header) ([]tc.DeliveryServiceServer, toclientlib.ReqInf, error)

func (*TOClient) GetGlobalParameters

func (cl *TOClient) GetGlobalParameters(reqHdr http.Header) ([]tc.Parameter, toclientlib.ReqInf, error)

func (*TOClient) GetJobs

func (cl *TOClient) GetJobs(reqHdr http.Header, cdnName string) ([]atscfg.InvalidationJob, toclientlib.ReqInf, error)

func (*TOClient) GetJobsCompat

func (cl *TOClient) GetJobsCompat(opts toclient.RequestOptions) (tc.InvalidationJobsResponseV4, toclientlib.ReqInf, error)

GetJobsCompat gets jobs from any Traffic Ops built from the ATC `master` branch, and converts the different formats to the latest. This makes t3c work with old or new Traffic Ops deployed from `master`, though it doesn't make a version of t3c older than this work with a new TO, which isn't logically possible from the client.

func (*TOClient) GetParametersByName

func (cl *TOClient) GetParametersByName(paramName string, reqHdr http.Header) ([]tc.Parameter, toclientlib.ReqInf, error)

func (*TOClient) GetProfileByName

func (cl *TOClient) GetProfileByName(profileName string, reqHdr http.Header) (tc.Profile, toclientlib.ReqInf, error)

func (*TOClient) GetServerByHostName

func (cl *TOClient) GetServerByHostName(serverHostName string, reqHdr http.Header) (*atscfg.Server, toclientlib.ReqInf, error)

func (*TOClient) GetServerCapabilitiesByID

func (cl *TOClient) GetServerCapabilitiesByID(serverIDs []int, reqHdr http.Header) (map[int]map[atscfg.ServerCapability]struct{}, toclientlib.ReqInf, error)

func (*TOClient) GetServerProfileParameters

func (cl *TOClient) GetServerProfileParameters(profileName string, reqHdr http.Header) ([]tc.Parameter, toclientlib.ReqInf, error)

func (*TOClient) GetServerUpdateStatus

func (cl *TOClient) GetServerUpdateStatus(cacheHostName tc.CacheName, reqHdr http.Header) (atscfg.ServerUpdateStatus, toclientlib.ReqInf, error)

GetServerUpdateStatus returns the data, the Traffic Ops address, and any error.

func (*TOClient) GetServers

func (cl *TOClient) GetServers(reqHdr http.Header) ([]atscfg.Server, toclientlib.ReqInf, error)

func (*TOClient) GetServersCompat

func (cl *TOClient) GetServersCompat(opts toclient.RequestOptions) (tc.ServersV4Response, toclientlib.ReqInf, error)

GetServersCompat gets servers from any Traffic Ops built from the ATC `master` branch, and converts the different formats to the latest. This makes t3c work with old or new Traffic Ops deployed from `master`, though it doesn't make a version of t3c older than this work with a new TO, which isn't logically possible from the client.

func (*TOClient) GetStatuses

func (cl *TOClient) GetStatuses(reqHdr http.Header) ([]tc.Status, toclientlib.ReqInf, error)

func (*TOClient) GetTopologies

func (cl *TOClient) GetTopologies(reqHdr http.Header) ([]tc.Topology, toclientlib.ReqInf, error)

GetTopologies returns the data, the Traffic Ops address, and any error.

func (*TOClient) GetURISigningKeys

func (cl *TOClient) GetURISigningKeys(dsName string, reqHdr http.Header) ([]byte, toclientlib.ReqInf, error)

func (*TOClient) GetURLSigKeys

func (cl *TOClient) GetURLSigKeys(dsName string, reqHdr http.Header) (tc.URLSigKeys, toclientlib.ReqInf, error)

func (*TOClient) HTTPClient

func (cl *TOClient) HTTPClient() *http.Client

func (*TOClient) SetServerUpdateStatus

func (cl *TOClient) SetServerUpdateStatus(cacheHostName tc.CacheName, configApply, revalApply *time.Time) (toclientlib.ReqInf, error)

SetServerUpdateStatus sets the server's update and reval statuses in Traffic Ops.

func (*TOClient) SetServerUpdateStatusBoolCompat

func (cl *TOClient) SetServerUpdateStatusBoolCompat(cacheHostName tc.CacheName, configApply *time.Time, revalApply *time.Time, configApplyBool *bool, revalApplyBool *bool) (toclientlib.ReqInf, error)

SetServerUpdateStatusBoolCompat sets the server's update and reval statuses in Traffic Ops. *** Compatability requirement until ATC (v7.0+) is deployed with the timestamp features

func (*TOClient) SetServerUpdateStatusCompat

func (cl *TOClient) SetServerUpdateStatusCompat(serverName string, configApplyTime, revalApplyTime *time.Time, configApplyBool, revalApplyBool *bool, opts toclient.RequestOptions) (tc.Alerts, toclientlib.ReqInf, error)

SetServerUpdateStatusCompat is a bridge to send both styles of query parameters to the TO endpoint /servers/{hostname-or-id}/update. The current (old) is to send a bool value, however this has resulted in an accidental race condition. The attempt to fix this is to send a timestamp representing when the config or revalidation changes have been applied.

To ensure T3C is compatible with both the current releases and future releases this function will send both "styles". Once both T3C and TO have been deployed with the timestamp only V4 TO API endpoint, this function can be removed and the V4 client function `SetUpdateServerStatusTimes` may be used instead (as intended). *** Compatability requirement until ATC (v7.0+) is deployed with the timestamp features

func (*TOClient) SetURL

func (cl *TOClient) SetURL(newURL string)

func (*TOClient) URL

func (cl *TOClient) URL() string

func (*TOClient) WriteFsCookie

func (cl *TOClient) WriteFsCookie(fileName string)

Directories

Path Synopsis
Package toreqold calls the previous Traffic Ops API major version.
Package toreqold calls the previous Traffic Ops API major version.
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