Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DeleteCmd = &cobra.Command{ Use: "delete <id-0 [id-1 ...]>", Short: "Delete identities by ID", Long: fmt.Sprintf(`This command deletes one or more identities by ID. To delete an identity by some selector, e.g. the recovery email address, use the list command in combination with jq. %s `, clihelpers.WarningJQIsComplicated), Example: `To delete the identity with the recovery email address "foo@bar.com", run: $ kratos identities delete $(kratos identities list --format json | jq -r 'map(select(.recovery_addresses[].value == "foo@bar.com")) | .[].id')`, Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { c := cliclient.NewClient(cmd) var ( deleted = make([]string, 0, len(args)) errs []error ) for _, a := range args { _, err := c.AdminApi.DeleteIdentity(cmd.Context(), a).Execute() if err != nil { errs = append(errs, err) continue } deleted = append(deleted, a) } for _, d := range deleted { _, _ = fmt.Fprintln(cmd.OutOrStdout(), d) } for _, err := range errs { _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%+v\n", err) } if len(errs) != 0 { return cmdx.FailSilently(cmd) } return nil }, }
View Source
var GetCmd = &cobra.Command{ Use: "get <id-0 [id-1 ...]>", Short: "Get one or more identities by ID", Long: fmt.Sprintf(`This command gets all the details about an identity. To get an identity by some selector, e.g. the recovery email address, use the list command in combination with jq. %s `, clihelpers.WarningJQIsComplicated), Example: `To get the identities with the recovery email address at the domain "ory.sh", run: $ kratos identities get $(kratos identities list --format json | jq -r 'map(select(.recovery_addresses[].value | endswith("@ory.sh"))) | .[].id')`, Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { c := cliclient.NewClient(cmd) identities := make([]kratos.Identity, 0, len(args)) failed := make(map[string]error) for _, id := range args { identity, _, err := c.AdminApi.GetIdentity(cmd.Context(), id).Execute() if x.SDKError(err) != nil { failed[id] = err continue } identities = append(identities, *identity) } if len(identities) == 1 { cmdx.PrintRow(cmd, (*outputIdentity)(&identities[0])) } else if len(identities) > 1 { cmdx.PrintTable(cmd, &outputIdentityCollection{identities}) } cmdx.PrintErrors(cmd, failed) if len(failed) != 0 { return cmdx.FailSilently(cmd) } return nil }, }
View Source
var ImportCmd = &cobra.Command{ Use: "import <file.json [file-2.json [file-3.json] ...]>", Short: "Import identities from files or STD_IN", Example: `$ cat > ./file.json <<EOF { "schema_id": "default", "traits": { "email": "foo@example.com" } } EOF $ kratos identities import file.json # Alternatively: $ cat file.json | kratos identities import`, Long: `Import identities from files or STD_IN. Files can contain only a single or an array of identities. The validity of files can be tested beforehand using "... identities validate". WARNING: Importing credentials is not yet supported.`, RunE: func(cmd *cobra.Command, args []string) error { c := cliclient.NewClient(cmd) imported := make([]kratos.Identity, 0, len(args)) failed := make(map[string]error) is, err := readIdentities(cmd, args) if err != nil { return err } for src, i := range is { err = validateIdentity(cmd, src, i, func(ctx context.Context, id string) (map[string]interface{}, *http.Response, error) { return c.PublicApi.GetSchema(ctx, id).Execute() }) if err != nil { return err } var params kratos.CreateIdentity err = json.Unmarshal([]byte(i), ¶ms) if err != nil { _, _ = fmt.Fprintln(cmd.ErrOrStderr(), "STD_IN: Could not parse identity") return cmdx.FailSilently(cmd) } ident, _, err := c.AdminApi.CreateIdentity(cmd.Context()).CreateIdentity(params).Execute() if err != nil { failed[src] = err } else { imported = append(imported, *ident) } } if len(imported) == 1 { cmdx.PrintRow(cmd, (*outputIdentity)(&imported[0])) } else { cmdx.PrintTable(cmd, &outputIdentityCollection{identities: imported}) } cmdx.PrintErrors(cmd, failed) if len(failed) != 0 { return cmdx.FailSilently(cmd) } return nil }, }
ImportCmd represents the import command
View Source
var ListCmd = &cobra.Command{ Use: "list [<page> <per-page>]", Short: "List identities", Long: "List identities (paginated)", Args: func(cmd *cobra.Command, args []string) error { if len(args) != 0 && len(args) != 2 { return fmt.Errorf("expected zero or two args, got %d: %+v", len(args), args) } return nil }, Aliases: []string{"ls"}, RunE: func(cmd *cobra.Command, args []string) error { c := cliclient.NewClient(cmd) req := c.AdminApi.ListIdentities(cmd.Context()) if len(args) == 2 { page, err := strconv.ParseInt(args[0], 0, 64) if err != nil { _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not parse page argument\"%s\": %s", args[0], err) return cmdx.FailSilently(cmd) } req = req.Page(page) perPage, err := strconv.ParseInt(args[1], 0, 64) if err != nil { _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not parse per-page argument\"%s\": %s", args[1], err) return cmdx.FailSilently(cmd) } req = req.PerPage(perPage) } identities, _, err := req.Execute() if err != nil { _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not get the identities: %+v\n", err) return cmdx.FailSilently(cmd) } cmdx.PrintTable(cmd, &outputIdentityCollection{ identities: identities, }) return nil }, }
View Source
var PatchCmd = &cobra.Command{ Use: "patch <file.json [file-2.json [file-3.json] ...]>", Short: "Patch identities by ID (not yet implemented)", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { fmt.Println("not yet implemented") os.Exit(1) }, }
View Source
var ValidateCmd = &cobra.Command{ Use: "validate <file.json [file-2.json [file-3.json] ...]>", Short: "Validate local identity files", Long: `This command allows validation of identity files. It validates against the payload of the API and the identity schema as configured in Ory Kratos. Identities can be supplied via STD_IN or JSON files containing a single or an array of identities. `, RunE: func(cmd *cobra.Command, args []string) error { c := cliclient.NewClient(cmd) is, err := readIdentities(cmd, args) if err != nil { return err } for src, i := range is { err = validateIdentity(cmd, src, i, func(ctx context.Context, id string) (map[string]interface{}, *http.Response, error) { return c.PublicApi.GetSchema(ctx, id).Execute() }) if err != nil { return err } } _, _ = fmt.Fprintln(cmd.OutOrStdout(), "All identity files are valid.") return nil }, }
Functions ¶
func RegisterFlags ¶
func RegisterFlags()
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.