diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 654b523..eb519e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,18 +20,21 @@ jobs: # needs: lint strategy: matrix: - ckan-version: [2.9] + ckan-base-version: [2.9] + ckan-version: [py3.9] + solr-version: [solr8] fail-fast: false - name: CKAN ${{ matrix.ckan-version }} + name: CKAN ${{ matrix.ckan-base-version }} runs-on: ubuntu-latest container: - image: openknowledge/ckan-dev:${{ matrix.ckan-version }} + image: ckan/ckan-dev:${{ matrix.ckan-base-version }}-${{ matrix.ckan-version }} + options: --user root services: solr: - image: ckan/ckan-solr-dev:${{ matrix.ckan-version }} + image: ckan/ckan-solr:${{ matrix.ckan-base-version }}-${{ matrix.solr-version }} postgres: - image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }} + image: ckan/ckan-postgres-dev:${{ matrix.ckan-base-version }} env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres @@ -46,6 +49,8 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install CURL + run: apt install curl -y - name: Install requirements run: | pip install -r dev-requirements.txt @@ -57,8 +62,8 @@ jobs: ckan -c test.ini db init - name: Run tests run: pytest --ckan-ini=test.ini --cov=ckanext.validationapi --cov-report=xml --cov-append --disable-warnings ckanext/validationapi/tests - - name: Upload coverage report to codecov - uses: codecov/codecov-action@v1 - with: - file: ./coverage.xml - token: ${{secrets.CODECOV_TOKEN}} + - name: Upload coverage reports to Codecov + run: | + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + ./codecov \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 66e5513..493e379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## Development +## [0.2.3](https://github.com/berlinonline/ckanext-validationapi/releases/tag/0.2.3) + +_(2024-12-11)_ + +- Add publiccode.yml +- Update company information +- Fix Github Workflow (CI/CD) + ## [0.2.2](https://github.com/berlinonline/ckanext-validationapi/releases/tag/0.2.2) _(2023-05-22)_ diff --git a/README.md b/README.md index bc8aa60..d3ec042 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ The complete list of error codes is: ## License This material is copyright © -[BerlinOnline Stadtportal GmbH & Co. KG](https://www.berlinonline.net/). +[BerlinOnline Stadtportal GmbH](https://www.berlinonline.net/). This extension is open and licensed under the GNU Affero General Public License (AGPL) v3.0. Its full text may be found at: diff --git a/publiccode.yml b/publiccode.yml new file mode 100644 index 0000000..ce6e731 --- /dev/null +++ b/publiccode.yml @@ -0,0 +1,220 @@ +# This repository adheres to the publiccode.yml standard by including this +# metadata file that makes public software easily discoverable. +# More info at https://github.com/italia/publiccode.yml + +publiccodeYmlVersion: '0.2' +name: ckanext-validationapi +applicationSuite: CKAN +url: 'https://github.com/berlinonline/ckanext-validationapi' +releaseDate: '2018-11-02' +developmentStatus: stable +softwareVersion: 0.2.3 +softwareType: library +platforms: + - web +maintenance: + type: internal + contacts: + - name: Dr. Knud Möller + email: knud.moeller@berlinonline.de +legal: + license: AGPL-3.0-only + mainCopyrightOwner: BerlinOnline GmbH + repoOwner: BerlinOnline GmbH +localisation: + localisationReady: false + availableLanguages: + - en +description: + it: + genericName: ckanext-validationapi + documentation: 'https://github.com/berlinonline/ckanext-validationapi' + apiDocumentation: >- + https://github.com/berlinonline/ckanext-validationapi?tab=readme-ov-file#using-the-api + shortDescription: >- + ckanext-validationapi provides an API as a public wrapper around the + internal validator functions of CKAN. + longDescription: > + This plugin belongs to a set of plugins for the _Datenregister_ – the + non-public [CKAN](https://ckan.org/) instance that is part of Berlin's + open data portal [daten.berlin.de](https://daten.berlin.de/). + + + `ckanext-validationapi` provides an API as a public wrapper around the + internal validator functions of CKAN. + + + The plugin implements the following CKAN interfaces: + + + - + [IBlueprint](http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IBlueprint) + + - + [IConfigurer](http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IConfigurer) + + + ## Requirements + + + This plugin has been tested with CKAN 2.9 (which requires Python 3). + + + ## Using the API + + + All validator functions that are available through + `ckan.plugins.toolkit.get\_validator()` can be used. The list of standard + validators that CKAN offers is available at + [https://docs.ckan.org/en/latest/extensions/validators.html](https://docs.ckan.org/en/latest/extensions/validators.html). + Plugins can add more validators by implementing the + [IValidators](https://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IValidators) + interface. + + + The API is accessible via `$CKAN\_URL/api/validation`; currently its only + method is `validate`. Only POST requests with content type + `application/json` are accepted. + + + The expected payload to `validate` is a JSON object with two attributes: + + + - `validator`: The name of the validator as it would be passed to + `ckan.plugins.toolkit.get\_validator()`. + + - `value`: The value we want to submit for validation. + + + Here is an example: + + { + "validator": "email\_validator" , + "value": "jane.doe@company.com" + } + + If the validator exists, `validationapi` will call the validator function + with the provided value. The response will be a JSON object with these + attributes: + + + - `validator`: The name of the validator as it would be passed to + `ckan.plugins.toolkit.get\_validator()`. + + - `value`: The value that was submitted for validation. + + - `success`: Whether or not `value` passed the validation. + + - `result`: If successful, the output of the validator. This will often be the same as `value`, but sometimes the validator will perform some transformation as well. + - `message`: If not successful, this will contain an error message as provided by the validator. + + Here are some examples for communicating with the validation API via curl: + + + ### Valid input, unchanged + + curl -X POST \ + --data '{ "validator": "email\_validator", "value": "jane.doe@company.com" }' \ + -H "Content-Type: application/json" \ + $CKAN\_URL/api/validation/validate + + { + "validator": "email\_validator", + "value": "jane.doe@company.com", + "success": true, + "result": "jane.doe@company.com" + } + + ### Valid input, changed + + curl -X POST \ + --data '{ "validator": "isodate", "value": "2004-10-10" }' \ + -H "Content-Type: application/json" \ + $CKAN\_URL/api/validation/validate + + { + "validator": "isodate", + "value": "2004-10-10", + "success": true, + "result": "2004-10-10 00:00:00" + } + + ### Invalid input + + curl -X POST \ + --data '{ "validator": "isodate", "value": "2004-10-10x" }' \ + -H "Content-Type: application/json" \ + $CKAN\_URL/api/validation/validate + + { + "message": "Invalid: u'Datumsformat ung\\xfcltig.'", + "validator": "isodate", + "value": "2004-10-10x", + "success": false + } + + ### Errors + + + If possible, validationapi will catch errors and provide an error message + in the same format as above, but with the HTTP Response Code 400 (Bad + Request). Below are some examples: + + + #### Unknown Validator + + curl -X POST \ + --data '{ "validator": "foolidator", "value": "barbar" }' \ + -H "Content-Type: application/json" \ + $CKAN\_URL/api/validation/validate + + { + "validator": "foolidator", + "value": "barbar", + "success": false, + "error": { + "message": "Bad Request - Validator \`foolidator\` does not exist", + "code": 7 + } + } + + #### Wrong Request Format + + curl $CKAN\_URL/api/validation/validate + + { + "validator": null, + "value": null, + "success": false, + "error": { + "message": "Bad Request - Validation API accepts only POST requests with content type 'application/json'.", + "code": 1 + } + } + + #### Error Codes + + + The complete list of error codes is: + + + - Wrong HTTP method = 1 + + - Wrong content type = 2 + + - No request data found = 3 + + - Cannot decode JSON = 4 + + - Wrong type of JSON = 5 + + - Wrong JSON structure = 6 + + - Unknown validator = 7 + + - Validator has unexpected number of arguments = 8 + + - Unexpected error = 20 +categories: + - it-development + - knowledge-management