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

Preserve resource format when saving a resource via grr serve #512

Merged
merged 1 commit into from
Oct 30, 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
2 changes: 2 additions & 0 deletions pkg/grizzly/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ func parseAny(registry Registry, data any, resourceKind, folderUID string, sourc
if err != nil {
return Resources{}, err
}

source.WithEnvelope = true
resource.SetSource(source)

return NewResources(*resource), nil
Expand Down
14 changes: 10 additions & 4 deletions pkg/grizzly/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ func (ref ResourceRef) String() string {
return fmt.Sprintf("%s.%s", ref.Kind, ref.Name)
}

// Source represents the on disk (etc) location of a resource
// Source holds metadata regarding the origin of a resource on disk.
type Source struct {
Format string
Location string
Path string
// Format represents the original format. Ex: json, yaml, ...
Format string
Location string
// Path represents the path on disk to the file describing the resource.
Path string
// Rewritable indicates whether the resource can be written or not.
// Ex: resources parsed from a watch script are not rewritable.
Rewritable bool
// WithEnvelope indicates whether the resource had an envelope or not.
WithEnvelope bool
}

// Resource represents a single Resource destined for a single endpoint
Expand Down
2 changes: 1 addition & 1 deletion pkg/grizzly/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (s *Server) faviconHandlerFunc() http.HandlerFunc {
}

func (s *Server) UpdateResource(name string, resource Resource) error {
out, _, _, err := Format(s.Registry, s.ResourcePath, &resource, s.OutputFormat, s.OnlySpec)
out, _, _, err := Format(s.Registry, s.ResourcePath, &resource, resource.Source.Format, !resource.Source.WithEnvelope)
if err != nil {
return fmt.Errorf("error formatting content: %s", err)
}
Expand Down
Loading