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:
Jonathan Leibiusky
2017-11-14 15:50:04 -03:00
committed by GitHub
parent 3dee0d3f0b
commit 3f5b3882dd
24 changed files with 784 additions and 159 deletions

36
pwd/playground.go Normal file
View File

@@ -0,0 +1,36 @@
package pwd
import (
"log"
"github.com/play-with-docker/play-with-docker/pwd/types"
"github.com/twinj/uuid"
)
func (p *pwd) PlaygroundNew(playground types.Playground) (*types.Playground, error) {
playground.Id = uuid.NewV5(uuid.NameSpaceURL, uuid.Name(playground.Domain)).String()
if err := p.storage.PlaygroundPut(&playground); err != nil {
log.Printf("Error saving playground %s. Got: %v\n", playground.Id, err)
return nil, err
}
return &playground, nil
}
func (p *pwd) PlaygroundGet(id string) *types.Playground {
if playground, err := p.storage.PlaygroundGet(id); err != nil {
log.Printf("Error retrieving playground %s. Got: %v\n", id, err)
return nil
} else {
return playground
}
}
func (p *pwd) PlaygroundFindByDomain(domain string) *types.Playground {
id := uuid.NewV5(uuid.NameSpaceURL, uuid.Name(domain)).String()
return p.PlaygroundGet(id)
}
func (p *pwd) PlaygroundList() ([]*types.Playground, error) {
return p.storage.PlaygroundGetAll()
}