@@ -256,21 +256,33 @@ type SyncRequest struct {
256256
257257type Input struct {
258258 Uri string `json:"uri,omitempty"`
259- Component string `json:"component "`
259+ ComponentName string `json:"componentName "`
260260 ComponentType string `json:"componentType"`
261- Type ResourceType `json:"type"`
262261 Metadata map [string ]string `json:"metadata,omitempty"`
263262}
264263
264+ // GetType will be called after the context has been parsed correctly,
265+ // therefore we do not have to handle the error return of getBuildingBlockType()
266+ func (i * Input ) GetType () ResourceType {
267+ bbt , _ := getBuildingBlockType (i .ComponentType )
268+ return bbt
269+ }
270+
265271type Output struct {
266272 Uri string `json:"uri,omitempty"`
267- Component string `json:"component "`
273+ ComponentName string `json:"componentName "`
268274 ComponentType string `json:"componentType"`
269- Type ResourceType `json:"type"`
270275 Metadata map [string ]string `json:"metadata,omitempty"`
271276 Operation string `json:"operation,omitempty"`
272277}
273278
279+ // GetType will be called after the context has been parsed correctly,
280+ // therefore we do not have to handle the error return of getBuildingBlockType()
281+ func (o * Output ) GetType () ResourceType {
282+ bbt , _ := getBuildingBlockType (o .ComponentType )
283+ return bbt
284+ }
285+
274286type FunctionOut struct {
275287 mu sync.Mutex
276288 Code int `json:"code"`
@@ -348,12 +360,12 @@ func (ctx *FunctionContext) Send(outputName string, data []byte) ([]byte, error)
348360 payloadBytes = ie .GetCloudEventJSON ()
349361 }
350362
351- switch output .Type {
363+ switch output .GetType () {
352364 case OpenFuncTopic :
353- err = ctx .daprClient .PublishEvent (context .Background (), output .Component , output .Uri , payload )
365+ err = ctx .daprClient .PublishEvent (context .Background (), output .ComponentName , output .Uri , payload )
354366 case OpenFuncBinding :
355367 in := & dapr.InvokeBindingRequest {
356- Name : output .Component ,
368+ Name : output .ComponentName ,
357369 Operation : output .Operation ,
358370 Data : payloadBytes ,
359371 Metadata : output .Metadata ,
@@ -684,22 +696,18 @@ func parseContext() (*FunctionContext, error) {
684696
685697 if ! ctx .HasInputs () {
686698 for name , in := range ctx .Inputs {
687- switch in .Type {
688- case OpenFuncBinding , OpenFuncTopic :
689- break
690- default :
691- return nil , fmt .Errorf ("invalid input type %s: %s" , name , in .Type )
699+ if _ , err := getBuildingBlockType (in .ComponentType ); err != nil {
700+ klog .Errorf ("failed to get building block type for input %s: %v" , name , err )
701+ return nil , err
692702 }
693703 }
694704 }
695705
696706 if ! ctx .HasOutputs () {
697707 for name , out := range ctx .Outputs {
698- switch out .Type {
699- case OpenFuncBinding , OpenFuncTopic :
700- break
701- default :
702- return nil , fmt .Errorf ("invalid output type %s: %s" , name , out .Type )
708+ if _ , err := getBuildingBlockType (out .ComponentType ); err != nil {
709+ klog .Errorf ("failed to get building block type for output %s: %v" , name , err )
710+ return nil , err
703711 }
704712 }
705713 }
@@ -784,3 +792,17 @@ func traceable(t string) bool {
784792 // determine if the tracing metadata can be added.
785793 return bindingQueueComponents [t ]
786794}
795+
796+ func getBuildingBlockType (componentType string ) (ResourceType , error ) {
797+ typeSplit := strings .Split (componentType , "." )
798+ if len (typeSplit ) > 1 {
799+ t := typeSplit [0 ]
800+ switch ResourceType (t ) {
801+ case OpenFuncBinding , OpenFuncTopic :
802+ return ResourceType (t ), nil
803+ default :
804+ return "" , fmt .Errorf ("unknown component type: %s" , t )
805+ }
806+ }
807+ return "" , errors .New ("invalid component type" )
808+ }
0 commit comments