-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add admin-console reset-password command (#1345)
* feat: add admin-console reset-password command add a new command to reset the admin console password. * chore: add step to reset admin console password adds a step to our single node installation test to reset the admin console password and to login once more.
- Loading branch information
1 parent
dc8f153
commit a581c4f
Showing
9 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/replicatedhq/embedded-cluster/pkg/defaults" | ||
"github.com/replicatedhq/embedded-cluster/pkg/kotscli" | ||
) | ||
|
||
func adminConsoleCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "admin-console", | ||
Usage: fmt.Sprintf("Manage the %s Admin Console", defaults.BinaryName()), | ||
Subcommands: []*cli.Command{ | ||
adminConsoleResetPassswordCommand(), | ||
}, | ||
} | ||
} | ||
|
||
func adminConsoleResetPassswordCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "reset-password", | ||
Usage: "Reset the Admin Console password", | ||
Before: func(c *cli.Context) error { | ||
if os.Getuid() != 0 { | ||
return fmt.Errorf("reset-password command must be run as root") | ||
} | ||
if len(c.Args().Slice()) != 1 { | ||
return fmt.Errorf("expected admin console password as argument") | ||
} | ||
return nil | ||
}, | ||
Action: func(c *cli.Context) error { | ||
provider, err := getProviderFromCluster(c.Context) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
password := c.Args().Get(0) | ||
if !validateAdminConsolePassword(password, password) { | ||
return ErrNothingElseToAdd | ||
} | ||
|
||
if err := kotscli.ResetPassword(provider, password); err != nil { | ||
return err | ||
} | ||
|
||
logrus.Info("Admin Console password reset successfully") | ||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { login } from '../shared'; | ||
|
||
test('login with custom password', async ({ page }) => { | ||
test.setTimeout(30 * 1000); // 30 seconds | ||
await login(page, process.env.ADMIN_CONSOLE_PASSWORD); | ||
await expect(page.locator('.NavItem').getByText('Cluster Management')).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export const login = async (page) => { | ||
export const login = async (page, password = 'password') => { | ||
await page.goto('/'); | ||
await page.getByPlaceholder('password').click(); | ||
await page.getByPlaceholder('password').fill('password'); | ||
await page.getByPlaceholder('password').fill(password); | ||
await page.getByRole('button', { name: 'Log in' }).click(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters