medifor

package
v0.0.0-...-5a762db Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package medifor contains a basic client library for dialing and communicating with MediFor services.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPathTranslator = defaultTranslator{}

DefaultPathTranslator provides no-op Translate and Untranslate methods.

Functions

func CheckDetectionScore

func CheckDetectionScore(detection *pb.Detection) error

CheckDetectionScore returns an error if a response score is not in [0, 1], otherwise nil. A nil detection object results in no error, since that would produce a default 0 score.

func EnsureIDAndOutput

func EnsureIDAndOutput(req Request) error

EnsureIDAndOutput checks that a request object contains a RequestID, and that its output directory ends with that ID. If either of those things is not true, it remedies that fact before sending the request.

func FusedScore

func FusedScore(f *pb.Fusion) (float64, error)

FusedScore pulls the score from a Fusion object.

func IDVersionFromDetection

func IDVersionFromDetection(d *pb.AnnotatedDetection) (id, version string, err error)

IDVersionFromDetection gets the analytic ID and version from an AnnotatedDetection proto.

func MustDetectionReq

func MustDetectionReq(req Request) *pb.Detection

MustDetectionReq calls NewDetectionReq and panics if an error occurs.

func NewDetectionReq

func NewDetectionReq(req Request) (*pb.Detection, error)

NewDetectionReq creates a detection object from a given request proto. It doesn't do anything special with the request (like set its ID). That should be done by the caller.

func NewImageCameraMatchRequest

func NewImageCameraMatchRequest(probePath string, opts ...ManipOpt) *pb.ImageCameraMatchRequest

NewImageCameraMatchRequest creates a new ImageCameraMatchRequest from the given probe and camera ID.

func NewImageCamerasRequest

func NewImageCamerasRequest(probePath string, opts ...ManipOpt) *pb.ImageCamerasRequest

NewImageCamerasRequest creates a new ImageCamerasRequest from the given probe and camera ID.

func NewImageManipulationRequest

func NewImageManipulationRequest(imgPath string, opts ...ManipOpt) *pb.ImageManipulationRequest

NewImageManipulationRequest creates a new ImageManipulationRequest from the given image path. It determines the mime type from the file extension. It creates a unique request ID and appends it to the output directory prefix. If the output prefix is unspecified in the options, it is set to a location based on the OS temp directory.

func NewImageSpliceRequest

func NewImageSpliceRequest(donorPath, probePath string, opts ...ManipOpt) *pb.ImageSpliceRequest

NewImageSpliceRequest creates a new ImageSpliceRequest from the given probe and donor image paths. Works similarly to NewImageManipulationRequest.

func NewVideoManipulationRequest

func NewVideoManipulationRequest(vidPath string, opts ...ManipOpt) *pb.VideoManipulationRequest

NewVideoManipulationRequest creates a new VideoManipulationRequest from the given video path. Works similarly to NewImageManipulationRequest.

func ParseAnalyticID

func ParseAnalyticID(id string) (name, version string)

ParseAnalyticID separates the ID into name and version components if possible.

Types

type Client

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

Client is a client library for speaking to MediFor services (e.g., analytic indicators) over gRPC.

func NewClient

func NewClient(ctx context.Context, hostPort string, opts ...Option) (*Client, error)

NewClient creates a new medifor client and dials the host.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying connection to the host.

func (*Client) Detect

func (c *Client) Detect(ctx context.Context, detection *pb.Detection) (err error)

Detect calls the endpoint corresponding to the request type in the given Detection, and fills in the response and status on reply. The request ID can be omitted. One will be assigned if not present.

func (*Client) DetectImageCameraMatch

func (c *Client) DetectImageCameraMatch(ctx context.Context, req *pb.ImageCameraMatchRequest) (*pb.ImageCameraMatch, error)

DetectImageCameraMatch calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.

func (*Client) DetectImageCameras

func (c *Client) DetectImageCameras(ctx context.Context, req *pb.ImageCamerasRequest) (*pb.ImageCameras, error)

DetectImageCameras calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.

func (*Client) DetectImageManipulation

func (c *Client) DetectImageManipulation(ctx context.Context, req *pb.ImageManipulationRequest) (*pb.ImageManipulation, error)

DetectImageManipulation calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.

func (*Client) DetectImageSplice

func (c *Client) DetectImageSplice(ctx context.Context, req *pb.ImageSpliceRequest) (*pb.ImageSplice, error)

DetectImageSplice calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.

func (*Client) DetectReq

func (c *Client) DetectReq(ctx context.Context, req Request) (*pb.Detection, error)

DetectReq creates a Detection from a given request, and calls Detect on it before returning it. It is valid to have a non-nil detection *and* a non-nil error. The detection, in that case, will contain the relevant endpoint error information in its status field, and the error will contain the call stack leading to it.

func (*Client) DetectVideoCameraMatch

func (c *Client) DetectVideoCameraMatch(ctx context.Context, req *pb.VideoCameraMatchRequest) (*pb.VideoCameraMatch, error)

DetectVideoCameraMatch calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.

func (*Client) DetectVideoManipulation

func (c *Client) DetectVideoManipulation(ctx context.Context, req *pb.VideoManipulationRequest) (*pb.VideoManipulation, error)

DetectVideoManipulation calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.

func (*Client) Health

Health sends a health check request and returns a response proto.

type FusionClient

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

FusionClient is a client library for speaking to MediFor Analytic Fusion Services over gRPC

func NewFusionClient

func NewFusionClient(ctx context.Context, hostPort string, opts ...Option) (*FusionClient, error)

NewFusionClient creates a new medfifor fusion client and dials the host

func (*FusionClient) Close

func (c *FusionClient) Close() error

Close closes the underlying connection to the host.

func (*FusionClient) Fuse

func (c *FusionClient) Fuse(ctx context.Context, fusion *pb.Fusion) (err error)

Fuse calls the endpoint corresponding to the request type in the given Fusion, fills in the response and status on reply. The request ID can be left off, and will be assigned if missing.

func (*FusionClient) FuseDetections

func (c *FusionClient) FuseDetections(ctx context.Context, ds []*pb.AnnotatedDetection) (fusion *pb.Fusion, err error)

FuseDetections calls the endpoint corresponding to the request type in the first of a slice of AnnotatedDetection protos. All protos are assumed to have the same underlying request, and their responses are converted into inputs for fusion.

func (*FusionClient) FuseImageManipulation

func (c *FusionClient) FuseImageManipulation(ctx context.Context, req *pb.FuseImageManipulationRequest) (*pb.ImageManipulation, error)

FuseImageManipulation calls fusion with the given request.

func (*FusionClient) FuseVideoManipulation

func (c *FusionClient) FuseVideoManipulation(ctx context.Context, req *pb.FuseVideoManipulationRequest) (*pb.VideoManipulation, error)

FuseVideoManipulation calls fusion with the given request.

func (*FusionClient) Health

Health sends a health check request and returns a response proto.

type ManipOpt

type ManipOpt func(*manipConfig)

ManipOpt is an option passed to image or video manipulation detection request creation functions for optional values.

func WithDeviceID

func WithDeviceID(id string) ManipOpt

WithDeviceID sets the device ID on a manipulation request. Default is empty. Not all manipulation types will make use of this.

func WithOutputPrefix

func WithOutputPrefix(out string) ManipOpt

WithOutputPrefix sets the output prefix to the given value. If not called, the default is used, based on operating systsem temporary directory.

type MultiClient

type MultiClient struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MultiClient is a client manager that handles multiple clients at once, allowing one-request-at-a-time mode against a set of clients.

func NewMultiClient

func NewMultiClient(ctx context.Context, hostPorts []string, opts ...Option) (client *MultiClient, err error)

NewMultiClient creates a new multiclient, where every client uses the same options.

func (*MultiClient) CallWithClient

func (c *MultiClient) CallWithClient(ctx context.Context, f func(context.Context, *Client) error) error

CallWithClient calls the specific function with the next available client, if any.

func (*MultiClient) Close

func (c *MultiClient) Close() error

Close closes all underlying clients. Waits for all outstanding CallWithClient calls to finish.

func (*MultiClient) Len

func (c *MultiClient) Len() int

Len returns the total number of clients.

type Option

type Option func(o *mfcOpts) error

Option changes aspects of client creation.

func WithDial

func WithDial(opts ...grpc.DialOption) Option

WithDial sets a particular gRPC dial option when creating the client. For example, to use an insecure connection, you can do the following:

client, err := NewClient(ctx, hostPort, WithDial(grpc.WithInsecure()))

Note, the above is the default, so this is merely an example of something you *could* do.

func WithFusionInputTranslator

func WithFusionInputTranslator(t PathTranslator) Option

WithFusionInputTranslator sets the input URI translator for fusion inputs (which are all analytic outputs, not the original source data). Works like WithInputTranslator, but affects only the analytic output portion of a fusion request.

func WithHealthy

func WithHealthy() Option

WithHealthy sets an option that causes client creation to fail if the service does not immediately send a "SERVING" health response. Otherwise creation may succeed where requests fail.

func WithInputTranslator

func WithInputTranslator(t PathTranslator) Option

WithInputTranslator sets the input URI translator to be the given function. When present, this will translate any URI in a request proto by passing it through the provided translation function before sending the request. Operates on URIs in requests. Defaults to DefaultPathTranslator.

func WithMTLS

func WithMTLS(caCertPath, clientCertPath, clientKeyPath string) Option

WithMTLS creates an option for MTLS authentication, using a server CA file, a client cert PEM, and a client private key file.

func WithOutputTranslator

func WithOutputTranslator(t PathTranslator) Option

WithOutputTranslator sets the output directory and response URI translation mechanism to the given function. Similar to WithInputTranslator, but operates on the output directory in requests, and on all URIs in responses.

func WithWaitForBackend

func WithWaitForBackend() Option

WithWaitForBackend blocks the dialer until the backend is ready. Do not use for buffered connections, just for production.

type PathTranslator

type PathTranslator interface {
	Translate(string) (string, error)
	Untranslate(string) (string, error)
}

PathTranslator is used to translate one path to another and back.

type Request

type Request interface {
	proto.Message
	GetOutDir() string
	GetRequestId() string
}

Request captures protos that look like they might be analytic requests because of particular fields.

Jump to

Keyboard shortcuts

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