publiccode

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: EUPL-1.2 Imports: 28 Imported by: 3

README

publiccode.yml parser for Go

Get invited CircleCI

A Go parser and validator for publiccode.yml files.

publiccode.yml is an international standard for describing public software, which should be placed at the root of Free/Libre and Open Source software repositories.

This parser performs syntactic and semantic validation according to the official spec.

Features

  • Support for the Italian extension
  • Check ISO 3166-1 alpha-2 and alpha-3 country codes
  • Validate emails, URLs (http scheme, valid status code), local and remote files, dates as "YYYY-MM-DD", images (colors, mimes)
  • Check pa-types
  • Validate oembed video links and retrieve HTML for easy embedding
  • Validate SPDX licenses. Without WITH keyword.
  • Check tags
  • Strict and non-strict modes (use non-strict when you want to be tolerant, such as in a crawler, but use strict in editors and validators)

Example

parser := publiccode.NewParser()

// all these settings are optional:
parser.LocalBasePath = "/path/to/local/clone"
parser.RemoteBaseURL = "https://raw.githubusercontent.com/gith002/Medusa/master"
parser.DisableNetwork = false

err := parser.ParseRemoteFile(url)
pc := parser.PublicCode

Validation from command line

This repository also contains pcvalidate which can be used for validating a publiccode.yml from the command line.

To get the latest development version use:

go get github.com/italia/publiccode-parser-go/pcvalidate
pcvalidate mypubliccode.yml

To get the latest stable version go to the release page and grab the one for your arch.

Run pcvalidate --help for the available command line flags.

The tool returns 0 in case of successful validation, 1 otherwise.

Easy validation with Docker

You can easily validate your files using Docker on your local machine or in your CI pipeline:

docker run -i italia/publiccode-parser-go /dev/stdin < publiccode.yml

The image is available on Dockerhub. You can also build your own running:

docker build -t italia/publiccode-parser-go .
Examples

The examples assume that your publiccode.yml file is on your local machine, at /home/my-user/publiccodes/publiccode.yml

  • Validate and print the canonicalized file

    docker run -i italia/publiccode-parser-go -export /dev/stdout /dev/stdin < publiccode.yml
    
  • Validate a publiccode file named publiccode.yml (default)

    docker run -v /home/my-user/publiccodes:/files italia/publiccode-parser-go
    
  • Validate a publiccode file named /opt/publiccodes/my-amazing-code.yaml

    docker run -v /opt/publiccodes:/files italia/publiccode-parser-go my-amazing-code.yaml
    
  • Do extra validations of the local publiccode.yml file against the corresponding remote repository

    docker run -v /opt/publiccodes/publiccodes:/files italia/publiccode-parser-go -remote-base-url https://raw.githubusercontent.com/USER/REPO/master/
    
  • Debugging, access the container interactive shell, overriding the entrypoint

    docker run -it --entrypoint /bin/sh italia/publiccode-parser-go
    

Assets

In order to update the assets, run this command:

go-bindata -o assets.go data/

And change the package name into publiccode

Contributing

Contributing is always appreciated. Feel free to open issues, fork or submit a Pull Request. If you want to know more about how to add new fields, check out CONTRIBUTING.md. In order to support other country-specific extensions in addition to Italy some refactoring might be needed.

See also

Maintainers

This software is maintained by the Developers Italia team.

License

© 2018-2020 Team per la Trasformazione Digitale - Presidenza del Consiglio dei Minstri

Licensed under the EUPL. The version control system provides attribution for specific lines of code.

Documentation

Index

Constants

View Source
const Version = "0.2"

Version of the latest PublicCode specs. Source https://github.com/publiccodenet/publiccode.yml

Variables

View Source
var ExtensionITSupportedVersions = []string{"0.2"}

ExtensionITSupportedVersions declares the versions of the 'it' extension supported by this parser. We also support legacy publiccode.yml files which did not contain the it/countryExtensionVersion key.

View Source
var ExtensionITVersion = "0.2"

ExtensionITVersion declares the latest supported version of the 'it' extension

View Source
var SupportedVersions = []string{"0.1", "0.2"}

SupportedVersions lists the publiccode.yml versions this parser supports.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Amministrazione

type Amministrazione struct {
	CodAmm            string
	DesAmm            string
	Comune            string
	NomeResp          string
	CognResp          string
	Cap               string
	Provincia         string
	Regione           string
	SitoIstituzionale string
	Indirizzo         string
	TitoloResp        string
	TipologiaIstat    string
	TipologiaAmm      string
	Acronimo          string
	CFValidato        string
	CF                string
	Mail1             string
	TipoMail1         string
	Mail2             string
	TipoMail2         string
	Mail3             string
	TipoMail3         string
	Mail4             string
	TipoMail4         string
	Mail5             string
	TipoMail5         string
	URLFacebook       string
	URLTwitter        string
	URLGoogleplus     string
	URLYoutube        string
	LivAccessibili    string
}

Amministrazione is an Administration from amministrazoni.txt Retrieved from: http://www.indicepa.gov.it/documentale/n-opendata.php

type Contact

type Contact struct {
	Name        string `yaml:"name"`
	Email       string `yaml:"email,omitempty"`
	Affiliation string `yaml:"affiliation,omitempty"`
	Phone       string `yaml:"phone,omitempty"`
}

Contact is a contact info maintaining the software. Reference: https://github.com/publiccodenet/publiccode.yml/blob/develop/schema.md#contact

type Contractor

type Contractor struct {
	Name          string    `yaml:"name"`
	Email         string    `yaml:"email,omitempty"`
	Website       *url.URL  `yaml:"-"`
	WebsiteString string    `yaml:"website,omitempty"`
	Until         time.Time `yaml:"-"`
	UntilString   string    `yaml:"until,omitempty"`
}

Contractor is an entity or entities, if any, that are currently contracted for maintaining the software. Reference: https://github.com/publiccodenet/publiccode.yml/blob/develop/schema.md#contractor

type Dependency

type Dependency struct {
	Name       string `yaml:"name"`
	VersionMin string `yaml:"versionMin"`
	VersionMax string `yaml:"versionMax"`
	Optional   bool   `yaml:"optional"`
	Version    string `yaml:"version"`
}

Dependency describe system-level dependencies required to install and use this software. Reference: https://github.com/publiccodenet/publiccode.yml/blob/develop/schema.md#section-dependencies

type Desc

type Desc struct {
	LocalisedName          string     `yaml:"localisedName,omitempty"`
	GenericName            string     `yaml:"genericName"`
	ShortDescription       string     `yaml:"shortDescription"`
	LongDescription        string     `yaml:"longDescription,omitempty"`
	Documentation          *url.URL   `yaml:"-"`
	DocumentationString    string     `yaml:"documentation,omitempty"`
	APIDocumentation       *url.URL   `yaml:"-"`
	APIDocumentationString string     `yaml:"apiDocumentation,omitempty"`
	Features               []string   `yaml:"features,omitempty"`
	Screenshots            []string   `yaml:"screenshots,omitempty"`
	Videos                 []*url.URL `yaml:"-"`
	VideosStrings          []string   `yaml:"videos,omitempty"`
	Awards                 []string   `yaml:"awards,omitempty"`
}

Desc is a general description of the software. Reference: https://github.com/publiccodenet/publiccode.yml/blob/develop/schema.md#section-description

type Domain

type Domain struct {
	// Domains.yml data
	Host        string   `yaml:"host"`
	UseTokenFor []string `yaml:"use-token-for"`
	BasicAuth   []string `yaml:"basic-auth"`
}

Domain is a single code hosting service.

type ErrorInvalidKey

type ErrorInvalidKey struct {
	Key string
}

ErrorInvalidKey represents an error caused by an invalid key.

func (ErrorInvalidKey) Error

func (e ErrorInvalidKey) Error() string

type ErrorInvalidValue

type ErrorInvalidValue struct {
	Key    string
	Reason string
}

ErrorInvalidValue represents an error caused by an invalid value.

func (ErrorInvalidValue) Error

func (e ErrorInvalidValue) Error() string

type ErrorParseMulti

type ErrorParseMulti []error

ErrorParseMulti represents an error caused by a multivalue key.

func (ErrorParseMulti) Error

func (es ErrorParseMulti) Error() string

type ExtensionIT

type ExtensionIT struct {
	CountryExtensionVersion string `yaml:"countryExtensionVersion"`

	Conforme struct {
		LineeGuidaDesign        bool `yaml:"lineeGuidaDesign"`
		ModelloInteroperabilita bool `yaml:"modelloInteroperabilita"`
		MisureMinimeSicurezza   bool `yaml:"misureMinimeSicurezza"`
		GDPR                    bool `yaml:"gdpr"`
	} `yaml:"conforme"`

	Riuso struct {
		CodiceIPA string `yaml:"codiceIPA,omitempty"`
	} `yaml:"riuso"`

	Piattaforme struct {
		Spid   bool `yaml:"spid"`
		Pagopa bool `yaml:"pagopa"`
		Cie    bool `yaml:"cie"`
		Anpr   bool `yaml:"anpr"`
	} `yaml:"piattaforme"`
}

ExtensionIT is the country-specific extension for Italy. Reference: https://github.com/publiccodenet/publiccode.yml/blob/develop/schema.it.md

type ParseError added in v1.2.3

type ParseError struct {
	Reason string
}

A generic parse error.

func (ParseError) Error added in v1.2.3

func (e ParseError) Error() string

type Parser

type Parser struct {
	PublicCode PublicCode

	// LocalBasePath is a filesystem path pointing to the directory where the
	// publiccode.yml is located. It's used as a base for relative paths. If
	// left empty, RemoteBaseURL will be used.
	LocalBasePath string

	// RemoteBaseURL is the URL pointing to the raw directory where the publiccode.yml
	// file is located. It's used for validating abolute URLs and as a base for
	// relative paths. If left empty, absolute URLs will not be validated and
	// no remote validation of files with relative paths will be performed. If
	// not left empty, publiccode.yml keys with relative paths will be turned
	// into absolute URLs.
	// (eg: https://raw.githubusercontent.com/gith002/Medusa/master)
	RemoteBaseURL string

	// DisableNetwork disables all network tests (URL existence and Oembed). This
	// results in much faster parsing.
	DisableNetwork bool

	// Strict makes the parser less tolerant by allowing some errors that do not
	// affect the rendering of the software catalog. It is enabled by default.
	Strict bool

	OEmbed map[string]string

	// Domain will have domain specific settings, including basic auth if provided
	// this will avoid strong quota limit imposed by code hosting platform
	Domain Domain
	// contains filtered or unexported fields
}

Parser is a helper class for parsing publiccode.yml files.

func NewParser

func NewParser() *Parser

NewParser initializes a new Parser object and returns it.

func (*Parser) Parse

func (p *Parser) Parse(in []byte) error

Parse loads the yaml bytes and tries to parse it. Return an error if fails.

func (*Parser) ParseFile

func (p *Parser) ParseFile(file string) error

ParseFile loads a publiccode.yml file from a given file path.

func (*Parser) ParseInDomain

func (p *Parser) ParseInDomain(in []byte, host string, utf []string, ba []string) error

ParseInDomain wrapper func to be in domain env

func (*Parser) ParseRemoteFile

func (p *Parser) ParseRemoteFile(url string) error

ParseRemoteFile loads a publiccode.yml file from its raw URL.

func (*Parser) ToYAML

func (p *Parser) ToYAML() ([]byte, error)

ToYAML converts parser.PublicCode into YAML again.

type PublicCode

type PublicCode struct {
	PubliccodeYamlVersion string `yaml:"publiccodeYmlVersion"`

	Name             string   `yaml:"name"`
	ApplicationSuite string   `yaml:"applicationSuite,omitempty"`
	URL              *url.URL `yaml:"-"`
	URLString        string   `yaml:"url"`
	LandingURL       *url.URL `yaml:"-"`
	LandingURLString string   `yaml:"landingURL,omitempty"`

	IsBasedOn         []string  `yaml:"isBasedOn,omitempty"`
	SoftwareVersion   string    `yaml:"softwareVersion,omitempty"`
	ReleaseDate       time.Time `yaml:"-"`
	ReleaseDateString string    `yaml:"releaseDate"`

	InputTypes  []string `yaml:"inputTypes,omitempty"`
	OutputTypes []string `yaml:"outputTypes,omitempty"`

	Platforms []string `yaml:"platforms"`

	Categories []string `yaml:"categories"`

	UsedBy []string `yaml:"usedBy,omitempty"`

	Roadmap       *url.URL `yaml:"-"`
	RoadmapString string   `yaml:"roadmap,omitempty"`

	DevelopmentStatus string `yaml:"developmentStatus"`

	SoftwareType string `yaml:"softwareType"`

	IntendedAudience struct {
		Scope                []string `yaml:"scope,omitempty"`
		Countries            []string `yaml:"countries,omitempty"`
		UnsupportedCountries []string `yaml:"unsupportedCountries,omitempty"`
	} `yaml:"intendedAudience"`

	Description map[string]Desc `yaml:"description"`

	Legal struct {
		License            string `yaml:"license"`
		MainCopyrightOwner string `yaml:"mainCopyrightOwner,omitempty"`
		RepoOwner          string `yaml:"repoOwner,omitempty"`
		AuthorsFile        string `yaml:"authorsFile,omitempty"`
	} `yaml:"legal"`

	Maintenance struct {
		Type        string       `yaml:"type"`
		Contractors []Contractor `yaml:"contractors,omitempty"`
		Contacts    []Contact    `yaml:"contacts,omitempty"`
	} `yaml:"maintenance"`

	Localisation struct {
		LocalisationReady  bool     `yaml:"localisationReady"`
		AvailableLanguages []string `yaml:"availableLanguages"`
	} `yaml:"localisation"`

	DependsOn struct {
		Open        []Dependency `yaml:"open,omitempty"`
		Proprietary []Dependency `yaml:"proprietary,omitempty"`
		Hardware    []Dependency `yaml:"hardware,omitempty"`
	} `yaml:"dependsOn,omitempty"`

	It ExtensionIT `yaml:"it"`
}

PublicCode is a publiccode.yml file definition. Reference: https://github.com/publiccodenet/publiccode.yml

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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