Skip to content

Commit 96785a1

Browse files
Merge pull request #37 from snyk/feat/add-legacy-json-org
feat: include organization slug in the legacy JSON output
2 parents a906715 + acd393c commit 96785a1

File tree

8 files changed

+29
-10
lines changed

8 files changed

+29
-10
lines changed

internal/commands/ostest/__snapshots__/sbom_reachability_flow_test.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"severities": null
2222
},
2323
"ok": false,
24-
"org": "",
24+
"org": "test-org-slug",
2525
"packageManager": "",
2626
"policy": "",
2727
"projectName": "",

internal/commands/ostest/depgraph_flow.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func RunUnifiedTestFlow(
2828
riskScoreThreshold *uint16,
2929
severityThreshold *testapi.Severity,
3030
orgID string,
31+
orgSlugOrID string,
3132
errFactory *errors.ErrorFactory,
3233
logger *zerolog.Logger,
3334
) ([]workflow.Data, error) {
@@ -46,6 +47,7 @@ func RunUnifiedTestFlow(
4647
ictx,
4748
testClient,
4849
orgID,
50+
orgSlugOrID,
4951
errFactory,
5052
logger,
5153
localPolicy,
@@ -65,6 +67,7 @@ func testAllDepGraphs(
6567
ictx workflow.InvocationContext,
6668
testClient testapi.TestClient,
6769
orgID string,
70+
orgSlugOrID string,
6871
errFactory *errors.ErrorFactory,
6972
logger *zerolog.Logger,
7073
localPolicy *testapi.LocalPolicy,
@@ -92,7 +95,7 @@ func testAllDepGraphs(
9295
// Run the test with the depgraph subject
9396
legacyFinding, outputData, err := RunTest(
9497
ctx, ictx, testClient, subject, projectName, packageManager, depCount,
95-
displayTargetFile, orgID, errFactory, logger, localPolicy)
98+
displayTargetFile, orgID, orgSlugOrID, errFactory, logger, localPolicy)
9699
if err != nil {
97100
return nil, nil, err
98101
}

internal/commands/ostest/sbom_reachability_flow.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func RunSbomReachabilityFlow(
2626
sourceCodePath string,
2727
bsClient bundlestore.Client,
2828
orgID string,
29+
orgSlugOrID string,
2930
) ([]workflow.Data, error) {
3031
if sourceCodePath == "" {
3132
sourceCodePath = "."
@@ -68,7 +69,7 @@ func RunSbomReachabilityFlow(
6869
return nil, fmt.Errorf("failed to create sbom test reachability subject: %w", err)
6970
}
7071

71-
findings, summary, err := RunTest(ctx, ictx, testClient, subject, "", "", int(0), "", orgID, errFactory, logger, nil)
72+
findings, summary, err := RunTest(ctx, ictx, testClient, subject, "", "", int(0), "", orgID, orgSlugOrID, errFactory, logger, nil)
7273
if err != nil {
7374
return nil, err
7475
}

internal/commands/ostest/sbom_reachability_flow_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func Test_RunSbomReachabilityFlow_Success(t *testing.T) {
3737
sbomPath := "./testdata/bom.json"
3838
sourceCodePath := "./testdata/test_dir"
3939
orgID := "test-org-id"
40+
orgSlug := "test-org-slug"
4041

4142
vulnTime, err := time.Parse(time.RFC3339, "2025-07-28T17:11:43+03:00")
4243
require.NoError(t, err)
@@ -156,14 +157,15 @@ func Test_RunSbomReachabilityFlow_Success(t *testing.T) {
156157
mockBsClient.EXPECT().UploadSBOM(ctx, sbomPath).Return("test-sbom-hash", nil).Times(1)
157158
mockBsClient.EXPECT().UploadSourceCode(ctx, sourceCodePath).Return("test-source-hash", nil).Times(1)
158159

159-
// Mock Invocation COntext
160+
// Mock Invocation Context
160161
mockConfig := configuration.New()
161162
mockConfig.Set(outputworkflow.OutputConfigKeyJSON, true)
163+
mockConfig.Set(configuration.ORGANIZATION_SLUG, orgSlug)
162164
mockIctx := gafmocks.NewMockInvocationContext(ctrl)
163-
mockIctx.EXPECT().GetConfiguration().Return(mockConfig).Times(1)
165+
mockIctx.EXPECT().GetConfiguration().Return(mockConfig).AnyTimes()
164166

165167
// This should now succeed with proper finding data
166-
result, err := ostest.RunSbomReachabilityFlow(ctx, mockIctx, mockTestClient, ef, &logger, sbomPath, sourceCodePath, mockBsClient, orgID)
168+
result, err := ostest.RunSbomReachabilityFlow(ctx, mockIctx, mockTestClient, ef, &logger, sbomPath, sourceCodePath, mockBsClient, orgID, orgSlug)
167169

168170
require.NoError(t, err)
169171
require.NotNil(t, result)

internal/commands/ostest/test_execution.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func RunTest(
4343
depCount int,
4444
displayTargetFile string,
4545
orgID string,
46+
orgSlugOrID string,
4647
errFactory *errors.ErrorFactory,
4748
logger *zerolog.Logger,
4849
localPolicy *testapi.LocalPolicy,
@@ -71,6 +72,7 @@ func RunTest(
7172
legacyParams := &transform.SnykSchemaToLegacyParams{
7273
Findings: findingsData,
7374
TestResult: finalResult,
75+
OrgSlugOrID: orgSlugOrID,
7476
ProjectName: projectName,
7577
PackageManager: packageManager,
7678
CurrentDir: currentDir,

internal/commands/ostest/workflow.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func setupSBOMReachabilityFlow(
7878
ictx workflow.InvocationContext,
7979
testClient testapi.TestClient,
8080
orgID string,
81+
orgSlugOrID string,
8182
errFactory *errors.ErrorFactory,
8283
logger *zerolog.Logger,
8384
sbom, sourceDir string,
@@ -104,7 +105,7 @@ func setupSBOMReachabilityFlow(
104105
)
105106

106107
bsClient := bundlestore.NewClient(ictx.GetNetworkAccess().GetHttpClient(), codeScannerConfig, cScanner, logger)
107-
return RunSbomReachabilityFlow(ctx, ictx, testClient, errFactory, logger, sbom, sourceDir, bsClient, orgID)
108+
return RunSbomReachabilityFlow(ctx, ictx, testClient, errFactory, logger, sbom, sourceDir, bsClient, orgID, orgSlugOrID)
108109
}
109110

110111
// setupDefaultTestFlow sets up and runs the default test flow with risk score and severity thresholds.
@@ -113,6 +114,7 @@ func setupDefaultTestFlow(
113114
ictx workflow.InvocationContext,
114115
testClient testapi.TestClient,
115116
orgID string,
117+
orgSlugOrID string,
116118
errFactory *errors.ErrorFactory,
117119
logger *zerolog.Logger,
118120
riskScoreThreshold int,
@@ -151,7 +153,7 @@ func setupDefaultTestFlow(
151153
severityThresholdPtr = &st
152154
}
153155

154-
return RunUnifiedTestFlow(ctx, ictx, testClient, riskScorePtr, severityThresholdPtr, orgID, errFactory, logger)
156+
return RunUnifiedTestFlow(ctx, ictx, testClient, riskScorePtr, severityThresholdPtr, orgID, orgSlugOrID, errFactory, logger)
155157
}
156158

157159
// OSWorkflow is the entry point for the Open Source Test workflow.
@@ -195,6 +197,12 @@ func OSWorkflow(
195197
return nil, errFactory.NewEmptyOrgError()
196198
}
197199

200+
orgSlugOrID := config.GetString(configuration.ORGANIZATION_SLUG)
201+
if orgSlugOrID == "" {
202+
logger.Info().Msg("No organization slug provided; using organization ID.")
203+
orgSlugOrID = orgID
204+
}
205+
198206
// Create Snyk client
199207
httpClient := ictx.GetNetworkAccess().GetHttpClient()
200208
snykClient := snykclient.NewSnykClient(httpClient, ictx.GetConfiguration().GetString(configuration.API_URL), orgID)
@@ -212,8 +220,8 @@ func OSWorkflow(
212220
// Route to the appropriate flow based on flags
213221
switch {
214222
case sbomReachabilityTest:
215-
return setupSBOMReachabilityFlow(ctx, ictx, testClient, orgID, errFactory, logger, sbom, sourceDir)
223+
return setupSBOMReachabilityFlow(ctx, ictx, testClient, orgID, orgSlugOrID, errFactory, logger, sbom, sourceDir)
216224
default:
217-
return setupDefaultTestFlow(ctx, ictx, testClient, orgID, errFactory, logger, riskScoreThreshold)
225+
return setupDefaultTestFlow(ctx, ictx, testClient, orgID, orgSlugOrID, errFactory, logger, riskScoreThreshold)
218226
}
219227
}

internal/commands/ostest/workflow_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ func createMockInvocationCtxWithURL(t *testing.T, ctrl *gomock.Controller, engin
248248
mockConfig := configuration.New()
249249
mockConfig.Set(configuration.AUTHENTICATION_TOKEN, "<SOME API TOKEN>")
250250
mockConfig.Set(configuration.ORGANIZATION, uuid.New().String())
251+
mockConfig.Set(configuration.ORGANIZATION_SLUG, "some-org")
251252
mockConfig.Set(configuration.API_URL, mockServerURL)
252253

253254
// Initialize with default values for our flags

internal/legacy/transform/transform.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
type SnykSchemaToLegacyParams struct {
2525
Findings []testapi.FindingData
2626
TestResult testapi.TestResult
27+
OrgSlugOrID string
2728
ProjectName string
2829
PackageManager string
2930
CurrentDir string
@@ -348,6 +349,7 @@ func ConvertSnykSchemaFindingsToLegacy(params *SnykSchemaToLegacyParams) (*defin
348349
}
349350

350351
res := definitions.LegacyVulnerabilityResponse{
352+
Org: params.OrgSlugOrID,
351353
ProjectName: params.ProjectName,
352354
Path: params.CurrentDir,
353355
PackageManager: params.PackageManager,

0 commit comments

Comments
 (0)