Allow configured providers to provide additional functions. (#1491)

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
Christian Mesh
2024-04-18 09:11:38 -04:00
committed by GitHub
parent 0ea88633d0
commit a69d19d9f3
32 changed files with 720 additions and 276 deletions

View File

@@ -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{