Skip to content

Commit

Permalink
feat: enable checker go plugins
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Jan 18, 2024
1 parent 91a8032 commit a5b0675
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions checks/dynamic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024 OpenSSF Scorecard Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package checks

import (
"io/ioutil"
"log"
"os"
"plugin"
"strings"
)

const CheckDynamicPluginLocationEnvironmentVariable = "SCORECARD_DYNAMIC_CHECKS"

//nolint:gochecknoinits
func init() {
pluginsDir, ok := os.LookupEnv(CheckDynamicPluginLocationEnvironmentVariable)
if !ok {
return
}

files, err := ioutil.ReadDir(pluginsDir)
if err != nil {
log.Fatal(err)
}

for _, file := range files {
if !strings.HasSuffix(file.Name(), ".so") {
continue
}

p, err := plugin.Open(file.Name())
if err != nil {
log.Fatal(err)
}

registerCheck, err := p.Lookup("RegisterCheck")
if err != nil {
log.Fatal(err)
}

err = registerCheck.(func() error)()
if err != nil {
log.Fatal(err)
}
}
}

0 comments on commit a5b0675

Please sign in to comment.