-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3088: add full text field for licenses to default syft-json output #3450
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
b51f450
to
bbca5e5
Compare
// FullTextValue is a placeholder value when license metadata is discovered to be fullText | ||
// A license with "FullText" in its value refers the consumer to look at the FullText field | ||
// This is so that we can keep Value as a required field up until syft 2.0 | ||
var FullTextValue = "FullText" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of a placeholder field that is attempting to have consumers reference the full text, should we just populate this with an empty value? That is, the json schema requires the field to be present but does not state that it must not be empty. I feel that if we don't know the ID we should leave this blank, but allow the new full text field to convey any discovered information. That way we can stay compliant to syft v1 json output but still add full text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we do things like otherLicenses
in SPDX what would we use for the license ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wagoodman - it looks like in syft we have a couple of places where we assume value should not be ""
This includes the constructor for creating a license set:
Lines 48 to 64 in 02f9350
func (s *LicenseSet) Add(licenses ...License) { | |
if s.set == nil { | |
s.set = make(map[artifact.ID]License) | |
} | |
for _, l := range licenses { | |
// we only want to add licenses that have a value | |
// note, this check should be moved to the license constructor in the future | |
if l.Value != "" { | |
if id, merged, err := s.addToExisting(l); err == nil && !merged { | |
// doesn't exist, add it | |
s.set[id] = l | |
} else if err != nil { | |
log.Trace("license set failed to add license %#v: %+v", l, err) | |
} | |
} | |
} | |
} |
If we were to keep this const
as a placeholder some alternatives that @willmurphyscode and I discussed could be as follows:
Other Options for Value
- SeeFullText
- “<First_50_Characters of file> … [TRUNCATED]”
Do we want a better name for this const
or do we want to go back and break up the license set/spdx formatter assumptions about value
being present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this section will need to be updated already to account for filtering out "FullText" values. In that same way, can't we do the same for an empty value and the full text is specified in the other field?
Description
This PR updates the syft
License
model to include a newFullText
field without any breaking changes to the current license behavior. We select candidates for this new field based on if the metadata being analyzed contains any new line characters. Because we still wantValue
to be populated as it is a required field I've included a default string that will be added here whenFullText
is the selected outcome for a newly constructed license.Verification
Use the following
Dockerfile
and build a test imagedocker build -t syft-3088:latest .
Run the latest syft against this image using this branch:
go run cmd/syft/main.go -o json syft-3088 | jq '.artifacts[] | select(.name=="numpy") | { name: .name, licenses: .licenses }'
The large license value extracted from the package should now be listed under the field
fullText
withvalue
being set toFullText
to keep the field required and not incur any breaking changes.Type of change
Checklist: