server

package
v0.0.0-...-8c72eba Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// actions
	ActionReadObject   = "read_object"
	ActionCommitObject = "commit_object"
	ActionDeleteObject = "delete_object"
)

Variables

View Source
var (
	ErrDigestAlgorithm = errors.New("invalid digest algorithm")
)

Functions

func AuthResource

func AuthResource(root, obj string) string

func AuthUserMiddleware

func AuthUserMiddleware(authFn AuthUserFunc) func(http.Handler) http.Handler

func CtxWithAuthUser

func CtxWithAuthUser(ctx context.Context, user AuthUser) context.Context

func CtxWithLogger

func CtxWithLogger(ctx context.Context, logger *slog.Logger) context.Context

func LoggerFromCtx

func LoggerFromCtx(ctx context.Context) *slog.Logger

func LoggerMiddleware

func LoggerMiddleware(logger *slog.Logger) func(http.Handler) http.Handler

LoggerMiddlware returns middleware that adds the logger to request context. The logger can be accessed LoggerFromCtx().

func New

func New(opts ...Option) *chi.Mux

New returns a server mux with registered handlers for access and commit services.

func UserFromProto

func UserFromProto(proto *chaprv1.User) *ocfl.User

Types

type AccessService

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

func (AccessService) AccessServiceHandler

func (c AccessService) AccessServiceHandler() (string, http.Handler)

func (AccessService) Close

func (c AccessService) Close() error

close any resource created with New().

func (AccessService) CommitServiceHandler

func (c AccessService) CommitServiceHandler() (string, http.Handler)

func (*AccessService) DownloadHandler

func (srv *AccessService) DownloadHandler(w http.ResponseWriter, r *http.Request)

func (*AccessService) GetObjectManifest

func (s *AccessService) GetObjectManifest(ctx context.Context, req *connect.Request[chaparralv1.GetObjectManifestRequest]) (*connect.Response[chaparralv1.GetObjectManifestResponse], error)

func (*AccessService) GetObjectVersion

func (s *AccessService) GetObjectVersion(ctx context.Context, req *connect.Request[chaparralv1.GetObjectVersionRequest]) (*connect.Response[chaparralv1.GetObjectVersionResponse], error)

func (*AccessService) Handler

func (s *AccessService) Handler() (string, http.Handler)

type AuthToken

type AuthToken struct {
	jwt.Claims
	User AuthUser `json:"chaparral"`
}

AuthToken is the JWT bearer token used to authenticate users.

type AuthUser

type AuthUser struct {
	ID    string   `json:"id"`
	Name  string   `json:"name"`
	Email string   `json:"email"`
	Roles []string `json:"roles"`
}

func AuthUserFromCtx

func AuthUserFromCtx(ctx context.Context) AuthUser

func (AuthUser) Empty

func (u AuthUser) Empty() bool

type AuthUserFunc

type AuthUserFunc func(*http.Request) (AuthUser, error)

AuthUserFunc returns the AuthUser for the request. The AuthUser may be empty.

func JWSAuthFunc

func JWSAuthFunc(pubkey any) (AuthUserFunc, error)

JWSAuthFunc returns an Authentication func that looks for a jwt bearer token signed with the public key.

type Authorizer

type Authorizer interface {
	// Allowed returns true if the user is allowed to perform action
	// on the resource with the given root_id.
	Allowed(ctx context.Context, action string, resources string) bool
}

Authorizer is an interface used by types that can perform authorziation for requests.

type CommitService

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

CommitService implements chaparral.v1.CommitService

func (CommitService) AccessServiceHandler

func (c CommitService) AccessServiceHandler() (string, http.Handler)

func (*CommitService) AuthorizeInterceptor

func (s *CommitService) AuthorizeInterceptor() connect.UnaryInterceptorFunc

AuthIntercept is middleware that does authorization for all grpc/connect-go requests to the commit service. Note that auth for the upload handler is done in handler itself.

func (CommitService) Close

func (c CommitService) Close() error

close any resource created with New().

func (*CommitService) Commit

func (s *CommitService) Commit(ctx context.Context, req *connect.Request[chaparralv1.CommitRequest]) (*connect.Response[chaparralv1.CommitResponse], error)

Commit is used to create or update OCFL objects

func (CommitService) CommitServiceHandler

func (c CommitService) CommitServiceHandler() (string, http.Handler)

func (*CommitService) DeleteObject

func (s *CommitService) DeleteObject(ctx context.Context, req *connect.Request[chaparralv1.DeleteObjectRequest]) (*connect.Response[chaparralv1.DeleteObjectResponse], error)

DeleteObject permanently deletes an existing OCFL object.

func (*CommitService) DeleteUploader

func (s *CommitService) DeleteUploader(ctx context.Context, req *connect.Request[chaparralv1.DeleteUploaderRequest]) (*connect.Response[chaparralv1.DeleteUploaderResponse], error)

DeleteUploader deletes the uploader created with NewUploader and all files uploaded to it. Delete will fail if the uploader is being used, either because files are being uploaded to it or because it is being used for a commit.

func (*CommitService) GetUploader

func (s *CommitService) GetUploader(ctx context.Context, req *connect.Request[chaparralv1.GetUploaderRequest]) (*connect.Response[chaparralv1.GetUploaderResponse], error)

func (*CommitService) HandleUpload

func (s *CommitService) HandleUpload(w http.ResponseWriter, r *http.Request)

Handler for file uploads.

func (*CommitService) Handler

func (s *CommitService) Handler() (string, http.Handler)

func (*CommitService) ListUploaders

func (s *CommitService) ListUploaders(ctx context.Context, req *connect.Request[chaparralv1.ListUploadersRequest]) (*connect.Response[chaparralv1.ListUploadersResponse], error)

func (*CommitService) NewUploader

func (s *CommitService) NewUploader(ctx context.Context, req *connect.Request[chaparralv1.NewUploaderRequest]) (*connect.Response[chaparralv1.NewUploaderResponse], error)

type Option

type Option func(*config)

Option is used to configure the server mux created with New

func WithAuthUserFunc

func WithAuthUserFunc(fn AuthUserFunc) Option

WithAuthUserFun sets the function used to resolve users from requests

func WithAuthorizer

func WithAuthorizer(auth Authorizer) Option

WithAuthorizer sets the Authorizer used to determine if user are authorize user actions on resources.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger that is added to all requests contexts and used by service hanlders.

func WithMiddleware

func WithMiddleware(mids ...func(http.Handler) http.Handler) Option

func WithStorageRoots

func WithStorageRoots(roots ...*store.StorageRoot) Option

func WithUploaderManager

func WithUploaderManager(mgr *uploader.Manager) Option

type Permissions

type Permissions map[string][]string

Permissions maps actions to resources for which the action is allowed.

type RolePermissions

type RolePermissions struct {
	// Default permissions that apply to all users and un-authenticated requests
	Default Permissions            `json:"default"`
	Roles   map[string]Permissions `json:"roles"`
}

RolePermissions is a map of role names to Permissions. It implements the Authorizer interface.

func (RolePermissions) Allowed

func (r RolePermissions) Allowed(ctx context.Context, action string, resource string) bool

Allowed returns true if the user associated with the context has a role with a permission allowing the action on the resource. If resource is '*', Allowed returns true if the if the action is allowed for any resource.

func (RolePermissions) Empty

func (r RolePermissions) Empty() bool

type User

type User ocfl.User

User is used to convert to/from a protobuf User

func (User) AsProto

func (user User) AsProto() *chaprv1.User

func (*User) FromProto

func (user *User) FromProto(proto *chaprv1.User)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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