Compare commits
2 Commits
test-versi
...
poc-orphan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5588f42504 | ||
|
|
4ce19ff818 |
@@ -15,7 +15,7 @@ type stackFileResponse struct {
|
|||||||
StackFileContent string `json:"StackFileContent"`
|
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 {
|
func (handler *Handler) stackFile(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||||
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
||||||
if err != nil {
|
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}
|
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 {
|
if err == portainer.ErrObjectNotFound {
|
||||||
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
|
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/portainer/portainer/api/http/security"
|
"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 {
|
func (handler *Handler) stackInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||||
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
||||||
if err != nil {
|
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}
|
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 {
|
if err == portainer.ErrObjectNotFound {
|
||||||
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
|
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|||||||
@@ -59,11 +59,12 @@ func (handler *Handler) stackUpdate(w http.ResponseWriter, r *http.Request) *htt
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
|
||||||
}
|
}
|
||||||
if endpointID != int(stack.EndpointID) {
|
endpointIdentifier := stack.EndpointID
|
||||||
stack.EndpointID = portainer.EndpointID(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 {
|
if err == portainer.ErrObjectNotFound {
|
||||||
return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err}
|
return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import { StackViewModel, ExternalStackViewModel } from '../../models/stack';
|
import { ExternalStackViewModel, StackViewModel } from '../../models/stack';
|
||||||
|
|
||||||
angular.module('portainer.app').factory('StackService', [
|
angular.module('portainer.app').factory('StackService', [
|
||||||
'$q',
|
'$q',
|
||||||
@@ -15,10 +15,10 @@ angular.module('portainer.app').factory('StackService', [
|
|||||||
'use strict';
|
'use strict';
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
service.stack = function (id) {
|
service.stack = function (id, endpointId) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
Stack.get({ id: id })
|
Stack.get({ id: id, endpointId: endpointId })
|
||||||
.$promise.then(function success(data) {
|
.$promise.then(function success(data) {
|
||||||
var stack = new StackViewModel(data);
|
var stack = new StackViewModel(data);
|
||||||
deferred.resolve(stack);
|
deferred.resolve(stack);
|
||||||
@@ -30,10 +30,10 @@ angular.module('portainer.app').factory('StackService', [
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
service.getStackFile = function (id) {
|
service.getStackFile = function (id, endpointId) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
Stack.getStackFile({ id: id })
|
Stack.getStackFile({ id: id, endpointId: endpointId })
|
||||||
.$promise.then(function success(data) {
|
.$promise.then(function success(data) {
|
||||||
deferred.resolve(data.StackFileContent);
|
deferred.resolve(data.StackFileContent);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -151,15 +151,7 @@ angular.module('portainer.app').controller('StackController', [
|
|||||||
var env = FormHelper.removeInvalidEnvVars($scope.stack.Env);
|
var env = FormHelper.removeInvalidEnvVars($scope.stack.Env);
|
||||||
var prune = $scope.formValues.Prune;
|
var prune = $scope.formValues.Prune;
|
||||||
var stack = $scope.stack;
|
var stack = $scope.stack;
|
||||||
|
stack.EndpointId = EndpointProvider.endpointID();
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.state.actionInProgress = true;
|
$scope.state.actionInProgress = true;
|
||||||
StackService.updateStack(stack, stackFile, env, prune)
|
StackService.updateStack(stack, stackFile, env, prune)
|
||||||
@@ -199,7 +191,7 @@ angular.module('portainer.app').controller('StackController', [
|
|||||||
});
|
});
|
||||||
|
|
||||||
$q.all({
|
$q.all({
|
||||||
stack: StackService.stack(id),
|
stack: StackService.stack(id, EndpointProvider.endpointID()),
|
||||||
groups: GroupService.groups(),
|
groups: GroupService.groups(),
|
||||||
})
|
})
|
||||||
.then(function success(data) {
|
.then(function success(data) {
|
||||||
@@ -208,7 +200,7 @@ angular.module('portainer.app').controller('StackController', [
|
|||||||
$scope.stack = stack;
|
$scope.stack = stack;
|
||||||
|
|
||||||
return $q.all({
|
return $q.all({
|
||||||
stackFile: StackService.getStackFile(id),
|
stackFile: StackService.getStackFile(id, EndpointProvider.endpointID()),
|
||||||
resources: stack.Type === 1 ? retrieveSwarmStackResources(stack.Name, agentProxy) : retrieveComposeStackResources(stack.Name),
|
resources: stack.Type === 1 ? retrieveSwarmStackResources(stack.Name, agentProxy) : retrieveComposeStackResources(stack.Name),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user