Documentation
¶
Overview ¶
Package service holds the data vertical's business rules: registered datasets, the storages they live on and the virtual datasets assembled out of them, all reached through ownership and sharing rules rather than through platform roles.
The rule itself lives in api/sharing/service, which every vertical shares. What is here is the part only this vertical can answer: which record an id names, who owns it, and which shares apply to it.
Index ¶
- func NewDataProductSharingService(db *gorm.DB, products *repository.DataProductRepository, ...) *sharingsvc.Service
- func NewSCPDataStorageSharingService(db *gorm.DB, storages *repository.SCPDataStorageRepository, ...) *sharingsvc.Service
- func NewVirtualDataDirectorySharingService(db *gorm.DB, directories *repository.VirtualDataDirectoryRepository, ...) *sharingsvc.Service
- type DataProductService
- func (s *DataProductService) Create(ctx context.Context, req *dto.DataProductRequest) (*dto.DataProductResponse, error)
- func (s *DataProductService) Delete(ctx context.Context, id string) error
- func (s *DataProductService) Get(ctx context.Context, id string) (*dto.DataProductResponse, error)
- func (s *DataProductService) List(ctx context.Context) ([]dto.DataProductResponse, error)
- func (s *DataProductService) ListMine(ctx context.Context) ([]dto.DataProductResponse, error)
- func (s *DataProductService) ListSharedWithMe(ctx context.Context) ([]dto.DataProductResponse, error)
- func (s *DataProductService) Update(ctx context.Context, id string, req *dto.DataProductRequest) (*dto.DataProductResponse, error)
- type DataTransferService
- type Download
- type Endpoint
- type SCPDataStorageService
- func (s *SCPDataStorageService) Create(ctx context.Context, req *dto.SCPDataStorageRequest) (*dto.SCPDataStorageResponse, error)
- func (s *SCPDataStorageService) Delete(ctx context.Context, id string) error
- func (s *SCPDataStorageService) Get(ctx context.Context, id string) (*dto.SCPDataStorageResponse, error)
- func (s *SCPDataStorageService) List(ctx context.Context) ([]dto.SCPDataStorageResponse, error)
- func (s *SCPDataStorageService) ListMine(ctx context.Context) ([]dto.SCPDataStorageResponse, error)
- func (s *SCPDataStorageService) ListSharedWithMe(ctx context.Context) ([]dto.SCPDataStorageResponse, error)
- func (s *SCPDataStorageService) Update(ctx context.Context, id string, req *dto.SCPDataStorageRequest) (*dto.SCPDataStorageResponse, error)
- type SCPTransport
- type Transport
- type VirtualDataDirectoryService
- func (s *VirtualDataDirectoryService) Create(ctx context.Context, req *dto.VirtualDataDirectoryRequest) (*dto.VirtualDataDirectoryResponse, error)
- func (s *VirtualDataDirectoryService) Delete(ctx context.Context, id string) error
- func (s *VirtualDataDirectoryService) Get(ctx context.Context, id string) (*dto.VirtualDataDirectoryResponse, error)
- func (s *VirtualDataDirectoryService) GetContents(ctx context.Context, id string) (*dto.VirtualDataDirectoryResponse, error)
- func (s *VirtualDataDirectoryService) List(ctx context.Context) ([]dto.VirtualDataDirectoryResponse, error)
- func (s *VirtualDataDirectoryService) ListMine(ctx context.Context) ([]dto.VirtualDataDirectoryResponse, error)
- func (s *VirtualDataDirectoryService) ListSharedWithMe(ctx context.Context) ([]dto.VirtualDataDirectoryResponse, error)
- func (s *VirtualDataDirectoryService) Update(ctx context.Context, id string, req *dto.VirtualDataDirectoryRequest) (*dto.VirtualDataDirectoryResponse, error)
- type VirtualDataFileService
- func (s *VirtualDataFileService) Create(ctx context.Context, req *dto.VirtualDataFileRequest) (*dto.VirtualDataFileResponse, error)
- func (s *VirtualDataFileService) Delete(ctx context.Context, id string) error
- func (s *VirtualDataFileService) Get(ctx context.Context, id string) (*dto.VirtualDataFileResponse, error)
- func (s *VirtualDataFileService) ListByDirectory(ctx context.Context, directoryID string) ([]dto.VirtualDataFileResponse, error)
- func (s *VirtualDataFileService) Update(ctx context.Context, id string, req *dto.VirtualDataFileRequest) (*dto.VirtualDataFileResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDataProductSharingService ¶
func NewDataProductSharingService( db *gorm.DB, products *repository.DataProductRepository, sharing *sharingrepo.Repository, groups *iamrepo.GroupRepository, users *iamrepo.UserRepository, members *iamrepo.GroupMemberRepository, ) *sharingsvc.Service
NewDataProductSharingService returns the sharing service for data products.
func NewSCPDataStorageSharingService ¶
func NewSCPDataStorageSharingService( db *gorm.DB, storages *repository.SCPDataStorageRepository, sharing *sharingrepo.Repository, groups *iamrepo.GroupRepository, users *iamrepo.UserRepository, members *iamrepo.GroupMemberRepository, ) *sharingsvc.Service
NewSCPDataStorageSharingService returns the sharing service for SCP data storages.
func NewVirtualDataDirectorySharingService ¶
func NewVirtualDataDirectorySharingService( db *gorm.DB, directories *repository.VirtualDataDirectoryRepository, sharing *sharingrepo.Repository, groups *iamrepo.GroupRepository, users *iamrepo.UserRepository, members *iamrepo.GroupMemberRepository, ) *sharingsvc.Service
NewVirtualDataDirectorySharingService returns the sharing service for virtual data directories.
Types ¶
type DataProductService ¶
type DataProductService struct {
// contains filtered or unexported fields
}
DataProductService manages registered datasets.
A product belongs to whoever registered it, and everyone else reaches it only through a sharing rule — there is no listing an ordinary caller can use to discover products that were never shared with them.
func NewDataProductService ¶
func NewDataProductService( db *gorm.DB, products *repository.DataProductRepository, sharing *sharingrepo.Repository, storages *repository.SCPDataStorageRepository, users *iamrepo.UserRepository, members *iamrepo.GroupMemberRepository, ) *DataProductService
NewDataProductService returns a data product service.
func (*DataProductService) Create ¶
func (s *DataProductService) Create(ctx context.Context, req *dto.DataProductRequest) (*dto.DataProductResponse, error)
Create registers a dataset owned by the calling user.
The storage it names must be one the caller can already reach: registering data into a storage nobody shared with them would be a way to have the platform touch a host they have no standing on.
func (*DataProductService) Delete ¶
func (s *DataProductService) Delete(ctx context.Context, id string) error
Delete removes a product and every share of it, for its owner or an admin.
The shares go first and in the same transaction: their foreign keys are RESTRICT, so leaving them would turn an ordinary delete into a constraint violation.
func (*DataProductService) Get ¶
func (s *DataProductService) Get(ctx context.Context, id string) (*dto.DataProductResponse, error)
Get returns one product, to anyone holding READ on it.
func (*DataProductService) List ¶
func (s *DataProductService) List(ctx context.Context) ([]dto.DataProductResponse, error)
List returns every product across every owner. Needs dataproduct:list — it names who holds what data.
func (*DataProductService) ListMine ¶
func (s *DataProductService) ListMine(ctx context.Context) ([]dto.DataProductResponse, error)
ListMine returns the caller's own products.
func (*DataProductService) ListSharedWithMe ¶
func (s *DataProductService) ListSharedWithMe(ctx context.Context) ([]dto.DataProductResponse, error)
ListSharedWithMe returns the products other users have shared with the caller, directly or through a group, each carrying what it grants them.
func (*DataProductService) Update ¶
func (s *DataProductService) Update(ctx context.Context, id string, req *dto.DataProductRequest) (*dto.DataProductResponse, error)
Update changes a product's own fields. It needs WRITE, which a share can confer.
The owner, the provision status and the creation time are left alone: re-deriving the owner from the caller's token would hand the product to whichever admin — or grantee — happened to issue the request.
type DataTransferService ¶
type DataTransferService struct {
// contains filtered or unexported fields
}
func NewDataTransferService ¶
func NewDataTransferService( db *gorm.DB, products *repository.DataProductRepository, sharing *sharingrepo.Repository, storages *repository.SCPDataStorageRepository, members *iamrepo.GroupMemberRepository, transport Transport, ) *DataTransferService
NewDataTransferService returns a transfer service moving bytes through transport.
type Download ¶
type Download struct {
FileName string
Size int64
io.ReadCloser
}
Download is the handle a caller streams a product's bytes from.
type Endpoint ¶
type Endpoint struct {
Host string
Port int
LoginUser string
Key credmodel.SSHCredential
}
Endpoint is the host and account one transfer runs against.
type SCPDataStorageService ¶
type SCPDataStorageService struct {
// contains filtered or unexported fields
}
SCPDataStorageService manages the storages datasets are staged through.
Registering one is self-service: any authenticated caller may declare a storage on a host of their choosing, under an account of their choosing, presenting one of their own SSH credentials, and it belongs to them. Everyone else reaches it through its sharing rules — which is how they stage under a key they do not hold.
func NewSCPDataStorageService ¶
func NewSCPDataStorageService( db *gorm.DB, storages *repository.SCPDataStorageRepository, sharing *sharingrepo.Repository, keys *credsvc.KeyAccess, products *repository.DataProductRepository, users *iamrepo.UserRepository, members *iamrepo.GroupMemberRepository, ) *SCPDataStorageService
NewSCPDataStorageService returns a storage service.
func (*SCPDataStorageService) Create ¶
func (s *SCPDataStorageService) Create(ctx context.Context, req *dto.SCPDataStorageRequest) (*dto.SCPDataStorageResponse, error)
Create registers a storage owned by the calling user, on the host it names and under an existing SSH credential.
The owner is taken from the token, so there is no way to register a storage on someone else's behalf.
func (*SCPDataStorageService) Delete ¶
func (s *SCPDataStorageService) Delete(ctx context.Context, id string) error
Delete removes a storage nothing is staged on, together with its shares.
Products are checked first: a product's storage id carries no foreign key — it is qualified by a storage *type* — so nothing at the database level would stop this from orphaning them.
func (*SCPDataStorageService) Get ¶
func (s *SCPDataStorageService) Get(ctx context.Context, id string) (*dto.SCPDataStorageResponse, error)
Get returns one storage, to an admin or to anyone a share reaches.
func (*SCPDataStorageService) List ¶
func (s *SCPDataStorageService) List(ctx context.Context) ([]dto.SCPDataStorageResponse, error)
List returns every storage across every owner. Needs storage:list — it names who stages what where.
func (*SCPDataStorageService) ListMine ¶
func (s *SCPDataStorageService) ListMine(ctx context.Context) ([]dto.SCPDataStorageResponse, error)
ListMine returns the caller's own storages.
func (*SCPDataStorageService) ListSharedWithMe ¶
func (s *SCPDataStorageService) ListSharedWithMe(ctx context.Context) ([]dto.SCPDataStorageResponse, error)
ListSharedWithMe returns the storages other users have shared with the caller, directly or through a group, each carrying what it grants them.
func (*SCPDataStorageService) Update ¶
func (s *SCPDataStorageService) Update(ctx context.Context, id string, req *dto.SCPDataStorageRequest) (*dto.SCPDataStorageResponse, error)
Update changes a storage, including which host it stages through and which account and key it stages under. It needs WRITE, which a share can confer.
The owner is deliberately left alone: re-deriving it from the caller's token would hand the storage to whichever admin — or grantee — happened to issue the request.
type SCPTransport ¶
type SCPTransport struct {
// contains filtered or unexported fields
}
func NewSCPTransport ¶
func NewSCPTransport(sshContext *ssh.GlobalSSHContext) *SCPTransport
func (*SCPTransport) MakeDirectory ¶
type Transport ¶
type Transport interface {
Download(ctx context.Context, ep Endpoint, remotePath, localPath string) error
Upload(ctx context.Context, ep Endpoint, localPath, remotePath string) error
MakeDirectory(ctx context.Context, ep Endpoint, remoteDir string) error
}
Transport moves a single file between this server and the host an Endpoint names.
type VirtualDataDirectoryService ¶
type VirtualDataDirectoryService struct {
// contains filtered or unexported fields
}
VirtualDataDirectoryService manages the directory nodes of virtual datasets.
A dataset is a tree of references to already-registered products. Creating a node never moves or copies data: it records that a product appears at a place in a tree, which is why placing one needs only READ on the product itself.
func NewVirtualDataDirectoryService ¶
func NewVirtualDataDirectoryService( db *gorm.DB, directories *repository.VirtualDataDirectoryRepository, files *repository.VirtualDataFileRepository, sharing *sharingrepo.Repository, products *repository.DataProductRepository, users *iamrepo.UserRepository, members *iamrepo.GroupMemberRepository, ) *VirtualDataDirectoryService
NewVirtualDataDirectoryService returns a virtual data directory service.
func (*VirtualDataDirectoryService) Create ¶
func (s *VirtualDataDirectoryService) Create(ctx context.Context, req *dto.VirtualDataDirectoryRequest) (*dto.VirtualDataDirectoryResponse, error)
Create adds a directory node.
With no parent it is a new dataset, owned by the caller. With one it is placed inside an existing dataset, which needs WRITE there, and it inherits that dataset's owner rather than belonging to whoever added it — a grantee building out someone else's dataset does not come to own a piece of it.
func (*VirtualDataDirectoryService) Delete ¶
func (s *VirtualDataDirectoryService) Delete(ctx context.Context, id string) error
Delete removes a directory and everything under it, for an owner in its lineage or an admin.
Control rather than WRITE: the subtree can hold nodes other people were granted access to, and withdrawing that is the owner's decision.
The directory rows below are cascaded away by the database. Their shares are not — nothing in the sharing table points at a directory — so they are collected and deleted here, in the same transaction, before the subtree they describe is gone.
func (*VirtualDataDirectoryService) Get ¶
func (s *VirtualDataDirectoryService) Get(ctx context.Context, id string) (*dto.VirtualDataDirectoryResponse, error)
Get returns one directory without its contents, to anyone holding READ on it.
func (*VirtualDataDirectoryService) GetContents ¶
func (s *VirtualDataDirectoryService) GetContents(ctx context.Context, id string) (*dto.VirtualDataDirectoryResponse, error)
GetContents returns one directory with the files and directories directly under it.
One level only. A dataset can be arbitrarily deep, and returning all of it would make the cost of a request a property of someone else's data rather than of the request; callers walk down a level at a time.
func (*VirtualDataDirectoryService) List ¶
func (s *VirtualDataDirectoryService) List(ctx context.Context) ([]dto.VirtualDataDirectoryResponse, error)
List returns every directory node across every dataset. Needs virtualdirectory:list — it names who holds what data.
func (*VirtualDataDirectoryService) ListMine ¶
func (s *VirtualDataDirectoryService) ListMine(ctx context.Context) ([]dto.VirtualDataDirectoryResponse, error)
ListMine returns the roots of the caller's own datasets.
Roots only: every other node is reached by walking down from one of these, and listing them all would bury the datasets under their own contents.
func (*VirtualDataDirectoryService) ListSharedWithMe ¶
func (s *VirtualDataDirectoryService) ListSharedWithMe(ctx context.Context) ([]dto.VirtualDataDirectoryResponse, error)
ListSharedWithMe returns the directories other users have shared with the caller, directly or through a group, each carrying what it grants them.
The nodes returned are the ones the shares name, which may be interior: a share opens a subtree, and its top is as far up as the grantee can see.
func (*VirtualDataDirectoryService) Update ¶
func (s *VirtualDataDirectoryService) Update(ctx context.Context, id string, req *dto.VirtualDataDirectoryRequest) (*dto.VirtualDataDirectoryResponse, error)
Update renames a directory, re-points the product it stands for, or moves it.
It needs WRITE on the node. Moving it needs WRITE on the destination too, and is refused if the destination sits inside the subtree being moved. The owner and the creation time are left alone: re-deriving the owner from the caller's token would hand the dataset to whichever grantee happened to issue the request.
type VirtualDataFileService ¶
type VirtualDataFileService struct {
// contains filtered or unexported fields
}
VirtualDataFileService manages the leaves of virtual datasets.
A file carries no owner and no shares of its own: it is reached through the directory it sits under, and everything about who may touch it is decided there.
func NewVirtualDataFileService ¶
func NewVirtualDataFileService( db *gorm.DB, directories *repository.VirtualDataDirectoryRepository, files *repository.VirtualDataFileRepository, sharing *sharingrepo.Repository, products *repository.DataProductRepository, members *iamrepo.GroupMemberRepository, ) *VirtualDataFileService
func (*VirtualDataFileService) Create ¶
func (s *VirtualDataFileService) Create(ctx context.Context, req *dto.VirtualDataFileRequest) (*dto.VirtualDataFileResponse, error)
Create places a file product into a directory, which needs WRITE there.
func (*VirtualDataFileService) Delete ¶
func (s *VirtualDataFileService) Delete(ctx context.Context, id string) error
Delete removes a file from its dataset, which needs WRITE on the directory holding it. The product it cited stays registered.
WRITE rather than control, unlike deleting a directory: a leaf carries no shares, so removing one withdraws nobody's access.
func (*VirtualDataFileService) Get ¶
func (s *VirtualDataFileService) Get(ctx context.Context, id string) (*dto.VirtualDataFileResponse, error)
Get returns one file, to anyone holding READ on the directory it sits under.
func (*VirtualDataFileService) ListByDirectory ¶
func (s *VirtualDataFileService) ListByDirectory(ctx context.Context, directoryID string) ([]dto.VirtualDataFileResponse, error)
ListByDirectory returns the files directly under one directory, to anyone holding READ on it.
func (*VirtualDataFileService) Update ¶
func (s *VirtualDataFileService) Update(ctx context.Context, id string, req *dto.VirtualDataFileRequest) (*dto.VirtualDataFileResponse, error)
Update renames a file, re-points the product it stands for, or moves it to another directory.
A move needs WRITE on both ends: taking an entry out of a dataset is a write to the dataset losing it just as much as to the one gaining it.