Skip to content

Commit

Permalink
add support for magento 2.4.6+ --disable-tfa
Browse files Browse the repository at this point in the history
  • Loading branch information
janosmiko committed Mar 20, 2023
1 parent 7e0066b commit 655b74c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.6] - 2023-03-20

### Added

- Above Magento 2.4.6 when you run `reward bootstrap` with `--disable-tfa` flag Reward will also disable Adobe IMS.

## [0.4.5] - 2023-03-08

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.5
v0.4.6
42 changes: 31 additions & 11 deletions internal/logic/bootstrapMagento2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ import (

// bootstrapMagento2 runs a full Magento 2 bootstrap process.
func (c *bootstrapper) bootstrapMagento2() error {
if !util.AskForConfirmation(fmt.Sprintf("Would you like to bootstrap Magento v%s?",
c.magento2Version().String())) {
if !util.AskForConfirmation(
fmt.Sprintf(
"Would you like to bootstrap Magento v%s?",
c.magento2Version().String(),
),
) {
return nil
}

Expand Down Expand Up @@ -148,8 +152,12 @@ func (c *bootstrapper) installMagento2(freshInstall bool) (string, error) {
func (c *bootstrapper) installMagento2SetupInstall() error {
log.Println("Running Magento setup:install...")

err := c.RunCmdEnvExec(fmt.Sprintf("bin/magento setup:install %s",
strings.Join(c.buildMagento2InstallCommand(), " ")))
err := c.RunCmdEnvExec(
fmt.Sprintf(
"bin/magento setup:install %s",
strings.Join(c.buildMagento2InstallCommand(), " "),
),
)
if err != nil {
return fmt.Errorf("cannot run bin/magento setup:install: %w", err)
}
Expand Down Expand Up @@ -252,12 +260,20 @@ func (c *bootstrapper) installMagento2ConfigureAdminUser() (string, error) {
func (c *bootstrapper) installMagento2ConfigureTFA() error {
minimumMagentoVersionForMFA := version.Must(version.NewVersion("2.4.0"))

// For Magento 2.4.6 and above, we need to disable the Adobe IMS module as well
minimumMagentoVersionForMFAAdminAdobeImsTwoFactorAuth := version.Must(version.NewVersion("2.4.6"))

if c.magento2Version().GreaterThan(minimumMagentoVersionForMFA) && c.MagentoDisableTFA() {
log.Println("Disabling TFA for local development...")

err := c.RunCmdEnvExec("bin/magento module:disable Magento_TwoFactorAuth")
modules := "Magento_TwoFactorAuth"
if c.magento2Version().GreaterThanOrEqual(minimumMagentoVersionForMFAAdminAdobeImsTwoFactorAuth) {
modules += " Magento_AdminAdobeImsTwoFactorAuth"
}

err := c.RunCmdEnvExec("bin/magento module:disable " + modules)
if err != nil {
return fmt.Errorf("cannot run bin/magento module:disable Magento_TwoFactorAuth: %w", err)
return fmt.Errorf("cannot run bin/magento module:disable %v: %w", modules, err)
}

log.Println("...TFA disabled.")
Expand All @@ -270,8 +286,9 @@ func (c *bootstrapper) installMagento2DeploySampleData(freshInstall bool) error
if freshInstall && (c.WithSampleData() || c.FullBootstrap()) {
log.Println("Installing sample data...")

err := c.RunCmdEnvExec("mkdir -p /var/www/html/var/composer_home/ && " +
"cp -va ~/.composer/auth.json /var/www/html/var/composer_home/auth.json",
err := c.RunCmdEnvExec(
"mkdir -p /var/www/html/var/composer_home/ && " +
"cp -va ~/.composer/auth.json /var/www/html/var/composer_home/auth.json",
)
if err != nil {
return fmt.Errorf("cannot copy auth.json: %w", err)
Expand Down Expand Up @@ -316,7 +333,8 @@ func (c *bootstrapper) installMagento2ConfigureSearch() error {

if c.magento2Version().GreaterThan(c.minimumMagento2VersionForSearch()) {
err = c.RunCmdEnvExec(
fmt.Sprintf("bin/magento config:set --lock-env catalog/search/engine %s",
fmt.Sprintf(
"bin/magento config:set --lock-env catalog/search/engine %s",
searchEngine,
),
)
Expand Down Expand Up @@ -474,7 +492,8 @@ func (c *bootstrapper) buildMagento2InstallCommand() []string {

// Redis configuration
if c.ServiceEnabled("redis") {
magentoCmdParams = append(magentoCmdParams,
magentoCmdParams = append(
magentoCmdParams,
"--session-save=redis",
"--session-save-redis-host=redis",
"--session-save-redis-port=6379",
Expand All @@ -500,7 +519,8 @@ func (c *bootstrapper) buildMagento2InstallCommand() []string {

// RabbitMQ configuration
if c.ServiceEnabled("rabbitmq") {
magentoCmdParams = append(magentoCmdParams,
magentoCmdParams = append(
magentoCmdParams,
"--amqp-host=rabbitmq",
"--amqp-port=5672",
"--amqp-user=guest",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sonar.organization=rewardenv

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=reward
sonar.projectVersion=0.4.5
sonar.projectVersion=0.4.6

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.
Expand Down

0 comments on commit 655b74c

Please sign in to comment.