From c2673557590ed39b94668ba09a1f957ac735ec15 Mon Sep 17 00:00:00 2001 From: Marcelo Rydel Date: Mon, 29 Nov 2021 14:44:33 -0700 Subject: [PATCH] fix(openamt): fix IsFeatureFlagEnabled, rename MPS Url to MPS Server [INT-6] (#6172) --- api/bolt/settings/settings.go | 2 +- api/hostmanagement/openamt/authorization.go | 2 +- api/hostmanagement/openamt/configCIRA.go | 12 ++++++------ api/hostmanagement/openamt/configDomain.go | 4 ++-- api/hostmanagement/openamt/configProfile.go | 4 ++-- api/hostmanagement/openamt/configWireless.go | 4 ++-- .../handler/hostmanagement/openamt/openamt.go | 10 +++++----- api/portainer.go | 2 +- .../general/open-amt/open-amt.controller.js | 4 ++-- .../settings/general/open-amt/open-amt.html | 16 ++++++++-------- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/api/bolt/settings/settings.go b/api/bolt/settings/settings.go index 061023685..e0e4781dd 100644 --- a/api/bolt/settings/settings.go +++ b/api/bolt/settings/settings.go @@ -51,7 +51,7 @@ func (service *Service) IsFeatureFlagEnabled(feature portainer.Feature) bool { return false } - featureFlagSetting, ok := settings.FeatureFlagSettings[portainer.FeatOpenAMT] + featureFlagSetting, ok := settings.FeatureFlagSettings[feature] if ok { return featureFlagSetting } diff --git a/api/hostmanagement/openamt/authorization.go b/api/hostmanagement/openamt/authorization.go index ec0fc4813..92be17b49 100644 --- a/api/hostmanagement/openamt/authorization.go +++ b/api/hostmanagement/openamt/authorization.go @@ -15,7 +15,7 @@ type authenticationResponse struct { } func (service *Service) executeAuthenticationRequest(configuration portainer.OpenAMTConfiguration) (*authenticationResponse, error) { - loginURL := fmt.Sprintf("https://%s/mps/login/api/v1/authorize", configuration.MPSURL) + loginURL := fmt.Sprintf("https://%s/mps/login/api/v1/authorize", configuration.MPSServer) payload := map[string]string{ "username": configuration.Credentials.MPSUser, diff --git a/api/hostmanagement/openamt/configCIRA.go b/api/hostmanagement/openamt/configCIRA.go index 5678b5628..fdbc23202 100644 --- a/api/hostmanagement/openamt/configCIRA.go +++ b/api/hostmanagement/openamt/configCIRA.go @@ -45,7 +45,7 @@ func (service *Service) createOrUpdateCIRAConfig(configuration portainer.OpenAMT } func (service *Service) getCIRAConfig(configuration portainer.OpenAMTConfiguration, configName string) (*CIRAConfig, error) { - url := fmt.Sprintf("https://%s/rps/api/v1/admin/ciraconfigs/%s", configuration.MPSURL, configName) + url := fmt.Sprintf("https://%s/rps/api/v1/admin/ciraconfigs/%s", configuration.MPSServer, configName) responseBody, err := service.executeGetRequest(url, configuration.Credentials.MPSToken) if err != nil { @@ -64,22 +64,22 @@ func (service *Service) getCIRAConfig(configuration portainer.OpenAMTConfigurati } func (service *Service) saveCIRAConfig(method string, configuration portainer.OpenAMTConfiguration, configName string) (*CIRAConfig, error) { - url := fmt.Sprintf("https://%s/rps/api/v1/admin/ciraconfigs", configuration.MPSURL) + url := fmt.Sprintf("https://%s/rps/api/v1/admin/ciraconfigs", configuration.MPSServer) certificate, err := service.getCIRACertificate(configuration) if err != nil { return nil, err } - addressFormat, err := addressFormat(configuration.MPSURL) + addressFormat, err := addressFormat(configuration.MPSServer) if err != nil { return nil, err } config := CIRAConfig{ ConfigName: configName, - MPSServerAddress: configuration.MPSURL, - CommonName: configuration.MPSURL, + MPSServerAddress: configuration.MPSServer, + CommonName: configuration.MPSServer, ServerAddressFormat: addressFormat, MPSPort: 4433, Username: "admin", @@ -117,7 +117,7 @@ func addressFormat(url string) (int, error) { } func (service *Service) getCIRACertificate(configuration portainer.OpenAMTConfiguration) (string, error) { - loginURL := fmt.Sprintf("https://%s/mps/api/v1/ciracert", configuration.MPSURL) + loginURL := fmt.Sprintf("https://%s/mps/api/v1/ciracert", configuration.MPSServer) req, err := http.NewRequest(http.MethodGet, loginURL, nil) if err != nil { diff --git a/api/hostmanagement/openamt/configDomain.go b/api/hostmanagement/openamt/configDomain.go index b3b04385a..4936ad8ca 100644 --- a/api/hostmanagement/openamt/configDomain.go +++ b/api/hostmanagement/openamt/configDomain.go @@ -37,7 +37,7 @@ func (service *Service) createOrUpdateDomain(configuration portainer.OpenAMTConf } func (service *Service) getDomain(configuration portainer.OpenAMTConfiguration) (*Domain, error) { - url := fmt.Sprintf("https://%s/rps/api/v1/admin/domains/%s", configuration.MPSURL, configuration.DomainConfiguration.DomainName) + url := fmt.Sprintf("https://%s/rps/api/v1/admin/domains/%s", configuration.MPSServer, configuration.DomainConfiguration.DomainName) responseBody, err := service.executeGetRequest(url, configuration.Credentials.MPSToken) if err != nil { @@ -56,7 +56,7 @@ func (service *Service) getDomain(configuration portainer.OpenAMTConfiguration) } func (service *Service) saveDomain(method string, configuration portainer.OpenAMTConfiguration) (*Domain, error) { - url := fmt.Sprintf("https://%s/rps/api/v1/admin/domains", configuration.MPSURL) + url := fmt.Sprintf("https://%s/rps/api/v1/admin/domains", configuration.MPSServer) profile := Domain{ DomainName: configuration.DomainConfiguration.DomainName, diff --git a/api/hostmanagement/openamt/configProfile.go b/api/hostmanagement/openamt/configProfile.go index c50f66f6f..55cd6f1a8 100644 --- a/api/hostmanagement/openamt/configProfile.go +++ b/api/hostmanagement/openamt/configProfile.go @@ -48,7 +48,7 @@ func (service *Service) createOrUpdateAMTProfile(configuration portainer.OpenAMT } func (service *Service) getAMTProfile(configuration portainer.OpenAMTConfiguration, profileName string) (*Profile, error) { - url := fmt.Sprintf("https://%s/rps/api/v1/admin/profiles/%s", configuration.MPSURL, profileName) + url := fmt.Sprintf("https://%s/rps/api/v1/admin/profiles/%s", configuration.MPSServer, profileName) responseBody, err := service.executeGetRequest(url, configuration.Credentials.MPSToken) if err != nil { @@ -67,7 +67,7 @@ func (service *Service) getAMTProfile(configuration portainer.OpenAMTConfigurati } func (service *Service) saveAMTProfile(method string, configuration portainer.OpenAMTConfiguration, profileName string, ciraConfigName string, wirelessConfig string) (*Profile, error) { - url := fmt.Sprintf("https://%s/rps/api/v1/admin/profiles", configuration.MPSURL) + url := fmt.Sprintf("https://%s/rps/api/v1/admin/profiles", configuration.MPSServer) profile := Profile{ ProfileName: profileName, diff --git a/api/hostmanagement/openamt/configWireless.go b/api/hostmanagement/openamt/configWireless.go index 0a3938fa0..958626755 100644 --- a/api/hostmanagement/openamt/configWireless.go +++ b/api/hostmanagement/openamt/configWireless.go @@ -38,7 +38,7 @@ func (service *Service) createOrUpdateWirelessConfig(configuration portainer.Ope } func (service *Service) getWirelessConfig(configuration portainer.OpenAMTConfiguration, configName string) (*WirelessProfile, error) { - url := fmt.Sprintf("https://%s/rps/api/v1/admin/wirelessconfigs/%s", configuration.MPSURL, configName) + url := fmt.Sprintf("https://%s/rps/api/v1/admin/wirelessconfigs/%s", configuration.MPSServer, configName) responseBody, err := service.executeGetRequest(url, configuration.Credentials.MPSToken) if err != nil { @@ -66,7 +66,7 @@ func (service *Service) saveWirelessConfig(method string, configuration portaine return nil, fmt.Errorf("error parsing wireless encryption method: %s", err.Error()) } - url := fmt.Sprintf("https://%s/rps/api/v1/admin/wirelessconfigs", configuration.MPSURL) + url := fmt.Sprintf("https://%s/rps/api/v1/admin/wirelessconfigs", configuration.MPSServer) config := WirelessProfile{ ProfileName: configName, diff --git a/api/http/handler/hostmanagement/openamt/openamt.go b/api/http/handler/hostmanagement/openamt/openamt.go index 59754712b..69eb0918d 100644 --- a/api/http/handler/hostmanagement/openamt/openamt.go +++ b/api/http/handler/hostmanagement/openamt/openamt.go @@ -18,7 +18,7 @@ import ( type openAMTConfigureDefaultPayload struct { EnableOpenAMT bool - MPSURL string + MPSServer string MPSUser string MPSPassword string CertFileText string @@ -33,8 +33,8 @@ type openAMTConfigureDefaultPayload struct { func (payload *openAMTConfigureDefaultPayload) Validate(r *http.Request) error { if payload.EnableOpenAMT { - if payload.MPSURL == "" { - return errors.New("MPS Url must be provided") + if payload.MPSServer == "" { + return errors.New("MPS Server must be provided") } if payload.MPSUser == "" { return errors.New("MPS User must be provided") @@ -145,8 +145,8 @@ func isValidIssuer(issuer string) bool { func (handler *Handler) enableOpenAMT(configurationPayload openAMTConfigureDefaultPayload) error { configuration := portainer.OpenAMTConfiguration{ - Enabled: true, - MPSURL: configurationPayload.MPSURL, + Enabled: true, + MPSServer: configurationPayload.MPSServer, Credentials: portainer.MPSCredentials{ MPSUser: configurationPayload.MPSUser, MPSPassword: configurationPayload.MPSPassword, diff --git a/api/portainer.go b/api/portainer.go index 6be22c7d7..3d2ba11ec 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -42,7 +42,7 @@ type ( // OpenAMTConfiguration represents the credentials and configurations used to connect to an OpenAMT MPS server OpenAMTConfiguration struct { Enabled bool `json:"Enabled"` - MPSURL string `json:"MPSURL"` + MPSServer string `json:"MPSServer"` Credentials MPSCredentials `json:"Credentials"` DomainConfiguration DomainConfiguration `json:"DomainConfiguration"` WirelessConfiguration *WirelessConfiguration `json:"WirelessConfiguration"` diff --git a/app/portainer/settings/general/open-amt/open-amt.controller.js b/app/portainer/settings/general/open-amt/open-amt.controller.js index e2a835413..1e52b5d96 100644 --- a/app/portainer/settings/general/open-amt/open-amt.controller.js +++ b/app/portainer/settings/general/open-amt/open-amt.controller.js @@ -6,7 +6,7 @@ class OpenAmtController { this.originalValues = {}; this.formValues = { enableOpenAMT: false, - mpsURL: '', + mpsServer: '', mpsUser: '', mpsPassword: '', domainName: '', @@ -85,7 +85,7 @@ class OpenAmtController { this.formValues = { ...this.formValues, enableOpenAMT: config.Enabled, - mpsURL: config.MPSURL, + mpsServer: config.MPSServer, mpsUser: config.Credentials.MPSUser, domainName: config.DomainConfiguration.DomainName, }; diff --git a/app/portainer/settings/general/open-amt/open-amt.html b/app/portainer/settings/general/open-amt/open-amt.html index 7926f5aaa..38798fa77 100644 --- a/app/portainer/settings/general/open-amt/open-amt.html +++ b/app/portainer/settings/general/open-amt/open-amt.html @@ -16,24 +16,24 @@
-
-
+
-
+

This field is required.