// formatListEndpointsTabular returns a tabular summary of listed applications' endpoints.
511051
func formatListEndpointsTabular(writer io.Writer, offers offeredApplications) error {
	tw := output.TabWriter(writer)
	w := output.Wrapper{tw}

	// Sort offers by source then application name.
	allOffers := offerItems{}
	for _, offer := range offers {
		allOffers = append(allOffers, offer)
	}
	sort.Sort(allOffers)

	w.Println("Offer", "User", "Relation id", "Status", "Endpoint", "Interface", "Role", "Ingress subnets")
	for _, offer := range allOffers {
		// Sort endpoints alphabetically.
		endpoints := []string{}
		for endpoint := range offer.Endpoints {
			endpoints = append(endpoints, endpoint)
		}
		sort.Strings(endpoints)

		// Sort connections by relation id and username.
		sort.Sort(byUserRelationId(offer.Connections))

		// If there are no connections, print am empty row.
		if len(offer.Connections) == 0 {
			w.Println(offer.OfferName, "-", "", "", "", "", "", "")
		}

		for i, conn := range offer.Connections {
			if i == 0 {
				w.Print(offer.OfferName)
			} else {
				w.Print("")
			}
			endpoints := make(map[string]RemoteEndpoint)
			for alias, ep := range offer.Endpoints {
				aliasedEp := ep
				aliasedEp.Name = alias
				endpoints[ep.Name] = ep
			}
			connEp := endpoints[conn.Endpoint]
			w.Print(conn.Username, conn.RelationId)
			w.PrintColor(RelationStatusColor(relation.Status(conn.Status.Current)), conn.Status.Current)
			w.Println(connEp.Name, connEp.Interface, connEp.Role, strings.Join(conn.IngressSubnets, ","))
		}
	}
	tw.Flush()
	return nil
}
399827
func (c *EndpointsController) List(ctx *app.ListEndpointsContext) error {
	c.endpointsLock.Lock()
	defer c.endpointsLock.Unlock()
	if c.endpoints == nil {
		endpoints, err := getEndpoints(ctx, c.FileHandler)
		if err != nil || endpoints == nil {
			log.Error(ctx, map[string]interface{}{
				"err":  errs.WithStack(err),
				"file": embeddedSwaggerSpecFile,
			}, err.Error())
			return jsonapi.JSONErrorResponse(ctx, errs.WithStack(err))
		}
		c.endpoints = endpoints
	}
	return ctx.OK(&app.EndpointSingle{Data: c.endpoints})
}
141689
func BuildEndpointReports(appEndpoints []ApplicationEndpoint) []EndpointReport {
	endpoints := make([]EndpointReport, 0)
	for _, appEndpoint := range appEndpoints {
		endpoints = append(endpoints, EndpointReport{Endpoint: appEndpoint, Messages: []string{}})
	}
	return endpoints
}
6831
func (c *Config) WithEndpoint(endpoint string) *Config {
	c.Endpoint = &endpoint
	return c
}
407606
func (s *StoreToEndpointsLister) List() (services api.EndpointsList, err error) {
	for _, m := range s.Store.List() {
		services.Items = append(services.Items, *(m.(*api.Endpoints)))
	}
	return services, nil
}
1123511
func (p *Proxy) addToEndpointList(ctx context.Context, r string) error {
	rgx, err := regexp.Compile(r)
	if err == nil {
		p.mutex.Lock()
		p.endpointBlackList = append(p.endpointBlackList, rgx)
		p.mutex.Unlock()
	}
	return err
}
106465
func (policylist *PolicyList) AddEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
	operation := "AddEndpoint"
	title := "hcsshim::PolicyList::" + operation
	logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)

	_, err := policylist.Delete()
	if err != nil {
		return nil, err
	}

	// Add Endpoint to the Existing List
	policylist.EndpointReferences = append(policylist.EndpointReferences, "/endpoints/"+endpoint.Id)

	return policylist.Create()
}
915482
func (a *API) setMetadataEndpointsKey() {
	if len(a.Metadata.EndpointsID) != 0 {
		return
	}

	if v, ok := custEndpointsKey[a.PackageName()]; ok {
		a.Metadata.EndpointsID = v
	} else {
		a.Metadata.EndpointsID = a.Metadata.EndpointPrefix
	}
}
1065380
func ParseEndpointType(str string) EndpointType {
	str = strings.ToLower(str)
	switch str {
	case "unix":
		return UnixEndpoint
	case "tcp":
		return TCPEndpoint
	}
	return UnknownEndpointType
}
170557
func formatListSummary(writer io.Writer, value interface{}) error {
	offers, ok := value.(offeredApplications)
	if !ok {
		return errors.Errorf("expected value of type %T, got %T", offers, value)
	}
	return formatListEndpointsSummary(writer, offers)
}
694284
func (s endpointsNamespaceLister) List(selector labels.Selector) (ret []*v1.Endpoints, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.Endpoints))
	})
	return ret, err
}
478475
func (s *ListedServer) SetEndpointType(v string) *ListedServer {
	s.EndpointType = &v
	return s
}
885964
func (e *EgressRule) GetDestinationEndpointSelectors() EndpointSelectorSlice {
	if e.aggregatedSelectors == nil {
		e.SetAggregatedSelectors()
	}
	return e.aggregatedSelectors
}
1246467
func (a *Application) EndpointBindings() (map[string]string, error) {
	// We don't need the TxnRevno below.
	bindings, _, err := readEndpointBindings(a.st, a.globalKey())
	if err != nil && !errors.IsNotFound(err) {
		return nil, errors.Trace(err)
	}
	if bindings == nil {
		bindings, err = a.defaultEndpointBindings()
		if err != nil {
			return nil, errors.Trace(err)
		}
	}
	return bindings, nil
}
110255
func (m *MockCoreV1Interface) Endpoints(arg0 string) v11.EndpointsInterface {
	ret := m.ctrl.Call(m, "Endpoints", arg0)
	ret0, _ := ret[0].(v11.EndpointsInterface)
	return ret0
}
1061575
func (a *Application) defaultEndpointBindings() (map[string]string, error) {
	if a.doc.CharmURL == nil {
		return map[string]string{}, nil
	}

	appCharm, _, err := a.Charm()
	if err != nil {
		return nil, errors.Trace(err)
	}

	return DefaultEndpointBindingsForCharm(appCharm.Meta()), nil
}
915641
func formatEndpoints(endpoints *corev1.Endpoints, ports sets.String) string {
	if len(endpoints.Subsets) == 0 {
		return "<none>"
	}
	list := []string{}
	max := 3
	more := false
	count := 0
	for i := range endpoints.Subsets {
		ss := &endpoints.Subsets[i]
		if len(ss.Ports) == 0 {
			// It's possible to have headless services with no ports.
			for i := range ss.Addresses {
				if len(list) == max {
					more = true
				}
				if !more {
					list = append(list, ss.Addresses[i].IP)
				}
				count++
			}
		} else {
			// "Normal" services with ports defined.
			for i := range ss.Ports {
				port := &ss.Ports[i]
				if ports == nil || ports.Has(port.Name) {
					for i := range ss.Addresses {
						if len(list) == max {
							more = true
						}
						addr := &ss.Addresses[i]
						if !more {
							hostPort := net.JoinHostPort(addr.IP, strconv.Itoa(int(port.Port)))
							list = append(list, hostPort)
						}
						count++
					}
				}
			}
		}
	}
	ret := strings.Join(list, ",")
	if more {
		return fmt.Sprintf("%s + %d more...", ret, count-max)
	}
	return ret
}