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"
|
|
|
|
|
2020-07-27 07:11:32 +00:00
|
|
|
portainer "github.com/portainer/portainer/api"
|
2023-02-09 04:17:46 +00:00
|
|
|
"github.com/portainer/portainer/pkg/featureflags"
|
2023-09-01 22:27:02 +00:00
|
|
|
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
|
|
|
"github.com/portainer/portainer/pkg/libhttp/response"
|
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"`
|
2022-06-03 04:00:13 +00:00
|
|
|
// The minimum required length for a password of any user when using internal auth mode
|
|
|
|
RequiredPasswordLength int `json:"RequiredPasswordLength" example:"1"`
|
2023-10-16 01:08:06 +00:00
|
|
|
// Deployment options for encouraging deployment as code
|
|
|
|
GlobalDeploymentOptions portainer.GlobalDeploymentOptions `json:"GlobalDeploymentOptions"`
|
2022-12-01 00:46:23 +00:00
|
|
|
// Show the Kompose build option (discontinued in 2.18)
|
|
|
|
ShowKomposeBuildOption bool `json:"ShowKomposeBuildOption" example:"false"`
|
2021-02-23 03:21:39 +00:00
|
|
|
// Whether edge compute features are enabled
|
|
|
|
EnableEdgeComputeFeatures bool `json:"EnableEdgeComputeFeatures" example:"true"`
|
2021-11-11 18:49:50 +00:00
|
|
|
// Supported feature flags
|
2023-02-09 04:17:46 +00:00
|
|
|
Features map[featureflags.Feature]bool `json:"Features"`
|
2021-02-23 03:21:39 +00:00
|
|
|
// 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"`
|
2021-09-10 10:42:25 +00:00
|
|
|
// The expiry of a Kubeconfig
|
|
|
|
KubeconfigExpiry string `example:"24h" default:"0"`
|
2022-06-03 04:44:42 +00:00
|
|
|
// Whether team sync is enabled
|
|
|
|
TeamSync bool `json:"TeamSync" example:"true"`
|
2022-06-27 16:29:17 +00:00
|
|
|
|
2022-12-20 21:07:34 +00:00
|
|
|
// Whether FDO is enabled
|
|
|
|
IsFDOEnabled bool
|
|
|
|
// Whether AMT is enabled
|
|
|
|
IsAMTEnabled bool
|
|
|
|
|
2022-06-27 16:29:17 +00:00
|
|
|
Edge struct {
|
|
|
|
// The ping interval for edge agent - used in edge async mode [seconds]
|
|
|
|
PingInterval int `json:"PingInterval" example:"60"`
|
|
|
|
// The snapshot interval for edge agent - used in edge async mode [seconds]
|
|
|
|
SnapshotInterval int `json:"SnapshotInterval" example:"60"`
|
|
|
|
// The command list interval for edge agent - used in edge async mode [seconds]
|
|
|
|
CommandInterval int `json:"CommandInterval" example:"60"`
|
|
|
|
// The check in interval for edge agent (in seconds) - used in non async mode [seconds]
|
|
|
|
CheckinInterval int `example:"60"`
|
|
|
|
}
|
2023-05-17 02:31:46 +00:00
|
|
|
|
2023-05-17 22:21:07 +00:00
|
|
|
IsDockerDesktopExtension bool `json:"IsDockerDesktopExtension" example:"false"`
|
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 {
|
2022-09-14 23:42:39 +00:00
|
|
|
return httperror.InternalServerError("Unable to retrieve the settings from the database", 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,
|
2022-06-03 04:00:13 +00:00
|
|
|
RequiredPasswordLength: appSettings.InternalAuthSettings.RequiredPasswordLength,
|
2021-06-10 22:09:04 +00:00
|
|
|
EnableEdgeComputeFeatures: appSettings.EnableEdgeComputeFeatures,
|
2023-10-16 01:08:06 +00:00
|
|
|
GlobalDeploymentOptions: appSettings.GlobalDeploymentOptions,
|
2022-12-01 00:46:23 +00:00
|
|
|
ShowKomposeBuildOption: appSettings.ShowKomposeBuildOption,
|
2021-06-10 22:09:04 +00:00
|
|
|
EnableTelemetry: appSettings.EnableTelemetry,
|
2021-09-10 10:42:25 +00:00
|
|
|
KubeconfigExpiry: appSettings.KubeconfigExpiry,
|
2023-02-09 04:17:46 +00:00
|
|
|
Features: featureflags.FeatureFlags(),
|
2022-12-20 21:07:34 +00:00
|
|
|
IsFDOEnabled: appSettings.EnableEdgeComputeFeatures && appSettings.FDOConfiguration.Enabled,
|
|
|
|
IsAMTEnabled: appSettings.EnableEdgeComputeFeatures && appSettings.OpenAMTConfiguration.Enabled,
|
2018-08-07 15:43:36 +00:00
|
|
|
}
|
2022-06-27 16:29:17 +00:00
|
|
|
|
|
|
|
publicSettings.Edge.PingInterval = appSettings.Edge.PingInterval
|
|
|
|
publicSettings.Edge.SnapshotInterval = appSettings.Edge.SnapshotInterval
|
|
|
|
publicSettings.Edge.CommandInterval = appSettings.Edge.CommandInterval
|
|
|
|
publicSettings.Edge.CheckinInterval = appSettings.EdgeAgentCheckinInterval
|
|
|
|
|
2023-05-17 22:21:07 +00:00
|
|
|
publicSettings.IsDockerDesktopExtension = appSettings.IsDockerDesktopExtension
|
2023-05-17 02:31:46 +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"
|
|
|
|
}
|
|
|
|
}
|
2022-06-03 04:44:42 +00:00
|
|
|
//if LDAP authentication is on, compose the related fields from application settings
|
2022-07-21 09:29:34 +00:00
|
|
|
if publicSettings.AuthenticationMethod == portainer.AuthenticationLDAP && appSettings.LDAPSettings.GroupSearchSettings != nil {
|
|
|
|
if len(appSettings.LDAPSettings.GroupSearchSettings) > 0 {
|
|
|
|
publicSettings.TeamSync = len(appSettings.LDAPSettings.GroupSearchSettings[0].GroupBaseDN) > 0
|
|
|
|
}
|
2022-06-03 04:44:42 +00:00
|
|
|
}
|
2021-06-10 22:09:04 +00:00
|
|
|
return publicSettings
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|