mirror of
https://github.com/portainer/portainer.git
synced 2025-08-09 15:55:23 +02:00
WIP: commented error code and set CGO_ENABLED to 1
This commit is contained in:
parent
8fd67d8320
commit
52142c3151
22 changed files with 251 additions and 277 deletions
|
@ -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
|
||||
|
|
|
@ -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=
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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" \
|
||||
|
|
|
@ -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
|
||||
// }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue