Skip to content

Commit

Permalink
feat: get snyk api endpoint from env
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrosca-snyk committed Apr 1, 2024
1 parent 4391914 commit 6fdc1fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/snyk/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
)

const (
snykServer = "https://api.snyk.io/rest"
version = "2023-04-28"
snykAdvisorServer = "https://snyk.io/advisor"
snykVulnDBServer = "https://security.snyk.io/package"
Expand Down Expand Up @@ -86,7 +85,7 @@ func SnykVulnURL(purl *packageurl.PackageURL) string {
}

func GetPackageVulnerabilities(purl *packageurl.PackageURL, auth *securityprovider.SecurityProviderApiKey, orgID *uuid.UUID) (*issues.FetchIssuesPerPurlResponse, error) {
client, err := issues.NewClientWithResponses(snykServer, issues.WithRequestEditorFn(auth.Intercept))
client, err := issues.NewClientWithResponses(APIEndpoint(), issues.WithRequestEditorFn(auth.Intercept))
if err != nil {
return nil, err
}
Expand Down
10 changes: 9 additions & 1 deletion lib/snyk/self.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type selfDocument struct {
}

func SnykOrgID(auth *securityprovider.SecurityProviderApiKey) (*uuid.UUID, error) {
experimental, err := users.NewClientWithResponses(snykServer, users.WithRequestEditorFn(auth.Intercept))
experimental, err := users.NewClientWithResponses(APIEndpoint(), users.WithRequestEditorFn(auth.Intercept))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -82,3 +82,11 @@ func AuthFromToken(token string) (*securityprovider.SecurityProviderApiKey, erro
func APIToken() string {
return os.Getenv("SNYK_TOKEN")
}

func APIEndpoint() string {
snykApiEnv := os.Getenv("SNYK_API")
if snykApiEnv != "" {
return snykApiEnv
}
return "https://api.snyk.io/rest"
}

0 comments on commit 6fdc1fa

Please sign in to comment.