Multiple playgrounds support (#215)
* Add Playground struct and basic support for creating it and retrieving it * Add missing functions in pwd mock * Get playground from request domain and validate it exists. If valid set it on the newly created session. * Move playground specific configurations to the playground struct and use it everytime we need that conf. * Don't allow to specify a duration bigger that the allowed in the playground
This commit is contained in:
committed by
GitHub
parent
3dee0d3f0b
commit
3f5b3882dd
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/play-with-docker/play-with-docker/config"
|
||||
"github.com/play-with-docker/play-with-docker/provisioner"
|
||||
@@ -49,8 +50,32 @@ func NewSession(rw http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
}
|
||||
duration := config.GetDuration(reqDur)
|
||||
s, err := core.SessionNew(userId, duration, stack, stackName, imageName)
|
||||
|
||||
playground := core.PlaygroundFindByDomain(req.Host)
|
||||
if playground == nil {
|
||||
log.Printf("Playground for domain %s was not found!", req.Host)
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var duration time.Duration
|
||||
if reqDur != "" {
|
||||
d, err := time.ParseDuration(reqDur)
|
||||
if err != nil {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if d > playground.DefaultSessionDuration {
|
||||
log.Printf("Specified session duration was %s but maximum allowed by this playground is %d\n", d.String(), playground.DefaultSessionDuration.String())
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
duration = d
|
||||
} else {
|
||||
duration = playground.DefaultSessionDuration
|
||||
}
|
||||
|
||||
s, err := core.SessionNew(playground, userId, duration, stack, stackName, imageName)
|
||||
if err != nil {
|
||||
if provisioner.OutOfCapacity(err) {
|
||||
http.Redirect(rw, req, "/ooc", http.StatusFound)
|
||||
@@ -62,9 +87,6 @@ func NewSession(rw http.ResponseWriter, req *http.Request) {
|
||||
//TODO: Return some error code
|
||||
} else {
|
||||
hostname := req.Host
|
||||
if config.PWDCName != "" {
|
||||
hostname = fmt.Sprintf("%s.%s", config.PWDCName, req.Host)
|
||||
}
|
||||
// If request is not a form, return sessionId in the body
|
||||
if req.Header.Get("X-Requested-With") == "XMLHttpRequest" {
|
||||
resp := NewSessionResponse{SessionId: s.Id, Hostname: hostname}
|
||||
|
||||
Reference in New Issue
Block a user