mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
Allow configured providers to provide additional functions. (#1491)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
@@ -693,6 +693,26 @@ func (p *GRPCProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp p
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *GRPCProvider) GetFunctions() (resp providers.GetFunctionsResponse) {
|
||||
logger.Trace("GRPCProvider: GetFunctions")
|
||||
|
||||
protoReq := &proto.GetFunctions_Request{}
|
||||
|
||||
protoResp, err := p.client.GetFunctions(p.ctx, protoReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(grpcErr(err))
|
||||
return resp
|
||||
}
|
||||
resp.Diagnostics = resp.Diagnostics.Append(convert.ProtoToDiagnostics(protoResp.Diagnostics))
|
||||
resp.Functions = make(map[string]providers.FunctionSpec)
|
||||
|
||||
for name, fn := range protoResp.Functions {
|
||||
resp.Functions[name] = convert.ProtoToFunctionSpec(fn)
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *GRPCProvider) CallFunction(r providers.CallFunctionRequest) (resp providers.CallFunctionResponse) {
|
||||
logger.Trace("GRPCProvider: CallFunction")
|
||||
|
||||
@@ -705,9 +725,18 @@ func (p *GRPCProvider) CallFunction(r providers.CallFunctionRequest) (resp provi
|
||||
|
||||
spec, ok := schema.Functions[r.Name]
|
||||
if !ok {
|
||||
// This should be unreachable
|
||||
resp.Error = fmt.Errorf("invalid CallFunctionRequest: function %s not defined in provider schema", r.Name)
|
||||
return resp
|
||||
funcs := p.GetFunctions()
|
||||
if funcs.Diagnostics.HasErrors() {
|
||||
// This should be unreachable
|
||||
resp.Error = funcs.Diagnostics.Err()
|
||||
return resp
|
||||
}
|
||||
spec, ok = funcs.Functions[r.Name]
|
||||
if !ok {
|
||||
// This should be unreachable
|
||||
resp.Error = fmt.Errorf("invalid CallFunctionRequest: function %s not defined in provider schema", r.Name)
|
||||
return resp
|
||||
}
|
||||
}
|
||||
|
||||
protoReq := &proto.CallFunction_Request{
|
||||
|
||||
Reference in New Issue
Block a user