",
26 | Args: cobra.ExactArgs(1),
27 | Short: "Render a Markdown file",
28 | Run: func(cmd *cobra.Command, args []string) {
29 | changelogRaw, err := os.ReadFile(args[0])
30 | pkg.Check(err)
31 |
32 | fmt.Println(renderMarkdown(changelogRaw))
33 | },
34 | }
35 |
36 | func renderMarkdown(source []byte) template.HTML {
37 | var markdownRenderer = html.NewRenderer(html.RendererOptions{Flags: html.CommonFlags | html.HrefTargetBlank})
38 | var markdownParser = parser.NewWithExtensions(
39 | parser.NoIntraEmphasis | parser.Tables | parser.FencedCode | parser.NoEmptyLineBeforeBlock |
40 | parser.Autolink | parser.Strikethrough | parser.SpaceHeadings | parser.DefinitionLists)
41 |
42 | rendered := string(markdown.ToHTML(source, markdownParser, markdownRenderer))
43 | rendered = strings.ReplaceAll(rendered, "", "")
44 | rendered = strings.ReplaceAll(rendered, "
", "
")
45 | return template.HTML(rendered)
46 | }
47 |
--------------------------------------------------------------------------------
/cmd/dev/headers/comments/file_type_test.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2023 Ory Corp
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package comments_test
5 |
6 | import (
7 | "fmt"
8 | "testing"
9 |
10 | "github.com/stretchr/testify/assert"
11 |
12 | "github.com/ory/cli/cmd/dev/headers/comments"
13 | )
14 |
15 | func TestContainsFileType(t *testing.T) {
16 | t.Parallel()
17 | fileTypes := []comments.FileType{"ts", "md", "go"}
18 | assert.True(t, comments.ContainsFileType(fileTypes, "ts"))
19 | assert.True(t, comments.ContainsFileType(fileTypes, "go"))
20 | assert.False(t, comments.ContainsFileType(fileTypes, "rs"))
21 | }
22 |
23 | func TestGetFileType(t *testing.T) {
24 | t.Parallel()
25 | tests := map[string]comments.FileType{
26 | "foo.yml": "yml",
27 | "foo.yaml": "yml",
28 | "foo.md": "md",
29 | "foo.xxx": "xxx",
30 | "foo": "",
31 | }
32 | for give, want := range tests {
33 | t.Run(fmt.Sprintf("%s -> %s", give, want), func(t *testing.T) {
34 | have := comments.GetFileType(give)
35 | assert.Equal(t, want, have)
36 | })
37 | }
38 | }
39 |
40 | func TestSupports(t *testing.T) {
41 | t.Parallel()
42 | assert.True(t, comments.SupportsFile("foo.ts"))
43 | assert.True(t, comments.SupportsFile("foo.md"))
44 | assert.False(t, comments.SupportsFile("foo.xxx"))
45 | assert.False(t, comments.SupportsFile("nodemon"))
46 | assert.False(t, comments.SupportsFile("./nodemon"))
47 | assert.False(t, comments.SupportsFile(".bin/nodemon"))
48 | }
49 |
--------------------------------------------------------------------------------
/cmd/cloudx/project/use.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2022 Ory Corp
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package project
5 |
6 | import (
7 | "github.com/spf13/cobra"
8 |
9 | "github.com/ory/cli/cmd/cloudx/client"
10 | "github.com/ory/x/cmdx"
11 | )
12 |
13 | func NewUseProjectCmd() *cobra.Command {
14 | cmd := &cobra.Command{
15 | Use: "project [id]",
16 | Args: cobra.MaximumNArgs(1),
17 | Short: "Set the project as the default. When no id is provided, prints the currently used default project.",
18 | Example: `$ ory use project ecaaa3cb-0730-4ee8-a6df-9553cdfeef89
19 |
20 | ID ecaaa3cb-0730-4ee8-a6df-9553cdfeef89
21 |
22 | $ ory use project ecaaa3cb-0730-4ee8-a6df-9553cdfeef89 --format json
23 |
24 | {
25 | "id": "ecaaa3cb-0730-4ee8-a6df-9553cdfeef89
26 | }`,
27 | RunE: func(cmd *cobra.Command, args []string) error {
28 | opts := make([]client.CommandHelperOption, 0, 1)
29 | if len(args) == 1 {
30 | opts = append(opts, client.WithProjectOverride(args[0]))
31 | }
32 | h, err := client.NewCobraCommandHelper(cmd, opts...)
33 | if err != nil {
34 | return err
35 | }
36 |
37 | id, err := h.ProjectID()
38 | if err != nil {
39 | return cmdx.PrintOpenAPIError(cmd, err)
40 | }
41 |
42 | if err := h.SelectProject(id); err != nil {
43 | return cmdx.PrintOpenAPIError(cmd, err)
44 | }
45 |
46 | cmdx.PrintRow(cmd, &selectedProject{ID: id})
47 | return nil
48 | },
49 | }
50 |
51 | cmdx.RegisterFormatFlags(cmd.Flags())
52 | return cmd
53 | }
54 |
--------------------------------------------------------------------------------
/cmd/dev/schema/fixtures/render_version_test/.schema/version.schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "$id": "https://github.com/ory/cli/cmd/dev/schema/fixtures/render_version_test/.schema/version.schema.json",
3 | "$schema": "http://json-schema.org/draft-07/schema#",
4 | "title": "Test Fixture schema.",
5 | "type": "object",
6 | "oneOf": [
7 | {
8 | "allOf": [
9 | {
10 | "properties": {
11 | "version": {
12 | "const": "v0.0.0"
13 | }
14 | },
15 | "required": [
16 | "version"
17 | ]
18 | },
19 | {
20 | "$ref": "https://raw.githubusercontent.com/ory/hydra/v0.0.0/.schema/config.schema.json"
21 | }
22 | ]
23 | },
24 | {
25 | "allOf": [
26 | {
27 | "oneOf": [
28 | {
29 | "properties": {
30 | "version": {
31 | "type": "string",
32 | "maxLength": 0
33 | }
34 | },
35 | "required": [
36 | "version"
37 | ]
38 | },
39 | {
40 | "not": {
41 | "properties": {
42 | "version": {}
43 | },
44 | "required": [
45 | "version"
46 | ]
47 | }
48 | }
49 | ]
50 | },
51 | {
52 | "$ref": "#/oneOf/0/allOf/1"
53 | }
54 | ]
55 | }
56 | ]
57 | }
58 |
--------------------------------------------------------------------------------
/cmd/cloudx/eventstreams/update.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2024 Ory Corp
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package eventstreams
5 |
6 | import (
7 | "fmt"
8 |
9 | "github.com/spf13/cobra"
10 |
11 | "github.com/ory/cli/cmd/cloudx/client"
12 | cloud "github.com/ory/client-go"
13 |
14 | "github.com/ory/x/cmdx"
15 | )
16 |
17 | func NewUpdateEventStreamCmd() *cobra.Command {
18 | c := streamConfig{}
19 |
20 | cmd := &cobra.Command{
21 | Use: "event-stream id [--project=PROJECT_ID] [--type=sns] [--aws-iam-role-arn=arn:aws:iam::123456789012:role/MyRole] [--aws-sns-topic-arn=arn:aws:sns:us-east-1:123456789012:MyTopic]",
22 | Args: cobra.ExactArgs(1),
23 | Short: "Update the event stream with the given ID",
24 | RunE: func(cmd *cobra.Command, args []string) error {
25 | ctx := cmd.Context()
26 | h, err := client.NewCobraCommandHelper(cmd)
27 | if err != nil {
28 | return err
29 | }
30 |
31 | projectID, err := h.ProjectID()
32 | if err != nil {
33 | return err
34 | }
35 | streamID := args[0]
36 |
37 | if err := c.Validate(); err != nil {
38 | return err
39 | }
40 | stream, err := h.UpdateEventStream(ctx, projectID, streamID, cloud.SetEventStreamBody(c))
41 | if err != nil {
42 | return cmdx.PrintOpenAPIError(cmd, err)
43 | }
44 |
45 | _, _ = fmt.Fprintln(h.VerboseErrWriter, "Event stream updated successfully!")
46 | cmdx.PrintRow(cmd, output(*stream))
47 | return nil
48 | },
49 | }
50 |
51 | client.RegisterProjectFlag(cmd.Flags())
52 | cmdx.RegisterFormatFlags(cmd.Flags())
53 |
54 | return cmd
55 | }
56 |
--------------------------------------------------------------------------------
/cmd/cloudx/project/get_identity_config.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2023 Ory Corp
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package project
5 |
6 | import (
7 | "github.com/spf13/cobra"
8 |
9 | "github.com/ory/cli/cmd/cloudx/client"
10 | "github.com/ory/x/cmdx"
11 | )
12 |
13 | func NewGetKratosConfigCmd() *cobra.Command {
14 | cmd := &cobra.Command{
15 | Use: "identity-config",
16 | Aliases: []string{"ic", "kratos-config"},
17 | Args: cobra.NoArgs,
18 | Short: "Get Ory Identities configuration.",
19 | Long: "Get the Ory Identities configuration for an Ory Network project.",
20 | Example: `$ ory get identity-config --project ecaaa3cb-0730-4ee8-a6df-9553cdfeef89 --format yaml > identity-config.yaml
21 |
22 | $ ory get identity-config --format json # uses currently selected project
23 |
24 | {
25 | "selfservice": {
26 | "methods": {
27 | "password": { "enabled": false }
28 | }
29 | // ...
30 | }
31 | }`,
32 | RunE: func(cmd *cobra.Command, _ []string) error {
33 | h, err := client.NewCobraCommandHelper(cmd)
34 | if err != nil {
35 | return err
36 | }
37 |
38 | pID, err := h.ProjectID()
39 | if err != nil {
40 | return err
41 | }
42 | project, err := h.GetProject(cmd.Context(), pID, nil)
43 | if err != nil {
44 | return cmdx.PrintOpenAPIError(cmd, err)
45 | }
46 |
47 | cmdx.PrintJSONAble(cmd, outputConfig(project.Services.Identity.Config))
48 | return nil
49 | },
50 | }
51 |
52 | cmdx.RegisterJSONFormatFlags(cmd.Flags())
53 | client.RegisterProjectFlag(cmd.Flags())
54 | client.RegisterWorkspaceFlag(cmd.Flags())
55 | return cmd
56 | }
57 |
--------------------------------------------------------------------------------
/cmd/cloudx/eventstreams/create.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2024 Ory Corp
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package eventstreams
5 |
6 | import (
7 | "fmt"
8 |
9 | "github.com/spf13/cobra"
10 |
11 | "github.com/ory/cli/cmd/cloudx/client"
12 | cloud "github.com/ory/client-go"
13 | "github.com/ory/x/cmdx"
14 | )
15 |
16 | func NewCreateEventStreamCmd() *cobra.Command {
17 | c := streamConfig{}
18 |
19 | cmd := &cobra.Command{
20 | Use: "event-stream [--project=PROJECT_ID] --type=sns --aws-iam-role-arn=arn:aws:iam::123456789012:role/MyRole --aws-sns-topic-arn=arn:aws:sns:us-east-1:123456789012:MyTopic",
21 | Short: "Create a new event stream",
22 | Args: cobra.NoArgs,
23 | RunE: func(cmd *cobra.Command, args []string) error {
24 | ctx := cmd.Context()
25 |
26 | h, err := client.NewCobraCommandHelper(cmd)
27 | if err != nil {
28 | return err
29 | }
30 |
31 | projectID, err := h.ProjectID()
32 | if err != nil {
33 | return err
34 | }
35 |
36 | if err := c.Validate(); err != nil {
37 | return err
38 | }
39 | stream, err := h.CreateEventStream(ctx, projectID, cloud.CreateEventStreamBody(c))
40 | if err != nil {
41 | return cmdx.PrintOpenAPIError(cmd, err)
42 | }
43 |
44 | _, _ = fmt.Fprintln(h.VerboseErrWriter, "Event stream created successfully!")
45 | cmdx.PrintRow(cmd, output(*stream))
46 | return nil
47 | },
48 | }
49 |
50 | client.RegisterProjectFlag(cmd.Flags())
51 | client.RegisterWorkspaceFlag(cmd.Flags())
52 | cmdx.RegisterFormatFlags(cmd.Flags())
53 |
54 | registerStreamConfigFlags(cmd.Flags(), &c)
55 |
56 | return cmd
57 | }
58 |
--------------------------------------------------------------------------------
/cmd/cloudx/project/get_permission_config.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2023 Ory Corp
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package project
5 |
6 | import (
7 | "github.com/spf13/cobra"
8 |
9 | "github.com/ory/cli/cmd/cloudx/client"
10 | "github.com/ory/x/cmdx"
11 | )
12 |
13 | func NewGetKetoConfigCmd() *cobra.Command {
14 | cmd := &cobra.Command{
15 | Use: "permission-config",
16 | Aliases: []string{"pc", "keto-config"},
17 | Args: cobra.NoArgs,
18 | Short: "Get Ory Permissions configuration.",
19 | Long: "Get the Ory Permissions configuration for an Ory Network project.",
20 | Example: `$ ory get permission-config --project ecaaa3cb-0730-4ee8-a6df-9553cdfeef89 --format yaml > permission-config.yaml
21 |
22 | $ ory get permission-config --format json # uses currently selected project
23 |
24 | {
25 | "namespaces": [
26 | {
27 | "name": "files",
28 | "id": 1
29 | },1
30 | // ...
31 | ]
32 | }`,
33 | RunE: func(cmd *cobra.Command, _ []string) error {
34 | h, err := client.NewCobraCommandHelper(cmd)
35 | if err != nil {
36 | return err
37 | }
38 |
39 | pID, err := h.ProjectID()
40 | if err != nil {
41 | return err
42 | }
43 | project, err := h.GetProject(cmd.Context(), pID, nil)
44 | if err != nil {
45 | return cmdx.PrintOpenAPIError(cmd, err)
46 | }
47 |
48 | cmdx.PrintJSONAble(cmd, outputConfig(project.Services.Permission.Config))
49 | return nil
50 | },
51 | }
52 |
53 | cmdx.RegisterJSONFormatFlags(cmd.Flags())
54 | client.RegisterProjectFlag(cmd.Flags())
55 | client.RegisterWorkspaceFlag(cmd.Flags())
56 | return cmd
57 | }
58 |
--------------------------------------------------------------------------------
/cmd/cloudx/identity/delete_test.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2023 Ory Corp
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package identity_test
5 |
6 | import (
7 | "context"
8 | "testing"
9 |
10 | "github.com/stretchr/testify/assert"
11 | "github.com/stretchr/testify/require"
12 | "github.com/tidwall/gjson"
13 |
14 | "github.com/ory/cli/cmd/cloudx/client"
15 | "github.com/ory/cli/cmd/cloudx/testhelpers"
16 | )
17 |
18 | func TestDeleteIdentity(t *testing.T) {
19 | t.Parallel()
20 |
21 | userID := testhelpers.ImportIdentity(ctx, t, defaultProject.Id, nil)
22 |
23 | t.Run("is not able to delete identities if not authenticated and quiet flag", func(t *testing.T) {
24 | ctx := testhelpers.WithCleanConfigFile(context.Background(), t)
25 | _, _, err := testhelpers.Cmd(ctx).Exec(nil, "delete", "identity", "--quiet", "--project", defaultProject.Id, userID)
26 | require.ErrorIs(t, err, client.ErrNoConfigQuiet)
27 | })
28 |
29 | t.Run("triggers auth flow when not authenticated", func(t *testing.T) {
30 | ctx := testhelpers.WithEmitAuthFlowTriggeredErr(context.Background(), t)
31 | _, _, err := testhelpers.Cmd(ctx).Exec(nil, "delete", "identity", "--project", defaultProject.Id, userID)
32 | require.ErrorIs(t, err, testhelpers.ErrAuthFlowTriggered)
33 | })
34 |
35 | t.Run("is able to delete identities", func(t *testing.T) {
36 | stdout, stderr, err := defaultCmd.Exec(nil, "delete", "identity", "--format", "json", "--project", defaultProject.Id, userID)
37 | require.NoError(t, err, stderr)
38 | out := gjson.Parse(stdout)
39 | assert.True(t, gjson.Valid(stdout))
40 | assert.Equal(t, userID, out.String(), "stdout: %s", stdout)
41 | })
42 | }
43 |
--------------------------------------------------------------------------------
/cmd/cloudx/organizations/create_organization.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2023 Ory Corp
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package organizations
5 |
6 | import (
7 | "fmt"
8 |
9 | "github.com/spf13/cobra"
10 |
11 | "github.com/ory/cli/cmd/cloudx/client"
12 | cloud "github.com/ory/client-go"
13 |
14 | "github.com/ory/x/cmdx"
15 | )
16 |
17 | func NewCreateOrganizationCmd() *cobra.Command {
18 | var domains []string
19 |
20 | cmd := &cobra.Command{
21 | Use: "organization