From b0cda75132431a397225266dba12b82be15b6be7 Mon Sep 17 00:00:00 2001 From: Paul Rosca Date: Thu, 22 Aug 2024 14:55:31 +0300 Subject: [PATCH] fix!: improve interoperability of SNYK_API environment variable BREAKING CHANGE: The SNYK_API environment variable should be set to the same value as intended for the Snyk CLI and no longer requires the "/rest" suffix. Instead, only the base URL of the Snyk API shall be used. To adapt to the new version, change the SNYK_API environment variable to omit the "/rest", e.g. `SNYK_API="https://api.snyk.io`. --- README.md | 2 +- lib/snyk/self.go | 2 +- snyk/issues/issues.go | 1 + snyk/users/users.go | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f47fbde..0bed157 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ It's important to note vulnerability data is moment-in-time information. By addi Note the Snyk commands require you to be a Snyk customer, and require passing a valid Snyk API token in the `SNYK_TOKEN` environment variable. -The API base url can be set using the `SNYK_API` environment variable, and if missing it will default to `https://api.snyk.io/rest`. +The API base url can be set using the `SNYK_API` environment variable, and if missing it will default to `https://api.snyk.io`. ``` parlay snyk enrich testing/sbom.cyclonedx.json diff --git a/lib/snyk/self.go b/lib/snyk/self.go index 9a44432..d4fa25d 100644 --- a/lib/snyk/self.go +++ b/lib/snyk/self.go @@ -88,5 +88,5 @@ func APIBaseURL() string { if snykApiEnv != "" { return snykApiEnv } - return "https://api.snyk.io/rest" + return "https://api.snyk.io" } diff --git a/snyk/issues/issues.go b/snyk/issues/issues.go index 242c665..484eaf1 100644 --- a/snyk/issues/issues.go +++ b/snyk/issues/issues.go @@ -548,6 +548,7 @@ func NewClient(server string, opts ...ClientOption) (*Client, error) { if !strings.HasSuffix(client.Server, "/") { client.Server += "/" } + client.Server += "rest/" // create httpClient, if not already present if client.Client == nil { client.Client = &http.Client{} diff --git a/snyk/users/users.go b/snyk/users/users.go index 93ac2b9..2db3af5 100644 --- a/snyk/users/users.go +++ b/snyk/users/users.go @@ -497,6 +497,7 @@ func NewClient(server string, opts ...ClientOption) (*Client, error) { if !strings.HasSuffix(client.Server, "/") { client.Server += "/" } + client.Server += "rest/" // create httpClient, if not already present if client.Client == nil { client.Client = &http.Client{}