Skip to content

Commit

Permalink
Redact empty status properties (#3180)
Browse files Browse the repository at this point in the history
* Add redaction of resources
* Use correct output stream
* Rename method based on PR feedback
  • Loading branch information
theunrepentantgeek authored Aug 6, 2023
1 parent 21171f2 commit b4e626b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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
13 changes: 13 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 = redactStatus(data)

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

return nil
}

// redactStatus removes any empty `status { }` blocks from the yaml.
// If we start redacting other things, we should rename this method
// and possibly consider using a more general purpose technique,
// such as a yaml parser.
func redactStatus(data []byte) []byte {
content := string(data)
content = strings.Replace(content, "status: {}", "", -1)
return []byte(content)
}

0 comments on commit b4e626b

Please sign in to comment.