libgin

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: BSD-3-Clause Imports: 17 Imported by: 2

Documentation

Overview

Package libgin provides functionality shared between the G-Node GIN services. These include: - GIN Web: The G-Node/GOGS fork (https://github.com/G-Node/gogs) - GIN DOI: The DOI registration service (https://github.com/G-Node/gin-doi) - GIN DEX: The indexing service for GIN (https://github.com/G-Node/gin-dex)

Index

Constants

View Source
const (
	Schema         = "http://www.w3.org/2001/XMLSchema-instance"
	SchemaLocation = "http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.3/metadata.xsd"
	Publisher      = "G-Node"
	Language       = "eng"
	Version        = "1.0"
)
View Source
const (
	SEARCH_MATCH = iota
	SEARCH_FUZZY
	SEARCH_WILDCARD
	SEARCH_QUERY
	SEARCH_SUGGEST
)

Variables

View Source
var UUIDMap = map[string]string{
	"INT/multielectrode_grasp":                   "f83565d148510fede8a277f660e1a419",
	"ajkumaraswamy/HB-PAC_disinhibitory_network": "1090f803258557299d287c4d44a541b2",
	"steffi/Kleineidam_et_al_2017":               "f53069de4c4921a3cfa8f17d55ef98bb",
	"Churan/Morris_et_al_Frontiers_2016":         "97bc1456d3f4bca2d945357b3ec92029",
	"fabee/efish_locking":                        "6953bbf0087ba444b2d549b759de4a06",
}

UUIDMap is a map between registered repositories and their UUIDs for datasets registered before the new UUID generation method was implemented. This map is required because the current method of computing UUIDs differs from the older method and this lookup is used to handle the old-method UUIDs. This map is used in the G-Node gin-doi project.

Functions

func Decrypt

func Decrypt(key, ciphertext []byte) ([]byte, error)

Decrypt an AES encrypted array of bytes.

func DecryptString

func DecryptString(key []byte, encstring string) (string, error)

DecryptString decrypts an AES encrypted base64 string.

func DecryptURLString

func DecryptURLString(key []byte, encstring string) (string, error)

DecryptURLString decrypts an AES encrypted URL encoded base64 string.

func Encrypt

func Encrypt(key, plaintext []byte) ([]byte, error)

Encrypt an array of bytes with AES.

func EncryptString

func EncryptString(key []byte, plaintext string) (string, error)

EncryptString encrypts a string using AES and returns it in base64.

func EncryptURLString

func EncryptURLString(key []byte, plaintext string) (string, error)

EncryptURLString encrypts a string using AES and returns it in URL encoded base64.

func GetArchiveSize added in v0.5.5

func GetArchiveSize(archiveURL string) (uint64, error)

GetArchiveSize returns the size of the archive at the given URL. If the URL is invalid or unreachable, an error is returned.

func IsRegisteredDOI

func IsRegisteredDOI(doi string) bool

IsRegisteredDOI tries to http.Get a DOI via a provided DOI ID and returns a boolean value accoring to success or failure. This Function is used in the G-Node gin-doi and gogs projects.

func PrettyDate added in v0.5.5

func PrettyDate(dt *time.Time) string

PrettyDate is currently not used in any project and should be considered deprecated.

func ReadConf

func ReadConf(key string) string

ReadConf returns the value of a configuration env variable. If the variable is not set, an empty string is returned (ignores any errors).

func ReadConfDefault

func ReadConfDefault(key, defval string) string

ReadConfDefault returns the value of a configuration env variable. If the variable is not set, the default is returned.

func RepoPathToUUID

func RepoPathToUUID(URI string) string

RepoPathToUUID computes a UUID from a repository path. This function is used in the G-Node gogs project.

Types

type Author

type Author struct {
	FirstName   string `yaml:"firstname"`
	LastName    string `yaml:"lastname"`
	Affiliation string `yaml:"affiliation,omitempty"`
	ID          string `yaml:"id,omitempty"`
}

Author holds information about a DOI Author. This struct is used in the G-Node gin-doi project.

func (*Author) GetValidID

func (c *Author) GetValidID() *NamedIdentifier

GetValidID returns a NamedIdentifier struct for an Author, if the Author.ID contains a valid ORCID entry. The Method is currently not used in any project and should be considered deprecated.

func (*Author) RenderAuthor

func (a *Author) RenderAuthor() string

RenderAuthor returns a string of the Author content in the format 'Lastname, Firstname; Affiliation; ID'. Empty entries are omitted. This method is used in the G-Node gogs project.

type BlobSResult

type BlobSResult struct {
	Source    *IndexBlob  `json:"_source"`
	Score     float64     `json:"_score"`
	Highlight interface{} `json:"highlight"`
}

type CommitSResult

type CommitSResult struct {
	Source    *IndexCommit `json:"_source"`
	Score     float64      `json:"_score"`
	Highlight interface{}  `json:"highlight"`
}

type Contributor added in v0.5.5

type Contributor struct {
	Name string `xml:"contributorName"`
	Type string `xml:"contributorType,attr"`
}

type Creator added in v0.5.5

type Creator struct {
	Name        string          `xml:"creatorName"`
	Identifier  *NameIdentifier `xml:"nameIdentifier,omitempty"`
	Affiliation string          `xml:"affiliation,omitempty"`
}

type DOIRegInfo

type DOIRegInfo struct {
	Missing         []string
	DOI             string
	UUID            string
	FileName        string
	FileSize        string
	Title           string
	Authors         []Author
	Description     string
	Keywords        []string
	References      []Reference
	Funding         []string
	License         *License
	ResourceType    string
	DateTime        time.Time
	TemplateVersion string
}

DOIRegInfo holds all the metadata and information necessary for a DOI registration request. Deprecated: Marked for removal This struct is used in the G-Node gogs project.

func (*DOIRegInfo) GetCitation

func (c *DOIRegInfo) GetCitation() string

GetCitation returns a formatted string of a DOIRegInfo content containing Authors, Year, Title and DOI link. This method is currently not used in any project and should be considered deprecated.

func (*DOIRegInfo) GetType

func (c *DOIRegInfo) GetType() string

GetType returns the ResourceType entry of a DOIRegInfo or the string "Dataset" if no ResourceType entry was found. This method is currently used in the G-Node gogs project.

func (*DOIRegInfo) ISODate added in v0.3.2

func (c *DOIRegInfo) ISODate() string

ISODate is currently not used in any project and should be considered deprecated.

func (*DOIRegInfo) Year added in v0.3.2

func (c *DOIRegInfo) Year() string

Year is used in the unused GetCitation DOIRefInfo method and should be considered deprecated.

type DOIRequestData

type DOIRequestData struct {
	Username   string
	Realname   string
	Repository string
	Email      string
}

DOIRequestData is used to transmit data from GIN to DOI when a registration request is triggered. This struct is used in the G-Node gogs and gin-doi projects.

type DataCite added in v0.5.5

type DataCite struct {
	XMLName        xml.Name `xml:"http://datacite.org/schema/kernel-4 resource"`
	Schema         string   `xml:"xmlns:xsi,attr"`
	SchemaLocation string   `xml:"xsi:schemaLocation,attr"`
	// Resource identifier (DOI)
	Identifier Identifier `xml:"identifier"`
	// Creators: Authors
	Creators     []Creator     `xml:"creators>creator"`
	Titles       []string      `xml:"titles>title"`
	Descriptions []Description `xml:"descriptions>description"`
	// RightsList: Licenses
	RightsList []Rights `xml:"rightsList>rights"`
	// Subjects: Keywords
	Subjects *[]string `xml:"subjects>subject,omitempty"`
	// RelatedIdentifiers: References
	RelatedIdentifiers []RelatedIdentifier `xml:"relatedIdentifiers>relatedIdentifier"`
	FundingReferences  *[]FundingReference `xml:"fundingReferences>fundingReference,omitempty"`
	// Contributors: Always German Neuroinformatics Node with type "HostingInstitution"
	Contributors []Contributor `xml:"contributors>contributor"`
	// Publisher: Always G-Node
	Publisher string `xml:"publisher"`
	// Publication Year
	Year int `xml:"publicationYear"`
	// Publication Date marked with type "Issued"
	Dates []Date `xml:"dates>date"`
	// Language: eng
	Language     string       `xml:"language"`
	ResourceType ResourceType `xml:"resourceType"`
	// Size of the archive
	Sizes *[]string `xml:"sizes>size,omitempty"`
	// Version: 1.0
	Version string `xml:"version"`
}

func NewDataCite added in v0.5.5

func NewDataCite() DataCite

Returns a DataCite struct populated with our defaults. The following values are set and generally shouldn't be changed: Schema, Namespace, SchemaLocation, Contributors, Publisher, Language, Version. Dates and Year are also pre-filled with the current date but should be changed when working with an existing publication.

func NewDataCiteFromYAML added in v0.5.5

func NewDataCiteFromYAML(info *RepositoryYAML) *DataCite

func UnmarshalFile added in v0.5.5

func UnmarshalFile(path string) (*DataCite, error)

UnmarshalFile reads an XML file specified by the given path and returns a populated DataCite struct. Before returning, it adds the schema attributes for the top-level tag. See also FixSchemaAttrs.

func (*DataCite) AddAbstract added in v0.5.5

func (dc *DataCite) AddAbstract(abstract string)

AddAbstract is a convenience function for adding a Description with type "Abstract".

func (*DataCite) AddAuthor added in v0.5.5

func (dc *DataCite) AddAuthor(author *Author)

func (*DataCite) AddFunding added in v0.5.5

func (dc *DataCite) AddFunding(fundstr string)

AddFunding is a convenience function for appending a FundingReference in the format of the YAML data (<FUNDER>; <AWARDNUMBER>).

func (*DataCite) AddReference added in v0.5.5

func (dc *DataCite) AddReference(ref *Reference)

AddReference is a convenience function for appending a RelatedIdentifier that describes a referenced work. The RelatedIdentifier includes the identifier, relation type, and identifier type. The RelatedIdentifier is not appended, if either identifier or relation type cannot be identified. A full citation string is also added to the Descriptions list.

func (*DataCite) AddURLs added in v0.5.5

func (dc *DataCite) AddURLs(repo, fork, archive string)

AddURLs is a convenience function for appending three reference URLs: 1. The source repository URL; 2. The DOI fork repository URL; 3. The Archive URL. If the archive URL is valid and reachable, the Size of the archive is added as well.

func (*DataCite) FixSchemaAttrs added in v0.5.5

func (dc *DataCite) FixSchemaAttrs()

FixSchemaAttrs adds the Schema and SchemaLocation attributes that can't be read from existing files when Unmarshaling. See https://github.com/golang/go/issues/9519 for the issue with attributes that have a namespace prefix.

func (*DataCite) Marshal added in v0.5.5

func (dc *DataCite) Marshal() (string, error)

Marshal returns the marshalled version of the metadata structure, indented with tabs and with the appropriate XML header.

func (*DataCite) SetResourceType added in v0.5.5

func (dc *DataCite) SetResourceType(resourceType string)

SetResourceType is a convenience function for setting the ResourceType data and its resourceTypeGeneral to the same value.

type Date added in v0.5.5

type Date struct {
	Value string `xml:",chardata"`
	// Always set to "Issued"
	Type string `xml:"dateType,attr"`
}

type Description added in v0.5.5

type Description struct {
	Content string `xml:",chardata"`
	Type    string `xml:"descriptionType,attr"`
}

type FunderIdentifier added in v0.5.5

type FunderIdentifier struct {
	ID   string `xml:",chardata"`
	Type string `xml:"funderIdentifierType,attr"`
}

type FundingReference added in v0.5.5

type FundingReference struct {
	Funder      string            `xml:"funderName"`
	AwardNumber string            `xml:"awardNumber"`
	Identifier  *FunderIdentifier `xml:"funderIdentifier"`
}

type GINUser added in v0.5.5

type GINUser struct {
	Username string
	Email    string
	RealName string
}

GINUser holds basic information about a user on GIN. This struct is used in the G-Node gin-doi project.

type Identifier added in v0.5.5

type Identifier struct {
	ID   string `xml:",chardata"`
	Type string `xml:"identifierType,attr"`
}

type IndexBlob

type IndexBlob struct {
	*gig.Blob
	GinRepoName  string
	GinRepoId    string
	FirstCommit  string
	Id           int64
	Oid          gig.SHA1
	IndexingTime time.Time
	Content      string
	Path         string
}

type IndexCommit

type IndexCommit struct {
	*gig.Commit
	GinRepoId    string
	Oid          gig.SHA1
	GinRepoName  string
	IndexingTime time.Time
}

type IndexRequest

type IndexRequest struct {
	UserID   int64
	RepoID   int64
	RepoPath string
}

type License

type License struct {
	Name string `yaml:"name"`
	URL  string `yaml:"url"`
}

License holds information about a DOI license. The struct is used in the G-Node gogs and gin-doi projects.

type NameIdentifier added in v0.5.5

type NameIdentifier struct {
	ID        string `xml:",chardata"`
	SchemeURI string `xml:"schemeURI,attr"`
	Scheme    string `xml:"nameIdentifierScheme,attr"`
}

type NamedIdentifier

type NamedIdentifier struct {
	SchemeURI string
	Scheme    string
	ID        string
}

NamedIdentifier is used in the unused GetValidID Author method and should be considered deprecated.

type Reference

type Reference struct {
	ID       string `yaml:"id,omitempty"`
	RefType  string `yaml:"reftype,omitempty"`
	Name     string `yaml:"name,omitempty"`     // deprecated, but still read for older versions
	Citation string `yaml:"citation,omitempty"` // meant to replace Name
}

Reference holds information about a DOI reference. The "Name" field has been deprecated. This struct is used in the G-Node gin-doi project.

func (Reference) GetURL added in v0.3.2

func (ref Reference) GetURL() string

GetURL splits the ID string of a Reference at the ":" char into prefix and value and returns a full URL dependent on the provided prefix. Supported prefixes are "doi", "archiv", "pmid" and "url". If no prefix can be identified, an empty string is returned. This method is used in the G-Node gin-doi project.

type RelatedIdentifier added in v0.5.5

type RelatedIdentifier struct {
	Identifier   string `xml:",chardata"`
	Type         string `xml:"relatedIdentifierType,attr"`
	RelationType string `xml:"relationType,attr"`
}

type RepositoryMetadata added in v0.5.5

type RepositoryMetadata struct {
	// YAMLData is the original data coming from the repository
	YAMLData *RepositoryYAML
	// DataCite is the struct that produces the XML file
	*DataCite

	// The user that sent the request
	RequestingUser *GINUser
	// Should be full repository path (<user>/<reponame>)
	SourceRepository string
	// Should be full repository path of the snapshot fork (doi/<rpeoname>)
	ForkRepository string
	// UUID calculated from unique repository path or randomly assigned
	UUID string
}

RepositoryMetadata can contain all known metadata for a registered (or to-be-registered) repository. This struct is used in the G-Node gin-doi project.

type RepositoryYAML added in v0.5.5

type RepositoryYAML struct {
	Authors         []Author    `yaml:"authors"`
	Title           string      `yaml:"title"`
	Description     string      `yaml:"description"`
	Keywords        []string    `yaml:"keywords"`
	License         *License    `yaml:"license,omitempty"`
	Funding         []string    `yaml:"funding,omitempty"`
	References      []Reference `yaml:"references,omitempty"`
	TemplateVersion string      `yaml:"templateversion,omitempty"`
	ResourceType    string      `yaml:"resourcetype"`
}

RepositoryYAML is used to read the information provided by a GIN user through the datacite.yml file. This data is usually used to populate the DataCite and RepositoryMetadata types. This struct is used in the G-Node gin-doi project.

type ResourceType added in v0.5.5

type ResourceType struct {
	Value   string `xml:",chardata"`
	General string `xml:"resourceTypeGeneral,attr"`
}

type Rights added in v0.5.5

type Rights struct {
	Name string `xml:",chardata"`
	URL  string `xml:"rightsURI,attr"`
}

type SearchRequest

type SearchRequest struct {
	Keywords string
	SType    int
	RepoIDs  []int64
}

type SearchResults

type SearchResults struct {
	Blobs   []BlobSResult
	Commits []CommitSResult
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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