Documentation
¶
Index ¶
- Constants
- Variables
- func AuthResource(root, obj string) string
- func AuthUserMiddleware(authFn AuthUserFunc) func(http.Handler) http.Handler
- func CtxWithAuthUser(ctx context.Context, user AuthUser) context.Context
- func CtxWithLogger(ctx context.Context, logger *slog.Logger) context.Context
- func LoggerFromCtx(ctx context.Context) *slog.Logger
- func LoggerMiddleware(logger *slog.Logger) func(http.Handler) http.Handler
- func New(opts ...Option) *chi.Mux
- func UserFromProto(proto *chaprv1.User) *ocfl.User
- type AccessService
- func (c AccessService) AccessServiceHandler() (string, http.Handler)
- func (c AccessService) Close() error
- func (c AccessService) CommitServiceHandler() (string, http.Handler)
- func (srv *AccessService) DownloadHandler(w http.ResponseWriter, r *http.Request)
- func (s *AccessService) GetObjectManifest(ctx context.Context, ...) (*connect.Response[chaparralv1.GetObjectManifestResponse], error)
- func (s *AccessService) GetObjectVersion(ctx context.Context, req *connect.Request[chaparralv1.GetObjectVersionRequest]) (*connect.Response[chaparralv1.GetObjectVersionResponse], error)
- func (s *AccessService) Handler() (string, http.Handler)
- type AuthToken
- type AuthUser
- type AuthUserFunc
- type Authorizer
- type CommitService
- func (c CommitService) AccessServiceHandler() (string, http.Handler)
- func (s *CommitService) AuthorizeInterceptor() connect.UnaryInterceptorFunc
- func (c CommitService) Close() error
- func (s *CommitService) Commit(ctx context.Context, req *connect.Request[chaparralv1.CommitRequest]) (*connect.Response[chaparralv1.CommitResponse], error)
- func (c CommitService) CommitServiceHandler() (string, http.Handler)
- func (s *CommitService) DeleteObject(ctx context.Context, req *connect.Request[chaparralv1.DeleteObjectRequest]) (*connect.Response[chaparralv1.DeleteObjectResponse], error)
- func (s *CommitService) DeleteUploader(ctx context.Context, req *connect.Request[chaparralv1.DeleteUploaderRequest]) (*connect.Response[chaparralv1.DeleteUploaderResponse], error)
- func (s *CommitService) GetUploader(ctx context.Context, req *connect.Request[chaparralv1.GetUploaderRequest]) (*connect.Response[chaparralv1.GetUploaderResponse], error)
- func (s *CommitService) HandleUpload(w http.ResponseWriter, r *http.Request)
- func (s *CommitService) Handler() (string, http.Handler)
- func (s *CommitService) ListUploaders(ctx context.Context, req *connect.Request[chaparralv1.ListUploadersRequest]) (*connect.Response[chaparralv1.ListUploadersResponse], error)
- func (s *CommitService) NewUploader(ctx context.Context, req *connect.Request[chaparralv1.NewUploaderRequest]) (*connect.Response[chaparralv1.NewUploaderResponse], error)
- type Option
- func WithAuthUserFunc(fn AuthUserFunc) Option
- func WithAuthorizer(auth Authorizer) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMiddleware(mids ...func(http.Handler) http.Handler) Option
- func WithStorageRoots(roots ...*store.StorageRoot) Option
- func WithUploaderManager(mgr *uploader.Manager) Option
- type Permissions
- type RolePermissions
- type User
Constants ¶
const ( // actions ActionReadObject = "read_object" ActionCommitObject = "commit_object" ActionDeleteObject = "delete_object" )
Variables ¶
var (
ErrDigestAlgorithm = errors.New("invalid digest algorithm")
)
Functions ¶
func AuthResource ¶
func AuthUserMiddleware ¶
func AuthUserMiddleware(authFn AuthUserFunc) func(http.Handler) http.Handler
func LoggerMiddleware ¶
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 ¶
Types ¶
type AccessService ¶
type AccessService struct {
// contains filtered or unexported fields
}
func (AccessService) AccessServiceHandler ¶
func (AccessService) Close ¶
func (c AccessService) Close() error
close any resource created with New().
func (AccessService) CommitServiceHandler ¶
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)
type AuthUser ¶
type AuthUser struct { ID string `json:"id"` Name string `json:"name"` Email string `json:"email"` Roles []string `json:"roles"` }
func AuthUserFromCtx ¶
type AuthUserFunc ¶
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 (*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 (*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) 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 ¶
WithLogger sets the logger that is added to all requests contexts and used by service hanlders.
func WithStorageRoots ¶
func WithStorageRoots(roots ...*store.StorageRoot) Option
func WithUploaderManager ¶
type Permissions ¶
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 ¶
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