Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
914 additions
and
192 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,91 @@ | ||
package identities | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ory/kratos/internal/clihelpers" | ||
"github.com/ory/kratos/internal/httpclient/models" | ||
) | ||
|
||
type ( | ||
outputIdentity models.Identity | ||
outputIdentityCollection struct { | ||
identities []*models.Identity | ||
} | ||
) | ||
|
||
func (_ *outputIdentity) Header() []string { | ||
return []string{"ID", "VERIFIED ADDRESSES", "RECOVERY ADDRESSES", "SCHEMA ID", "SCHEMA URL"} | ||
} | ||
|
||
func (i *outputIdentity) Fields() []string { | ||
data := [5]string{ | ||
string(i.ID), | ||
clihelpers.None, | ||
clihelpers.None, | ||
clihelpers.None, | ||
i.SchemaURL, | ||
} | ||
|
||
addresses := make([]string, 0, len(i.VerifiableAddresses)) | ||
for _, a := range i.VerifiableAddresses { | ||
if a.Value != nil { | ||
addresses = append(addresses, *a.Value) | ||
} | ||
} | ||
data[1] = strings.Join(addresses, ", ") | ||
|
||
addresses = addresses[:0] | ||
for _, a := range i.RecoveryAddresses { | ||
if a.Value != nil { | ||
addresses = append(addresses, *a.Value) | ||
} | ||
} | ||
data[2] = strings.Join(addresses, ", ") | ||
|
||
if i.SchemaID != nil { | ||
data[3] = *i.SchemaID | ||
} | ||
|
||
return data[:] | ||
} | ||
|
||
func (i *outputIdentity) Interface() interface{} { | ||
return i | ||
} | ||
|
||
func (_ *outputIdentityCollection) Header() []string { | ||
return []string{"ID", "VERIFIED ADDRESS 1", "RECOVERY ADDRESS 1", "SCHEMA ID", "SCHEMA URL"} | ||
} | ||
|
||
func (c *outputIdentityCollection) Table() [][]string { | ||
rows := make([][]string, len(c.identities)) | ||
for i, ident := range c.identities { | ||
data := [5]string{ | ||
string(ident.ID), | ||
clihelpers.None, | ||
clihelpers.None, | ||
clihelpers.None, | ||
ident.SchemaURL, | ||
} | ||
|
||
if len(ident.VerifiableAddresses) != 0 && ident.VerifiableAddresses[0].Value != nil { | ||
data[1] = *ident.VerifiableAddresses[0].Value | ||
} | ||
|
||
if len(ident.RecoveryAddresses) != 0 && ident.RecoveryAddresses[0].Value != nil { | ||
data[2] = *ident.RecoveryAddresses[0].Value | ||
} | ||
|
||
if ident.SchemaID != nil { | ||
data[3] = *ident.SchemaID | ||
} | ||
|
||
rows[i] = data[:] | ||
} | ||
return rows | ||
} | ||
|
||
func (c *outputIdentityCollection) Interface() interface{} { | ||
return c.identities | ||
} |
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,49 @@ | ||
package identities | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/kratos/cmd/cliclient" | ||
"github.com/ory/kratos/internal/httpclient/client/admin" | ||
) | ||
|
||
var deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
c := cliclient.NewClient(cmd) | ||
|
||
var ( | ||
deleted = make([]string, 0, len(args)) | ||
errs []error | ||
) | ||
|
||
for _, a := range args { | ||
_, err := c.Admin.DeleteIdentity(&admin.DeleteIdentityParams{ | ||
ID: a, | ||
Context: context.Background(), | ||
}) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
deleted = append(deleted, a) | ||
} | ||
|
||
for _, d := range deleted { | ||
fmt.Println(d) | ||
} | ||
|
||
for _, err := range errs { | ||
fmt.Fprintln(os.Stderr, err) | ||
} | ||
|
||
if len(errs) != 0 { | ||
os.Exit(1) | ||
} | ||
}, | ||
} |
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,28 @@ | ||
package identities | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/kratos/cmd/cliclient" | ||
"github.com/ory/kratos/internal/clihelpers" | ||
"github.com/ory/kratos/internal/httpclient/client/admin" | ||
"github.com/ory/x/cmdx" | ||
) | ||
|
||
var getCmd = &cobra.Command{ | ||
Use: "get <id>", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
c := cliclient.NewClient(cmd) | ||
|
||
resp, err := c.Admin.GetIdentity(&admin.GetIdentityParams{ | ||
ID: args[0], | ||
Context: context.Background(), | ||
}) | ||
cmdx.Must(err, "Could not get identity \"%s\": %s", args[0], err) | ||
|
||
clihelpers.PrintRow(cmd, (*outputIdentity)(resp.Payload)) | ||
}, | ||
} |
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
Oops, something went wrong.