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
1188f8df
Commit
1188f8df
authored
Aug 04, 2017
by
Konstantin Chukhlomin
Committed by
bergquist
Sep 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt fixes
parent
72d7c4d6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
45 deletions
+45
-45
pkg/components/imguploader/gcpuploader.go
+36
-36
pkg/components/imguploader/imguploader.go
+8
-8
pkg/components/imguploader/imguploader_test.go
+1
-1
No files found.
pkg/components/imguploader/gcpuploader.go
View file @
1188f8df
package
imguploader
import
(
"github.com/grafana/grafana/pkg/log
"
"github.com/grafana/grafana/pkg/util
"
"google.golang.org/api/option
"
"cloud.google.com/go/storage
"
"golang.org/x/net/context"
"io/ioutil
"
"fmt
"
"cloud.google.com/go/storage
"
"fmt
"
"github.com/grafana/grafana/pkg/log
"
"github.com/grafana/grafana/pkg/util
"
"golang.org/x/net/context"
"google.golang.org/api/option
"
"io/ioutil
"
)
type
GCPUploader
struct
{
keyFile
string
bucket
string
log
log
.
Logger
keyFile
string
bucket
string
log
log
.
Logger
}
func
NewGCPUploader
(
keyFile
,
bucket
string
)
*
GCPUploader
{
return
&
GCPUploader
{
keyFile
:
keyFile
,
bucket
:
bucket
,
log
:
log
.
New
(
"gcpuploader"
),
}
return
&
GCPUploader
{
keyFile
:
keyFile
,
bucket
:
bucket
,
log
:
log
.
New
(
"gcpuploader"
),
}
}
func
(
u
*
GCPUploader
)
Upload
(
imageDiskPath
string
)
(
string
,
error
)
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
client
,
err
:=
storage
.
NewClient
(
ctx
,
option
.
WithServiceAccountFile
(
u
.
keyFile
))
if
err
!=
nil
{
return
""
,
err
}
client
,
err
:=
storage
.
NewClient
(
ctx
,
option
.
WithServiceAccountFile
(
u
.
keyFile
))
if
err
!=
nil
{
return
""
,
err
}
key
:=
util
.
GetRandomString
(
20
)
+
".png"
log
.
Debug
(
"Uploading image to GCP bucket = %s key = %s"
,
u
.
bucket
,
key
)
key
:=
util
.
GetRandomString
(
20
)
+
".png"
log
.
Debug
(
"Uploading image to GCP bucket = %s key = %s"
,
u
.
bucket
,
key
)
file
,
err
:=
ioutil
.
ReadFile
(
imageDiskPath
)
if
err
!=
nil
{
return
""
,
err
}
file
,
err
:=
ioutil
.
ReadFile
(
imageDiskPath
)
if
err
!=
nil
{
return
""
,
err
}
wc
:=
client
.
Bucket
(
u
.
bucket
)
.
Object
(
key
)
.
NewWriter
(
ctx
)
wc
.
ContentType
=
"image/png"
wc
.
ACL
=
[]
storage
.
ACLRule
{{
Entity
:
storage
.
AllUsers
,
Role
:
storage
.
RoleReader
}}
wc
:=
client
.
Bucket
(
u
.
bucket
)
.
Object
(
key
)
.
NewWriter
(
ctx
)
wc
.
ContentType
=
"image/png"
wc
.
ACL
=
[]
storage
.
ACLRule
{{
Entity
:
storage
.
AllUsers
,
Role
:
storage
.
RoleReader
}}
if
_
,
err
:=
wc
.
Write
(
file
);
err
!=
nil
{
return
""
,
err
}
if
_
,
err
:=
wc
.
Write
(
file
);
err
!=
nil
{
return
""
,
err
}
if
err
:=
wc
.
Close
();
err
!=
nil
{
return
""
,
err
}
if
err
:=
wc
.
Close
();
err
!=
nil
{
return
""
,
err
}
return
fmt
.
Sprintf
(
"https://storage.googleapis.com/%s/%s"
,
u
.
bucket
,
key
),
nil
return
fmt
.
Sprintf
(
"https://storage.googleapis.com/%s/%s"
,
u
.
bucket
,
key
),
nil
}
pkg/components/imguploader/imguploader.go
View file @
1188f8df
...
...
@@ -52,16 +52,16 @@ func NewImageUploader() (ImageUploader, error) {
password
:=
webdavSec
.
Key
(
"password"
)
.
String
()
return
NewWebdavImageUploader
(
url
,
username
,
password
,
public_url
)
case
"gcp"
:
gcpsec
,
err
:=
setting
.
Cfg
.
GetSection
(
"external_image_storage.gcp"
)
if
err
!=
nil
{
return
nil
,
err
}
case
"gcp"
:
gcpsec
,
err
:=
setting
.
Cfg
.
GetSection
(
"external_image_storage.gcp"
)
if
err
!=
nil
{
return
nil
,
err
}
keyFile
:=
gcpsec
.
Key
(
"key_file"
)
.
MustString
(
""
)
bucketName
:=
gcpsec
.
Key
(
"bucket"
)
.
MustString
(
""
)
keyFile
:=
gcpsec
.
Key
(
"key_file"
)
.
MustString
(
""
)
bucketName
:=
gcpsec
.
Key
(
"bucket"
)
.
MustString
(
""
)
return
NewGCPUploader
(
keyFile
,
bucketName
),
nil
return
NewGCPUploader
(
keyFile
,
bucketName
),
nil
}
return
NopImageUploader
{},
nil
...
...
pkg/components/imguploader/imguploader_test.go
View file @
1188f8df
...
...
@@ -97,7 +97,7 @@ func TestImageUploaderFactory(t *testing.T) {
So
(
original
.
password
,
ShouldEqual
,
"password"
)
})
Convey
(
"GCP uploader"
,
func
()
{
Convey
(
"GCP uploader"
,
func
()
{
var
err
error
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{
...
...
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