in lib/dam/dam.go [881:943]
func makeViewInterfaces(srcView *pb.View, srcRes *pb.Resource, cfg *pb.DamConfig, tas *adapter.ServiceAdapters) map[string]*pb.Interface {
out := make(map[string]*pb.Interface)
entries, err := resolveAggregates(srcRes, srcView, cfg, tas)
if err != nil {
return out
}
// Map of <client_interface_name>.<interface_uri>.<label_name>.<label_value>.
cliMap := make(map[string]map[string]map[string]string)
for _, entry := range entries {
st, ok := cfg.ServiceTemplates[entry.View.ServiceTemplate]
if !ok {
return out
}
for _, item := range entry.View.Items {
vars, _, err := adapter.GetItemVariables(tas, st.ServiceName, item)
if err != nil {
return out
}
for client, uriFmt := range st.Interfaces {
uriMap, ok := cliMap[client]
if !ok {
uriMap = make(map[string]map[string]string)
cliMap[client] = uriMap
}
for k, v := range vars {
uriFmt = strings.Replace(uriFmt, "${"+k+"}", v, -1)
}
if !hasItemVariable(uriFmt) {
// Accept this string that has no more variables to replace.
uriMap[uriFmt] = srcView.Labels
if srcView.Labels == nil || srcView.Labels["platform"] == "" || len(item.Labels) > 0 {
// Merge label lists for this item, with item.Labels overriding any view.Labels.
labels := make(map[string]string)
for k, v := range srcView.Labels {
labels[k] = v
}
for k, v := range item.Labels {
labels[k] = v
}
if desc := tas.Descriptors[st.ServiceName]; desc != nil {
labels["platform"] = desc.Platform
}
uriMap[uriFmt] = labels
}
}
}
}
}
for k, v := range cliMap {
vi := &pb.Interface{
Uri: []string{},
}
for uri, labels := range v {
vi.Uri = append(vi.Uri, uri)
if len(labels) > 0 {
vi.Labels = labels
}
}
sort.Strings(vi.Uri)
out[k] = vi
}
return out
}