Skip to content

Commit

Permalink
proto helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed May 21, 2024
1 parent 0a5fbac commit 218525d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 2 additions & 6 deletions backend/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ func TestInstanceSettingsAdmissionConversions(t *testing.T) {
"A": "B",
},
}
wire, err := before.ToProto()
require.NoError(t, err)
after, err := backend.DataSourceInstanceSettingsFromProto(wire, "")
after, err := backend.DataSourceInstanceSettingsFromProto(before.ProtoBytes(), "")
require.NoError(t, err)
require.Equal(t, before.URL, after.URL)
require.Equal(t, before.User, after.User)
Expand All @@ -37,9 +35,7 @@ func TestInstanceSettingsAdmissionConversions(t *testing.T) {
"A": "B",
},
}
wire, err := before.ToProto()
require.NoError(t, err)
after, err := backend.AppInstanceSettingsFromProto(wire)
after, err := backend.AppInstanceSettingsFromProto(before.ProtoBytes())
require.NoError(t, err)
require.Equal(t, before.JSONData, after.JSONData)
require.Equal(t, before.DecryptedSecureJSONData, after.DecryptedSecureJSONData)
Expand Down
12 changes: 8 additions & 4 deletions backend/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ func (s *AppInstanceSettings) GVK() GroupVersionKind {
}
}

func (s *AppInstanceSettings) ToProto() ([]byte, error) {
return proto.Marshal(ConvertToProtobuf{}.AppInstanceSettings(s))
// ProtoBytes returns the settings the the byte structure expected by admission hooks
func (s *AppInstanceSettings) ProtoBytes() []byte {
v, _ := proto.Marshal(ConvertToProtobuf{}.AppInstanceSettings(s))
return v
}

func AppInstanceSettingsFromProto(body []byte) (*AppInstanceSettings, error) {
Expand Down Expand Up @@ -179,8 +181,10 @@ func (s *DataSourceInstanceSettings) GVK() GroupVersionKind {
}
}

func (s *DataSourceInstanceSettings) ToProto() ([]byte, error) {
return proto.Marshal(ConvertToProtobuf{}.DataSourceInstanceSettings(s))
// ProtoBytes returns the settings the the byte structure expected by admission hooks
func (s *DataSourceInstanceSettings) ProtoBytes() []byte {
v, _ := proto.Marshal(ConvertToProtobuf{}.DataSourceInstanceSettings(s))
return v
}

func DataSourceInstanceSettingsFromProto(body []byte, pluginID string) (*DataSourceInstanceSettings, error) {
Expand Down

0 comments on commit 218525d

Please sign in to comment.