func (p *RequestedPlugin) TLSEnabled() bool {
	return p.tlsEnabled
}
TLSEnabled returns the TLS enabled flag for requested plugin
package core
import (
	"bufio"
	"crypto/sha256"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"time"
	"net/url"
	"github.com/asaskevich/govalidator"
	"github.com/intelsdi-x/snap/control/plugin/cpolicy"
	"github.com/intelsdi-x/snap/core/cdata"
	"github.com/intelsdi-x/snap/core/serror"
	"github.com/intelsdi-x/snap/pkg/fileutils"
)
type Plugin interface {
	TypeName() string
	Name() string
	Version() int
}
type PluginType int
func ToPluginType(name string) (PluginType, error) {
	pts := map[string]PluginType{
		"collector":           0,
		"processor":           1,
		"publisher":           2,
		"streaming-collector": 3,
	}
	t, ok := pts[name]
	if !ok {
		return -1, fmt.Errorf("invalid plugin type name given %s", name)
	}
	return t, nil
}
func CheckPluginType(id PluginType) bool {
	pts := map[PluginType]string{
		0: "collector",
		1: "processor",
		2: "publisher",
		3: "streaming-collector",
	}
	_, ok := pts[id]
	return ok
}
func GetPluginType(t string) (PluginType, error) {
	if ityp, err := strconv.Atoi(t); err == nil {
		if !CheckPluginType(PluginType(ityp)) {
			return PluginType(-1), fmt.Errorf("invalid plugin type id given %d", ityp)
		}
		return PluginType(ityp), nil
	}
	return ToPluginType(t)
}
func (pt PluginType) String() string {
	return []string{
		"collector",
		"processor",
		"publisher",
		"streaming-collector",
	}[pt]
}
const (
	CollectorPluginType PluginType = iota
	ProcessorPluginType
	PublisherPluginType
	StreamingCollectorPluginType
)
type AvailablePlugin interface {
	Plugin
	HitCount() int
	LastHit() time.Time
	ID() uint32
	Port() string
}
type CatalogedPlugin interface {
	Plugin
	IsSigned() bool
	Status() string
	PluginPath() string
	LoadedTimestamp() *time.Time
	Policy() *cpolicy.ConfigPolicy
	Key() string
}
type PluginCatalog []CatalogedPlugin
type SubscribedPlugin interface {
	Plugin
	Config() *cdata.ConfigDataNode
}
type SubscribedPluginAssert func(plugins []SubscribedPlugin) serror.SnapError
type RequestedPlugin struct {
	path        string
	checkSum    [sha256.Size]byte
	signature   []byte
	certPath    string
	keyPath     string
	caCertPaths string
	tlsEnabled  bool
	autoLoaded  bool
	uri         *url.URL
}
func NewRequestedPlugin(path, fileName string, b []byte) (*RequestedPlugin, error) {
	if IsUri(path) {
		if uri, err := url.ParseRequestURI(path); err == nil && uri != nil {
			return &RequestedPlugin{uri: uri}, nil
		}
	}
	var rp *RequestedPlugin
	if b == nil {
		file, err := os.Open(path)
		if err != nil {
			return nil, err
		}
		defer file.Close()
		info, err := file.Stat()
		if err != nil {
			return nil, err
		}
		size := info.Size()
		bytes := make([]byte, size)
		buffer := bufio.NewReader(file)
		_, err = buffer.Read(bytes)
		if err != nil {
			return nil, err
		}
		tempFile, err := fileutils.WriteFile(filepath.Base(path), fileName, bytes)
		if err != nil {
			return nil, err
		}
		rp = &RequestedPlugin{
			path:      tempFile,
			signature: nil,
		}
		genErr := rp.generateCheckSum()
		if genErr != nil {
			return nil, err
		}
	} else {
		tmpFile, err := fileutils.WriteFile(filepath.Base(path), fileName, b)
		if err != nil {
			return nil, nil
		}
		rp = &RequestedPlugin{
			path:      tmpFile,
			signature: nil,
		}
		genErr := rp.generateCheckSum()
		if genErr != nil {
			return nil, err
		}
	}
	return rp, nil
}
func IsUri(url string) bool {
	if !govalidator.IsURL(url) || !strings.HasPrefix(url, "http") {
		return false
	}
	return true
}
func (p *RequestedPlugin) Path() string {
	return p.path
}
func (p *RequestedPlugin) CertPath() string {
	return p.certPath
}
func (p *RequestedPlugin) KeyPath() string {
	return p.keyPath
}
func (p *RequestedPlugin) CACertPaths() string {
	return p.caCertPaths
}