Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
766d8a58
Unverified
Commit
766d8a58
authored
Mar 04, 2020
by
Carl Bergquist
Committed by
GitHub
Mar 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid aliased import in cli (#22566)
parent
3fdd2648
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
32 deletions
+33
-32
pkg/cmd/grafana-cli/commands/install_command.go
+7
-7
pkg/cmd/grafana-cli/commands/ls_command.go
+4
-4
pkg/cmd/grafana-cli/commands/ls_command_test.go
+5
-4
pkg/cmd/grafana-cli/commands/upgrade_all_command.go
+6
-6
pkg/cmd/grafana-cli/commands/upgrade_command.go
+3
-3
pkg/cmd/grafana-cli/services/services.go
+8
-8
No files found.
pkg/cmd/grafana-cli/commands/install_command.go
View file @
766d8a58
...
...
@@ -20,8 +20,8 @@ import (
"golang.org/x/xerrors"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
)
func
validateInput
(
c
utils
.
CommandLine
,
pluginFolder
string
)
error
{
...
...
@@ -132,7 +132,7 @@ func InstallPlugin(pluginName, version string, c utils.CommandLine, client utils
logger
.
Infof
(
"%s Installed %s successfully
\n
"
,
color
.
GreenString
(
"✔"
),
pluginName
)
res
,
_
:=
s
.
ReadPlugin
(
pluginFolder
,
pluginName
)
res
,
_
:=
s
ervices
.
ReadPlugin
(
pluginFolder
,
pluginName
)
for
_
,
v
:=
range
res
.
Dependencies
.
Plugins
{
if
err
:=
InstallPlugin
(
v
.
Id
,
""
,
c
,
client
);
err
!=
nil
{
return
errutil
.
Wrapf
(
err
,
"failed to install plugin '%s'"
,
v
.
Id
)
...
...
@@ -150,7 +150,7 @@ func osAndArchString() string {
return
osString
+
"-"
+
arch
}
func
supportsCurrentArch
(
version
*
m
.
Version
)
bool
{
func
supportsCurrentArch
(
version
*
m
odels
.
Version
)
bool
{
if
version
.
Arch
==
nil
{
return
true
}
...
...
@@ -162,7 +162,7 @@ func supportsCurrentArch(version *m.Version) bool {
return
false
}
func
latestSupportedVersion
(
plugin
*
m
.
Plugin
)
*
m
.
Version
{
func
latestSupportedVersion
(
plugin
*
m
odels
.
Plugin
)
*
models
.
Version
{
for
_
,
ver
:=
range
plugin
.
Versions
{
if
supportsCurrentArch
(
&
ver
)
{
return
&
ver
...
...
@@ -174,8 +174,8 @@ func latestSupportedVersion(plugin *m.Plugin) *m.Version {
// SelectVersion returns latest version if none is specified or the specified version. If the version string is not
// matched to existing version it errors out. It also errors out if version that is matched is not available for current
// os and platform. It expects plugin.Versions to be sorted so the newest version is first.
func
SelectVersion
(
plugin
*
m
.
Plugin
,
version
string
)
(
*
m
.
Version
,
error
)
{
var
ver
m
.
Version
func
SelectVersion
(
plugin
*
m
odels
.
Plugin
,
version
string
)
(
*
models
.
Version
,
error
)
{
var
ver
m
odels
.
Version
latestForArch
:=
latestSupportedVersion
(
plugin
)
if
latestForArch
==
nil
{
...
...
pkg/cmd/grafana-cli/commands/ls_command.go
View file @
766d8a58
...
...
@@ -5,12 +5,12 @@ import (
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
)
var
ls_getPlugins
func
(
path
string
)
[]
m
.
InstalledPlugin
=
s
.
GetLocalPlugins
var
ls_getPlugins
func
(
path
string
)
[]
m
odels
.
InstalledPlugin
=
service
s
.
GetLocalPlugins
var
validateLsCommand
=
func
(
pluginDir
string
)
error
{
if
pluginDir
==
""
{
...
...
@@ -18,7 +18,7 @@ var validateLsCommand = func(pluginDir string) error {
}
logger
.
Debug
(
"plugindir: "
+
pluginDir
+
"
\n
"
)
pluginDirInfo
,
err
:=
s
.
IoHelper
.
Stat
(
pluginDir
)
pluginDirInfo
,
err
:=
s
ervices
.
IoHelper
.
Stat
(
pluginDir
)
if
err
!=
nil
{
return
err
}
...
...
pkg/cmd/grafana-cli/commands/ls_command_test.go
View file @
766d8a58
...
...
@@ -2,10 +2,11 @@ package commands
import
(
"errors"
"testing"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/commandstest"
s
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
.
"github.com/smartystreets/goconvey/convey"
"testing"
)
func
TestMissingPath
(
t
*
testing
.
T
)
{
...
...
@@ -18,7 +19,7 @@ func TestMissingPath(t *testing.T) {
cmd
:=
Command
{}
c
,
err
:=
commandstest
.
NewCliContext
(
map
[
string
]
string
{})
So
(
err
,
ShouldBeNil
)
s
.
IoHelper
=
&
commandstest
.
FakeIoUtil
{}
s
ervices
.
IoHelper
=
&
commandstest
.
FakeIoUtil
{}
Convey
(
"should return error"
,
func
()
{
err
:=
cmd
.
lsCommand
(
c
)
...
...
@@ -29,7 +30,7 @@ func TestMissingPath(t *testing.T) {
Convey
(
"Path is not a directory"
,
func
()
{
c
,
err
:=
commandstest
.
NewCliContext
(
map
[
string
]
string
{
"path"
:
"/var/lib/grafana/plugins"
})
So
(
err
,
ShouldBeNil
)
s
.
IoHelper
=
&
commandstest
.
FakeIoUtil
{
s
ervices
.
IoHelper
=
&
commandstest
.
FakeIoUtil
{
FakeIsDirectory
:
false
,
}
cmd
:=
Command
{}
...
...
pkg/cmd/grafana-cli/commands/upgrade_all_command.go
View file @
766d8a58
...
...
@@ -2,13 +2,13 @@ package commands
import
(
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/hashicorp/go-version"
)
func
shouldUpgrade
(
installed
string
,
remote
*
m
.
Plugin
)
bool
{
func
shouldUpgrade
(
installed
string
,
remote
*
m
odels
.
Plugin
)
bool
{
installedVersion
,
err
:=
version
.
NewVersion
(
installed
)
if
err
!=
nil
{
return
false
...
...
@@ -25,14 +25,14 @@ func shouldUpgrade(installed string, remote *m.Plugin) bool {
func
(
cmd
Command
)
upgradeAllCommand
(
c
utils
.
CommandLine
)
error
{
pluginsDir
:=
c
.
PluginDirectory
()
localPlugins
:=
s
.
GetLocalPlugins
(
pluginsDir
)
localPlugins
:=
s
ervices
.
GetLocalPlugins
(
pluginsDir
)
remotePlugins
,
err
:=
cmd
.
Client
.
ListAllPlugins
(
c
.
String
(
"repo"
))
if
err
!=
nil
{
return
err
}
pluginsToUpgrade
:=
make
([]
m
.
InstalledPlugin
,
0
)
pluginsToUpgrade
:=
make
([]
m
odels
.
InstalledPlugin
,
0
)
for
_
,
localPlugin
:=
range
localPlugins
{
for
_
,
remotePlugin
:=
range
remotePlugins
.
Plugins
{
...
...
@@ -47,7 +47,7 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
for
_
,
p
:=
range
pluginsToUpgrade
{
logger
.
Infof
(
"Updating %v
\n
"
,
p
.
Id
)
err
:=
s
.
RemoveInstalledPlugin
(
pluginsDir
,
p
.
Id
)
err
:=
s
ervices
.
RemoveInstalledPlugin
(
pluginsDir
,
p
.
Id
)
if
err
!=
nil
{
return
err
}
...
...
pkg/cmd/grafana-cli/commands/upgrade_command.go
View file @
766d8a58
...
...
@@ -3,7 +3,7 @@ package commands
import
(
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
s
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/util/errutil"
)
...
...
@@ -12,7 +12,7 @@ func (cmd Command) upgradeCommand(c utils.CommandLine) error {
pluginsDir
:=
c
.
PluginDirectory
()
pluginName
:=
c
.
Args
()
.
First
()
localPlugin
,
err
:=
s
.
ReadPlugin
(
pluginsDir
,
pluginName
)
localPlugin
,
err
:=
s
ervices
.
ReadPlugin
(
pluginsDir
,
pluginName
)
if
err
!=
nil
{
return
err
...
...
@@ -24,7 +24,7 @@ func (cmd Command) upgradeCommand(c utils.CommandLine) error {
}
if
shouldUpgrade
(
localPlugin
.
Info
.
Version
,
&
plugin
)
{
if
err
:=
s
.
RemoveInstalledPlugin
(
pluginsDir
,
pluginName
);
err
!=
nil
{
if
err
:=
s
ervices
.
RemoveInstalledPlugin
(
pluginsDir
,
pluginName
);
err
!=
nil
{
return
errutil
.
Wrapf
(
err
,
"failed to remove plugin '%s'"
,
pluginName
)
}
...
...
pkg/cmd/grafana-cli/services/services.go
View file @
766d8a58
...
...
@@ -11,11 +11,11 @@ import (
"time"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
)
var
(
IoHelper
m
.
IoUtil
=
IoUtilImp
{}
IoHelper
m
odels
.
IoUtil
=
IoUtilImp
{}
HttpClient
http
.
Client
HttpClientNoTimeout
http
.
Client
grafanaVersion
string
...
...
@@ -63,7 +63,7 @@ func makeHttpClient(skipTLSVerify bool, timeout time.Duration) http.Client {
}
}
func
ReadPlugin
(
pluginDir
,
pluginName
string
)
(
m
.
InstalledPlugin
,
error
)
{
func
ReadPlugin
(
pluginDir
,
pluginName
string
)
(
m
odels
.
InstalledPlugin
,
error
)
{
distPluginDataPath
:=
path
.
Join
(
pluginDir
,
pluginName
,
"dist"
,
"plugin.json"
)
var
data
[]
byte
...
...
@@ -75,11 +75,11 @@ func ReadPlugin(pluginDir, pluginName string) (m.InstalledPlugin, error) {
data
,
err
=
IoHelper
.
ReadFile
(
pluginDataPath
)
if
err
!=
nil
{
return
m
.
InstalledPlugin
{},
errors
.
New
(
"Could not find dist/plugin.json or plugin.json on "
+
pluginName
+
" in "
+
pluginDir
)
return
m
odels
.
InstalledPlugin
{},
errors
.
New
(
"Could not find dist/plugin.json or plugin.json on "
+
pluginName
+
" in "
+
pluginDir
)
}
}
res
:=
m
.
InstalledPlugin
{}
res
:=
m
odels
.
InstalledPlugin
{}
if
err
:=
json
.
Unmarshal
(
data
,
&
res
);
err
!=
nil
{
return
res
,
err
}
...
...
@@ -89,14 +89,14 @@ func ReadPlugin(pluginDir, pluginName string) (m.InstalledPlugin, error) {
}
if
res
.
Id
==
""
{
return
m
.
InstalledPlugin
{},
errors
.
New
(
"could not find plugin "
+
pluginName
+
" in "
+
pluginDir
)
return
m
odels
.
InstalledPlugin
{},
errors
.
New
(
"could not find plugin "
+
pluginName
+
" in "
+
pluginDir
)
}
return
res
,
nil
}
func
GetLocalPlugins
(
pluginDir
string
)
[]
m
.
InstalledPlugin
{
result
:=
make
([]
m
.
InstalledPlugin
,
0
)
func
GetLocalPlugins
(
pluginDir
string
)
[]
m
odels
.
InstalledPlugin
{
result
:=
make
([]
m
odels
.
InstalledPlugin
,
0
)
files
,
_
:=
IoHelper
.
ReadDir
(
pluginDir
)
for
_
,
f
:=
range
files
{
res
,
err
:=
ReadPlugin
(
pluginDir
,
f
.
Name
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment