Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
These functions and variables are not used anywhere. Let's remove them
to avoid collecting cruft.

Signed-off-by: Luiz Carvalho <[email protected]>
  • Loading branch information
lcarva committed Nov 21, 2024
1 parent ce4106d commit f8fe994
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 389 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ type ApplicationSnapshotImage struct {
snapshot app.SnapshotSpec
}

func (a ApplicationSnapshotImage) GetReference() name.Reference {
return a.reference
}

// NewApplicationSnapshotImage returns an ApplicationSnapshotImage struct with reference, checkOpts, and evaluator ready to use.
func NewApplicationSnapshotImage(ctx context.Context, component app.SnapshotComponent, p policy.Policy, snap app.SnapshotSpec) (*ApplicationSnapshotImage, error) {
opts, err := p.CheckOpts()
Expand Down
174 changes: 0 additions & 174 deletions internal/policy/__snapshots__/policy_test.snap

This file was deleted.

19 changes: 1 addition & 18 deletions internal/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"crypto"
_ "embed"
"encoding/json"
"errors"
"fmt"
"os"
Expand All @@ -29,7 +28,6 @@ import (

"github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
ecc "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
schemaExporter "github.com/invopop/jsonschema"
"github.com/santhosh-tekuri/jsonschema/v5"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/fulcio"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/rekor"
Expand All @@ -55,27 +53,12 @@ const (
// allows controlling time in tests
var now = time.Now

var (
PolicySourcesFrom = source.PolicySourcesFrom
CreateWorkDir = utils.CreateWorkDir
PolicyCacheFromContext = cache.PolicyCacheFromContext
)
var PolicySourcesFrom = source.PolicySourcesFrom

func ValidatePolicy(ctx context.Context, policyConfig string) error {
return validatePolicyConfig(policyConfig)
}

// Create a JSON schema from a Go type, and return the JSON as a byte slice
func jsonSchemaFromPolicySpec(ecp *ecc.EnterpriseContractPolicySpec) ([]byte, error) {
r := new(schemaExporter.Reflector)
schema := r.Reflect(ecp)
schemaJson, err := json.MarshalIndent(schema, "", " ")
if err != nil {
return nil, err
}
return schemaJson, nil
}

type SigstoreOpts struct {
CertificateIdentity string `json:"certificate_identity"`
CertificateIdentityRegExp string `json:"certificate_identity_regexp"`
Expand Down
12 changes: 0 additions & 12 deletions internal/policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

hd "github.com/MakeNowJust/heredoc"
ecc "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
"github.com/gkampitakis/go-snaps/snaps"
"github.com/sigstore/cosign/v2/pkg/cosign"
cosignSig "github.com/sigstore/cosign/v2/pkg/signature"
sigstoreSig "github.com/sigstore/sigstore/pkg/signature"
Expand Down Expand Up @@ -718,17 +717,6 @@ func TestIsConformant(t *testing.T) {
}
}

func TestJsonSchemaFromPolicySpec(t *testing.T) {
ecp := &ecc.EnterpriseContractPolicySpec{
PublicKey: "testPublicKey",
RekorUrl: "testRekorUrl",
}
schemaJson, err := jsonSchemaFromPolicySpec(ecp)
assert.NoError(t, err)

snaps.MatchJSON(t, schemaJson)
}

func TestSigstoreOpts(t *testing.T) {
cases := []struct {
name string
Expand Down
26 changes: 0 additions & 26 deletions internal/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,19 @@
package utils

import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"unicode"

isatty "github.com/mattn/go-isatty"
log "github.com/sirupsen/logrus"
"github.com/spf13/afero"
"sigs.k8s.io/yaml"
)

// ToJSON converts a single YAML document into a JSON document
// or returns an error. If the document appears to be JSON the
// YAML decoding path is not used.
func ToJSON(data []byte) ([]byte, error) {
if hasJSONPrefix(data) {
return data, nil
}
return yaml.YAMLToJSON(data)
}

var jsonPrefix = []byte("{")

// hasJSONPrefix returns true if the provided buffer appears to start with
// a JSON open brace.
func hasJSONPrefix(buf []byte) bool {
return hasPrefix(buf, jsonPrefix)
}

// hasPrefix returns true if the first non-whitespace bytes in buf is prefix.
func hasPrefix(buf []byte, prefix []byte) bool {
trim := bytes.TrimLeftFunc(buf, unicode.IsSpace)
return bytes.HasPrefix(trim, prefix)
}

// CreateWorkDir creates the working directory in tmp and some subdirectories
func CreateWorkDir(fs afero.Fs) (string, error) {
workDir, err := afero.TempDir(fs, afero.GetTempDir(fs, ""), "ec-work-")
Expand Down
Loading

0 comments on commit f8fe994

Please sign in to comment.