-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement SOLID principles for folder output adapter
Signed-off-by: Vivek Kumar Sahu <[email protected]>
- Loading branch information
1 parent
c939e1f
commit e3617ca
Showing
6 changed files
with
197 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2025 Interlynk.io | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package folder | ||
|
||
import "github.com/interlynk-io/sbommv/pkg/types" | ||
|
||
type FolderConfig struct { | ||
FolderPath string | ||
Settings types.UploadSettings | ||
} | ||
|
||
func NewFolderConfig() *FolderConfig { | ||
return &FolderConfig{ | ||
Settings: types.UploadSettings{ProcessingMode: types.UploadSequential}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2025 Interlynk.io | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package folder | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"path/filepath" | ||
|
||
"github.com/google/uuid" | ||
"github.com/interlynk-io/sbommv/pkg/iterator" | ||
"github.com/interlynk-io/sbommv/pkg/logger" | ||
) | ||
|
||
type FolderOutputReporter struct { | ||
folderPath string | ||
} | ||
|
||
func NewFolderOutputReporter(folderPath string) *FolderOutputReporter { | ||
return &FolderOutputReporter{folderPath: folderPath} | ||
} | ||
|
||
func (r *FolderOutputReporter) DryRun(ctx context.Context, iter iterator.SBOMIterator) error { | ||
logger.LogDebug(ctx, "Dry-run mode: Displaying SBOMs for folder output") | ||
fmt.Println("\n📦 **Folder Output Adapter Dry-Run**") | ||
sbomCount := 0 | ||
|
||
for { | ||
sbom, err := iter.Next(ctx) | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
logger.LogError(ctx, err, "Error retrieving SBOM from iterator") | ||
return err | ||
} | ||
|
||
namespace := filepath.Base(sbom.Namespace) | ||
if namespace == "" { | ||
namespace = fmt.Sprintf("sbom_%s.json", uuid.New().String()) | ||
} | ||
outputPath := filepath.Join(r.folderPath, namespace) | ||
outputFile := filepath.Join(outputPath, sbom.Path) | ||
if sbom.Path == "" { | ||
outputFile = filepath.Join(outputPath, fmt.Sprintf("%s.sbom.json", uuid.New().String())) | ||
} | ||
|
||
fmt.Printf("- 📂 Would write: %s\n", outputFile) | ||
sbomCount++ | ||
} | ||
|
||
fmt.Printf("\n📊 Total SBOMs to be stored: %d\n", sbomCount) | ||
logger.LogDebug(ctx, "Dry-run completed", "total_sboms", sbomCount) | ||
return nil | ||
} |
Oops, something went wrong.