// configCheck checks for configuration changes.
979500
func (n *Notifier) configCheck() {
	log.Infof("Checking for config changes...")

	s := n.Source()
	last := n.last
	note, err := n.pullConfig(s)
	if err != nil && s == SourcePeer {
		log.Errorf("Failed to pull configuration from peer: %v", err)
		n.peerFailures++
		if n.peerFailures < n.engineCfg.MaxPeerConfigSyncErrors {
			return
		}
		log.Infof("Sync from peer failed %v times, falling back to config server",
			n.engineCfg.MaxPeerConfigSyncErrors)
		s = SourceServer
		note, err = n.pullConfig(s)
	}
	n.peerFailures = 0
	if err != nil {
		log.Errorf("Failed to pull configuration: %v", err)
		return
	}

	if s != SourceDisk && s != SourcePeer {
		oldMeta := last.protobuf.Metadata
		newMeta := note.protobuf.Metadata
		if oldMeta != nil && newMeta != nil && oldMeta.GetLastUpdated() > newMeta.GetLastUpdated() {
			log.Infof("Ignoring out-of-date config from %v", note.SourceDetail)
			return
		}
	}

	if note.Cluster.Equal(last.Cluster) {
		log.Infof("No config changes found")
		return
	}

	// If there's only metadata differences, note it so we can skip some processing later.
	oldCluster := *n.last.Cluster
	oldCluster.Status = seesaw.ConfigStatus{}
	newCluster := *note.Cluster
	newCluster.Status = seesaw.ConfigStatus{}
	if newCluster.Equal(&oldCluster) {
		note.MetadataOnly = true
	}

	log.Infof("Sending config update notification")
	n.last = note
	n.outgoing <- *note
	log.Infof("Sent config update notification")

	if s != SourceDisk {
		if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, !note.MetadataOnly); err != nil {
			log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
		}
	}
}
1210725
func NewChecker(config *Config) *Checker {
	if config == nil {
		config = &Config{}
	}

	if config.RuntimeTTL == 0 {
		config.RuntimeTTL = DefaultRuntimeTTL
	}

	return &Checker{
		since:      time.Now(),
		metadata:   make(map[string]interface{}),
		checks:     make(map[string]*check),
		runtimeTTL: config.RuntimeTTL,
	}
}
1204905
func NewWeakRandCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
	return &weakRand{
		funcNames:   []string{"Read", "Int"},
		packagePath: "math/rand",
		MetaData: gosec.MetaData{
			ID:         id,
			Severity:   gosec.High,
			Confidence: gosec.Medium,
			What:       "Use of weak random number generator (math/rand instead of crypto/rand)",
		},
	}, []ast.Node{(*ast.CallExpr)(nil)}
}
485557
func ModifyConfig(c context.Context, cb func(Config) Config) context.Context {
	var cfg Config
	if cur := getConfig(c); cur != nil {
		cfg = *cur
	}
	cfg = cb(cfg)
	return setConfig(c, &cfg)
}
1314851
func UidCheck(at []AccessTuple) func(tc *ginoauth2.TokenContainer, ctx *gin.Context) bool {
	ats := at
	return func(tc *ginoauth2.TokenContainer, ctx *gin.Context) bool {
		uid := tc.Scopes["uid"].(string)
		for idx := range ats {
			at := ats[idx]
			if tc.Realm == at.Realm && uid == at.Uid {
				ctx.Set("uid", uid)  //in this way I can set the authorized uid
				ctx.Set("cn", at.Cn) //in this way I can set the authorized Realname
				glog.Infof("[Gin-OAuth] Grant access to %s\n", uid)
				return true
			}
		}
		return false
	}
}
1370163
func (f *Function) configChanged(config *lambda.GetFunctionOutput) bool {
	type diffConfig struct {
		Description      string
		Memory           int64
		Timeout          int64
		Role             string
		Runtime          string
		Handler          string
		VPC              vpc.VPC
		Environment      []string
		KMSKeyArn        string
		DeadLetterConfig lambda.DeadLetterConfig
	}

	localConfig := &diffConfig{
		Description: f.Description,
		Memory:      f.Memory,
		Timeout:     f.Timeout,
		Role:        f.Role,
		Runtime:     f.Runtime,
		Handler:     f.Handler,
		KMSKeyArn:   f.KMSKeyArn,
		Environment: environ(f.environment().Variables),
		VPC: vpc.VPC{
			Subnets:        f.VPC.Subnets,
			SecurityGroups: f.VPC.SecurityGroups,
		},
	}

	if f.DeadLetterARN != "" {
		localConfig.DeadLetterConfig = lambda.DeadLetterConfig{
			TargetArn: &f.DeadLetterARN,
		}
	}

	remoteConfig := &diffConfig{
		Description: *config.Configuration.Description,
		Memory:      *config.Configuration.MemorySize,
		Timeout:     *config.Configuration.Timeout,
		Role:        *config.Configuration.Role,
		Runtime:     *config.Configuration.Runtime,
		Handler:     *config.Configuration.Handler,
	}

	if config.Configuration.KMSKeyArn != nil {
		remoteConfig.KMSKeyArn = *config.Configuration.KMSKeyArn
	}

	if config.Configuration.Environment != nil {
		remoteConfig.Environment = environ(config.Configuration.Environment.Variables)
	}

	if config.Configuration.DeadLetterConfig != nil {
		remoteConfig.DeadLetterConfig = lambda.DeadLetterConfig{
			TargetArn: config.Configuration.DeadLetterConfig.TargetArn,
		}
	}

	// SDK is inconsistent here. VpcConfig can be nil or empty struct.
	remoteConfig.VPC = vpc.VPC{Subnets: []string{}, SecurityGroups: []string{}}
	if config.Configuration.VpcConfig != nil {
		remoteConfig.VPC = vpc.VPC{
			Subnets:        aws.StringValueSlice(config.Configuration.VpcConfig.SubnetIds),
			SecurityGroups: aws.StringValueSlice(config.Configuration.VpcConfig.SecurityGroupIds),
		}
	}

	// don't make any assumptions about the order AWS stores the subnets or security groups
	sort.StringSlice(remoteConfig.VPC.Subnets).Sort()
	sort.StringSlice(localConfig.VPC.Subnets).Sort()
	sort.StringSlice(remoteConfig.VPC.SecurityGroups).Sort()
	sort.StringSlice(localConfig.VPC.SecurityGroups).Sort()

	localConfigJSON, _ := json.Marshal(localConfig)
	remoteConfigJSON, _ := json.Marshal(remoteConfig)
	return string(localConfigJSON) != string(remoteConfigJSON)
}
806521
func (spec *configSpec) LocalConfig() loader.ConfigContainer {
	spec.local = &LocalConfig{spec: spec}
	return spec.local
}
4771
func (s *serverConfig) ConfigDiff(t *serverConfig) string {
	switch {
	case t == nil:
		return "Given configuration is empty"
	case s.Credential != t.Credential:
		return "Credential configuration differs"
	case s.Region != t.Region:
		return "Region configuration differs"
	case s.StorageClass != t.StorageClass:
		return "StorageClass configuration differs"
	case !reflect.DeepEqual(s.Cache, t.Cache):
		return "Cache configuration differs"
	case !reflect.DeepEqual(s.Compression, t.Compression):
		return "Compression configuration differs"
	case !reflect.DeepEqual(s.Notify.AMQP, t.Notify.AMQP):
		return "AMQP Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.NATS, t.Notify.NATS):
		return "NATS Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.NSQ, t.Notify.NSQ):
		return "NSQ Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.Elasticsearch, t.Notify.Elasticsearch):
		return "ElasticSearch Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.Redis, t.Notify.Redis):
		return "Redis Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.PostgreSQL, t.Notify.PostgreSQL):
		return "PostgreSQL Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.Kafka, t.Notify.Kafka):
		return "Kafka Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.Webhook, t.Notify.Webhook):
		return "Webhook Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.MySQL, t.Notify.MySQL):
		return "MySQL Notification configuration differs"
	case !reflect.DeepEqual(s.Notify.MQTT, t.Notify.MQTT):
		return "MQTT Notification configuration differs"
	case !reflect.DeepEqual(s.Logger, t.Logger):
		return "Logger configuration differs"
	case !reflect.DeepEqual(s.KMS, t.KMS):
		return "KMS configuration differs"
	case reflect.DeepEqual(s, t):
		return ""
	default:
		// This case will not happen unless this comparison
		// function has become stale.
		return "Configuration differs"
	}
}
984715
func (s *ServiceSummary) SetHealthCheckConfig(v *HealthCheckConfig) *ServiceSummary {
	s.HealthCheckConfig = v
	return s
}
709365
func DefaultCheck(c Context, key, match string) bool {
	cred, ok := c.Auth[key]
	if !ok {
		return false
	}
	return cred == match
}
739738
func ValidateConfig(p storage.Provider, cfg *storage.Config) error {
	return p.ValidateConfig(cfg)
}
1335320
func WithConfigDir(ctx context.Context, cfgdir string) context.Context {
	return context.WithValue(ctx, ctxKeyConfigDir, cfgdir)
}
915113
func ScopeCheck(name string, scopes ...string) func(tc *ginoauth2.TokenContainer, ctx *gin.Context) bool {
	glog.Infof("ScopeCheck %s configured to grant access for scopes: %v", name, scopes)
	configuredScopes := scopes
	return func(tc *ginoauth2.TokenContainer, ctx *gin.Context) bool {
		scopesFromToken := make([]string, 0)
		for _, s := range configuredScopes {
			if cur, ok := tc.Scopes[s]; ok {
				glog.V(2).Infof("Found configured scope %s", s)
				scopesFromToken = append(scopesFromToken, s)
				ctx.Set(s, cur) // set value from token of configured scope to the context, which you can use in your application.
			}
		}
		//Getting the uid for identification of the service calling
		if cur, ok := tc.Scopes["uid"]; ok {
			ctx.Set("uid", cur)
		}
		return len(scopesFromToken) > 0
	}
}
1086887
func (L *State) Argcheck(cond bool, narg int, extramsg string) {
	if !cond {
		Cextramsg := C.CString(extramsg)
		defer C.free(unsafe.Pointer(Cextramsg))
		C.luaL_argerror(L.s, C.int(narg), Cextramsg)
	}
}
559199
func ParseGocheck(rd io.Reader, suitePrefix string) (Suites, error) {
	findStart := gcStartRE.FindStringSubmatch
	findEnd := gcEndRE.FindStringSubmatch
	findSuite := gcSuiteRE.FindStringSubmatch

	scanner := NewLineScanner(rd)
	var suites = make([]*Suite, 0)
	var suiteName string
	var suite *Suite

	var testName string
	var out []string

	for scanner.Scan() {
		line := scanner.Text()

		tokens := findStart(line)
		if len(tokens) > 0 {
			if tokens[2] == "SetUpTest" || tokens[2] == "TearDownTest" {
				continue
			}
			if testName != "" {
				return nil, fmt.Errorf("%d: start in middle of test", scanner.Line())
			}
			suiteName = tokens[1]
			testName = tokens[2]
			out = []string{}
			continue
		}

		tokens = findEnd(line)
		if len(tokens) > 0 {
			if tokens[3] == "SetUpTest" || tokens[3] == "TearDownTest" {
				continue
			}
			if testName == "" {
				return nil, fmt.Errorf("%d: orphan end", scanner.Line())
			}
			if (tokens[2] != suiteName) || (tokens[3] != testName) {
				return nil, fmt.Errorf("%d: suite/name mismatch", scanner.Line())
			}
			test := &Test{Name: testName}
			test.Message = strings.Join(out, "\n")
			test.Time = tokens[4]
			test.Status = Token2Status(tokens[1])
			if test.Status == UnknownStatus {
				return nil, fmt.Errorf("%d: unknown status %s", scanner.Line(), tokens[1])
			}

			if suite == nil || suite.Name != suiteName {
				suite = &Suite{Name: suitePrefix + suiteName}
				suites = append(suites, suite)
			}
			suite.Tests = append(suite.Tests, test)

			testName = ""
			suiteName = ""
			out = []string{}

			continue
		}

		// last "suite" is test summary
		tokens = findSuite(line)
		if tokens != nil {
			if suite == nil {
				suite = &Suite{Name: tokens[2], Status: tokens[1], Time: tokens[3]}
				suites = append(suites, suite)
			} else {
				suite.Status = tokens[1]
				suite.Time = tokens[3]
			}

			testName = ""
			suiteName = ""
			out = []string{}

			continue
		}

		if testName != "" {
			out = append(out, line)
		}
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return Suites(suites), nil
}
212137
func (s *LUCIConfigProvider) Config(c context.Context) (*config.Config, error) {
	s.lock.Lock()
	defer s.lock.Unlock()

	// Load/cache the global config.
	if s.gcfg == nil {
		var err error
		s.gcfg, err = config.Load(c)
		if err != nil {
			return nil, err
		}
	}

	return s.gcfg, nil
}
1290033
func config(c context.Context) *Config {
	cfg, _ := c.Value(configContextKey(0)).(*Config)
	if cfg == nil {
		panic("impossible, configContextKey is not set")
	}
	return cfg
}