// AddPublicEndpointPort provides a mock function with given fields: serviceid, endpointName, portAddr, usetls, protocol, isEnabled, restart
504062
func (_m *ClientInterface) AddPublicEndpointPort(serviceid string, endpointName string, portAddr string, usetls bool, protocol string, isEnabled bool, restart bool) (*servicedefinition.Port, error) {
	ret := _m.Called(serviceid, endpointName, portAddr, usetls, protocol, isEnabled, restart)

	var r0 *servicedefinition.Port
	if rf, ok := ret.Get(0).(func(string, string, string, bool, string, bool, bool) *servicedefinition.Port); ok {
		r0 = rf(serviceid, endpointName, portAddr, usetls, protocol, isEnabled, restart)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*servicedefinition.Port)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string, string, string, bool, string, bool, bool) error); ok {
		r1 = rf(serviceid, endpointName, portAddr, usetls, protocol, isEnabled, restart)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
834520
func (s *VpcConfigResponse) SetEndpointPublicAccess(v bool) *VpcConfigResponse {
	s.EndpointPublicAccess = &v
	return s
}
848813
func (c *ServicedCli) cmdPublicEndpointsPortList(ctx *cli.Context) {
	cmdPublicEndpointsList(c, ctx, false, true)
}
1136791
func (s *Server) AddPublicEndpointVHost(request *PublicEndpointRequest, reply *servicedefinition.VHost) error {
	vhost, err := s.f.AddPublicEndpointVHost(s.context(), request.Serviceid, request.EndpointName, request.Name,
		request.IsEnabled, request.Restart)
	if err != nil {
		return err
	}
	*reply = *vhost
	return err
}
187566
func (c *Client) AddPublicEndpointPort(serviceid, endpointName, portAddr string, usetls bool,
	protocol string, isEnabled bool, restart bool) (*servicedefinition.Port, error) {
	request := &PublicEndpointRequest{
		Serviceid:    serviceid,
		EndpointName: endpointName,
		Name:         portAddr,
		UseTLS:       usetls,
		Protocol:     protocol,
		IsEnabled:    isEnabled,
		Restart:      restart,
	}
	var result servicedefinition.Port
	err := c.call("AddPublicEndpointPort", request, &result)
	return &result, err
}
839417
func (c *Client) AddPublicEndpointVHost(serviceid, endpointName, vhost string, isEnabled,
	restart bool) (*servicedefinition.VHost, error) {
	request := &PublicEndpointRequest{
		Serviceid:    serviceid,
		EndpointName: endpointName,
		Name:         vhost,
		IsEnabled:    isEnabled,
		Restart:      restart,
	}
	var result servicedefinition.VHost
	err := c.call("AddPublicEndpointVHost", request, &result)
	return &result, err
}
496756
func (s *VPCRouterSetting) AddPortForwarding(protocol string, globalPort string, privateAddress string,
	privatePort string, description string) (int, *VPCRouterPortForwardingConfig) {
	if s.PortForwarding == nil {
		s.PortForwarding = &VPCRouterPortForwarding{
			Enabled: "True",
		}
	}

	if s.PortForwarding.Config == nil {
		s.PortForwarding.Config = []*VPCRouterPortForwardingConfig{}
	}

	c := &VPCRouterPortForwardingConfig{
		Protocol:       protocol,
		GlobalPort:     globalPort,
		PrivateAddress: privateAddress,
		PrivatePort:    privatePort,
		Description:    description,
	}

	s.PortForwarding.Config = append(s.PortForwarding.Config, c)

	return len(s.PortForwarding.Config) - 1, c
}
330568
func (p *PodContainer) AddEndpoint(endpoint *PodEndpoint) *PodContainer {
	p.Endpoints = append(p.Endpoints, endpoint)
	return p
}
1029734
func (proxier *Proxier) addServiceOnPort(service proxy.ServicePortName, protocol v1.Protocol, proxyPort int, timeout time.Duration) (*ServiceInfo, error) {
	proxier.mu.Lock()
	defer proxier.mu.Unlock()
	return proxier.addServiceOnPortInternal(service, protocol, proxyPort, timeout)
}
114494
func (f *Facade) AddPublicEndpointVHost(ctx datastore.Context, serviceid, endpointName, vhostName string, isEnabled, restart bool) (*servicedefinition.VHost, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.AddPublicEndpointVHost"))
	alog := f.auditLogger.Message(ctx, "Adding Public Endpoint VHost").Action(audit.Update).ID(serviceid).
		WithFields(logrus.Fields{
			"endpointname": endpointName,
			"vhostname":    vhostName,
			"isenabled":    isEnabled,
		})
	// Get the service for this service id.
	svc, err := f.GetService(ctx, serviceid)
	if err != nil {
		err = fmt.Errorf("Could not find service %s: %s", serviceid, err)
		glog.Error(err)
		return nil, alog.Error(err)
	}
	alog = alog.Entity(svc)

	// Make sure the name doesn't contain invalid characters.
	if !vhostNameRegex.MatchString(vhostName) {
		err = fmt.Errorf("Invalid virtual host name: %s", vhostName)
		glog.Error(err)
		return nil, alog.Error(err)
	}

	// check other virtual hosts for redundancy
	vhostLowerName := strings.ToLower(vhostName)

	// FIXME: GetAllServices is really expensive. Can this be replaced
	//        with a more targeted method like get-all-services with vhost "blah"?
	services, err := f.GetAllServices(ctx)
	if err != nil {
		err = fmt.Errorf("Could not get the list of services: %s", err)
		glog.Error(err)
		return nil, alog.Error(err)
	}

	for _, otherService := range services {
		if otherService.Endpoints == nil {
			continue
		}
		for _, endpoint := range otherService.Endpoints {
			for _, vhost := range endpoint.VHostList {
				if strings.ToLower(vhost.Name) == vhostLowerName {
					err := fmt.Errorf("vhost %s already defined for service: %s", vhostName, otherService.Name)
					glog.Error(err)
					return nil, alog.Error(err)
				}
			}
		}
	}

	vhost, err := svc.AddVirtualHost(endpointName, vhostName, isEnabled)
	if err != nil {
		err := fmt.Errorf("Error adding vhost (%s) to service (%s): %v", vhostName, svc.Name, err)
		glog.Error(err)
		return nil, alog.Error(err)
	}

	// Make sure no other service currently has zzk data for this vhost -- this would result
	// in the service getting turned off during restart but not being able to start again.
	if err := f.validateServiceStart(ctx, svc); err != nil {
		// We don't call UpdateService() service here; effectively unwinding the svc.AddVirtualHost() call above.
		glog.Error(err)
		return nil, alog.Error(err)
	}

	glog.V(2).Infof("Added vhost public endpoint %s to service %s", vhost.Name, svc.Name)

	if err = f.UpdateService(ctx, *svc); err != nil {
		glog.Error(err)
		return nil, alog.Error(err)
	}

	glog.V(2).Infof("Service (%s) updated", svc.Name)
	alog.Succeeded()
	return vhost, nil
}
1159176
func BuildServiceEndpoint(epd servicedefinition.EndpointDefinition) ServiceEndpoint {
	sep := ServiceEndpoint{}
	sep.Name = epd.Name
	sep.Purpose = epd.Purpose
	sep.Protocol = epd.Protocol
	sep.PortNumber = epd.PortNumber
	sep.PortTemplate = epd.PortTemplate
	sep.VirtualAddress = epd.VirtualAddress
	sep.Application = epd.Application
	sep.ApplicationTemplate = epd.ApplicationTemplate
	sep.AddressConfig = epd.AddressConfig
	sep.VHosts = epd.VHosts
	sep.VHostList = epd.VHostList
	sep.PortList = epd.PortList

	// run public ports through scrubber to allow for "almost correct" port addresses
	for index, port := range sep.PortList {
		sep.PortList[index].PortAddr = ScrubPortString(port.PortAddr)
	}
	return sep
}
994696
func (c *ServicedCli) createPublicEndpoints(ctx *cli.Context, services []service.Service,
	showVHosts bool, showPorts bool) ([]PublicEndpoint, error) {
	publicEndpoints := []PublicEndpoint{}

	// See if they provided the endpoint name
	epName := ""
	epFound := false
	if len(ctx.Args()) > 1 {
		epName = ctx.Args()[1]
	}

	// Iterate the list of services -> endpoints -> vhosts/ports
	for _, svc := range services {
		for _, ep := range svc.Endpoints {
			if epName != "" && epName != ep.Name {
				continue
			}
			epFound = true
			if showVHosts {
				for _, vhost := range ep.VHostList {
					publicEndpoint := NewPublicEndpoint(
						svc.Name,
						svc.ID,
						ep.Application,
						"vhost",
						"https",
						vhost.Name,
						vhost.Enabled,
					)
					publicEndpoints = append(publicEndpoints, publicEndpoint)
				}
			}
			if showPorts {
				for _, port := range ep.PortList {
					protocol := port.Protocol
					if protocol == "" {
						if port.UseTLS {
							protocol = "other-tls"
						} else {
							protocol = "other"
						}
					}
					publicEndpoint := NewPublicEndpoint(
						svc.Name,
						svc.ID,
						ep.Application,
						"port",
						protocol,
						port.PortAddr,
						port.Enabled,
					)
					publicEndpoints = append(publicEndpoints, publicEndpoint)
				}
			}
		}
	}

	if !epFound {
		return nil, fmt.Errorf("Endpoint '%s' not found", epName)
	}

	return publicEndpoints, nil
}
873092
func AddHostEntry(ip net.IP) error {
	key := NewEndpointKey(ip)
	ep := &EndpointInfo{Flags: EndpointFlagHost}
	return LXCMap.Update(key, ep)
}
165155
func buildPortsToEndpointsMap(endpoints *v1.Endpoints) map[string][]hostPortPair {
	portsToEndpoints := map[string][]hostPortPair{}
	for i := range endpoints.Subsets {
		ss := &endpoints.Subsets[i]
		for i := range ss.Ports {
			port := &ss.Ports[i]
			for i := range ss.Addresses {
				addr := &ss.Addresses[i]
				portsToEndpoints[port.Name] = append(portsToEndpoints[port.Name], hostPortPair{addr.IP, int(port.Port)})
				// Ignore the protocol field - we'll get that from the Service objects.
			}
		}
	}
	return portsToEndpoints
}
1317774
func AddEndpoint(owner endpoint.Owner, ep *endpoint.Endpoint, reason string) (err error) {
	alwaysEnforce := policy.GetPolicyEnabled() == option.AlwaysEnforce
	ep.SetDesiredIngressPolicyEnabled(alwaysEnforce)
	ep.SetDesiredEgressPolicyEnabled(alwaysEnforce)

	if ep.ID != 0 {
		return fmt.Errorf("Endpoint ID is already set to %d", ep.ID)
	}
	return Insert(ep)
}
485670
func MakePostAddressEndpoint(s Service) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (response interface{}, err error) {
		req := request.(postAddressRequest)
		e := s.PostAddress(ctx, req.ProfileID, req.Address)
		return postAddressResponse{Err: e}, nil
	}
}
995730
func (s *VpcConfigRequest) SetEndpointPublicAccess(v bool) *VpcConfigRequest {
	s.EndpointPublicAccess = &v
	return s
}