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

reduce yaml output verbosity #67

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 11 additions & 7 deletions cmd/generate_gatewayapi_httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"

"github.com/getkin/kin-openapi/openapi3"
"github.com/ghodss/yaml"
"github.com/kuadrant/kuadrantctl/pkg/gatewayapi"
"github.com/kuadrant/kuadrantctl/pkg/utils"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)
Expand Down Expand Up @@ -57,15 +57,19 @@ func runGenerateGatewayApiHttpRoute(cmd *cobra.Command, args []string) error {
}

httpRoute := buildHTTPRoute(doc)
jsonBytes, err := json.Marshal(httpRoute)
if err != nil {
return err
}

var outputBytes []byte
if generateGatewayAPIHTTPRouteFormat == "json" {
outputBytes, err = json.Marshal(httpRoute)
} else { // default to YAML if not explicitly JSON
outputBytes, err = yaml.Marshal(httpRoute)
}
if err != nil {
return err
outputBytes = jsonBytes
} else {
outputBytes, err = yaml.JSONToYAML(jsonBytes) // use `omitempty`'s from the json Marshal
if err != nil {
return err
}
}

fmt.Fprintln(cmd.OutOrStdout(), string(outputBytes))
Expand Down
18 changes: 11 additions & 7 deletions cmd/generate_kuadrant_authpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"

"github.com/getkin/kin-openapi/openapi3"
"github.com/ghodss/yaml"
kuadrantapiv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
Expand Down Expand Up @@ -61,15 +61,19 @@ func runGenerateKuadrantAuthPolicy(cmd *cobra.Command, args []string) error {
}

ap := buildAuthPolicy(doc)
jsonBytes, err := json.Marshal(ap)
if err != nil {
return err
}

var outputBytes []byte
if generateAuthPolicyFormat == "json" {
outputBytes, err = json.Marshal(ap)
} else { // default to YAML if not explicitly JSON
outputBytes, err = yaml.Marshal(ap)
}
if err != nil {
return err
outputBytes = jsonBytes
} else {
outputBytes, err = yaml.JSONToYAML(jsonBytes) // use `omitempty`'s from the json Marshal
if err != nil {
return err
}
}

fmt.Fprintln(cmd.OutOrStdout(), string(outputBytes))
Expand Down
20 changes: 13 additions & 7 deletions cmd/generate_kuadrant_ratelimitpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"os"

"github.com/getkin/kin-openapi/openapi3"
"github.com/ghodss/yaml"

kuadrantapiv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
Expand Down Expand Up @@ -63,16 +64,21 @@ func runGenerateKuadrantRateLimitPolicy(cmd *cobra.Command, args []string) error

rlp := buildRateLimitPolicy(doc)

var outputBytes []byte
if generateRateLimitPolicyFormat == "json" {
outputBytes, err = json.Marshal(rlp)
} else { // default to YAML if not explicitly JSON
outputBytes, err = yaml.Marshal(rlp)
}
jsonBytes, err := json.Marshal(rlp)
if err != nil {
return err
}

var outputBytes []byte
if generateRateLimitPolicyFormat == "json" {
outputBytes = jsonBytes
} else {
outputBytes, err = yaml.JSONToYAML(jsonBytes) // use `omitempty`'s from the json Marshal
if err != nil {
return err
}
}

fmt.Fprintln(cmd.OutOrStdout(), string(outputBytes))
return nil
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/getkin/kin-openapi v0.120.0 h1:MqJcNJFrMDFNc07iwE8iFC5eT2k/NPUFDIpNeiZv8Jg=
github.com/getkin/kin-openapi v0.120.0/go.mod h1:PCWw/lfBrJY4HcdqE3jj+QFkaFK8ABoqo7PvqVhXXqw=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down
Loading