Skip to content
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

chore(policies): decouple evaluations representation #1294

Merged
merged 10 commits into from
Sep 9, 2024

Conversation

jiparis
Copy link
Member

@jiparis jiparis commented Sep 5, 2024

This PR decouples Policy Evaluation representation in the different layers: crafting, render and attestation API.
Apart from the decoupling advantage, this change solves the different [de]serialization problem when dealing with protobuf and structpb representations, in particular with Enums and oneOfs.
Thanks to this change, type field in evaluations has been fixed.

          "CHAINLOOP.ATTESTATION": [
@@ -74,7 +86,7 @@
                   },
                   "name": "chainloop://localhost:8002/sbom-present"
                },
-               "type": 12
+               "type": "ATTESTATION"
             },
             {
                "description": "Verifies that the attestation explicitly references a specific Git commit",
@@ -85,8 +97,34 @@
                   },
                   "name": "chainloop://localhost:8002/source-commit"
                },
-               "type": 12
+               "type": "ATTESTATION"
             }

Note: I've added a fix in extractPredicate method to be able to read old attestations with the wrong type field (int)

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis jiparis requested review from migmartri and javirln September 5, 2024 14:41
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@@ -209,30 +207,3 @@ func Craft(ctx context.Context, materialSchema *schemaapi.CraftingSchema_Materia

return m, nil
}

// LoadJSONBytes Extracts raw data in JSON format from different sources, i.e cue or yaml files
func LoadJSONBytes(rawData []byte, extension string) ([]byte, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to avoid import cycles

@@ -189,6 +193,23 @@ func extractPredicate(statement *intoto.Statement, v *ProvenancePredicateV02) er
return nil
}

func fixPolicyTypeField(statement *intoto.Statement) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to prevent marshaling errors with old, wrong attestations with enum (number) type field.

@jiparis jiparis requested a review from migmartri September 6, 2024 09:16
@jiparis jiparis merged commit 3158604 into chainloop-dev:main Sep 9, 2024
13 checks passed
@jiparis jiparis deleted the PFM-1127-enums branch September 9, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants