github.com/ystia/yorc/v4@v4.3.0/plugin/definitions.go (about) 1 // Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package plugin 16 17 import ( 18 "net/rpc" 19 20 plugin "github.com/hashicorp/go-plugin" 21 "github.com/pkg/errors" 22 ) 23 24 // Definitions is the interface that allows a plugin to export TOSCA definitions 25 type Definitions interface { 26 // GetDefinitions returns a map of definition names / definition content 27 GetDefinitions() (map[string][]byte, error) 28 } 29 30 // DefinitionsPlugin is public for use by reflexion and should be considered as private to this package. 31 // Please do not use it directly. 32 type DefinitionsPlugin struct { 33 Definitions map[string][]byte 34 } 35 36 // DefinitionsServer is public for use by reflexion and should be considered as private to this package. 37 // Please do not use it directly. 38 type DefinitionsServer struct { 39 Definitions map[string][]byte 40 } 41 42 // Server is public for use by reflexion and should be considered as private to this package. 43 // Please do not use it directly. 44 func (p *DefinitionsPlugin) Server(b *plugin.MuxBroker) (interface{}, error) { 45 return &DefinitionsServer{Definitions: p.Definitions}, nil 46 } 47 48 // DefinitionsClient is public for use by reflexion and should be considered as private to this package. 49 // Please do not use it directly. 50 type DefinitionsClient struct { 51 Client *rpc.Client 52 } 53 54 // Client is public for use by reflexion and should be considered as private to this package. 55 // Please do not use it directly. 56 func (p *DefinitionsPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) { 57 return &DefinitionsClient{Client: c}, nil 58 } 59 60 // GetDefinitions is public for use by reflexion and should be considered as private to this package. 61 // Please do not use it directly. 62 func (s *DefinitionsServer) GetDefinitions(_ interface{}, reply *DelegateExecutorGetDefinitionsResponse) error { 63 *reply = DelegateExecutorGetDefinitionsResponse{ 64 Definitions: s.Definitions, 65 } 66 return nil 67 } 68 69 // DelegateExecutorGetDefinitionsResponse is public for use by reflexion and should be considered as private to this package. 70 // Please do not use it directly. 71 type DelegateExecutorGetDefinitionsResponse struct { 72 Definitions map[string][]byte 73 Error *RPCError 74 } 75 76 // GetDefinitions is public for use by reflexion and should be considered as private to this package. 77 // Please do not use it directly. 78 func (c *DefinitionsClient) GetDefinitions() (map[string][]byte, error) { 79 var resp DelegateExecutorGetDefinitionsResponse 80 err := c.Client.Call("Plugin.GetDefinitions", new(interface{}), &resp) 81 if err != nil { 82 return nil, errors.Wrap(err, "Failed to get tosca definitions for delegate plugin") 83 } 84 return resp.Definitions, toError(resp.Error) 85 }