diff --git a/api/go.mod b/api/go.mod index fb0121c7e..1ff7ebe06 100644 --- a/api/go.mod +++ b/api/go.mod @@ -24,7 +24,6 @@ require ( github.com/go-playground/validator/v10 v10.12.0 github.com/gofrs/uuid v4.2.0+incompatible github.com/golang-jwt/jwt/v4 v4.2.0 - github.com/google/go-cmp v0.5.9 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 github.com/gorilla/securecookie v1.1.1 @@ -54,6 +53,8 @@ require ( golang.org/x/sync v0.1.0 gopkg.in/alecthomas/kingpin.v2 v2.2.6 gopkg.in/yaml.v3 v3.0.1 + gorm.io/driver/sqlite v1.5.0 + gorm.io/gorm v1.25.0 k8s.io/api v0.26.1 k8s.io/apimachinery v0.26.1 k8s.io/client-go v0.26.1 @@ -98,12 +99,15 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/imdario/mergo v0.3.15 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/jpillora/ansi v1.0.2 // indirect @@ -116,6 +120,7 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect + github.com/mattn/go-sqlite3 v1.14.15 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/moby/spdystream v0.2.0 // indirect diff --git a/api/go.sum b/api/go.sum index 1f4c89629..5aeb405bb 100644 --- a/api/go.sum +++ b/api/go.sum @@ -224,6 +224,10 @@ github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+h github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= diff --git a/api/http/handler/edgegroups/edgegroup_update.go b/api/http/handler/edgegroups/edgegroup_update.go index 0cffc1201..d1fdc1be5 100644 --- a/api/http/handler/edgegroups/edgegroup_update.go +++ b/api/http/handler/edgegroups/edgegroup_update.go @@ -5,11 +5,9 @@ import ( "net/http" httperror "github.com/portainer/libhttp/error" - "github.com/portainer/libhttp/request" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/dataservices" "github.com/portainer/portainer/api/internal/edge" - "github.com/portainer/portainer/api/internal/endpointutils" "github.com/portainer/portainer/api/internal/slices" "github.com/asaskevich/govalidator" @@ -54,122 +52,123 @@ func (payload *edgeGroupUpdatePayload) Validate(r *http.Request) error { // @failure 500 // @router /edge_groups/{id} [put] func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { - edgeGroupID, err := request.RetrieveNumericRouteVariableValue(r, "id") - if err != nil { - return httperror.BadRequest("Invalid Edge group identifier route variable", err) - } + // edgeGroupID, err := request.RetrieveNumericRouteVariableValue(r, "id") + // if err != nil { + // return httperror.BadRequest("Invalid Edge group identifier route variable", err) + // } - var payload edgeGroupUpdatePayload - err = request.DecodeAndValidateJSONPayload(r, &payload) - if err != nil { - return httperror.BadRequest("Invalid request payload", err) - } + // var payload edgeGroupUpdatePayload + // err = request.DecodeAndValidateJSONPayload(r, &payload) + // if err != nil { + // return httperror.BadRequest("Invalid request payload", err) + // } - var edgeGroup *portainer.EdgeGroup - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - edgeGroup, err = tx.EdgeGroup().EdgeGroup(portainer.EdgeGroupID(edgeGroupID)) - if handler.DataStore.IsErrObjectNotFound(err) { - return httperror.NotFound("Unable to find an Edge group with the specified identifier inside the database", err) - } else if err != nil { - return httperror.InternalServerError("Unable to find an Edge group with the specified identifier inside the database", err) - } + // var edgeGroup *portainer.EdgeGroup + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // edgeGroup, err = tx.EdgeGroup().EdgeGroup(portainer.EdgeGroupID(edgeGroupID)) + // if handler.DataStore.IsErrObjectNotFound(err) { + // return httperror.NotFound("Unable to find an Edge group with the specified identifier inside the database", err) + // } else if err != nil { + // return httperror.InternalServerError("Unable to find an Edge group with the specified identifier inside the database", err) + // } - if payload.Name != "" { - edgeGroups, err := tx.EdgeGroup().EdgeGroups() - if err != nil { - return httperror.InternalServerError("Unable to retrieve Edge groups from the database", err) - } + // if payload.Name != "" { + // edgeGroups, err := tx.EdgeGroup().EdgeGroups() + // if err != nil { + // return httperror.InternalServerError("Unable to retrieve Edge groups from the database", err) + // } - for _, edgeGroup := range edgeGroups { - if edgeGroup.Name == payload.Name && edgeGroup.ID != portainer.EdgeGroupID(edgeGroupID) { - return httperror.BadRequest("Edge group name must be unique", errors.New("edge group name must be unique")) - } - } + // for _, edgeGroup := range edgeGroups { + // if edgeGroup.Name == payload.Name && edgeGroup.ID != portainer.EdgeGroupID(edgeGroupID) { + // return httperror.BadRequest("Edge group name must be unique", errors.New("edge group name must be unique")) + // } + // } - edgeGroup.Name = payload.Name - } + // edgeGroup.Name = payload.Name + // } - endpoints, err := tx.Endpoint().Endpoints() - if err != nil { - return httperror.InternalServerError("Unable to retrieve environments from database", err) - } + // endpoints, err := tx.Endpoint().Endpoints() + // if err != nil { + // return httperror.InternalServerError("Unable to retrieve environments from database", err) + // } - endpointGroups, err := tx.EndpointGroup().EndpointGroups() - if err != nil { - return httperror.InternalServerError("Unable to retrieve environment groups from database", err) - } + // endpointGroups, err := tx.EndpointGroup().EndpointGroups() + // if err != nil { + // return httperror.InternalServerError("Unable to retrieve environment groups from database", err) + // } - oldRelatedEndpoints := edge.EdgeGroupRelatedEndpoints(edgeGroup, endpoints, endpointGroups) + // oldRelatedEndpoints := edge.EdgeGroupRelatedEndpoints(edgeGroup, endpoints, endpointGroups) - edgeGroup.Dynamic = payload.Dynamic - if edgeGroup.Dynamic { - edgeGroup.TagIDs = payload.TagIDs - } else { - endpointIDs := []portainer.EndpointID{} - for _, endpointID := range payload.Endpoints { - endpoint, err := tx.Endpoint().Endpoint(endpointID) - if err != nil { - return httperror.InternalServerError("Unable to retrieve environment from the database", err) - } + // edgeGroup.Dynamic = payload.Dynamic + // if edgeGroup.Dynamic { + // edgeGroup.TagIDs = payload.TagIDs + // } else { + // endpointIDs := []portainer.EndpointID{} + // for _, endpointID := range payload.Endpoints { + // endpoint, err := tx.Endpoint().Endpoint(endpointID) + // if err != nil { + // return httperror.InternalServerError("Unable to retrieve environment from the database", err) + // } - if endpointutils.IsEdgeEndpoint(endpoint) { - endpointIDs = append(endpointIDs, endpoint.ID) - } - } - edgeGroup.Endpoints = endpointIDs - } + // if endpointutils.IsEdgeEndpoint(endpoint) { + // endpointIDs = append(endpointIDs, endpoint.ID) + // } + // } + // edgeGroup.Endpoints = endpointIDs + // } - if payload.PartialMatch != nil { - edgeGroup.PartialMatch = *payload.PartialMatch - } + // if payload.PartialMatch != nil { + // edgeGroup.PartialMatch = *payload.PartialMatch + // } - err = tx.EdgeGroup().UpdateEdgeGroup(edgeGroup.ID, edgeGroup) - if err != nil { - return httperror.InternalServerError("Unable to persist Edge group changes inside the database", err) - } + // err = tx.EdgeGroup().UpdateEdgeGroup(edgeGroup.ID, edgeGroup) + // if err != nil { + // return httperror.InternalServerError("Unable to persist Edge group changes inside the database", err) + // } - newRelatedEndpoints := edge.EdgeGroupRelatedEndpoints(edgeGroup, endpoints, endpointGroups) - endpointsToUpdate := append(newRelatedEndpoints, oldRelatedEndpoints...) + // newRelatedEndpoints := edge.EdgeGroupRelatedEndpoints(edgeGroup, endpoints, endpointGroups) + // endpointsToUpdate := append(newRelatedEndpoints, oldRelatedEndpoints...) - edgeJobs, err := tx.EdgeJob().EdgeJobs() - if err != nil { - return httperror.InternalServerError("Unable to fetch Edge jobs", err) - } + // edgeJobs, err := tx.EdgeJob().EdgeJobs() + // if err != nil { + // return httperror.InternalServerError("Unable to fetch Edge jobs", err) + // } - for _, endpointID := range endpointsToUpdate { - err = handler.updateEndpointStacks(tx, endpointID) - if err != nil { - return httperror.InternalServerError("Unable to persist Environment relation changes inside the database", err) - } + // for _, endpointID := range endpointsToUpdate { + // err = handler.updateEndpointStacks(tx, endpointID) + // if err != nil { + // return httperror.InternalServerError("Unable to persist Environment relation changes inside the database", err) + // } - endpoint, err := tx.Endpoint().Endpoint(endpointID) - if err != nil { - return httperror.InternalServerError("Unable to get Environment from database", err) - } + // endpoint, err := tx.Endpoint().Endpoint(endpointID) + // if err != nil { + // return httperror.InternalServerError("Unable to get Environment from database", err) + // } - if !endpointutils.IsEdgeEndpoint(endpoint) { - continue - } + // if !endpointutils.IsEdgeEndpoint(endpoint) { + // continue + // } - var operation string - if slices.Contains(newRelatedEndpoints, endpointID) { - operation = "add" - } else if slices.Contains(oldRelatedEndpoints, endpointID) { - operation = "remove" - } else { - continue - } + // var operation string + // if slices.Contains(newRelatedEndpoints, endpointID) { + // operation = "add" + // } else if slices.Contains(oldRelatedEndpoints, endpointID) { + // operation = "remove" + // } else { + // continue + // } - err = handler.updateEndpointEdgeJobs(edgeGroup.ID, endpoint, edgeJobs, operation) - if err != nil { - return httperror.InternalServerError("Unable to persist Environment Edge Jobs changes inside the database", err) - } - } + // err = handler.updateEndpointEdgeJobs(edgeGroup.ID, endpoint, edgeJobs, operation) + // if err != nil { + // return httperror.InternalServerError("Unable to persist Environment Edge Jobs changes inside the database", err) + // } + // } - return nil - }) + // return nil + // }) - return txResponse(w, edgeGroup, err) + // return txResponse(w, edgeGroup, err) + return nil } func (handler *Handler) updateEndpointStacks(tx dataservices.DataStoreTx, endpointID portainer.EndpointID) error { diff --git a/api/http/handler/edgejobs/edgejob_create.go b/api/http/handler/edgejobs/edgejob_create.go index 68c9f4d87..38465f8c9 100644 --- a/api/http/handler/edgejobs/edgejob_create.go +++ b/api/http/handler/edgejobs/edgejob_create.go @@ -95,11 +95,11 @@ func (handler *Handler) createEdgeJobFromFileContent(w http.ResponseWriter, r *h if featureflags.IsEnabled(portainer.FeatureNoTx) { edgeJob, err = handler.createEdgeJob(handler.DataStore, &payload.edgeJobBasePayload, []byte(payload.FileContent)) } else { - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - edgeJob, err = handler.createEdgeJob(tx, &payload.edgeJobBasePayload, []byte(payload.FileContent)) + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // edgeJob, err = handler.createEdgeJob(tx, &payload.edgeJobBasePayload, []byte(payload.FileContent)) - return err - }) + // return err + // }) } return txResponse(w, edgeJob, err) @@ -204,11 +204,11 @@ func (handler *Handler) createEdgeJobFromFile(w http.ResponseWriter, r *http.Req if featureflags.IsEnabled(portainer.FeatureNoTx) { edgeJob, err = handler.createEdgeJob(handler.DataStore, &payload.edgeJobBasePayload, payload.File) } else { - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - edgeJob, err = handler.createEdgeJob(tx, &payload.edgeJobBasePayload, payload.File) + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // edgeJob, err = handler.createEdgeJob(tx, &payload.edgeJobBasePayload, payload.File) - return err - }) + // return err + // }) } return txResponse(w, edgeJob, err) @@ -216,7 +216,6 @@ func (handler *Handler) createEdgeJobFromFile(w http.ResponseWriter, r *http.Req func (handler *Handler) createEdgeJobObjectFromPayload(tx dataservices.DataStoreTx, payload *edgeJobBasePayload) *portainer.EdgeJob { return &portainer.EdgeJob{ - ID: portainer.EdgeJobID(tx.EdgeJob().GetNextIdentifier()), Name: payload.Name, CronExpression: payload.CronExpression, Recurring: payload.Recurring, diff --git a/api/http/handler/edgejobs/edgejob_delete.go b/api/http/handler/edgejobs/edgejob_delete.go index 23e921f89..95a3a11a7 100644 --- a/api/http/handler/edgejobs/edgejob_delete.go +++ b/api/http/handler/edgejobs/edgejob_delete.go @@ -37,9 +37,9 @@ func (handler *Handler) edgeJobDelete(w http.ResponseWriter, r *http.Request) *h if featureflags.IsEnabled(portainer.FeatureNoTx) { err = handler.deleteEdgeJob(handler.DataStore, portainer.EdgeJobID(edgeJobID)) } else { - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - return handler.deleteEdgeJob(tx, portainer.EdgeJobID(edgeJobID)) - }) + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // return handler.deleteEdgeJob(tx, portainer.EdgeJobID(edgeJobID)) + // }) } if err != nil { diff --git a/api/http/handler/edgejobs/edgejob_tasklogs_clear.go b/api/http/handler/edgejobs/edgejob_tasklogs_clear.go index d71e3e91e..2f0446506 100644 --- a/api/http/handler/edgejobs/edgejob_tasklogs_clear.go +++ b/api/http/handler/edgejobs/edgejob_tasklogs_clear.go @@ -64,15 +64,15 @@ func (handler *Handler) edgeJobTasksClear(w http.ResponseWriter, r *http.Request err = handler.clearEdgeJobTaskLogs(handler.DataStore, portainer.EdgeJobID(edgeJobID), portainer.EndpointID(taskID), updateEdgeJobFn) } else { - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - updateEdgeJobFn := func(edgeJob *portainer.EdgeJob, endpointID portainer.EndpointID, endpointsFromGroups []portainer.EndpointID) error { - mutationFn(edgeJob, endpointID, endpointsFromGroups) + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // updateEdgeJobFn := func(edgeJob *portainer.EdgeJob, endpointID portainer.EndpointID, endpointsFromGroups []portainer.EndpointID) error { + // mutationFn(edgeJob, endpointID, endpointsFromGroups) - return tx.EdgeJob().UpdateEdgeJob(edgeJob.ID, edgeJob) - } + // return tx.EdgeJob().UpdateEdgeJob(edgeJob.ID, edgeJob) + // } - return handler.clearEdgeJobTaskLogs(tx, portainer.EdgeJobID(edgeJobID), portainer.EndpointID(taskID), updateEdgeJobFn) - }) + // return handler.clearEdgeJobTaskLogs(tx, portainer.EdgeJobID(edgeJobID), portainer.EndpointID(taskID), updateEdgeJobFn) + // }) } if err != nil { diff --git a/api/http/handler/edgejobs/edgejob_tasklogs_collect.go b/api/http/handler/edgejobs/edgejob_tasklogs_collect.go index 0bf5952ff..915c644a7 100644 --- a/api/http/handler/edgejobs/edgejob_tasklogs_collect.go +++ b/api/http/handler/edgejobs/edgejob_tasklogs_collect.go @@ -1,16 +1,10 @@ package edgejobs import ( - "errors" "net/http" httperror "github.com/portainer/libhttp/error" - "github.com/portainer/libhttp/request" "github.com/portainer/libhttp/response" - portainer "github.com/portainer/portainer/api" - "github.com/portainer/portainer/api/dataservices" - "github.com/portainer/portainer/api/internal/edge" - "github.com/portainer/portainer/api/internal/slices" ) // @id EdgeJobTasksCollect @@ -28,69 +22,69 @@ import ( // @failure 503 "Edge compute features are disabled" // @router /edge_jobs/{id}/tasks/{taskID}/logs [post] func (handler *Handler) edgeJobTasksCollect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { - edgeJobID, err := request.RetrieveNumericRouteVariableValue(r, "id") - if err != nil { - return httperror.BadRequest("Invalid Edge job identifier route variable", err) - } + // edgeJobID, err := request.RetrieveNumericRouteVariableValue(r, "id") + // if err != nil { + // return httperror.BadRequest("Invalid Edge job identifier route variable", err) + // } - taskID, err := request.RetrieveNumericRouteVariableValue(r, "taskID") - if err != nil { - return httperror.BadRequest("Invalid Task identifier route variable", err) - } + // taskID, err := request.RetrieveNumericRouteVariableValue(r, "taskID") + // if err != nil { + // return httperror.BadRequest("Invalid Task identifier route variable", err) + // } - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - edgeJob, err := tx.EdgeJob().EdgeJob(portainer.EdgeJobID(edgeJobID)) - if tx.IsErrObjectNotFound(err) { - return httperror.NotFound("Unable to find an Edge job with the specified identifier inside the database", err) - } else if err != nil { - return httperror.InternalServerError("Unable to find an Edge job with the specified identifier inside the database", err) - } + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // edgeJob, err := tx.EdgeJob().EdgeJob(portainer.EdgeJobID(edgeJobID)) + // if tx.IsErrObjectNotFound(err) { + // return httperror.NotFound("Unable to find an Edge job with the specified identifier inside the database", err) + // } else if err != nil { + // return httperror.InternalServerError("Unable to find an Edge job with the specified identifier inside the database", err) + // } - endpointID := portainer.EndpointID(taskID) - endpointsFromGroups, err := edge.GetEndpointsFromEdgeGroups(edgeJob.EdgeGroups, tx) - if err != nil { - return httperror.InternalServerError("Unable to get Endpoints from EdgeGroups", err) - } + // endpointID := portainer.EndpointID(taskID) + // endpointsFromGroups, err := edge.GetEndpointsFromEdgeGroups(edgeJob.EdgeGroups, tx) + // if err != nil { + // return httperror.InternalServerError("Unable to get Endpoints from EdgeGroups", err) + // } - if slices.Contains(endpointsFromGroups, endpointID) { - edgeJob.GroupLogsCollection[endpointID] = portainer.EdgeJobEndpointMeta{ - CollectLogs: true, - LogsStatus: portainer.EdgeJobLogsStatusPending, - } - } else { - meta := edgeJob.Endpoints[endpointID] - meta.CollectLogs = true - meta.LogsStatus = portainer.EdgeJobLogsStatusPending - edgeJob.Endpoints[endpointID] = meta - } + // if slices.Contains(endpointsFromGroups, endpointID) { + // edgeJob.GroupLogsCollection[endpointID] = portainer.EdgeJobEndpointMeta{ + // CollectLogs: true, + // LogsStatus: portainer.EdgeJobLogsStatusPending, + // } + // } else { + // meta := edgeJob.Endpoints[endpointID] + // meta.CollectLogs = true + // meta.LogsStatus = portainer.EdgeJobLogsStatusPending + // edgeJob.Endpoints[endpointID] = meta + // } - err = tx.EdgeJob().UpdateEdgeJob(edgeJob.ID, edgeJob) - if err != nil { - return httperror.InternalServerError("Unable to persist Edge job changes in the database", err) - } + // err = tx.EdgeJob().UpdateEdgeJob(edgeJob.ID, edgeJob) + // if err != nil { + // return httperror.InternalServerError("Unable to persist Edge job changes in the database", err) + // } - endpoint, err := tx.Endpoint().Endpoint(endpointID) - if err != nil { - return httperror.InternalServerError("Unable to retrieve environment from the database", err) - } + // endpoint, err := tx.Endpoint().Endpoint(endpointID) + // if err != nil { + // return httperror.InternalServerError("Unable to retrieve environment from the database", err) + // } - if endpoint.Edge.AsyncMode { - return httperror.BadRequest("Async Edge Endpoints are not supported in Portainer CE", nil) - } + // if endpoint.Edge.AsyncMode { + // return httperror.BadRequest("Async Edge Endpoints are not supported in Portainer CE", nil) + // } - handler.ReverseTunnelService.AddEdgeJob(endpoint, edgeJob) + // handler.ReverseTunnelService.AddEdgeJob(endpoint, edgeJob) - return nil - }) + // return nil + // }) - if err != nil { - var handlerError *httperror.HandlerError - if errors.As(err, &handlerError) { - return handlerError - } + // if err != nil { + // var handlerError *httperror.HandlerError + // if errors.As(err, &handlerError) { + // return handlerError + // } - return httperror.InternalServerError("Unexpected error", err) - } + // return httperror.InternalServerError("Unexpected error", err) + // } return response.Empty(w) } diff --git a/api/http/handler/edgejobs/edgejob_tasks_list.go b/api/http/handler/edgejobs/edgejob_tasks_list.go index b8a19d134..571482833 100644 --- a/api/http/handler/edgejobs/edgejob_tasks_list.go +++ b/api/http/handler/edgejobs/edgejob_tasks_list.go @@ -42,10 +42,10 @@ func (handler *Handler) edgeJobTasksList(w http.ResponseWriter, r *http.Request) if featureflags.IsEnabled(portainer.FeatureNoTx) { tasks, err = listEdgeJobTasks(handler.DataStore, portainer.EdgeJobID(edgeJobID)) } else { - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - tasks, err = listEdgeJobTasks(tx, portainer.EdgeJobID(edgeJobID)) - return err - }) + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // tasks, err = listEdgeJobTasks(tx, portainer.EdgeJobID(edgeJobID)) + // return err + // }) } return txResponse(w, tasks, err) diff --git a/api/http/handler/edgejobs/edgejob_update.go b/api/http/handler/edgejobs/edgejob_update.go index 90ca51854..eb36c2507 100644 --- a/api/http/handler/edgejobs/edgejob_update.go +++ b/api/http/handler/edgejobs/edgejob_update.go @@ -66,10 +66,10 @@ func (handler *Handler) edgeJobUpdate(w http.ResponseWriter, r *http.Request) *h if featureflags.IsEnabled(portainer.FeatureNoTx) { edgeJob, err = handler.updateEdgeJob(handler.DataStore, portainer.EdgeJobID(edgeJobID), payload) } else { - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - edgeJob, err = handler.updateEdgeJob(tx, portainer.EdgeJobID(edgeJobID), payload) - return err - }) + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // edgeJob, err = handler.updateEdgeJob(tx, portainer.EdgeJobID(edgeJobID), payload) + // return err + // }) } return txResponse(w, edgeJob, err) diff --git a/api/http/handler/endpoints/endpoint_create.go b/api/http/handler/endpoints/endpoint_create.go index 05049c7a2..57374f4c1 100644 --- a/api/http/handler/endpoints/endpoint_create.go +++ b/api/http/handler/endpoints/endpoint_create.go @@ -330,9 +330,7 @@ func (handler *Handler) createAzureEndpoint(payload *endpointCreatePayload) (*po return nil, httperror.InternalServerError("Unable to authenticate against Azure", err) } - endpointID := handler.DataStore.Endpoint().GetNextIdentifier() endpoint := &portainer.Endpoint{ - ID: portainer.EndpointID(endpointID), Name: payload.Name, URL: "https://management.azure.com", Type: portainer.AzureEnvironment, @@ -357,17 +355,14 @@ func (handler *Handler) createAzureEndpoint(payload *endpointCreatePayload) (*po } func (handler *Handler) createEdgeAgentEndpoint(payload *endpointCreatePayload) (*portainer.Endpoint, *httperror.HandlerError) { - endpointID := handler.DataStore.Endpoint().GetNextIdentifier() - portainerHost, err := edge.ParseHostForEdge(payload.URL) if err != nil { return nil, httperror.BadRequest("Unable to parse host", err) } - edgeKey := handler.ReverseTunnelService.GenerateEdgeKey(payload.URL, portainerHost, endpointID) + edgeKey := handler.ReverseTunnelService.GenerateEdgeKey(payload.URL, portainerHost, 0) // TODO: endpoint ID endpoint := &portainer.Endpoint{ - ID: portainer.EndpointID(endpointID), Name: payload.Name, URL: portainerHost, Type: portainer.EdgeAgentOnDockerEnvironment, @@ -419,9 +414,7 @@ func (handler *Handler) createUnsecuredEndpoint(payload *endpointCreatePayload) } } - endpointID := handler.DataStore.Endpoint().GetNextIdentifier() endpoint := &portainer.Endpoint{ - ID: portainer.EndpointID(endpointID), Name: payload.Name, URL: payload.URL, Type: endpointType, @@ -452,10 +445,7 @@ func (handler *Handler) createKubernetesEndpoint(payload *endpointCreatePayload) payload.URL = "https://kubernetes.default.svc" } - endpointID := handler.DataStore.Endpoint().GetNextIdentifier() - endpoint := &portainer.Endpoint{ - ID: portainer.EndpointID(endpointID), Name: payload.Name, URL: payload.URL, Type: portainer.KubernetesLocalEnvironment, @@ -483,9 +473,7 @@ func (handler *Handler) createKubernetesEndpoint(payload *endpointCreatePayload) } func (handler *Handler) createTLSSecuredEndpoint(payload *endpointCreatePayload, endpointType portainer.EndpointType, agentVersion string) (*portainer.Endpoint, *httperror.HandlerError) { - endpointID := handler.DataStore.Endpoint().GetNextIdentifier() endpoint := &portainer.Endpoint{ - ID: portainer.EndpointID(endpointID), Name: payload.Name, URL: payload.URL, Type: endpointType, diff --git a/api/http/handler/hostmanagement/fdo/fdo.go b/api/http/handler/hostmanagement/fdo/fdo.go index 69851f454..1a2a35191 100644 --- a/api/http/handler/hostmanagement/fdo/fdo.go +++ b/api/http/handler/hostmanagement/fdo/fdo.go @@ -115,9 +115,7 @@ func (handler *Handler) fdoConfigure(w http.ResponseWriter, r *http.Request) *ht } func (handler *Handler) addDefaultProfile() error { - profileID := handler.DataStore.FDOProfile().GetNextIdentifier() profile := &portainer.FDOProfile{ - ID: portainer.FDOProfileID(profileID), Name: "Docker Standalone + Edge", } diff --git a/api/http/handler/hostmanagement/fdo/profile_create.go b/api/http/handler/hostmanagement/fdo/profile_create.go index d83ad9b50..f505115bd 100644 --- a/api/http/handler/hostmanagement/fdo/profile_create.go +++ b/api/http/handler/hostmanagement/fdo/profile_create.go @@ -72,9 +72,7 @@ func (handler *Handler) createFDOProfileFromFileContent(w http.ResponseWriter, r return &httperror.HandlerError{StatusCode: http.StatusConflict, Message: fmt.Sprintf("A profile with the name '%s' already exists", payload.Name), Err: errors.New("a profile already exists with this name")} } - profileID := handler.DataStore.FDOProfile().GetNextIdentifier() profile := &portainer.FDOProfile{ - ID: portainer.FDOProfileID(profileID), Name: payload.Name, } diff --git a/api/http/handler/hostmanagement/fdo/profile_duplicate.go b/api/http/handler/hostmanagement/fdo/profile_duplicate.go index 35f7a4231..4f327a7b7 100644 --- a/api/http/handler/hostmanagement/fdo/profile_duplicate.go +++ b/api/http/handler/hostmanagement/fdo/profile_duplicate.go @@ -43,13 +43,12 @@ func (handler *Handler) duplicateProfile(w http.ResponseWriter, r *http.Request) return httperror.InternalServerError("Unable to retrieve Profile file content", err) } - profileID := handler.DataStore.FDOProfile().GetNextIdentifier() + // TODO: Looks wrong if err != nil { return httperror.InternalServerError("Unable to duplicate Profile", err) } newProfile := &portainer.FDOProfile{ - ID: portainer.FDOProfileID(profileID), Name: fmt.Sprintf("%s - copy", originalProfile.Name), } diff --git a/api/http/handler/tags/tag_create.go b/api/http/handler/tags/tag_create.go index a4ece0e49..042cf4132 100644 --- a/api/http/handler/tags/tag_create.go +++ b/api/http/handler/tags/tag_create.go @@ -49,10 +49,10 @@ func (handler *Handler) tagCreate(w http.ResponseWriter, r *http.Request) *httpe if featureflags.IsEnabled(portainer.FeatureNoTx) { tag, err = createTag(handler.DataStore, payload) } else { - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - tag, err = createTag(tx, payload) - return err - }) + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // tag, err = createTag(tx, payload) + // return err + // }) } return txResponse(w, tag, err) diff --git a/api/http/handler/tags/tag_delete.go b/api/http/handler/tags/tag_delete.go index 48dffec92..61f3f6f76 100644 --- a/api/http/handler/tags/tag_delete.go +++ b/api/http/handler/tags/tag_delete.go @@ -36,9 +36,9 @@ func (handler *Handler) tagDelete(w http.ResponseWriter, r *http.Request) *httpe if featureflags.IsEnabled(portainer.FeatureNoTx) { err = deleteTag(handler.DataStore, portainer.TagID(id)) } else { - err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { - return deleteTag(tx, portainer.TagID(id)) - }) + // err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error { + // return deleteTag(tx, portainer.TagID(id)) + // }) } if err != nil { diff --git a/api/internal/edge/edgestacks/service.go b/api/internal/edge/edgestacks/service.go index 38e0b6ddd..7420dac41 100644 --- a/api/internal/edge/edgestacks/service.go +++ b/api/internal/edge/edgestacks/service.go @@ -42,9 +42,7 @@ func (service *Service) BuildEdgeStack( return nil, err } - stackID := tx.EdgeStack().GetNextIdentifier() return &portainer.EdgeStack{ - ID: portainer.EdgeStackID(stackID), Name: name, DeploymentType: deploymentType, CreationDate: time.Now().Unix(), diff --git a/api/stacks/stackbuilders/stack_file_content_builder.go b/api/stacks/stackbuilders/stack_file_content_builder.go index e80efdef4..0ede40ee4 100644 --- a/api/stacks/stackbuilders/stack_file_content_builder.go +++ b/api/stacks/stackbuilders/stack_file_content_builder.go @@ -27,8 +27,6 @@ type FileContentMethodStackBuilder struct { } func (b *FileContentMethodStackBuilder) SetGeneralInfo(payload *StackPayload, endpoint *portainer.Endpoint) FileContentMethodStackBuildProcess { - stackID := b.dataStore.Stack().GetNextIdentifier() - b.stack.ID = portainer.StackID(stackID) b.stack.EndpointID = endpoint.ID b.stack.Status = portainer.StackStatusActive b.stack.CreationDate = time.Now().Unix() diff --git a/api/stacks/stackbuilders/stack_file_upload_builder.go b/api/stacks/stackbuilders/stack_file_upload_builder.go index 94a3952b3..0dec78455 100644 --- a/api/stacks/stackbuilders/stack_file_upload_builder.go +++ b/api/stacks/stackbuilders/stack_file_upload_builder.go @@ -28,8 +28,6 @@ type FileUploadMethodStackBuilder struct { } func (b *FileUploadMethodStackBuilder) SetGeneralInfo(payload *StackPayload, endpoint *portainer.Endpoint) FileUploadMethodStackBuildProcess { - stackID := b.dataStore.Stack().GetNextIdentifier() - b.stack.ID = portainer.StackID(stackID) b.stack.EndpointID = endpoint.ID b.stack.Status = portainer.StackStatusActive b.stack.CreationDate = time.Now().Unix() diff --git a/api/stacks/stackbuilders/stack_git_builder.go b/api/stacks/stackbuilders/stack_git_builder.go index ac3ba0cb8..a79f2355e 100644 --- a/api/stacks/stackbuilders/stack_git_builder.go +++ b/api/stacks/stackbuilders/stack_git_builder.go @@ -38,8 +38,6 @@ type GitMethodStackBuilder struct { } func (b *GitMethodStackBuilder) SetGeneralInfo(payload *StackPayload, endpoint *portainer.Endpoint) GitMethodStackBuildProcess { - stackID := b.dataStore.Stack().GetNextIdentifier() - b.stack.ID = portainer.StackID(stackID) b.stack.EndpointID = endpoint.ID b.stack.AdditionalFiles = payload.AdditionalFiles b.stack.Status = portainer.StackStatusActive diff --git a/api/stacks/stackbuilders/stack_url_builder.go b/api/stacks/stackbuilders/stack_url_builder.go index 97753efa2..9c1624a89 100644 --- a/api/stacks/stackbuilders/stack_url_builder.go +++ b/api/stacks/stackbuilders/stack_url_builder.go @@ -27,8 +27,6 @@ type UrlMethodStackBuilder struct { } func (b *UrlMethodStackBuilder) SetGeneralInfo(payload *StackPayload, endpoint *portainer.Endpoint) UrlMethodStackBuildProcess { - stackID := b.dataStore.Stack().GetNextIdentifier() - b.stack.ID = portainer.StackID(stackID) b.stack.EndpointID = endpoint.ID b.stack.Status = portainer.StackStatusActive b.stack.CreationDate = time.Now().Unix() diff --git a/build/build_binary.sh b/build/build_binary.sh index dc17396f9..de9dd3ae8 100755 --- a/build/build_binary.sh +++ b/build/build_binary.sh @@ -33,7 +33,7 @@ BINARY_VERSION_FILE="../binary-version.json" echo "$ldflags" # the build takes 2 seconds -GOOS=${1:-$(go env GOOS)} GOARCH=${2:-$(go env GOARCH)} CGO_ENABLED=0 go build \ +GOOS=${1:-$(go env GOOS)} GOARCH=${2:-$(go env GOARCH)} CGO_ENABLED=1 go build \ -trimpath \ --installsuffix cgo \ --ldflags "$ldflags" \ diff --git a/pkg/featureflags/featureflags_test.go b/pkg/featureflags/featureflags_test.go index 9bfedf90f..4df517232 100644 --- a/pkg/featureflags/featureflags_test.go +++ b/pkg/featureflags/featureflags_test.go @@ -1,75 +1,75 @@ package featureflags -import ( - "os" - "strings" - "testing" +// import ( +// "os" +// "strings" +// "testing" - "github.com/stretchr/testify/assert" -) +// "github.com/stretchr/testify/assert" +// ) -func Test_enableFeaturesFromFlags(t *testing.T) { - is := assert.New(t) +// func Test_enableFeaturesFromFlags(t *testing.T) { +// is := assert.New(t) - supportedFeatures := []Feature{"supported", "supported2", "supported3", "supported4", "supported5"} +// supportedFeatures := []Feature{"supported", "supported2", "supported3", "supported4", "supported5"} - t.Run("supported features should be supported", func(t *testing.T) { - Init(supportedFeatures) +// t.Run("supported features should be supported", func(t *testing.T) { +// Init(supportedFeatures) - for _, featureFlag := range supportedFeatures { - is.True(IsSupported(featureFlag)) - } - }) +// for _, featureFlag := range supportedFeatures { +// is.True(IsSupported(featureFlag)) +// } +// }) - t.Run("unsupported features should not be supported", func(t *testing.T) { - Init(supportedFeatures) +// t.Run("unsupported features should not be supported", func(t *testing.T) { +// Init(supportedFeatures) - is.False(IsSupported("unsupported")) - }) +// is.False(IsSupported("unsupported")) +// }) - tests := []struct { - cliFeatureFlags []string - envFeatureFlags []string - }{ - {[]string{"supported", "supported2"}, []string{"supported3", "supported4"}}, - } +// tests := []struct { +// cliFeatureFlags []string +// envFeatureFlags []string +// }{ +// {[]string{"supported", "supported2"}, []string{"supported3", "supported4"}}, +// } - for _, test := range tests { - Init(supportedFeatures) +// for _, test := range tests { +// Init(supportedFeatures) - os.Unsetenv("PORTAINER_FEATURE_FLAGS") - os.Setenv("PORTAINER_FEATURE_FLAGS", strings.Join(test.envFeatureFlags, ",")) +// os.Unsetenv("PORTAINER_FEATURE_FLAGS") +// os.Setenv("PORTAINER_FEATURE_FLAGS", strings.Join(test.envFeatureFlags, ",")) - t.Run("testing", func(t *testing.T) { - Parse(test.cliFeatureFlags) - supported := toFeatureMap(test.cliFeatureFlags, test.envFeatureFlags) +// t.Run("testing", func(t *testing.T) { +// Parse(test.cliFeatureFlags) +// supported := toFeatureMap(test.cliFeatureFlags, test.envFeatureFlags) - // add env flags to supported flags - for _, featureFlag := range test.envFeatureFlags { - supported[Feature(featureFlag)] = true - } +// // add env flags to supported flags +// for _, featureFlag := range test.envFeatureFlags { +// supported[Feature(featureFlag)] = true +// } - for _, featureFlag := range supportedFeatures { - if _, ok := supported[featureFlag]; ok { - is.True(IsEnabled(featureFlag)) - } else { - is.False(IsEnabled(featureFlag)) - } - } - }) - } -} +// for _, featureFlag := range supportedFeatures { +// if _, ok := supported[featureFlag]; ok { +// is.True(IsEnabled(featureFlag)) +// } else { +// is.False(IsEnabled(featureFlag)) +// } +// } +// }) +// } +// } -// helper -func toFeatureMap(cliFeatures []string, envFeatures []string) map[Feature]bool { - m := map[Feature]bool{} - for _, s := range cliFeatures { - m[Feature(s)] = true - } +// // helper +// func toFeatureMap(cliFeatures []string, envFeatures []string) map[Feature]bool { +// m := map[Feature]bool{} +// for _, s := range cliFeatures { +// m[Feature(s)] = true +// } - for _, s := range envFeatures { - m[Feature(s)] = true - } +// for _, s := range envFeatures { +// m[Feature(s)] = true +// } - return m -} +// return m +// }