Compare commits
2 Commits
fix/EE-145
...
poc-orphan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5588f42504 | ||
|
|
4ce19ff818 |
@@ -15,7 +15,7 @@ type stackFileResponse struct {
|
||||
StackFileContent string `json:"StackFileContent"`
|
||||
}
|
||||
|
||||
// GET request on /api/stacks/:id/file
|
||||
// GET request on /api/stacks/:id/file?endpointId=<endpointId>
|
||||
func (handler *Handler) stackFile(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
||||
if err != nil {
|
||||
@@ -29,7 +29,16 @@ func (handler *Handler) stackFile(w http.ResponseWriter, r *http.Request) *httpe
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a stack with the specified identifier inside the database", err}
|
||||
}
|
||||
|
||||
endpoint, err := handler.DataStore.Endpoint().Endpoint(stack.EndpointID)
|
||||
endpointID, err := request.RetrieveNumericQueryParameter(r, "endpointId", true)
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
|
||||
}
|
||||
endpointIdentifier := stack.EndpointID
|
||||
if endpointID != 0 {
|
||||
endpointIdentifier = portainer.EndpointID(endpointID)
|
||||
}
|
||||
|
||||
endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointIdentifier)
|
||||
if err == portainer.ErrObjectNotFound {
|
||||
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
|
||||
} else if err != nil {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
)
|
||||
|
||||
// GET request on /api/stacks/:id
|
||||
// GET request on /api/stacks/:id?endpointId=<endpointId>
|
||||
func (handler *Handler) stackInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
||||
if err != nil {
|
||||
@@ -24,7 +24,16 @@ func (handler *Handler) stackInspect(w http.ResponseWriter, r *http.Request) *ht
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a stack with the specified identifier inside the database", err}
|
||||
}
|
||||
|
||||
endpoint, err := handler.DataStore.Endpoint().Endpoint(stack.EndpointID)
|
||||
endpointID, err := request.RetrieveNumericQueryParameter(r, "endpointId", true)
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
|
||||
}
|
||||
endpointIdentifier := stack.EndpointID
|
||||
if endpointID != 0 {
|
||||
endpointIdentifier = portainer.EndpointID(endpointID)
|
||||
}
|
||||
|
||||
endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointIdentifier)
|
||||
if err == portainer.ErrObjectNotFound {
|
||||
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
|
||||
} else if err != nil {
|
||||
|
||||
@@ -59,11 +59,12 @@ func (handler *Handler) stackUpdate(w http.ResponseWriter, r *http.Request) *htt
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
|
||||
}
|
||||
if endpointID != int(stack.EndpointID) {
|
||||
stack.EndpointID = portainer.EndpointID(endpointID)
|
||||
endpointIdentifier := stack.EndpointID
|
||||
if endpointID != 0 {
|
||||
endpointIdentifier = portainer.EndpointID(endpointID)
|
||||
}
|
||||
|
||||
endpoint, err := handler.DataStore.Endpoint().Endpoint(stack.EndpointID)
|
||||
endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointIdentifier)
|
||||
if err == portainer.ErrObjectNotFound {
|
||||
return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err}
|
||||
} else if err != nil {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import _ from 'lodash-es';
|
||||
import { StackViewModel, ExternalStackViewModel } from '../../models/stack';
|
||||
import { ExternalStackViewModel, StackViewModel } from '../../models/stack';
|
||||
|
||||
angular.module('portainer.app').factory('StackService', [
|
||||
'$q',
|
||||
@@ -15,10 +15,10 @@ angular.module('portainer.app').factory('StackService', [
|
||||
'use strict';
|
||||
var service = {};
|
||||
|
||||
service.stack = function (id) {
|
||||
service.stack = function (id, endpointId) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
Stack.get({ id: id })
|
||||
Stack.get({ id: id, endpointId: endpointId })
|
||||
.$promise.then(function success(data) {
|
||||
var stack = new StackViewModel(data);
|
||||
deferred.resolve(stack);
|
||||
@@ -30,10 +30,10 @@ angular.module('portainer.app').factory('StackService', [
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.getStackFile = function (id) {
|
||||
service.getStackFile = function (id, endpointId) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
Stack.getStackFile({ id: id })
|
||||
Stack.getStackFile({ id: id, endpointId: endpointId })
|
||||
.$promise.then(function success(data) {
|
||||
deferred.resolve(data.StackFileContent);
|
||||
})
|
||||
|
||||
@@ -151,15 +151,7 @@ angular.module('portainer.app').controller('StackController', [
|
||||
var env = FormHelper.removeInvalidEnvVars($scope.stack.Env);
|
||||
var prune = $scope.formValues.Prune;
|
||||
var stack = $scope.stack;
|
||||
|
||||
// TODO: this is a work-around for stacks created with Portainer version >= 1.17.1
|
||||
// The EndpointID property is not available for these stacks, we can pass
|
||||
// the current endpoint identifier as a part of the update request. It will be used if
|
||||
// the EndpointID property is not defined on the stack.
|
||||
var endpointId = EndpointProvider.endpointID();
|
||||
if (stack.EndpointId === 0) {
|
||||
stack.EndpointId = endpointId;
|
||||
}
|
||||
stack.EndpointId = EndpointProvider.endpointID();
|
||||
|
||||
$scope.state.actionInProgress = true;
|
||||
StackService.updateStack(stack, stackFile, env, prune)
|
||||
@@ -199,7 +191,7 @@ angular.module('portainer.app').controller('StackController', [
|
||||
});
|
||||
|
||||
$q.all({
|
||||
stack: StackService.stack(id),
|
||||
stack: StackService.stack(id, EndpointProvider.endpointID()),
|
||||
groups: GroupService.groups(),
|
||||
})
|
||||
.then(function success(data) {
|
||||
@@ -208,7 +200,7 @@ angular.module('portainer.app').controller('StackController', [
|
||||
$scope.stack = stack;
|
||||
|
||||
return $q.all({
|
||||
stackFile: StackService.getStackFile(id),
|
||||
stackFile: StackService.getStackFile(id, EndpointProvider.endpointID()),
|
||||
resources: stack.Type === 1 ? retrieveSwarmStackResources(stack.Name, agentProxy) : retrieveComposeStackResources(stack.Name),
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user