Skip to content

Commit 53e95df

Browse files
authored
Delete keychain support (#189)
Deprecated in #164 / 2023.4.0 (last release).
1 parent feb9db9 commit 53e95df

File tree

12 files changed

+8
-157
lines changed

12 files changed

+8
-157
lines changed

library/src/integrationTest/kotlin/com/gabrielfeo/develocity/api/DevelocityApiIntegrationTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class DevelocityApiIntegrationTest {
1515
@Test
1616
fun canFetchBuildsWithDefaultConfig() = runTest {
1717
env = RealEnv
18-
keychain = realKeychain()
1918
val api = DevelocityApi.newInstance(
2019
config = Config(
2120
cacheConfig = Config.CacheConfig(cacheEnabled = false)
@@ -33,7 +32,6 @@ class DevelocityApiIntegrationTest {
3332
@Test
3433
fun canBuildNewInstanceWithPureCodeConfiguration() = runTest {
3534
env = FakeEnv()
36-
keychain = FakeKeychain()
3735
assertDoesNotThrow {
3836
val config = Config(
3937
apiUrl = "https://google.com/api/",

library/src/integrationTest/kotlin/com/gabrielfeo/develocity/api/extension/BuildsApiExtensionsIntegrationTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class BuildsApiExtensionsIntegrationTest {
1616

1717
init {
1818
env = RealEnv
19-
keychain = realKeychain()
2019
}
2120

2221
private val recorder = RequestRecorder()

library/src/integrationTest/kotlin/com/gabrielfeo/develocity/api/internal/KeychainIntegrationTest.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

library/src/main/kotlin/com/gabrielfeo/develocity/api/Config.kt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ data class Config(
3232
?: error("DEVELOCITY_API_URL is required"),
3333

3434
/**
35-
* Provides the access token for a Develocity API instance. By default, uses keychain entry
36-
* `gradle-enterprise-api-token` or environment variable `DEVELOCITY_API_TOKEN`.
35+
* Provides the access token for a Develocity API instance. By default, uses environment
36+
* variable `DEVELOCITY_API_TOKEN`.
3737
*/
3838
val apiToken: () -> String = {
39-
requireEnvOrKeychainToken()
39+
env["DEVELOCITY_API_TOKEN"]
40+
?: error("DEVELOCITY_API_TOKEN is required")
4041
},
4142

4243
/**
@@ -194,14 +195,3 @@ data class Config(
194195
?: 1.days.inWholeSeconds,
195196
)
196197
}
197-
198-
internal fun requireEnvOrKeychainToken(): String {
199-
if (systemProperties["os.name"] == "Mac OS X") {
200-
when (val result = keychain.get("gradle-enterprise-api-token")) {
201-
is KeychainResult.Success -> return result.token
202-
is KeychainResult.Error -> {}
203-
}
204-
}
205-
return env["DEVELOCITY_API_TOKEN"]
206-
?: error("DEVELOCITY_API_TOKEN is required")
207-
}

library/src/main/kotlin/com/gabrielfeo/develocity/api/internal/Keychain.kt

Lines changed: 0 additions & 51 deletions
This file was deleted.

library/src/test/kotlin/com/gabrielfeo/develocity/api/CacheConfigTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class CacheConfigTest {
88
@BeforeTest
99
fun before() {
1010
env = FakeEnv("DEVELOCITY_API_URL" to "https://example.com/api/")
11-
systemProperties = FakeSystemProperties.macOs
12-
keychain = FakeKeychain()
1311
}
1412

1513
@Test

library/src/test/kotlin/com/gabrielfeo/develocity/api/ConfigTest.kt

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class ConfigTest {
99
@BeforeTest
1010
fun before() {
1111
env = FakeEnv("DEVELOCITY_API_URL" to "https://example.com/api/")
12-
systemProperties = FakeSystemProperties.macOs
13-
keychain = FakeKeychain()
1412
}
1513

1614
@Test
@@ -28,42 +26,16 @@ class ConfigTest {
2826
}
2927

3028
@Test
31-
fun `Given macOS and keychain token, keychain token used`() {
32-
(env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar"
33-
keychain = FakeKeychain("gradle-enterprise-api-token" to "foo")
34-
assertEquals("foo", Config().apiToken())
35-
}
36-
37-
@Test
38-
fun `Given macOS but no keychain token, env token used`() {
39-
(env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar"
40-
assertEquals("bar", Config().apiToken())
41-
}
42-
43-
@Test
44-
fun `Given Linux, keychain never tried and env token used`() {
45-
(env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar"
46-
keychain = object : Keychain {
47-
override fun get(entry: String) =
48-
error("Error: Tried to access macOS keychain in Linux")
49-
}
50-
systemProperties = FakeSystemProperties.linux
51-
assertEquals("bar", Config().apiToken())
52-
}
53-
54-
@Test
55-
fun `Given macOS and no token anywhere, error`() {
29+
fun `Given no token, error`() {
5630
assertFails {
5731
Config().apiToken()
5832
}
5933
}
6034

6135
@Test
62-
fun `Given Linux and no env token, fails`() {
63-
systemProperties = FakeSystemProperties.linux
64-
assertFails {
65-
Config().apiToken()
66-
}
36+
fun `Given token set in env, apiToken is env token`() {
37+
(env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar"
38+
assertEquals("bar", Config().apiToken())
6739
}
6840

6941
@Test

library/src/test/kotlin/com/gabrielfeo/develocity/api/DevelocityApiTest.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ class DevelocityApiTest {
1111
@Test
1212
fun `Fails eagerly if no API URL`() {
1313
env = FakeEnv()
14-
keychain = FakeKeychain()
15-
systemProperties = FakeSystemProperties.linux
1614
val error = assertThrows<Exception> {
1715
DevelocityApi.newInstance(Config())
1816
}
@@ -22,8 +20,6 @@ class DevelocityApiTest {
2220
@Test
2321
fun `Fails lazily if no API token`() {
2422
env = FakeEnv("DEVELOCITY_API_URL" to "example-url")
25-
keychain = FakeKeychain()
26-
systemProperties = FakeSystemProperties.linux
2723
val api = assertDoesNotThrow {
2824
DevelocityApi.newInstance(Config())
2925
}

library/src/test/kotlin/com/gabrielfeo/develocity/api/OkHttpClientTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.gabrielfeo.develocity.api
22

33
import com.gabrielfeo.develocity.api.internal.*
4-
import com.gabrielfeo.develocity.api.internal.FakeKeychain
54
import com.gabrielfeo.develocity.api.internal.auth.HttpBearerAuth
65
import com.gabrielfeo.develocity.api.internal.caching.CacheEnforcingInterceptor
76
import com.gabrielfeo.develocity.api.internal.caching.CacheHitLoggingInterceptor
@@ -72,8 +71,6 @@ class OkHttpClientTest {
7271
if ("DEVELOCITY_API_URL" !in fakeEnv)
7372
fakeEnv["DEVELOCITY_API_URL"] = "example-url"
7473
env = fakeEnv
75-
systemProperties = FakeSystemProperties.macOs
76-
keychain = FakeKeychain()
7774
val config = when (clientBuilder) {
7875
null -> Config()
7976
else -> Config(clientBuilder = clientBuilder)

library/src/test/kotlin/com/gabrielfeo/develocity/api/RetrofitTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class RetrofitTest {
3232
if ("DEVELOCITY_API_TOKEN" !in fakeEnv)
3333
fakeEnv["DEVELOCITY_API_TOKEN"] = "example-token"
3434
env = fakeEnv
35-
systemProperties = FakeSystemProperties.macOs
36-
keychain = FakeKeychain()
3735
val config = Config()
3836
return buildRetrofit(
3937
config = config,

0 commit comments

Comments
 (0)