// GetPlugin returns the plugin by name
356632
func GetPlugin(name string) Plugin {
	// Find the conf store
	pluginMutex.Lock()
	defer pluginMutex.Unlock()
	if pluginList[name] == nil {
		log.Errorf("Objdb Plugin %s not registered", name)
		return nil
	}

	return pluginList[name]
}
865738
func GetPluginExecutablePath(name string) (string, bool, error) {
	route, found, err := ReadPluginRoute(name)
	if err != nil {
		return "", false, err
	}
	if !found {
		return "", false, fmt.Errorf("plugin not installed with name (%s)", name)
	}

	if route.Executable != "" {
		return filepath.Join(GetPluginBinDir(name), name), true, nil
	}
	return filepath.Join(GetPluginSrcDir(name), pluginScriptFileName), false, nil
}
336837
func (e *examplePlugin) GetInfo(ctx context.Context, req *registerapi.InfoRequest) (*registerapi.PluginInfo, error) {
	return &registerapi.PluginInfo{
		Type:              e.pluginType,
		Name:              e.pluginName,
		Endpoint:          e.endpoint,
		SupportedVersions: e.versions,
	}, nil
}
925520
func GetPluginProperties(jsonPropertiesFile string) (map[string]interface{}, error) {
	pluginPropertiesJSON, err := ioutil.ReadFile(jsonPropertiesFile)
	if err != nil {
		return nil, fmt.Errorf("Could not read %s: %s\n", filepath.Base(jsonPropertiesFile), err)
	}
	var pluginJSON interface{}
	if err = json.Unmarshal([]byte(pluginPropertiesJSON), &pluginJSON); err != nil {
		return nil, fmt.Errorf("Could not read %s: %s\n", filepath.Base(jsonPropertiesFile), err)
	}
	return pluginJSON.(map[string]interface{}), nil
}
1258061
func (d *MasterDaemon) getPluginAddress(hostName string) (string, error) {
	srvList, err := d.objdbClient.GetService("netplugin.vtep")
	if err != nil {
		log.Errorf("Error getting netplugin nodes. Err: %v", err)
		return "", err
	}

	for _, srv := range srvList {
		if srv.Hostname == hostName {
			return srv.HostAddr, nil
		}
	}

	return "", fmt.Errorf("Could not find plugin instance with name: %s", hostName)
}
819756
func GetDriver(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) {
	if initFunc, exists := drivers[name]; exists {
		return initFunc(filepath.Join(config.Root, name), config.DriverOptions, config.UIDMaps, config.GIDMaps)
	}

	pluginDriver, err := lookupPlugin(name, pg, config)
	if err == nil {
		return pluginDriver, nil
	}
	logrus.WithError(err).WithField("driver", name).WithField("home-dir", config.Root).Error("Failed to GetDriver graph")
	return nil, ErrNotSupported
}
989668
func NewPlugin(name string, getQueries GetQueriesFunc, writeResults WriteResultsFunc) *Plugin {
	return &Plugin{name: name, getQueries: getQueries, writeResults: writeResults}
}
600653
func GetGaugePluginVersion(pluginName string) (string, error) {
	pluginProperties, err := GetPluginProperties(fmt.Sprintf("%s.json", pluginName))
	if err != nil {
		return "", fmt.Errorf("Failed to get gauge %s properties file. %s", pluginName, err)
	}
	return pluginProperties["version"].(string), nil
}
469330
func Lookup(name string) ChainingPlugin {
	mutex.RLock()
	defer mutex.RUnlock()

	return chainingPlugins[name]
}
1170930
func Get(kind Kind, name string) *Plugin {
	plugins := pluginGlobal.plugins()
	if plugins == nil {
		return nil
	}
	for _, p := range plugins.plugins[kind] {
		if p.Name == name {
			return &p
		}
	}
	return nil
}
545477
func (c *Client) InspectPlugins(name string, ctx context.Context) (*PluginDetail, error) {
	resp, err := c.do("GET", "/plugins/"+name+"/json", doOptions{
		context: ctx,
	})
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if err != nil {
		if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
			return nil, &NoSuchPlugin{ID: name}
		}
		return nil, err
	}
	resp.Body.Close()
	var pluginDetail PluginDetail
	if err := json.NewDecoder(resp.Body).Decode(&pluginDetail); err != nil {
		return nil, err
	}
	return &pluginDetail, nil
}
565751
func (c *PluginCatalog) getPluginTypeFromUnknown(ctx context.Context, logger log.Logger, plugin *pluginutil.PluginRunner) (consts.PluginType, error) {

	{
		// Attempt to run as database plugin
		client, err := dbplugin.NewPluginClient(ctx, nil, plugin, log.NewNullLogger(), true)
		if err == nil {
			// Close the client and cleanup the plugin process
			client.Close()
			return consts.PluginTypeDatabase, nil
		} else {
			logger.Warn(fmt.Sprintf("received %s attempting as db plugin, attempting as auth/secret plugin", err))
		}
	}

	{
		// Attempt to run as backend plugin
		client, err := backendplugin.NewPluginClient(ctx, nil, plugin, log.NewNullLogger(), true)
		if err == nil {
			err := client.Setup(ctx, &logical.BackendConfig{})
			if err != nil {
				return consts.PluginTypeUnknown, err
			}

			backendType := client.Type()
			client.Cleanup(ctx)

			switch backendType {
			case logical.TypeCredential:
				return consts.PluginTypeCredential, nil
			case logical.TypeLogical:
				return consts.PluginTypeSecrets, nil
			}
			logger.Warn(fmt.Sprintf("unknown backendType of %s", backendType))
		} else {
			logger.Warn(fmt.Sprintf("received %s attempting as an auth/secret plugin, continuing", err))
		}
	}

	return consts.PluginTypeUnknown, nil
}
622989
func (l *localRegistry) Plugin(name string) (*Plugin, error) {
	socketpaths := pluginPaths(socketsPath, name, ".sock")

	for _, p := range socketpaths {
		if fi, err := os.Stat(p); err == nil && fi.Mode()&os.ModeSocket != 0 {
			return NewLocalPlugin(name, "unix://"+p), nil
		}
	}

	var txtspecpaths []string
	for _, p := range specsPaths {
		txtspecpaths = append(txtspecpaths, pluginPaths(p, name, ".spec")...)
		txtspecpaths = append(txtspecpaths, pluginPaths(p, name, ".json")...)
	}

	for _, p := range txtspecpaths {
		if _, err := os.Stat(p); err == nil {
			if strings.HasSuffix(p, ".json") {
				return readPluginJSONInfo(name, p)
			}
			return readPluginInfo(name, p)
		}
	}
	return nil, errors.Wrapf(ErrNotFound, "could not find plugin %s in v1 plugin registry", name)
}
1112958
func (pm *PluginManager) savePlugin(p *plugin) error {
	// save the plugin by name
	if _, exists := pm.pluginsByName[p.name]; exists {
		return errors.New("Plugin already exists with that name")
	}
	pm.pluginsByName[p.name] = p

	// save the plugin by type
	// either add it to the existing slice
	// or create a new one
	if plugins, ok := pm.pluginsByType[p.iFace.Identifier]; ok {
		plugins = append(plugins, p)
		pm.pluginsByType[p.iFace.Identifier] = plugins
	} else {
		plugins = []*plugin{p}
		pm.pluginsByType[p.iFace.Identifier] = plugins
	}

	return nil
}
570766
func (reader PluginConfigReaderWithError) GetPluginArray(key string, defaultValue []Plugin) ([]Plugin, error) {
	key = reader.config.registerKey(key)
	namedConfigs, err := reader.GetArray(key, []interface{}{})
	if err != nil {
		return defaultValue, err
	}

	if len(namedConfigs) == 0 {
		return defaultValue, nil
	}

	pluginArray := make([]Plugin, 0, len(namedConfigs))

	// Iterate over all entries in the array.
	// An entry can either be a string or a string -> map[string]interface{}
	for _, typedConfigInterface := range namedConfigs {
		typedConfigMap := tcontainer.TryConvertToMarshalMap(typedConfigInterface, nil)
		typedConfig, isMap := typedConfigMap.(tcontainer.MarshalMap)

		if !isMap {
			typeNameStr, isString := typedConfigInterface.(string)
			if !isString {
				return nil, fmt.Errorf("%s section is malformed (entry does not contain a config)", key)
			}

			// Only string given, initialize with empty config
			pluginConfig, _ := NewNestedPluginConfig(typeNameStr, tcontainer.NewMarshalMap())
			plugin, err := NewPluginWithConfig(pluginConfig)
			if err != nil {
				return nil, err
			}
			pluginArray = append(pluginArray, plugin)
		}

		// string -> map[string]interface{}
		// This is actually a map with just one entry
		for typename, config := range typedConfig {
			configMap, err := tcontainer.ConvertToMarshalMap(config, nil)
			if err != nil {
				return nil, fmt.Errorf("%s section is malformed (config for %s is not a map but %T)", key, typename, config)
			}

			pluginConfig, _ := NewNestedPluginConfig(typename, configMap)
			plugin, err := NewPluginWithConfig(pluginConfig)
			if err != nil {
				return pluginArray, err
			}
			pluginArray = append(pluginArray, plugin)
		}
	}

	return pluginArray, nil
}
776567
func (ps *Store) GetV2Plugin(refOrID string) (*v2.Plugin, error) {
	ps.RLock()
	defer ps.RUnlock()

	id, err := ps.resolvePluginID(refOrID)
	if err != nil {
		return nil, err
	}

	p, idOk := ps.plugins[id]
	if !idOk {
		return nil, errors.WithStack(errNotFound(id))
	}

	return p, nil
}
1245611
func (c *Client) GetPlugin(typ, name string, ver int) *GetPluginResult {
	r := &GetPluginResult{}

	path := "/plugins/" + typ + "/" + name + "/" + strconv.Itoa(ver)

	resp, err := c.do("GET", path, ContentTypeJSON)
	if err != nil {
		r.Err = err
		return r
	}

	switch resp.Meta.Type {
	// TODO change this to concrete const type when Joel adds it
	case rbody.PluginReturnedType:
		// Success
		b := resp.Body.(*rbody.PluginReturned)
		r.ReturnedPlugin = ReturnedPlugin{b}
		return r
	case rbody.ErrorType:
		r.Err = resp.Body.(*rbody.Error)
	default:
		r.Err = ErrAPIResponseMetaType
	}
	return r
}