Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions command/remote_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/ONSdigital/dp-cli/aws"
"github.com/ONSdigital/dp-cli/cli"
"github.com/ONSdigital/dp-cli/config"
"github.com/ONSdigital/dp-cli/out"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -155,6 +156,7 @@ func remoteAccess(ctx context.Context, cfg *config.Config) *cobra.Command {

cmd.AddCommand(remoteAllowCommand(ctx, cfg))
cmd.AddCommand(remoteDenyCommand(ctx, cfg))
cmd.AddCommand(remoteLoginCommand(ctx, cfg))

return cmd
}
Expand Down Expand Up @@ -276,3 +278,25 @@ func remoteDenyCommand(ctx context.Context, cfg *config.Config) *cobra.Command {
cmd.AddCommand(envSubCmds...)
return cmd
}

// remoteLoginCommand creates the login subcommand for remote
func remoteLoginCommand(ctx context.Context, cfg *config.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Short: "login to AWS environment",
}

if len(cfg.Environments) > 0 {
firstEnv := cfg.Environments[0]
cmd.RunE = func(cmd *cobra.Command, args []string) error {
lvl := out.GetLevel(firstEnv)
loginCmd := "aws sso login --profile " + cfg.GetProfile(firstEnv.Name)
out.Highlight(lvl, "logging in to %s using %s", firstEnv.Name, loginCmd)
return cli.ExecCommand(ctx, loginCmd, ".")
}
} else {
out.WarnFHighlight("Warning: No environments found in config - `dp remote login` will not work")
}

return cmd
}