Skip to content

Commit

Permalink
Sentry 9 deprecated the priv key in the DSN (#5)
Browse files Browse the repository at this point in the history
This removes the requirement for the Sentry DSN to include the private key component and adds support for sending only the public key to Sentry 9 if no private key is included. It does not involve any breaking API changes.
  • Loading branch information
francoishill authored and spartan563 committed Dec 4, 2018
1 parent 6f3c77b commit 2d84dba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (

// ErrMissingPrivateKey is returned when a DSN does not have
// a valid private key contained within its URL
// [DEPRECATED] error is never thrown since Sentry 9 has deprecated the secret key requirement
ErrMissingPrivateKey = ErrType("sentry: missing private key")

// ErrMissingProjectID is returned when a DSN does not have a valid
Expand Down Expand Up @@ -72,7 +73,7 @@ func (d *dsn) AuthHeader() string {
}

if d.PrivateKey == "" {
return ""
return fmt.Sprintf("Sentry sentry_version=4, sentry_key=%s", d.PublicKey)
}

return fmt.Sprintf("Sentry sentry_version=4, sentry_key=%s, sentry_secret=%s", d.PublicKey, d.PrivateKey)
Expand All @@ -95,10 +96,9 @@ func (d *dsn) Parse(dsn string) error {
d.PublicKey = uri.User.Username()

privateKey, ok := uri.User.Password()
if !ok {
return errors.Wrap(fmt.Errorf("missing URL password"), ErrMissingPrivateKey.Error())
if ok {
d.PrivateKey = privateKey
}
d.PrivateKey = privateKey

uri.User = nil

Expand Down
4 changes: 2 additions & 2 deletions dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDSN(t *testing.T) {
{"With a valid URL", "https://u:p@example.com/sentry/1", nil},
{"With a badly formatted URL", ":", ErrBadURL},
{"Without a public key", "https://example.com/sentry/1", ErrMissingPublicKey},
{"Without a private key", "https://u@example.com/sentry/1", ErrMissingPrivateKey},
{"Without a private key", "https://u@example.com/sentry/1", nil},
{"Without a project ID", "https://u:p@example.com", ErrMissingProjectID},
}

Expand Down Expand Up @@ -60,7 +60,7 @@ func TestDSN(t *testing.T) {
d := &dsn{
PublicKey: "key",
}
So(d.AuthHeader(), ShouldEqual, "")
So(d.AuthHeader(), ShouldEqual, "Sentry sentry_version=4, sentry_key=key")
})

Convey("With valid keys", func() {
Expand Down
2 changes: 1 addition & 1 deletion httpTransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestHTTPTransport(t *testing.T) {
Convey("With a missing private key", func() {
err := t.Send("https://key@example.com/sentry/1", p)
So(err, ShouldNotBeNil)
So(ErrMissingPrivateKey.IsInstance(err), ShouldBeTrue)
So(err.Error(), ShouldEqual, "got http status 404, expected 200")
})

Convey("When it cannot connect to the server", func() {
Expand Down

0 comments on commit 2d84dba

Please sign in to comment.