Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added

## [1.5.2] - 2025-11-07
### Added
- Added Custom Contents URL support (`SCANOSS_FILE_CONTENTS_URL`)

## [1.5.1]- 2025-10-0
### Added
- Removed `Content-Length` from header as it is reported with Loadbalancer
Expand Down Expand Up @@ -153,4 +159,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[1.4.5]: https://github.com/scanoss/api.go/compare/v1.4.4...v1.4.5
[1.4.5]: https://github.com/scanoss/api.go/compare/v1.4.4...v1.4.5
[1.5.0]: https://github.com/scanoss/api.go/compare/v1.4.5...v1.5.0

[1.5.1]: https://github.com/scanoss/api.go/compare/v1.5.0...v1.5.1
[1.5.2]: https://github.com/scanoss/api.go/compare/v1.5.1...v1.5.2
24 changes: 22 additions & 2 deletions pkg/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,35 @@ func setupEnvVars(cfg *myconfig.ServerConfig) {
zlog.S.Infof("Failed to set alternative SCANOSS_API_URL value to %s: %v", cfg.Scanning.ScanningURL, err)
}
}
if customURL := os.Getenv("SCANOSS_API_URL"); len(customURL) > 0 {
var contentsURL string
customURL := os.Getenv("SCANOSS_API_URL")
if len(customURL) > 0 {
zlog.S.Infof("Using custom API URL: %s", customURL)
customURL = strings.TrimSuffix(customURL, "/")
contentsURL = fmt.Sprintf("%s/file_contents", customURL) // Assume the contents URL from the scanning URL
}
if len(cfg.Scanning.FileContentsURL) > 0 {
contentsURL = cfg.Scanning.FileContentsURL // We have an explicit contents URL specified. Use it
}
if len(contentsURL) > 0 {
err := os.Setenv("SCANOSS_FILE_CONTENTS_URL", contentsURL)
if err != nil {
zlog.S.Infof("Failed to set SCANOSS_FILE_CONTENTS_URL value to %v: %v", contentsURL, err)
}
}
if customContentsURL := os.Getenv("SCANOSS_FILE_CONTENTS_URL"); len(customContentsURL) > 0 {
zlog.S.Infof("Using custom content URL: %s.", customContentsURL)
}
err := os.Setenv("SCANOSS_FILE_CONTENTS", fmt.Sprintf("%v", cfg.Scanning.FileContents))
if err != nil {
zlog.S.Infof("Failed to set SCANOSS_FILE_CONTENTS SCANOSS_API_URL value to %v: %v", cfg.Scanning.FileContents, err)
zlog.S.Infof("Failed to set SCANOSS_FILE_CONTENTS value to %v: %v", cfg.Scanning.FileContents, err)
}
if customContents := os.Getenv("SCANOSS_FILE_CONTENTS"); len(customContents) > 0 && customContents == "false" {
zlog.S.Infof("Skipping file_url datafield.")
err2 := os.Setenv("SCANOSS_FILE_CONTENTS_URL", customContents) // Force the contents URL to say 'false' also
if err2 != nil {
zlog.S.Infof("Failed to set SCANOSS_FILE_CONTENTS_URL value to %v: %v", customContents, err)
}
}
}

Expand Down
29 changes: 15 additions & 14 deletions pkg/config/server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ type ServerConfig struct {
OltpExporter string `env:"OTEL_EXPORTER_OLTP"` // OTEL OLTP exporter (default 0.0.0.0:4317)
}
Scanning struct {
WfpLoc string `env:"SCAN_WFP_TMP"` // specific location to write temporary WFP files to
ScanBinary string `env:"SCAN_BINARY"` // Binary to use for scanning
ScanKbName string `env:"SCAN_KB_NAME"` // KB name passed as "-n" parameter to the scanoss command
ScanDebug bool `env:"SCAN_DEBUG"` // true/false
ScanFlags int `env:"SCAN_ENGINE_FLAGS"` // Default flags to use when scanning
ScanTimeout int `env:"SCAN_ENGINE_TIMEOUT"` // timeout for waiting for the scan engine to respond
WfpGrouping int `env:"SCAN_WFP_GROUPING"` // number of WFP to group into a single scan engine command
Workers int `env:"SCAN_WORKERS"` // Number of concurrent workers to use per scan request
TmpFileDelete bool `env:"SCAN_TMP_DELETE"` // true/false
KeepFailedWfps bool `env:"SCAN_KEEP_FAILED_WFP"` // true/false
ScanningURL string `env:"SCANOSS_API_URL"` // URL to present back in API responses - default https://osskb.org/api
HPSMEnabled bool `env:"SCAN_HPSM_ENABLED"` // Enable HPSM (High Precision Snippet Matching) or not (default true)
FileContents bool `env:"SCANOSS_FILE_CONTENTS"` // Show matched file URL in scan results (default true)
LoadKbDetails bool `env:"SCANOSS_LOAD_KB_DETAILS"` // Load the version of the KB into the service for reporting
WfpLoc string `env:"SCAN_WFP_TMP"` // specific location to write temporary WFP files to
ScanBinary string `env:"SCAN_BINARY"` // Binary to use for scanning
ScanKbName string `env:"SCAN_KB_NAME"` // KB name passed as "-n" parameter to the scanoss command
ScanDebug bool `env:"SCAN_DEBUG"` // true/false
ScanFlags int `env:"SCAN_ENGINE_FLAGS"` // Default flags to use when scanning
ScanTimeout int `env:"SCAN_ENGINE_TIMEOUT"` // timeout for waiting for the scan engine to respond
WfpGrouping int `env:"SCAN_WFP_GROUPING"` // number of WFP to group into a single scan engine command
Workers int `env:"SCAN_WORKERS"` // Number of concurrent workers to use per scan request
TmpFileDelete bool `env:"SCAN_TMP_DELETE"` // true/false
KeepFailedWfps bool `env:"SCAN_KEEP_FAILED_WFP"` // true/false
ScanningURL string `env:"SCANOSS_API_URL"` // URL to present back in API responses - default https://osskb.org/api
HPSMEnabled bool `env:"SCAN_HPSM_ENABLED"` // Enable HPSM (High Precision Snippet Matching) or not (default true)
FileContents bool `env:"SCANOSS_FILE_CONTENTS"` // Show matched file URL in scan results (default true)
FileContentsURL string `env:"SCANOSS_FILE_CONTENTS_URL"` // Explicit file contents URL to use for the engine
LoadKbDetails bool `env:"SCANOSS_LOAD_KB_DETAILS"` // Load the version of the KB into the service for reporting
}
TLS struct {
CertFile string `env:"SCAN_TLS_CERT"` // TLS Certificate
Expand Down
4 changes: 4 additions & 0 deletions pkg/service/filecontents_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (s APIService) FileContents(w http.ResponseWriter, r *http.Request) {
}
zs := sugaredLogger(logContext) // Setup logger with context
logRequestDetails(r, zs)
if !s.config.Scanning.FileContents {
zs.Warn("File contents retrieval is disabled.")
http.Error(w, "ERROR file contents disabled", http.StatusForbidden)
}
vars := mux.Vars(r)
zs.Debugf("%v request from %v - %v", r.URL.Path, r.RemoteAddr, vars)
if len(vars) == 0 {
Expand Down
Loading