-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
plugin.ts
208 lines (175 loc) · 5.04 KB
/
plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { ComponentType } from 'react';
import { KeyValue } from './data';
import { IconName } from './icon';
/** Describes plugins life cycle status */
export enum PluginState {
alpha = 'alpha', // Only included if `enable_alpha` config option is true
beta = 'beta', // Will show a warning banner
stable = 'stable', // Will not show anything
deprecated = 'deprecated', // Will continue to work -- but not show up in the options to add
}
/** Describes {@link https://grafana.com/docs/grafana/latest/plugins | type of plugin} */
export enum PluginType {
panel = 'panel',
datasource = 'datasource',
app = 'app',
renderer = 'renderer',
secretsmanager = 'secretsmanager',
}
/** Describes status of {@link https://grafana.com/docs/grafana/latest/plugins/plugin-signatures/ | plugin signature} */
export enum PluginSignatureStatus {
internal = 'internal', // core plugin, no signature
valid = 'valid', // signed and accurate MANIFEST
invalid = 'invalid', // invalid signature
modified = 'modified', // valid signature, but content mismatch
missing = 'missing', // missing signature file
}
/** Describes level of {@link https://grafana.com/docs/grafana/latest/plugins/plugin-signatures/#plugin-signature-levels/ | plugin signature level} */
export enum PluginSignatureType {
grafana = 'grafana',
commercial = 'commercial',
community = 'community',
private = 'private',
core = 'core',
}
/** Describes error code returned from Grafana plugins API call */
export enum PluginErrorCode {
missingSignature = 'signatureMissing',
invalidSignature = 'signatureInvalid',
modifiedSignature = 'signatureModified',
}
/** Describes error returned from Grafana plugins API call */
export interface PluginError {
errorCode: PluginErrorCode;
pluginId: string;
}
export interface PluginMeta<T extends KeyValue = {}> {
id: string;
name: string;
type: PluginType;
info: PluginMetaInfo;
includes?: PluginInclude[];
state?: PluginState;
alias?: string;
// System.load & relative URLS
module: string;
baseUrl: string;
// Define plugin requirements
dependencies?: PluginDependencies;
// Filled in by the backend
jsonData?: T;
secureJsonData?: KeyValue;
secureJsonFields?: KeyValue<boolean>;
enabled?: boolean;
defaultNavUrl?: string;
hasUpdate?: boolean;
enterprise?: boolean;
latestVersion?: string;
pinned?: boolean;
signature?: PluginSignatureStatus;
signatureType?: PluginSignatureType;
signatureOrg?: string;
live?: boolean;
angularDetected?: boolean;
}
interface PluginDependencyInfo {
id: string;
name: string;
version: string;
type: PluginType;
}
export interface PluginDependencies {
grafanaDependency?: string;
grafanaVersion: string;
plugins: PluginDependencyInfo[];
}
export enum PluginIncludeType {
dashboard = 'dashboard',
page = 'page',
// Only valid for apps
panel = 'panel',
datasource = 'datasource',
}
export interface PluginInclude {
type: PluginIncludeType;
name: string;
path?: string;
icon?: string;
// "Admin", "Editor" or "Viewer". If set then the include will only show up in the navigation if the user has the required roles.
role?: string;
// Adds the "page" or "dashboard" type includes to the navigation if set to `true`.
addToNav?: boolean;
// Angular app pages
component?: string;
}
interface PluginMetaInfoLink {
name: string;
url: string;
target?: '_blank' | '_self' | '_parent' | '_top';
}
export interface PluginBuildInfo {
time?: number;
repo?: string;
branch?: string;
hash?: string;
number?: number;
pr?: number;
}
export interface ScreenshotInfo {
name: string;
path: string;
}
export interface PluginMetaInfo {
author: {
name: string;
url?: string;
};
description: string;
links: PluginMetaInfoLink[];
logos: {
large: string;
small: string;
};
build?: PluginBuildInfo;
screenshots: ScreenshotInfo[];
updated: string;
version: string;
}
export interface PluginConfigPageProps<T extends PluginMeta> {
plugin: GrafanaPlugin<T>;
query: KeyValue; // The URL query parameters
}
export interface PluginConfigPage<T extends PluginMeta> {
title: string; // Display
icon?: IconName;
id: string; // Unique, in URL
body: ComponentType<PluginConfigPageProps<T>>;
}
export class GrafanaPlugin<T extends PluginMeta = PluginMeta> {
// Meta is filled in by the plugin loading system
meta: T;
// This is set if the plugin system had errors loading the plugin
loadError?: boolean;
// Config control (app/datasource)
angularConfigCtrl?: any;
// Show configuration tabs on the plugin page
configPages?: Array<PluginConfigPage<T>>;
// Tabs on the plugin page
addConfigPage(tab: PluginConfigPage<T>) {
if (!this.configPages) {
this.configPages = [];
}
this.configPages.push(tab);
return this;
}
/**
* @deprecated -- this is no longer necessary and will be removed
*/
setChannelSupport(support: any) {
console.warn('[deprecation] plugin is using ignored option: setChannelSupport', this.meta);
return this;
}
constructor() {
this.meta = {} as T;
}
}