Skip to content

Commit

Permalink
NodeSupport: Remove the now unused read*FromNpmRc() functions
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io>
  • Loading branch information
sschuberth committed Mar 18, 2022
1 parent 68adcc8 commit 25f1734
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
43 changes: 0 additions & 43 deletions analyzer/src/main/kotlin/managers/utils/NodeSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ import java.nio.file.PathMatcher
import org.ossreviewtoolkit.model.readJsonFile
import org.ossreviewtoolkit.utils.common.collectMessagesAsString
import org.ossreviewtoolkit.utils.common.toUri
import org.ossreviewtoolkit.utils.core.AuthenticatedProxy
import org.ossreviewtoolkit.utils.core.ProtocolProxyMap
import org.ossreviewtoolkit.utils.core.determineProxyFromURL
import org.ossreviewtoolkit.utils.core.log
import org.ossreviewtoolkit.utils.core.showStackTrace

Expand Down Expand Up @@ -112,46 +109,6 @@ fun expandNpmShortcutUrl(url: String): String {
}
}

/**
* Return all proxies defined in the provided [NPM configuration][npmRc].
*/
fun readProxySettingsFromNpmRc(npmRc: String): ProtocolProxyMap {
val map = mutableMapOf<String, MutableList<AuthenticatedProxy>>()

npmRc.lines().forEach { line ->
val keyAndValue = line.split('=', limit = 2).map { it.trim() }
if (keyAndValue.size != 2) return@forEach

val (key, value) = keyAndValue
when (key) {
"proxy" -> determineProxyFromURL(value)?.let {
map.getOrPut("http") { mutableListOf() } += it
}

"https-proxy" -> determineProxyFromURL(value)?.let {
map.getOrPut("https") { mutableListOf() } += it
}
}
}

return map
}

/**
* Return the npm registry defined in the provided [NPM configuration][npmRc] or null.
*/
fun readRegistryFromNpmRc(npmRc: String): String? {
npmRc.lines().forEach { line ->
val keyAndValue = line.split('=', limit = 2).map { it.trim() }
if (keyAndValue.size != 2) return@forEach

val (key, value) = keyAndValue
if (key == "registry") return value
}

return null
}

private val NPM_LOCK_FILES = listOf("npm-shrinkwrap.json", "package-lock.json")
private val YARN_LOCK_FILES = listOf("yarn.lock")

Expand Down
77 changes: 0 additions & 77 deletions analyzer/src/test/kotlin/managers/utils/NodeSupportTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@ import io.kotest.inspectors.forAll
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.collections.containExactly
import io.kotest.matchers.collections.containExactlyInAnyOrder
import io.kotest.matchers.maps.beEmpty as beEmptyMap
import io.kotest.matchers.maps.containExactly as containExactlyEntries
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe

import java.io.File

import org.ossreviewtoolkit.utils.common.safeMkdirs
import org.ossreviewtoolkit.utils.core.ProtocolProxyMap
import org.ossreviewtoolkit.utils.test.createTestTempDir
import org.ossreviewtoolkit.utils.test.toGenericString

class NodeSupportTest : WordSpec() {
companion object {
Expand Down Expand Up @@ -205,79 +201,6 @@ class NodeSupportTest : WordSpec() {
}
}
}

"readProxySettingFromNpmRc" should {
"properly read proxy configuration" {
fun ProtocolProxyMap.mapSingleValuesToString() =
mapValues { (_, proxies) ->
val (proxy, authentication) = proxies.single()
listOfNotNull(
proxy.toGenericString(),
authentication?.userName,
authentication?.password?.let { String(it) }
)
}

readProxySettingsFromNpmRc("""
proxy=http://user:password@host.tld:3129/
https-proxy=http://user:password@host.tld:3129/
""".trimIndent()
).mapSingleValuesToString() should containExactlyEntries(
"http" to listOf("HTTP @ host.tld:3129", "user", "password"),
"https" to listOf("HTTP @ host.tld:3129", "user", "password")
)

readProxySettingsFromNpmRc("""
proxy=http://user:password@host.tld
https-proxy=http://user:password@host.tld
""".trimIndent()
).mapSingleValuesToString() should containExactlyEntries(
"http" to listOf("HTTP @ host.tld:8080", "user", "password"),
"https" to listOf("HTTP @ host.tld:8080", "user", "password")
)

readProxySettingsFromNpmRc("""
proxy=user:password@host.tld
https-proxy=user:password@host.tld
""".trimIndent()
).mapSingleValuesToString() should containExactlyEntries(
"http" to listOf("HTTP @ host.tld:8080", "user", "password"),
"https" to listOf("HTTP @ host.tld:8080", "user", "password")
)

readProxySettingsFromNpmRc("""
proxy=host.tld
https-proxy=host.tld
""".trimIndent()
).mapSingleValuesToString() should containExactlyEntries(
"http" to listOf("HTTP @ host.tld:8080"),
"https" to listOf("HTTP @ host.tld:8080")
)
}

"ignore non-proxy URLs" {
readProxySettingsFromNpmRc("""
registry=http://my.artifactory.com/artifactory/api/npm/npm-virtual
""".trimIndent()
) should beEmptyMap()
}
}

"readRegistryFromNpmRc" should {
"properly read registry configuration" {
readRegistryFromNpmRc("""
registry=http://my.artifactory.com/artifactory/api/npm/npm-virtual
""".trimIndent()
) shouldBe "http://my.artifactory.com/artifactory/api/npm/npm-virtual"
}

"return null when no registry is defined" {
readRegistryFromNpmRc("""
""".trimIndent()
) shouldBe null
}
}
}

private lateinit var tempDir: File
Expand Down

0 comments on commit 25f1734

Please sign in to comment.