Skip to content

Commit fc161fb

Browse files
authored
Rename package gh_control -> ghcontrol (#191)
* Rename gh_control dir Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]> * Rename package gh_control -> ghcontrol Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]> * Rename gh_control refs to ghcontrol Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]> --------- Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]>
1 parent 0cb6679 commit fc161fb

19 files changed

+103
-103
lines changed

sourcetool/cmd/checklevel.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"os"
1212

1313
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/attest"
14-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
14+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1515
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/policy"
1616

1717
"github.com/spf13/cobra"
@@ -50,25 +50,25 @@ func doCheckLevel(cla *CheckLevelArgs) {
5050
log.Fatalf("Error: %v", err)
5151
}
5252

53-
gh_connection := gh_control.NewGhConnection(
54-
cla.owner, cla.repo, gh_control.BranchToFullRef(cla.branch),
53+
ghconnection := ghcontrol.NewGhConnection(
54+
cla.owner, cla.repo, ghcontrol.BranchToFullRef(cla.branch),
5555
).WithAuthToken(githubToken)
56-
gh_connection.Options.AllowMergeCommits = cla.allowMergeCommits
56+
ghconnection.Options.AllowMergeCommits = cla.allowMergeCommits
5757

5858
ctx := context.Background()
59-
controlStatus, err := gh_connection.GetBranchControls(ctx, cla.commit, gh_connection.GetFullRef())
59+
controlStatus, err := ghconnection.GetBranchControls(ctx, cla.commit, ghconnection.GetFullRef())
6060
if err != nil {
6161
log.Fatal(err)
6262
}
6363
pe := policy.NewPolicyEvaluator()
6464
pe.UseLocalPolicy = checkLevelProvArgs.useLocalPolicy
65-
verifiedLevels, policyPath, err := pe.EvaluateControl(ctx, gh_connection, controlStatus)
65+
verifiedLevels, policyPath, err := pe.EvaluateControl(ctx, ghconnection, controlStatus)
6666
if err != nil {
6767
log.Fatal(err)
6868
}
6969
fmt.Print(verifiedLevels)
7070

71-
unsignedVsa, err := attest.CreateUnsignedSourceVsa(gh_connection.GetRepoUri(), gh_connection.GetFullRef(), cla.commit, verifiedLevels, policyPath)
71+
unsignedVsa, err := attest.CreateUnsignedSourceVsa(ghconnection.GetRepoUri(), ghconnection.GetFullRef(), cla.commit, verifiedLevels, policyPath)
7272
if err != nil {
7373
log.Fatal(err)
7474
}

sourcetool/cmd/checklevelprov.go

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

1212
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/attest"
13-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
13+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1414
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/policy"
1515
"google.golang.org/protobuf/encoding/protojson"
1616

@@ -46,36 +46,36 @@ var (
4646
)
4747

4848
func doCheckLevelProv(checkLevelProvArgs CheckLevelProvArgs) {
49-
gh_connection :=
50-
gh_control.NewGhConnection(checkLevelProvArgs.owner, checkLevelProvArgs.repo, gh_control.BranchToFullRef(checkLevelProvArgs.branch)).WithAuthToken(githubToken)
51-
gh_connection.Options.AllowMergeCommits = checkLevelProvArgs.allowMergeCommits
49+
ghconnection :=
50+
ghcontrol.NewGhConnection(checkLevelProvArgs.owner, checkLevelProvArgs.repo, ghcontrol.BranchToFullRef(checkLevelProvArgs.branch)).WithAuthToken(githubToken)
51+
ghconnection.Options.AllowMergeCommits = checkLevelProvArgs.allowMergeCommits
5252
ctx := context.Background()
5353

5454
prevCommit := checkLevelProvArgs.prevCommit
5555
var err error
5656
if prevCommit == "" {
57-
prevCommit, err = gh_connection.GetPriorCommit(ctx, checkLevelProvArgs.commit)
57+
prevCommit, err = ghconnection.GetPriorCommit(ctx, checkLevelProvArgs.commit)
5858
if err != nil {
5959
log.Fatal(err)
6060
}
6161
}
6262

63-
pa := attest.NewProvenanceAttestor(gh_connection, getVerifier())
64-
prov, err := pa.CreateSourceProvenance(ctx, checkLevelProvArgs.prevBundlePath, checkLevelProvArgs.commit, prevCommit, gh_connection.GetFullRef())
63+
pa := attest.NewProvenanceAttestor(ghconnection, getVerifier())
64+
prov, err := pa.CreateSourceProvenance(ctx, checkLevelProvArgs.prevBundlePath, checkLevelProvArgs.commit, prevCommit, ghconnection.GetFullRef())
6565
if err != nil {
6666
log.Fatal(err)
6767
}
6868

6969
// check p against policy
7070
pe := policy.NewPolicyEvaluator()
7171
pe.UseLocalPolicy = checkLevelProvArgs.useLocalPolicy
72-
verifiedLevels, policyPath, err := pe.EvaluateSourceProv(ctx, gh_connection, prov)
72+
verifiedLevels, policyPath, err := pe.EvaluateSourceProv(ctx, ghconnection, prov)
7373
if err != nil {
7474
log.Fatal(err)
7575
}
7676

7777
// create vsa
78-
unsignedVsa, err := attest.CreateUnsignedSourceVsa(gh_connection.GetRepoUri(), gh_connection.GetFullRef(), checkLevelProvArgs.commit, verifiedLevels, policyPath)
78+
unsignedVsa, err := attest.CreateUnsignedSourceVsa(ghconnection.GetRepoUri(), ghconnection.GetFullRef(), checkLevelProvArgs.commit, verifiedLevels, policyPath)
7979
if err != nil {
8080
log.Fatal(err)
8181
}

sourcetool/cmd/checktag.go

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

1212
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/attest"
13-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
13+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1414
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/policy"
1515
"github.com/spf13/cobra"
1616
"google.golang.org/protobuf/encoding/protojson"
@@ -39,28 +39,28 @@ var (
3939
)
4040

4141
func doCheckTag(args CheckTagArgs) {
42-
gh_connection :=
43-
gh_control.NewGhConnection(args.owner, args.repo, gh_control.TagToFullRef(args.tagName)).WithAuthToken(githubToken)
42+
ghconnection :=
43+
ghcontrol.NewGhConnection(args.owner, args.repo, ghcontrol.TagToFullRef(args.tagName)).WithAuthToken(githubToken)
4444
ctx := context.Background()
4545
verifier := getVerifier()
4646

4747
// Create tag provenance.
48-
pa := attest.NewProvenanceAttestor(gh_connection, verifier)
49-
prov, err := pa.CreateTagProvenance(ctx, args.commit, gh_control.TagToFullRef(args.tagName), args.actor)
48+
pa := attest.NewProvenanceAttestor(ghconnection, verifier)
49+
prov, err := pa.CreateTagProvenance(ctx, args.commit, ghcontrol.TagToFullRef(args.tagName), args.actor)
5050
if err != nil {
5151
log.Fatal(err)
5252
}
5353

5454
// check p against policy
5555
pe := policy.NewPolicyEvaluator()
5656
pe.UseLocalPolicy = args.useLocalPolicy
57-
verifiedLevels, policyPath, err := pe.EvaluateTagProv(ctx, gh_connection, prov)
57+
verifiedLevels, policyPath, err := pe.EvaluateTagProv(ctx, ghconnection, prov)
5858
if err != nil {
5959
log.Fatal(err)
6060
}
6161

6262
// create vsa
63-
unsignedVsa, err := attest.CreateUnsignedSourceVsa(gh_connection.GetRepoUri(), gh_connection.GetFullRef(), args.commit, verifiedLevels, policyPath)
63+
unsignedVsa, err := attest.CreateUnsignedSourceVsa(ghconnection.GetRepoUri(), ghconnection.GetFullRef(), args.commit, verifiedLevels, policyPath)
6464
if err != nil {
6565
log.Fatal(err)
6666
}

sourcetool/cmd/createpolicy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"log"
1010

11-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
11+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1212
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/policy"
1313

1414
"github.com/spf13/cobra"
@@ -35,9 +35,9 @@ var (
3535
)
3636

3737
func doCreatePolicy(policyRepoPath, owner, repo, branch string) {
38-
gh_connection := gh_control.NewGhConnection(owner, repo, gh_control.BranchToFullRef(branch)).WithAuthToken(githubToken)
38+
ghconnection := ghcontrol.NewGhConnection(owner, repo, ghcontrol.BranchToFullRef(branch)).WithAuthToken(githubToken)
3939
ctx := context.Background()
40-
outpath, err := policy.CreateLocalPolicy(ctx, gh_connection, policyRepoPath)
40+
outpath, err := policy.CreateLocalPolicy(ctx, ghconnection, policyRepoPath)
4141
if err != nil {
4242
log.Fatal(err)
4343
}

sourcetool/cmd/prov.go

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

1111
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/attest"
12-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
12+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1313
"google.golang.org/protobuf/encoding/protojson"
1414

1515
"github.com/spf13/cobra"
@@ -32,10 +32,10 @@ var (
3232
)
3333

3434
func doProv(prevAttPath, commit, prevCommit, owner, repo, branch string) {
35-
gh_connection := gh_control.NewGhConnection(owner, repo, gh_control.BranchToFullRef(branch)).WithAuthToken(githubToken)
35+
ghconnection := ghcontrol.NewGhConnection(owner, repo, ghcontrol.BranchToFullRef(branch)).WithAuthToken(githubToken)
3636
ctx := context.Background()
37-
pa := attest.NewProvenanceAttestor(gh_connection, getVerifier())
38-
newProv, err := pa.CreateSourceProvenance(ctx, prevAttPath, commit, prevCommit, gh_connection.GetFullRef())
37+
pa := attest.NewProvenanceAttestor(ghconnection, getVerifier())
38+
newProv, err := pa.CreateSourceProvenance(ctx, prevAttPath, commit, prevCommit, ghconnection.GetFullRef())
3939
if err != nil {
4040
log.Fatal(err)
4141
}

sourcetool/cmd/verifycommit.go

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

1111
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/attest"
12-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
12+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1313
"github.com/spf13/cobra"
1414
)
1515

@@ -36,17 +36,17 @@ func doVerifyCommit(commit, owner, repo, branch, tag string) {
3636

3737
ref := ""
3838
if branch != "" {
39-
ref = gh_control.BranchToFullRef(branch)
39+
ref = ghcontrol.BranchToFullRef(branch)
4040
} else if tag != "" {
41-
ref = gh_control.TagToFullRef(tag)
41+
ref = ghcontrol.TagToFullRef(tag)
4242
} else {
4343
log.Fatal("Must specify either branch or tag.")
4444
}
4545

46-
gh_connection := gh_control.NewGhConnection(owner, repo, ref).WithAuthToken(githubToken)
46+
ghconnection := ghcontrol.NewGhConnection(owner, repo, ref).WithAuthToken(githubToken)
4747
ctx := context.Background()
4848

49-
_, vsaPred, err := attest.GetVsa(ctx, gh_connection, getVerifier(), commit, gh_connection.GetFullRef())
49+
_, vsaPred, err := attest.GetVsa(ctx, ghconnection, getVerifier(), commit, ghconnection.GetFullRef())
5050
if err != nil {
5151
log.Fatal(err)
5252
}

sourcetool/pkg/attest/provenance.go

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

18-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
18+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1919
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
2020
)
2121

@@ -56,10 +56,10 @@ type TagProvenancePred struct {
5656

5757
type ProvenanceAttestor struct {
5858
verifier Verifier
59-
gh_connection *gh_control.GitHubConnection
59+
gh_connection *ghcontrol.GitHubConnection
6060
}
6161

62-
func NewProvenanceAttestor(gh_connection *gh_control.GitHubConnection, verifier Verifier) *ProvenanceAttestor {
62+
func NewProvenanceAttestor(gh_connection *ghcontrol.GitHubConnection, verifier Verifier) *ProvenanceAttestor {
6363
return &ProvenanceAttestor{verifier: verifier, gh_connection: gh_connection}
6464
}
6565

@@ -206,7 +206,7 @@ func (pa ProvenanceAttestor) getProvFromReader(reader *BundleReader, commit, ref
206206
if err != nil {
207207
return nil, nil, err
208208
}
209-
if ref == gh_control.AnyReference || prevProdPred.Branch == ref {
209+
if ref == ghcontrol.AnyReference || prevProdPred.Branch == ref {
210210
// Should be good!
211211
return stmt, prevProdPred, nil
212212
} else {
@@ -286,7 +286,7 @@ func (pa ProvenanceAttestor) CreateTagProvenance(ctx context.Context, commit, re
286286
// Find the most recent VSA for this commit. Any reference is OK.
287287
// TODO: in the future get all of them.
288288
// TODO: we should actually verify this vsa: https://github.com/slsa-framework/slsa-source-poc/issues/148
289-
vsaStatement, vsaPred, err := GetVsa(ctx, pa.gh_connection, pa.verifier, commit, gh_control.AnyReference)
289+
vsaStatement, vsaPred, err := GetVsa(ctx, pa.gh_connection, pa.verifier, commit, ghcontrol.AnyReference)
290290
if err != nil {
291291
return nil, fmt.Errorf("error fetching VSA when creating tag provenance %w", err)
292292
}

sourcetool/pkg/attest/provenance_test.go

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

99
"github.com/google/go-github/v69/github"
1010
"github.com/migueleliasweb/go-github-mock/src/mock"
11-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
11+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1212
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
1313
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/testsupport"
1414
)
@@ -77,9 +77,9 @@ func newMockedGitHubClient(rulesetResponse *github.RepositoryRuleset, notesConte
7777
}
7878

7979
// Helper to create a test GH Branch connection with no client.
80-
func newTestGhConnection(owner, repo, branch string, rulesetResponse *github.RepositoryRuleset, notesContent *github.RepositoryContent) *gh_control.GitHubConnection {
81-
return gh_control.NewGhConnectionWithClient(
82-
owner, repo, gh_control.BranchToFullRef(branch),
80+
func newTestGhConnection(owner, repo, branch string, rulesetResponse *github.RepositoryRuleset, notesContent *github.RepositoryContent) *ghcontrol.GitHubConnection {
81+
return ghcontrol.NewGhConnectionWithClient(
82+
owner, repo, ghcontrol.BranchToFullRef(branch),
8383
newMockedGitHubClient(rulesetResponse, notesContent))
8484
}
8585

sourcetool/pkg/attest/vsa.go

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

1010
vpb "github.com/in-toto/attestation/go/predicates/vsa/v1"
1111
spb "github.com/in-toto/attestation/go/v1"
12-
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/gh_control"
12+
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
1313
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa_types"
1414
"google.golang.org/protobuf/encoding/protojson"
1515
"google.golang.org/protobuf/types/known/structpb"
@@ -66,7 +66,7 @@ func CreateUnsignedSourceVsa(repoUri, ref, commit string, verifiedLevels slsa_ty
6666
}
6767

6868
// Gets provenance for the commit from git notes.
69-
func GetVsa(ctx context.Context, ghc *gh_control.GitHubConnection, verifier Verifier, commit, ref string) (*spb.Statement, *vpb.VerificationSummary, error) {
69+
func GetVsa(ctx context.Context, ghc *ghcontrol.GitHubConnection, verifier Verifier, commit, ref string) (*spb.Statement, *vpb.VerificationSummary, error) {
7070
notes, err := ghc.GetNotesForCommit(ctx, commit)
7171
if notes == "" {
7272
log.Printf("didn't find notes for commit %s", commit)
@@ -106,7 +106,7 @@ func MatchesTypeCommitAndRef(predicateType, commit, targetRef string) StatementM
106106
return false
107107
}
108108
for _, ref := range refs {
109-
if targetRef == gh_control.AnyReference || ref == targetRef {
109+
if targetRef == ghcontrol.AnyReference || ref == targetRef {
110110
log.Printf("statement \n%v\n matches commit '%s' on ref '%s'", StatementToString(statement), commit, targetRef)
111111
return true
112112
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gh_control
1+
package ghcontrol
22

33
import (
44
"context"
@@ -205,7 +205,7 @@ func (ghc *GitHubConnection) computeRequiredChecks(ctx context.Context, ghCheckR
205205
continue
206206
}
207207
requiredChecks = append(requiredChecks, &slsa_types.Control{
208-
Name: CheckNameToControlName(check.Context),
208+
Name: CheckNameToControlName(check.Context),
209209
Since: ruleset.UpdatedAt.Time,
210210
})
211211
}

0 commit comments

Comments
 (0)