Skip to content

Commit 2eb8c47

Browse files
fix: append v1 suffix conditionally (#531)
* 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
1 parent bf772d7 commit 2eb8c47

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Snyk Security Changelog
22

3+
## [2.7.21]
4+
5+
### Fixed
6+
- Append /v1 to the endpoint when necessary
7+
38
## [2.7.20]
49
### Added
510
- (LS OSS) Starts rendering the Tree Nodes for OSS via the LS

src/main/kotlin/io/snyk/plugin/SnykPostStartupActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class SnykPostStartupActivity : ProjectActivity {
115115
getKubernetesImageCache(project)?.cacheKubernetesFileFromProject()
116116
}
117117

118-
if (settings.scanOnSave && (isSnykCodeLSEnabled() || isSnykOSSLSEnabled() || isSnykIaCLSEnabled())) {
118+
if (!settings.token.isNullOrBlank() && settings.scanOnSave && (isSnykCodeLSEnabled() || isSnykOSSLSEnabled() || isSnykIaCLSEnabled())) {
119119
getSnykTaskQueueService(project)?.scan(true)
120120
}
121121

src/main/kotlin/snyk/common/CustomEndpoints.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ fun toSnykCodeApiUrl(endpointUrl: String?): String {
2121
uri.isDev() ->
2222
endpoint
2323
.replace("api.", "")
24+
.replace("/v1", "")
2425
.replace("https://dev.", "https://$codeSubdomain.dev.")
2526
.suffixIfNot("/")
2627

2728
uri.isSnykTenant() ->
2829
endpoint
2930
.replace("https://api.", "https://")
31+
.replace("/v1", "")
3032
.replace("https://", "https://$codeSubdomain.")
3133
.suffixIfNot("/")
3234

@@ -73,7 +75,8 @@ fun getEndpointUrl(): String {
7375
""
7476
}
7577
val customEndpointUrl = resolveCustomEndpoint(endpointUrl)
76-
return customEndpointUrl.removeTrailingSlashesIfPresent()
78+
// we need to set v1 here, to make the sast-enabled calls work in LS
79+
return customEndpointUrl.removeTrailingSlashesIfPresent().suffixIfNot("/v1")
7780
}
7881

7982
fun isSnykCodeAvailable(endpointUrl: String?): Boolean {

src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class LanguageServerWrapper(
271271
}
272272

273273
private fun getFeatureFlagStatusInternal(featureFlag: String): Boolean {
274-
if (!isSnykCodeLSEnabled()) {
274+
if (!(isSnykCodeLSEnabled() || isSnykOSSLSEnabled() || isSnykIaCLSEnabled()) || pluginSettings().token.isNullOrBlank()) {
275275
return false
276276
}
277277

src/test/kotlin/snyk/common/CustomEndpointsTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ class CustomEndpointsTest {
107107
fun `toSnykCodeApiUrl returns correct deeproxy url for SaaS deployments using api url`() {
108108
val apiUrlForProduction = toSnykCodeApiUrl("https://api.eu.snyk.io")
109109
val apiUrlForDevelopment = toSnykCodeApiUrl("https://dev.api.eu.snyk.io")
110+
val apiUrlForWithV1 = toSnykCodeApiUrl("https://api.eu.snyk.io/v1")
110111

111112
assertEquals("https://deeproxy.eu.snyk.io/", apiUrlForProduction)
112113
assertEquals("https://deeproxy.dev.eu.snyk.io/", apiUrlForDevelopment)
114+
assertEquals("https://deeproxy.eu.snyk.io/", apiUrlForWithV1)
113115
}
114116

115117
@Test

0 commit comments

Comments
 (0)