From a1c7bbb991ac0dce76633c0a6e01b3c028dd3d25 Mon Sep 17 00:00:00 2001 From: James Carnegie Date: Mon, 29 Jul 2024 17:21:15 +0100 Subject: [PATCH] debt: remove goyaml. Fixup directives (#103) --- go.mod | 2 +- pkg/config/config.go | 6 +++--- pkg/config/types.go | 32 +++++++++++++++++--------------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 30e0841..415ecdc 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,6 @@ require ( github.com/testcontainers/testcontainers-go/modules/registry v0.32.0 github.com/theupdateframework/go-tuf/v2 v2.0.0 google.golang.org/api v0.189.0 - gopkg.in/yaml.v3 v3.0.1 sigs.k8s.io/yaml v1.4.0 ) @@ -200,5 +199,6 @@ require ( google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/klog/v2 v2.120.1 // indirect ) diff --git a/pkg/config/config.go b/pkg/config/config.go index 415e5b1..164c4f6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -7,7 +7,7 @@ import ( "regexp" "github.com/docker/attest/pkg/tuf" - goyaml "gopkg.in/yaml.v3" + "sigs.k8s.io/yaml" ) const ( @@ -24,7 +24,7 @@ func LoadLocalMappings(configDir string) (*PolicyMappings, error) { if err != nil { return nil, fmt.Errorf("failed to read local policy mapping file %s: %w", path, err) } - err = goyaml.Unmarshal(mappingFile, mappings) + err = yaml.Unmarshal(mappingFile, mappings) if err != nil { return nil, fmt.Errorf("failed to unmarshal policy mapping file %s: %w", path, err) } @@ -42,7 +42,7 @@ func LoadTufMappings(tufClient tuf.TUFClient, localTargetsDir string) (*PolicyMa } mappings := &policyMappingsFile{} - err = goyaml.Unmarshal(fileContents, mappings) + err = yaml.Unmarshal(fileContents, mappings) if err != nil { return nil, fmt.Errorf("failed to unmarshal policy mapping file %s: %w", filename, err) } diff --git a/pkg/config/types.go b/pkg/config/types.go index bbb8f55..1521803 100644 --- a/pkg/config/types.go +++ b/pkg/config/types.go @@ -1,18 +1,20 @@ package config -import "regexp" +import ( + "regexp" +) type policyMappingsFile struct { - Version string `yaml:"version"` - Kind string `yaml:"kind"` - Policies []*PolicyMapping `yaml:"policies"` - Rules []*policyRuleFile `yaml:"rules"` + Version string `json:"version"` + Kind string `json:"kind"` + Policies []*PolicyMapping `json:"policies"` + Rules []*policyRuleFile `json:"rules"` } type policyRuleFile struct { - Pattern string `yaml:"pattern"` - PolicyId string `yaml:"policy-id"` - Replacement string `yaml:"rewrite"` + Pattern string `json:"pattern"` + PolicyId string `json:"policy-id"` + Replacement string `json:"rewrite"` } type PolicyMappings struct { @@ -30,19 +32,19 @@ const ( ) type PolicyMapping struct { - Id string `yaml:"id"` - Description string `yaml:"description"` - Files []PolicyMappingFile `yaml:"files"` - Attestations *AttestationConfig `yaml:"attestations"` + Id string `json:"id"` + Description string `json:"description"` + Files []PolicyMappingFile `json:"files"` + Attestations *AttestationConfig `json:"attestations"` } type AttestationConfig struct { - Style AttestationStyle `yaml:"style"` - Repo string `yaml:"repo"` + Style AttestationStyle `json:"style"` + Repo string `json:"repo"` } type PolicyMappingFile struct { - Path string `yaml:"path"` + Path string `json:"path"` } type PolicyRule struct {