Skip to content

Commit

Permalink
feature(apikey): adding apikey to session
Browse files Browse the repository at this point in the history
  • Loading branch information
YYChen01988 committed Jun 15, 2023
2 parents dce60da + ef240c3 commit 27d7278
Show file tree
Hide file tree
Showing 29 changed files with 291 additions and 124 deletions.
40 changes: 30 additions & 10 deletions .buildkite/pipeline.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ steps:
download:
- "build/fixture-r19.apk"
- "build/fixture-r19/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -120,7 +122,9 @@ steps:
download:
- "build/fixture-r19.apk"
- "build/fixture-r19/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -204,7 +208,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -232,7 +238,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -260,7 +268,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -288,7 +298,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -320,7 +332,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -348,7 +362,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -376,7 +392,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -404,7 +422,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down
28 changes: 21 additions & 7 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ steps:
download:
- "build/fixture-r19.apk"
- "build/fixture-r19/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -157,7 +159,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand All @@ -184,7 +188,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -212,7 +218,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -244,7 +252,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -273,7 +283,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down Expand Up @@ -301,7 +313,9 @@ steps:
download:
- "build/fixture-r21.apk"
- "build/fixture-r21/*"
upload: "maze_output/failed/**/*"
upload:
- "maze_output/failed/**/*"
- "maze_output/metrics.csv"
docker-compose#v4.7.0:
pull: maze-runner
run: maze-runner
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## TBD

### Enhancements

* Added `Session.apiKey` so that it can be changed in an `OnSessionCallback`.
[#1855](https://github.com/bugsnag/bugsnag-android/pull/1855)
*
## 5.30.0 (2023-05-11)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"
#gem 'bugsnag-maze-runner', path: '../maze-runner'

# Or a specific release:
gem 'bugsnag-maze-runner', '~>7.0'
gem 'bugsnag-maze-runner', '~>7.30.2'

# Or follow master:
#gem 'bugsnag-maze-runner', git: 'https://github.com/bugsnag/maze-runner'
Expand Down
20 changes: 11 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ GEM
selenium-webdriver (~> 4.2, < 4.6)
bugsnag (6.25.2)
concurrent-ruby (~> 1.0)
bugsnag-maze-runner (7.23.0)
bugsnag-maze-runner (7.30.2)
appium_lib (~> 12.0.0)
appium_lib_core (~> 5.4.0)
bugsnag (~> 6.24)
cucumber (~> 7.1)
cucumber-expressions (~> 6.0.0)
curb (~> 0.9.6)
dogstatsd-ruby (~> 5.5.0)
json_schemer (~> 0.2.24)
optimist (~> 3.0.1)
os (~> 1.0.0)
Expand Down Expand Up @@ -62,10 +63,11 @@ GEM
cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
curb (0.9.11)
diff-lcs (1.5.0)
dogstatsd-ruby (5.5.0)
ecma-re-validator (0.4.0)
regexp_parser (~> 2.2)
eventmachine (1.2.7)
faye-websocket (0.11.1)
faye-websocket (0.11.2)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.5.1)
ffi (1.15.5)
Expand All @@ -86,27 +88,27 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
multi_test (0.1.2)
nokogiri (1.14.2-arm64-darwin)
nokogiri (1.15.1-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.2-x86_64-darwin)
nokogiri (1.15.1-x86_64-darwin)
racc (~> 1.4)
optimist (3.0.1)
os (1.0.1)
power_assert (2.0.3)
racc (1.6.2)
rack (2.2.6.4)
rack (2.2.7)
rake (12.3.3)
regexp_parser (2.7.0)
regexp_parser (2.8.0)
rexml (3.2.5)
rubyzip (2.3.2)
selenium-webdriver (4.5.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sys-uname (1.2.2)
sys-uname (1.2.3)
ffi (~> 1.1)
test-unit (3.5.7)
test-unit (3.5.8)
power_assert
thor (1.0.1)
tomlrb (2.0.3)
Expand All @@ -125,7 +127,7 @@ PLATFORMS
x86_64-darwin-20

DEPENDENCIES
bugsnag-maze-runner (~> 7.0)
bugsnag-maze-runner (~> 7.30.2)
license_finder (~> 6.13)

BUNDLED WITH
Expand Down
2 changes: 2 additions & 0 deletions bugsnag-android-core/api/bugsnag-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,13 @@ public abstract interface class com/bugsnag/android/Plugin {
}

public final class com/bugsnag/android/Session : com/bugsnag/android/JsonStream$Streamable, com/bugsnag/android/UserAware {
public fun getApiKey ()Ljava/lang/String;
public fun getApp ()Lcom/bugsnag/android/App;
public fun getDevice ()Lcom/bugsnag/android/Device;
public fun getId ()Ljava/lang/String;
public fun getStartedAt ()Ljava/util/Date;
public fun getUser ()Lcom/bugsnag/android/User;
public fun setApiKey (Ljava/lang/String;)V
public fun setId (Ljava/lang/String;)V
public fun setStartedAt (Ljava/util/Date;)V
public fun setUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testSessionFromFile() throws Exception {
session.toStream(stream);
out.flush();

Session payload = new Session(file, new Notifier(), NoopLogger.INSTANCE, "Test Apikey");
Session payload = new Session(file, new Notifier(), NoopLogger.INSTANCE, "TEST APIKEY");
JSONObject obj = BugsnagTestUtils.streamableToJson(payload);
JSONObject rootNode = obj.getJSONArray("sessions").getJSONObject(0);
assertNotNull(rootNode);
Expand All @@ -71,7 +71,15 @@ public void testSessionFromFile() throws Exception {

@Test
public void testAutoCapturedOverride() throws Exception {
session = new Session("id", new Date(), null, false, new Notifier(), NoopLogger.INSTANCE, "TEST APIKEY");
session = new Session(
"id",
new Date(),
null,
false,
new Notifier(),
NoopLogger.INSTANCE,
"TEST APIKEY"
);
assertFalse(session.isAutoCaptured());
session.setAutoCaptured(true);
assertTrue(session.isAutoCaptured());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ internal data class SessionFilenameInfo(
}

@JvmStatic
fun defaultFilename(apiKey: String, config: ImmutableConfig): String {
val sanitizedApiKey = apiKey.takeUnless { it.isEmpty() } ?: config.apiKey
fun defaultFilename(
obj: Any,
config: ImmutableConfig
): SessionFilenameInfo {
val sanitizedApiKey = when (obj) {
is Session -> obj.apiKey
else -> config.apiKey
}

return toFilename(
return SessionFilenameInfo(
sanitizedApiKey,
System.currentTimeMillis(),
UUID.randomUUID().toString()
Expand All @@ -53,7 +59,7 @@ internal data class SessionFilenameInfo(
}

private fun findUuidInFilename(file: File): String {
val uuidWithTimestamp = file.name.substringAfter("_")
val uuidWithTimestamp = file.name.substringAfter('_')
val uuidName = if (uuidWithTimestamp.length >= uuidLength) {
uuidWithTimestamp.take(uuidLength)
} else {
Expand All @@ -64,15 +70,19 @@ internal data class SessionFilenameInfo(

@JvmStatic
fun findTimestampInFilename(file: File): Long {
return file.name.substringAfter("_").drop(uuidLength)
return file.name.substringAfter('_')
.drop(uuidLength)
.substringBefore('_')
.toLongOrNull() ?: -1
}

fun findApiKeyInFilename(file: File, config: ImmutableConfig): String {
val apiKey = if (file.name.indexOf("_") == 0) {
val apiKeyEnd = file.name.indexOf('_')

val apiKey = if (apiKeyEnd <= 0) {
null
} else {
file.name.substringBefore("_", missingDelimiterValue = "-1")
file.name.substring(0, apiKeyEnd)
}
return apiKey.takeUnless { it.isNullOrBlank() } ?: config.apiKey
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ public int compare(File lhs, File rhs) {
SESSION_COMPARATOR,
logger,
delegate);
this.config =config;
this.config = config;
}

@NonNull
@Override
String getFilename(Object object) {
return SessionFilenameInfo.defaultFilename("", config);
SessionFilenameInfo sessionInfo
= SessionFilenameInfo.defaultFilename(object, config);
return sessionInfo.encode();
}

public boolean isTooOld(File file) {
Expand Down

0 comments on commit 27d7278

Please sign in to comment.