mirror of https://github.com/portainer/portainer
#2732 feat(stacks): adding saveComposeStackFromFileContent method
parent
35834c65ea
commit
7268697633
|
@ -130,6 +130,48 @@ func (handler *Handler) createComposeStackFromFileContent(w http.ResponseWriter,
|
|||
return handler.decorateStackResponse(w, stack, userID)
|
||||
}
|
||||
|
||||
// @id StackSaveDockerStandaloneString
|
||||
// @summary Save a new compose stack from a text
|
||||
// @description Deploy a new stack into a Docker environment specified via the environment identifier.
|
||||
// @description **Access policy**: authenticated
|
||||
// @tags stacks
|
||||
// @security ApiKeyAuth
|
||||
// @security jwt
|
||||
// @accept json
|
||||
// @produce json
|
||||
// @param body body composeStackFromFileContentPayload true "stack config"
|
||||
// @param endpointId query int true "Identifier of the environment that will be used to deploy the stack"
|
||||
// @success 200 {object} portainer.Stack
|
||||
// @failure 400 "Invalid request"
|
||||
// @failure 500 "Server error"
|
||||
// @router /stacks/create/standalone/string [post]
|
||||
func (handler *Handler) saveComposeStackFromFileContent(w http.ResponseWriter, r *http.Request, endpoint *portainer.Endpoint, userID portainer.UserID) *httperror.HandlerError {
|
||||
payload, handlerError := handler.getValidatedPayload(w, r, endpoint, userID)
|
||||
if handlerError != nil {
|
||||
return handlerError
|
||||
}
|
||||
|
||||
securityContext, err := security.RetrieveRestrictedRequestContext(r)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve info from request context", err)
|
||||
}
|
||||
|
||||
stackPayload := createStackPayloadFromComposeFileContentPayload(payload.Name, payload.StackFileContent, payload.Env, payload.FromAppTemplate)
|
||||
|
||||
composeStackBuilder := stackbuilders.CreateComposeStackFileContentBuilder(securityContext,
|
||||
handler.DataStore,
|
||||
handler.FileService,
|
||||
handler.StackDeployer)
|
||||
|
||||
stackBuilderDirector := stackbuilders.NewStackBuilderDirector(composeStackBuilder)
|
||||
stack, httpErr := stackBuilderDirector.Save(&stackPayload, endpoint)
|
||||
if httpErr != nil {
|
||||
return httpErr
|
||||
}
|
||||
|
||||
return handler.decorateStackResponse(w, stack, userID)
|
||||
}
|
||||
|
||||
func (handler *Handler) getValidatedPayload(w http.ResponseWriter, r *http.Request, endpoint *portainer.Endpoint, userID portainer.UserID) (*composeStackFromFileContentPayload, *httperror.HandlerError) {
|
||||
var payload composeStackFromFileContentPayload
|
||||
err := request.DecodeAndValidateJSONPayload(r, &payload)
|
||||
|
|
Loading…
Reference in New Issue