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
600bbf7e
Unverified
Commit
600bbf7e
authored
Feb 18, 2019
by
Daniel Lee
Committed by
GitHub
Feb 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15502 from grafana/15500-cli
cli: chmod 755 for backend plugin binaries
parents
2afd3cf5
56c965e5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
4 deletions
+57
-4
pkg/cmd/grafana-cli/commands/install_command.go
+16
-4
pkg/cmd/grafana-cli/commands/install_command_test.go
+41
-0
pkg/cmd/grafana-cli/commands/testdata/grafana-simple-json-datasource-ec18fa4da8096a952608a7e4c7782b4260b41bcf.zip
+0
-0
No files found.
pkg/cmd/grafana-cli/commands/install_command.go
View file @
600bbf7e
...
...
@@ -57,6 +57,8 @@ func installCommand(c CommandLine) error {
return
InstallPlugin
(
pluginToInstall
,
version
,
c
)
}
// InstallPlugin downloads the plugin code as a zip file from the Grafana.com API
// and then extracts the zip into the plugins directory.
func
InstallPlugin
(
pluginName
,
version
string
,
c
CommandLine
)
error
{
pluginFolder
:=
c
.
PluginDirectory
()
downloadURL
:=
c
.
PluginURL
()
...
...
@@ -152,6 +154,10 @@ func downloadFile(pluginName, filePath, url string) (err error) {
return
err
}
return
extractFiles
(
body
,
pluginName
,
filePath
)
}
func
extractFiles
(
body
[]
byte
,
pluginName
string
,
filePath
string
)
error
{
r
,
err
:=
zip
.
NewReader
(
bytes
.
NewReader
(
body
),
int64
(
len
(
body
)))
if
err
!=
nil
{
return
err
...
...
@@ -161,12 +167,18 @@ func downloadFile(pluginName, filePath, url string) (err error) {
if
zf
.
FileInfo
()
.
IsDir
()
{
err
:=
os
.
Mkdir
(
newFile
,
0777
)
if
P
ermissionsError
(
err
)
{
if
p
ermissionsError
(
err
)
{
return
fmt
.
Errorf
(
permissionsDeniedMessage
,
newFile
)
}
}
else
{
dst
,
err
:=
os
.
Create
(
newFile
)
if
PermissionsError
(
err
)
{
fileMode
:=
zf
.
Mode
()
if
strings
.
HasSuffix
(
newFile
,
"_linux_amd64"
)
||
strings
.
HasSuffix
(
newFile
,
"_darwin_amd64"
)
{
fileMode
=
os
.
FileMode
(
0755
)
}
dst
,
err
:=
os
.
OpenFile
(
newFile
,
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_TRUNC
,
fileMode
)
if
permissionsError
(
err
)
{
return
fmt
.
Errorf
(
permissionsDeniedMessage
,
newFile
)
}
...
...
@@ -184,6 +196,6 @@ func downloadFile(pluginName, filePath, url string) (err error) {
return
nil
}
func
P
ermissionsError
(
err
error
)
bool
{
func
p
ermissionsError
(
err
error
)
bool
{
return
err
!=
nil
&&
strings
.
Contains
(
err
.
Error
(),
"permission denied"
)
}
pkg/cmd/grafana-cli/commands/install_command_test.go
View file @
600bbf7e
package
commands
import
(
"io/ioutil"
"os"
"testing"
.
"github.com/smartystreets/goconvey/convey"
...
...
@@ -37,3 +39,42 @@ func TestFoldernameReplacement(t *testing.T) {
})
})
}
func
TestExtractFiles
(
t
*
testing
.
T
)
{
Convey
(
"Should preserve file permissions for plugin backend binaries for linux and darwin"
,
t
,
func
()
{
err
:=
os
.
RemoveAll
(
"testdata/fake-plugins-dir"
)
So
(
err
,
ShouldBeNil
)
err
=
os
.
MkdirAll
(
"testdata/fake-plugins-dir"
,
0774
)
So
(
err
,
ShouldBeNil
)
body
,
err
:=
ioutil
.
ReadFile
(
"testdata/grafana-simple-json-datasource-ec18fa4da8096a952608a7e4c7782b4260b41bcf.zip"
)
So
(
err
,
ShouldBeNil
)
err
=
extractFiles
(
body
,
"grafana-simple-json-datasource"
,
"testdata/fake-plugins-dir"
)
So
(
err
,
ShouldBeNil
)
//File in zip has permissions 777
fileInfo
,
err
:=
os
.
Stat
(
"testdata/fake-plugins-dir/grafana-simple-json-datasource/simple-plugin_darwin_amd64"
)
So
(
err
,
ShouldBeNil
)
So
(
fileInfo
.
Mode
()
.
String
(),
ShouldEqual
,
"-rwxr-xr-x"
)
//File in zip has permission 664
fileInfo
,
err
=
os
.
Stat
(
"testdata/fake-plugins-dir/grafana-simple-json-datasource/simple-plugin_linux_amd64"
)
So
(
err
,
ShouldBeNil
)
So
(
fileInfo
.
Mode
()
.
String
(),
ShouldEqual
,
"-rwxr-xr-x"
)
//File in zip has permission 644
fileInfo
,
err
=
os
.
Stat
(
"testdata/fake-plugins-dir/grafana-simple-json-datasource/simple-plugin_windows_amd64.exe"
)
So
(
err
,
ShouldBeNil
)
So
(
fileInfo
.
Mode
()
.
String
(),
ShouldEqual
,
"-rw-r--r--"
)
//File in zip has permission 755
fileInfo
,
err
=
os
.
Stat
(
"testdata/fake-plugins-dir/grafana-simple-json-datasource/non-plugin-binary"
)
So
(
err
,
ShouldBeNil
)
So
(
fileInfo
.
Mode
()
.
String
(),
ShouldEqual
,
"-rwxr-xr-x"
)
err
=
os
.
RemoveAll
(
"testdata/fake-plugins-dir"
)
So
(
err
,
ShouldBeNil
)
})
}
pkg/cmd/grafana-cli/commands/testdata/grafana-simple-json-datasource-ec18fa4da8096a952608a7e4c7782b4260b41bcf.zip
0 → 100644
View file @
600bbf7e
File added
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