-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
154 additions
and
0 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
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,69 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package accountexperience | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"os/exec" | ||
|
||
"github.com/pkg/browser" | ||
"github.com/spf13/cobra" | ||
|
||
client "github.com/ory/cli/cmd/cloudx/client" | ||
cloud "github.com/ory/client-go" | ||
"github.com/ory/x/cmdx" | ||
) | ||
|
||
func NewAccountExperienceOpenCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "account-experience [project-id]", | ||
Args: cobra.MaximumNArgs(1), | ||
Short: "Open Ory Account Experience Pages", | ||
} | ||
var pages = [5]string{"login", "registration", "recovery", "verification", "settings"} | ||
for _, p := range pages { | ||
cmd.AddCommand(NewAxCmd(p)) | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func NewAxCmd(cmd string) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: cmd, | ||
Short: "Open " + cmd + " page", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
h, err := client.NewCommandHelper(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
id, err := getSelectedProjectId(h, args) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
project, err := h.GetProject(id) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
return AxWrapper(cmd, project) | ||
|
||
}} | ||
} | ||
|
||
func AxWrapper(cmd *cobra.Command, p *cloud.Project) error { | ||
url := fmt.Sprintf("https://%s.projects.oryapis.com/ui/%s", p.GetSlug(), cmd.CalledAs()) | ||
|
||
err := browser.OpenURL(url) | ||
if err != nil { | ||
|
||
// #nosec G204 - this is ok | ||
if err := exec.Command("open", url); err != nil { | ||
_, _ = fmt.Fprintf(os.Stderr, "Unable to automatically open the %s page in your browser. Please open it manually!", cmd.CalledAs()) | ||
} | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package accountexperience_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ory/cli/cmd/cloudx/testhelpers" | ||
) | ||
|
||
var _, _, _, _, defaultProject, defaultCmd = testhelpers.CreateDefaultAssets() | ||
|
||
func TestOpenAXPages(t *testing.T) { | ||
|
||
t.Run("is able to open login page", func(t *testing.T) { | ||
var pages = [5]string{"login", "registration", "recovery", "verification", "settings"} | ||
for _, p := range pages { | ||
_, _, err := defaultCmd.Exec(nil, "open", "account-experience", p, "--project", defaultProject) | ||
require.NoError(t, err) | ||
} | ||
}) | ||
|
||
} |
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,24 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package accountexperience | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
"github.com/ory/cli/cmd/cloudx/client" | ||
) | ||
|
||
var defaultProjectNotSetError = errors.New("no project was specified") | ||
|
||
func getSelectedProjectId(h *client.CommandHelper, args []string) (string, error) { | ||
if len(args) == 0 { | ||
if id := h.GetDefaultProjectID(); id == "" { | ||
return "", defaultProjectNotSetError | ||
} else { | ||
return id, nil | ||
} | ||
} else { | ||
return args[0], 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cloudx | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/cli/cmd/cloudx/accountexperience" | ||
"github.com/ory/cli/cmd/cloudx/client" | ||
"github.com/ory/x/cmdx" | ||
) | ||
|
||
func NewOpenCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "open", | ||
Short: "Open Ory Account Experience Pages", | ||
} | ||
cmd.AddCommand(accountexperience.NewAccountExperienceOpenCmd()) | ||
client.RegisterProjectFlag(cmd.PersistentFlags()) | ||
client.RegisterConfigFlag(cmd.PersistentFlags()) | ||
cmdx.RegisterNoiseFlags(cmd.PersistentFlags()) | ||
client.RegisterYesFlag(cmd.PersistentFlags()) | ||
|
||
return cmd | ||
} |
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