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"
|
2020-07-27 07:11:32 +00:00
|
|
|
portainer "github.com/portainer/portainer/api"
|
2018-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type publicSettingsResponse struct {
|
2021-02-23 03:21:39 +00:00
|
|
|
// URL to a logo that will be displayed on the login page as well as on top of the sidebar. Will use default Portainer logo when value is empty string
|
|
|
|
LogoURL string `json:"LogoURL" example:"https://mycompany.mydomain.tld/logo.png"`
|
|
|
|
// Active authentication method for the Portainer instance. Valid values are: 1 for internal, 2 for LDAP, or 3 for oauth
|
|
|
|
AuthenticationMethod portainer.AuthenticationMethod `json:"AuthenticationMethod" example:"1"`
|
|
|
|
// Whether edge compute features are enabled
|
|
|
|
EnableEdgeComputeFeatures bool `json:"EnableEdgeComputeFeatures" example:"true"`
|
|
|
|
// The URL used for oauth login
|
|
|
|
OAuthLoginURI string `json:"OAuthLoginURI" example:"https://gitlab.com/oauth"`
|
2021-06-10 22:09:04 +00:00
|
|
|
// The URL used for oauth logout
|
|
|
|
OAuthLogoutURI string `json:"OAuthLogoutURI" example:"https://gitlab.com/oauth/logout"`
|
2021-02-23 03:21:39 +00:00
|
|
|
// Whether telemetry is enabled
|
|
|
|
EnableTelemetry bool `json:"EnableTelemetry" example:"true"`
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 03:21:39 +00:00
|
|
|
// @id SettingsPublic
|
|
|
|
// @summary Retrieve Portainer public settings
|
|
|
|
// @description Retrieve public settings. Returns a small set of settings that are not reserved to administrators only.
|
|
|
|
// @description **Access policy**: public
|
|
|
|
// @tags settings
|
|
|
|
// @produce json
|
|
|
|
// @success 200 {object} publicSettingsResponse "Success"
|
|
|
|
// @failure 500 "Server error"
|
|
|
|
// @router /settings/public [get]
|
2018-06-11 13:13:19 +00:00
|
|
|
func (handler *Handler) settingsPublic(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
2020-05-20 05:23:15 +00:00
|
|
|
settings, err := handler.DataStore.Settings().Settings()
|
2018-06-11 13:13:19 +00:00
|
|
|
if err != nil {
|
2021-06-10 22:09:04 +00:00
|
|
|
return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to retrieve the settings from the database", Err: err}
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 22:09:04 +00:00
|
|
|
publicSettings := generatePublicSettings(settings)
|
|
|
|
return response.JSON(w, publicSettings)
|
|
|
|
}
|
|
|
|
|
|
|
|
func generatePublicSettings(appSettings *portainer.Settings) *publicSettingsResponse {
|
2018-06-11 13:13:19 +00:00
|
|
|
publicSettings := &publicSettingsResponse{
|
2021-06-10 22:09:04 +00:00
|
|
|
LogoURL: appSettings.LogoURL,
|
|
|
|
AuthenticationMethod: appSettings.AuthenticationMethod,
|
|
|
|
EnableEdgeComputeFeatures: appSettings.EnableEdgeComputeFeatures,
|
|
|
|
EnableTelemetry: appSettings.EnableTelemetry,
|
2018-08-07 15:43:36 +00:00
|
|
|
}
|
2021-06-10 22:09:04 +00:00
|
|
|
//if OAuth authentication is on, compose the related fields from application settings
|
|
|
|
if publicSettings.AuthenticationMethod == portainer.AuthenticationOAuth {
|
|
|
|
publicSettings.OAuthLogoutURI = appSettings.OAuthSettings.LogoutURI
|
|
|
|
publicSettings.OAuthLoginURI = fmt.Sprintf("%s?response_type=code&client_id=%s&redirect_uri=%s&scope=%s",
|
|
|
|
appSettings.OAuthSettings.AuthorizationURI,
|
|
|
|
appSettings.OAuthSettings.ClientID,
|
|
|
|
appSettings.OAuthSettings.RedirectURI,
|
|
|
|
appSettings.OAuthSettings.Scopes)
|
|
|
|
//control prompt=login param according to the SSO setting
|
|
|
|
if !appSettings.OAuthSettings.SSO {
|
|
|
|
publicSettings.OAuthLoginURI += "&prompt=login"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return publicSettings
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|