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"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api"
|
2018-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type publicSettingsResponse struct {
|
|
|
|
LogoURL string `json:"LogoURL"`
|
|
|
|
AuthenticationMethod portainer.AuthenticationMethod `json:"AuthenticationMethod"`
|
|
|
|
AllowBindMountsForRegularUsers bool `json:"AllowBindMountsForRegularUsers"`
|
|
|
|
AllowPrivilegedModeForRegularUsers bool `json:"AllowPrivilegedModeForRegularUsers"`
|
2019-10-08 00:17:58 +00:00
|
|
|
AllowVolumeBrowserForRegularUsers bool `json:"AllowVolumeBrowserForRegularUsers"`
|
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,
|
2019-10-08 00:17:58 +00:00
|
|
|
AllowVolumeBrowserForRegularUsers: settings.AllowVolumeBrowserForRegularUsers,
|
2018-12-05 22:36:25 +00:00
|
|
|
EnableHostManagementFeatures: settings.EnableHostManagementFeatures,
|
2018-08-07 15:43:36 +00:00
|
|
|
ExternalTemplates: false,
|
2019-02-21 01:02:25 +00:00
|
|
|
OAuthLoginURI: fmt.Sprintf("%s?response_type=code&client_id=%s&redirect_uri=%s&scope=%s&prompt=login",
|
2019-01-16 15:25:16 +00:00
|
|
|
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)
|
|
|
|
}
|