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
3c92f78e
Commit
3c92f78e
authored
Sep 15, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(cli): add grafana version header to all request against grafana.net
parent
3c966caa
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
73 additions
and
138 deletions
+73
-138
pkg/cmd/grafana-cli/main.go
+3
-0
pkg/cmd/grafana-cli/services/services.go
+70
-19
vendor/github.com/franela/goreq/.gitignore
+0
-24
vendor/github.com/franela/goreq/.travis.yml
+0
-8
vendor/github.com/franela/goreq/LICENSE
+0
-20
vendor/github.com/franela/goreq/Makefile
+0
-3
vendor/github.com/franela/goreq/README.md
+0
-0
vendor/github.com/franela/goreq/goreq.go
+0
-0
vendor/github.com/franela/goreq/tags.go
+0
-64
No files found.
pkg/cmd/grafana-cli/main.go
View file @
3c92f78e
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/codegangsta/cli"
"github.com/codegangsta/cli"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
)
)
...
@@ -16,6 +17,8 @@ var version = "master"
...
@@ -16,6 +17,8 @@ var version = "master"
func
main
()
{
func
main
()
{
setupLogging
()
setupLogging
()
services
.
Init
(
version
)
app
:=
cli
.
NewApp
()
app
:=
cli
.
NewApp
()
app
.
Name
=
"Grafana cli"
app
.
Name
=
"Grafana cli"
app
.
Usage
=
""
app
.
Usage
=
""
...
...
pkg/cmd/grafana-cli/services/services.go
View file @
3c92f78e
package
services
package
services
import
(
import
(
"crypto/tls"
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"path"
"path"
"time"
"github.com/franela/goreq"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
m
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
)
)
var
IoHelper
m
.
IoUtil
=
IoUtilImp
{}
var
(
IoHelper
m
.
IoUtil
=
IoUtilImp
{}
HttpClient
http
.
Client
grafanaVersion
string
)
func
Init
(
version
string
)
{
grafanaVersion
=
version
tr
:=
&
http
.
Transport
{
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
false
},
}
HttpClient
=
http
.
Client
{
Timeout
:
time
.
Duration
(
10
*
time
.
Second
),
Transport
:
tr
,
}
}
func
ListAllPlugins
(
repoUrl
string
)
(
m
.
PluginRepo
,
error
)
{
func
ListAllPlugins
(
repoUrl
string
)
(
m
.
PluginRepo
,
error
)
{
fullUrl
:=
repoUrl
+
"/repo"
body
,
err
:=
createRequest
(
repoUrl
,
"repo"
)
res
,
err
:=
goreq
.
Request
{
Uri
:
fullUrl
,
MaxRedirects
:
3
}
.
Do
()
if
err
!=
nil
{
if
err
!=
nil
{
return
m
.
PluginRepo
{},
err
logger
.
Info
(
"Failed to create request"
,
"error"
,
err
)
return
m
.
PluginRepo
{},
fmt
.
Errorf
(
"Failed to create request. error: %v"
,
err
)
}
}
if
res
.
StatusCode
!=
200
{
return
m
.
PluginRepo
{},
fmt
.
Errorf
(
"Could not access %s statuscode %v"
,
fullUrl
,
res
.
StatusCode
)
if
err
!=
nil
{
return
m
.
PluginRepo
{},
err
}
}
var
resp
m
.
PluginRepo
var
data
m
.
PluginRepo
err
=
res
.
Body
.
FromJsonTo
(
&
resp
)
err
=
json
.
Unmarshal
(
body
,
&
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
m
.
PluginRepo
{},
errors
.
New
(
"Could not load plugin data"
)
logger
.
Info
(
"Failed to unmarshal graphite response error: %v"
,
err
)
return
m
.
PluginRepo
{},
err
}
}
return
resp
,
nil
return
data
,
nil
}
}
func
ReadPlugin
(
pluginDir
,
pluginName
string
)
(
m
.
InstalledPlugin
,
error
)
{
func
ReadPlugin
(
pluginDir
,
pluginName
string
)
(
m
.
InstalledPlugin
,
error
)
{
...
@@ -88,21 +112,48 @@ func RemoveInstalledPlugin(pluginPath, pluginName string) error {
...
@@ -88,21 +112,48 @@ func RemoveInstalledPlugin(pluginPath, pluginName string) error {
}
}
func
GetPlugin
(
pluginId
,
repoUrl
string
)
(
m
.
Plugin
,
error
)
{
func
GetPlugin
(
pluginId
,
repoUrl
string
)
(
m
.
Plugin
,
error
)
{
fullUrl
:=
repoUrl
+
"/repo/"
+
pluginId
body
,
err
:=
createRequest
(
repoUrl
,
"repo"
,
pluginId
)
if
err
!=
nil
{
logger
.
Info
(
"Failed to create request"
,
"error"
,
err
)
return
m
.
Plugin
{},
fmt
.
Errorf
(
"Failed to create request. error: %v"
,
err
)
}
res
,
err
:=
goreq
.
Request
{
Uri
:
fullUrl
,
MaxRedirects
:
3
}
.
Do
()
if
err
!=
nil
{
if
err
!=
nil
{
return
m
.
Plugin
{},
err
return
m
.
Plugin
{},
err
}
}
if
res
.
StatusCode
!=
200
{
return
m
.
Plugin
{},
fmt
.
Errorf
(
"Could not access %s statuscode %v"
,
fullUrl
,
res
.
StatusCode
)
var
data
m
.
Plugin
err
=
json
.
Unmarshal
(
body
,
&
data
)
if
err
!=
nil
{
logger
.
Info
(
"Failed to unmarshal graphite response error: %v"
,
err
)
return
m
.
Plugin
{},
err
}
return
data
,
nil
}
func
createRequest
(
repoUrl
string
,
subPaths
...
string
)
([]
byte
,
error
)
{
u
,
_
:=
url
.
Parse
(
repoUrl
)
for
_
,
v
:=
range
subPaths
{
u
.
Path
=
path
.
Join
(
u
.
Path
,
v
)
}
}
var
resp
m
.
Plugin
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
u
.
String
(),
nil
)
err
=
res
.
Body
.
FromJsonTo
(
&
resp
)
logger
.
Info
(
"grafanaVersion "
,
grafanaVersion
)
req
.
Header
.
Set
(
"grafana-version"
,
grafanaVersion
)
req
.
Header
.
Set
(
"User-Agent"
,
"grafana "
+
grafanaVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
m
.
Plugin
{},
errors
.
New
(
"Could not load plugin data"
)
return
[]
byte
{},
err
}
}
return
resp
,
nil
res
,
err
:=
HttpClient
.
Do
(
req
)
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
defer
res
.
Body
.
Close
()
return
body
,
err
}
}
vendor/github.com/franela/goreq/.gitignore
deleted
100644 → 0
View file @
3c966caa
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
src
vendor/github.com/franela/goreq/.travis.yml
deleted
100644 → 0
View file @
3c966caa
language
:
go
go
:
-
1.5.3
-
tip
notifications
:
email
:
-
ionathan@gmail.com
-
marcosnils@gmail.com
vendor/github.com/franela/goreq/LICENSE
deleted
100644 → 0
View file @
3c966caa
The MIT License (MIT)
Copyright (c) 2013 Jonathan Leibiusky and Marcos Lilljedahl
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
vendor/github.com/franela/goreq/Makefile
deleted
100644 → 0
View file @
3c966caa
test
:
go get
-v
-d
-t
./...
go
test
-v
vendor/github.com/franela/goreq/README.md
deleted
100644 → 0
View file @
3c966caa
This diff is collapsed.
Click to expand it.
vendor/github.com/franela/goreq/goreq.go
deleted
100644 → 0
View file @
3c966caa
This diff is collapsed.
Click to expand it.
vendor/github.com/franela/goreq/tags.go
deleted
100644 → 0
View file @
3c966caa
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
goreq
import
(
"strings"
"unicode"
)
// tagOptions is the string following a comma in a struct field's "json"
// tag, or the empty string. It does not include the leading comma.
type
tagOptions
string
// parseTag splits a struct field's json tag into its name and
// comma-separated options.
func
parseTag
(
tag
string
)
(
string
,
tagOptions
)
{
if
idx
:=
strings
.
Index
(
tag
,
","
);
idx
!=
-
1
{
return
tag
[
:
idx
],
tagOptions
(
tag
[
idx
+
1
:
])
}
return
tag
,
tagOptions
(
""
)
}
// Contains reports whether a comma-separated list of options
// contains a particular substr flag. substr must be surrounded by a
// string boundary or commas.
func
(
o
tagOptions
)
Contains
(
optionName
string
)
bool
{
if
len
(
o
)
==
0
{
return
false
}
s
:=
string
(
o
)
for
s
!=
""
{
var
next
string
i
:=
strings
.
Index
(
s
,
","
)
if
i
>=
0
{
s
,
next
=
s
[
:
i
],
s
[
i
+
1
:
]
}
if
s
==
optionName
{
return
true
}
s
=
next
}
return
false
}
func
isValidTag
(
s
string
)
bool
{
if
s
==
""
{
return
false
}
for
_
,
c
:=
range
s
{
switch
{
case
strings
.
ContainsRune
(
"!#$%&()*+-./:<=>?@[]^_{|}~ "
,
c
)
:
// Backslash and quote chars are reserved, but
// otherwise any punctuation chars are allowed
// in a tag name.
default
:
if
!
unicode
.
IsLetter
(
c
)
&&
!
unicode
.
IsDigit
(
c
)
{
return
false
}
}
}
return
true
}
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