databases

package
v0.0.0-...-08568b3 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(states DatabaseSaveStates) error

loads a previously saved map of save states for all databases, restoring their previous states

func RegisterDatabase

func RegisterDatabase(dbName string, createDb func() (Database, error)) error

registers a database creation function under the given database name to allow for e.g. test database implementations

func SecureHttpClient

func SecureHttpClient() http.Client

Here's a secure HTTP client that can be used to connect to databases. It sets a reasonable timeout and enables HTTP Strict Transport Security (HSTS).

Types

type AlreadyRegisteredError

type AlreadyRegisteredError struct {
	Database string
}

indicates that a database is already registered and an attempt has been made to register it again

func (AlreadyRegisteredError) Error

func (e AlreadyRegisteredError) Error() string

type Database

type Database interface {
	// returns a mapping of database-specific search parameters to zeroed values
	// of specific types accessible via type switches
	// * supported types: int, string, bool, float64, slices
	// * slices represent sets of accepted values of their respective types
	//   (useful for pulldown menus)
	// * databases with no specific search parameters should return nil
	SpecificSearchParameters() map[string]interface{}
	// search for files visible to the user with the given ORCID using the given
	// parameters
	Search(orcid string, params SearchParameters) (SearchResults, error)
	// returns a slice of Frictionless DataResources for the files visible to the
	// user with the given ORCID that match the given IDs
	Resources(orcid string, fileIds []string) ([]frictionless.DataResource, error)
	// begins staging the files visible to the user with the given ORCID for
	// transfer, returning a UUID representing the staging operation
	StageFiles(orcid string, fileIds []string) (uuid.UUID, error)
	// returns the status of a given staging operation
	StagingStatus(id uuid.UUID) (StagingStatus, error)
	// returns the local username associated with the given ORCID
	LocalUser(orcid string) (string, error)
	// returns the saved state of the Database, loadable via Load
	Save() (DatabaseSaveState, error)
	// loads a previously saved state into the Database
	Load(state DatabaseSaveState) error
}

Database defines the interface for a database that is used to search for files and initiate file transfers

func NewDatabase

func NewDatabase(dbName string) (Database, error)

creates a database proxy associated with the given ORCID, based on the configured type, or returns an existing instance

type DatabaseSaveState

type DatabaseSaveState struct {
	// database name
	Name string
	// serialized database in bytes
	Data []byte
}

represents a saved database state (for service restarts)

type DatabaseSaveStates

type DatabaseSaveStates struct {
	// mapping of orcid/database keys to database save states
	Data map[string]DatabaseSaveState
}

represents a collection of saved database states

func Save

func Save() (DatabaseSaveStates, error)

saves the internal states of all resident databases, returning a map to their save states

type DowngradedRedirectError

type DowngradedRedirectError struct {
	Endpoint string
}

this error type is emitted if an endpoint redirects an HTTPS request to an HTTP endpoint (it's NUTS that this can happen!)

func (DowngradedRedirectError) Error

func (e DowngradedRedirectError) Error() string

type InvalidEndpointsError

type InvalidEndpointsError struct {
	Database, Message string
}

this error type is returned when a database's endpoint configuration is invalid

func (InvalidEndpointsError) Error

func (e InvalidEndpointsError) Error() string

type InvalidResourceEndpointError

type InvalidResourceEndpointError struct {
	Database, ResourceId, Endpoint string
}

this error type is returned when an endpoint associated with a resource is invalid

func (InvalidResourceEndpointError) Error

type InvalidSearchParameter

type InvalidSearchParameter struct {
	Database, Message string
}

This error type is returned when an invalid database-specific search parameter is specified

func (InvalidSearchParameter) Error

func (e InvalidSearchParameter) Error() string

type MissingOrcidError

type MissingOrcidError struct {
	Database string
}

this error type is returned when an operation requires a user ORCID but none is provided

func (MissingOrcidError) Error

func (e MissingOrcidError) Error() string

type NotFoundError

type NotFoundError struct {
	Database string
}

This error type is returned when a database is sought but not found.

func (NotFoundError) Error

func (e NotFoundError) Error() string

type PermissionDeniedError

type PermissionDeniedError struct {
	Database, ResourceId string
}

this error type is returned when a resource is requested for which the requester does not have permission

func (PermissionDeniedError) Error

func (e PermissionDeniedError) Error() string

type ResourceEndpointNotFoundError

type ResourceEndpointNotFoundError struct {
	Database, ResourceId string
}

this error type is returned when an endpoint cannot be found for a file ID

func (ResourceEndpointNotFoundError) Error

type ResourceNotFoundError

type ResourceNotFoundError struct {
	Database, ResourceId string
}

this error type is returned when a resource is requested and is not found

func (ResourceNotFoundError) Error

func (e ResourceNotFoundError) Error() string

type SearchFileStatus

type SearchFileStatus int

allows searching for files that are staged, not yet staged, etc

const (
	SearchFileStatusAny SearchFileStatus = iota
	SearchFileStatusStaged
	SearchFileStatusUnstaged
)

type SearchPaginationParameters

type SearchPaginationParameters struct {
	// number of search results to skip
	Offset int
	// maximum number of search results to include (0 indicates no max)
	MaxNum int
}

type SearchParameters

type SearchParameters struct {
	// ElasticSearch query string
	Query string
	// file status, if requested
	Status SearchFileStatus
	// pagination support
	Pagination SearchPaginationParameters
	// database-specific search parameters with names matched to provided values
	// (validated by database)
	Specific map[string]json.RawMessage
}

parameters that define a search for files

type SearchResults

type SearchResults struct {
	Resources []frictionless.DataResource `json:"resources"`
}

results from a file search

type StagingStatus

type StagingStatus int

This enum identifies the status of a staging operation that moves files into place on a Database's endpoint.

const (
	StagingStatusUnknown   StagingStatus = iota // unknown staging operation or status not available
	StagingStatusActive                         // staging in progress
	StagingStatusSucceeded                      // staging completed successfully
	StagingStatusFailed                         // staging failed
)

type UnauthorizedError

type UnauthorizedError struct {
	Database, Message, User string
}

indicates that a user could not be authorized to access a database with their ORCID

func (UnauthorizedError) Error

func (e UnauthorizedError) Error() string

type UnavailableError

type UnavailableError struct {
	Database string
}

indicates that a database exists but is currently unavailable

func (UnavailableError) Error

func (e UnavailableError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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