plugin

package
v0.12.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 15 Imported by: 0

README

Authorization plugin SDK

Import github.com/calypr/funnel/api/plugin as plugin for the generated messages, Authorize interface, handshake, and transport adapters. Both Funnel and external plugin implementations use this package.

Implement plugin.Authorize and supply the implementation through &plugin.AuthorizePlugin{Impl: impl} for net/rpc or &plugin.AuthorizeGRPCPlugin{Impl: impl} for gRPC. Pass plugin.Handshake to HashiCorp go-plugin on both sides. Host executable discovery and process lifecycle management remain internal to Funnel.

Task configuration

Plugins receive the complete server configuration in PluginAction. Return that configuration with the changes needed for the task. Local and Kubernetes backends merge the response into a per-task clone using mergo.WithOverwriteWithEmptyValue, matching uc-cdis Funnel. Empty values take precedence over server defaults.

effective := proto.Clone(inputConfig).(*config.Config)
effective.Worker.LeaveWorkDir = false
effective.Worker.ScratchPath = ""
delete(effective.Worker.Container.Env, "TEMP_TOKEN")

return &pluginproto.JobResponse{
	Code:   200,
	Config: effective,
}, nil

The example uses proto from google.golang.org/protobuf/proto and pluginproto from github.com/calypr/funnel/api/plugin.

Return the complete edited input, including settings unrelated to the plugin's changes. Partial responses can erase required configuration. False, zero, empty strings, cleared collections, and removed map entries override inherited values. The server's shared configuration stays unchanged between tasks. Existing task validation still applies, including Kubernetes' fixed Jobs namespace.

No response flag or protobuf schema change is required. Plugins that previously returned partial configurations must return the complete edited input instead.

Documentation

Overview

Package plugin defines Funnel's authorization plugin contract and shared HashiCorp go-plugin transport adapters for hosts and plugin implementations. Process discovery and lifecycle management live in internal/pluginmanager.

Index

Constants

View Source
const (
	Authorize_PluginAction_FullMethodName = "/proto.Authorize/PluginAction"
)

Variables

View Source
var (
	Type_name = map[int32]string{
		0: "CREATE",
		1: "GET",
		2: "CANCEL",
	}
	Type_value = map[string]int32{
		"CREATE": 0,
		"GET":    1,
		"CANCEL": 2,
	}
)

Enum value maps for Type.

View Source
var Authorize_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "proto.Authorize",
	HandlerType: (*AuthorizeServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "PluginAction",
			Handler:    _Authorize_PluginAction_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "plugin/plugin.proto",
}

Authorize_ServiceDesc is the grpc.ServiceDesc for Authorize service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

View Source
var File_plugin_plugin_proto protoreflect.FileDescriptor
View Source
var Handshake = hplugin.HandshakeConfig{

	ProtocolVersion:  1,
	MagicCookieKey:   "AUTHORIZE_PLUGIN",
	MagicCookieValue: "authorize",
}

Handshake is a common handshake that is shared by plugin and host.

View Source
var PluginMap = map[string]hplugin.Plugin{
	"authorize_grpc": &AuthorizeGRPCPlugin{},
	"authorize":      &AuthorizePlugin{},
}

PluginMap is the map of plugins we can dispense.

Functions

func RegisterAuthorizeServer

func RegisterAuthorizeServer(s grpc.ServiceRegistrar, srv AuthorizeServer)

Types

type Authorize

type Authorize interface {
	PluginAction(params map[string]string, headers map[string]*StringList, config *config.Config, task *tes.Task, actionType Type) (*JobResponse, error)
}

Authorize is implemented by Funnel authorization plugins.

type AuthorizeClient

type AuthorizeClient interface {
	PluginAction(ctx context.Context, in *Job, opts ...grpc.CallOption) (*JobResponse, error)
}

AuthorizeClient is the client API for Authorize service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewAuthorizeClient

func NewAuthorizeClient(cc grpc.ClientConnInterface) AuthorizeClient

type AuthorizeGRPCPlugin

type AuthorizeGRPCPlugin struct {
	// GRPCPlugin must still implement the Plugin interface
	hplugin.Plugin
	Impl Authorize
}

AuthorizeGRPCPlugin connects the authorizer to HashiCorp go-plugin over gRPC.

func (*AuthorizeGRPCPlugin) GRPCClient

func (p *AuthorizeGRPCPlugin) GRPCClient(ctx context.Context, broker *hplugin.GRPCBroker, c *grpc.ClientConn) (any, error)

func (*AuthorizeGRPCPlugin) GRPCServer

func (p *AuthorizeGRPCPlugin) GRPCServer(broker *hplugin.GRPCBroker, s *grpc.Server) error

type AuthorizePlugin

type AuthorizePlugin struct {
	Impl Authorize
}

AuthorizePlugin connects the authorizer to HashiCorp go-plugin over net/rpc.

func (*AuthorizePlugin) Client

func (*AuthorizePlugin) Client(b *hplugin.MuxBroker, c *rpc.Client) (any, error)

func (*AuthorizePlugin) Server

func (p *AuthorizePlugin) Server(*hplugin.MuxBroker) (any, error)

type AuthorizeServer

type AuthorizeServer interface {
	PluginAction(context.Context, *Job) (*JobResponse, error)
}

AuthorizeServer is the server API for Authorize service. All implementations should embed UnimplementedAuthorizeServer for forward compatibility

type Empty

type Empty struct {
	// contains filtered or unexported fields
}

func (*Empty) Descriptor deprecated

func (*Empty) Descriptor() ([]byte, []int)

Deprecated: Use Empty.ProtoReflect.Descriptor instead.

func (*Empty) ProtoMessage

func (*Empty) ProtoMessage()

func (*Empty) ProtoReflect

func (x *Empty) ProtoReflect() protoreflect.Message

func (*Empty) Reset

func (x *Empty) Reset()

func (*Empty) String

func (x *Empty) String() string

type GRPCClient

type GRPCClient struct {
	// contains filtered or unexported fields
}

GRPCClient invokes an authorizer over gRPC.

func (*GRPCClient) PluginAction

func (m *GRPCClient) PluginAction(params map[string]string, headers map[string]*StringList, config *config.Config, task *tes.Task, actionType Type) (*JobResponse, error)

type GRPCServer

type GRPCServer struct {
	Impl Authorize
}

func (*GRPCServer) PluginAction

func (m *GRPCServer) PluginAction(ctx context.Context, req *Job) (*JobResponse, error)

type Job

type Job struct {
	Headers map[string]*StringList `` /* 141-byte string literal not displayed */
	Params  map[string]string      `` /* 139-byte string literal not displayed */
	Config  *config.Config         `protobuf:"bytes,3,opt,name=config,proto3" json:"config,omitempty"`
	Task    *tes.Task              `protobuf:"bytes,4,opt,name=task,proto3" json:"task,omitempty"`
	Type    Type                   `protobuf:"varint,5,opt,name=type,proto3,enum=proto.Type" json:"type,omitempty"`
	// contains filtered or unexported fields
}

func (*Job) Descriptor deprecated

func (*Job) Descriptor() ([]byte, []int)

Deprecated: Use Job.ProtoReflect.Descriptor instead.

func (*Job) GetConfig

func (x *Job) GetConfig() *config.Config

func (*Job) GetHeaders

func (x *Job) GetHeaders() map[string]*StringList

func (*Job) GetParams

func (x *Job) GetParams() map[string]string

func (*Job) GetTask

func (x *Job) GetTask() *tes.Task

func (*Job) GetType

func (x *Job) GetType() Type

func (*Job) GobDecode

func (m *Job) GobDecode(data []byte) error

func (*Job) GobEncode

func (m *Job) GobEncode() ([]byte, error)

func (*Job) ProtoMessage

func (*Job) ProtoMessage()

func (*Job) ProtoReflect

func (x *Job) ProtoReflect() protoreflect.Message

func (*Job) Reset

func (x *Job) Reset()

func (*Job) String

func (x *Job) String() string

type JobResponse

type JobResponse struct {
	Code    int64          `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Message string         `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	Config  *config.Config `protobuf:"bytes,3,opt,name=config,proto3" json:"config,omitempty"`
	Task    *tes.Task      `protobuf:"bytes,4,opt,name=task,proto3" json:"task,omitempty"`
	UserId  string         `protobuf:"bytes,7,opt,name=userId,proto3" json:"userId,omitempty"`
	// contains filtered or unexported fields
}

func (*JobResponse) Descriptor deprecated

func (*JobResponse) Descriptor() ([]byte, []int)

Deprecated: Use JobResponse.ProtoReflect.Descriptor instead.

func (*JobResponse) GetCode

func (x *JobResponse) GetCode() int64

func (*JobResponse) GetConfig

func (x *JobResponse) GetConfig() *config.Config

func (*JobResponse) GetMessage

func (x *JobResponse) GetMessage() string

func (*JobResponse) GetTask

func (x *JobResponse) GetTask() *tes.Task

func (*JobResponse) GetUserId

func (x *JobResponse) GetUserId() string

func (*JobResponse) GobDecode

func (m *JobResponse) GobDecode(data []byte) error

func (*JobResponse) GobEncode

func (m *JobResponse) GobEncode() ([]byte, error)

func (*JobResponse) ProtoMessage

func (*JobResponse) ProtoMessage()

func (*JobResponse) ProtoReflect

func (x *JobResponse) ProtoReflect() protoreflect.Message

func (*JobResponse) Reset

func (x *JobResponse) Reset()

func (*JobResponse) String

func (x *JobResponse) String() string

type RPCClient

type RPCClient struct {
	// contains filtered or unexported fields
}

RPCClient is an implementation of Authorize that talks over RPC.

func (*RPCClient) PluginAction

func (m *RPCClient) PluginAction(params map[string]string, headers map[string]*StringList, config *funnelConfig.Config, task *tes.Task, actionType Type) (*JobResponse, error)

type RPCServer

type RPCServer struct {
	Impl Authorize
}

func (*RPCServer) PluginAction

func (m *RPCServer) PluginAction(args *Job, resp *JobResponse) error

type StringList

type StringList struct {
	Values []string `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"`
	// contains filtered or unexported fields
}

func (*StringList) Descriptor deprecated

func (*StringList) Descriptor() ([]byte, []int)

Deprecated: Use StringList.ProtoReflect.Descriptor instead.

func (*StringList) GetValues

func (x *StringList) GetValues() []string

func (*StringList) ProtoMessage

func (*StringList) ProtoMessage()

func (*StringList) ProtoReflect

func (x *StringList) ProtoReflect() protoreflect.Message

func (*StringList) Reset

func (x *StringList) Reset()

func (*StringList) String

func (x *StringList) String() string

type Type

type Type int32
const (
	Type_CREATE Type = 0
	Type_GET    Type = 1
	Type_CANCEL Type = 2
)

func (Type) Descriptor

func (Type) Descriptor() protoreflect.EnumDescriptor

func (Type) Enum

func (x Type) Enum() *Type

func (Type) EnumDescriptor deprecated

func (Type) EnumDescriptor() ([]byte, []int)

Deprecated: Use Type.Descriptor instead.

func (Type) Number

func (x Type) Number() protoreflect.EnumNumber

func (Type) String

func (x Type) String() string

func (Type) Type

func (Type) Type() protoreflect.EnumType

type UnimplementedAuthorizeServer

type UnimplementedAuthorizeServer struct {
}

UnimplementedAuthorizeServer should be embedded to have forward compatible implementations.

func (UnimplementedAuthorizeServer) PluginAction

type UnsafeAuthorizeServer

type UnsafeAuthorizeServer interface {
	// contains filtered or unexported methods
}

UnsafeAuthorizeServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to AuthorizeServer will result in compilation errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL