Skip to content

Commit

Permalink
fix: append v1 suffix conditionally (#531)
Browse files Browse the repository at this point in the history
* fix: sast settings call by appending /v1

* fix: do not add /v1 to deeproxy APIs

* chore: CHANGELOG

* fix: don't retrieve feature flag status or scan via LS if token is not present

Co-authored-by: [email protected]

* test: add unit test for custom endpoint with /v1
  • Loading branch information
teodora-sandu authored May 23, 2024
1 parent bf772d7 commit 2eb8c47
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Snyk Security Changelog

## [2.7.21]

### Fixed
- Append /v1 to the endpoint when necessary

## [2.7.20]
### Added
- (LS OSS) Starts rendering the Tree Nodes for OSS via the LS
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/snyk/plugin/SnykPostStartupActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class SnykPostStartupActivity : ProjectActivity {
getKubernetesImageCache(project)?.cacheKubernetesFileFromProject()
}

if (settings.scanOnSave && (isSnykCodeLSEnabled() || isSnykOSSLSEnabled() || isSnykIaCLSEnabled())) {
if (!settings.token.isNullOrBlank() && settings.scanOnSave && (isSnykCodeLSEnabled() || isSnykOSSLSEnabled() || isSnykIaCLSEnabled())) {
getSnykTaskQueueService(project)?.scan(true)
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/snyk/common/CustomEndpoints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ fun toSnykCodeApiUrl(endpointUrl: String?): String {
uri.isDev() ->
endpoint
.replace("api.", "")
.replace("/v1", "")
.replace("https://dev.", "https://$codeSubdomain.dev.")
.suffixIfNot("/")

uri.isSnykTenant() ->
endpoint
.replace("https://api.", "https://")
.replace("/v1", "")
.replace("https://", "https://$codeSubdomain.")
.suffixIfNot("/")

Expand Down Expand Up @@ -73,7 +75,8 @@ fun getEndpointUrl(): String {
""
}
val customEndpointUrl = resolveCustomEndpoint(endpointUrl)
return customEndpointUrl.removeTrailingSlashesIfPresent()
// we need to set v1 here, to make the sast-enabled calls work in LS
return customEndpointUrl.removeTrailingSlashesIfPresent().suffixIfNot("/v1")
}

fun isSnykCodeAvailable(endpointUrl: String?): Boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class LanguageServerWrapper(
}

private fun getFeatureFlagStatusInternal(featureFlag: String): Boolean {
if (!isSnykCodeLSEnabled()) {
if (!(isSnykCodeLSEnabled() || isSnykOSSLSEnabled() || isSnykIaCLSEnabled()) || pluginSettings().token.isNullOrBlank()) {
return false
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/kotlin/snyk/common/CustomEndpointsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ class CustomEndpointsTest {
fun `toSnykCodeApiUrl returns correct deeproxy url for SaaS deployments using api url`() {
val apiUrlForProduction = toSnykCodeApiUrl("https://api.eu.snyk.io")
val apiUrlForDevelopment = toSnykCodeApiUrl("https://dev.api.eu.snyk.io")
val apiUrlForWithV1 = toSnykCodeApiUrl("https://api.eu.snyk.io/v1")

assertEquals("https://deeproxy.eu.snyk.io/", apiUrlForProduction)
assertEquals("https://deeproxy.dev.eu.snyk.io/", apiUrlForDevelopment)
assertEquals("https://deeproxy.eu.snyk.io/", apiUrlForWithV1)
}

@Test
Expand Down

0 comments on commit 2eb8c47

Please sign in to comment.