ftx

package module
v0.9.13 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: Unlicense Imports: 60 Imported by: 0

README

ftx

Documentation

Index

Constants

View Source
const (
	// RequestMaxBodySize limits the amount of data read from the request body to prevent memory exhaustion
	RequestMaxBodySize = 2 * 1024 * 1024 // 2 MB
)

Variables

View Source
var (
	OTPRequestedTopic = Topic("auth.otp.requested")
)

Functions

func AdminKeyFromContext

func AdminKeyFromContext(ctx context.Context) (value string, found bool)

func BaseType

func BaseType(elem any) reflect.Type

BaseType returns the base type of the given element

func Collection

func Collection[T any]() string

Collection returns the name of the collection for the given element

func CompositeMiddleware

func CompositeMiddleware(middleware ...mux.MiddlewareFunc) mux.MiddlewareFunc

CompositeMiddleware composes multiple mux.MiddlewareFunc into a single one, applying them in the order provided (first to last).

func ConfigFromEnv

func ConfigFromEnv[T proto.Message](defaultConf T) T

func ContextWithAdminKey

func ContextWithAdminKey(parent context.Context, key string) context.Context

func ContextWithDirectives

func ContextWithDirectives(parent context.Context, directives []string) context.Context

func ContextWithSession

func ContextWithSession(parent context.Context, session *authv1.Session) context.Context

func CreateDashboardAdmin added in v0.9.7

func CreateDashboardAdmin(ctx context.Context, access Access, req *dashboardv1.CreateAccountRequest) (err error)

func DirectivesFromContext

func DirectivesFromContext(ctx context.Context) (directives []string, found bool)

func Dot added in v0.9.11

func Dot(parts ...string) string

Dot joins a slice of strings with a dot

func DoubleQuote

func DoubleQuote(s string) string

DoubleQuote ...

func Enforce

func Enforce[T proto.Message](ctx context.Context, enforcer casbin.IEnforcer, subjectFn SubjectFn[T], enforceFn EnforceFn[T]) (subject T, authorized bool)

Enforce is a helper function to enforce a policy

func Enforcer

func Enforcer(conf, policy string) func() (*casbin.Enforcer, error)

Enforcer is a helper function to provide a casbin enforcer

func Expose added in v0.9.6

func Expose[T proto.Message]() exposed

Expose ...

func GraphqlMiddleware

func GraphqlMiddleware(next http.Handler) http.Handler

GraphqlMiddleware injects the directives into the context

func HandleDownloadFile added in v0.9.7

func HandleDownloadFile[T FileStorage](fs T) runtime.HandlerFunc

func HandleUploadFile added in v0.9.7

func HandleUploadFile[T FileStorage](fs T) runtime.HandlerFunc

func HashFile added in v0.9.7

func HashFile(file []byte) (string, error)

HashFile ...

func HttpHandler added in v0.9.7

func HttpHandler(hf grpc_runtime.HandlerFunc) http.HandlerFunc

HttpHandler converts a runtime.HandlerFunc to a http.HandlerFunc

func ID

func ID[T any](key string) string

NODE HELPERS

func JSONName

func JSONName(f reflect.StructField) string

JSONName returns the name of the field in the JSON tag

func Join added in v0.9.7

func Join(parts ...string) string

Join joins a slice of strings

func Map

func Map[T any](size int, fn func(int) T) (result []T)

Map converts a slice of values to a slice of values using a function

func Match added in v0.9.7

Match applies a single mux.MiddlewareFunc only if the request path matches the given regexp.

func Mutation

func Mutation[Arg, Out proto.Message](fn func(context.Context, Arg) (Out, error)) mutation

Mutation ...

func NewConnection

func NewConnection(ctx context.Context, conf *configv1.Connection) (*connection, error)

NewConnection ...

func NewDbFileStorage

func NewDbFileStorage(access Access) (*dbFileStorage, error)

NewDbFileStorage ...

func NewFilesystemStorage

func NewFilesystemStorage(config *configv1.FilesystemStorage) *filesystemStorage

NewFilesystemStorage ...

func NewGraph

func NewGraph() *graph

NewGraph ...

func NewObserver

func NewObserver[T comparable]() *observer[T]

NewObserver ...

func OTPMailSubscriber

func OTPMailSubscriber(ctx context.Context, config *configv1.Mail, message OTPMailTemplate) (Topic, Processor[Topic])

OTPMailSubscriber is a function that sends an email to the user with the OTP code

func ProtoMarshal

func ProtoMarshal(v any, out proto.Message) error

func Provide

func Provide[T any](val any) fx.Option

Provide provides a value annotated with a specific type

func Pure

func Pure[T any](v T) (result T)

Pure converts a value to a pure JSON value

func Query

func Query[Arg, Out proto.Message](fn func(context.Context, Arg) (Out, error)) query

Query ...

func QueryJoin

func QueryJoin(parts ...string) string

QueryJoin joins a slice of strings with a space

func Quote

func Quote(s string) string

Quote ...

func ReadRequestBody

func ReadRequestBody(r *http.Request) ([]byte, error)

ReadRequestBody reads and returns the full body of the request without consuming it permanently. It restores the body so it can be read again later. Returns an error if reading fails or body exceeds MaxBodySize.

func ResourceID

func ResourceID(resource, key string) string

func RuntimeHandler added in v0.9.7

func RuntimeHandler(hf http.HandlerFunc) grpc_runtime.HandlerFunc

RuntimeHandler converts a http.HandlerFunc to a runtime.HandlerFunc

func Select

func Select[T any](v T) selector[T]

Select returns a new selector with the given value

func SessionFromContext

func SessionFromContext(ctx context.Context) (session *authv1.Session, found bool)

func Should

func Should[T any](v T, _ error) T

Should returns a value and ignores the error

func Subject

func Subject[T proto.Message](ctx context.Context, subject SubjectFn[T]) (val T, err error)

Subject returns a value and an error from a SubjectFn

func ToMap

func ToMap(v any) (result map[string]any)

ToMap converts a value to a map[string]any

func Vars

func Vars() bindVars

Vars ...

func VarsFor

func VarsFor[T proto.Message](elem T) bindVars

Types

type Access

type Access interface {
	// AutoMigrate ...
	AutoMigrate(ctx context.Context, graph Graph) error

	// Collection ...
	Collection(ctx context.Context, elem any, callbacks ...CollectionCallback) (driver.Collection, error)

	// Query returns a list of elements
	Query(ctx context.Context, query string, bindVars map[string]any, out any) error

	// Fetch returns a single element
	Fetch(ctx context.Context, query string, bindVars map[string]any, out any) error

	// List ...
	List(ctx context.Context, bindVars BindVars, out any) (int64, error)

	// Find ...
	Find(ctx context.Context, bindVars BindVars, out any) error

	// Create ...
	Create(ctx context.Context, val any) ([]string, error)

	// Update ...
	Update(ctx context.Context, key string, item any) error

	// Replace ...
	Replace(ctx context.Context, key string, item any) error

	// Delete ...
	Delete(ctx context.Context, item any) error

	// Relations ...
	Relations(ctx context.Context, id string, bindVars BindVars, direction Direction, out any) (int64, error)
}

Access ...

type ArangoAccess

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

func NewArangoAccess

func NewArangoAccess(conn Connection, observer Observer[Topic]) (*ArangoAccess, error)

func (*ArangoAccess) AutoMigrate

func (e *ArangoAccess) AutoMigrate(ctx context.Context, graph Graph) error

AutoMigrate ...

func (*ArangoAccess) Collection

func (e *ArangoAccess) Collection(ctx context.Context, elem any, callbacks ...CollectionCallback) (col driver.Collection, err error)

Collection ...

func (*ArangoAccess) Create

func (e *ArangoAccess) Create(ctx context.Context, val any) ([]string, error)

Create ...

func (*ArangoAccess) Delete

func (e *ArangoAccess) Delete(ctx context.Context, item any) error

Delete ...

func (*ArangoAccess) Fetch

func (e *ArangoAccess) Fetch(ctx context.Context, query string, bindVars map[string]any, out any) error

Fetch ...

func (*ArangoAccess) Find

func (e *ArangoAccess) Find(ctx context.Context, bindVars BindVars, out any) error

Find ...

func (*ArangoAccess) List

func (e *ArangoAccess) List(ctx context.Context, bindVars BindVars, out any) (int64, error)

List ...

func (*ArangoAccess) Query

func (e *ArangoAccess) Query(ctx context.Context, query string, bindVars map[string]any, out any) error

Query ...

func (*ArangoAccess) Relations

func (e *ArangoAccess) Relations(ctx context.Context, id string, bindVars BindVars, direction Direction, out any) (int64, error)

Relations ...

func (*ArangoAccess) Replace

func (e *ArangoAccess) Replace(ctx context.Context, key string, item any) error

Replace ...

func (*ArangoAccess) Update

func (e *ArangoAccess) Update(ctx context.Context, key string, item any) error

Update ...

type AuthHandler

type AuthHandler struct {
	authv1.UnsafeAuthenticationServiceServer
	// contains filtered or unexported fields
}

func NewAuthHandler

func NewAuthHandler(ctx context.Context, config *configv1.Auth, params AuthHandlerParams) (*AuthHandler, error)

func (*AuthHandler) Handler

func (h *AuthHandler) Handler(ctx context.Context) http.Handler

func (*AuthHandler) Middleware

func (h *AuthHandler) Middleware(next http.Handler) http.Handler

func (*AuthHandler) RefreshToken

func (h *AuthHandler) RefreshToken(ctx context.Context, req *emptypb.Empty) (*authv1.RefreshTokenResponse, error)

func (*AuthHandler) RequestOTP

func (*AuthHandler) ValidateSSOToken

func (h *AuthHandler) ValidateSSOToken(ctx context.Context, req *emptypb.Empty) (*authv1.ValidateSSOTokenResponse, error)

func (*AuthHandler) VerifyOTP

type AuthHandlerParams

type AuthHandlerParams struct {
	fx.In

	Access   Access
	Observer Observer[Topic]
}

type BindVars

type BindVars interface {
	// LimitString ...
	LimitString() string

	// FiltersFor ...
	FiltersFor(doc string) string

	// Values ...
	Values() map[string]interface{}
}

BindVars ...

type CasbinAdapter

type CasbinAdapter[T proto.Message] struct {
	// contains filtered or unexported fields
}

CasbinAdapter ...

func Unsafe_NewCasbinAdapter added in v0.9.6

func Unsafe_NewCasbinAdapter[T proto.Message](ctx context.Context, access Access) (*CasbinAdapter[T], error)

Unsafe_NewCasbinAdapter ... TODO: finish this

func (*CasbinAdapter[T]) AddPolicy

func (a *CasbinAdapter[T]) AddPolicy(sec string, ptype string, rule []string) error

AddPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) Fields

func (a *CasbinAdapter[T]) Fields() (result []protoreflect.FieldDescriptor)

func (*CasbinAdapter[T]) LoadPolicy

func (a *CasbinAdapter[T]) LoadPolicy(model model.Model) error

LoadPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) Marshal

func (a *CasbinAdapter[T]) Marshal(el T) (sec string, ptype string, rule []string)

func (*CasbinAdapter[T]) RemoveFilteredPolicy

func (a *CasbinAdapter[T]) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) RemovePolicy

func (a *CasbinAdapter[T]) RemovePolicy(sec string, ptype string, rule []string) error

RemovePolicy implements persist.Adapter.

func (*CasbinAdapter[T]) SavePolicy

func (a *CasbinAdapter[T]) SavePolicy(model model.Model) error

SavePolicy implements persist.Adapter.

func (*CasbinAdapter[T]) Unmarshal

func (a *CasbinAdapter[T]) Unmarshal(sec string, ptype string, rule []string) (out T, err error)

type CollectionCallback

type CollectionCallback func(context.Context, driver.Collection)

CollectionCallback ...

type Connection

type Connection interface {
	// Database ...
	Database(ctx context.Context) (driver.Database, error)
	// Collection ...
	Collection(ctx context.Context, elem any) (driver.Collection, error)
	// Reflect ...
	Reflect(ctx context.Context, elem reflect.Type) (driver.Collection, error)
}

Connection ...

type DashboardHandler added in v0.9.7

DashboardHandler ...

func NewDashboard added in v0.9.7

func NewDashboard(ctx context.Context, config *configv1.Dashboard, params DashboardParams) (*DashboardHandler, error)

NewDashboard ...

func (*DashboardHandler) CreateAccount added in v0.9.7

func (*DashboardHandler) CreateResource added in v0.9.7

func (*DashboardHandler) DeleteResource added in v0.9.7

func (*DashboardHandler) GetAccount added in v0.9.7

func (*DashboardHandler) GetResource added in v0.9.7

func (*DashboardHandler) GetResourceRelation added in v0.9.7

func (*DashboardHandler) GetSchema added in v0.9.7

func (*DashboardHandler) Handler added in v0.9.7

func (h *DashboardHandler) Handler(ctx context.Context) http.Handler

func (*DashboardHandler) ListResources added in v0.9.7

func (*DashboardHandler) Login added in v0.9.7

func (*DashboardHandler) UpdateResource added in v0.9.7

type DashboardParams added in v0.9.7

type DashboardParams struct {
	fx.In

	Access   Access
	Graph    Graph
	Storage  FileStorage
	Observer Observer[Topic]
}

DashboardParams ...

type Direction

type Direction string
const (
	DirectionInbound  Direction = "INBOUND"
	DirectionOutbound Direction = "OUTBOUND"
	DirectionAny      Direction = "ANY"
)

func (Direction) String

func (d Direction) String() string

type EnforceFn

type EnforceFn[T proto.Message] func(ctx context.Context, subject T) (Rules, error)

EnforceFn is a function that returns a slice of any and an error

type Event

type Event[T comparable] struct {
	// Topic ...
	Topic T
	// Payload ...
	Payload protoreflect.ProtoMessage
	// Timestamp ...
	Timestamp time.Time
}

Event ...

type FileStorage

type FileStorage interface {
	// StoreFile ...
	StoreFile(name string, file []byte) (err error)

	// StoreByHash ...
	StoreByHash(file []byte) (hash string, err error)

	// ReadFile ...
	ReadFile(name string) (fileContent []byte, errr error)

	// MaxMemory ...
	MaxMemory() int64
}

FileStorage ...

type Graph

type Graph interface {
	// Node ...
	Node(node any)
	// Edge ...
	Edge(from, to, edge any)

	// Nodes ...
	Nodes() []reflect.Type
	// Edges ...
	Edges() []reflect.Type
	// Relation ...
	Relation(edge reflect.Type) *Relation

	// CollectionFor ...
	CollectionFor(elem reflect.Type) string
	// TypeOf ...
	TypeOf(name string) reflect.Type
}

Graph ...

type GraphqlHandler

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

GraphqlHandler ...

func NewGraphqlHandler

func NewGraphqlHandler(access Access, graph Graph) (*GraphqlHandler, error)

NewGraphqlHandler ...

func (*GraphqlHandler) Handler added in v0.9.7

func (e *GraphqlHandler) Handler(ctx context.Context, handlers ...interface{}) *handler.Handler

Handler ...

type OTPMailTemplate

type OTPMailTemplate func(email, code string) []byte

OTPMailTemplate is a function that returns the message to send to the user

type Observer

type Observer[T comparable] interface {
	// Subscribe ...
	Subscribe(t T, p Processor[T]) SourceID
	// Unsubscribe ...
	Unsubscribe(s SourceID)
	// Emit ...
	Emit(e *Event[T]) error
}

Observer ...

type Processor

type Processor[T comparable] func(e *Event[T]) error

Processor ...

type Relation

type Relation struct {
	From reflect.Type `json:"_from"`
	To   reflect.Type `json:"_to"`
}

Relation

type Rule

type Rule []interface{}

Rule is a slice of any

type Rules

type Rules []Rule

Rules is a slice of Rule

func EnforceDirectives

func EnforceDirectives(ctx context.Context, role fmt.Stringer) Rules

EnforceDirectives returns the rules for the given role for each directive

type Set added in v0.9.13

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is a collection of unique items

func (*Set[T]) Add added in v0.9.13

func (s *Set[T]) Add(item ...T)

func (*Set[T]) Clear added in v0.9.13

func (s *Set[T]) Clear()

func (*Set[T]) Has added in v0.9.13

func (s *Set[T]) Has(item T) bool

func (*Set[T]) Len added in v0.9.13

func (s *Set[T]) Len() int

func (*Set[T]) Remove added in v0.9.13

func (s *Set[T]) Remove(item T)

func (*Set[T]) Values added in v0.9.13

func (s *Set[T]) Values() []T

type SourceID

type SourceID int64

SourceID ...

type SubjectFn

type SubjectFn[T proto.Message] func(ctx context.Context, session *domainv1.Session) (T, error)

SubjectFn is a function that returns a value and an error

type Topic

type Topic string
var (
	CreatedTopic  Topic = "document.created"
	UpdatedTopic  Topic = "document.updated"
	ReplacedTopic Topic = "document.replaced"
	DeletedTopic  Topic = "document.deleted"
)
var (
	DashboardCreatedTopic  Topic = "dashboard.created"
	DashboardReplacedTopic Topic = "dashboard.replaced"
	DashboardDeletedTopic  Topic = "dashboard.deleted"
)

func (Topic) For

func (t Topic) For(elem any) Topic

Jump to

Keyboard shortcuts

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