//Returns the login landing page constant with the service name and state passed through as a query parameter.  
//Note, the 'code' probably should not be passed through the client side code!
13207
func (self *SimplePageMapper) LoginLandingPage(conn OauthConnector, state string, code string) string {
	v := url.Values{
		"service": []string{conn.Name()},
		"state":   []string{state},
	}
	return fmt.Sprintf("%s?%s", self.loginOk, v.Encode())
}
1015069
func (ctx *context) URLParamDefault(name string, def string) string {
	if v := ctx.request.URL.Query().Get(name); v != "" {
		return v
	}

	return def
}
313543
func (d *Domain) GetLaunchSecurityInfo(flags uint32) (*DomainLaunchSecurityParameters, error) {
	if C.LIBVIR_VERSION_NUMBER < 4005000 {
		return nil, makeNotImplementedError("virDomainGetLaunchSecurityInfo")
	}

	params := &DomainLaunchSecurityParameters{}
	info := getDomainLaunchSecurityFieldInfo(params)

	var cparams *C.virTypedParameter
	var cnparams C.int

	var err C.virError
	ret := C.virDomainGetLaunchSecurityInfoWrapper(d.ptr, (*C.virTypedParameterPtr)(unsafe.Pointer(&cparams)), &cnparams, C.uint(flags), &err)
	if ret == -1 {
		return nil, makeError(&err)
	}

	defer C.virTypedParamsFree(cparams, cnparams)

	_, gerr := typedParamsUnpack(cparams, cnparams, info)
	if gerr != nil {
		return nil, gerr
	}

	return params, nil
}
310422
func (c *Controller) GetLogin() mvc.Result {
	if c.isLoggedIn() {
		return c.logout()
	}
	return userLoginView
}
346226
func (client *Client) GetRunstatusPage(ctx context.Context, page RunstatusPage) (*RunstatusPage, error) {
	if page.URL != "" {
		return client.getRunstatusPage(ctx, page.URL)
	}

	ps, err := client.ListRunstatusPages(ctx)
	if err != nil {
		return nil, err
	}

	for i := range ps {
		if ps[i].Match(page) {
			return client.getRunstatusPage(ctx, ps[i].URL)
		}
	}

	return nil, fmt.Errorf("%#v not found", page)
}
661424
func (f *Facade) GetServiceAddressAssignmentDetails(ctx datastore.Context, serviceID string, children bool) ([]service.IPAssignment, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.GetServiceAddressAssignmentDetails"))
	logger := plog.WithFields(log.Fields{
		"parentserviceid": serviceID,
		"children":        children,
	})

	// Get a list of all ip assignments in the entire system based on services with endpoints
	// (not records in the addressassignment store)
	allIPs, err := f.serviceStore.GetAllIPAssignments(ctx)
	if err != nil {
		logger.WithError(err).Error("Could not look up address assignments")
		return nil, err
	} else if len(allIPs) == 0 {
		return []service.IPAssignment{}, nil
	}

	// Build a map of those assignments which belong to the specified serviceID or any of its children
	serviceIPs := make(map[string]service.BaseIPAssignment)
	gs := func(id string) (*service.ServiceDetails, error) {
		return f.GetServiceDetails(ctx, id)
	}
	for _, ip := range allIPs {
		key := fmt.Sprintf("%s-%s", ip.ServiceID, ip.EndpointName)
		if _, ok := serviceIPs[key]; ok {
			continue
		}
		if ip.ServiceID == serviceID {
			serviceIPs[key] = ip
		} else if children {
			_, servicePath, err := f.serviceCache.GetServicePath(ip.ServiceID, gs)
			if err != nil {
				logger.WithError(err).WithField("serviceid", ip.ServiceID).Error("Could not find service")
				return nil, err
			}
			if strings.Contains(servicePath, serviceID) {
				serviceIPs[key] = ip
			}
		}
	}

	// For each service endpoint that needs an address assignement,
	// 	retrieve the corresponding assignment from the DB
	store := addressassignment.NewStore()
	ipAssignments := []service.IPAssignment{}
	for _, ip := range serviceIPs {
		servicelogger := logger.WithFields(log.Fields{
			"serviceid":    ip.ServiceID,
			"servicename":  ip.ServiceName,
			"poolid":       ip.PoolID,
			"endpointname": ip.EndpointName,
			"children":     children,
		})
		ipassignment := service.IPAssignment{
			BaseIPAssignment: ip,
		}
		addr, err := store.FindAssignmentByServiceEndpoint(ctx, ip.ServiceID, ip.EndpointName)
		if err != nil {
			err := fmt.Errorf("Can not find address assignment")
			servicelogger.WithFields(log.Fields{
				"endpointname": ip.EndpointName,
			}).WithError(err).Error("Address assignment lookup failed")
			return nil, err
		}

		if addr != nil {
			// Get the host info for the address assignment
			var hostID, hostName string
			if addr.AssignmentType == "virtual" {
				hostID, _ = f.zzk.GetVirtualIPHostID(ip.PoolID, addr.IPAddr)
			} else {
				hostID = addr.HostID
			}

			if hostID != "" {
				hst := &host.Host{}
				if err := f.hostStore.Get(ctx, host.HostKey(hostID), hst); err != nil {
					servicelogger.WithField("hostid", hostID).WithError(err).Debug("Could not look up host for address assignment")
					return nil, err
				}
				hostName = hst.Name
			}

			ipassignment.Type = addr.AssignmentType
			ipassignment.HostID = hostID
			ipassignment.HostName = hostName
			ipassignment.IPAddress = addr.IPAddr
			servicelogger.Debug("Set address assignment for service endpoint")
		} else {
			servicelogger.Debug("No address assignment available for service endpoint")
		}

		// Append a new record for the port
		ipAssignments = append(ipAssignments, ipassignment)
	}
	return ipAssignments, nil
}
179932
func GetGenericPassword(service string, account string, label string, accessGroup string) ([]byte, error) {
	query := NewItem()
	query.SetSecClass(SecClassGenericPassword)
	query.SetService(service)
	query.SetAccount(account)
	query.SetLabel(label)
	query.SetAccessGroup(accessGroup)
	query.SetMatchLimit(MatchLimitOne)
	query.SetReturnData(true)
	results, err := QueryItem(query)
	if err != nil {
		return nil, err
	}
	if len(results) > 1 {
		return nil, fmt.Errorf("Too many results")
	}
	if len(results) == 1 {
		return results[0].Data, nil
	}
	return nil, nil
}
1251216
func (g *SearchService) Code(uri *Hyperlink, uriParams M) (codeSearchResults *CodeSearchResults, result *Result) {
	url, err := ExpandWithDefault(uri, &CodeSearchURL, uriParams)
	if err != nil {
		return nil, &Result{Err: err}
	}

	result = g.client.get(url, &codeSearchResults)
	return
}
236345
func (ens *NetpluginNameServer) InspectState() (interface{}, error) {

	s := struct {
		SvcChan int                                       `json:"serviceQueue"`
		EpChan  int                                       `json:"endpointQueue"`
		Dtbl    map[string]map[string]map[string][]string `json:"dnsRecords"`
		Stats   map[string]map[string]uint64              `json:"stats"`
	}{SvcChan: len(ens.svcChan), EpChan: len(ens.epChan),
		Dtbl: ens.inspectNameRecord(), Stats: ens.inspectStats()}
	return &s, nil
}
510572
func (r *Request) QueryParameters(name string) []string {
	return r.Request.URL.Query()[name]
}
1221623
func GetServiceStateIDs(conn client.Connection, poolID, serviceID string) ([]StateRequest, error) {
	logger := plog.WithField("serviceid", serviceID)

	basepth := "/"
	if poolID != "" {
		basepth = path.Join("/pools", poolID)
	}

	spth := path.Join(basepth, "/services", serviceID)
	ch, err := conn.Children(spth)
	if err != nil && err != client.ErrNoNode {

		logger.WithError(err).Debug("Could not look up states on service")

		// TODO: wrap the error?
		return nil, err
	}

	states := make([]StateRequest, len(ch))
	for i, stateID := range ch {
		hostID, _, instanceID, err := ParseStateID(stateID)
		if err != nil {
			logger.WithField("stateid", stateID).WithError(err).Debug("Could not parse state")
			return nil, err
		}

		states[i] = StateRequest{
			PoolID:     poolID,
			HostID:     hostID,
			ServiceID:  serviceID,
			InstanceID: instanceID,
		}
	}

	logger.WithField("statecount", len(states)).Debug("Loaded state ids")
	return states, nil
}
1333711
func LoginProviderFrom(ctx context.Context) (name string, ok bool) {
	name, ok = ctx.Value(loginProviderNameKey).(string)
	return
}
746768
func (c *linkedInConnector) LoginURL(scopes connector.Scopes, callbackURL, state string) (string, error) {
	if c.oauth2Config.RedirectURL != callbackURL {
		return "", fmt.Errorf("expected callback URL %q did not match the URL in the config %q",
			callbackURL, c.oauth2Config.RedirectURL)
	}

	return c.oauth2Config.AuthCodeURL(state), nil
}
725331
func getLogEntry(req *http.Request) *logrus.Entry {
	return req.Context().Value(logCtxKey).(*logrus.Entry)
}
1114243
func (c *loginCommand) getKnownControllerDomain(name, controllerName string) (string, error) {
	if strings.Contains(name, ".") || strings.Contains(name, ":") {
		return "", errors.NotFoundf("controller %q", name)
	}
	baseURL := defaultJujuDirectory
	if u := os.Getenv("JUJU_DIRECTORY"); u != "" {
		baseURL = u
	}
	client, err := c.CommandBase.BakeryClient(c.ClientStore(), controllerName)
	if err != nil {
		return "", errors.Trace(err)
	}
	req, err := http.NewRequest("GET", baseURL+"/v1/controller/"+name, nil)
	if err != nil {
		return "", errors.Trace(err)
	}
	httpResp, err := client.Do(req)
	if err != nil {
		return "", errors.Trace(err)
	}
	defer httpResp.Body.Close()
	if httpResp.StatusCode != http.StatusOK {
		if httpResp.StatusCode == http.StatusNotFound {
			return "", errors.NotFoundf("controller %q", name)
		}
		return "", errors.Errorf("unexpected HTTP response %q", httpResp.Status)
	}
	var resp controllerDomainResponse
	if err := httprequest.UnmarshalJSONResponse(httpResp, &resp); err != nil {
		return "", errors.Trace(err)
	}
	if resp.Host == "" {
		return "", errors.Errorf("no host field found in response")
	}
	return resp.Host, nil
}
1293805
func (f *Facade) GetServiceDetailsByTenantID(ctx datastore.Context, tenantID string) ([]service.ServiceDetails, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.GetServiceDetailsByTenantID"))
	svcs, err := f.serviceStore.Query(ctx, service.Query{})
	if err != nil {
		return nil, err
	}
	return f.filterDetailsByTenantID(ctx, tenantID, svcs)
}
1150352
func GetConfigServiceAppID(c context.Context) (string, error) {
	s, err := FetchCachedSettings(c)
	switch {
	case err != nil:
		return "", err
	case s.ConfigServiceHost == "":
		return "", nil
	}
	info, err := signing.FetchServiceInfoFromLUCIService(c, "https://"+s.ConfigServiceHost)
	if err != nil {
		return "", err
	}
	return info.AppID, nil
}