Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Change DSN ProjectID to be a string #420

Merged
merged 1 commit into from Mar 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions dsn.go
Expand Up @@ -45,7 +45,7 @@ type Dsn struct {
host string
port int
path string
projectID int
projectID string
}

// NewDsn creates a Dsn by parsing rawURL. Most users will never call this
Expand Down Expand Up @@ -104,9 +104,10 @@ func NewDsn(rawURL string) (*Dsn, error) {
return nil, &DsnParseError{"empty project id"}
}
pathSegments := strings.Split(parsedURL.Path[1:], "/")
projectID, err := strconv.Atoi(pathSegments[len(pathSegments)-1])
if err != nil {
return nil, &DsnParseError{"invalid project id"}
projectID := pathSegments[len(pathSegments)-1]

if projectID == "" {
return nil, &DsnParseError{"empty project id"}
}

// Path
Expand Down Expand Up @@ -140,7 +141,7 @@ func (dsn Dsn) String() string {
if dsn.path != "" {
url += dsn.path
}
url += fmt.Sprintf("/%d", dsn.projectID)
url += fmt.Sprintf("/%s", dsn.projectID)
return url
}

Expand All @@ -165,7 +166,7 @@ func (dsn Dsn) getAPIURL(s string) *url.URL {
if dsn.path != "" {
rawURL += dsn.path
}
rawURL += fmt.Sprintf("/api/%d/%s/", dsn.projectID, s)
rawURL += fmt.Sprintf("/api/%s/%s/", dsn.projectID, s)
parsedURL, _ := url.Parse(rawURL)
return parsedURL
}
Expand Down
9 changes: 4 additions & 5 deletions dsn_test.go
Expand Up @@ -26,7 +26,7 @@ var dsnTests = map[string]DsnTest{
host: "domain",
port: 8888,
path: "/foo/bar",
projectID: 42,
projectID: "42",
},
url: "https://domain:8888/foo/bar/api/42/store/",
envURL: "https://domain:8888/foo/bar/api/42/envelope/",
Expand All @@ -38,7 +38,7 @@ var dsnTests = map[string]DsnTest{
publicKey: "public",
host: "domain",
port: 443,
projectID: 42,
projectID: "42",
},
url: "https://domain/api/42/store/",
envURL: "https://domain/api/42/envelope/",
Expand All @@ -50,7 +50,7 @@ var dsnTests = map[string]DsnTest{
publicKey: "public",
host: "domain",
port: 80,
projectID: 42,
projectID: "42",
},
url: "http://domain/api/42/store/",
envURL: "http://domain/api/42/envelope/",
Expand Down Expand Up @@ -100,9 +100,8 @@ var invalidDsnTests = map[string]invalidDsnTest{
"NoProjectID2": {"https://public:secret@domain:8888", "empty project id"},
"BadURL": {"!@#$%^&*()", "invalid url"},
"BadScheme": {"ftp://public:secret@domain:8888/1", "invalid scheme"},
"BadProjectID": {"https://public:secret@domain:8888/wbvdf7^W#$", "invalid project id"},
"BadPort": {"https://public:secret@domain:wat/42", "invalid port"},
"TrailingSlash": {"https://public:secret@domain:8888/42/", "invalid project id"},
"TrailingSlash": {"https://public:secret@domain:8888/42/", "empty project id"},
}

//nolint: scopelint // false positive https://github.com/kyoh86/scopelint/issues/4
Expand Down
4 changes: 2 additions & 2 deletions transport.go
Expand Up @@ -304,7 +304,7 @@ func (t *HTTPTransport) SendEvent(event *Event) {
eventType = fmt.Sprintf("%s event", event.Level)
}
Logger.Printf(
"Sending %s [%s] to %s project: %d",
"Sending %s [%s] to %s project: %s",
eventType,
event.EventID,
t.dsn.host,
Expand Down Expand Up @@ -511,7 +511,7 @@ func (t *HTTPSyncTransport) SendEvent(event *Event) {
eventType = fmt.Sprintf("%s event", event.Level)
}
Logger.Printf(
"Sending %s [%s] to %s project: %d",
"Sending %s [%s] to %s project: %s",
eventType,
event.EventID,
t.dsn.host,
Expand Down