Skip to content
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
2 changes: 1 addition & 1 deletion .docker/Dockerfile-build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-alpine3.19 AS builder
FROM golang:1.22-alpine3.19 AS builder

RUN apk -U --no-cache add build-base git gcc bash

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: ory/ci/checkout@master
- uses: actions/setup-go@v2
with:
go-version: "1.21"
go-version: "1.22"
- run: |
make test
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.21
go-version: 1.22
- run: make format
- name: Indicate formatting issues
run: git diff HEAD --exit-code --color
2 changes: 1 addition & 1 deletion .github/workflows/licenses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.21"
go-version: "1.22"
- uses: actions/setup-node@v2
with:
node-version: "18"
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "^1.21"
go-version: "1.22"
- uses: actions/setup-node@v2
with:
node-version: "16"
- run: |
go build -o ory .
./ory tunnel http://localhost:4001 --project admiring-tu-swczqlujc0 --quiet &
./ory tunnel http://localhost:4001 --quiet &
env:
ORY_API_KEY: ${{ secrets.ORY_PROJECT_API_KEY }}
- name: Install dependencies and run server
ORY_PROJECT_SLUG: admiring-tu-swczqlujc0
- name: Install dependencies
working-directory: cmd/cloudx/e2e
run: |
npm ci
Expand Down Expand Up @@ -53,15 +54,16 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "^1.21"
go-version: "1.22"
- uses: actions/setup-node@v2
with:
node-version: "16"
- run: |
go build -o ory .
./ory proxy https://ory-network-httpbin-ijakee5waq-ez.a.run.app/anything --rewrite-host --project admiring-tu-swczqlujc0 --quiet &
./ory proxy https://ory-network-httpbin-ijakee5waq-ez.a.run.app/anything --rewrite-host --quiet &
env:
ORY_API_KEY: ${{ secrets.ORY_PROJECT_API_KEY }}
ORY_PROJECT_SLUG: admiring-tu-swczqlujc0
- name: Install Node
working-directory: cmd/cloudx/e2e
run: |
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "^1.21"
go-version: "1.22"
- uses: actions/setup-node@v2
with:
node-version: "16"
- run: npm ci
- run: go build -o ory .
- run: |
go build -o ory .
./ory proxy https://ory-network-httpbin-ijakee5waq-ez.a.run.app --quiet --rewrite-host &
npm run test
env:
ORY_SDK_URL: https://affectionate-archimedes-s9mkjq77k0.projects.staging.oryapis.dev
ORY_CLOUD_CONSOLE_URL: https://console.staging.ory.dev
ORY_CLOUD_ORYAPIS_URL: https://staging.oryapis.dev
ORY_API_KEY: nokey
ORY_PROJECT_SLUG: affectionate-archimedes-s9mkjq77k0
ORY_CONSOLE_URL: https://console.staging.ory.dev
ORY_ORYAPIS_URL: https://projects.staging.oryapis.dev
ORY_RATE_LIMIT_HEADER: ${{ secrets.ORY_RATE_LIMIT_HEADER }}
78 changes: 36 additions & 42 deletions cmd/cloudx/accountexperience/accountexperience.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,59 @@ package accountexperience

import (
"fmt"
"os"

"os/exec"
"path"

"github.com/pkg/browser"
"github.com/pkg/errors"
"github.com/spf13/cobra"

client "github.com/ory/cli/cmd/cloudx/client"
cloud "github.com/ory/client-go"
"github.com/ory/x/flagx"
"github.com/ory/x/stringsx"

"github.com/ory/cli/cmd/cloudx/client"
"github.com/ory/x/cmdx"
)

func NewAccountExperienceOpenCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "account-experience [project-id]",
Args: cobra.MaximumNArgs(1),
Use: "account-experience <login|registration|recovery|verification|settings>",
Aliases: []string{"ax", "ui"},
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return err
}
switch f := stringsx.SwitchExact(args[0]); {
case f.AddCase("login", "registration", "recovery", "verification", "settings"):
return nil
default:
return errors.Wrap(f.ToUnknownCaseErr(), "unknown flow type")
}
},
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)
h, err := client.NewCobraCommandHelper(cmd)
if err != nil {
return err
}
id, err := getSelectedProjectId(h, args)
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
project, err := h.GetProject(id)

project, err := h.GetSelectedProject(cmd.Context())
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())
}
url := client.CloudAPIsURL(project.Slug)
url.Path = path.Join(url.Path, "ui", args[0])
if flagx.MustGetBool(cmd, cmdx.FlagQuiet) {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s\n", url)
return nil
}
if err := browser.OpenURL(url.String()); err != nil {
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%s\n\nUnable to automatically open %s in your browser. Please open it manually!\n", err, url)
return cmdx.FailSilently(cmd)
}
return nil
},
}

return nil
cmdx.RegisterNoiseFlags(cmd.Flags())
return cmd
}
29 changes: 18 additions & 11 deletions cmd/cloudx/accountexperience/accountexperience_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,35 @@ package accountexperience_test
import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"

"github.com/ory/cli/cmd/cloudx/testhelpers"
"github.com/ory/x/cmdx"
)

var (
defaultProject, defaultConfig, defaultEmail, defaultPassword string
defaultCmd *cmdx.CommandExecuter
)

func TestMain(m *testing.M) {
defaultConfig, defaultEmail, defaultPassword, _, defaultProject, defaultCmd = testhelpers.CreateDefaultAssets()
testhelpers.RunAgainstStaging(m)
}

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 {
_, stderr, err := defaultCmd.Exec(nil, "open", "account-experience", p, "--project", defaultProject)
cfg := testhelpers.NewConfigFile(t)
testhelpers.RegisterAccount(t, cfg)
project := testhelpers.CreateProject(t, cfg, nil)
cmd := testhelpers.CmdWithConfig(cfg)

t.Run("is able to open all pages", func(t *testing.T) {
for _, flowType := range []string{"login", "registration", "recovery", "verification", "settings"} {
stdout, stderr, err := cmd.Exec(nil, "open", "account-experience", flowType, "--quiet")
require.NoError(t, err, stderr)
assert.Contains(t, stdout, "https://"+project.Slug)
assert.Contains(t, stdout, flowType)
}
})

t.Run("errors on unknown flow type", func(t *testing.T) {
stdout, stderr, err := cmd.Exec(nil, "open", "account-experience", "unknown", "--quiet")
require.Error(t, err)
assert.Contains(t, stderr, "unknown flow type", stdout)
})
}
24 changes: 0 additions & 24 deletions cmd/cloudx/accountexperience/utils.go

This file was deleted.

6 changes: 4 additions & 2 deletions cmd/cloudx/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ func NewAuthCmd() *cobra.Command {
Use: "auth",
Short: "Create a new Ory Network account or sign in to an existing account.",
RunE: func(cmd *cobra.Command, args []string) error {
h, err := client.NewCommandHelper(cmd)
h, err := client.NewCobraCommandHelper(cmd)
if err != nil {
return err
}
ac, err := h.Authenticate()

ac, err := h.GetAuthenticatedConfig(cmd.Context())
if err != nil {
return err
}

cmdx.PrintRow(cmd, ac)
return nil
},
Expand Down
Loading