2022-10-05 09:33:59 +00:00
package stackbuilders
import (
"errors"
portainer "github.com/portainer/portainer/api"
2023-09-01 22:27:02 +00:00
httperror "github.com/portainer/portainer/pkg/libhttp/error"
"github.com/portainer/portainer/pkg/libhttp/request"
2022-10-05 09:33:59 +00:00
)
type StackBuilderDirector struct {
builder interface { }
}
func NewStackBuilderDirector ( b interface { } ) * StackBuilderDirector {
return & StackBuilderDirector {
builder : b ,
}
}
func ( d * StackBuilderDirector ) Build ( payload * StackPayload , endpoint * portainer . Endpoint ) ( * portainer . Stack , * httperror . HandlerError ) {
switch builder := d . builder . ( type ) {
case GitMethodStackBuildProcess :
return builder . SetGeneralInfo ( payload , endpoint ) .
SetUniqueInfo ( payload ) .
SetGitRepository ( payload ) .
Deploy ( payload , endpoint ) .
SetAutoUpdate ( payload ) .
SaveStack ( )
case FileUploadMethodStackBuildProcess :
return builder . SetGeneralInfo ( payload , endpoint ) .
SetUniqueInfo ( payload ) .
SetUploadedFile ( payload ) .
Deploy ( payload , endpoint ) .
SaveStack ( )
case FileContentMethodStackBuildProcess :
return builder . SetGeneralInfo ( payload , endpoint ) .
SetUniqueInfo ( payload ) .
SetFileContent ( payload ) .
Deploy ( payload , endpoint ) .
SaveStack ( )
case UrlMethodStackBuildProcess :
return builder . SetGeneralInfo ( payload , endpoint ) .
SetUniqueInfo ( payload ) .
SetURL ( payload ) .
Deploy ( payload , endpoint ) .
SaveStack ( )
}
return nil , httperror . BadRequest ( "Invalid value for query parameter: method. Value must be one of: string or repository or url or file" , errors . New ( request . ErrInvalidQueryParameter ) )
}