-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benji Visser <[email protected]>
- Loading branch information
Showing
6 changed files
with
246 additions
and
9 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
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,63 @@ | ||
package xeolio | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/anchore/syft/syft/source" | ||
) | ||
|
||
type EventSource interface { | ||
Serialize() map[string]interface{} | ||
} | ||
|
||
type DirectorySource struct { | ||
Type string | ||
Target string | ||
} | ||
|
||
func (s *DirectorySource) Serialize() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"Type": s.Type, | ||
"Target": s.Target, | ||
} | ||
} | ||
|
||
func NewDirectorySource(dirSource source.DirectorySourceMetadata) *DirectorySource { | ||
return &DirectorySource{ | ||
Type: "DirectoryScheme", | ||
Target: dirSource.Path, | ||
} | ||
} | ||
|
||
type ImageSource struct { | ||
Type string | ||
ImageName string | ||
ImageDigest string | ||
} | ||
|
||
func NewImageSource(imageSource source.StereoscopeImageSourceMetadata) *ImageSource { | ||
return &ImageSource{ | ||
Type: "ImageScheme", | ||
ImageName: imageSource.UserInput, | ||
ImageDigest: imageSource.ManifestDigest, | ||
} | ||
} | ||
|
||
func (s *ImageSource) Serialize() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"Type": s.Type, | ||
"ImageName": s.ImageName, | ||
"ImageDigest": s.ImageDigest, | ||
} | ||
} | ||
|
||
func NewEventSource(sbomSource source.Description) (map[string]interface{}, error) { | ||
switch v := sbomSource.Metadata.(type) { | ||
case source.DirectorySourceMetadata: | ||
return NewDirectorySource(v).Serialize(), nil | ||
case source.StereoscopeImageSourceMetadata: | ||
return NewImageSource(v).Serialize(), nil | ||
default: | ||
return nil, fmt.Errorf("unsupported source type: %s", v) | ||
} | ||
} |