forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDsn.java
More file actions
89 lines (81 loc) · 2.25 KB
/
Dsn.java
File metadata and controls
89 lines (81 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package io.sentry;
import io.sentry.exception.InvalidDsnException;
import java.net.URI;
import org.jetbrains.annotations.Nullable;
final class Dsn {
private final String projectId;
private final String path;
private final String secretKey;
private final String publicKey;
private final URI sentryUri;
/*
/ The project ID which the authenticated user is bound to.
*/
public String getProjectId() {
return projectId;
}
/*
/ An optional path of which Sentry is hosted
*/
public String getPath() {
return path;
}
/*
/ The optional secret key to authenticate the SDK.
*/
public String getSecretKey() {
return secretKey;
}
/*
/ The required public key to authenticate the SDK.
*/
public String getPublicKey() {
return publicKey;
}
/*
/ The URI used to communicate with Sentry
*/
URI getSentryUri() {
return sentryUri;
}
Dsn(@Nullable String dsn) throws InvalidDsnException {
try {
URI uri = new URI(dsn).normalize();
String userInfo = uri.getUserInfo();
if (userInfo == null || userInfo.isEmpty()) {
throw new IllegalArgumentException("Invalid DSN: No public key provided.");
}
String[] keys = userInfo.split(":", -1);
publicKey = keys[0];
if (publicKey == null || publicKey.isEmpty()) {
throw new IllegalArgumentException("Invalid DSN: No public key provided.");
}
secretKey = keys.length > 1 ? keys[1] : null;
String uriPath = uri.getPath();
if (uriPath.endsWith("/")) {
uriPath = uriPath.substring(0, uriPath.length() - 1);
}
int projectIdStart = uriPath.lastIndexOf("/") + 1;
String path = uriPath.substring(0, projectIdStart);
if (!path.endsWith("/")) {
path += "/";
}
this.path = path;
projectId = uriPath.substring(projectIdStart);
if (projectId.isEmpty()) {
throw new IllegalArgumentException("Invalid DSN: A Project Id is required.");
}
sentryUri =
new URI(
uri.getScheme(),
null,
uri.getHost(),
uri.getPort(),
path + "api/" + projectId,
null,
null);
} catch (Exception e) {
throw new InvalidDsnException(dsn, e);
}
}
}