Skip to content

Commit e614d88

Browse files
authored
Merge pull request #2177 from lcarva/unused-stuff
Remove dead code
2 parents ce4106d + f8fe994 commit e614d88

File tree

8 files changed

+1
-389
lines changed

8 files changed

+1
-389
lines changed

internal/evaluation_target/application_snapshot_image/application_snapshot_image.go

-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ type ApplicationSnapshotImage struct {
6363
snapshot app.SnapshotSpec
6464
}
6565

66-
func (a ApplicationSnapshotImage) GetReference() name.Reference {
67-
return a.reference
68-
}
69-
7066
// NewApplicationSnapshotImage returns an ApplicationSnapshotImage struct with reference, checkOpts, and evaluator ready to use.
7167
func NewApplicationSnapshotImage(ctx context.Context, component app.SnapshotComponent, p policy.Policy, snap app.SnapshotSpec) (*ApplicationSnapshotImage, error) {
7268
opts, err := p.CheckOpts()

internal/policy/__snapshots__/policy_test.snap

-174
This file was deleted.

internal/policy/policy.go

+1-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"crypto"
2222
_ "embed"
23-
"encoding/json"
2423
"errors"
2524
"fmt"
2625
"os"
@@ -29,7 +28,6 @@ import (
2928

3029
"github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
3130
ecc "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
32-
schemaExporter "github.com/invopop/jsonschema"
3331
"github.com/santhosh-tekuri/jsonschema/v5"
3432
"github.com/sigstore/cosign/v2/cmd/cosign/cli/fulcio"
3533
"github.com/sigstore/cosign/v2/cmd/cosign/cli/rekor"
@@ -55,27 +53,12 @@ const (
5553
// allows controlling time in tests
5654
var now = time.Now
5755

58-
var (
59-
PolicySourcesFrom = source.PolicySourcesFrom
60-
CreateWorkDir = utils.CreateWorkDir
61-
PolicyCacheFromContext = cache.PolicyCacheFromContext
62-
)
56+
var PolicySourcesFrom = source.PolicySourcesFrom
6357

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

68-
// Create a JSON schema from a Go type, and return the JSON as a byte slice
69-
func jsonSchemaFromPolicySpec(ecp *ecc.EnterpriseContractPolicySpec) ([]byte, error) {
70-
r := new(schemaExporter.Reflector)
71-
schema := r.Reflect(ecp)
72-
schemaJson, err := json.MarshalIndent(schema, "", " ")
73-
if err != nil {
74-
return nil, err
75-
}
76-
return schemaJson, nil
77-
}
78-
7962
type SigstoreOpts struct {
8063
CertificateIdentity string `json:"certificate_identity"`
8164
CertificateIdentityRegExp string `json:"certificate_identity_regexp"`

internal/policy/policy_test.go

-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
hd "github.com/MakeNowJust/heredoc"
3131
ecc "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
32-
"github.com/gkampitakis/go-snaps/snaps"
3332
"github.com/sigstore/cosign/v2/pkg/cosign"
3433
cosignSig "github.com/sigstore/cosign/v2/pkg/signature"
3534
sigstoreSig "github.com/sigstore/sigstore/pkg/signature"
@@ -718,17 +717,6 @@ func TestIsConformant(t *testing.T) {
718717
}
719718
}
720719

721-
func TestJsonSchemaFromPolicySpec(t *testing.T) {
722-
ecp := &ecc.EnterpriseContractPolicySpec{
723-
PublicKey: "testPublicKey",
724-
RekorUrl: "testRekorUrl",
725-
}
726-
schemaJson, err := jsonSchemaFromPolicySpec(ecp)
727-
assert.NoError(t, err)
728-
729-
snaps.MatchJSON(t, schemaJson)
730-
}
731-
732720
func TestSigstoreOpts(t *testing.T) {
733721
cases := []struct {
734722
name string

internal/utils/helpers.go

-26
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,19 @@
1717
package utils
1818

1919
import (
20-
"bytes"
2120
"context"
2221
"encoding/json"
2322
"fmt"
2423
"os"
2524
"path/filepath"
2625
"strings"
27-
"unicode"
2826

2927
isatty "github.com/mattn/go-isatty"
3028
log "github.com/sirupsen/logrus"
3129
"github.com/spf13/afero"
3230
"sigs.k8s.io/yaml"
3331
)
3432

35-
// ToJSON converts a single YAML document into a JSON document
36-
// or returns an error. If the document appears to be JSON the
37-
// YAML decoding path is not used.
38-
func ToJSON(data []byte) ([]byte, error) {
39-
if hasJSONPrefix(data) {
40-
return data, nil
41-
}
42-
return yaml.YAMLToJSON(data)
43-
}
44-
45-
var jsonPrefix = []byte("{")
46-
47-
// hasJSONPrefix returns true if the provided buffer appears to start with
48-
// a JSON open brace.
49-
func hasJSONPrefix(buf []byte) bool {
50-
return hasPrefix(buf, jsonPrefix)
51-
}
52-
53-
// hasPrefix returns true if the first non-whitespace bytes in buf is prefix.
54-
func hasPrefix(buf []byte, prefix []byte) bool {
55-
trim := bytes.TrimLeftFunc(buf, unicode.IsSpace)
56-
return bytes.HasPrefix(trim, prefix)
57-
}
58-
5933
// CreateWorkDir creates the working directory in tmp and some subdirectories
6034
func CreateWorkDir(fs afero.Fs) (string, error) {
6135
workDir, err := afero.TempDir(fs, afero.GetTempDir(fs, ""), "ec-work-")

0 commit comments

Comments
 (0)