// GrantNeeded implements the GrantHandler interface
351470
func (g *redirectGrant) GrantNeeded(user user.Info, grant *api.Grant, w http.ResponseWriter, req *http.Request) (bool, bool, error) {
	_, lastSegment := path.Split(req.URL.Path)

	// We're going to descend one dir for the approve endpoint.
	// Make our "then" URL a relative backstep, so we can return to this URL (with no trailing slash) even via an auth proxy.
	// Depends on any auth proxies matching the last segment of the URL we used to get here, proxying subpaths of this URL, and passing through the complete query.
	// Example:
	//   User -> https://auth.example.com/foo/oauth/authorize?... -> https://api.example.com/oauth/authorize?...
	//        <- Location: authorize/approve?then=../authorize?...
	//   User -> https://auth.example.com/foo/oauth/authorize/approve?then=../authorize?...
	//           submits grant approval form, gets redirected to 'then' URL
	//        <- Location: ../authorize?...
	//   User -> https://auth.example.com/foo/oauth/authorize?...
	reqURL := &(*req.URL)
	reqURL.Host = ""
	reqURL.Scheme = ""
	reqURL.Path = path.Join("..", lastSegment)

	// Make our redirect URL a relative redirect to the subpath
	redirectURL := &url.URL{
		Path: path.Join(lastSegment, g.subpath),
		RawQuery: url.Values{
			"then":         {reqURL.String()},
			"client_id":    {grant.Client.GetId()},
			"scope":        {grant.Scope},
			"redirect_uri": {grant.RedirectURI},
		}.Encode(),
	}
	w.Header().Set("Location", redirectURL.String())
	w.WriteHeader(http.StatusFound)
	return false, true, nil
}
1363320
func (s *S3Grant) SetGrantee(v *S3Grantee) *S3Grant {
	s.Grantee = v
	return s
}
1196365
func (conn *Connection) GrantRole(username string, role string,
	auth Auth) (string, error) {
	userDb := conn.SelectDB("_users", auth)
	namestring := "org.couchdb.user:" + username
	var userData interface{}

	rev, err := userDb.Read(namestring, &userData, nil)
	if err != nil {
		return "", err
	}
	if reflect.ValueOf(userData).Kind() != reflect.Map {
		return "", errors.New("Type Error")
	}
	userMap := userData.(map[string]interface{})
	if reflect.ValueOf(userMap["roles"]).Kind() != reflect.Slice {
		return "", errors.New("Type Error")
	}
	userRoles := userMap["roles"].([]interface{})
	//Check if our role is already in the array, so we don't add it twice
	for _, r := range userRoles {
		if r == role {
			return rev, nil
		}
	}
	userMap["roles"] = append(userRoles, role)
	return userDb.Save(&userMap, namestring, rev)
}
25346
func (r *runner) printStageEndIfNeeded(ctx context.Context) {
	r.printStageLock.Lock()
	defer r.printStageLock.Unlock()
	// go-git grabs the lock right after plumbing.StatusIndexOffset, but before
	// sending the Done status update. As a result, it would look like we are
	// flushing the journal before plumbing.StatusIndexOffset is done. So
	// instead, print "done." only if it's not printed yet.
	if r.needPrintDone {
		elapsedStr := r.getElapsedStr(ctx,
			r.stageStartTime, r.stageMemProfName, r.stageCPUProfPath)
		r.errput.Write([]byte("done." + elapsedStr + "\n"))
		r.needPrintDone = false
	}
}
931951
func (s *MultipartUpload) SetInitiated(v time.Time) *MultipartUpload {
	s.Initiated = &v
	return s
}
93692
func (r *Replicator) IsReplicationNeeded() (bool, error) {
	systemChannelLedger, err := r.LedgerFactory.GetOrCreate(r.SystemChannel)
	if err != nil {
		return false, err
	}

	height := systemChannelLedger.Height()
	var lastBlockSeq uint64
	// If Height is 0 then lastBlockSeq would be 2^64 - 1,
	// so make it 0 to take care of the overflow.
	if height == 0 {
		lastBlockSeq = 0
	} else {
		lastBlockSeq = height - 1
	}

	if r.BootBlock.Header.Number > lastBlockSeq {
		return true, nil
	}
	return false, nil
}
1135236
func (l Listener) OnPermissionDenied(e *gumble.PermissionDeniedEvent) {
	if l.PermissionDenied != nil {
		l.PermissionDenied(e)
	}
}
494334
func (l *TeamLoader) checkNeededSeqnos(ctx context.Context,
	state *keybase1.TeamData, needSeqnos []keybase1.Seqno) error {

	if len(needSeqnos) == 0 {
		return nil
	}
	if state == nil {
		return fmt.Errorf("nil team does not contain needed seqnos")
	}

	for _, seqno := range needSeqnos {
		if (TeamSigChainState{inner: state.Chain}).HasStubbedSeqno(seqno) {
			return fmt.Errorf("needed seqno is stubbed: %v", seqno)
		}
	}
	return nil
}
862572
func (s *UpdateMatchmakingConfigurationInput) SetAcceptanceRequired(v bool) *UpdateMatchmakingConfigurationInput {
	s.AcceptanceRequired = &v
	return s
}
338361
func (s *ListServerNeighborsInput) SetPortInformationNeeded(v bool) *ListServerNeighborsInput {
	s.PortInformationNeeded = &v
	return s
}
444568
func PermissionDenied(w http.ResponseWriter, req *http.Request) {
	http.Error(w, "Permission denied.", http.StatusForbidden)
}
118592
func (clnt *Client) GrantRoles(policy *AdminPolicy, user string, roles []string) error {
	policy = clnt.getUsableAdminPolicy(policy)

	command := newAdminCommand(nil)
	return command.grantRoles(clnt.cluster, policy, user, roles)
}
895143
func (t Term) Grant(args ...interface{}) Term {
	return constructMethodTerm(t, "Grant", p.Term_GRANT, args, map[string]interface{}{})
}
1012716
func (s *CreateQualificationTypeInput) SetAutoGranted(v bool) *CreateQualificationTypeInput {
	s.AutoGranted = &v
	return s
}
842512
func (s *CostTypes) SetUseBlended(v bool) *CostTypes {
	s.UseBlended = &v
	return s
}
582908
func IsPermissionDenied(err error) bool {
	pd, ok := err.(permissionDeniedError)
	return ok && pd.IsPermissionDenied()
}
1168565
func wordsNeeded(i uint) int {
	if i > (Cap() - wordSize + 1) {
		return int(Cap() >> log2WordSize)
	}
	return int((i + (wordSize - 1)) >> log2WordSize)
}