From 329e930497a04a76a39fef5402ba949508796251 Mon Sep 17 00:00:00 2001 From: dlorenc <dlorenc@google.com> Date: Mon, 20 Dec 2021 06:56:46 -0600 Subject: [PATCH] Remove the fetchedExternalEntities bool. (#551) This didn't appear to actually be useful on any of our types - we also check the actual fields that need to be hydrated directly. Signed-off-by: Dan Lorenc <lorenc.d@gmail.com> --- pkg/types/alpine/v0.0.1/entry.go | 16 +++------------- pkg/types/helm/v0.0.1/entry.go | 18 ++++-------------- pkg/types/jar/v0.0.1/entry.go | 18 ++++-------------- pkg/types/rekord/v0.0.1/entry.go | 23 +++-------------------- pkg/types/rpm/v0.0.1/entry.go | 14 +++----------- pkg/types/tuf/v0.0.1/entry.go | 11 +++-------- 6 files changed, 20 insertions(+), 80 deletions(-) diff --git a/pkg/types/alpine/v0.0.1/entry.go b/pkg/types/alpine/v0.0.1/entry.go index 43ec183..c27a3ae 100644 --- a/pkg/types/alpine/v0.0.1/entry.go +++ b/pkg/types/alpine/v0.0.1/entry.go @@ -52,10 +52,9 @@ func init() { } type V001Entry struct { - AlpineModel models.AlpineV001Schema - fetchedExternalEntities bool - keyObj pki.PublicKey - apkObj *alpine.Package + AlpineModel models.AlpineV001Schema + keyObj pki.PublicKey + apkObj *alpine.Package } func (v V001Entry) APIVersion() string { @@ -113,10 +112,6 @@ func (v *V001Entry) Unmarshal(pe models.ProposedEntry) error { } func (v V001Entry) hasExternalEntities() bool { - if v.fetchedExternalEntities { - return false - } - if v.AlpineModel.Package != nil && v.AlpineModel.Package.URL.String() != "" { return true } @@ -127,10 +122,6 @@ func (v V001Entry) hasExternalEntities() bool { } func (v *V001Entry) fetchExternalEntities(ctx context.Context) error { - if v.fetchedExternalEntities { - return nil - } - if err := v.validate(); err != nil { return types.ValidationError(err) } @@ -268,7 +259,6 @@ func (v *V001Entry) fetchExternalEntities(ctx context.Context) error { v.AlpineModel.Package.Hash.Value = swag.String(computedSHA) } - v.fetchedExternalEntities = true return nil } diff --git a/pkg/types/helm/v0.0.1/entry.go b/pkg/types/helm/v0.0.1/entry.go index 74de7f0..627ecd6 100644 --- a/pkg/types/helm/v0.0.1/entry.go +++ b/pkg/types/helm/v0.0.1/entry.go @@ -52,11 +52,10 @@ func init() { } type V001Entry struct { - HelmObj models.HelmV001Schema - fetchedExternalEntities bool - keyObj pki.PublicKey - sigObj pki.Signature - provenanceObj *helm.Provenance + HelmObj models.HelmV001Schema + keyObj pki.PublicKey + sigObj pki.Signature + provenanceObj *helm.Provenance } func (v V001Entry) APIVersion() string { @@ -120,10 +119,6 @@ func (v *V001Entry) Unmarshal(pe models.ProposedEntry) error { } func (v V001Entry) hasExternalEntities() bool { - if v.fetchedExternalEntities { - return false - } - if v.HelmObj.PublicKey != nil && v.HelmObj.PublicKey.URL.String() != "" { return true } @@ -135,10 +130,6 @@ func (v V001Entry) hasExternalEntities() bool { } func (v *V001Entry) fetchExternalEntities(ctx context.Context) error { - if v.fetchedExternalEntities { - return nil - } - if err := v.validate(); err != nil { return types.ValidationError(err) } @@ -246,7 +237,6 @@ func (v *V001Entry) fetchExternalEntities(ctx context.Context) error { return err } - v.fetchedExternalEntities = true return nil } diff --git a/pkg/types/jar/v0.0.1/entry.go b/pkg/types/jar/v0.0.1/entry.go index c7932f1..e033d07 100644 --- a/pkg/types/jar/v0.0.1/entry.go +++ b/pkg/types/jar/v0.0.1/entry.go @@ -56,11 +56,10 @@ func init() { } type V001Entry struct { - JARModel models.JarV001Schema - fetchedExternalEntities bool - jarObj *jarutils.JarSignature - keyObj pki.PublicKey - sigObj pki.Signature + JARModel models.JarV001Schema + jarObj *jarutils.JarSignature + keyObj pki.PublicKey + sigObj pki.Signature } func (v V001Entry) APIVersion() string { @@ -116,10 +115,6 @@ func (v *V001Entry) Unmarshal(pe models.ProposedEntry) error { } func (v V001Entry) hasExternalEntities() bool { - if v.fetchedExternalEntities { - return false - } - if v.JARModel.Archive != nil && v.JARModel.Archive.URL.String() != "" { return true } @@ -127,10 +122,6 @@ func (v V001Entry) hasExternalEntities() bool { } func (v *V001Entry) fetchExternalEntities(ctx context.Context) error { - if v.fetchedExternalEntities { - return nil - } - if err := v.validate(); err != nil { return types.ValidationError(err) } @@ -206,7 +197,6 @@ func (v *V001Entry) fetchExternalEntities(ctx context.Context) error { v.JARModel.Archive.Hash.Value = swag.String(computedSHA) } - v.fetchedExternalEntities = true return nil } diff --git a/pkg/types/rekord/v0.0.1/entry.go b/pkg/types/rekord/v0.0.1/entry.go index 5377987..24f8997 100644 --- a/pkg/types/rekord/v0.0.1/entry.go +++ b/pkg/types/rekord/v0.0.1/entry.go @@ -51,10 +51,9 @@ func init() { } type V001Entry struct { - RekordObj models.RekordV001Schema - fetchedExternalEntities bool - keyObj pki.PublicKey - sigObj pki.Signature + RekordObj models.RekordV001Schema + keyObj pki.PublicKey + sigObj pki.Signature } func (v V001Entry) APIVersion() string { @@ -68,13 +67,6 @@ func NewEntry() types.EntryImpl { func (v V001Entry) IndexKeys() []string { var result []string - if v.HasExternalEntities() { - if err := v.FetchExternalEntities(context.Background()); err != nil { - log.Logger.Error(err) - return result - } - } - key, err := v.keyObj.CanonicalValue() if err != nil { log.Logger.Error(err) @@ -113,10 +105,6 @@ func (v *V001Entry) Unmarshal(pe models.ProposedEntry) error { } func (v V001Entry) HasExternalEntities() bool { - if v.fetchedExternalEntities { - return false - } - if v.RekordObj.Data != nil && v.RekordObj.Data.URL.String() != "" { return true } @@ -130,10 +118,6 @@ func (v V001Entry) HasExternalEntities() bool { } func (v *V001Entry) FetchExternalEntities(ctx context.Context) error { - if v.fetchedExternalEntities { - return nil - } - if err := v.validate(); err != nil { return types.ValidationError(err) } @@ -291,7 +275,6 @@ func (v *V001Entry) FetchExternalEntities(ctx context.Context) error { v.RekordObj.Data.Hash.Value = swag.String(computedSHA) } - v.fetchedExternalEntities = true return nil } diff --git a/pkg/types/rpm/v0.0.1/entry.go b/pkg/types/rpm/v0.0.1/entry.go index 449cfa3..5e915f1 100644 --- a/pkg/types/rpm/v0.0.1/entry.go +++ b/pkg/types/rpm/v0.0.1/entry.go @@ -54,10 +54,9 @@ func init() { } type V001Entry struct { - RPMModel models.RpmV001Schema - fetchedExternalEntities bool - keyObj pki.PublicKey - rpmObj *rpmutils.PackageFile + RPMModel models.RpmV001Schema + keyObj pki.PublicKey + rpmObj *rpmutils.PackageFile } func (v V001Entry) APIVersion() string { @@ -115,9 +114,6 @@ func (v *V001Entry) Unmarshal(pe models.ProposedEntry) error { } func (v V001Entry) HasExternalEntities() bool { - if v.fetchedExternalEntities { - return false - } if v.RPMModel.Package != nil && v.RPMModel.Package.URL.String() != "" { return true @@ -129,9 +125,6 @@ func (v V001Entry) HasExternalEntities() bool { } func (v *V001Entry) FetchExternalEntities(ctx context.Context) error { - if v.fetchedExternalEntities { - return nil - } if err := v.validate(); err != nil { return types.ValidationError(err) @@ -273,7 +266,6 @@ func (v *V001Entry) FetchExternalEntities(ctx context.Context) error { v.RPMModel.Package.Hash.Value = swag.String(computedSHA) } - v.fetchedExternalEntities = true return nil } diff --git a/pkg/types/tuf/v0.0.1/entry.go b/pkg/types/tuf/v0.0.1/entry.go index 012f41b..2af6291 100644 --- a/pkg/types/tuf/v0.0.1/entry.go +++ b/pkg/types/tuf/v0.0.1/entry.go @@ -63,10 +63,9 @@ type BaseSigned struct { } type V001Entry struct { - TufObj models.TUFV001Schema - fetchedExternalEntities bool - keyObj pki.PublicKey - sigObj pki.Signature + TufObj models.TUFV001Schema + keyObj pki.PublicKey + sigObj pki.Signature } func (v V001Entry) APIVersion() string { @@ -138,9 +137,6 @@ func (v *V001Entry) Unmarshal(pe models.ProposedEntry) error { } func (v V001Entry) hasExternalEntities() bool { - if v.fetchedExternalEntities { - return false - } if v.TufObj.Metadata != nil && v.TufObj.Metadata.URL.String() != "" { return true @@ -278,7 +274,6 @@ func (v *V001Entry) fetchExternalEntities(ctx context.Context) error { return err } - v.fetchedExternalEntities = true return nil } -- GitLab