Skip to content

Commit

Permalink
chore: change check for fedramp to rely on the snykgov.io domain only
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Aug 31, 2023
1 parent 59e4611 commit 6ff532e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/main/kotlin/snyk/common/CustomEndpoints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,38 @@ internal fun resolveCustomEndpoint(endpointUrl: String?): String {
}

fun URI.isSnykTenant() =
isSnykDomain() && (host.startsWith("app.") || host == "snyk.io" || isDev()) && path.endsWith("/api")
isSnykDomain() &&
path.lowercase().endsWith("/api") &&
(host.lowercase().startsWith("app.") ||

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning

Missing newline after "("

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning

Missing newline before ")"
host.lowercase() == "snyk.io" ||
isDev())

fun URI.isSnykApi() = isSnykDomain() && (host.startsWith("api.") || path.endsWith("/api"))
fun URI.isSnykApi() = isSnykDomain() && (host.lowercase().startsWith("api.") || path.lowercase().endsWith("/api"))

fun URI.toSnykAPIv1(): URI {
val host = host
val host = host.lowercase()
.replaceFirst("app.", "api.")
.replaceFirst("deeproxy.", "api.")
.prefixIfNot("api.")

return URI(scheme, host, "/v1/", null)
}

fun URI.isSnykDomain() = host != null && (host.endsWith("snyk.io") || host.endsWith("snykgov.io"))
fun URI.isSnykDomain() = host != null &&
(

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning

Missing newline before ")"
host.lowercase().endsWith(".snyk.io") ||
host.lowercase() == "snyk.io" ||
host.lowercase().endsWith(".snykgov.io"))

fun URI.isDeeproxy() = isSnykDomain() && host.startsWith("deeproxy.")
fun URI.isDeeproxy() = isSnykDomain() && host.lowercase().startsWith("deeproxy.")

fun URI.isOauth() = host != null && host.endsWith(".snykgov.io")
fun URI.isSnykGov() = host != null && host.lowercase().endsWith(".snykgov.io")

fun URI.isDev() = isSnykDomain() && host.startsWith("dev.")
fun URI.isOauth() = isSnykGov()

fun URI.isFedramp() = isOauth() && host.contains("fedramp")
fun URI.isDev() = isSnykDomain() && host.lowercase().startsWith("dev.")

fun URI.isFedramp() = isSnykGov()

fun isFedramp(): Boolean {
val settings = pluginSettings()
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/snyk/common/CustomEndpointsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class CustomEndpointsTest {

@Test
fun `isSnykAPI false for api subdomain and not snyk domain`() {
val uri = URI("https://api.NOTSNYK.io")
val uri = URI("https://api.notsnyk.io")
assertFalse(uri.isSnykApi())
}

Expand Down Expand Up @@ -171,7 +171,7 @@ class CustomEndpointsTest {

@Test
fun `isFedramp false for the right URI`() {
val uri = URI("https://app.fedddramp.snykgov.io")
val uri = URI("https://app.fedddramp.snykagov.io")
assertFalse(uri.isFedramp())
}
}

0 comments on commit 6ff532e

Please sign in to comment.