// apiProcessor is called for every request. It processes the request
// and forwards to the originator of the secrets service after
// authenticating that the client can access the service.
492607
func (s *SecretsProxy) apiProcessor(w http.ResponseWriter, r *http.Request) {
	zap.L().Info("Processing secrets call",
		zap.String("URI", r.RequestURI),
		zap.String("Host", r.Host),
		zap.String("Remote address", r.RemoteAddr),
	)

	// The remote address will contain the uid, gid and pid of the calling process.
	// This is because of the specific socket listener we are uing.
	parts := strings.Split(r.RemoteAddr, ":")
	if len(parts) != 3 {
		httpError(w, fmt.Errorf("Bad Remote Address"), "Unauthorized request", http.StatusUnauthorized)
		return
	}

	// We only care about the originating PID.
	pid := parts[2]
	cgroup, err := findParentCgroup(pid)
	if err != nil {
		httpError(w, err, "Unauthorized client - not the first process", http.StatusUnauthorized)
		return
	}

	data, err := s.apiCacheMapping.Get(cgroup)
	if err != nil {
		httpError(w, err, "Unauthorized client", http.StatusUnauthorized)
		return
	}

	// Find the corresponding API cache with the access permissions for
	// this particular client.
	apiCache, ok := data.(*urisearch.APICache)
	if !ok {
		httpError(w, fmt.Errorf("Invalid data types"), "Internal server error - invalid type", http.StatusInternalServerError)
		return
	}

	// Find the identity of the PU
	policyData, err := s.policyCache.Get(cgroup)
	if err != nil {
		httpError(w, err, "Unauthorized client", http.StatusUnauthorized)
		return
	}

	scopes, ok := policyData.([]string)
	if !ok {
		httpError(w, fmt.Errorf("Invalid data types"), "Internal server error - invalid type", http.StatusInternalServerError)
		return
	}

	// Search the API cache for matching rules.
	found, _ := apiCache.FindAndMatchScope(r.Method, r.RequestURI, scopes)
	if !found {
		httpError(w, fmt.Errorf("Unauthorized service"), "Unauthorized access", http.StatusUnauthorized)
		return
	}

	// Retrieve the secrets driver data and information.
	driverData, err := s.drivers.Get(cgroup)
	if err != nil {
		httpError(w, err, "No secrets driver for this client", http.StatusBadRequest)
		return
	}
	driver, ok := driverData.(SecretsDriver)
	if !ok {
		httpError(w, fmt.Errorf("driver not found"), "Bad driver", http.StatusInternalServerError)
		return
	}

	// Transfor the request based on the driver.
	if err := driver.Transform(r); err != nil {
		httpError(w, err, "Secrets driver error", http.StatusInternalServerError)
		return
	}

	// Forward the request. TODO .. we need to massage the return here.
	forwarder, err := forward.New(forward.RoundTripper(driver.Transport()))
	if err != nil {
		httpError(w, err, "Failed to configure forwarder", http.StatusInternalServerError)
		return
	}

	forwarder.ServeHTTP(w, r)
}
1065093
func (p *ProcessingResult) Proto() (*api.Processor, error) {
	out := &api.Processor{Id: p.ProcID}

	if p.CreatedTs.IsZero() {
		out.State = api.Processor_PENDING // no result yet
		return out, nil
	}
	out.FinishedTs = google.NewTimestamp(p.CreatedTs)

	if p.Success {
		out.State = api.Processor_SUCCEEDED
		res := &structpb.Struct{}
		if err := p.ReadResultIntoStruct(res); err != nil {
			return nil, err
		}
		if len(res.Fields) != 0 {
			out.Result = res
		}
	} else {
		out.State = api.Processor_FAILED
		out.Error = p.Error
	}

	return out, nil
}
914229
func (q *BaseQueue) SetProcessor(processor Processor) {
	q.pmu.Lock()
	defer q.pmu.Unlock()

	q.processor = processor
}
95117
func (s *specAggregator) GetAPIServiceInfo(apiServiceName string) (handler http.Handler, etag string, exists bool) {
	s.rwMutex.RLock()
	defer s.rwMutex.RUnlock()

	if info, existingService := s.openAPISpecs[apiServiceName]; existingService {
		return info.handler, info.etag, true
	}
	return nil, "", false
}
565960
func (n *Node) startInProc(apis []rpc.API) error {
	// Register all the APIs exposed by the services
	handler := rpc.NewServer()
	for _, api := range apis {
		if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
			return err
		}
		n.log.Debug("InProc registered", "namespace", api.Namespace)
	}
	n.inprocHandler = handler
	return nil
}
616571
func (r *proxyHandler) updateAPIService(apiService *apiregistrationapi.APIService) {
	if apiService.Spec.Service == nil {
		r.handlingInfo.Store(proxyHandlingInfo{local: true})
		return
	}

	newInfo := proxyHandlingInfo{
		name: apiService.Name,
		restConfig: &restclient.Config{
			TLSClientConfig: restclient.TLSClientConfig{
				Insecure:   apiService.Spec.InsecureSkipTLSVerify,
				ServerName: apiService.Spec.Service.Name + "." + apiService.Spec.Service.Namespace + ".svc",
				CertData:   r.proxyClientCert,
				KeyData:    r.proxyClientKey,
				CAData:     apiService.Spec.CABundle,
			},
		},
		serviceName:      apiService.Spec.Service.Name,
		serviceNamespace: apiService.Spec.Service.Namespace,
		servicePort:      apiService.Spec.Service.Port,
		serviceAvailable: apiregistrationapi.IsAPIServiceConditionTrue(apiService, apiregistrationapi.Available),
	}
	if r.proxyTransport != nil && r.proxyTransport.DialContext != nil {
		newInfo.restConfig.Dial = r.proxyTransport.DialContext
	}
	newInfo.proxyRoundTripper, newInfo.transportBuildingError = restclient.TransportFor(newInfo.restConfig)
	if newInfo.transportBuildingError != nil {
		klog.Warning(newInfo.transportBuildingError.Error())
	}
	r.handlingInfo.Store(newInfo)
}
33280
func (c *templateProcessor) Process(in *templatev1.Template) (*templatev1.Template, error) {
	template := &templatev1.Template{}
	err := c.client.Post().
		Namespace(c.ns).
		Resource("processedTemplates").
		Body(in).Do().Into(template)
	return template, err
}
761153
func DialInProc(handler *Server) *Client {
	initctx := context.Background()
	c, _ := newClient(initctx, func(context.Context) (ServerCodec, error) {
		p1, p2 := net.Pipe()
		go handler.ServeCodec(NewJSONCodec(p1), OptionMethodInvocation|OptionSubscriptions)
		return NewJSONCodec(p2), nil
	})
	return c
}
1190512
func NewAPIAddresser(getter AddressAndCertGetter, resources facade.Resources) *APIAddresser {
	return &APIAddresser{
		getter:    getter,
		resources: resources,
	}
}
1217518
func (f ProcessorFunc) Process(nim image.Image, params imageserver.Params) (image.Image, error) {
	return f(nim, params)
}
1262777
func (d *DockerMonitor) eventProcessors(ctx context.Context) {

	for i := 0; i < d.numberOfQueues; i++ {
		go func(i int) {
			for {
				select {
				case event := <-d.eventnotifications[i]:
					if f, ok := d.handlers[Event(event.Action)]; ok {
						if err := f(ctx, event); err != nil {
							zap.L().Error("Unable to handle docker event",
								zap.String("action", event.Action),
								zap.Error(err),
							)
						}
						continue
					}
				case <-ctx.Done():
					return
				}
			}
		}(i)
	}
}
832903
func (l *Synchronizer) PostProcess(processing map[string]struct{}) {
	// Get all locally stored data
	nodes, err := l.GetAll()
	if err != nil {
		glog.Warningf("Could not access locally stored data: %s", err)
		return
	}

	// Delete any local nodes that do not exist remotely and are not in process
	for _, node := range nodes {
		if _, ok := processing[node.GetID()]; ok {
			// pass
		} else if err := l.Delete(node.GetID()); err != nil {
			glog.Warningf("Could not delete %s from locally stored data: %s", node.GetID(), err)
		}
	}
}
352189
func HTTPProvider(servers map[string]string, cache cache.Cache) Provider {
	return &httpProvider{
		servers: servers,
		cache:   cache,
	}
}
1082960
func WrapProcessorFunc(f func(fin string) string) ProcessorFunc {
	return func(in string) (string, bool) {
		return f(in), true
	}
}
875034
func (v *version) APIServices() APIServiceInformer {
	return &aPIServiceInformer{factory: v.factory, tweakListOptions: v.tweakListOptions}
}
28506
func (m *Method) postProcess(r *Resource, name string, traitsMap map[string]Trait, apiDef *APIDefinition) {
	m.Name = name
	m.inheritFromTraits(r, append(r.Is, m.Is...), traitsMap, apiDef)
	r.Methods = append(r.Methods, m)

	// post process the responses
	resps := make(map[HTTPCode]Response)
	for code, resp := range m.Responses {
		resp.postProcess()
		resps[code] = resp
	}
	m.Responses = resps

	// post process request body
	m.Bodies.postProcess()
}
666183
func (m method) ServerProcParams() string {
	var params []string

	for _, p := range cr.GetResourceParams(m.Resource) {
		params = append(params, p+": string")
	}

	params = append(params, "req: Request")
	return strings.Join(params, ", ")
}