Skip to content

Commit

Permalink
remove structs usage, using mapstructure instead
Browse files Browse the repository at this point in the history
Signed-off-by: Javan lacerda <javanlacerda@google.com>
  • Loading branch information
javanlacerda committed Jun 26, 2024
1 parent e7cd08f commit 13e7059
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/ThalesIgnite/crypto11 v1.2.5
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/coreos/go-oidc/v3 v3.10.0
github.com/fatih/structs v1.1.0
github.com/fsnotify/fsnotify v1.7.0
github.com/go-jose/go-jose/v4 v4.0.2
github.com/goadesign/goa v2.2.5+incompatible
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand Down
10 changes: 7 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"time"

"github.com/coreos/go-oidc/v3/oidc"
"github.com/fatih/structs"
lru "github.com/hashicorp/golang-lru"
"github.com/mitchellh/mapstructure"
"github.com/sigstore/fulcio/pkg/certificate"
fulciogrpc "github.com/sigstore/fulcio/pkg/generated/protobuf"
"github.com/sigstore/fulcio/pkg/log"
Expand Down Expand Up @@ -468,14 +468,18 @@ func CheckParseTemplates(fulcioConfig *FulcioConfig) error {
}

for _, ciIssuerMetadata := range fulcioConfig.CIIssuerMetadata {
claimsTemplates := structs.Map(ciIssuerMetadata.ClaimsTemplates)
claimsTemplates := make(map[string]interface{})
err := mapstructure.Decode(ciIssuerMetadata.ClaimsTemplates, &claimsTemplates)
if err != nil {
return err
}
for _, temp := range claimsTemplates {
err := checkParse(temp)
if err != nil {
return err
}
}
err := checkParse(ciIssuerMetadata.SubjectAlternativeNameTemplate)
err = checkParse(ciIssuerMetadata.SubjectAlternativeNameTemplate)
if err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/identity/ciprovider/principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"strings"

"github.com/coreos/go-oidc/v3/oidc"
"github.com/fatih/structs"
"github.com/mitchellh/mapstructure"
"github.com/sigstore/fulcio/pkg/certificate"
"github.com/sigstore/fulcio/pkg/config"
Expand Down Expand Up @@ -128,8 +127,13 @@ func (principal ciPrincipal) Embed(_ context.Context, cert *x509.Certificate) er
}
uris := []*url.URL{sanURL}
cert.URIs = uris
mapExtensionsForTemplate := mapValuesToString(structs.Map(claimsTemplates))
for k, v := range mapExtensionsForTemplate {
mapExtensionsForTemplate := make(map[string]interface{})
err = mapstructure.Decode(claimsTemplates, &mapExtensionsForTemplate)
if err != nil {
return err
}

for k, v := range mapValuesToString(mapExtensionsForTemplate) {
// It avoids to try applying template or replace for a empty string.
if v != "" {
mapExtensionsForTemplate[k], err = applyTemplateOrReplace(v, claims, defaults)
Expand Down

0 comments on commit 13e7059

Please sign in to comment.