Skip to content

Commit

Permalink
refactor: remove unused code (#473)
Browse files Browse the repository at this point in the history
github_app_should_limit_permissions can't be excluded.
  • Loading branch information
suzuki-shunsuke authored Jun 8, 2024
1 parent 28ded74 commit 672d424
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 52 deletions.
32 changes: 1 addition & 31 deletions pkg/policy/github_app_should_limit_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (p *GitHubAppShouldLimitPermissionsPolicy) ID() string {
return "010"
}

func (p *GitHubAppShouldLimitPermissionsPolicy) ApplyStep(logE *logrus.Entry, cfg *config.Config, stepCtx *StepContext, step *workflow.Step) (ge error) {
func (p *GitHubAppShouldLimitPermissionsPolicy) ApplyStep(_ *logrus.Entry, _ *config.Config, _ *StepContext, step *workflow.Step) (ge error) {
action := p.checkUses(step.Uses)
if action == "" {
return nil
Expand All @@ -32,15 +32,6 @@ func (p *GitHubAppShouldLimitPermissionsPolicy) ApplyStep(logE *logrus.Entry, cf
}
}()

var name string
if stepCtx.Job != nil {
name = stepCtx.Job.Name
}
if p.excluded(cfg.Excludes, stepCtx.FilePath, name, step.ID) {
logE.Debug("this step is ignored")
return nil
}

if action == "tibdex/github-app-token" {
if step.With == nil {
return errPermissionsIsRequired
Expand All @@ -60,24 +51,3 @@ func (p *GitHubAppShouldLimitPermissionsPolicy) checkUses(uses string) string {
action, _, _ := strings.Cut(uses, "@")
return action
}

func (p *GitHubAppShouldLimitPermissionsPolicy) excluded(excludes []*config.Exclude, filePath, jobName, stepID string) bool {
for _, exclude := range excludes {
if exclude.PolicyName != p.Name() {
continue
}
if exclude.FilePath() != filePath {
continue
}
if jobName != "" {
if exclude.JobName != jobName {
continue
}
}
if exclude.StepID != stepID {
continue
}
return true
}
return false
}
21 changes: 0 additions & 21 deletions pkg/policy/github_app_should_limit_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,6 @@ func TestGitHubAppShouldLimitPermissionsPolicy_ApplyStep(t *testing.T) { //nolin
},
},
},
{
name: "exclude",
cfg: &config.Config{
Excludes: []*config.Exclude{
{
PolicyName: "github_app_should_limit_permissions",
WorkflowFilePath: ".github/workflows/test.yaml",
JobName: "test",
StepID: "token",
},
},
},
step: &workflow.Step{
Uses: "tibdex/github-app-token@v2",
ID: "token",
With: map[string]string{
"app_id": "xxx",
"private_key": "xxx",
},
},
},
}
p := &policy.GitHubAppShouldLimitPermissionsPolicy{}
logE := logrus.NewEntry(logrus.New())
Expand Down

0 comments on commit 672d424

Please sign in to comment.