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

Redact empty status properties #3180

Merged
merged 3 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions v2/cmd/asoctl/cmd/import_azure_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package cmd

import (
"context"
"os"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
Expand Down Expand Up @@ -118,7 +117,7 @@ func importAzureResource(ctx context.Context, armIDs []string, options importAzu
return errors.Wrapf(err, "failed to write into folder %s", folder)
}
} else {
err := result.SaveToWriter(os.Stdout)
err := result.SaveToWriter(progress)
if err != nil {
return errors.Wrapf(err, "failed to write to stdout")
}
Expand Down
10 changes: 10 additions & 0 deletions v2/cmd/asoctl/internal/importing/resource_import_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -125,6 +126,8 @@ func (*ResourceImportResult) writeTo(resources []genruntime.MetaObject, destinat
return errors.Wrap(err, "unable to save to writer")
}

data = redact(data)

_, err = buf.Write(data)
if err != nil {
return errors.Wrap(err, "unable to save to writer")
Expand All @@ -138,3 +141,10 @@ func (*ResourceImportResult) writeTo(resources []genruntime.MetaObject, destinat

return nil
}

// redact removes any empty `status { }` blocks from the yaml
func redact(data []byte) []byte {
Copy link
Member

Choose a reason for hiding this comment

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

minor: redactStatus? Since it doesn't generally redact "other stuff"?

content := string(data)
content = strings.Replace(content, "status: {}", "", -1)
return []byte(content)
}