// Check checks validity of all parameters and sets defaults
433961
func (c *TrustedClusterV2) CheckAndSetDefaults() error {
	// make sure we have defaults for all fields
	if err := c.Metadata.CheckAndSetDefaults(); err != nil {
		return trace.Wrap(err)
	}
	// This is to force users to migrate
	if len(c.Spec.Roles) != 0 && len(c.Spec.RoleMap) != 0 {
		return trace.BadParameter("should set either 'roles' or 'role_map', not both")
	}
	// we are not mentioning Roles parameter because we are deprecating it
	if len(c.Spec.Roles) == 0 && len(c.Spec.RoleMap) == 0 {
		if err := modules.GetModules().EmptyRolesHandler(); err != nil {
			return trace.Wrap(err)
		}
		// OSS teleport uses 'admin' by default:
		c.Spec.RoleMap = RoleMap{
			RoleMapping{
				Remote: teleport.AdminRoleName,
				Local:  []string{teleport.AdminRoleName},
			},
		}
	}
	// Imply that by default proxy listens on the same port for
	// web and reverse tunnel connections
	if c.Spec.ReverseTunnelAddress == "" {
		c.Spec.ReverseTunnelAddress = c.Spec.ProxyAddress
	}
	if err := c.Spec.RoleMap.Check(); err != nil {
		return trace.Wrap(err)
	}
	return nil
}
966792
func (c *Checker) Check(rel string, recurse bool, beforeRev, afterRev string) ([]Change, error) {
	// If revision is unset use VCS's default revision
	dBefore, dAfter := c.vcs.DefaultRevision()
	if beforeRev == "" {
		beforeRev = dBefore
	}
	if afterRev == "" {
		afterRev = dAfter
	}
	c.recurse = recurse

	var err error
	c.path, err = importPathTo(rel)
	if err != nil {
		return nil, err
	}

	c.logf("import path: %q before: %q after: %q recursive: %v\n", c.path, beforeRev, afterRev, c.recurse)

	// Parse revisions from VCS into go/ast
	start := time.Now()
	if c.b, err = c.parse(beforeRev); err != nil {
		return nil, err
	}
	if c.a, err = c.parse(afterRev); err != nil {
		return nil, err
	}
	parse := time.Since(start)

	start = time.Now()
	changes, err := c.compareDecls()
	if err != nil {
		var buf bytes.Buffer
		fmt.Fprintf(&buf, "error comparing declarations: %s\n", err)
		if derr, ok := err.(*diffError); ok {
			_ = ast.Fprint(&buf, c.b[derr.pkg].fset, derr.bdecl, ast.NotNilFilter)
			_ = ast.Fprint(&buf, c.a[derr.pkg].fset, derr.adecl, ast.NotNilFilter)
		}
		return nil, errors.New(buf.String())
	}
	diff := time.Since(start)

	start = time.Now()
	sort.Sort(byID(changes))
	sort := time.Since(start)

	c.logf("Timing: parse: %v, diff: %v, sort: %v, total: %v\n", parse, diff, sort, parse+diff+sort)
	c.logf("Changes detected: %v\n", len(changes))

	return changes, nil
}
709365
func DefaultCheck(c Context, key, match string) bool {
	cred, ok := c.Auth[key]
	if !ok {
		return false
	}
	return cred == match
}
200996
func (h *dnsHc) Check(p *Proxy) error {
	err := h.send(p.addr)
	if err != nil {
		HealthcheckFailureCount.WithLabelValues(p.addr).Add(1)
		atomic.AddUint32(&p.fails, 1)
		return err
	}

	atomic.StoreUint32(&p.fails, 0)
	return nil
}
361467
func (i *OIDCAuthRequest) Check() error {
	if i.ConnectorID == "" {
		return trace.BadParameter("ConnectorID: missing value")
	}
	if i.StateToken == "" {
		return trace.BadParameter("StateToken: missing value")
	}
	if len(i.PublicKey) != 0 {
		_, _, _, _, err := ssh.ParseAuthorizedKey(i.PublicKey)
		if err != nil {
			return trace.BadParameter("PublicKey: bad key: %v", err)
		}
		if (i.CertTTL > defaults.MaxCertDuration) || (i.CertTTL < defaults.MinCertDuration) {
			return trace.BadParameter("CertTTL: wrong certificate TTL")
		}
	}

	return nil
}
234728
func (d *DialParams) CheckAndSetDefaults() error {
	if d.From == nil {
		return trace.BadParameter("parameter From required")
	}
	if d.To == nil {
		return trace.BadParameter("parameter To required")
	}

	return nil
}
165249
func (f *ReadyFilter) Check(n *NodeInfo) bool {
	return n.Status.State == api.NodeStatus_READY &&
		n.Spec.Availability == api.NodeAvailabilityActive
}
25441
func (c *Config) Check() (err error) {
	if c.AccessKeyID == "" {
		err = errors.New("access key ID not specified")
		return
	}
	if c.SecretAccessKey == "" {
		err = errors.New("secret access key not specified")
		return
	}

	if c.Host == "" {
		err = errors.New("server host not specified")
		return
	}
	if c.Port <= 0 {
		err = errors.New("server port not specified")
		return
	}
	if c.Protocol == "" {
		err = errors.New("server protocol not specified")
		return
	}

	if c.AdditionalUserAgent != "" {
		for _, x := range c.AdditionalUserAgent {
			// Allow space(32) to ~(126) in ASCII Table, exclude "(34).
			if int(x) < 32 || int(x) > 126 || int(x) == 32 || int(x) == 34 {
				err = errors.New("additional User-Agent contains characters that not allowed")
				return
			}
		}
	}

	err = logger.CheckLevel(c.LogLevel)
	if err != nil {
		return
	}

	return
}
559234
func Check(err error) {
	if err != nil {
		log.Fatalf("%+v", errors.WithStack(err))
	}
}
36383
func (m *SafeMap) Check(k interface{}) bool {
	m.lock.RLock()
	defer m.lock.RUnlock()
	if _, ok := m.bm[k]; !ok {
		return false
	}
	return true
}
798666
func (c *batchOptions) Check() error {
	for i, p := range c.Payments {
		if strings.TrimSpace(p.Recipient) == "" {
			return fmt.Errorf("payment %d: %s", i, ErrRecipientMissing)
		}
		if strings.TrimSpace(p.Amount) == "" {
			return fmt.Errorf("payment %d: %s", i, ErrAmountMissing)
		}
		namt, err := stellarnet.ParseStellarAmount(p.Amount)
		if err != nil {
			return fmt.Errorf("payment %d: %s", i, ErrInvalidAmount)
		}
		if namt < 0 {
			return fmt.Errorf("payment %d: %s", i, ErrInvalidAmount)
		}
		if len(p.Message) > libkb.MaxStellarPaymentNoteLength {
			return fmt.Errorf("payment %d: %s", i, ErrMessageTooLong)
		}
	}

	if c.Timeout <= 0 {
		c.Timeout = 15 * len(c.Payments)
	}

	return nil
}
764163
func (c *Container) check() error {
	var a ErrorList

	if c.isArray() {
		array := c.array()
		if int32(len(array)) != c.n {
			a.Append(fmt.Errorf("array count mismatch: count=%d, n=%d", len(array), c.n))
		}
	} else if c.isRun() {
		n := c.runCountRange(0, maxContainerVal+1)
		if n != c.n {
			a.Append(fmt.Errorf("run count mismatch: count=%d, n=%d", n, c.n))
		}
	} else if c.isBitmap() {
		if n := c.bitmapCountRange(0, maxContainerVal+1); n != c.n {
			a.Append(fmt.Errorf("bitmap count mismatch: count=%d, n=%d", n, c.n))
		}
	} else {
		a.Append(fmt.Errorf("empty container"))
		if c.n != 0 {
			a.Append(fmt.Errorf("empty container with nonzero count: n=%d", c.n))
		}
	}

	if a == nil {
		return nil
	}
	return a
}
259998
func (s *Server) Check(ctx context.Context, in *api.HealthCheckRequest) (*api.HealthCheckResponse, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	if in.Service == "" {
		// check the server overall health status.
		return &api.HealthCheckResponse{
			Status: api.HealthCheckResponse_SERVING,
		}, nil
	}
	if status, ok := s.statusMap[in.Service]; ok {
		return &api.HealthCheckResponse{
			Status: status,
		}, nil
	}
	return nil, status.Errorf(codes.NotFound, "unknown service")
}
676870
func (cs Constraints) Check(v *Version) bool {
	for _, c := range cs {
		if !c.Check(v) {
			return false
		}
	}

	return true
}
449117
func (v *Validation) Check(obj interface{}, checks ...Validator) *ValidationResult {
	var result *ValidationResult
	for _, check := range checks {
		result = v.apply(check, obj)
		if !result.Ok {
			return result
		}
	}
	return result
}
130885
func (c *HostCertParams) Check() error {
	if c.HostID == "" && len(c.Principals) == 0 {
		return trace.BadParameter("HostID [%q] or Principals [%q] are required",
			c.HostID, c.Principals)
	}
	if c.ClusterName == "" {
		return trace.BadParameter("ClusterName [%q] is required", c.ClusterName)
	}

	if err := c.Roles.Check(); err != nil {
		return trace.Wrap(err)
	}

	return nil
}
171089
func (p *Params) Check() error {
	// Validate N
	if p.N > maxInt || p.N <= 1 || p.N%2 != 0 {
		return ErrInvalidParams
	}

	// Validate r
	if p.R < 1 || p.R > maxInt {
		return ErrInvalidParams
	}

	// Validate p
	if p.P < 1 || p.P > maxInt {
		return ErrInvalidParams
	}

	// Validate that r & p don't exceed 2^30 and that N, r, p values don't
	// exceed the limits defined by the scrypt algorithm.
	if uint64(p.R)*uint64(p.P) >= 1<<30 || p.R > maxInt/128/p.P || p.R > maxInt/256 || p.N > maxInt/128/p.R {
		return ErrInvalidParams
	}

	// Validate the salt length
	if p.SaltLen < minSaltLen || p.SaltLen > maxInt {
		return ErrInvalidParams
	}

	// Validate the derived key length
	if p.DKLen < minDKLen || p.DKLen > maxInt {
		return ErrInvalidParams
	}

	return nil
}