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
d1e9b6d6
Commit
d1e9b6d6
authored
May 01, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Began work on auth_proxy feature (#1932), and began work on testing http api, and auth middleware
parent
e7ac3673
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
5 deletions
+91
-5
conf/defaults.ini
+7
-0
pkg/cmd/web.go
+1
-1
pkg/middleware/middleware_test.go
+40
-0
pkg/middleware/session.go
+30
-4
pkg/setting/setting.go
+13
-0
No files found.
conf/defaults.ini
View file @
d1e9b6d6
...
...
@@ -162,6 +162,13 @@ token_url = https://accounts.google.com/o/oauth2/token
api_url
=
https://www.googleapis.com/oauth2/v1/userinfo
allowed_domains
=
#################################### Auth Proxy ##########################
[auth.proxy]
enabled
=
false;
header_name
=
X-WEBAUTH-USER
header_property
=
username
auto_sign_up
=
true
#################################### Logging ##########################
[log]
# Either "console", "file", default is "console"
...
...
pkg/cmd/web.go
View file @
d1e9b6d6
...
...
@@ -41,7 +41,7 @@ func newMacaron() *macaron.Macaron {
}))
m
.
Use
(
middleware
.
GetContextHandler
())
m
.
Use
(
middleware
.
Sessioner
(
setting
.
SessionOptions
))
m
.
Use
(
middleware
.
Sessioner
(
&
setting
.
SessionOptions
))
return
m
}
...
...
pkg/middleware/middleware_test.go
0 → 100644
View file @
d1e9b6d6
package
middleware
import
(
"net/http"
"net/http/httptest"
"testing"
"github.com/Unknwon/macaron"
"github.com/macaron-contrib/session"
.
"github.com/smartystreets/goconvey/convey"
)
func
TestMiddlewareContext
(
t
*
testing
.
T
)
{
Convey
(
"Given grafana context"
,
t
,
func
()
{
m
:=
macaron
.
New
()
m
.
Use
(
GetContextHandler
())
m
.
Use
(
Sessioner
(
&
session
.
Options
{}))
var
context
*
Context
m
.
Get
(
"/"
,
func
(
c
*
Context
)
{
context
=
c
})
resp
:=
httptest
.
NewRecorder
()
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"/"
,
nil
)
So
(
err
,
ShouldBeNil
)
m
.
ServeHTTP
(
resp
,
req
)
Convey
(
"Should be able to get grafana context in handlers"
,
func
()
{
So
(
context
,
ShouldNotBeNil
)
})
Convey
(
"should return 200"
,
func
()
{
So
(
resp
.
Code
,
ShouldEqual
,
200
)
})
})
}
pkg/middleware/session.go
View file @
d1e9b6d6
...
...
@@ -16,17 +16,43 @@ const (
)
var
sessionManager
*
session
.
Manager
var
sessionOptions
session
.
Options
var
sessionOptions
*
session
.
Options
func
startSessionGC
()
{
sessionManager
.
GC
()
time
.
AfterFunc
(
time
.
Duration
(
sessionOptions
.
Gclifetime
)
*
time
.
Second
,
startSessionGC
)
}
func
Sessioner
(
options
session
.
Options
)
macaron
.
Handler
{
func
prepareOptions
(
opt
*
session
.
Options
)
*
session
.
Options
{
if
len
(
opt
.
Provider
)
==
0
{
opt
.
Provider
=
"memory"
}
if
len
(
opt
.
ProviderConfig
)
==
0
{
opt
.
ProviderConfig
=
"data/sessions"
}
if
len
(
opt
.
CookieName
)
==
0
{
opt
.
CookieName
=
"grafana_sess"
}
if
len
(
opt
.
CookiePath
)
==
0
{
opt
.
CookiePath
=
"/"
}
if
opt
.
Gclifetime
==
0
{
opt
.
Gclifetime
=
3600
}
if
opt
.
Maxlifetime
==
0
{
opt
.
Maxlifetime
=
opt
.
Gclifetime
}
if
opt
.
IDLength
==
0
{
opt
.
IDLength
=
16
}
return
opt
}
func
Sessioner
(
options
*
session
.
Options
)
macaron
.
Handler
{
var
err
error
sessionOptions
=
options
sessionManager
,
err
=
session
.
NewManager
(
options
.
Provider
,
options
)
sessionOptions
=
prepareOptions
(
options
)
sessionManager
,
err
=
session
.
NewManager
(
options
.
Provider
,
*
options
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
pkg/setting/setting.go
View file @
d1e9b6d6
...
...
@@ -87,6 +87,12 @@ var (
AnonymousOrgName
string
AnonymousOrgRole
string
// Auth proxy settings
AuthProxyEnabled
bool
AuthProxyHeaderName
string
AuthProxyHeaderProperty
string
AuthProxyAutoSignUp
bool
// Session settings.
SessionOptions
session
.
Options
...
...
@@ -376,6 +382,13 @@ func NewConfigContext(args *CommandLineArgs) {
AnonymousOrgName
=
Cfg
.
Section
(
"auth.anonymous"
)
.
Key
(
"org_name"
)
.
String
()
AnonymousOrgRole
=
Cfg
.
Section
(
"auth.anonymous"
)
.
Key
(
"org_role"
)
.
String
()
// auth proxy
authProxy
:=
Cfg
.
Section
(
"auth.proxy"
)
AuthProxyEnabled
=
authProxy
.
Key
(
"enabled"
)
.
MustBool
(
false
)
AuthProxyHeaderName
=
authProxy
.
Key
(
"header_name"
)
.
String
()
AuthProxyHeaderProperty
=
authProxy
.
Key
(
"header_property"
)
.
String
()
AuthProxyAutoSignUp
=
authProxy
.
Key
(
"auto_sign_up"
)
.
MustBool
(
true
)
// PhantomJS rendering
ImagesDir
=
filepath
.
Join
(
DataPath
,
"png"
)
PhantomDir
=
filepath
.
Join
(
HomePath
,
"vendor/phantomjs"
)
...
...
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