mirror of https://github.com/portainer/portainer
fix(edge/jobs): fix get edge job file content [EE-2702] (#6622)
parent
b846c8e6d2
commit
8860d72f70
|
@ -67,14 +67,14 @@ func (service *Service) EdgeJob(ID portainer.EdgeJobID) (*portainer.EdgeJob, err
|
||||||
return &edgeJob, nil
|
return &edgeJob, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateEdgeJob creates a new Edge job
|
// Create creates a new EdgeJob
|
||||||
func (service *Service) Create(edgeJob *portainer.EdgeJob) error {
|
func (service *Service) Create(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error {
|
||||||
return service.connection.CreateObject(
|
edgeJob.ID = ID
|
||||||
|
|
||||||
|
return service.connection.CreateObjectWithId(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
int(edgeJob.ID),
|
||||||
edgeJob.ID = portainer.EdgeJobID(id)
|
edgeJob,
|
||||||
return int(edgeJob.ID), edgeJob
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ type (
|
||||||
EdgeJobService interface {
|
EdgeJobService interface {
|
||||||
EdgeJobs() ([]portainer.EdgeJob, error)
|
EdgeJobs() ([]portainer.EdgeJob, error)
|
||||||
EdgeJob(ID portainer.EdgeJobID) (*portainer.EdgeJob, error)
|
EdgeJob(ID portainer.EdgeJobID) (*portainer.EdgeJob, error)
|
||||||
Create(edgeJob *portainer.EdgeJob) error
|
Create(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error
|
||||||
UpdateEdgeJob(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error
|
UpdateEdgeJob(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error
|
||||||
DeleteEdgeJob(ID portainer.EdgeJobID) error
|
DeleteEdgeJob(ID portainer.EdgeJobID) error
|
||||||
GetNextIdentifier() int
|
GetNextIdentifier() int
|
||||||
|
|
|
@ -219,7 +219,7 @@ func (handler *Handler) addAndPersistEdgeJob(edgeJob *portainer.EdgeJob, file []
|
||||||
handler.ReverseTunnelService.AddEdgeJob(endpointID, edgeJob)
|
handler.ReverseTunnelService.AddEdgeJob(endpointID, edgeJob)
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler.DataStore.EdgeJob().Create(edgeJob)
|
return handler.DataStore.EdgeJob().Create(edgeJob.ID, edgeJob)
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertEndpointsToMetaObject(endpoints []portainer.EndpointID) map[portainer.EndpointID]portainer.EdgeJobEndpointMeta {
|
func convertEndpointsToMetaObject(endpoints []portainer.EndpointID) map[portainer.EndpointID]portainer.EdgeJobEndpointMeta {
|
||||||
|
|
|
@ -39,7 +39,7 @@ func (handler *Handler) edgeJobFile(w http.ResponseWriter, r *http.Request) *htt
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an Edge job with the specified identifier inside the database", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an Edge job with the specified identifier inside the database", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeJobFileContent, err := handler.FileService.GetFileContent("", edgeJob.ScriptPath)
|
edgeJobFileContent, err := handler.FileService.GetFileContent(edgeJob.ScriptPath, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge job script file from disk", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge job script file from disk", err}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ func (handler *Handler) endpointStatusInspect(w http.ResponseWriter, r *http.Req
|
||||||
Version: job.Version,
|
Version: job.Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := handler.FileService.GetFileContent("", job.ScriptPath)
|
file, err := handler.FileService.GetFileContent(job.ScriptPath, "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge job script file", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge job script file", err}
|
||||||
|
|
|
@ -153,7 +153,9 @@ func (s *stubEdgeJobService) EdgeJobs() ([]portainer.EdgeJob, error) { return s.
|
||||||
func (s *stubEdgeJobService) EdgeJob(ID portainer.EdgeJobID) (*portainer.EdgeJob, error) {
|
func (s *stubEdgeJobService) EdgeJob(ID portainer.EdgeJobID) (*portainer.EdgeJob, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
func (s *stubEdgeJobService) Create(edgeJob *portainer.EdgeJob) error { return nil }
|
func (s *stubEdgeJobService) Create(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (s *stubEdgeJobService) UpdateEdgeJob(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error {
|
func (s *stubEdgeJobService) UpdateEdgeJob(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ export class EdgeJobController {
|
||||||
}
|
}
|
||||||
|
|
||||||
async uiCanExit() {
|
async uiCanExit() {
|
||||||
if (this.edgeJob.FileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
if (this.edgeJob && this.edgeJob.FileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
||||||
return this.ModalService.confirmWebEditorDiscard();
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ export class EdgeJobController {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$window.onbeforeunload = () => {
|
this.$window.onbeforeunload = () => {
|
||||||
if (this.edgeJob.FileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
if (this.edgeJob && this.edgeJob.FileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue