Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
03805054
Commit
03805054
authored
Dec 22, 2011
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add /key handler
R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/5504066
parent
ddc85f41
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
7 deletions
+30
-7
misc/dashboard/app/app.yaml
misc/dashboard/app/app.yaml
+1
-1
misc/dashboard/app/build/handler.go
misc/dashboard/app/build/handler.go
+29
-6
No files found.
misc/dashboard/app/app.yaml
View file @
03805054
...
...
@@ -10,6 +10,6 @@ handlers:
script
:
_go_app
-
url
:
/(|commit|packages|result|tag|todo)
script
:
_go_app
-
url
:
/(init|buildtest|_ah/queue/go/delay)
-
url
:
/(init|buildtest|
key|
_ah/queue/go/delay)
script
:
_go_app
login
:
admin
misc/dashboard/app/build/handler.go
View file @
03805054
...
...
@@ -321,12 +321,9 @@ func AuthHandler(h dashHandler) http.HandlerFunc {
// Validate key query parameter for POST requests only.
key
:=
r
.
FormValue
(
"key"
)
if
r
.
Method
==
"POST"
&&
key
!=
secretKey
&&
!
appengine
.
IsDevAppServer
()
{
h
:=
hmac
.
NewMD5
([]
byte
(
secretKey
))
h
.
Write
([]
byte
(
r
.
FormValue
(
"builder"
)))
if
key
!=
fmt
.
Sprintf
(
"%x"
,
h
.
Sum
())
{
err
=
os
.
NewError
(
"invalid key: "
+
key
)
}
builder
:=
r
.
FormValue
(
"builder"
)
if
r
.
Method
==
"POST"
&&
!
validKey
(
key
,
builder
)
{
err
=
os
.
NewError
(
"invalid key: "
+
key
)
}
// Call the original HandlerFunc and return the response.
...
...
@@ -365,9 +362,19 @@ func initHandler(w http.ResponseWriter, r *http.Request) {
fmt
.
Fprint
(
w
,
"OK"
)
}
func
keyHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
builder
:=
r
.
FormValue
(
"builder"
)
if
builder
==
""
{
logErr
(
w
,
r
,
os
.
NewError
(
"must supply builder in query string"
))
return
}
fmt
.
Fprint
(
w
,
builderKey
(
builder
))
}
func
init
()
{
// admin handlers
http
.
HandleFunc
(
"/init"
,
initHandler
)
http
.
HandleFunc
(
"/key"
,
keyHandler
)
// authenticated handlers
http
.
HandleFunc
(
"/commit"
,
AuthHandler
(
commitHandler
))
...
...
@@ -385,6 +392,22 @@ func validHash(hash string) bool {
return
hash
!=
""
}
func
validKey
(
key
,
builder
string
)
bool
{
if
appengine
.
IsDevAppServer
()
{
return
true
}
if
key
==
secretKey
{
return
true
}
return
key
==
builderKey
(
builder
)
}
func
builderKey
(
builder
string
)
string
{
h
:=
hmac
.
NewMD5
([]
byte
(
secretKey
))
h
.
Write
([]
byte
(
builder
))
return
fmt
.
Sprintf
(
"%x"
,
h
.
Sum
())
}
func
logErr
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
err
os
.
Error
)
{
appengine
.
NewContext
(
r
)
.
Errorf
(
"Error: %v"
,
err
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
...
...
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