Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly convert inMediaType json to outMediaType yaml #54

Merged
merged 2 commits into from
May 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/encoding/encoding.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄 I think we can just use yaml.YAMLToJSON and yaml.JSONToYAML from sigs.k8s.io/yaml

I made a similar change in another repo.
https://github.com/kubernetes-sigs/kwok/blob/a284d0ca8703257a9b36a48bb4de328898268162/pkg/kwokctl/etcd/etcd.go#L61-L75

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right about this.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

: # github.com/etcd-io/auger/pkg/encoding [github.com/etcd-io/auger/pkg/encoding.test]
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -95,6 +95,15 @@
if outMediaType == JsonMediaType {
encoded = append(encoded, '\n')
}
} else if inMediaType == JsonMediaType && outMediaType == YamlMediaType {
val := map[string]interface{}{}
if err := json.Unmarshal(in, &val); err != nil {
return nil, fmt.Errorf("error decoding from %s: %s", inMediaType, err)

Check failure on line 101 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / test

not enough return values

Check failure on line 101 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values

Check failure on line 101 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values

Check failure on line 101 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values
}
encoded, err = yaml.Marshal(val)
if err != nil {
return nil, fmt.Errorf("error encoding from %s: %s", outMediaType, err)

Check failure on line 105 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / test

not enough return values

Check failure on line 105 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values

Check failure on line 105 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values

Check failure on line 105 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values
}
} else {
inCodec, err := newCodec(codecs, typeMeta, inMediaType)
if err != nil {
Expand Down
Loading