MCPcopy
hub / github.com/ossf/scorecard / GetEnabled

Function GetEnabled

policy/policy.go:144–219  ·  view source on GitHub ↗

GetEnabled returns the list of enabled checks.

(
	sp *ScorecardPolicy,
	argsChecks []string,
	requiredRequestTypes []checker.RequestType,
	repoType clients.RepoType,
)

Source from the content-addressed store, hash-verified

142
143// GetEnabled returns the list of enabled checks.
144func GetEnabled(
145 sp *ScorecardPolicy,
146 argsChecks []string,
147 requiredRequestTypes []checker.RequestType,
148 repoType clients.RepoType,
149) (checker.CheckNameToFnMap, error) {
150 enabledChecks := checker.CheckNameToFnMap{}
151
152 // Build a case-insensitive repo-type lookup map once, only when needed.
153 var repoTypeLookup map[string][]string
154 if repoType != "" {
155 if d, err := docs.Read(); err == nil {
156 repoTypeLookup = make(map[string][]string)
157 for _, c := range d.GetChecks() {
158 repoTypeLookup[strings.ToLower(c.GetName())] = c.GetSupportedRepoTypes()
159 }
160 }
161 }
162
163 switch {
164 case len(argsChecks) != 0:
165 // Populate checks to run with the `--repo` CLI argument.
166 for _, checkName := range argsChecks {
167 if !isSupportedCheck(checkName, requiredRequestTypes) {
168 return enabledChecks,
169 sce.WithMessage(sce.ErrScorecardInternal,
170 fmt.Sprintf("Unsupported RequestType %s by check: %s",
171 fmt.Sprint(requiredRequestTypes), checkName))
172 }
173 if !isSupportedRepoType(repoTypeLookup, checkName, repoType) {
174 continue
175 }
176 if !enableCheck(checkName, &enabledChecks) {
177 return enabledChecks,
178 sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("invalid check: %s", checkName))
179 }
180 }
181 case sp != nil:
182 // Populate checks to run with policy file.
183 for checkName := range sp.GetPolicies() {
184 if !isSupportedCheck(checkName, requiredRequestTypes) {
185 continue
186 }
187 if !isSupportedRepoType(repoTypeLookup, checkName, repoType) {
188 continue
189 }
190
191 if !enableCheck(checkName, &enabledChecks) {
192 return enabledChecks,
193 sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("invalid check: %s", checkName))
194 }
195 }
196 default:
197 // Enable all checks that are supported.
198 for checkName := range checks.GetAll() {
199 if !isSupportedCheck(checkName, requiredRequestTypes) {
200 continue
201 }

Callers 5

processRequestFunction · 0.92
RunFunction · 0.92
rootCmdFunction · 0.92
handleScorecardMethod · 0.92
TestGetEnabledFunction · 0.85

Calls 10

isSupportedCheckFunction · 0.85
isSupportedRepoTypeFunction · 0.85
enableCheckFunction · 0.85
checksHavePoliciesFunction · 0.85
ReadMethod · 0.80
WithMessageMethod · 0.80
GetPoliciesMethod · 0.80
GetChecksMethod · 0.65
GetNameMethod · 0.65
GetSupportedRepoTypesMethod · 0.65

Tested by 1

TestGetEnabledFunction · 0.68