plugin_settings.go 1.67 KB
Newer Older
woodsaj committed
1 2
package models

3 4 5
import (
	"errors"
	"time"
6

7
	"github.com/grafana/grafana/pkg/components/securejsondata"
8 9 10
)

var (
11
	ErrPluginSettingNotFound = errors.New("Plugin setting not found")
12
)
13

14
type PluginSetting struct {
15
	Id             int64
16
	PluginId       string
17 18 19 20
	OrgId          int64
	Enabled        bool
	Pinned         bool
	JsonData       map[string]interface{}
21
	SecureJsonData securejsondata.SecureJsonData
22
	PluginVersion  string
23 24 25 26 27 28 29 30 31

	Created time.Time
	Updated time.Time
}

// ----------------------
// COMMANDS

// Also acts as api DTO
32
type UpdatePluginSettingCmd struct {
33 34 35 36
	Enabled        bool                   `json:"enabled"`
	Pinned         bool                   `json:"pinned"`
	JsonData       map[string]interface{} `json:"jsonData"`
	SecureJsonData map[string]string      `json:"secureJsonData"`
37
	PluginVersion  string                 `json:"version"`
38

39 40
	PluginId string `json:"-"`
	OrgId    int64  `json:"-"`
41 42
}

43 44 45 46 47 48 49
// specific command, will only update version
type UpdatePluginSettingVersionCmd struct {
	PluginVersion string
	PluginId      string `json:"-"`
	OrgId         int64  `json:"-"`
}

50 51
func (cmd *UpdatePluginSettingCmd) GetEncryptedJsonData() securejsondata.SecureJsonData {
	return securejsondata.GetEncryptedJsonData(cmd.SecureJsonData)
52 53
}

54 55
// ---------------------
// QUERIES
56
type GetPluginSettingsQuery struct {
57
	OrgId  int64
58 59 60 61
	Result []*PluginSettingInfoDTO
}

type PluginSettingInfoDTO struct {
62 63 64 65 66
	OrgId         int64
	PluginId      string
	Enabled       bool
	Pinned        bool
	PluginVersion string
woodsaj committed
67
}
68

69 70 71 72
type GetPluginSettingByIdQuery struct {
	PluginId string
	OrgId    int64
	Result   *PluginSetting
73
}
74 75 76 77 78 79

type PluginStateChangedEvent struct {
	PluginId string
	OrgId    int64
	Enabled  bool
}