Move DindVolumeSize to playground opts

This commit is contained in:
Marcos Lilljedahl
2019-04-23 01:47:06 -03:00
parent 1bee95e862
commit 4b1dc52c59
11 changed files with 65 additions and 41 deletions

View File

@@ -240,10 +240,8 @@ func initOauthProviders(p *types.Playground) {
config.Providers[p.Id]["facebook"] = conf
}
if p.DockerClientID != "" && p.DockerClientSecret != "" {
endpoint := "id.docker.com"
if len(p.DockerHost) > 0 {
endpoint = p.DockerHost
}
endpoint := getDockerEndpoint(p)
oauth2.RegisterBrokenAuthHeaderProvider(fmt.Sprintf(".%s", endpoint))
conf := &oauth2.Config{
ClientID: p.DockerClientID,

View File

@@ -12,11 +12,12 @@ type CookieID struct {
UserAvatar string `json:"user_avatar"`
}
func (c *CookieID) SetCookie(rw http.ResponseWriter) error {
func (c *CookieID) SetCookie(rw http.ResponseWriter, host string) error {
if encoded, err := config.SecureCookie.Encode("id", c); err == nil {
cookie := &http.Cookie{
Name: "id",
Value: encoded,
Domain: host,
Path: "/",
Secure: config.UseLetsEncrypt,
HttpOnly: true,

View File

@@ -166,7 +166,9 @@ func LoginCallback(rw http.ResponseWriter, req *http.Request) {
&oauth2.Token{AccessToken: tok.AccessToken},
)
tc := oauth2.NewClient(ctx, ts)
resp, err := tc.Get("https://id.docker.com/api/id/v1/openid/userinfo")
endpoint := getDockerEndpoint(playground)
resp, err := tc.Get(fmt.Sprintf("https://%s/api/id/v1/openid/userinfo", endpoint))
if err != nil {
log.Printf("Could not get user from docker. Got: %v\n", err)
rw.WriteHeader(http.StatusInternalServerError)
@@ -197,26 +199,42 @@ func LoginCallback(rw http.ResponseWriter, req *http.Request) {
cookieData := CookieID{Id: user.Id, UserName: user.Name, UserAvatar: user.Avatar}
if err := cookieData.SetCookie(rw); err != nil {
host := "localhost"
if req.Host != "" {
host = req.Host
}
if err := cookieData.SetCookie(rw, host); err != nil {
log.Printf("Could not encode cookie. Got: %v\n", err)
rw.WriteHeader(http.StatusInternalServerError)
return
}
r, _ := playground.Extras.GetString("LoginRedirect")
fmt.Fprintf(rw, `
<html>
<head>
<script>
if (window.opener && !window.opener.closed) {
try {
window.opener.postMessage('done','*')
window.opener.postMessage('done','*');
}
catch(e) { }
window.close();
} else {
window.location = '%s';
}
</script>
</head>
<body>
</body>
</html>`)
</html>`, r)
}
func getDockerEndpoint(p *types.Playground) string {
if len(p.DockerHost) > 0 {
return p.DockerHost
}
return "id.docker.com"
}

View File

@@ -15,7 +15,7 @@ func NewInstance(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
sessionId := vars["sessionId"]
body := types.InstanceConfig{PlaygroundFQDN: req.Host}
body := types.InstanceConfig{PlaygroundFQDN: req.Host, DindVolumeSize: "5G"}
json.NewDecoder(req.Body).Decode(&body)
@@ -51,6 +51,10 @@ func NewInstance(rw http.ResponseWriter, req *http.Request) {
return
}
if len(playground.DindVolumeSize) > 0 {
body.DindVolumeSize = playground.DindVolumeSize
}
i, err := core.InstanceNew(s, body)
if err != nil {
if provisioner.OutOfCapacity(err) {

View File

@@ -59,6 +59,7 @@ type PlaygroundConfigurationResponse struct {
AvailableDinDInstanceImages []string `json:"available_dind_instance_images"`
AllowWindowsInstances bool `json:"allow_windows_instances"`
DefaultSessionDuration time.Duration `json:"default_session_duration"`
DindVolumeSize string `json:"dind_volume_size"`
}
func GetCurrentPlayground(rw http.ResponseWriter, req *http.Request) {
@@ -69,12 +70,13 @@ func GetCurrentPlayground(rw http.ResponseWriter, req *http.Request) {
return
}
json.NewEncoder(rw).Encode(PlaygroundConfigurationResponse{
Id: playground.Id,
Domain: playground.Domain,
Id: playground.Id,
Domain: playground.Domain,
DefaultDinDInstanceImage: playground.DefaultDinDInstanceImage,
AvailableDinDInstanceImages: playground.AvailableDinDInstanceImages,
AllowWindowsInstances: playground.AllowWindowsInstances,
DefaultSessionDuration: playground.DefaultSessionDuration,
DindVolumeSize: playground.DindVolumeSize,
})
}