Documentation
¶
Index ¶
- Variables
- func AddCollectionMembers(db *gorm.DB, id string, members []string, addedBy string, groups []string, ...) error
- func AddGroupMember(db *gorm.DB, groupId, userId, addedByUserId string) error
- func CreateApiKey(db *gorm.DB, name, createdBy, scopes string, expiration time.Time) (string, error)
- func CreateCounter(key string, value int) error
- func CreateDowntime(downtime *server_structs.Downtime) error
- func CreateOrUpdateCounter(key string, value int) error
- func DeleteApiKey(db *gorm.DB, id string, ...) error
- func DeleteCollection(db *gorm.DB, id string, owner string, groups []string, isAdmin bool) error
- func DeleteCollectionMetadata(db *gorm.DB, id, user string, groups []string, key string, isAdmin bool) error
- func DeleteDowntime(uuid string) error
- func GetAllDowntimes(source string) ([]server_structs.Downtime, error)
- func GetDowntimeByUUID(uuid string) (*server_structs.Downtime, error)
- func GetIncompleteDowntimes(source string) ([]server_structs.Downtime, error)
- func GetServerLocalMetadata() (server_structs.ServerLocalMetadata, error)
- func GetServerLocalMetadataHistory() ([]server_structs.ServerLocalMetadata, error)
- func GrantCollectionAcl(db *gorm.DB, id, user string, groups []string, groupId string, role AclRole, ...) error
- func InitServerDatabase(serverType server_structs.ServerType) error
- func InsertMockDowntime(d server_structs.Downtime) error
- func ListApiKeys(db *gorm.DB) ([]server_structs.ApiKey, error)
- func RemoveCollectionMembers(db *gorm.DB, id string, members []string, user string, groups []string, ...) error
- func RemoveGroupMember(db *gorm.DB, groupId, userId, removedByUserId string) error
- func RevokeCollectionAcl(db *gorm.DB, id, user string, groups []string, groupId string, role AclRole, ...) error
- func SetupMockDowntimeDB(t *testing.T)
- func ShutdownDB() error
- func SoftDeleteServerLocalMetadata(id string) error
- func TeardownMockDowntimeDB(t *testing.T)
- func UpdateCollection(db *gorm.DB, id, user string, groups []string, name, description *string, ...) error
- func UpdateDowntime(uuid string, updatedDowntime *server_structs.Downtime) error
- func UpsertCollectionMetadata(db *gorm.DB, id, user string, groups []string, key, value string, isAdmin bool) error
- func UpsertServerLocalMetadata(metadata server_structs.ServerRegistration) error
- func VerifyApiKey(db *gorm.DB, apiKey string, ...) (bool, []string, error)
- type AclRole
- type Collection
- func CreateCollection(db *gorm.DB, name, description, owner, namespace string, visibility Visibility) (*Collection, error)
- func CreateCollectionWithMetadata(db *gorm.DB, name, description, owner, namespace string, visibility Visibility, ...) (*Collection, error)
- func GetCollection(db *gorm.DB, id string, user string, groups []string) (*Collection, error)
- func ListCollections(db *gorm.DB, user string, groups []string) ([]Collection, error)
- type CollectionACL
- type CollectionMember
- type CollectionMetadata
- type Counter
- type Group
- type GroupMember
- type User
- type Visibility
Constants ¶
This section is empty.
Variables ¶
var ( ErrForbidden = errors.New("forbidden") // ErrReservedGroupPrefix indicates a requested group name collides with the // reserved prefix used for automatically managed personal groups. ErrReservedGroupPrefix = errors.New("reserved group name prefix 'user-'") )
var DirectorDB *gorm.DB
var ( ScopeToRole map[token_scopes.TokenScope][]AclRole = map[token_scopes.TokenScope][]AclRole{ token_scopes.Collection_Read: {AclRoleRead, AclRoleWrite, AclRoleOwner}, token_scopes.Collection_Modify: {AclRoleWrite, AclRoleOwner}, token_scopes.Collection_Delete: {AclRoleOwner}, } )
var ServerDatabase *gorm.DB
Functions ¶
func AddCollectionMembers ¶
func CreateApiKey ¶
func CreateApiKey(db *gorm.DB, name, createdBy, scopes string, expiration time.Time) (string, error)
CreateApiKey creates a new API key with the given name, creator, scopes, and expiration time. It returns the API key in the format "$ID.$SECRET_IN_HEX" and an error if an error occurred. The scopes can are a comma-separated list of capabilities. i.e "monitoring.query,monitoring.scrape" The scopes are defined in the token_scopes package
func CreateCounter ¶
func CreateDowntime ¶
func CreateDowntime(downtime *server_structs.Downtime) error
CRUD operations for downtimes table Create a new downtime entry
func CreateOrUpdateCounter ¶
func DeleteApiKey ¶
func DeleteApiKey(db *gorm.DB, id string, verifiedKeysCache *ttlcache.Cache[string, server_structs.ApiKeyCached]) error
DeleteApiKey deletes the API key with the given ID. It returns an error if an error occurred. It also removes the API key from the verifiedKeysCache so that the deleted key is no longer valid.
func DeleteCollection ¶
func DeleteDowntime ¶
Delete a downtime entry by UUID (hard delete)
func GetAllDowntimes ¶
func GetAllDowntimes(source string) ([]server_structs.Downtime, error)
Retrieve all downtime entries
func GetDowntimeByUUID ¶
func GetDowntimeByUUID(uuid string) (*server_structs.Downtime, error)
Retrieve a downtime entry by UUID
func GetIncompleteDowntimes ¶
func GetIncompleteDowntimes(source string) ([]server_structs.Downtime, error)
Retrieve all downtime entries where EndTime is later than the current UTC time.
func GetServerLocalMetadata ¶
func GetServerLocalMetadata() (server_structs.ServerLocalMetadata, error)
Retrieve the server local metadata in use - lookup the entry whose UpdatedAt is the most recent
func GetServerLocalMetadataHistory ¶
func GetServerLocalMetadataHistory() ([]server_structs.ServerLocalMetadata, error)
Retrieve server local metadata history from most recent to oldest
func GrantCollectionAcl ¶
func InitServerDatabase ¶
func InitServerDatabase(serverType server_structs.ServerType) error
Initialize a centralized server database and run universal and server-type-specific migrations
func InsertMockDowntime ¶
func InsertMockDowntime(d server_structs.Downtime) error
func ListApiKeys ¶
func ListApiKeys(db *gorm.DB) ([]server_structs.ApiKey, error)
func RemoveCollectionMembers ¶
func RemoveGroupMember ¶
func RevokeCollectionAcl ¶
func SetupMockDowntimeDB ¶
Test helper functions for Downtime
func ShutdownDB ¶
func ShutdownDB() error
func SoftDeleteServerLocalMetadata ¶
Mark a server local metadata as deleted without actually removing it from the database
func TeardownMockDowntimeDB ¶
func UpdateCollection ¶
func UpdateDowntime ¶
func UpdateDowntime(uuid string, updatedDowntime *server_structs.Downtime) error
Update an existing downtime entry by UUID
func UpsertServerLocalMetadata ¶
func UpsertServerLocalMetadata(metadata server_structs.ServerRegistration) error
Create or update a record to sync local server metadata with the Registry Server id is an unique 7 characters string randomly generated by the server itself during initial registration, consisting of [0-9a-z], e.g. 18f1jk5 Server name is a human-friendly name set by the admin via SiteName field in webUI or Xrootd.Sitename in local config during initial registration, e.g. "UW_OSDF_CACHE" 1) If no such row exists, it inserts a new one. 2) If a row with that server ID exists, it updates the existing entry.
func VerifyApiKey ¶
func VerifyApiKey(db *gorm.DB, apiKey string, verifiedKeysCache *ttlcache.Cache[string, server_structs.ApiKeyCached]) (bool, []string, error)
VerifyApiKey verifies the API key and returns the capabilities associated with the key. It assumes that the API key is in the format "$ID.$SECRET_IN_HEX". It returns true if the API key is valid, false if the API key is invalid, and an error if an error occurred. If the API key is valid, it also returns the capabilities associated with the key.
Types ¶
type Collection ¶
type Collection struct {
ID string `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null;uniqueIndex:idx_owner_name" json:"name"`
Description string `json:"description"`
Owner string `gorm:"not null;uniqueIndex:idx_owner_name" json:"owner"`
Namespace string `gorm:"not null" json:"namespace"`
Visibility Visibility `gorm:"not null;default:private" json:"visibility"`
CreatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP" json:"createdAt"`
UpdatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP" json:"updatedAt"`
Members []CollectionMember `gorm:"foreignKey:CollectionID" json:"members"`
ACLs []CollectionACL `gorm:"foreignKey:CollectionID" json:"acls"`
Metadata []CollectionMetadata `gorm:"foreignKey:CollectionID" json:"metadata"`
}
func CreateCollection ¶
func CreateCollection(db *gorm.DB, name, description, owner, namespace string, visibility Visibility) (*Collection, error)
func CreateCollectionWithMetadata ¶
func CreateCollectionWithMetadata(db *gorm.DB, name, description, owner, namespace string, visibility Visibility, metadata map[string]string) (*Collection, error)
func GetCollection ¶
func ListCollections ¶
type CollectionACL ¶
type CollectionACL struct {
CollectionID string `gorm:"primaryKey" json:"collectionId"`
GroupID string `gorm:"primaryKey" json:"groupId"`
Role AclRole `gorm:"primaryKey;not null" json:"role"`
GrantedBy string `gorm:"not null" json:"createdBy"`
GrantedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP" json:"createdAt"`
ExpiresAt *time.Time `json:"expiresAt"`
}
func GetCollectionAcls ¶
type CollectionMember ¶
type CollectionMetadata ¶
type CollectionMetadata struct {
CollectionID string `gorm:"primaryKey" json:"collectionId"`
Key string `gorm:"primaryKey;not null" json:"key"`
Value string `gorm:"not null" json:"value"`
}
func GetCollectionMetadata ¶
type Group ¶
type Group struct {
ID string `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null;unique" json:"name"`
Description string `json:"description"`
CreatedBy string `gorm:"not null" json:"createdBy"`
CreatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP" json:"createdAt"`
Members []GroupMember `gorm:"foreignKey:GroupID" json:"members"`
}
func CreateGroup ¶
type GroupMember ¶
type GroupMember struct {
GroupID string `gorm:"primaryKey" json:"groupId"`
UserID string `gorm:"primaryKey" json:"userId"`
User User `gorm:"foreignKey:UserID" json:"user"`
AddedBy string `gorm:"not null" json:"createdBy"`
AddedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP" json:"createdAt"`
}
type User ¶
type User struct {
ID string `gorm:"primaryKey" json:"id"`
Username string `gorm:"not null;uniqueIndex:idx_user_issuer" json:"username"`
Sub string `gorm:"not null;uniqueIndex:idx_user_sub_issuer" json:"sub"`
Issuer string `gorm:"not null;uniqueIndex:idx_user_issuer;uniqueIndex:idx_user_sub_issuer" json:"issuer"`
CreatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP" json:"createdAt"`
}
func CreateUser ¶
func GetOrCreateUser ¶
type Visibility ¶
type Visibility string
const ( VisibilityPrivate Visibility = "private" VisibilityPublic Visibility = "public" )