server_structs

package
v0.0.0-...-b29c24b Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package server_structs shares structs and their methods used across multiple server packages (origin/cache/registry/director).

It should only import lower level packages (config/param/etc). It should NEVER import any server packages (origin/cache/registry/director) or server_utils package.

For functions used across multiple server packages, put them in server_utils package instead

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownOriginStorageType = errors.New("unknown origin storage type")
)

Functions

func GetCacheNS

func GetCacheNS(host string) string

Get the namespace for a cache server, i.e. /caches/<hostname> It returns an empty string is the host is empty

func GetOriginNs

func GetOriginNs(host string) string

Get the namespace for an origin server, i.e. /origins/<hostname> It returns an empty string is the host is empty

func IsCacheNS

func IsCacheNS(ns string) bool

Check if a namespace is for a cache, i.e. /caches/<hostname>

func IsOriginNS

func IsOriginNS(ns string) bool

Check if a namespace is for an origin, i.e. /origins/<hostname>

func IsValidRegStatus

func IsValidRegStatus(s string) bool

func IsValidStrategy

func IsValidStrategy(strategy string) bool

func ServerAdsToServerNameURL

func ServerAdsToServerNameURL(ads []ServerAd) (output string)

Types

type AdTokCfg

type AdTokCfg struct {
	Issuer   string
	Subject  string
	Audience string
}

type AdminMetadata

type AdminMetadata struct {
	UserID                string             `json:"user_id" post:"exclude"` // "sub" claim of user JWT who requested registration
	Description           string             `json:"description"`
	SiteName              string             `json:"site_name"`
	Institution           string             `json:"institution" validate:"required"`                                                                                // the unique identifier of the institution
	SecurityContactUserID string             `json:"security_contact_user_id" description:"User Identifier of the user responsible for the security of the service"` // "sub" claim of user who is responsible for taking security concern
	Status                RegistrationStatus `json:"status" post:"exclude"`
	ApproverID            string             `json:"approver_id" post:"exclude"` // "sub" claim of user JWT who approved registration
	ApprovedAt            time.Time          `json:"approved_at" post:"exclude"`
	CreatedAt             time.Time          `json:"created_at" post:"exclude"`
	UpdatedAt             time.Time          `json:"updated_at" post:"exclude"`
}

The AdminMetadata is used in Namespace as a marshaled JSON string to be stored in registry DB.

The UserID and SecurityContactUserID are meant to correspond to the "sub" claim of the user token that the OAuth client issues if the user is logged in using OAuth, or it should be "admin" from local password-based authentication.

To prevent users from writing to certain fields (readonly), you may use "post" tag with value "exclude". This will exclude the field from user's create/update requests and the field will also be excluded from field discovery endpoint (OPTION method).

We use validator package to validate struct fields from user requests. If a field is required, add `validate:"required"` to that field. This tag will also be used by fields discovery endpoint to tell the UI if a field is required. For other validator tags, visit: https://pkg.go.dev/github.com/go-playground/validator/v10

func (AdminMetadata) Equal

func (a AdminMetadata) Equal(b AdminMetadata) bool
type Advertisement struct {
	sync.RWMutex
	ServerAd
	NamespaceAds []NamespaceAdV2
}

The struct holding a server's advertisement (including ServerAd and NamespaceAd)

func (*Advertisement) GetIOLoad

func (ad *Advertisement) GetIOLoad() float64

func (*Advertisement) SetIOLoad

func (ad *Advertisement) SetIOLoad(load float64)

type ApiKey

type ApiKey struct {
	ID          string `gorm:"primaryKey;column:id;type:text;not null;unique"`
	Name        string `gorm:"column:name;type:text"`
	HashedValue string `gorm:"column:hashed_value;type:text;not null"`
	Scopes      string `gorm:"column:scopes;type:text"`
	ExpiresAt   time.Time
	CreatedAt   time.Time
	CreatedBy   string `gorm:"column:created_by;type:text"`
}

type ApiKeyCached

type ApiKeyCached struct {
	Token        string // "$ID.$SECRET_IN_HEX" string form
	Capabilities []string
	ExpiresAt    time.Time
}

type Capabilities

type Capabilities struct {
	PublicReads bool `json:"PublicRead"`
	Reads       bool `json:"Read"`
	Writes      bool `json:"Write"`
	Listings    bool `json:"Listing"`
	DirectReads bool `json:"FallBackRead"`
}

Note that the json are kept in uppercase for backward compatibility

type CheckNamespaceCompleteReq

type CheckNamespaceCompleteReq struct {
	Prefixes []string `json:"prefixes"`
}

type CheckNamespaceCompleteRes

type CheckNamespaceCompleteRes struct {
	Results map[string]NamespaceCompletenessResult `json:"results"`
}

type CheckNamespaceExistsReq

type CheckNamespaceExistsReq struct {
	Prefix string `json:"prefix"`
	PubKey string `json:"pubkey"`
}

type CheckNamespaceExistsRes

type CheckNamespaceExistsRes struct {
	PrefixExists bool   `json:"prefix_exists"`
	KeyMatch     bool   `json:"key_match"`
	Message      string `json:"message"`
	Error        string `json:"error"`
}

type CheckNamespaceStatusReq

type CheckNamespaceStatusReq struct {
	Prefix string `json:"prefix"`
}

type CheckNamespaceStatusRes

type CheckNamespaceStatusRes struct {
	Approved bool `json:"approved"`
}

type DirectorResponse

type DirectorResponse struct {
	ObjectServers []*url.URL // List of servers provided in Link header
	Location      *url.URL   // URL content of the location header
	XPelAuthHdr   XPelAuth
	XPelNsHdr     XPelNs
	XPelTokGenHdr XPelTokGen
}

type DirectorTestResult

type DirectorTestResult struct {
	Status    string `json:"status"`
	Message   string `json:"message"`
	Timestamp int64  `json:"timestamp"` // Unix time, the number of seconds elapsed since January 1, 1970 UTC.
}

type GetPrefixByPathRes

type GetPrefixByPathRes struct {
	Prefix string `json:"prefix"`
}

type Namespace

type Namespace struct {
	ID            int                    `json:"id" post:"exclude" gorm:"primaryKey"`
	Prefix        string                 `json:"prefix" validate:"required"`
	Pubkey        string                 `json:"pubkey" validate:"required" description:"Pubkey is your Pelican server public key in JWKS form"`
	Identity      string                 `json:"identity" post:"exclude"`
	AdminMetadata AdminMetadata          `json:"admin_metadata" gorm:"serializer:json"`
	CustomFields  map[string]interface{} `json:"custom_fields" gorm:"serializer:json"`
}

func (Namespace) TableName

func (Namespace) TableName() string

type NamespaceAdV1

type NamespaceAdV1 struct {
	RequireToken  bool         `json:"requireToken"`
	Path          string       `json:"path"`
	Issuer        url.URL      `json:"url"`
	MaxScopeDepth uint         `json:"maxScopeDepth"`
	Strategy      StrategyType `json:"strategy"`
	BasePath      string       `json:"basePath"`
	VaultServer   string       `json:"vaultServer"`
	DirlistHost   string       `json:"dirlisthost"`
}

func ConvertNamespaceAdsV2ToV1

func ConvertNamespaceAdsV2ToV1(nsV2 []NamespaceAdV2) []NamespaceAdV1

type NamespaceAdV2

type NamespaceAdV2 struct {
	Caps         Capabilities  // Namespace capabilities should be considered independently of the origin’s capabilities.
	Path         string        `json:"path"`
	Generation   []TokenGen    `json:"token-generation"`
	Issuer       []TokenIssuer `json:"token-issuer"`
	FromTopology bool          `json:"from-topology"`
}

func ConvertNamespaceAdsV1ToV2

func ConvertNamespaceAdsV1ToV2(nsAdsV1 []NamespaceAdV1, oAd *OriginAdvertiseV1) []NamespaceAdV2

type NamespaceCompletenessResult

type NamespaceCompletenessResult struct {
	EditUrl   string `json:"edit_url"`
	Completed bool   `json:"complete"`
	Msg       string `json:"msg"`
}

type NamespaceHolder

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

func (*NamespaceHolder) GetNamespaceAds

func (ns *NamespaceHolder) GetNamespaceAds() []NamespaceAdV2

func (*NamespaceHolder) SetNamespaceAds

func (ns *NamespaceHolder) SetNamespaceAds(ads []NamespaceAdV2)

type OAuthCallbackRequest

type OAuthCallbackRequest struct {
	State string `form:"state"`
	Code  string `form:"code"`
}

type OAuthLoginRequest

type OAuthLoginRequest struct {
	NextUrl string `form:"nextUrl,omitempty"`
}

type OpenIdDiscoveryResponse

type OpenIdDiscoveryResponse struct {
	Issuer               string   `json:"issuer"`
	JwksUri              string   `json:"jwks_uri"`
	TokenEndpoint        string   `json:"token_endpoint,omitempty"`
	UserInfoEndpoint     string   `json:"userinfo_endpoint,omitempty"`
	RevocationEndpoint   string   `json:"revocation_endpoint,omitempty"`
	GrantTypesSupported  []string `json:"grant_types_supported,omitempty"`
	ScopesSupported      []string `json:"scopes_supported,omitempty"`
	TokenAuthMethods     []string `json:"token_endpoint_auth_methods_supported,omitempty"`
	RegistrationEndpoint string   `json:"registration_endpoint,omitempty"`
	DeviceEndpoint       string   `json:"device_authorization_endpoint,omitempty"`
}

type OriginAdvertiseV1

type OriginAdvertiseV1 struct {
	Name        string          `json:"name"`
	URL         string          `json:"url" binding:"required"` // This is the url for origin's XRootD service and file transfer
	WebURL      string          `json:"web_url,omitempty"`      // This is the url for origin's web engine and APIs
	Namespaces  []NamespaceAdV1 `json:"namespaces"`
	Writes      bool            `json:"enablewrite"`
	DirectReads bool            `json:"enable-fallback-read"` // True if the origin will allow direct client reads when no caches are available
}

type OriginAdvertiseV2

type OriginAdvertiseV2 struct {
	// The displayed name of the server.
	// The value is from the Sitename of the server registration in the registry if set, or Xrootd.Sitename if not
	Name string `json:"name"`
	// The namespace prefix to register/look up the server in the registry.
	// The value is /caches/{Xrootd.Sitename} for cache servers and /origins/{Xrootd.Sitename} for the origin servers
	RegistryPrefix      string            `json:"registry-prefix"`
	BrokerURL           string            `json:"broker-url,omitempty"`
	DataURL             string            `json:"data-url" binding:"required"`
	WebURL              string            `json:"web-url,omitempty"`
	Caps                Capabilities      `json:"capabilities"`
	Namespaces          []NamespaceAdV2   `json:"namespaces"`
	Issuer              []TokenIssuer     `json:"token-issuer"`
	StorageType         OriginStorageType `json:"storageType"`
	DisableDirectorTest bool              `json:"directorTest"` // Use negative attribute (disable instead of enable) to be BC with legacy servers where they don't have this field
	Version             string            `json:"version"`
}

func ConvertOriginAdV1ToV2

func ConvertOriginAdV1ToV2(oAd1 OriginAdvertiseV1) OriginAdvertiseV2

Converts a V1 origin advertisement to a V2 origin advertisement

type OriginStorageType

type OriginStorageType string
const (
	OriginStoragePosix  OriginStorageType = "posix"
	OriginStorageS3     OriginStorageType = "s3"
	OriginStorageHTTPS  OriginStorageType = "https"
	OriginStorageGlobus OriginStorageType = "globus"
	OriginStorageXRoot  OriginStorageType = "xroot" // Not meant to be extensible, but facilitates legacy OSDF --> Pelican transition
)

func ParseOriginStorageType

func ParseOriginStorageType(storageType string) (ost OriginStorageType, err error)

Convert a string to an OriginStorageType

type RegistrationStatus

type RegistrationStatus string
const (
	RegPending  RegistrationStatus = "Pending"
	RegApproved RegistrationStatus = "Approved"
	RegDenied   RegistrationStatus = "Denied"
	RegUnknown  RegistrationStatus = "Unknown"
)

func (RegistrationStatus) LowerString

func (rs RegistrationStatus) LowerString() string

func (RegistrationStatus) String

func (rs RegistrationStatus) String() string

type ServerAd

type ServerAd struct {
	Name                string            `json:"name"`
	StorageType         OriginStorageType `json:"storageType"` // Always POSIX for caches
	DisableDirectorTest bool              `json:"directorTest"`
	AuthURL             url.URL           `json:"auth_url"`
	BrokerURL           url.URL           `json:"broker_url"` // The URL of the broker service to use for this host.
	URL                 url.URL           `json:"url"`        // This is server's XRootD URL for file transfer
	WebURL              url.URL           `json:"web_url"`    // This is server's Web interface and API
	Type                string            `json:"type"`
	Latitude            float64           `json:"latitude"`
	Longitude           float64           `json:"longitude"`
	Caps                Capabilities      `json:"capabilities"`
	FromTopology        bool              `json:"from_topology"`
	IOLoad              float64           `json:"io_load"`
	Version             string            `json:"version"`
}

func (*ServerAd) MarshalJSON

func (ad *ServerAd) MarshalJSON() ([]byte, error)

type ServerPrefix

type ServerPrefix string // The base namespace prefix for origin/cache server
const (
	CachePrefix  ServerPrefix = "/caches/"
	OriginPrefix ServerPrefix = "/origins/"
)

func (ServerPrefix) String

func (s ServerPrefix) String() string

type ServerType

type ServerType int // ServerType is a bit mask indicating which Pelican server(s) are running in the current process
const (
	CacheType ServerType = 1 << iota
	OriginType
	DirectorType
	RegistryType
	BrokerType
	LocalCacheType
)

func NewServerType

func NewServerType() ServerType

Create a new, empty ServerType bitmask

func (*ServerType) Clear

func (sType *ServerType) Clear()

Clear all values in a server type

func (ServerType) IsEnabled

func (sType ServerType) IsEnabled(testServer ServerType) bool

IsEnabled checks if a testServer is in the ServerType instance

func (*ServerType) Set

func (sType *ServerType) Set(server ServerType) ServerType

Enable a single server type in the bitmask

func (*ServerType) SetList

func (sType *ServerType) SetList(newServers []ServerType)

Set sets a list of newServers to ServerType instance

func (*ServerType) SetString

func (sType *ServerType) SetString(name string) bool

func (ServerType) String

func (sType ServerType) String() string

Get the string representation of a ServerType instance. This is intended for getting the string form of a single ServerType constant, such as CacheType OriginType, etc. To get a string slice of enabled servers, use EnabledServerString()

type SimpleApiResp

type SimpleApiResp struct {
	Status SimpleRespStatus `json:"status"`
	Msg    string           `json:"msg,omitempty"`
}

A short response object, meant for the result from most of the Pelican APIs. Will generate a JSON of the form: {"status": "error", "msg": "Some Error Message"} or {"status": "success"}

type SimpleRespStatus

type SimpleRespStatus string

The standardized status message for the API response

const (
	// Indicates the API succeeded.
	RespOK SimpleRespStatus = "success"
	// Indicates the API call failed; the SimpleApiResp Msg should be non-empty in this case
	RespFailed SimpleRespStatus = "error"
	// For long-polling APIs, indicates the requested timeout was hit without any response generated.
	// Should not be considered an error or success but rather indication the long-poll should be retried.
	RespPollTimeout SimpleRespStatus = "timeout"
)

type SortType

type SortType string
const (
	// SortType for sorting the server ads
	DistanceType        SortType = "distance"
	DistanceAndLoadType SortType = "distanceAndLoad"
	RandomType          SortType = "random"
	AdaptiveType        SortType = "adaptive"
)

type StrategyType

type StrategyType string
const (
	OAuthStrategy StrategyType = "OAuth2"
	VaultStrategy StrategyType = "Vault"
)

type TokenGen

type TokenGen struct {
	Strategy         StrategyType `json:"strategy"`
	VaultServer      string       `json:"vault-server"`
	MaxScopeDepth    uint         `json:"max-scope-depth"`
	CredentialIssuer url.URL      `json:"issuer"`
}

type TokenIssuer

type TokenIssuer struct {
	BasePaths       []string `json:"base-paths"`
	RestrictedPaths []string `json:"restricted-paths"`
	IssuerUrl       url.URL  `json:"issuer"`
}

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	Error       string `json:"error"`
}

type TopoCredentialGeneration

type TopoCredentialGeneration struct {
	BasePath      string `json:"base_path"`
	Issuer        string `json:"issuer"`
	MaxScopeDepth int    `json:"max_scope_depth"`
	Strategy      string `json:"strategy"`
	VaultIssuer   string `json:"vault_issuer"`
	VaultServer   string `json:"vault_server"`
}

type TopoCurrentDowntimes

type TopoCurrentDowntimes struct {
	Downtimes []TopoServerDowntime `xml:"Downtime"`
}

type TopoDowntimeInfo

type TopoDowntimeInfo struct {
	XMLName          xml.Name             `xml:"Downtimes"`
	CurrentDowntimes TopoCurrentDowntimes `xml:"CurrentDowntimes"`
}

type TopoNamespace

type TopoNamespace struct {
	Caches               []TopoServer             `json:"caches"`
	Origins              []TopoServer             `json:"origins"`
	CredentialGeneration TopoCredentialGeneration `json:"credential_generation"`
	DirlistHost          string                   `json:"dirlisthost"`
	Path                 string                   `json:"path"`
	ReadHTTPS            bool                     `json:"readhttps"`
	Scitokens            []TopoScitokens          `json:"scitokens"`
	UseTokenOnRead       bool                     `json:"usetokenonread"`
	WritebackHost        string                   `json:"writebackhost"`
}

type TopoResourceGroup

type TopoResourceGroup struct {
	GroupName string `xml:"GroupName"`
	GroupID   int    `xml:"GroupID"`
}

type TopoScitokens

type TopoScitokens struct {
	BasePath   []string `json:"base_path"`
	Issuer     string   `json:"issuer"`
	Restricted []string `json:"restricted_path"`
}

type TopoServer

type TopoServer struct {
	AuthEndpoint string `json:"auth_endpoint"`
	Endpoint     string `json:"endpoint"`
	Resource     string `json:"resource"`
}

type TopoServerDowntime

type TopoServerDowntime struct {
	ID            int               `xml:"ID"`
	ResourceGroup TopoResourceGroup `xml:"ResourceGroup"`
	ResourceName  string            `xml:"ResourceName"`
	ResourceFQDN  string            `xml:"ResourceFQDN"`
	StartTime     string            `xml:"StartTime"`
	EndTime       string            `xml:"EndTime"`
	CreatedTime   string            `xml:"CreatedTime"`
	UpdateTime    string            `xml:"UpdateTime"`
	Services      TopoServices      `xml:"Services"`
	Description   string            `xml:"Description"`
}

type TopoService

type TopoService struct {
	ID          int    `xml:"ID"`
	Name        string `xml:"Name"`
	Description string `xml:"Description"`
}

type TopoServices

type TopoServices struct {
	Service []TopoService `xml:"Service"`
}

type TopologyNamespacesJSON

type TopologyNamespacesJSON struct {
	Caches     []TopoServer    `json:"caches"`
	Namespaces []TopoNamespace `json:"namespaces"`
}

type XPelAuth

type XPelAuth struct {
	Issuers []*url.URL
}

func (XPelAuth) GetName

func (x XPelAuth) GetName() string

func (*XPelAuth) ParseRawResponse

func (x *XPelAuth) ParseRawResponse(resp *http.Response) error

type XPelHeader

type XPelHeader interface {
	GetName() string
	ParseRawHeader(*http.Response) error
}

type XPelNs

type XPelNs struct {
	Namespace      string // Federation Prefix path
	RequireToken   bool   // Whether or not a token is required for read operations
	CollectionsUrl *url.URL
}

func (XPelNs) GetName

func (x XPelNs) GetName() string

func (*XPelNs) ParseRawResponse

func (x *XPelNs) ParseRawResponse(resp *http.Response) error

type XPelTokGen

type XPelTokGen struct {
	Issuers       []*url.URL
	MaxScopeDepth uint
	Strategy      StrategyType
	BasePaths     []string
	VaultServer   *url.URL
}

func (XPelTokGen) GetName

func (x XPelTokGen) GetName() string

func (*XPelTokGen) ParseRawResponse

func (x *XPelTokGen) ParseRawResponse(resp *http.Response) error

type XRootDServer

type XRootDServer interface {
	GetServerType() ServerType
	SetNamespaceAds([]NamespaceAdV2)
	GetNamespaceAds() []NamespaceAdV2
	CreateAdvertisement(name string, serverUrl string, serverWebUrl string) (*OriginAdvertiseV2, error)
	GetNamespaceAdsFromDirector() error
	GetAdTokCfg(context.Context) (AdTokCfg, error)
	GetFedTokLocation() string

	// Return the PIDs corresponding to the running process(es) for the XRootD
	// server instance (could be multiple if there's both cmsd and xrootd)
	GetPids() []int

	// Set the PIDs associated with the running process(es) for the XRootD instance
	SetPids([]int)
}

Jump to

Keyboard shortcuts

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