Skip to content

Commit 039f7cb

Browse files
authored
Rename slsa_types package to slsa (#194)
* Rename slsa_types dir to slsa Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]> * Rename slsa_types refs -> slsa This commit renames all references to the slsa_types package to the new slsa name Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]> --------- Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]>
1 parent 3823b2f commit 039f7cb

File tree

10 files changed

+337
-338
lines changed

10 files changed

+337
-338
lines changed

sourcetool/pkg/attest/provenance.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"google.golang.org/protobuf/types/known/structpb"
1717

1818
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
19-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
19+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
2020
)
2121

2222
const SourceProvPredicateType = "https://github.com/slsa-framework/slsa-source-poc/source-provenance/v1-draft"
@@ -35,13 +35,13 @@ type SourceProvenancePred struct {
3535
// TODO: get the author of the PR (if this was from a PR).
3636

3737
// The controls enabled at the time this commit was pushed.
38-
Controls slsa_types.Controls `json:"controls"`
38+
Controls slsa.Controls `json:"controls"`
3939
}
4040

4141
// Summary of a summary
4242
type VsaSummary struct {
43-
SourceRefs []string `json:"source_refs"`
44-
VerifiedLevels []slsa_types.ControlName `json:"verifiedLevels"`
43+
SourceRefs []string `json:"source_refs"`
44+
VerifiedLevels []slsa.ControlName `json:"verifiedLevels"`
4545
}
4646

4747
type TagProvenancePred struct {
@@ -50,8 +50,8 @@ type TagProvenancePred struct {
5050
Tag string `json:"tag"`
5151
CreatedOn time.Time `json:"created_on"`
5252
// The tag related controls enabled at the time this tag was created/updated.
53-
Controls slsa_types.Controls `json:"controls"`
54-
VsaSummaries []VsaSummary `json:"vsa_summaries"`
53+
Controls slsa.Controls `json:"controls"`
54+
VsaSummaries []VsaSummary `json:"vsa_summaries"`
5555
}
5656

5757
type ProvenanceAttestor struct {
@@ -163,7 +163,7 @@ func (pa ProvenanceAttestor) createCurrentProvenance(ctx context.Context, commit
163163
curProvPred.Controls = controlStatus.Controls
164164

165165
// At the very least provenance is available starting now. :)
166-
curProvPred.Controls.AddControl(&slsa_types.Control{Name: slsa_types.ProvenanceAvailable, Since: curTime})
166+
curProvPred.Controls.AddControl(&slsa.Control{Name: slsa.ProvenanceAvailable, Since: curTime})
167167

168168
return addPredToStatement(&curProvPred, SourceProvPredicateType, commit)
169169
}
@@ -265,7 +265,7 @@ func (pa ProvenanceAttestor) CreateSourceProvenance(ctx context.Context, prevAtt
265265
if prevControl == nil {
266266
continue
267267
}
268-
curControl.Since = slsa_types.EarlierTime(curControl.Since, prevControl.Since)
268+
curControl.Since = slsa.EarlierTime(curControl.Since, prevControl.Since)
269269
// Update the value.
270270
curProvPred.Controls[i] = curControl
271271
}
@@ -311,7 +311,7 @@ func (pa ProvenanceAttestor) CreateTagProvenance(ctx context.Context, commit, re
311311
VsaSummaries: []VsaSummary{
312312
{
313313
SourceRefs: vsaRefs,
314-
VerifiedLevels: slsa_types.StringsToControlNames(vsaPred.VerifiedLevels),
314+
VerifiedLevels: slsa.StringsToControlNames(vsaPred.VerifiedLevels),
315315
},
316316
},
317317
}

sourcetool/pkg/attest/provenance_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/google/go-github/v69/github"
1010
"github.com/migueleliasweb/go-github-mock/src/mock"
1111
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
12-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
12+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
1313
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/testsupport"
1414
)
1515

@@ -31,7 +31,7 @@ func conditionsForTagImmutability() *github.RepositoryRulesetConditions {
3131
}
3232
}
3333

34-
func createTestVsa(t *testing.T, repoUri, ref, commit string, verifiedLevels slsa_types.SourceVerifiedLevels) string {
34+
func createTestVsa(t *testing.T, repoUri, ref, commit string, verifiedLevels slsa.SourceVerifiedLevels) string {
3535
vsa, err := CreateUnsignedSourceVsa(repoUri, ref, commit, verifiedLevels, "test-policy")
3636
if err != nil {
3737
t.Fatalf("failure creating test vsa: %v", err)
@@ -121,7 +121,7 @@ func assertTagProvPredsEqual(t *testing.T, actual, expected TagProvenancePred) {
121121
}
122122

123123
func TestCreateTagProvenance(t *testing.T) {
124-
testVsa := createTestVsa(t, "http://repo", "refs/some/ref", "abc123", slsa_types.SourceVerifiedLevels{"TEST_LEVEL"})
124+
testVsa := createTestVsa(t, "http://repo", "refs/some/ref", "abc123", slsa.SourceVerifiedLevels{"TEST_LEVEL"})
125125

126126
ghc := newTestGhConnection("owner", "repo", "branch",
127127
newTagHygieneRulesetsResponse(123, github.RulesetTargetTag,
@@ -158,7 +158,7 @@ func TestCreateTagProvenance(t *testing.T) {
158158
Actor: "the-tag-pusher",
159159
Tag: "refs/tags/v1",
160160
CreatedOn: rulesetOldTime,
161-
Controls: []slsa_types.Control{
161+
Controls: []slsa.Control{
162162
{
163163
Name: "TAG_HYGIENE",
164164
Since: rulesetOldTime,
@@ -167,7 +167,7 @@ func TestCreateTagProvenance(t *testing.T) {
167167
VsaSummaries: []VsaSummary{
168168
{
169169
SourceRefs: []string{"refs/some/ref"},
170-
VerifiedLevels: []slsa_types.ControlName{"TEST_LEVEL"},
170+
VerifiedLevels: []slsa.ControlName{"TEST_LEVEL"},
171171
},
172172
},
173173
}

sourcetool/pkg/attest/statement.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"log"
88

99
spb "github.com/in-toto/attestation/go/v1"
10-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
10+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
1111
"google.golang.org/protobuf/encoding/protojson"
1212
)
1313

@@ -22,7 +22,7 @@ func NewBundleReader(reader *bufio.Reader, verifier Verifier) *BundleReader {
2222

2323
func (br BundleReader) convertLineToStatement(line string) (*spb.Statement, error) {
2424
// Is this a sigstore bundle with a statement?
25-
vr, err := br.verifier.Verify(line)
25+
vr, err := br.verifier.Verify(line)
2626
if err == nil {
2727
// This is it.
2828
return vr.Statement, nil
@@ -43,11 +43,11 @@ func GetSourceRefsForCommit(vsaStatement *spb.Statement, commit string) ([]strin
4343
return []string{}, fmt.Errorf("statement \n%v\n does not match commit %s", StatementToString(vsaStatement), commit)
4444
}
4545
annotations := subject.GetAnnotations()
46-
sourceRefs, ok := annotations.Fields[slsa_types.SourceRefsAnnotation]
46+
sourceRefs, ok := annotations.Fields[slsa.SourceRefsAnnotation]
4747
if !ok {
4848
// This used to be called 'source_branches', maybe this is an old VSA.
4949
// TODO: remove once we're not worried about backward compatibility.
50-
sourceRefs, ok = annotations.Fields[slsa_types.SourceBranchesAnnotation]
50+
sourceRefs, ok = annotations.Fields[slsa.SourceBranchesAnnotation]
5151
if !ok {
5252
return []string{}, fmt.Errorf("no source_refs or source_branches annotation in VSA subject")
5353
}

sourcetool/pkg/attest/vsa.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import (
1010
vpb "github.com/in-toto/attestation/go/predicates/vsa/v1"
1111
spb "github.com/in-toto/attestation/go/v1"
1212
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
13-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
13+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
1414
"google.golang.org/protobuf/encoding/protojson"
1515
"google.golang.org/protobuf/types/known/structpb"
1616
"google.golang.org/protobuf/types/known/timestamppb"
1717
)
1818

1919
const VsaPredicateType = "https://slsa.dev/verification_summary/v1"
2020

21-
func CreateUnsignedSourceVsa(repoUri, ref, commit string, verifiedLevels slsa_types.SourceVerifiedLevels, policy string) (string, error) {
21+
func CreateUnsignedSourceVsa(repoUri, ref, commit string, verifiedLevels slsa.SourceVerifiedLevels, policy string) (string, error) {
2222
resourceUri := fmt.Sprintf("git+%s", repoUri)
2323
vsaPred := &vpb.VerificationSummary{
2424
Verifier: &vpb.VerificationSummary_Verifier{
@@ -27,15 +27,15 @@ func CreateUnsignedSourceVsa(repoUri, ref, commit string, verifiedLevels slsa_ty
2727
ResourceUri: resourceUri,
2828
Policy: &vpb.VerificationSummary_Policy{Uri: policy},
2929
VerificationResult: "PASSED",
30-
VerifiedLevels: slsa_types.ControlNamesToStrings(verifiedLevels),
30+
VerifiedLevels: slsa.ControlNamesToStrings(verifiedLevels),
3131
}
3232

3333
predJson, err := protojson.Marshal(vsaPred)
3434
if err != nil {
3535
return "", err
3636
}
3737

38-
branchAnnotation := map[string]any{slsa_types.SourceRefsAnnotation: []any{ref}}
38+
branchAnnotation := map[string]any{slsa.SourceRefsAnnotation: []any{ref}}
3939
annotationStruct, err := structpb.NewStruct(branchAnnotation)
4040
if err != nil {
4141
return "", fmt.Errorf("creating struct from map: %w", err)

sourcetool/pkg/ghcontrol/checklevel.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99

1010
"github.com/google/go-github/v69/github"
11-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
11+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
1212
)
1313

1414
type actor struct {
@@ -69,7 +69,7 @@ type GhControlStatus struct {
6969
ActivityType string
7070
// The controls that are enabled according to the GitHub API.
7171
// May not include other controls like if we have provenance.
72-
Controls slsa_types.Controls
72+
Controls slsa.Controls
7373
}
7474

7575
func (ghc *GitHubConnection) ruleMeetsRequiresReview(rule *github.PullRequestBranchRule) bool {
@@ -80,7 +80,7 @@ func (ghc *GitHubConnection) ruleMeetsRequiresReview(rule *github.PullRequestBra
8080
}
8181

8282
// Computes the continuity control returning nil if it's not enabled.
83-
func (ghc *GitHubConnection) computeContinuityControl(ctx context.Context, commit string, rules *github.BranchRules, activity *activity) (*slsa_types.Control, error) {
83+
func (ghc *GitHubConnection) computeContinuityControl(ctx context.Context, commit string, rules *github.BranchRules, activity *activity) (*slsa.Control, error) {
8484
oldestDeletion, err := ghc.getOldestActiveRule(ctx, rules.Deletion)
8585
if err != nil {
8686
return nil, err
@@ -107,7 +107,7 @@ func (ghc *GitHubConnection) computeContinuityControl(ctx context.Context, commi
107107
return nil, fmt.Errorf("commit %s created before (%v) the rule was enabled (%v), that shouldn't happen", commit, activity.Timestamp, newestRule.UpdatedAt.Time)
108108
}
109109

110-
return &slsa_types.Control{Name: slsa_types.ContinuityEnforced, Since: newestRule.UpdatedAt.Time}, nil
110+
return &slsa.Control{Name: slsa.ContinuityEnforced, Since: newestRule.UpdatedAt.Time}, nil
111111
}
112112

113113
func enforcesTagHygiene(ruleset *github.RepositoryRuleset) bool {
@@ -123,7 +123,7 @@ func enforcesTagHygiene(ruleset *github.RepositoryRuleset) bool {
123123
return false
124124
}
125125

126-
func (ghc *GitHubConnection) computeTagHygieneControl(ctx context.Context, commit string, allRulesets []*github.RepositoryRuleset, activityTime *time.Time) (*slsa_types.Control, error) {
126+
func (ghc *GitHubConnection) computeTagHygieneControl(ctx context.Context, commit string, allRulesets []*github.RepositoryRuleset, activityTime *time.Time) (*slsa.Control, error) {
127127
var validRuleset *github.RepositoryRuleset
128128
for _, ruleset := range allRulesets {
129129
if *ruleset.Target != github.RulesetTargetTag {
@@ -158,11 +158,11 @@ func (ghc *GitHubConnection) computeTagHygieneControl(ctx context.Context, commi
158158
return nil, nil
159159
}
160160

161-
return &slsa_types.Control{Name: slsa_types.TagHygiene, Since: validRuleset.UpdatedAt.Time}, nil
161+
return &slsa.Control{Name: slsa.TagHygiene, Since: validRuleset.UpdatedAt.Time}, nil
162162
}
163163

164164
// Computes the review control returning nil if it's not enabled.
165-
func (ghc *GitHubConnection) computeReviewControl(ctx context.Context, rules []*github.PullRequestBranchRule) (*slsa_types.Control, error) {
165+
func (ghc *GitHubConnection) computeReviewControl(ctx context.Context, rules []*github.PullRequestBranchRule) (*slsa.Control, error) {
166166
var oldestActive *github.RepositoryRuleset
167167
for _, rule := range rules {
168168
if ghc.ruleMeetsRequiresReview(rule) {
@@ -179,16 +179,16 @@ func (ghc *GitHubConnection) computeReviewControl(ctx context.Context, rules []*
179179
}
180180

181181
if oldestActive != nil {
182-
return &slsa_types.Control{Name: slsa_types.ReviewEnforced, Since: oldestActive.UpdatedAt.Time}, nil
182+
return &slsa.Control{Name: slsa.ReviewEnforced, Since: oldestActive.UpdatedAt.Time}, nil
183183
}
184184

185185
return nil, nil
186186
}
187187

188-
func (ghc *GitHubConnection) computeRequiredChecks(ctx context.Context, ghCheckRules []*github.RequiredStatusChecksBranchRule) ([]*slsa_types.Control, error) {
188+
func (ghc *GitHubConnection) computeRequiredChecks(ctx context.Context, ghCheckRules []*github.RequiredStatusChecksBranchRule) ([]*slsa.Control, error) {
189189
// Only return the checks we're happy about.
190190
// For now that's only stuff from the GitHub Actions app.
191-
requiredChecks := []*slsa_types.Control{}
191+
requiredChecks := []*slsa.Control{}
192192
for _, ghCheckRule := range ghCheckRules {
193193
ruleset, _, err := ghc.Client().Repositories.GetRuleset(ctx, ghc.Owner(), ghc.Repo(), ghCheckRule.RulesetID, false)
194194
if err != nil {
@@ -204,7 +204,7 @@ func (ghc *GitHubConnection) computeRequiredChecks(ctx context.Context, ghCheckR
204204
// Ignore untrusted integration id.
205205
continue
206206
}
207-
requiredChecks = append(requiredChecks, &slsa_types.Control{
207+
requiredChecks = append(requiredChecks, &slsa.Control{
208208
Name: CheckNameToControlName(check.Context),
209209
Since: ruleset.UpdatedAt.Time,
210210
})
@@ -242,7 +242,7 @@ func (ghc *GitHubConnection) GetBranchControls(ctx context.Context, commit, ref
242242
CommitPushTime: activity.Timestamp,
243243
ActivityType: activity.ActivityType,
244244
ActorLogin: activity.Actor.Login,
245-
Controls: slsa_types.Controls{}}
245+
Controls: slsa.Controls{}}
246246

247247
branch := GetBranchFromRef(ref)
248248
if branch == "" {
@@ -289,7 +289,7 @@ func (ghc *GitHubConnection) GetBranchControls(ctx context.Context, commit, ref
289289
func (ghc *GitHubConnection) GetTagControls(ctx context.Context, commit, ref string) (*GhControlStatus, error) {
290290
controlStatus := GhControlStatus{
291291
CommitPushTime: time.Now(),
292-
Controls: slsa_types.Controls{}}
292+
Controls: slsa.Controls{}}
293293

294294
allRulesets, _, err := ghc.Client().Repositories.GetAllRulesets(ctx, ghc.Owner(), ghc.Repo(), true)
295295
if err != nil {

sourcetool/pkg/ghcontrol/checklevel_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/google/go-github/v69/github"
1212
"github.com/migueleliasweb/go-github-mock/src/mock"
13-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
13+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
1414
)
1515

1616
var curTime = time.Unix(1678886400, 0) // March 15, 2023 00:00:00 UTC
@@ -229,22 +229,22 @@ func TestBuiltinBranchControls(t *testing.T) {
229229
tests := []struct {
230230
branchRules []branchRuleRawResponse
231231
rulesetRules *github.RepositoryRulesetRules
232-
expectedControl slsa_types.ControlName
232+
expectedControl slsa.ControlName
233233
}{
234234
{
235235
branchRules: createContinuityBranchRules(),
236236
rulesetRules: rulesForBranchContinuity(),
237-
expectedControl: slsa_types.ContinuityEnforced,
237+
expectedControl: slsa.ContinuityEnforced,
238238
},
239239
{
240240
branchRules: createReviewBranchRules(),
241241
rulesetRules: rulesForReviewEnforced(),
242-
expectedControl: slsa_types.ReviewEnforced,
242+
expectedControl: slsa.ReviewEnforced,
243243
},
244244
{
245245
branchRules: createTagHygieneRules(),
246246
rulesetRules: rulesForTagHygiene(),
247-
expectedControl: slsa_types.TagHygiene,
247+
expectedControl: slsa.TagHygiene,
248248
},
249249
}
250250
for _, tt := range tests {
@@ -275,21 +275,21 @@ func TestGetBranchControlsRequiredChecks(t *testing.T) {
275275
tests := []struct {
276276
name string
277277
checks []branchRuleRawResponse
278-
expectedControlNames []slsa_types.ControlName
278+
expectedControlNames []slsa.ControlName
279279
}{
280280
{
281281
name: "check with invalid id",
282282
checks: createRequiredChecksRules([]*github.RuleStatusCheck{
283283
{Context: "check-bad", IntegrationID: github.Ptr(int64(1))},
284284
}),
285-
expectedControlNames: []slsa_types.ControlName{},
285+
expectedControlNames: []slsa.ControlName{},
286286
},
287287
{
288288
name: "check using Github Actions",
289289
checks: createRequiredChecksRules([]*github.RuleStatusCheck{
290290
{Context: "check-good", IntegrationID: github.Ptr(int64(15368))},
291291
}),
292-
expectedControlNames: []slsa_types.ControlName{"GH_REQUIRED_CHECK_check-good"},
292+
expectedControlNames: []slsa.ControlName{"GH_REQUIRED_CHECK_check-good"},
293293
},
294294
}
295295
for _, tt := range tests {
@@ -306,7 +306,7 @@ func TestGetBranchControlsRequiredChecks(t *testing.T) {
306306
t.Fatalf("Error getting branch controls: %v", err)
307307
}
308308

309-
controlNames := []slsa_types.ControlName{}
309+
controlNames := []slsa.ControlName{}
310310
for _, control := range controlStatus.Controls {
311311
controlNames = append(controlNames, control.Name)
312312
if !control.Since.Equal(priorTime) {

sourcetool/pkg/ghcontrol/git_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
7+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
88
)
99

1010
// Matches any reference type.
@@ -28,6 +28,6 @@ func GetTagFromRef(ref string) string {
2828
return strings.TrimPrefix(ref, "refs/tags/")
2929
}
3030

31-
func CheckNameToControlName(checkName string) slsa_types.ControlName {
32-
return slsa_types.ControlName(fmt.Sprintf("GH_REQUIRED_CHECK_%s", checkName))
31+
func CheckNameToControlName(checkName string) slsa.ControlName {
32+
return slsa.ControlName(fmt.Sprintf("GH_REQUIRED_CHECK_%s", checkName))
3333
}

0 commit comments

Comments
 (0)