Skip to content

Commit

Permalink
Merge branch 'main' into change-short-text-for-help-text
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmarf authored Nov 8, 2024
2 parents 5bb7462 + 3577e7e commit 8e3d3ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion api/credentials/internal/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,32 @@ func orMatcher(list []IdentityMatcher) IdentityMatcher {
// ConsumerIdentity describes the identity of a credential consumer.
type ConsumerIdentity map[string]string

// UnmarshalJSON allows a yaml specification containing a data type other
// string, e.g. a hostpath spec with a port. Previously, it would error if the
// user specified `port: 5000` and instead, the user had to specify
// `port: "5000"`.
func (c *ConsumerIdentity) UnmarshalJSON(data []byte) error {
var m map[string]interface{}
err := runtime.DefaultJSONEncoding.Unmarshal(data, &m)
if err != nil {
return err
}

if len(m) == 0 {
return nil
}
*c = make(map[string]string, len(m))
for k, v := range m {
switch v.(type) {
case nil:
(*c)[k] = ""
case map[string]interface{}:
return fmt.Errorf("cannot unmarshal complex type into consumer identity")
case []interface{}:
return fmt.Errorf("cannot unmarshal complex type into consumer identity")
default:
(*c)[k] = fmt.Sprintf("%v", v)
}
(*c)[k] = fmt.Sprintf("%v", v)
}
return nil
}
Expand Down
15 changes: 15 additions & 0 deletions api/credentials/internal/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ port:
cid := internal.ConsumerIdentity{}
Expect(yaml.Unmarshal([]byte(data), &cid)).NotTo(Succeed())
})
It("with nil", func() {
data := `
scheme: http
hostname: 127.0.0.1
port:
`
id := internal.ConsumerIdentity{
"scheme": "http",
"hostname": "127.0.0.1",
"port": "",
}
cid := internal.ConsumerIdentity{}
Expect(yaml.Unmarshal([]byte(data), &cid)).To(Succeed())
Expect(cid).To(Equal(id))
})
})
2 changes: 1 addition & 1 deletion api/ocm/extensions/accessmethods/ociartifact/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (m *accessMethod) eval(relto oci.Repository) error {
ocictx := m.ctx.OCIContext()
spec := ocictx.GetAlias(ref.Host)
if spec == nil {
spec = ocireg.NewRepositorySpec(ref.Host)
spec = ocireg.NewRepositorySpec(ref.RepositoryRef())
}
repo, err := ocictx.RepositoryForSpec(spec)
if err != nil {
Expand Down

0 comments on commit 8e3d3ef

Please sign in to comment.