mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(logging): replace all the loggers with zerolog EE-4186 (#7663)
This commit is contained in:
parent
53025178ef
commit
36e7981ab7
109 changed files with 1101 additions and 662 deletions
|
@ -6,13 +6,14 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/portainer/portainer/api"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var errInvalidResponseStatus = errors.New("Invalid response status (expecting 200)")
|
||||
|
@ -90,7 +91,8 @@ func Get(url string, timeout int) ([]byte, error) {
|
|||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
log.Printf("[ERROR] [http,client] [message: unexpected status code] [status_code: %d]", response.StatusCode)
|
||||
log.Error().Int("status_code", response.StatusCode).Msg("unexpected status code")
|
||||
|
||||
return nil, errInvalidResponseStatus
|
||||
}
|
||||
|
||||
|
|
|
@ -2,17 +2,18 @@ package auth
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
httperrors "github.com/portainer/portainer/api/http/errors"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type authenticatePayload struct {
|
||||
|
@ -31,9 +32,11 @@ func (payload *authenticatePayload) Validate(r *http.Request) error {
|
|||
if govalidator.IsNull(payload.Username) {
|
||||
return errors.New("Invalid username")
|
||||
}
|
||||
|
||||
if govalidator.IsNull(payload.Password) {
|
||||
return errors.New("Invalid password")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -101,6 +104,7 @@ func (handler *Handler) authenticateInternal(w http.ResponseWriter, user *portai
|
|||
}
|
||||
|
||||
forceChangePassword := !handler.passwordStrengthChecker.Check(password)
|
||||
|
||||
return handler.writeToken(w, user, forceChangePassword)
|
||||
}
|
||||
|
||||
|
@ -125,7 +129,7 @@ func (handler *Handler) authenticateLDAP(w http.ResponseWriter, user *portainer.
|
|||
|
||||
err = handler.addUserIntoTeams(user, ldapSettings)
|
||||
if err != nil {
|
||||
log.Printf("Warning: unable to automatically add user into teams: %s\n", err.Error())
|
||||
log.Warn().Err(err).Msg("unable to automatically add user into teams")
|
||||
}
|
||||
|
||||
return handler.writeToken(w, user, false)
|
||||
|
@ -191,6 +195,7 @@ func teamExists(teamName string, ldapGroups []string) bool {
|
|||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -200,6 +205,7 @@ func teamMembershipExists(teamID portainer.TeamID, memberships []portainer.TeamM
|
|||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,15 @@ package auth
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
httperrors "github.com/portainer/portainer/api/http/errors"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type oauthPayload struct {
|
||||
|
@ -71,7 +72,8 @@ func (handler *Handler) validateOAuth(w http.ResponseWriter, r *http.Request) *h
|
|||
|
||||
username, err := handler.authenticateOAuth(payload.Code, &settings.OAuthSettings)
|
||||
if err != nil {
|
||||
log.Printf("[DEBUG] - OAuth authentication error: %s", err)
|
||||
log.Debug().Err(err).Msg("OAuth authentication error")
|
||||
|
||||
return httperror.InternalServerError("Unable to authenticate through OAuth", httperrors.ErrUnauthorized)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,11 @@ package customtemplates
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
|
@ -17,6 +15,9 @@ import (
|
|||
"github.com/portainer/portainer/api/filesystem"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// @id CustomTemplateCreate
|
||||
|
@ -291,16 +292,18 @@ func (handler *Handler) createCustomTemplateFromGitRepository(r *http.Request) (
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
isValidProject := true
|
||||
defer func() {
|
||||
if !isValidProject {
|
||||
if err := handler.FileService.RemoveDirectory(projectPath); err != nil {
|
||||
log.Printf("[WARN] [http,customtemplate,git] [error: %s] [message: unable to remove git repository directory]", err)
|
||||
log.Warn().Err(err).Msg("unable to remove git repository directory")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
entryPath := filesystem.JoinPaths(projectPath, customTemplate.EntryPoint)
|
||||
|
||||
exists, err := handler.FileService.FileExists(entryPath)
|
||||
if err != nil || !exists {
|
||||
isValidProject = false
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package endpoints
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/internal/snapshot"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// @id EndpointSnapshots
|
||||
|
@ -35,13 +36,23 @@ func (handler *Handler) endpointSnapshots(w http.ResponseWriter, r *http.Request
|
|||
|
||||
latestEndpointReference, err := handler.DataStore.Endpoint().Endpoint(endpoint.ID)
|
||||
if latestEndpointReference == nil {
|
||||
log.Printf("background schedule error (environment snapshot). Environment not found inside the database anymore (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err)
|
||||
log.Debug().
|
||||
Str("endpoint", endpoint.Name).
|
||||
Str("URL", endpoint.URL).
|
||||
Err(err).
|
||||
Msg("background schedule error (environment snapshot), environment not found inside the database anymore")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
endpoint.Status = portainer.EndpointStatusUp
|
||||
if snapshotError != nil {
|
||||
log.Printf("background schedule error (environment snapshot). Unable to create snapshot (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, snapshotError)
|
||||
log.Debug().
|
||||
Str("endpoint", endpoint.Name).
|
||||
Str("URL", endpoint.URL).
|
||||
Err(snapshotError).
|
||||
Msg("background schedule error (environment snapshot), unable to create snapshot")
|
||||
|
||||
endpoint.Status = portainer.EndpointStatusDown
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package helm
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
|
@ -10,6 +9,8 @@ import (
|
|||
"github.com/portainer/libhelm/options"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// @id HelmShow
|
||||
|
@ -47,7 +48,7 @@ func (handler *Handler) helmShow(w http.ResponseWriter, r *http.Request) *httper
|
|||
cmd, err := request.RetrieveRouteVariableValue(r, "command")
|
||||
if err != nil {
|
||||
cmd = "all"
|
||||
log.Printf("[DEBUG] [internal,helm] [message: command not provided, defaulting to %s]", cmd)
|
||||
log.Debug().Str("default_command", cmd).Msg("command not provided, using default")
|
||||
}
|
||||
|
||||
showOptions := options.ShowOptions{
|
||||
|
|
|
@ -7,13 +7,13 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/fxamacker/cbor/v2"
|
||||
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/fxamacker/cbor/v2"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -63,7 +63,8 @@ func (payload *deviceConfigurePayload) Validate(r *http.Request) error {
|
|||
func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
guid, err := request.RetrieveRouteVariableValue(r, "guid")
|
||||
if err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: request.RetrieveRouteVariableValue()")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: request.RetrieveRouteVariableValue()")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: guid not found", err)
|
||||
}
|
||||
|
||||
|
@ -71,7 +72,8 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
|
||||
err = request.DecodeAndValidateJSONPayload(r, &payload)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Invalid request payload")
|
||||
log.Error().Err(err).Msg("invalid request payload")
|
||||
|
||||
return httperror.BadRequest("Invalid request payload", err)
|
||||
}
|
||||
|
||||
|
@ -84,13 +86,15 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
|
||||
fileContent, err := handler.FileService.GetFileContent(profile.FilePath, "")
|
||||
if err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: GetFileContent")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: GetFileContent")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: GetFileContent", err)
|
||||
}
|
||||
|
||||
fdoClient, err := handler.newFDOClient()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: newFDOClient()")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: newFDOClient()")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: newFDOClient()", err)
|
||||
}
|
||||
|
||||
|
@ -102,7 +106,8 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
"var": []string{"active"},
|
||||
"bytes": []string{"F5"}, // this is "true" in CBOR
|
||||
}, []byte("")); err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: PutDeviceSVIRaw()")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: PutDeviceSVIRaw()")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: PutDeviceSVIRaw()", err)
|
||||
}
|
||||
|
||||
|
@ -113,7 +118,8 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
"var": []string{"filedesc"},
|
||||
"filename": []string{"DEVICE_edgeid.txt"},
|
||||
}, []byte(payload.EdgeID)); err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: PutDeviceSVIRaw(edgeid)")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: PutDeviceSVIRaw(edgeid)")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: PutDeviceSVIRaw(edgeid)", err)
|
||||
}
|
||||
|
||||
|
@ -125,7 +131,8 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
"var": []string{"filedesc"},
|
||||
"filename": []string{"DEVICE_edgekey.txt"},
|
||||
}, []byte(payload.EdgeKey)); err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: PutDeviceSVIRaw(edgekey)")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: PutDeviceSVIRaw(edgekey)")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: PutDeviceSVIRaw(edgekey)", err)
|
||||
}
|
||||
|
||||
|
@ -137,7 +144,8 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
"var": []string{"filedesc"},
|
||||
"filename": []string{"DEVICE_name.txt"},
|
||||
}, []byte(payload.Name)); err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: PutDeviceSVIRaw(name)")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: PutDeviceSVIRaw(name)")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: PutDeviceSVIRaw(name)", err)
|
||||
}
|
||||
|
||||
|
@ -149,7 +157,8 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
"var": []string{"filedesc"},
|
||||
"filename": []string{"DEVICE_GUID.txt"},
|
||||
}, []byte(guid)); err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: PutDeviceSVIRaw()")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: PutDeviceSVIRaw()")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: PutDeviceSVIRaw()", err)
|
||||
}
|
||||
|
||||
|
@ -160,18 +169,20 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
"var": []string{"filedesc"},
|
||||
"filename": []string{deploymentScriptName},
|
||||
}, fileContent); err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: PutDeviceSVIRaw()")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: PutDeviceSVIRaw()")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: PutDeviceSVIRaw()", err)
|
||||
}
|
||||
|
||||
b, err := cbor.Marshal([]string{"/bin/sh", deploymentScriptName})
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("failed to marshal string to CBOR")
|
||||
log.Error().Err(err).Msg("failed to marshal string to CBOR")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: PutDeviceSVIRaw() failed to encode", err)
|
||||
}
|
||||
|
||||
cborBytes := strings.ToUpper(hex.EncodeToString(b))
|
||||
logrus.WithField("cbor", cborBytes).WithField("string", deploymentScriptName).Info("converted to CBOR")
|
||||
log.Debug().Str("cbor", cborBytes).Str("string", deploymentScriptName).Msg("converted to CBOR")
|
||||
|
||||
if err = fdoClient.PutDeviceSVIRaw(url.Values{
|
||||
"guid": []string{guid},
|
||||
|
@ -180,7 +191,8 @@ func (handler *Handler) fdoConfigureDevice(w http.ResponseWriter, r *http.Reques
|
|||
"var": []string{"exec"},
|
||||
"bytes": []string{cborBytes},
|
||||
}, []byte("")); err != nil {
|
||||
logrus.WithError(err).Info("fdoConfigureDevice: PutDeviceSVIRaw()")
|
||||
log.Error().Err(err).Msg("fdoConfigureDevice: PutDeviceSVIRaw()")
|
||||
|
||||
return httperror.InternalServerError("fdoConfigureDevice: PutDeviceSVIRaw()", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ import (
|
|||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/hostmanagement/fdo"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type fdoConfigurePayload portainer.FDOConfiguration
|
||||
|
@ -88,7 +89,8 @@ func (handler *Handler) fdoConfigure(w http.ResponseWriter, r *http.Request) *ht
|
|||
|
||||
err := request.DecodeAndValidateJSONPayload(r, &payload)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Invalid request payload")
|
||||
log.Error().Err(err).Msg("Invalid request payload")
|
||||
|
||||
return httperror.BadRequest("Invalid request payload", err)
|
||||
}
|
||||
|
||||
|
@ -101,6 +103,7 @@ func (handler *Handler) fdoConfigure(w http.ResponseWriter, r *http.Request) *ht
|
|||
if err != nil {
|
||||
return httperror.InternalServerError("Error saving FDO settings", err)
|
||||
}
|
||||
|
||||
if len(profiles) == 0 {
|
||||
err = handler.addDefaultProfile()
|
||||
if err != nil {
|
||||
|
@ -129,6 +132,7 @@ func (handler *Handler) addDefaultProfile() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"net/http"
|
||||
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/portainer/libhttp/response"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// @id fdoListAll
|
||||
|
@ -24,14 +24,16 @@ import (
|
|||
func (handler *Handler) fdoListAll(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
fdoClient, err := handler.newFDOClient()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Info("fdoListAll: newFDOClient()")
|
||||
log.Error().Err(err).Msg("fdoListAll: newFDOClient()")
|
||||
|
||||
return httperror.InternalServerError("fdoRegisterDevice: newFDOClient()", err)
|
||||
}
|
||||
|
||||
// Get all vouchers
|
||||
guids, err := fdoClient.GetVouchers()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Info("fdoListAll: GetVouchers()")
|
||||
log.Error().Err(err).Msg("fdoListAll: GetVouchers()")
|
||||
|
||||
return httperror.InternalServerError("fdoListAll: GetVouchers()", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type registerDeviceResponse struct {
|
||||
|
@ -29,19 +30,22 @@ func (handler *Handler) fdoRegisterDevice(w http.ResponseWriter, r *http.Request
|
|||
// Post a voucher
|
||||
ov, filename, err := request.RetrieveMultiPartFormFile(r, "voucher")
|
||||
if err != nil {
|
||||
logrus.WithField("filename", filename).WithError(err).Info("fdoRegisterDevice: readVoucher()")
|
||||
log.Info().Str("filename", filename).Err(err).Msg("fdoRegisterDevice: readVoucher()")
|
||||
|
||||
return httperror.InternalServerError("fdoRegisterDevice: read Voucher()", err)
|
||||
}
|
||||
|
||||
fdoClient, err := handler.newFDOClient()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Info("fdoRegisterDevice: newFDOClient()")
|
||||
log.Info().Err(err).Msg("fdoRegisterDevice: newFDOClient()")
|
||||
|
||||
return httperror.InternalServerError("fdoRegisterDevice: newFDOClient()", err)
|
||||
}
|
||||
|
||||
guid, err := fdoClient.PostVoucher(ov)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Info("fdoRegisterDevice: PostVoucher()")
|
||||
log.Info().Err(err).Msg("fdoRegisterDevice: PostVoucher()")
|
||||
|
||||
return httperror.InternalServerError("fdoRegisterDevice: PostVoucher()", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"software.sslmate.com/src/go-pkcs12"
|
||||
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"software.sslmate.com/src/go-pkcs12"
|
||||
)
|
||||
|
||||
type openAMTConfigurePayload struct {
|
||||
|
@ -73,7 +73,8 @@ func (handler *Handler) openAMTConfigure(w http.ResponseWriter, r *http.Request)
|
|||
var payload openAMTConfigurePayload
|
||||
err := request.DecodeAndValidateJSONPayload(r, &payload)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Invalid request payload")
|
||||
log.Error().Err(err).Msg("invalid request payload")
|
||||
|
||||
return httperror.BadRequest("Invalid request payload", err)
|
||||
}
|
||||
|
||||
|
@ -142,17 +143,20 @@ func (handler *Handler) enableOpenAMT(configurationPayload openAMTConfigurePaylo
|
|||
|
||||
err := handler.OpenAMTService.Configure(configuration)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("error configuring OpenAMT server")
|
||||
log.Error().Err(err).Msg("error configuring OpenAMT server")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
err = handler.saveConfiguration(configuration)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("error updating OpenAMT configurations")
|
||||
log.Error().Err(err).Msg("error updating OpenAMT configurations")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Info("OpenAMT successfully enabled")
|
||||
log.Info().Msg("OpenAMT successfully enabled")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -186,6 +190,7 @@ func (handler *Handler) disableOpenAMT() error {
|
|||
return err
|
||||
}
|
||||
|
||||
logrus.Info("OpenAMT successfully disabled")
|
||||
log.Info().Msg("OpenAMT successfully disabled")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ import (
|
|||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
bolterrors "github.com/portainer/portainer/api/dataservices/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// @id OpenAMTDevices
|
||||
|
@ -67,6 +68,7 @@ func (payload *deviceActionPayload) Validate(r *http.Request) error {
|
|||
if payload.Action == "" {
|
||||
return errors.New("device action must be provided")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -93,7 +95,8 @@ func (handler *Handler) deviceAction(w http.ResponseWriter, r *http.Request) *ht
|
|||
var payload deviceActionPayload
|
||||
err = request.DecodeAndValidateJSONPayload(r, &payload)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Invalid request payload")
|
||||
log.Error().Err(err).Msg("invalid request payload")
|
||||
|
||||
return httperror.BadRequest("Invalid request payload", err)
|
||||
}
|
||||
|
||||
|
@ -104,7 +107,8 @@ func (handler *Handler) deviceAction(w http.ResponseWriter, r *http.Request) *ht
|
|||
|
||||
err = handler.OpenAMTService.ExecuteDeviceAction(settings.OpenAMTConfiguration, deviceID, payload.Action)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Error executing device action")
|
||||
log.Error().Err(err).Msg("error executing device action")
|
||||
|
||||
return httperror.BadRequest("Error executing device action", err)
|
||||
}
|
||||
|
||||
|
@ -119,6 +123,7 @@ func (payload *deviceFeaturesPayload) Validate(r *http.Request) error {
|
|||
if payload.Features.UserConsent == "" {
|
||||
return errors.New("device user consent status must be provided")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -150,7 +155,8 @@ func (handler *Handler) deviceFeatures(w http.ResponseWriter, r *http.Request) *
|
|||
var payload deviceFeaturesPayload
|
||||
err = request.DecodeAndValidateJSONPayload(r, &payload)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Invalid request payload")
|
||||
log.Error().Err(err).Msg("invalid request payload")
|
||||
|
||||
return httperror.BadRequest("Invalid request payload", err)
|
||||
}
|
||||
|
||||
|
@ -166,7 +172,8 @@ func (handler *Handler) deviceFeatures(w http.ResponseWriter, r *http.Request) *
|
|||
|
||||
token, err := handler.OpenAMTService.EnableDeviceFeatures(settings.OpenAMTConfiguration, deviceID, payload.Features)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Error executing device action")
|
||||
log.Error().Err(err).Msg("error executing device action")
|
||||
|
||||
return httperror.BadRequest("Error executing device action", err)
|
||||
}
|
||||
|
||||
|
@ -174,5 +181,6 @@ func (handler *Handler) deviceFeatures(w http.ResponseWriter, r *http.Request) *
|
|||
Server: settings.OpenAMTConfiguration.MPSServer,
|
||||
Token: token,
|
||||
}
|
||||
|
||||
return response.JSON(w, authorizationResponse)
|
||||
}
|
||||
|
|
|
@ -4,24 +4,23 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/portainer/portainer/api/hostmanagement/openamt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/client"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
bolterrors "github.com/portainer/portainer/api/dataservices/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/portainer/portainer/api/hostmanagement/openamt"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type HostInfo struct {
|
||||
|
@ -60,7 +59,7 @@ func (handler *Handler) openAMTHostInfo(w http.ResponseWriter, r *http.Request)
|
|||
return httperror.BadRequest("Invalid environment identifier route variable", err)
|
||||
}
|
||||
|
||||
logrus.WithField("endpointID", endpointID).Info("OpenAMTHostInfo")
|
||||
log.Info().Int("endpointID", endpointID).Msg("OpenAMTHostInfo")
|
||||
|
||||
endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
|
||||
if err == bolterrors.ErrObjectNotFound {
|
||||
|
@ -121,6 +120,7 @@ func (handler *Handler) PullAndRunContainer(ctx context.Context, endpoint *porta
|
|||
if err != nil {
|
||||
return "Could not run container", err
|
||||
}
|
||||
|
||||
return output, nil
|
||||
}
|
||||
|
||||
|
@ -133,18 +133,20 @@ func (handler *Handler) PullAndRunContainer(ctx context.Context, endpoint *porta
|
|||
func pullImage(ctx context.Context, docker *client.Client, imageName string) error {
|
||||
out, err := docker.ImagePull(ctx, imageName, types.ImagePullOptions{})
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imageName", imageName).Error("Could not pull image from registry")
|
||||
log.Error().Str("image_name", imageName).Err(err).Msg("could not pull image from registry")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
defer out.Close()
|
||||
outputBytes, err := ioutil.ReadAll(out)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imageName", imageName).Error("Could not read image pull output")
|
||||
log.Error().Str("image_name", imageName).Err(err).Msg("could not read image pull output")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("%s imaged pulled with output:\n%s", imageName, string(outputBytes))
|
||||
log.Debug().Str("image_name", imageName).Str("output", string(outputBytes)).Msg("image pulled")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -158,14 +160,24 @@ func runContainer(ctx context.Context, docker *client.Client, imageName, contain
|
|||
opts.Filters.Add("name", containerName)
|
||||
existingContainers, err := docker.ContainerList(ctx, opts)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imagename", imageName).WithField("containername", containerName).Error("listing existing container")
|
||||
log.Error().
|
||||
Str("image_name", imageName).
|
||||
Str("container_name", containerName).
|
||||
Err(err).
|
||||
Msg("listing existing container")
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(existingContainers) > 0 {
|
||||
err = docker.ContainerRemove(ctx, existingContainers[0].ID, types.ContainerRemoveOptions{Force: true})
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imagename", imageName).WithField("containername", containerName).Error("removing existing container")
|
||||
log.Error().
|
||||
Str("image_name", imageName).
|
||||
Str("container_name", containerName).
|
||||
Err(err).
|
||||
Msg("removing existing container")
|
||||
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
@ -188,50 +200,82 @@ func runContainer(ctx context.Context, docker *client.Client, imageName, contain
|
|||
nil,
|
||||
containerName,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imagename", imageName).WithField("containername", containerName).Error("creating container")
|
||||
return "", err
|
||||
}
|
||||
err = docker.ContainerStart(ctx, created.ID, types.ContainerStartOptions{})
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imagename", imageName).WithField("containername", containerName).Error("starting container")
|
||||
log.Error().
|
||||
Str("image_name", imageName).
|
||||
Str("container_name", containerName).
|
||||
Err(err).
|
||||
Msg("creating container")
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
log.Printf("%s container created and started\n", containerName)
|
||||
err = docker.ContainerStart(ctx, created.ID, types.ContainerStartOptions{})
|
||||
if err != nil {
|
||||
log.Error().
|
||||
Str("image_name", imageName).
|
||||
Str("container_name", containerName).
|
||||
Err(err).
|
||||
Msg("starting container")
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
log.Debug().Str("container_name", containerName).Msg("container created and started")
|
||||
|
||||
statusCh, errCh := docker.ContainerWait(ctx, created.ID, container.WaitConditionNotRunning)
|
||||
var statusCode int64
|
||||
select {
|
||||
case err := <-errCh:
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imagename", imageName).WithField("containername", containerName).Error("starting container")
|
||||
log.Error().
|
||||
Str("image_name", imageName).
|
||||
Str("container_name", containerName).
|
||||
Err(err).
|
||||
Msg("starting container")
|
||||
|
||||
return "", err
|
||||
}
|
||||
case status := <-statusCh:
|
||||
statusCode = status.StatusCode
|
||||
}
|
||||
logrus.WithField("status", statusCode).Debug("container wait status")
|
||||
|
||||
log.Debug().Int64("status", statusCode).Msg("container wait status")
|
||||
|
||||
out, err := docker.ContainerLogs(ctx, created.ID, types.ContainerLogsOptions{ShowStdout: true})
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imagename", imageName).WithField("containername", containerName).Error("getting container log")
|
||||
log.Error().Err(err).Str("image_name", imageName).Str("container_name", containerName).Msg("getting container log")
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
err = docker.ContainerRemove(ctx, created.ID, types.ContainerRemoveOptions{})
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imagename", imageName).WithField("containername", containerName).Error("removing container")
|
||||
log.Error().
|
||||
Str("image_name", imageName).
|
||||
Str("container_name", containerName).
|
||||
Err(err).
|
||||
Msg("removing container")
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
outputBytes, err := ioutil.ReadAll(out)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("imagename", imageName).WithField("containername", containerName).Error("read container output")
|
||||
log.Error().
|
||||
Str("image_name", imageName).
|
||||
Str("container_name", containerName).
|
||||
Err(err).
|
||||
Msg("read container output")
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
log.Printf("%s container finished with output:\n%s", containerName, string(outputBytes))
|
||||
log.Debug().
|
||||
Str("container_name", containerName).
|
||||
Str("output", string(outputBytes)).
|
||||
Msg("container finished with output")
|
||||
|
||||
return string(outputBytes), nil
|
||||
}
|
||||
|
@ -269,6 +313,7 @@ func (handler *Handler) deactivateDevice(endpoint *portainer.Endpoint, settings
|
|||
"-u", fmt.Sprintf("wss://%s/activate", config.MPSServer),
|
||||
"-password", config.MPSPassword,
|
||||
}
|
||||
|
||||
_, err := handler.PullAndRunContainer(ctx, endpoint, rpcGoImageName, rpcGoContainerName, cmdLine)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package stacks
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
|
@ -9,6 +8,8 @@ import (
|
|||
"github.com/portainer/portainer/api/dataservices"
|
||||
"github.com/portainer/portainer/api/scheduler"
|
||||
"github.com/portainer/portainer/api/stacks"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func startAutoupdate(stackID portainer.StackID, interval string, scheduler *scheduler.Scheduler, stackDeployer stacks.StackDeployer, datastore dataservices.DataStore, gitService portainer.GitService) (jobID string, e *httperror.HandlerError) {
|
||||
|
@ -30,6 +31,6 @@ func stopAutoupdate(stackID portainer.StackID, jobID string, scheduler scheduler
|
|||
}
|
||||
|
||||
if err := scheduler.StopJob(jobID); err != nil {
|
||||
log.Printf("[WARN] could not stop the job for the stack %v", stackID)
|
||||
log.Warn().Int("stack_id", int(stackID)).Msg("could not stop the job for the stack")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package stacks
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -16,6 +15,8 @@ import (
|
|||
gittypes "github.com/portainer/portainer/api/git/types"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/stackutils"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type composeStackFromFileContentPayload struct {
|
||||
|
@ -44,6 +45,7 @@ func (handler *Handler) checkAndCleanStackDupFromSwarm(w http.ResponseWriter, r
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// stop scheduler updates of the stack before removal
|
||||
if stack.AutoUpdate != nil {
|
||||
stopAutoupdate(stack.ID, stack.AutoUpdate.JobID, *handler.Scheduler)
|
||||
|
@ -57,16 +59,21 @@ func (handler *Handler) checkAndCleanStackDupFromSwarm(w http.ResponseWriter, r
|
|||
if resourceControl != nil {
|
||||
err = handler.DataStore.ResourceControl().DeleteResourceControl(resourceControl.ID)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] [Stack] Unable to remove the associated resource control from the database for stack: [%+v].", stack)
|
||||
log.Error().
|
||||
Str("stack", fmt.Sprintf("%+v", stack)).
|
||||
Msg("unable to remove the associated resource control from the database for stack")
|
||||
}
|
||||
}
|
||||
|
||||
if exists, _ := handler.FileService.FileExists(stack.ProjectPath); exists {
|
||||
err = handler.FileService.RemoveDirectory(stack.ProjectPath)
|
||||
if err != nil {
|
||||
log.Printf("Unable to remove stack files from disk for stack: [%+v].", stack)
|
||||
log.Warn().
|
||||
Str("stack", fmt.Sprintf("%+v", stack)).
|
||||
Msg("unable to remove stack files from disk for stack")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package stacks
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/cli/cli/compose/loader"
|
||||
"github.com/docker/cli/cli/compose/types"
|
||||
"github.com/pkg/errors"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
|
@ -14,6 +10,11 @@ import (
|
|||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
"github.com/portainer/portainer/api/internal/stackutils"
|
||||
|
||||
"github.com/docker/cli/cli/compose/loader"
|
||||
"github.com/docker/cli/cli/compose/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (handler *Handler) cleanUp(stack *portainer.Stack, doCleanUp *bool) error {
|
||||
|
@ -23,8 +24,9 @@ func (handler *Handler) cleanUp(stack *portainer.Stack, doCleanUp *bool) error {
|
|||
|
||||
err := handler.FileService.RemoveDirectory(stack.ProjectPath)
|
||||
if err != nil {
|
||||
log.Printf("http error: Unable to cleanup stack creation (err=%s)\n", err)
|
||||
log.Error().Err(err).Msg("unable to cleanup stack creation")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package stacks
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
|
@ -16,6 +12,10 @@ import (
|
|||
httperrors "github.com/portainer/portainer/api/http/errors"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/stackutils"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type updateComposeStackPayload struct {
|
||||
|
@ -197,7 +197,7 @@ func (handler *Handler) updateComposeStack(r *http.Request, stack *portainer.Sta
|
|||
_, err = handler.FileService.UpdateStoreStackFileFromBytes(stackFolder, stack.EntryPoint, []byte(payload.StackFileContent))
|
||||
if err != nil {
|
||||
if rollbackErr := handler.FileService.RollbackStackFile(stackFolder, stack.EntryPoint); rollbackErr != nil {
|
||||
log.Printf("[WARN] [stack,update] [message: rollback stack file error] [err: %s]", rollbackErr)
|
||||
log.Warn().Err(rollbackErr).Msg("rollback stack file error")
|
||||
}
|
||||
|
||||
return httperror.InternalServerError("Unable to persist updated Compose file on disk", err)
|
||||
|
@ -206,7 +206,7 @@ func (handler *Handler) updateComposeStack(r *http.Request, stack *portainer.Sta
|
|||
config, configErr := handler.createComposeDeployConfig(r, stack, endpoint, payload.PullImage)
|
||||
if configErr != nil {
|
||||
if rollbackErr := handler.FileService.RollbackStackFile(stackFolder, stack.EntryPoint); rollbackErr != nil {
|
||||
log.Printf("[WARN] [stack,update] [message: rollback stack file error] [err: %s]", rollbackErr)
|
||||
log.Warn().Err(rollbackErr).Msg("rollback stack file error")
|
||||
}
|
||||
|
||||
return configErr
|
||||
|
@ -215,7 +215,7 @@ func (handler *Handler) updateComposeStack(r *http.Request, stack *portainer.Sta
|
|||
err = handler.deployComposeStack(config, false)
|
||||
if err != nil {
|
||||
if rollbackErr := handler.FileService.RollbackStackFile(stackFolder, stack.EntryPoint); rollbackErr != nil {
|
||||
log.Printf("[WARN] [stack,update] [message: rollback stack file error] [err: %s]", rollbackErr)
|
||||
log.Warn().Err(rollbackErr).Msg("rollback stack file error")
|
||||
}
|
||||
|
||||
return httperror.InternalServerError(err.Error(), err)
|
||||
|
@ -248,7 +248,7 @@ func (handler *Handler) updateSwarmStack(r *http.Request, stack *portainer.Stack
|
|||
_, err = handler.FileService.UpdateStoreStackFileFromBytes(stackFolder, stack.EntryPoint, []byte(payload.StackFileContent))
|
||||
if err != nil {
|
||||
if rollbackErr := handler.FileService.RollbackStackFile(stackFolder, stack.EntryPoint); rollbackErr != nil {
|
||||
log.Printf("[WARN] [swarm,stack,update] [message: rollback stack file error] [err: %s]", rollbackErr)
|
||||
log.Warn().Err(rollbackErr).Msg("rollback stack file error")
|
||||
}
|
||||
|
||||
return httperror.InternalServerError("Unable to persist updated Compose file on disk", err)
|
||||
|
@ -257,7 +257,7 @@ func (handler *Handler) updateSwarmStack(r *http.Request, stack *portainer.Stack
|
|||
config, configErr := handler.createSwarmDeployConfig(r, stack, endpoint, payload.Prune, payload.PullImage)
|
||||
if configErr != nil {
|
||||
if rollbackErr := handler.FileService.RollbackStackFile(stackFolder, stack.EntryPoint); rollbackErr != nil {
|
||||
log.Printf("[WARN] [swarm,stack,update] [message: rollback stack file error] [err: %s]", rollbackErr)
|
||||
log.Warn().Err(rollbackErr).Msg("rollback stack file error")
|
||||
}
|
||||
|
||||
return configErr
|
||||
|
@ -266,7 +266,7 @@ func (handler *Handler) updateSwarmStack(r *http.Request, stack *portainer.Stack
|
|||
err = handler.deploySwarmStack(config)
|
||||
if err != nil {
|
||||
if rollbackErr := handler.FileService.RollbackStackFile(stackFolder, stack.EntryPoint); rollbackErr != nil {
|
||||
log.Printf("[WARN] [swarm,stack,update] [message: rollback stack file error] [err: %s]", rollbackErr)
|
||||
log.Warn().Err(rollbackErr).Msg("rollback stack file error")
|
||||
}
|
||||
|
||||
return httperror.InternalServerError(err.Error(), err)
|
||||
|
|
|
@ -2,7 +2,6 @@ package stacks
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
@ -16,6 +15,8 @@ import (
|
|||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/stackutils"
|
||||
k "github.com/portainer/portainer/api/kubernetes"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type stackGitRedployPayload struct {
|
||||
|
@ -156,7 +157,7 @@ func (handler *Handler) stackGitRedeploy(w http.ResponseWriter, r *http.Request)
|
|||
if err != nil {
|
||||
restoreError := filesystem.MoveDirectory(backupProjectPath, stack.ProjectPath)
|
||||
if restoreError != nil {
|
||||
log.Printf("[WARN] [http,stacks,git] [error: %s] [message: failed restoring backup folder]", restoreError)
|
||||
log.Warn().Err(restoreError).Msg("failed restoring backup folder")
|
||||
}
|
||||
|
||||
return httperror.InternalServerError("Unable to clone git repository", err)
|
||||
|
@ -165,7 +166,7 @@ func (handler *Handler) stackGitRedeploy(w http.ResponseWriter, r *http.Request)
|
|||
defer func() {
|
||||
err = handler.FileService.RemoveDirectory(backupProjectPath)
|
||||
if err != nil {
|
||||
log.Printf("[WARN] [http,stacks,git] [error: %s] [message: unable to remove git repository directory]", err)
|
||||
log.Warn().Err(err).Msg("unable to remove git repository directory")
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -3,13 +3,10 @@ package stacks
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/pkg/errors"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
|
@ -17,6 +14,10 @@ import (
|
|||
gittypes "github.com/portainer/portainer/api/git/types"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
k "github.com/portainer/portainer/api/kubernetes"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type kubernetesFileStackUpdatePayload struct {
|
||||
|
@ -128,7 +129,7 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
|
|||
projectPath, err := handler.FileService.UpdateStoreStackFileFromBytes(stackFolder, stack.EntryPoint, []byte(payload.StackFileContent))
|
||||
if err != nil {
|
||||
if rollbackErr := handler.FileService.RollbackStackFile(stackFolder, stack.EntryPoint); rollbackErr != nil {
|
||||
log.Printf("[WARN] [kubernetes,stack,update] [message: rollback stack file error] [err: %s]", rollbackErr)
|
||||
log.Warn().Err(rollbackErr).Msg("rollback stack file error")
|
||||
}
|
||||
|
||||
fileType := "Manifest"
|
||||
|
|
|
@ -3,15 +3,13 @@ package stacks
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/portainer/libhttp/response"
|
||||
|
||||
"github.com/portainer/portainer/api/stacks"
|
||||
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
"github.com/portainer/portainer/api/stacks"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// @id WebhookInvoke
|
||||
|
@ -36,6 +34,7 @@ func (handler *Handler) webhookInvoke(w http.ResponseWriter, r *http.Request) *h
|
|||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
statusCode = http.StatusNotFound
|
||||
}
|
||||
|
||||
return &httperror.HandlerError{StatusCode: statusCode, Message: "Unable to find the stack by webhook ID", Err: err}
|
||||
}
|
||||
|
||||
|
@ -43,7 +42,9 @@ func (handler *Handler) webhookInvoke(w http.ResponseWriter, r *http.Request) *h
|
|||
if _, ok := err.(*stacks.StackAuthorMissingErr); ok {
|
||||
return &httperror.HandlerError{StatusCode: http.StatusConflict, Message: "Autoupdate for the stack isn't available", Err: err}
|
||||
}
|
||||
logrus.WithError(err).Error("failed to update the stack")
|
||||
|
||||
log.Error().Err(err).Msg("failed to update the stack")
|
||||
|
||||
return httperror.InternalServerError("Failed to update the stack", err)
|
||||
}
|
||||
|
||||
|
@ -57,7 +58,6 @@ func retrieveUUIDRouteVariableValue(r *http.Request, name string) (uuid.UUID, er
|
|||
}
|
||||
|
||||
uid, err := uuid.FromString(webhookID)
|
||||
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
|
|
@ -5,14 +5,13 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/coreos/go-semver/semver"
|
||||
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/build"
|
||||
"github.com/portainer/portainer/api/http/client"
|
||||
|
||||
"github.com/portainer/libhttp/response"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/coreos/go-semver/semver"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type versionResponse struct {
|
||||
|
@ -71,7 +70,8 @@ func (handler *Handler) version(w http.ResponseWriter, r *http.Request) {
|
|||
func getLatestVersion() string {
|
||||
motd, err := client.Get(portainer.VersionCheckURL, 5)
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("couldn't fetch latest Portainer release version")
|
||||
log.Debug().Err(err).Msg("couldn't fetch latest Portainer release version")
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,8 @@ func getLatestVersion() string {
|
|||
|
||||
err = json.Unmarshal(motd, &data)
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("couldn't parse latest Portainer version")
|
||||
log.Debug().Err(err).Msg("couldn't parse latest Portainer version")
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -91,13 +92,15 @@ func getLatestVersion() string {
|
|||
func hasNewerVersion(currentVersion, latestVersion string) bool {
|
||||
currentVersionSemver, err := semver.NewVersion(currentVersion)
|
||||
if err != nil {
|
||||
log.WithField("version", currentVersion).Debug("current Portainer version isn't a semver")
|
||||
log.Debug().Str("version", currentVersion).Msg("current Portainer version isn't a semver")
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
latestVersionSemver, err := semver.NewVersion(latestVersion)
|
||||
if err != nil {
|
||||
log.WithField("version", latestVersion).Debug("latest Portainer version isn't a semver")
|
||||
log.Debug().Str("version", latestVersion).Msg("latest Portainer version isn't a semver")
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package templates
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
|
@ -11,6 +10,8 @@ import (
|
|||
"github.com/portainer/libhttp/request"
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type filePayload struct {
|
||||
|
@ -114,7 +115,8 @@ func (handler *Handler) templateFile(w http.ResponseWriter, r *http.Request) *ht
|
|||
func (handler *Handler) cleanUp(projectPath string) error {
|
||||
err := handler.FileService.RemoveDirectory(projectPath)
|
||||
if err != nil {
|
||||
log.Printf("http error: Unable to cleanup stack creation (err=%s)\n", err)
|
||||
log.Debug().Err(err).Msg("HTTP error: unable to cleanup stack creation")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@ package websocket
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
"github.com/portainer/libhttp/request"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/http/proxy/factory/kubernetes"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// @summary Execute a websocket on pod
|
||||
|
@ -149,7 +149,8 @@ func (handler *Handler) hijackPodExecStartOperation(
|
|||
|
||||
// websocket client successfully disconnected
|
||||
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseNoStatusReceived) {
|
||||
log.Printf("websocket error: %s \n", err.Error())
|
||||
log.Debug().Err(err).Msg("websocket error")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package offlinegate
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
lock "github.com/viney-shih/go-lock"
|
||||
)
|
||||
|
||||
|
@ -40,7 +41,7 @@ func (o *OfflineGate) WaitingMiddleware(timeout time.Duration, next http.Handler
|
|||
}
|
||||
|
||||
if !o.lock.RTryLockWithTimeout(timeout) {
|
||||
log.Println("error: Timeout waiting for the offline gate to signal")
|
||||
log.Error().Msg("timeout waiting for the offline gate to signal")
|
||||
httperror.WriteError(w, http.StatusRequestTimeout, "Timeout waiting for the offline gate to signal", http.ErrHandlerTimeout)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,16 +2,17 @@ package factory
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/crypto"
|
||||
"github.com/portainer/portainer/api/http/proxy/factory/agent"
|
||||
"github.com/portainer/portainer/api/internal/endpointutils"
|
||||
"github.com/portainer/portainer/api/internal/url"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// ProxyServer provide an extended proxy with a local server to forward requests
|
||||
|
@ -24,7 +25,7 @@ type ProxyServer struct {
|
|||
func (factory *ProxyFactory) NewAgentProxy(endpoint *portainer.Endpoint) (*ProxyServer, error) {
|
||||
urlString := endpoint.URL
|
||||
|
||||
if endpointutils.IsEdgeEndpoint((endpoint)) {
|
||||
if endpointutils.IsEdgeEndpoint(endpoint) {
|
||||
tunnel, err := factory.reverseTunnelService.GetActiveTunnel(endpoint)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed starting tunnel")
|
||||
|
@ -77,15 +78,16 @@ func (proxy *ProxyServer) start() error {
|
|||
}
|
||||
|
||||
proxy.Port = listener.Addr().(*net.TCPAddr).Port
|
||||
|
||||
go func() {
|
||||
proxyHost := fmt.Sprintf("127.0.0.1:%d", proxy.Port)
|
||||
log.Printf("Starting Proxy server on %s...\n", proxyHost)
|
||||
log.Debug().Str("host", proxyHost).Msg("starting proxy server")
|
||||
|
||||
err := proxy.server.Serve(listener)
|
||||
log.Printf("Exiting Proxy server %s\n", proxyHost)
|
||||
log.Debug().Str("host", proxyHost).Msg("exiting proxy server")
|
||||
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
log.Printf("Proxy server %s exited with an error: %s\n", proxyHost, err)
|
||||
log.Debug().Str("host", proxyHost).Err(err).Msg("proxy server exited with an error")
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package azure
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (transport *Transport) createAzureRequestContext(request *http.Request) (*azureRequestContext, error) {
|
||||
|
@ -65,7 +66,11 @@ func (transport *Transport) createPrivateResourceControl(
|
|||
|
||||
err := transport.dataStore.ResourceControl().Create(resourceControl)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] [http,proxy,azure,transport] [message: unable to persist resource control] [resource: %s] [err: %s]", resourceIdentifier, err)
|
||||
log.Error().
|
||||
Str("resource", resourceIdentifier).
|
||||
Err(err).
|
||||
Msg("unable to persist resource control")
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -76,6 +81,7 @@ func (transport *Transport) userCanDeleteContainerGroup(request *http.Request, c
|
|||
if context.isAdmin {
|
||||
return true
|
||||
}
|
||||
|
||||
resourceIdentifier := request.URL.Path
|
||||
resourceControl := transport.findResourceControl(resourceIdentifier, context)
|
||||
return authorization.UserCanAccessResource(context.userID, context.userTeamIDs, resourceControl)
|
||||
|
@ -100,7 +106,7 @@ func (transport *Transport) decorateContainerGroup(containerGroup map[string]int
|
|||
containerGroup = decorateObject(containerGroup, resourceControl)
|
||||
}
|
||||
} else {
|
||||
log.Printf("[WARN] [http,proxy,azure,decorate] [message: unable to find resource id property in container group]")
|
||||
log.Warn().Msg("unable to find resource id property in container group")
|
||||
}
|
||||
|
||||
return containerGroup
|
||||
|
@ -137,7 +143,7 @@ func (transport *Transport) removeResourceControl(containerGroup map[string]inte
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
log.Printf("[WARN] [http,proxy,azure] [message: missign ID in container group]")
|
||||
log.Debug().Msg("missing ID in container group")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -3,7 +3,6 @@ package factory
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
@ -12,6 +11,8 @@ import (
|
|||
"github.com/portainer/portainer/api/crypto"
|
||||
"github.com/portainer/portainer/api/http/proxy/factory/docker"
|
||||
"github.com/portainer/portainer/api/internal/url"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (factory *ProxyFactory) newDockerProxy(endpoint *portainer.Endpoint) (http.Handler, error) {
|
||||
|
@ -107,6 +108,6 @@ func (proxy *dockerLocalProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|||
w.WriteHeader(res.StatusCode)
|
||||
|
||||
if _, err := io.Copy(w, res.Body); err != nil {
|
||||
log.Printf("proxy error: %s\n", err)
|
||||
log.Debug().Err(err).Msg("proxy error")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/portainer/portainer/api/internal/stackutils"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/http/proxy/factory/utils"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
"github.com/portainer/portainer/api/internal/stackutils"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -79,7 +78,11 @@ func (transport *Transport) newResourceControlFromPortainerLabels(labelsObject m
|
|||
for _, name := range teamNames {
|
||||
team, err := transport.dataStore.Team().TeamByName(name)
|
||||
if err != nil {
|
||||
log.Printf("[WARN] [http,proxy,docker] [message: unknown team name in access control label, ignoring access control rule for this team] [name: %s] [resource_id: %s]", name, resourceID)
|
||||
log.Warn().
|
||||
Str("name", name).
|
||||
Str("resource_id", resourceID).
|
||||
Msg("unknown team name in access control label, ignoring access control rule for this team")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -89,7 +92,11 @@ func (transport *Transport) newResourceControlFromPortainerLabels(labelsObject m
|
|||
for _, name := range userNames {
|
||||
user, err := transport.dataStore.User().UserByUsername(name)
|
||||
if err != nil {
|
||||
log.Printf("[WARN] [http,proxy,docker] [message: unknown user name in access control label, ignoring access control rule for this user] [name: %s] [resource_id: %s]", name, resourceID)
|
||||
log.Warn().
|
||||
Str("name", name).
|
||||
Str("resource_id", resourceID).
|
||||
Msg("unknown user name in access control label, ignoring access control rule for this user")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -114,7 +121,11 @@ func (transport *Transport) createPrivateResourceControl(resourceIdentifier stri
|
|||
|
||||
err := transport.dataStore.ResourceControl().Create(resourceControl)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] [http,proxy,docker,transport] [message: unable to persist resource control] [resource: %s] [err: %s]", resourceIdentifier, err)
|
||||
log.Error().
|
||||
Str("resource", resourceIdentifier).
|
||||
Err(err).
|
||||
Msg("unable to persist resource control")
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -148,7 +159,10 @@ func (transport *Transport) getInheritedResourceControlFromServiceOrStack(resour
|
|||
|
||||
func (transport *Transport) applyAccessControlOnResource(parameters *resourceOperationParameters, responseObject map[string]interface{}, response *http.Response, executor *operationExecutor) error {
|
||||
if responseObject[parameters.resourceIdentifierAttribute] == nil {
|
||||
log.Printf("[WARN] [message: unable to find resource identifier property in resource object] [identifier_attribute: %s]", parameters.resourceIdentifierAttribute)
|
||||
log.Warn().
|
||||
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
||||
Msg("unable to find resource identifier property in resource object")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -195,7 +209,10 @@ func (transport *Transport) decorateResourceList(parameters *resourceOperationPa
|
|||
resourceObject := resource.(map[string]interface{})
|
||||
|
||||
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
|
||||
log.Printf("[WARN] [http,proxy,docker,decorate] [message: unable to find resource identifier property in resource list element] [identifier_attribute: %s]", parameters.resourceIdentifierAttribute)
|
||||
log.Warn().
|
||||
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
||||
Msg("unable to find resource identifier property in resource list element")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -232,7 +249,10 @@ func (transport *Transport) filterResourceList(parameters *resourceOperationPara
|
|||
for _, resource := range resourceData {
|
||||
resourceObject := resource.(map[string]interface{})
|
||||
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
|
||||
log.Printf("[WARN] [http,proxy,docker,filter] [message: unable to find resource identifier property in resource list element] [identifier_attribute: %s]", parameters.resourceIdentifierAttribute)
|
||||
log.Warn().
|
||||
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
||||
Msg("unable to find resource identifier property in resource list element")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"mime"
|
||||
"net/http"
|
||||
|
||||
"github.com/portainer/portainer/api/archive"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const OneMegabyte = 1024768
|
||||
|
@ -78,7 +79,7 @@ func buildOperation(request *http.Request) error {
|
|||
|
||||
defer f.Close()
|
||||
|
||||
log.Printf("[INFO] [http,proxy,docker] [message: upload the file to build image] [filename: %s] [size: %d]", hdr.Filename, hdr.Size)
|
||||
log.Info().Str("filename", hdr.Filename).Int64("size", hdr.Size).Msg("upload the file to build image")
|
||||
|
||||
content, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"regexp"
|
||||
|
@ -21,6 +20,8 @@ import (
|
|||
"github.com/portainer/portainer/api/http/proxy/factory/utils"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var apiVersionRe = regexp.MustCompile(`(/v[0-9]\.[0-9]*)?`)
|
||||
|
@ -422,6 +423,7 @@ func (transport *Transport) proxyImageRequest(request *http.Request) (*http.Resp
|
|||
|
||||
func (transport *Transport) replaceRegistryAuthenticationHeader(request *http.Request) (*http.Response, error) {
|
||||
transport.decorateRegistryAuthenticationHeader(request)
|
||||
|
||||
return transport.decorateGenericResourceCreationOperation(request, serviceObjectIdentifier, portainer.ServiceResourceControl)
|
||||
}
|
||||
|
||||
|
@ -601,7 +603,8 @@ func (transport *Transport) decorateGenericResourceCreationResponse(response *ht
|
|||
}
|
||||
|
||||
if responseObject[resourceIdentifierAttribute] == nil {
|
||||
log.Printf("[ERROR] [proxy,docker]")
|
||||
log.Error().Msg("missing identifier in Docker resource creation response")
|
||||
|
||||
return errors.New("missing identifier in Docker resource creation response")
|
||||
}
|
||||
|
||||
|
@ -754,6 +757,7 @@ func (transport *Transport) createOperationContext(request *http.Request) (*rest
|
|||
for _, membership := range teamMemberships {
|
||||
userTeamIDs = append(userTeamIDs, membership.TeamID)
|
||||
}
|
||||
|
||||
operationContext.userTeamIDs = userTeamIDs
|
||||
}
|
||||
|
||||
|
|
|
@ -6,18 +6,18 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/kubernetes/cli"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type baseTransport struct {
|
||||
|
@ -132,7 +132,10 @@ func (transport *baseTransport) getRoundTripToken(request *http.Request, tokenMa
|
|||
} else {
|
||||
token, err = tokenManager.GetUserServiceAccountToken(int(tokenData.ID), transport.endpoint.ID)
|
||||
if err != nil {
|
||||
log.Printf("Failed retrieving service account token: %v", err)
|
||||
log.Debug().
|
||||
Err(err).
|
||||
Msg("failed retrieving service account token")
|
||||
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ package utils
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// GetResponseAsJSONObject returns the response content as a generic JSON object
|
||||
|
@ -34,10 +36,17 @@ func GetResponseAsJSONArray(response *http.Response) ([]interface{}, error) {
|
|||
if responseObject["message"] != nil {
|
||||
return nil, errors.New(responseObject["message"].(string))
|
||||
}
|
||||
log.Printf("[ERROR] [http,proxy,response] [message: invalid response format, expecting JSON array] [response: %+v]", responseObject)
|
||||
|
||||
log.Error().
|
||||
Str("response", fmt.Sprintf("%+v", responseObject)).
|
||||
Msg("invalid response format, expecting JSON array")
|
||||
|
||||
return nil, errors.New("unable to parse response: expected JSON array, got JSON object")
|
||||
default:
|
||||
log.Printf("[ERROR] [http,proxy,response] [message: invalid response format, expecting JSON array] [response: %+v]", responseObject)
|
||||
log.Error().
|
||||
Str("response", fmt.Sprintf("%+v", responseObject)).
|
||||
Msg("invalid response format, expecting JSON array")
|
||||
|
||||
return nil, errors.New("unable to parse response: expected JSON array")
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +59,7 @@ type errorResponse struct {
|
|||
func WriteAccessDeniedResponse() (*http.Response, error) {
|
||||
response := &http.Response{}
|
||||
err := RewriteResponse(response, errorResponse{Message: "access denied to resource"}, http.StatusForbidden)
|
||||
|
||||
return response, err
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ package security
|
|||
|
||||
import (
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type PasswordStrengthChecker interface {
|
||||
|
@ -23,7 +24,8 @@ func NewPasswordStrengthChecker(settings settingsService) *passwordStrengthCheck
|
|||
func (c *passwordStrengthChecker) Check(password string) bool {
|
||||
s, err := c.settings.Settings()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Warn("failed to fetch Portainer settings to validate user password")
|
||||
log.Warn().Err(err).Msg("failed to fetch Portainer settings to validate user password")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@ package http
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
@ -64,6 +62,8 @@ import (
|
|||
"github.com/portainer/portainer/api/kubernetes/cli"
|
||||
"github.com/portainer/portainer/api/scheduler"
|
||||
stackdeployer "github.com/portainer/portainer/api/stacks"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// Server implements the portainer.Server interface
|
||||
|
@ -319,21 +319,22 @@ func (server *Server) Start() error {
|
|||
handler := adminMonitor.WithRedirect(offlineGate.WaitingMiddleware(time.Minute, server.Handler))
|
||||
if server.HTTPEnabled {
|
||||
go func() {
|
||||
log.Printf("[INFO] [http,server] [message: starting HTTP server on port %s]", server.BindAddress)
|
||||
log.Info().Str("bind_address", server.BindAddress).Msg("starting HTTP server")
|
||||
httpServer := &http.Server{
|
||||
Addr: server.BindAddress,
|
||||
Handler: handler,
|
||||
}
|
||||
|
||||
go shutdown(server.ShutdownCtx, httpServer)
|
||||
|
||||
err := httpServer.ListenAndServe()
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
log.Printf("[ERROR] [message: http server failed] [error: %s]", err)
|
||||
log.Error().Err(err).Msg("HTTP server failed to start")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
log.Printf("[INFO] [http,server] [message: starting HTTPS server on port %s]", server.BindAddressHTTPS)
|
||||
log.Info().Str("bind_address", server.BindAddressHTTPS).Msg("starting HTTPS server")
|
||||
httpsServer := &http.Server{
|
||||
Addr: server.BindAddressHTTPS,
|
||||
Handler: handler,
|
||||
|
@ -345,18 +346,21 @@ func (server *Server) Start() error {
|
|||
}
|
||||
|
||||
go shutdown(server.ShutdownCtx, httpsServer)
|
||||
|
||||
return httpsServer.ListenAndServeTLS("", "")
|
||||
}
|
||||
|
||||
func shutdown(shutdownCtx context.Context, httpServer *http.Server) {
|
||||
<-shutdownCtx.Done()
|
||||
|
||||
log.Println("[DEBUG] [http,server] [message: shutting down http server]")
|
||||
log.Debug().Msg("shutting down the HTTP server")
|
||||
shutdownTimeout, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
err := httpServer.Shutdown(shutdownTimeout)
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] [http,server] [message: failed shutdown http server] [error: %s]", err)
|
||||
log.Error().
|
||||
Err(err).
|
||||
Msg("failed to shut down the HTTP server")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue