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 .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- run: |
docker create --name mailhog -p 8025:8025 -p 1025:1025 \
mailhog/mailhog:v1.0.0 \
MailHog -invite-jim -jim-linkspeed-affect=0.25 -jim-reject-auth=0.25 -jim-reject-recipient=0.25 -jim-reject-sender=0.25 -jim-disconnect=0.25 -jim-linkspeed-min=1250 -jim-linkspeed-max=12500 \
MailHog -invite-jim -jim-linkspeed-affect=0.25 -jim-reject-auth=0.25 -jim-reject-recipient=0 -jim-reject-sender=0 -jim-disconnect=0.25 -jim-linkspeed-min=1250 -jim-linkspeed-max=12500 \
|| true
docker start mailhog
name: Start MailHog
Expand Down
4 changes: 2 additions & 2 deletions courier/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *courier) Work(ctx context.Context) error {
}
return ctx.Err()
case err := <-errChan:
return err
return errors.WithStack(err)
}
}

Expand All @@ -98,7 +98,7 @@ func (c *courier) watchMessages(ctx context.Context, errChan chan error) {
if err := backoff.Retry(func() error {
return c.DispatchQueue(ctx)
}, c.backoff); err != nil {
errChan <- err
errChan <- errors.WithStack(err)
return
}
time.Sleep(wait)
Expand Down
6 changes: 4 additions & 2 deletions courier/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package courier
import (
"net/http"

"github.com/pkg/errors"

"github.com/ory/kratos/x/nosurfx"
"github.com/ory/kratos/x/redir"

Expand Down Expand Up @@ -140,15 +142,15 @@ func parseMessagesFilter(r *http.Request, keys [][32]byte) (ListCourierMessagesP
if r.URL.Query().Has("status") {
ms, err := ToMessageStatus(r.URL.Query().Get("status"))
if err != nil {
return ListCourierMessagesParameters{}, nil, err
return ListCourierMessagesParameters{}, nil, errors.WithStack(err)
}

status = &ms
}

opts, err := keysetpagination.ParseQueryParams(keys, r.URL.Query())
if err != nil {
return ListCourierMessagesParameters{}, nil, err
return ListCourierMessagesParameters{}, nil, errors.WithStack(err)
}

return ListCourierMessagesParameters{
Expand Down
12 changes: 6 additions & 6 deletions courier/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,25 @@ func NewSMTPClient(deps Dependencies, cfg *config.SMTPConfig) (*SMTPClient, erro
func (c *courier) QueueEmail(ctx context.Context, t EmailTemplate) (uuid.UUID, error) {
recipient, err := t.EmailRecipient()
if err != nil {
return uuid.Nil, err
return uuid.Nil, errors.WithStack(err)
}
if _, err := mail.ParseAddress(recipient); err != nil {
return uuid.Nil, err
return uuid.Nil, errors.WithStack(err)
}

subject, err := t.EmailSubject(ctx)
if err != nil {
return uuid.Nil, err
return uuid.Nil, errors.WithStack(err)
}

bodyPlaintext, err := t.EmailBodyPlaintext(ctx)
if err != nil {
return uuid.Nil, err
return uuid.Nil, errors.WithStack(err)
}

templateData, err := json.Marshal(t)
if err != nil {
return uuid.Nil, err
return uuid.Nil, errors.WithStack(err)
}

message := &Message{
Expand All @@ -132,7 +132,7 @@ func (c *courier) QueueEmail(ctx context.Context, t EmailTemplate) (uuid.UUID, e
}

if err := c.deps.CourierPersister().AddMessage(ctx, message); err != nil {
return uuid.Nil, err
return uuid.Nil, errors.WithStack(err)
}

return message.ID, nil
Expand Down
4 changes: 3 additions & 1 deletion courier/smtp_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func (c *SMTPChannel) Dispatch(ctx context.Context, msg Message) (err error) {
if err != nil {
logger.
WithError(err).
WithField("smtp_host", c.smtpClient.Host).
WithField("smtp_port", c.smtpClient.Port).
Error("Unable to dial SMTP connection.")
return errors.WithStack(herodot.ErrInternalServerError.
WithError(err.Error()).WithReason("failed to send email via smtp"))
Expand Down Expand Up @@ -155,7 +157,7 @@ func (c *SMTPChannel) Dispatch(ctx context.Context, msg Message) (err error) {
logger.
WithError(err).
Error(`Unable to reset the retried message's status to "abandoned".`)
return err
return errors.WithStack(err)
}
}

Expand Down
19 changes: 8 additions & 11 deletions identity/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,14 @@ func (c Credentials) Signature() string {
type (
// swagger:ignore
CredentialIdentifier struct {
ID uuid.UUID `db:"id"`
Identifier string `db:"identifier"`
// IdentityCredentialsID is a helper struct field for gobuffalo.pop.
IdentityCredentialsID uuid.UUID `json:"-" db:"identity_credential_id"`
// IdentityCredentialsTypeID is a helper struct field for gobuffalo.pop.
IdentityCredentialsTypeID uuid.UUID `json:"-" db:"identity_credential_type_id"`
// CreatedAt is a helper struct field for gobuffalo.pop.
CreatedAt time.Time `json:"created_at" db:"created_at"`
// UpdatedAt is a helper struct field for gobuffalo.pop.
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
NID uuid.UUID `json:"-" faker:"-" db:"nid"`
ID uuid.UUID `db:"id"`
Identifier string `db:"identifier"`
IdentityID *uuid.UUID `json:"-" db:"identity_id"`
IdentityCredentialsID uuid.UUID `json:"-" db:"identity_credential_id"`
IdentityCredentialsTypeID uuid.UUID `json:"-" db:"identity_credential_type_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
NID uuid.UUID `json:"-" faker:"-" db:"nid"`
}

// swagger:ignore
Expand Down
5 changes: 2 additions & 3 deletions identity/test/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,6 @@ func TestPool(ctx context.Context, p persistence.Persister, m *identity.Manager,
})
})
}

})

t.Run("case=create and update and find", func(t *testing.T) {
Expand Down Expand Up @@ -1547,8 +1546,8 @@ func TestPool(ctx context.Context, p persistence.Persister, m *identity.Manager,
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO identity_credentials (id, identity_id, nid, identity_credential_type_id, created_at, updated_at, config) VALUES (?, ?, ?, ?, ?, ?, '{}')", cid2, iid, nid2, m[0].ID, time.Now(), time.Now()).Exec())

ici1, ici2 := x.NewUUID(), x.NewUUID()
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO identity_credential_identifiers (id, identity_credential_id, nid, identifier, created_at, updated_at, identity_credential_type_id) VALUES (?, ?, ?, ?, ?, ?, ?)", ici1, cid1, nid1, "nid1", time.Now(), time.Now(), m[0].ID).Exec())
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO identity_credential_identifiers (id, identity_credential_id, nid, identifier, created_at, updated_at, identity_credential_type_id) VALUES (?, ?, ?, ?, ?, ?, ?)", ici2, cid2, nid2, "nid2", time.Now(), time.Now(), m[0].ID).Exec())
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO identity_credential_identifiers (id, identity_id, identity_credential_id, nid, identifier, created_at, updated_at, identity_credential_type_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", ici1, iid, cid1, nid1, "nid1", time.Now(), time.Now(), m[0].ID).Exec())
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO identity_credential_identifiers (id, identity_id, identity_credential_id, nid, identifier, created_at, updated_at, identity_credential_type_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", ici2, iid, cid2, nid2, "nid2", time.Now(), time.Now(), m[0].ID).Exec())

_, err := p.GetIdentity(ctx, nid1, identity.ExpandNothing)
require.ErrorIs(t, err, sqlcon.ErrNoRows)
Expand Down
3 changes: 1 addition & 2 deletions oryx/clidoc/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func generate(cmd *cobra.Command, dir string) error {
if _, err := io.WriteString(f, fmt.Sprintf(`---
id: %s
title: %s
description: %s %s
description: %s
---

<!--
Expand All @@ -64,7 +64,6 @@ To improve this file please make your change against the appropriate "./cmd/*.go
basename,
cmd.CommandPath(),
cmd.CommandPath(),
cmd.Short,
)); err != nil {
return err
}
Expand Down
46 changes: 41 additions & 5 deletions oryx/clidoc/md_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"os"
"path/filepath"
"regexp"
"sort"
"strings"

Expand Down Expand Up @@ -61,15 +62,15 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
name := cmd.CommandPath()

buf.WriteString("## " + html.EscapeString(name) + "\n\n")
buf.WriteString(cmd.Short + "\n\n")
buf.WriteString(fenceIndentedBlocks(cmd.Short) + "\n\n")
if len(cmd.Long) > 0 {
buf.WriteString("### Synopsis\n\n")
long, err := cmdx.TemplateCommandField(cmd, cmd.Long)
if err != nil {
buf.WriteString(fmt.Sprintf("<!-- Error rendering cmd.Long: %s -->\n\n", err.Error()))
long = cmd.Long
}
buf.WriteString(long + "\n\n")
buf.WriteString(fenceIndentedBlocks(long) + "\n\n")
}

if cmd.Runnable() {
Expand All @@ -90,13 +91,17 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
return err
}
if hasSeeAlso(cmd) {
buf.WriteString("### SEE ALSO\n\n")
buf.WriteString("### See also\n\n")
if cmd.HasParent() {
parent := cmd.Parent()
pname := parent.CommandPath()
link := pname + ".md"
link = strings.Replace(link, " ", "_", -1)
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short))
short := parent.Short
if short != "" {
short = fmt.Sprintf(" %s", short)
}
buf.WriteString(fmt.Sprintf("* [%s](%s)%s\n", pname, linkHandler(link), short))
cmd.VisitParents(func(c *cobra.Command) {
if c.DisableAutoGenTag {
cmd.DisableAutoGenTag = c.DisableAutoGenTag
Expand All @@ -114,7 +119,11 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
cname := name + " " + child.Name()
link := cname + ".md"
link = strings.Replace(link, " ", "_", -1)
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short))
short := child.Short
if short != "" {
short = fmt.Sprintf(" - %s", short)
}
buf.WriteString(fmt.Sprintf("* [%s](%s)\t%s\n", cname, linkHandler(link), short))
}
buf.WriteString("\n")
}
Expand Down Expand Up @@ -163,3 +172,30 @@ func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHa
}
return nil
}

var indentedBlock = regexp.MustCompile(`(?m)^(?: {4}|\t).*(?:\n(?: {4}|\t).*)*`)

func fenceIndentedBlocks(s string) string {
return indentedBlock.ReplaceAllStringFunc(s, func(block string) string {
// trim trailing newline to keep fence tidy
block = strings.TrimRight(block, "\n")

// de-indent exactly one level for nicer fenced output
lines := strings.Split(block, "\n")
for i, ln := range lines {
switch {
case strings.HasPrefix(ln, " "):
lines[i] = ln[4:]
case strings.HasPrefix(ln, "\t"):
lines[i] = ln[1:]
}
}
b := strings.Join(lines, "\n")

// guard against already fenced content
if strings.HasPrefix(strings.TrimSpace(b), "```") {
return block
}
return "```\n" + b + "\n```"
})
}
48 changes: 48 additions & 0 deletions oryx/clidoc/testdata/hydra-client-admin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
id: hydra-client-admin
title: hydra client admin
description: hydra client admin
---

<!--
This file is auto-generated.

To improve this file please make your change against the appropriate "./cmd/*.go" file.
-->
## hydra client admin

Foo bar baz bar

```
short with multiple
```



### Synopsis

Run the admin server

```
<[some argument]>
<[some argument]>
<[some argument]>
<[some argument]>
<[some argument]>
```


```
hydra client admin <args> [flags]
```

### Options

```
-h, --help help for admin
```

### See also

* [hydra client](hydra-client) Run client commands

36 changes: 36 additions & 0 deletions oryx/clidoc/testdata/hydra-client-public.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
id: hydra-client-public
title: hydra client public
description: hydra client public
---

<!--
This file is auto-generated.

To improve this file please make your change against the appropriate "./cmd/*.go" file.
-->
## hydra client public



### Synopsis

Run the public server

<[some argument]>


```
hydra client public <args> [flags]
```

### Options

```
-h, --help help for public
```

### See also

* [hydra client](hydra-client) Run client commands

48 changes: 48 additions & 0 deletions oryx/clidoc/testdata/hydra-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
id: hydra-client
title: hydra client
description: hydra client
---

<!--
This file is auto-generated.

To improve this file please make your change against the appropriate "./cmd/*.go" file.
-->
## hydra client

Run client commands

### Synopsis

Manage OAuth2 clients

<[some argument]>


```
hydra client [flags]
```

### Examples

```
hydra client --whatever
```

### Options

```
-h, --help help for client
```

### See also

* [hydra](hydra)
* [hydra client admin](hydra-client-admin) - Foo bar baz bar

short with multiple


* [hydra client public](hydra-client-public)

Loading