// ParsePluginFromYML ...
487929
func ParsePluginFromYML(ymlPth string) (Plugin, error) {
	// Parse plugin
	if isExists, err := pathutil.IsPathExists(ymlPth); err != nil {
		return Plugin{}, err
	} else if !isExists {
		return Plugin{}, fmt.Errorf("plugin definition does not exist at: %s", ymlPth)
	}

	bytes, err := fileutil.ReadBytesFromFile(ymlPth)
	if err != nil {
		return Plugin{}, err
	}

	plugin, err := parsePluginFromBytes(bytes)
	if err != nil {
		return Plugin{}, err
	}

	return plugin, nil
}
686632
func formatPluginName(str string) string {
	str = strings.Replace(str, "_", " ", -1)
	str = strings.Title(str)
	return strings.Replace(str, " ", "", -1)
}
41100
func (inliner *Inliner) parseHTML() error {
	doc, err := goquery.NewDocumentFromReader(strings.NewReader(inliner.html))
	if err != nil {
		return err
	}

	inliner.doc = doc

	return nil
}
1081887
func (registry *pluginRegistry) GetPlugin(ID string) Plugin {
	registry.guard.RLock()
	plugin, exists := registry.plugins[ID]
	registry.guard.RUnlock()

	if exists {
		return plugin
	}
	return nil
}
1324402
func InfoFromPlugin(pluginPath string) (PluginInfo, error) {
	cmd := exec.Command(pluginPath, PluginInfoCommandName)
	bytes, err := cmd.CombinedOutput()
	if err != nil {
		return nil, errors.Wrapf(err, "command %v failed.\nError:\n%v\nOutput:\n%s\n", cmd.Args, err, string(bytes))
	}

	var schemaVersionVar v1.SchemaVersion
	if err := json.Unmarshal(bytes, &schemaVersionVar); err != nil {
		return nil, errors.Wrapf(err, "failed to unmarshal plugin schema version for plugin %s from output %q", pluginPath, string(bytes))
	}

	var pluginInfo PluginInfo
	switch version := schemaVersionVar.PluginSchemaVersionVar; version {
	case v1.CurrentSchemaVersion:
		v1Info, err := v1.InfoFromBytes(bytes)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to unmarshal v1 plugin information")
		}

		// do baseline check/validation
		parts := strings.Split(v1Info.ID(), ":")
		if len(parts) != 3 {
			return nil, errors.Wrapf(err, "v1 plugin information provided invalid ID: %q", v1Info.ID())
		}
		if _, err := NewPluginInfo(parts[0], parts[1], parts[2]); err != nil {
			return nil, errors.Wrapf(err, "could not create v2 plugin info from v1 plugin info")
		}
		pluginInfo = wrappedV1PluginInfoImpl{
			v1PluginInfo: v1Info,
		}
	case CurrentSchemaVersion:
		var v2Info pluginInfoImpl
		if err := json.Unmarshal(bytes, &v2Info); err != nil {
			return nil, errors.Wrapf(err, "failed to unmarshal plugin information for plugin %s from output %q", pluginPath, string(bytes))
		}
		pluginInfo = v2Info
	default:
		return nil, errors.Errorf("unsupported plugin schema version: %s", version)
	}

	if !strings.HasSuffix(pluginInfo.Product(), "-plugin") {
		return nil, errors.Errorf(`plugin %s has an invalid product name: product names must have suffix "-plugin", but was %q`, pluginPath, pluginInfo.Product())
	}
	return pluginInfo, nil
}
422367
func ParseModule(filename, input string) (*Module, error) {
	stmts, comments, err := ParseStatements(filename, input)
	if err != nil {
		return nil, err
	}
	return parseModule(stmts, comments)
}
1305462
func WriteSML(node Node, ctx *WriterContext) error {
	wp := ctx.plugins[""]
	if wp == nil {
		return errors.New(ErrNoRootProcessor, errorMessages)
	}
	w := &mlWriter{
		context: ctx,
		stack:   []WriterProcessor{wp},
		indent:  0,
	}
	// Process the node with the new writer.
	if err := node.ProcessWith(w); err != nil {
		return err
	}
	return nil
}
42394
func (logger *Logger) parseFormat(format string) error {
	logger.runtime = false
	fts := strings.Split(format, "\n")
	if len(fts) != 2 {
		return errors.New("logging format error")
	}
	logger.recordFormat = fts[0]
	logger.recordArgs = strings.Split(fts[1], ",")
	for k, v := range logger.recordArgs {
		tv := strings.TrimSpace(v)
		_, ok := fields[tv]
		if ok == false {
			return errors.New("logging format error")
		}
		logger.recordArgs[k] = tv
		logger.runtime = logger.runtime || runtimeFields[tv]
	}
	return nil
}
1138549
func ToCorePlugins(pl []core.SubscribedPlugin) []core.Plugin {
	plugins := make([]core.Plugin, len(pl))
	for i, v := range pl {
		plugins[i] = v
	}
	return plugins
}
1160804
func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
	var err error

	// Parse PEM block
	var block *pem.Block
	if block, _ = pem.Decode(key); block == nil {
		return nil, ErrKeyMustBePEMEncoded
	}

	// Parse the key
	var parsedKey interface{}
	if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil {
		return nil, err
	}

	var pkey *ecdsa.PrivateKey
	var ok bool
	if pkey, ok = parsedKey.(*ecdsa.PrivateKey); !ok {
		return nil, ErrNotECPrivateKey
	}

	return pkey, nil
}
9046
func (p *Prometheus) UnmarshalTOML(data interface{}) error {
	dataOK, ok := data.(map[string]interface{})
	if !ok {
		return errors.New("bad urls for prometheus input plugin")
	}
	urls, ok := dataOK["urls"].([]interface{})
	if !ok {
		return errors.New("urls is not an array for prometheus input plugin")
	}
	for _, url := range urls {
		p.URLs = append(p.URLs, url.(string))
	}
	return nil
}
1090098
func (pm *PluginManager) loadPlugin(path, name string) error {
	libPath := path + "/" + name
	lib, err := dl.Open(libPath, dl.RTLD_LAZY)
	if err != nil {
		return err
	}
	// remove the .so from the file name
	name = name[:len(name)-3]

	p := &plugin{
		name: formatPluginName(name),
		lib:  lib,
	}

	// get the type of the plugin
	// and its associated interface definition
	t := p.getType()
	if _, exists := pm.interfaces[t]; !exists {
		return errors.New("Plugin loaded with an undefined type")
	}
	iface := pm.interfaces[t]
	p.iFace = &iface

	// ensure it implements the interface as defined
	// by the type and create a new instance of this plugin
	// via the defined factory, and map
	err = p.bootstrap()
	if err != nil {
		return err
	}

	// save our plugin
	err = pm.savePlugin(p)
	if err != nil {
		return err
	}

	// we're good!
	return nil
}
1000630
func (original Transform) TransformFromXML(from, to Transform, fncMap template.FuncMap) (string, error) {
	doc := etree.NewDocument()
	if err := doc.ReadFromString(string(original)); err != nil {
		return "", err
	}
	if translator, err := getTranslator(string(from)); err != nil {
		return "", err
	} else {
		values := createMapValues(translator, doc)
		return generateTransformedMessage(values, to, fncMap)
	}

}
576527
func getPluginMap(pluginType string, logger log.Logger) map[string]plugin.Plugin {
	pmap := map[string]plugin.Plugin{
		base.PluginTypeBase: &base.PluginBase{},
	}

	switch pluginType {
	case base.PluginTypeDevice:
		pmap[base.PluginTypeDevice] = &device.PluginDevice{}
	case base.PluginTypeDriver:
		pmap[base.PluginTypeDriver] = drivers.NewDriverPlugin(nil, logger)
	}

	return pmap
}
890605
func (config *Config) GetPlugin(pluginName string) (Plugin, bool) {
	plugin, exists := config.pluginsConfig.Plugins[pluginName]
	return plugin, exists
}
42026
func (f *PluginFilter) pluginExistsOnNode(pluginType string, pluginName string, nodePlugins []api.PluginDescription) (bool, bool) {
	var typeFound bool

	for _, np := range nodePlugins {
		if pluginType != np.Type {
			continue
		}
		typeFound = true

		if pluginName == np.Name {
			return true, true
		}
		// This does not use the reference package to avoid the
		// overhead of parsing references as part of the scheduling
		// loop. This is okay only because plugin names are a very
		// strict subset of the reference grammar that is always
		// name:tag.
		if strings.HasPrefix(np.Name, pluginName) && np.Name[len(pluginName):] == ":latest" {
			return true, true
		}
	}
	return typeFound, false
}
127182
func (l *PluginLoader) validatePluginConfigs() error {
	var mErr multierror.Error
	for id, info := range l.plugins {
		if err := l.validatePluginConfig(id, info); err != nil {
			wrapped := multierror.Prefix(err, fmt.Sprintf("plugin %s:", id))
			multierror.Append(&mErr, wrapped)
		}
	}

	return mErr.ErrorOrNil()
}