Skip to content

Commit

Permalink
allow nil data writes for resources
Browse files Browse the repository at this point in the history
  • Loading branch information
skpratt committed Sep 15, 2023
1 parent 9c1a1ff commit 100735c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
4 changes: 1 addition & 3 deletions agent/grpc-external/services/resource/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Server) Write(ctx context.Context, req *pbresource.WriteRequest) (*pbre
}

// Check the user sent the correct type of data.
if !req.Resource.Data.MessageIs(reg.Proto) {
if req.Resource.Data != nil && !req.Resource.Data.MessageIs(reg.Proto) {
got := strings.TrimPrefix(req.Resource.Data.TypeUrl, "type.googleapis.com/")

return nil, status.Errorf(
Expand Down Expand Up @@ -272,8 +272,6 @@ func (s *Server) validateWriteRequest(req *pbresource.WriteRequest) (*resource.R
field = "resource"
case req.Resource.Id == nil:
field = "resource.id"
case req.Resource.Data == nil:
field = "resource.data"
}

if field != "" {
Expand Down
4 changes: 0 additions & 4 deletions agent/grpc-external/services/resource/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ func TestWrite_InputValidation(t *testing.T) {
artist.Id.Name = ""
return artist
},
"no data": func(artist, _ *pbresource.Resource) *pbresource.Resource {
artist.Data = nil
return artist
},
"wrong data type": func(artist, _ *pbresource.Resource) *pbresource.Resource {
var err error
artist.Data, err = anypb.New(&pbdemov2.Album{})
Expand Down

0 comments on commit 100735c

Please sign in to comment.