Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable license and available_licenses info fields #1423

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion openapi/index_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,9 @@
"api_version",
"available_api_versions",
"available_endpoints",
"entry_types_by_format"
"entry_types_by_format",
"license",
"available_licenses"
],
"type": "object",
"properties": {
Expand Down Expand Up @@ -899,6 +901,29 @@
},
"description": "Available entry endpoints as a function of output formats."
},
"license": {
"title": "License",
"anyOf": [
{
"$ref": "#/components/schemas/Link"
},
{
"maxLength": 65536,
"minLength": 1,
"type": "string",
"format": "uri"
}
],
"description": "A [JSON API links object](http://jsonapi.org/format/1.0/#document-links) giving a URL to a web page containing a human-readable text describing the license (or licensing options if there are multiple) covering all the data and metadata provided by this database.\nClients are advised not to try automated parsing of this link or its content, but rather rely on the field `available_licenses` instead."
},
"available_licenses": {
"title": "Available Licenses",
"type": "array",
"items": {
"type": "string"
},
"description": "List of [SPDX license identifiers](https://spdx.org/licenses/) specifying a set of alternative licenses under which the client is granted access to all the data and metadata in this database.\n\nIf the data and metadata is available under multiple alternative licenses, identifiers of these multiple licenses SHOULD be provided to let clients know under which conditions the data and metadata can be used.\nInclusion of a license identifier in the list is a commitment of the database that the rights are in place to grant clients access to all the data and metadata according to the terms of either of these licenses (at the choice of the client).\nIf the licensing information provided via the field `license` omits licensing options specified in `available_licenses`, or if it otherwise contradicts them, a client MUST still be allowed to interpret the inclusion of a license in `available_licenses` as a full commitment from the database that the data and metadata is available, without exceptions, under the respective licenses.\nIf the database cannot make that commitment, e.g., if only part of the data is available under a license, the corresponding license identifier MUST NOT appear in `available_licenses` (but, rather, the field `license` is to be used to clarify the licensing situation.)\nAn empty list indicates that none of the SPDX licenses apply for the entirety of the database and that the licensing situation is clarified in human readable form in the field `license`."
},
"is_index": {
"title": "Is Index",
"type": "boolean",
Expand Down
27 changes: 26 additions & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,9 @@
"api_version",
"available_api_versions",
"available_endpoints",
"entry_types_by_format"
"entry_types_by_format",
"license",
"available_licenses"
],
"type": "object",
"properties": {
Expand Down Expand Up @@ -1465,6 +1467,29 @@
},
"description": "Available entry endpoints as a function of output formats."
},
"license": {
"title": "License",
"anyOf": [
{
"$ref": "#/components/schemas/Link"
},
{
"maxLength": 65536,
"minLength": 1,
"type": "string",
"format": "uri"
}
],
"description": "A [JSON API links object](http://jsonapi.org/format/1.0/#document-links) giving a URL to a web page containing a human-readable text describing the license (or licensing options if there are multiple) covering all the data and metadata provided by this database.\nClients are advised not to try automated parsing of this link or its content, but rather rely on the field `available_licenses` instead."
},
"available_licenses": {
"title": "Available Licenses",
"type": "array",
"items": {
"type": "string"
},
"description": "List of [SPDX license identifiers](https://spdx.org/licenses/) specifying a set of alternative licenses under which the client is granted access to all the data and metadata in this database.\n\nIf the data and metadata is available under multiple alternative licenses, identifiers of these multiple licenses SHOULD be provided to let clients know under which conditions the data and metadata can be used.\nInclusion of a license identifier in the list is a commitment of the database that the rights are in place to grant clients access to all the data and metadata according to the terms of either of these licenses (at the choice of the client).\nIf the licensing information provided via the field `license` omits licensing options specified in `available_licenses`, or if it otherwise contradicts them, a client MUST still be allowed to interpret the inclusion of a license in `available_licenses` as a full commitment from the database that the data and metadata is available, without exceptions, under the respective licenses.\nIf the database cannot make that commitment, e.g., if only part of the data is available under a license, the corresponding license identifier MUST NOT appear in `available_licenses` (but, rather, the field `license` is to be used to clarify the licensing situation.)\nAn empty list indicates that none of the SPDX licenses apply for the entirety of the database and that the licensing situation is clarified in human readable form in the field `license`."
},
"is_index": {
"title": "Is Index",
"type": "boolean",
Expand Down
19 changes: 17 additions & 2 deletions optimade/models/baseinfo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable=no-self-argument,no-name-in-module
import re
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Union

from pydantic import AnyHttpUrl, BaseModel, Field, root_validator, validator

from optimade.models.jsonapi import Resource
from optimade.models.jsonapi import Link, Resource
from optimade.models.utils import SemanticVersion, StrictField

__all__ = ("AvailableApiVersion", "BaseInfoAttributes", "BaseInfoResource")
Expand Down Expand Up @@ -78,6 +78,21 @@ class BaseInfoAttributes(BaseModel):
entry_types_by_format: Dict[str, List[str]] = StrictField(
..., description="Available entry endpoints as a function of output formats."
)
license: Union[Link, AnyHttpUrl] = StrictField(
...,
description="""A [JSON API links object](http://jsonapi.org/format/1.0/#document-links) giving a URL to a web page containing a human-readable text describing the license (or licensing options if there are multiple) covering all the data and metadata provided by this database.
Clients are advised not to try automated parsing of this link or its content, but rather rely on the field `available_licenses` instead.""",
)
available_licenses: Optional[List[str]] = StrictField(
...,
description="""List of [SPDX license identifiers](https://spdx.org/licenses/) specifying a set of alternative licenses under which the client is granted access to all the data and metadata in this database.

If the data and metadata is available under multiple alternative licenses, identifiers of these multiple licenses SHOULD be provided to let clients know under which conditions the data and metadata can be used.
Inclusion of a license identifier in the list is a commitment of the database that the rights are in place to grant clients access to all the data and metadata according to the terms of either of these licenses (at the choice of the client).
If the licensing information provided via the field `license` omits licensing options specified in `available_licenses`, or if it otherwise contradicts them, a client MUST still be allowed to interpret the inclusion of a license in `available_licenses` as a full commitment from the database that the data and metadata is available, without exceptions, under the respective licenses.
If the database cannot make that commitment, e.g., if only part of the data is available under a license, the corresponding license identifier MUST NOT appear in `available_licenses` (but, rather, the field `license` is to be used to clarify the licensing situation.)
An empty list indicates that none of the SPDX licenses apply for the entirety of the database and that the licensing situation is clarified in human readable form in the field `license`.""",
)
is_index: Optional[bool] = StrictField(
default=False,
description="If true, this is an index meta-database base URL (see section Index Meta-Database). "
Expand Down
7 changes: 7 additions & 0 deletions optimade/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ class ServerConfig(BaseSettings):
),
)

license: str = Field(
"CC-BY-4.0",
description="""The SPDX license identifier that will be linked to by the server under the info field `license`.
The `license` field value will be constructed from this identifier preprended with `https://spdx.org/licenses/CC-BY-4.0`, and the identifier will also be added to the `available_licenses` field directly.
There is currently no support for providing a full list of identifiers to be served at `available_licenses`.""",
)

log_level: LogLevel = Field(
LogLevel.INFO, description="Logging level for the OPTIMADE server."
)
Expand Down
2 changes: 2 additions & 0 deletions optimade/server/routers/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def get_info(request: Request) -> InfoResponse:
available_endpoints=["info", "links"] + list(ENTRY_INFO_SCHEMAS.keys()),
entry_types_by_format={"json": list(ENTRY_INFO_SCHEMAS.keys())},
is_index=False,
license={"href": f"https://spdx.org/licenses/{CONFIG.license}"},
available_licenses=[CONFIG.license],
),
),
)
Expand Down