Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add open ax pages #295

Merged
merged 23 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: abhi1693/setup-browser@v0.3.4
with:
browser: chrome
version: latest
- uses: ory/ci/checkout@master
- uses: actions/setup-go@v2
with:
Expand Down
69 changes: 69 additions & 0 deletions cmd/cloudx/accountexperience/accountexperience.go
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
}
26 changes: 26 additions & 0 deletions cmd/cloudx/accountexperience/accountexperience_test.go
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)
}
})

}
24 changes: 24 additions & 0 deletions cmd/cloudx/accountexperience/utils.go
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
}
}
26 changes: 26 additions & 0 deletions cmd/cloudx/open.go
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
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewRootCmd() *cobra.Command {
cloudx.NewUseCmd(),
cloudx.NewListCmd(),
cloudx.NewImportCmd(),
cloudx.NewOpenCmd(),
cloudx.NewPatchCmd(),
cloudx.NewParseCmd(),
cloudx.NewPerformCmd(),
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ require (
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/philhofer/fwd v1.1.1 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/profile v1.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/cachecontrol v0.1.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,8 @@ github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -1940,6 +1942,7 @@ golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down