2018-06-11 13:13:19 +00:00
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
2019-01-16 15:25:16 +00:00
|
|
|
"fmt"
|
2018-06-11 13:13:19 +00:00
|
|
|
"net/http"
|
|
|
|
|
2018-09-10 10:01:38 +00:00
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/libhttp/response"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type publicSettingsResponse struct {
|
|
|
|
LogoURL string `json:"LogoURL"`
|
|
|
|
AuthenticationMethod portainer.AuthenticationMethod `json:"AuthenticationMethod"`
|
|
|
|
AllowBindMountsForRegularUsers bool `json:"AllowBindMountsForRegularUsers"`
|
|
|
|
AllowPrivilegedModeForRegularUsers bool `json:"AllowPrivilegedModeForRegularUsers"`
|
2018-12-05 22:36:25 +00:00
|
|
|
EnableHostManagementFeatures bool `json:"EnableHostManagementFeatures"`
|
2018-08-07 15:43:36 +00:00
|
|
|
ExternalTemplates bool `json:"ExternalTemplates"`
|
2019-01-16 15:25:16 +00:00
|
|
|
OAuthLoginURI string `json:"OAuthLoginURI"`
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GET request on /api/settings/public
|
|
|
|
func (handler *Handler) settingsPublic(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
|
|
settings, err := handler.SettingsService.Settings()
|
|
|
|
if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve the settings from the database", err}
|
|
|
|
}
|
|
|
|
|
|
|
|
publicSettings := &publicSettingsResponse{
|
|
|
|
LogoURL: settings.LogoURL,
|
|
|
|
AuthenticationMethod: settings.AuthenticationMethod,
|
|
|
|
AllowBindMountsForRegularUsers: settings.AllowBindMountsForRegularUsers,
|
|
|
|
AllowPrivilegedModeForRegularUsers: settings.AllowPrivilegedModeForRegularUsers,
|
2018-12-05 22:36:25 +00:00
|
|
|
EnableHostManagementFeatures: settings.EnableHostManagementFeatures,
|
2018-08-07 15:43:36 +00:00
|
|
|
ExternalTemplates: false,
|
2019-02-18 01:46:34 +00:00
|
|
|
// TODO: check if state=portainer useful or not
|
2019-01-16 15:25:16 +00:00
|
|
|
OAuthLoginURI: fmt.Sprintf("%s?response_type=code&client_id=%s&redirect_uri=%s&scope=%s&state=portainer",
|
|
|
|
settings.OAuthSettings.AuthorizationURI,
|
|
|
|
settings.OAuthSettings.ClientID,
|
|
|
|
settings.OAuthSettings.RedirectURI,
|
|
|
|
settings.OAuthSettings.Scopes),
|
2018-08-07 15:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if settings.TemplatesURL != "" {
|
|
|
|
publicSettings.ExternalTemplates = true
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return response.JSON(w, publicSettings)
|
|
|
|
}
|