func GetDeliveryServices()

in traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go [1944:2094]


func GetDeliveryServices(query string, queryValues map[string]interface{}, tx *sqlx.Tx) ([]DSWithLegacyFields, error, error, int) {
	rows, err := tx.NamedQuery(query, queryValues)
	if err != nil {
		return nil, nil, fmt.Errorf("querying: %w", err), http.StatusInternalServerError
	}
	defer log.Close(rows, "getting Delivery Services")

	dses := []DSWithLegacyFields{}
	dsCDNDomains := map[string]string{}

	// ensure json generated from this slice won't come out as `null` if empty
	dsQueryParams := []string{}

	geoLimitCountries := new(string)
	for rows.Next() {
		var ds tc.DeliveryServiceV5
		var longDesc1 *string
		var longDesc2 *string
		var cdnDomain string
		err := rows.Scan(
			&ds.Active,
			&ds.AnonymousBlockingEnabled,
			&ds.CCRDNSTTL,
			&ds.CDNID,
			&ds.CDNName,
			&ds.CheckPath,
			&ds.ConsistentHashRegex,
			&ds.DeepCachingType,
			&ds.DisplayName,
			&ds.DNSBypassCNAME,
			&ds.DNSBypassIP,
			&ds.DNSBypassIP6,
			&ds.DNSBypassTTL,
			&ds.DSCP,
			&ds.EcsEnabled,
			&ds.EdgeHeaderRewrite,
			&ds.FirstHeaderRewrite,
			&ds.GeoLimitRedirectURL,
			&ds.GeoLimit,
			&geoLimitCountries,
			&ds.GeoProvider,
			&ds.GlobalMaxMBPS,
			&ds.GlobalMaxTPS,
			&ds.FQPacingRate,
			&ds.HTTPBypassFQDN,
			&ds.ID,
			&ds.InfoURL,
			&ds.InitialDispersion,
			&ds.InnerHeaderRewrite,
			&ds.IPV6RoutingEnabled,
			&ds.LastHeaderRewrite,
			&ds.LastUpdated,
			&ds.LogsEnabled,
			&ds.LongDesc,
			&longDesc1,
			&longDesc2,
			&ds.MaxDNSAnswers,
			&ds.MaxOriginConnections,
			&ds.MaxRequestHeaderBytes,
			&ds.MidHeaderRewrite,
			&ds.MissLat,
			&ds.MissLong,
			&ds.MultiSiteOrigin,
			&ds.OrgServerFQDN,
			&ds.OriginShield,
			&ds.ProfileID,
			&ds.ProfileName,
			&ds.ProfileDesc,
			&ds.Protocol,
			&ds.QStringIgnore,
			pq.Array(&dsQueryParams),
			&ds.RangeRequestHandling,
			&ds.RegexRemap,
			&ds.Regional,
			&ds.RegionalGeoBlocking,
			&ds.RemapText,
			pq.Array(&ds.RequiredCapabilities),
			&ds.RoutingName,
			&ds.ServiceCategory,
			&ds.SigningAlgorithm,
			&ds.RangeSliceBlockSize,
			&ds.SSLKeyVersion,
			&ds.TenantID,
			&ds.Tenant,
			pq.Array(&ds.TLSVersions),
			&ds.Topology,
			&ds.TRRequestHeaders,
			&ds.TRResponseHeaders,
			&ds.Type,
			&ds.TypeID,
			&ds.XMLID,
			&cdnDomain)

		if err != nil {
			return nil, nil, fmt.Errorf("getting delivery services: %w", err), http.StatusInternalServerError
		}

		if geoLimitCountries != nil && *geoLimitCountries != "" {
			geo := strings.Split(*geoLimitCountries, ",")
			ds.GeoLimitCountries = geo
		}
		ds.ConsistentHashQueryParams = make([]string, 0, len(dsQueryParams))
		// ensure unique and in consistent order
		m := make(map[string]struct{}, len(dsQueryParams))
		for _, k := range dsQueryParams {
			if _, exists := m[k]; exists {
				continue
			}
			m[k] = struct{}{}
			ds.ConsistentHashQueryParams = append(ds.ConsistentHashQueryParams, k)
		}

		dsCDNDomains[ds.XMLID] = cdnDomain
		ds.DeepCachingType = tc.DeepCachingTypeFromString(string(ds.DeepCachingType))

		ds.Signed = ds.SigningAlgorithm != nil && *ds.SigningAlgorithm == tc.SigningAlgorithmURLSig

		if len(ds.TLSVersions) < 1 {
			ds.TLSVersions = nil
		}

		dses = append(dses, DSWithLegacyFields{
			DS:        ds,
			LongDesc1: longDesc1,
			LongDesc2: longDesc2,
		})
	}

	dsNames := make([]string, len(dses))
	for i, ds := range dses {
		dsNames[i] = ds.DS.XMLID
	}

	matchLists, err := GetDeliveryServicesMatchLists(dsNames, tx.Tx)
	if err != nil {
		return nil, nil, fmt.Errorf("getting delivery service matchlists: %w", err), http.StatusInternalServerError
	}
	for i, d := range dses {
		ds := d.DS
		matchList, ok := matchLists[ds.XMLID]
		if !ok {
			continue
		}
		ds.MatchList = matchList
		ds.ExampleURLs = MakeExampleURLs(ds.Protocol, tc.DSType(*ds.Type), ds.RoutingName, ds.MatchList, dsCDNDomains[ds.XMLID])
		d.DS = ds
		dses[i] = d
	}

	return dses, nil, nil, http.StatusOK
}