Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class DevelocityApiIntegrationTest {
@Test
fun canFetchBuildsWithDefaultConfig() = runTest {
env = RealEnv
keychain = realKeychain()
val api = DevelocityApi.newInstance(
config = Config(
cacheConfig = Config.CacheConfig(cacheEnabled = false)
Expand All @@ -33,7 +32,6 @@ class DevelocityApiIntegrationTest {
@Test
fun canBuildNewInstanceWithPureCodeConfiguration() = runTest {
env = FakeEnv()
keychain = FakeKeychain()
assertDoesNotThrow {
val config = Config(
apiUrl = "https://google.com/api/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class BuildsApiExtensionsIntegrationTest {

init {
env = RealEnv
keychain = realKeychain()
}

private val recorder = RequestRecorder()
Expand Down

This file was deleted.

18 changes: 4 additions & 14 deletions library/src/main/kotlin/com/gabrielfeo/develocity/api/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ data class Config(
?: error("DEVELOCITY_API_URL is required"),

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

/**
Expand Down Expand Up @@ -194,14 +195,3 @@ data class Config(
?: 1.days.inWholeSeconds,
)
}

internal fun requireEnvOrKeychainToken(): String {
if (systemProperties["os.name"] == "Mac OS X") {
when (val result = keychain.get("gradle-enterprise-api-token")) {
is KeychainResult.Success -> return result.token
is KeychainResult.Error -> {}
}
}
return env["DEVELOCITY_API_TOKEN"]
?: error("DEVELOCITY_API_TOKEN is required")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class CacheConfigTest {
@BeforeTest
fun before() {
env = FakeEnv("DEVELOCITY_API_URL" to "https://example.com/api/")
systemProperties = FakeSystemProperties.macOs
keychain = FakeKeychain()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class ConfigTest {
@BeforeTest
fun before() {
env = FakeEnv("DEVELOCITY_API_URL" to "https://example.com/api/")
systemProperties = FakeSystemProperties.macOs
keychain = FakeKeychain()
}

@Test
Expand All @@ -28,42 +26,16 @@ class ConfigTest {
}

@Test
fun `Given macOS and keychain token, keychain token used`() {
(env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar"
keychain = FakeKeychain("gradle-enterprise-api-token" to "foo")
assertEquals("foo", Config().apiToken())
}

@Test
fun `Given macOS but no keychain token, env token used`() {
(env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar"
assertEquals("bar", Config().apiToken())
}

@Test
fun `Given Linux, keychain never tried and env token used`() {
(env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar"
keychain = object : Keychain {
override fun get(entry: String) =
error("Error: Tried to access macOS keychain in Linux")
}
systemProperties = FakeSystemProperties.linux
assertEquals("bar", Config().apiToken())
}

@Test
fun `Given macOS and no token anywhere, error`() {
fun `Given no token, error`() {
assertFails {
Config().apiToken()
}
}

@Test
fun `Given Linux and no env token, fails`() {
systemProperties = FakeSystemProperties.linux
assertFails {
Config().apiToken()
}
fun `Given token set in env, apiToken is env token`() {
(env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar"
assertEquals("bar", Config().apiToken())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class DevelocityApiTest {
@Test
fun `Fails eagerly if no API URL`() {
env = FakeEnv()
keychain = FakeKeychain()
systemProperties = FakeSystemProperties.linux
val error = assertThrows<Exception> {
DevelocityApi.newInstance(Config())
}
Expand All @@ -22,8 +20,6 @@ class DevelocityApiTest {
@Test
fun `Fails lazily if no API token`() {
env = FakeEnv("DEVELOCITY_API_URL" to "example-url")
keychain = FakeKeychain()
systemProperties = FakeSystemProperties.linux
val api = assertDoesNotThrow {
DevelocityApi.newInstance(Config())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gabrielfeo.develocity.api

import com.gabrielfeo.develocity.api.internal.*
import com.gabrielfeo.develocity.api.internal.FakeKeychain
import com.gabrielfeo.develocity.api.internal.auth.HttpBearerAuth
import com.gabrielfeo.develocity.api.internal.caching.CacheEnforcingInterceptor
import com.gabrielfeo.develocity.api.internal.caching.CacheHitLoggingInterceptor
Expand Down Expand Up @@ -72,8 +71,6 @@ class OkHttpClientTest {
if ("DEVELOCITY_API_URL" !in fakeEnv)
fakeEnv["DEVELOCITY_API_URL"] = "example-url"
env = fakeEnv
systemProperties = FakeSystemProperties.macOs
keychain = FakeKeychain()
val config = when (clientBuilder) {
null -> Config()
else -> Config(clientBuilder = clientBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class RetrofitTest {
if ("DEVELOCITY_API_TOKEN" !in fakeEnv)
fakeEnv["DEVELOCITY_API_TOKEN"] = "example-token"
env = fakeEnv
systemProperties = FakeSystemProperties.macOs
keychain = FakeKeychain()
val config = Config()
return buildRetrofit(
config = config,
Expand Down

This file was deleted.

This file was deleted.