// validateProjectConfig returns an error if the configuration violates any of the
// requirements in the proto definition.
166100
func validateProjectConfig(ctx *validation.Context, projectCfg *notifypb.ProjectConfig) {
	builderNames := stringset.New(len(projectCfg.Notifiers)) // At least one builder per notifier
	for i, cfgNotifier := range projectCfg.Notifiers {
		ctx.Enter("notifier #%d", i+1)
		validateNotifier(ctx, cfgNotifier, builderNames)
		ctx.Exit()
	}
}
454396
func ConfigNameForBuild(build *buildv1.Build) string {
	if build == nil {
		return ""
	}
	if build.Annotations != nil {
		if _, exists := build.Annotations[BuildConfigAnnotation]; exists {
			return build.Annotations[BuildConfigAnnotation]
		}
	}
	if _, exists := build.Labels[BuildConfigLabel]; exists {
		return build.Labels[BuildConfigLabel]
	}
	return build.Labels[BuildConfigLabelDeprecated]
}
525017
func (c WorkerConfig) Validate() error {
	if c.Facade == nil {
		return errors.NotValidf("nil Facade")
	}
	if c.AgentTag == nil {
		return errors.NotValidf("nil AgentTag")
	}
	empty := params.RetryStrategy{}
	if c.RetryStrategy == empty {
		return errors.NotValidf("empty RetryStrategy")
	}
	return nil
}
244668
func ValidateConfig(config *api.Config) []Error {
	allErrs := []Error{}
	if len(config.BuilderImage) == 0 {
		allErrs = append(allErrs, NewFieldRequired("builderImage"))
	}
	switch config.BuilderPullPolicy {
	case api.PullNever, api.PullAlways, api.PullIfNotPresent:
	default:
		allErrs = append(allErrs, NewFieldInvalidValue("builderPullPolicy"))
	}
	if config.DockerConfig == nil || len(config.DockerConfig.Endpoint) == 0 {
		allErrs = append(allErrs, NewFieldRequired("dockerConfig.endpoint"))
	}
	if config.DockerNetworkMode != "" && !validateDockerNetworkMode(config.DockerNetworkMode) {
		allErrs = append(allErrs, NewFieldInvalidValue("dockerNetworkMode"))
	}
	if config.Labels != nil {
		for k := range config.Labels {
			if len(k) == 0 {
				allErrs = append(allErrs, NewFieldInvalidValue("labels"))
			}
		}
	}
	if config.Tag != "" {
		if err := validateDockerReference(config.Tag); err != nil {
			allErrs = append(allErrs, NewFieldInvalidValueWithReason("tag", err.Error()))
		}
	}
	return allErrs
}
536307
func getValidConfig(objAPI ObjectLayer) (*serverConfig, error) {
	srvCfg, err := readServerConfig(context.Background(), objAPI)
	if err != nil {
		return nil, err
	}

	return srvCfg, srvCfg.Validate()
}
1192721
func validateConfig(config *ProviderConfig) error {
	// Validate the inputs
	if config == nil {
		return fmt.Errorf("missing config")
	}
	if config.Service == nil {
		return fmt.Errorf("missing service")
	}
	if config.Service.Service == "" {
		return fmt.Errorf("missing service name")
	}
	if config.Service.ServiceVersion == "" {
		return fmt.Errorf("missing service version")
	}
	if config.Service.ResourceType == "" {
		return fmt.Errorf("missing service resource type")
	}
	if config.Handlers == nil && len(config.Service.Capabilities) != 0 {
		return fmt.Errorf("missing handlers")
	}
	for c := range config.Service.Capabilities {
		if _, ok := config.Handlers[c]; !ok {
			return fmt.Errorf("missing handler for '%s' capability", c)
		}
	}
	if config.ResourceGroup == "" {
		return fmt.Errorf("missing resource group")
	}
	if config.Token == "" {
		config.Token = os.Getenv("ATLAS_TOKEN")
	}
	if config.Token == "" {
		return fmt.Errorf("missing token")
	}

	// Default the endpoint
	if config.Endpoint == "" {
		config.Endpoint = DefaultEndpoint
		if end := os.Getenv("SCADA_ENDPOINT"); end != "" {
			config.Endpoint = end
		}
	}
	return nil
}
1124964
func (config Config) Validate() error {
	if config.ApplicationGetter == nil {
		return errors.NotValidf("missing ApplicationGetter")
	}
	if config.ApplicationUpdater == nil {
		return errors.NotValidf("missing ApplicationUpdater")
	}
	if config.ServiceBroker == nil {
		return errors.NotValidf("missing ServiceBroker")
	}
	if config.ContainerBroker == nil {
		return errors.NotValidf("missing ContainerBroker")
	}
	if config.ProvisioningInfoGetter == nil {
		return errors.NotValidf("missing ProvisioningInfoGetter")
	}
	if config.LifeGetter == nil {
		return errors.NotValidf("missing LifeGetter")
	}
	if config.UnitUpdater == nil {
		return errors.NotValidf("missing UnitUpdater")
	}
	if config.ProvisioningStatusSetter == nil {
		return errors.NotValidf("missing ProvisioningStatusSetter")
	}
	return nil
}
780964
func SetupConfigValidation(rules *validation.RuleSet) {
	rules.Add("services/${config_service_appid}", projectsCfg, func(ctx *validation.Context, configSet, path string, content []byte) error {
		ctx.SetFile(projectsCfg)
		cfg := &config.ProjectsCfg{}
		if err := proto.UnmarshalText(string(content), cfg); err != nil {
			ctx.Errorf("not a valid ProjectsCfg proto message - %s", err)
		} else {
			validateProjectsCfg(ctx, cfg)
		}
		return nil
	})
}
623985
func (cfgs *Configs) Validate(c *validation.Context) {
	prjs := stringset.New(len(cfgs.GetProject()))
	for i, cfg := range cfgs.GetProject() {
		c.Enter("project %d", i)
		cfg.Validate(c)
		if !prjs.Add(cfg.Project) {
			c.Errorf("project %q is not unique", cfg.Project)
		}
		c.Exit()
	}
}
600139
func LoadProjectConfigFromFile() (ProjectConfigModel, error) {
	projectConfigFileAbsPath, err := ProjectConfigFileAbsPath()
	if err != nil {
		return ProjectConfigModel{}, fmt.Errorf("Failed to get absolute path of project config: %s", err)
	}

	bytes, err := ioutil.ReadFile(projectConfigFileAbsPath)
	if err != nil {
		return ProjectConfigModel{}, fmt.Errorf("Failed to read project config file (%s), error: %s", projectConfigFileAbsPath, err)
	}
	var projectConfig ProjectConfigModel
	if err := yaml.Unmarshal(bytes, &projectConfig); err != nil {
		return ProjectConfigModel{}, fmt.Errorf("Failed to parse project config (should be valid YML, path: %s), error: %s", projectConfigFileAbsPath, err)
	}

	return projectConfig, nil
}
510730
func (ref *Config) ValidateAsyncProducerConfig() error {
	if ref.Brokers == nil {
		return errors.New("invalid Brokers - one or more brokers must be specified")
	}
	if ref.SendSuccess && ref.SuccessChan == nil {
		return errors.New("success channel not specified")
	}
	if ref.SendError && ref.ErrorChan == nil {
		return errors.New("error channel not specified")
	}
	return ref.ProducerConfig().Validate()
}
424523
func ValidateConfigInfo(config *clientcmdapi.Config, clustername string) (*clientcmdapi.Config, error) {
	err := validateKubeConfig(config)
	if err != nil {
		return nil, err
	}

	// This is the cluster object we've got from the cluster-info kubeconfig file
	defaultCluster := kubeconfigutil.GetClusterFromKubeConfig(config)

	// Create a new kubeconfig object from the given, just copy over the server and the CA cert
	// We do this in order to not pick up other possible misconfigurations in the clusterinfo file
	kubeconfig := kubeconfigutil.CreateBasic(
		defaultCluster.Server,
		clustername,
		"", // no user provided
		defaultCluster.CertificateAuthorityData,
	)
	// load pre-existing client certificates
	if config.Contexts[config.CurrentContext] != nil && len(config.AuthInfos) > 0 {
		user := config.Contexts[config.CurrentContext].AuthInfo
		authInfo, ok := config.AuthInfos[user]
		if !ok || authInfo == nil {
			return nil, errors.Errorf("empty settings for user %q", user)
		}
		if len(authInfo.ClientCertificateData) == 0 && len(authInfo.ClientCertificate) != 0 {
			clientCert, err := ioutil.ReadFile(authInfo.ClientCertificate)
			if err != nil {
				return nil, err
			}
			authInfo.ClientCertificateData = clientCert
		}
		if len(authInfo.ClientKeyData) == 0 && len(authInfo.ClientKey) != 0 {
			clientKey, err := ioutil.ReadFile(authInfo.ClientKey)
			if err != nil {
				return nil, err
			}
			authInfo.ClientKeyData = clientKey
		}

		if len(authInfo.ClientCertificateData) == 0 || len(authInfo.ClientKeyData) == 0 {
			return nil, errors.New("couldn't read authentication info from the given kubeconfig file")
		}
		kubeconfig = kubeconfigutil.CreateWithCerts(
			defaultCluster.Server,
			clustername,
			"", // no user provided
			defaultCluster.CertificateAuthorityData,
			authInfo.ClientKeyData,
			authInfo.ClientCertificateData,
		)
	}

	client, err := kubeconfigutil.ToClientSet(kubeconfig)
	if err != nil {
		return nil, err
	}

	klog.V(1).Infof("[discovery] Created cluster-info discovery client, requesting info from %q\n", defaultCluster.Server)

	var clusterinfoCM *v1.ConfigMap
	wait.PollInfinite(constants.DiscoveryRetryInterval, func() (bool, error) {
		var err error
		clusterinfoCM, err = client.CoreV1().ConfigMaps(metav1.NamespacePublic).Get(bootstrapapi.ConfigMapClusterInfo, metav1.GetOptions{})
		if err != nil {
			if apierrors.IsForbidden(err) {
				// If the request is unauthorized, the cluster admin has not granted access to the cluster info configmap for unauthenticated users
				// In that case, trust the cluster admin and do not refresh the cluster-info credentials
				klog.Warningf("[discovery] Could not access the %s ConfigMap for refreshing the cluster-info information, but the TLS cert is valid so proceeding...\n", bootstrapapi.ConfigMapClusterInfo)
				return true, nil
			}
			klog.V(1).Infof("[discovery] Failed to validate the API Server's identity, will try again: [%v]\n", err)
			return false, nil
		}
		return true, nil
	})

	// If we couldn't fetch the cluster-info ConfigMap, just return the cluster-info object the user provided
	if clusterinfoCM == nil {
		return kubeconfig, nil
	}

	// We somehow got hold of the ConfigMap, try to read some data from it. If we can't, fallback on the user-provided file
	refreshedBaseKubeConfig, err := tryParseClusterInfoFromConfigMap(clusterinfoCM)
	if err != nil {
		klog.V(1).Infof("[discovery] The %s ConfigMap isn't set up properly (%v), but the TLS cert is valid so proceeding...\n", bootstrapapi.ConfigMapClusterInfo, err)
		return kubeconfig, nil
	}

	klog.V(1).Infoln("[discovery] Synced cluster-info information from the API Server so we have got the latest information")
	// In an HA world in the future, this will make more sense, because now we've got new information, possibly about new API Servers to talk to
	return refreshedBaseKubeConfig, nil
}
952838
func ProjectConfig(p project.APIProject, c *cli.Context) error {
	yaml, err := p.Config()
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	if !c.Bool("quiet") {
		fmt.Println(yaml)
	}
	return nil
}
1322972
func (l *PluginLoader) validatePluginConfig(id PluginID, info *pluginInfo) error {
	var mErr multierror.Error

	// Check if a config is allowed
	if info.configSchema == nil {
		if info.config != nil {
			return fmt.Errorf("configuration not allowed but config passed")
		}

		// Nothing to do
		return nil
	}

	// Convert the schema to hcl
	spec, diag := hclspecutils.Convert(info.configSchema)
	if diag.HasErrors() {
		multierror.Append(&mErr, diag.Errs()...)
		return multierror.Prefix(&mErr, "failed converting config schema:")
	}

	// If there is no config, initialize it to an empty map so we can still
	// handle defaults
	if info.config == nil {
		info.config = map[string]interface{}{}
	}

	// Parse the config using the spec
	val, diag := hclutils.ParseHclInterface(info.config, spec, nil)
	if diag.HasErrors() {
		multierror.Append(&mErr, diag.Errs()...)
		return multierror.Prefix(&mErr, "failed parsing config:")
	}

	// Marshal the value
	cdata, err := msgpack.Marshal(val, val.Type())
	if err != nil {
		return fmt.Errorf("failed to msgpack encode config: %v", err)
	}

	// Store the marshalled config
	info.msgpackConfig = cdata

	// Dispense the plugin and set its config and ensure it is error free
	instance, err := l.Dispense(id.Name, id.PluginType, nil, l.logger)
	if err != nil {
		return fmt.Errorf("failed to dispense plugin: %v", err)
	}
	defer instance.Kill()

	b, ok := instance.Plugin().(base.BasePlugin)
	if !ok {
		return fmt.Errorf("dispensed plugin %s doesn't meet base plugin interface", id)
	}

	c := &base.Config{
		PluginConfig: cdata,
		AgentConfig:  nil,
		ApiVersion:   info.apiVersion,
	}

	if err := b.SetConfig(c); err != nil {
		return fmt.Errorf("setting config on plugin failed: %v", err)
	}
	return nil
}
1322656
func validateConfig(config *PluginLoaderConfig) error {
	var mErr multierror.Error
	if config == nil {
		return fmt.Errorf("nil config passed")
	} else if config.Logger == nil {
		multierror.Append(&mErr, fmt.Errorf("nil logger passed"))
	}

	// Validate that all plugins have a binary name
	for _, c := range config.Configs {
		if c.Name == "" {
			multierror.Append(&mErr, fmt.Errorf("plugin config passed without binary name"))
		}
	}

	// Validate internal plugins
	for k, config := range config.InternalPlugins {
		// Validate config
		if config == nil {
			multierror.Append(&mErr, fmt.Errorf("nil config passed for internal plugin %s", k))
			continue
		} else if config.Factory == nil {
			multierror.Append(&mErr, fmt.Errorf("nil factory passed for internal plugin %s", k))
			continue
		}
	}

	return mErr.ErrorOrNil()
}
350827
func ValidateProjectUpdate(newProject *projectapi.Project, oldProject *projectapi.Project) field.ErrorList {
	allErrs := validation.ValidateObjectMetaUpdate(&newProject.ObjectMeta, &oldProject.ObjectMeta, field.NewPath("metadata"))
	allErrs = append(allErrs, ValidateProject(newProject)...)

	if !reflect.DeepEqual(newProject.Spec.Finalizers, oldProject.Spec.Finalizers) {
		allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "finalizers"), oldProject.Spec.Finalizers, "field is immutable"))
	}
	if !reflect.DeepEqual(newProject.Status, oldProject.Status) {
		allErrs = append(allErrs, field.Invalid(field.NewPath("status"), oldProject.Spec.Finalizers, "field is immutable"))
	}

	// TODO this restriction exists because our authorizer/admission cannot properly express and restrict mutation on the field level.
	for name, value := range newProject.Annotations {
		if name == oapi.OpenShiftDisplayName || name == oapi.OpenShiftDescription {
			continue
		}

		if value != oldProject.Annotations[name] {
			allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(name), value, "field is immutable, try updating the namespace"))
		}
	}
	// check for deletions
	for name, value := range oldProject.Annotations {
		if name == oapi.OpenShiftDisplayName || name == oapi.OpenShiftDescription {
			continue
		}
		if _, inNew := newProject.Annotations[name]; !inNew {
			allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(name), value, "field is immutable, try updating the namespace"))
		}
	}

	for name, value := range newProject.Labels {
		if value != oldProject.Labels[name] {
			allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "labels").Key(name), value, "field is immutable, , try updating the namespace"))
		}
	}
	for name, value := range oldProject.Labels {
		if _, inNew := newProject.Labels[name]; !inNew {
			allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "labels").Key(name), value, "field is immutable, try updating the namespace"))
		}
	}

	return allErrs
}
1038402
func (m *MockProvisionerClient) ValidateProvisionerConfig(arg0 context.Context, arg1 *tfplugin5.ValidateProvisionerConfig_Request, arg2 ...grpc.CallOption) (*tfplugin5.ValidateProvisionerConfig_Response, error) {
	m.ctrl.T.Helper()
	varargs := []interface{}{arg0, arg1}
	for _, a := range arg2 {
		varargs = append(varargs, a)
	}
	ret := m.ctrl.Call(m, "ValidateProvisionerConfig", varargs...)
	ret0, _ := ret[0].(*tfplugin5.ValidateProvisionerConfig_Response)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}