// Ban runs the "ban" action.
546578
func (c *NamedusersController) Ban(ctx *app.BanNamedusersContext) error {
	isSvcAccount := token.IsSpecificServiceAccount(ctx, token.OnlineRegistration)
	if !isSvcAccount {
		log.Error(ctx, nil, "the account is not an authorized service account allowed to deprovision users")
		return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("account not authorized to deprovision users"))
	}

	identity, err := c.app.UserService().BanUser(ctx, ctx.Username)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err":      err,
			"username": ctx.Username,
		}, "unable to deprovision user")
		return jsonapi.JSONErrorResponse(ctx, err)
	}

	// Delete tenant (if access to tenant service is configured/enabled)
	if c.tenantService != nil {
		err := c.tenantService.Delete(ctx, identity.ID)
		if err != nil {
			log.Error(ctx, map[string]interface{}{
				"err":         err,
				"identity_id": identity.ID,
				"username":    ctx.Username,
			}, "unable to delete tenant when deprovisioning user")
			sentry.Sentry().CaptureError(ctx, err)
			// Just log the error and proceed
		}
	}
	log.Info(ctx, map[string]interface{}{
		"username": ctx.Username,
	}, "user banned")

	return ctx.OK(ConvertToAppUser(ctx.RequestData, &identity.User, identity, true))
}
1323204
func Handle(h events.Handler) Rule {
	if h == nil {
		return nil
	}
	return func(ctx context.Context, e *scheduler.Event, err error, chain Chain) (context.Context, *scheduler.Event, error) {
		newErr := h.HandleEvent(ctx, e)
		return chain(ctx, e, Error2(err, newErr))
	}
}
447977
func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
	// Don't match on empty dirs.
	if path == "" {
		return false
	}

	// Disallow ignoring the current working directory.
	// See issue:
	// 1776 (New York City) Hamilton: "Pardon me, are you Aaron Burr, sir?"
	if path == "." || path == "./" {
		return false
	}
	for _, p := range r.patterns {
		if p.match == nil {
			log.Printf("ignore: no matcher supplied for %q", p.raw)
			return false
		}

		// For negative rules, we need to capture and return non-matches,
		// and continue for matches.
		if p.negate {
			if p.mustDir && !fi.IsDir() {
				return true
			}
			if !p.match(path, fi) {
				return true
			}
			continue
		}

		// If the rule is looking for directories, and this is not a directory,
		// skip it.
		if p.mustDir && !fi.IsDir() {
			continue
		}
		if p.match(path, fi) {
			return true
		}
	}
	return false
}
774051
func (cli *Client) BanUser(roomID string, req *ReqBanUser) (resp *RespBanUser, err error) {
	u := cli.BuildURL("rooms", roomID, "ban")
	_, err = cli.MakeRequest("POST", u, req, &resp)
	return
}
1182689
func (e Error) Error() string {
	return fmt.Sprintf("%s (%s): %s", e.Command.CommandType(), e.Command.AggregateID(), e.Err.Error())
}
847817
func (hc *Check) Blocking(block bool) {
	len := 0
	if !block {
		len = 1
	}
	hc.blocking = block
	hc.update = make(chan Config, len)
}
1367893
func (r *multipleOfRule) Error(message string) *multipleOfRule {
	r.message = message
	return r
}
244443
func (h *ClientHandler) Rule(r rule.Rule) *ClientHandler {
	if r == nil {
		// if nothing passed then use the allow-everything rule
		r = rule.Satisfied()
	}
	h.rule = r

	return h
}
1363691
func (p *Enforcer) Enforce(rule string, c Context) bool {
	c.rules = &p.rules
	c.checks = p.checks
	r, ok := p.rules[rule]
	return ok && r(c)
}
277731
func (v *LengthRule) Error(message string) *LengthRule {
	v.message = message
	return v
}
726502
func Allow(opts *Options) http.HandlerFunc {
	// Allow default headers if nothing is specified.
	if len(opts.AllowHeaders) == 0 {
		opts.AllowHeaders = defaultAllowHeaders
	}

	for _, origin := range opts.AllowOrigins {
		pattern := regexp.QuoteMeta(origin)
		pattern = strings.Replace(pattern, "\\*", ".*", -1)
		pattern = strings.Replace(pattern, "\\?", ".", -1)
		allowOriginPatterns = append(allowOriginPatterns, "^"+pattern+"$")
	}

	return func(res http.ResponseWriter, req *http.Request) {
		var (
			origin           = req.Header.Get(headerOrigin)
			requestedMethod  = req.Header.Get(headerRequestMethod)
			requestedHeaders = req.Header.Get(headerRequestHeaders)
			// additional headers to be added
			// to the response.
			headers map[string]string
		)

		if req.Method == "OPTIONS" &&
			(requestedMethod != "" || requestedHeaders != "") {
			// TODO: if preflight, respond with exact headers if allowed
			headers = opts.PreflightHeader(origin, requestedMethod, requestedHeaders)
			for key, value := range headers {
				res.Header().Set(key, value)
			}
			res.WriteHeader(http.StatusOK)
			return
		}
		headers = opts.Header(origin)

		for key, value := range headers {
			res.Header().Set(key, value)
		}
	}
}
947257
func (l *List) AddRule(r *Rule) error {
	l.rules[r.Value] = r
	return nil
}
1072301
func (cmd *CLI) Mute() {
	var err error
	cmd.errOutput, err = os.Open(os.DevNull)
	cmd.stdOutput, err = os.Open(os.DevNull)
	exitIfError(err)
}
824545
func (s *Stream) Blocked() bool {
	resp := StreamListResponse{}
	s.live.StreamsBlockList(&resp)
	for _, val := range resp.StreamUrls.StreamUrl {
		//遍历判断此流是否存在黑名单中
		if val == s.baseUrl() {
			return true
		}
	}
	return false
}
1250430
func (r FilterResult) Error() string {
	switch r {
	case OK:
		return "OK"
	case POLICY_DROP:
		return "POLICY_DROP"
	case PARSER_ERROR:
		return "PARSER_ERROR"
	case UNKNOWN_PARSER:
		return "UNKNOWN_PARSER"
	case UNKNOWN_CONNECTION:
		return "UNKNOWN_CONNECTION"
	case INVALID_ADDRESS:
		return "INVALID_ADDRESS"
	case INVALID_INSTANCE:
		return "INVALID_INSTANCE"
	}
	return "UNKNOWN_ERROR"
}
88236
func (checker GroupSubjectChecker) Allowed(subject rbac.Subject, ctx *RoleBindingRestrictionContext) (bool, error) {
	if subject.Kind != rbac.GroupKind {
		return false, nil
	}

	for _, groupName := range checker.groupRestriction.Groups {
		if subject.Name == groupName {
			return true, nil
		}
	}

	if len(checker.groupRestriction.Selectors) != 0 {
		labelSet, err := ctx.labelSetForGroup(subject)
		if err != nil {
			return false, err
		}

		for _, labelSelector := range checker.groupRestriction.Selectors {
			selector, err := metav1.LabelSelectorAsSelector(&labelSelector)
			if err != nil {
				return false, err
			}

			if selector.Matches(labelSet) {
				return true, nil
			}
		}
	}

	return false, nil
}
1285000
func (f *Machine) Allows(b uint8) bool {
	return f.isLegal(f.state, b)
}