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

API contract review - Phase one #1805

Closed
felipeneuhauss opened this issue Feb 20, 2023 · 1 comment
Closed

API contract review - Phase one #1805

felipeneuhauss opened this issue Feb 20, 2023 · 1 comment
Assignees
Labels
IEU Intellect EU Team

Comments

@felipeneuhauss
Copy link
Contributor

Problem description

This PR aims to fix the points bellow related to the Account, Profile, and Tokens modules

The API nowadays contains a lot of resources and we need to fix and improve some points in terms of best practices for RESTful APIs.

These are the points identified and require our attention:

  1. To fix status codes applying 200 for PUT, POST, 201 for entity creations, 204 when no body content is required, and 202 when an async process is executed in the background.
  2. To Apply validations for body data, path, and query requests, which means returning 422 for the user, with clear messages as well.
  3. When saving new data, check if it's indispensable to return some response. Maybe one id attribute is enough.
  4. Return 500 only for exceptions. Validation error is not an exception.
  5. To improve the route names, like applying plural names for resources keeping the conventions.
  6. Avoid returns like res.json('null') because it will generate an unexpected response for the consumer. Use res.json({}) or res.json([]) instead.
  7. Avoid the use of res.end(). The res.send() checks the structure of your output and sets header information accordingly.
  8. For deletions 204 status code for most cases is enough.
  9. Some endpoints contain params that are not used, such us profiles/:username. In this case for example, the data managed comes from the logged user and the :username param does not influence in the result.

Furthermore, we need to improve the strategy to manage all validations. As mentioned previously some policies and schema validations are not being appropriately treated.

We need to create a standard way to organize and manage any validation rules and place its logic in a different function or class in order to improve maintenance e.g.

The route should process only the functions it was made for. As practiced in the Express framework, middleware filters, sanitize, or even logs data. So we can use the same place to manage validation rules.

More information here

Requirements

This PR is related to the Account, Profile, and Tokens modules

Furthermore, these items need to be fixed.

  • Validations were applied through a new middleware.
  • Route names were changed to plural like /artifact to /artifacts
  • The way the errors were handled was changed to be more user-friendly not only returning 500 but also 422, 404, 403, with the specific errors.
  • The error handler was improved to centralize all request errors
  • Duplicated codes were removed in one only call
  • Some unnecessary casts were removed
  • Some unreachable conditions were removed.
  • Unnecessary conditions to check URL params were removed because once it's not present it automatically returns 404.
  • The hpp express middleware was added to protect against HTTP Parameter Pollution attacks

Definition of done

All the API attend the RESTful standard.

Acceptance criteria

All the API attend the RESTful standard.

@felipeneuhauss felipeneuhauss added the IEU Intellect EU Team label Feb 20, 2023
@felipeneuhauss felipeneuhauss self-assigned this Feb 20, 2023
@ieumuzair
Copy link
Contributor

@prernaadev01

anvabr pushed a commit that referenced this issue Apr 25, 2023
### Headlines
- Tagging of Policy Artifacts
- Improving Policy Configurator Blocks using Colors and Shapes
- Scalability of Artifact Size and DB
- Secrets in Pipeline

### Enhancements
- Tagging of Guardian policy artifacts [#1661](#1661)
- Scalability: Artifact (Policy, VC, Schema) size and internal DB [#1155](#1155)
- API contract reviewing [#1629](#1629)
- Develop guardian-cli to manage project [#1636](#1636)
- Dynamic Topic/Message configuration according to the environment [#1696](#1696)
- Monitoring tools - Application events [#1842](#1842)
- Multi configuration of persistance according to the environment [#1888](#1888)
- Develop cypress test suite for contracts [#1816](#1816)
- Secrets in pipelines [#1610](#1610)
- Expose subscribed event or log messages to an external application [#1634](#1634)
- API contract review - Phase one [#1805](#1805)
- Direct service-to-service communication for large payloads [#1998](#1998)
- Verra Reforestation Development [#2023](#2023)
- Use colours and shapes to highlight blocks properties and/or context [#1795](#1795)

### Bugs Fixed
- `policyRolesBlock` web interface allows me to choose role multiple times [#1980](#1980)
- Invalid schema owner [#1972](#1972)
- I cannot exit the code editor without saving the content of the expression [#1981](#1981)
- Persistent data gets dropped between application restarts [#1950](#1950)
- Show transaction id in log file of guardian-service [#1983](#1983)
- Unable to publish policy [#1978](#1978)
- Issue while setup, after new release: unable to Finish Setup [#1971](#1971)
- Potential memory leak in worker service [#1926](#1926)
- Wrong behaviour for minting token process for multipolicies [#2019](#2019)
- Large amount of tokens being minted [#1976](#1976)
- Clogging of queue due to high volume of tokens minted. [#2005](#2005)
- Progress Bar when performing Schema operations are missing [#2046](#2046)
- Unable to configure Guardian services [#1999](#1999)

* fix docker compose

Signed-off-by: simvalery <[email protected]>

* delete folder

Signed-off-by: simvalery <[email protected]>

* update vc in tags

* fixes

Signed-off-by: simvalery <[email protected]>

* share tasks

Signed-off-by: simvalery <[email protected]>

* service scripts

Signed-off-by: simvalery <[email protected]>

* clean code

Signed-off-by: simvalery <[email protected]>

* policy instance container

Signed-off-by: simvalery <[email protected]>

* fix tests

Signed-off-by: simvalery <[email protected]>

* corrected broken links in ReadMe

* added versions to ReadMe

* increase max hedera timeout

Signed-off-by: simvalery <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* bump version

Signed-off-by: simvalery <[email protected]>

* fix workers queue

Signed-off-by: simvalery <[email protected]>

* test fix

Signed-off-by: simvalery <[email protected]>

* wss updates

Signed-off-by: simvalery <[email protected]>

* fix

Signed-off-by: simvalery <[email protected]>

* fix

Signed-off-by: simvalery <[email protected]>

* fix block errors

Signed-off-by: simvalery <[email protected]>

* fix messageId

Signed-off-by: simvalery <[email protected]>

* Add documentation for Metered Energy Cooking policy

* Add policy workflow, registry and project proponent's responsibilities

* Complete policy guide

* Add TOC

* Add futureproofing section

* Add futureproofing section

* Add policy comparison

* Add futureproof flow diagram

* Add policy import screenshot

* Add policy file

* update blocks

* fix documents grid updates

Signed-off-by: artembuslaev <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* lint

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix loading for event blocks

Signed-off-by: artembuslaev <[email protected]>

* GITBOOK-308: change request with no subject merged in GitBook

* fix duplicate update block messages

Signed-off-by: artembuslaev <[email protected]>

* added loading to token confirmation ui

Signed-off-by: artembuslaev <[email protected]>

* update swagger

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix loading in event blocks

Signed-off-by: artembuslaev <[email protected]>

* Add relevant demo video links

* moved entities from guardian to common repo

Signed-off-by: artembuslaev <[email protected]>

* remove entities from policy-service

Signed-off-by: artembuslaev <[email protected]>

* chunking db entities

Signed-off-by: artembuslaev <[email protected]>

* fix build

Signed-off-by: artembuslaev <[email protected]>

* fix lint and tests

Signed-off-by: artembuslaev <[email protected]>

* fix duplicate transaction logs

Signed-off-by: artembuslaev <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* update entities

Signed-off-by: artembuslaev <[email protected]>

* added chunking property to send block

Signed-off-by: artembuslaev <[email protected]>

* update common package json

Signed-off-by: artembuslaev <[email protected]>

* fix contract tags

* lint

* Show transaction id in the log

Signed-off-by: Giuseppe Bertone <[email protected]>

* fix update token

Signed-off-by: Stepan Kiryakov <[email protected]>

* remove logs

Signed-off-by: Stepan Kiryakov <[email protected]>

* moved to common

* fix lint

Signed-off-by: artembuslaev <[email protected]>

* - #1888
- #1696

integrate previous changes to Dokerfile
docs and PREUSED
GUARDIAN_ENV in .env
Docs: Docker Compose V2 version
lint

Signed-off-by: otherNet <[email protected]>

* fix transaction logs

Signed-off-by: artembuslaev <[email protected]>

* fix tag schemas

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix delete tag schemas

Signed-off-by: Stepan Kiryakov <[email protected]>

* #1981

Signed-off-by: Stepan Kiryakov <[email protected]>

* automatically document cache

Signed-off-by: artembuslaev <[email protected]>

* fix lint

Signed-off-by: artembuslaev <[email protected]>

* reset send block properties

* moved tests

Signed-off-by: artembuslaev <[email protected]>

* set document cache to aggregate block

Signed-off-by: artembuslaev <[email protected]>

* fix creation of vp document

Signed-off-by: artembuslaev <[email protected]>

* fix publishing schemas

* fix comments and blinking request dialog

* themes

Signed-off-by: Stepan Kiryakov <[email protected]>

* added defs to schemas

Signed-off-by: artembuslaev <[email protected]>

* added document cache fields to external block

Signed-off-by: artembuslaev <[email protected]>

* fix updating files

Signed-off-by: artembuslaev <[email protected]>

* fix updating multi sign block

Signed-off-by: artembuslaev <[email protected]>

* fix lint

Signed-off-by: artembuslaev <[email protected]>

* update

* merge new secrets to dev

Signed-off-by: simvalery <[email protected]>

* merge new secrets to dev

Signed-off-by: simvalery <[email protected]>

* merge new secrets to dev

Signed-off-by: simvalery <[email protected]>

* improve minting tokens

Signed-off-by: artembuslaev <[email protected]>

* fix build

Signed-off-by: simvalery <[email protected]>

* update worker tasks priority

Signed-off-by: artembuslaev <[email protected]>

* fix user keys

Signed-off-by: simvalery <[email protected]>

* added loading tokens on creation retire request

Signed-off-by: artembuslaev <[email protected]>

* fix user keys oldstyle

Signed-off-by: simvalery <[email protected]>

* fix startup values

Signed-off-by: simvalery <[email protected]>

* fix api tests

Signed-off-by: simvalery <[email protected]>

* fix api tests

Signed-off-by: simvalery <[email protected]>

* .env files

Signed-off-by: simvalery <[email protected]>

* fix lint
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix common sorting in grids

Signed-off-by: artembuslaev <[email protected]>

* fix publishing policies

Signed-off-by: artembuslaev <[email protected]>

* update

* added readme of modules

* added docs link of modules

* GITBOOK-309: Adding subpage for the Guardian CLI under "Frameworks/Libraries"

* GITBOOK-310: added Guardian CLI

* added BATCH_NFT_MINT_SIZE setting

Signed-off-by: artembuslaev <[email protected]>

* feat: application-events module

Signed-off-by: Felipe Neuhauss <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix updating entities

Signed-off-by: artembuslaev <[email protected]>

* fix exporting modules

Signed-off-by: artembuslaev <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-311: Added Tymlez Policy demo guide

* feat: api contract review

Signed-off-by: Felipe Neuhauss <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* filter by api

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-312: Added env parameters for guardian-service

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* added handing non retryable errors

Signed-off-by: artembuslaev <[email protected]>

* added logs for mint

Signed-off-by: artembuslaev <[email protected]>

* [Cookstove Policy] Publish new policy version and readme with future TODOs

* update

* large payloads
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* docker-run
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix .env
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* add themes api

Signed-off-by: Stepan Kiryakov <[email protected]>

* remove quotes
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix port expose
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* feature/user-driven-mrv

* GITBOOK-313: adding instructions of changing operator ID and Key in settings

* fix api test
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix 404 error

Signed-off-by: simvalery <[email protected]>

* fix timeout

Signed-off-by: simvalery <[email protected]>

* devide test

Signed-off-by: simvalery <[email protected]>

* add auth header

Signed-off-by: simvalery <[email protected]>

* add destructor

Signed-off-by: simvalery <[email protected]>

* remove old test

Signed-off-by: simvalery <[email protected]>

* update theme api

Signed-off-by: Stepan Kiryakov <[email protected]>

* update swagger

Signed-off-by: Stepan Kiryakov <[email protected]>

* feat: application-events additional fixes

Signed-off-by: Felipe Neuhauss <[email protected]>

* change get balances

Signed-off-by: Stepan Kiryakov <[email protected]>

* rest balance

Signed-off-by: simvalery <[email protected]>

* feat: application-events reduced events to avoid annoying notifications

Signed-off-by: Felipe Neuhauss <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-314: added parameters for services

* GITBOOK-315: Adding Tag UI for Policies and Schemas

* secret manager update

Signed-off-by: simvalery <[email protected]>

* added duplicate transaction handler

Signed-off-by: artembuslaev <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* feat: application-events module.ts updated

Signed-off-by: Felipe Neuhauss <[email protected]>

* Fixed userInfo error

* fix #2019

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-317: Tags APIs for Policies

* GITBOOK-318: Schema Tag APIs added

* GITBOOK-319: corrected errors in tags

* Create API Guideline

* Delete API Guideline

* add settings validation

Signed-off-by: simvalery <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix label

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix update settings

Signed-off-by: simvalery <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix legends

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix application events listener; add service to publish CI

Signed-off-by: simvalery <[email protected]>

* Fixed conflict

* Fixed conflict 2

* added new policies [skip ci]

Signed-off-by: artembuslaev <[email protected]>

* slice users

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix lint

Signed-off-by: Stepan Kiryakov <[email protected]>

* Added iREC 9 in ReadMe

* fix version

Signed-off-by: Stepan Kiryakov <[email protected]>

* Added Verra ARR ReadMe

* update gold standard ar policy

Signed-off-by: artembuslaev <[email protected]>

* fix filters in button block

Signed-off-by: artembuslaev <[email protected]>

* Deleted Branding related code

* Adding Gold Standard AR ReadMe

* GITBOOK-320: Added Themes UI

* GITBOOK-321: Adding Theme APIs

* Add files via upload

* hotfix/progress-bar-schemas

* API Guideline 

This documentation is to underline the different types of validation status code and any error status code, including Naming Conventions for RESTful APIs. This documentation is apart of the API contract review PR #1974 and issue #1629

* fix duplicate schema field label

Signed-off-by: artembuslaev <[email protected]>

* updated policy files [skip ci]

Signed-off-by: artembuslaev <[email protected]>

* fix merge

Signed-off-by: Stepan Kiryakov <[email protected]>

* bump version

Signed-off-by: simvalery <[email protected]>

* GITBOOK-322: Guidance for Open Source Policy

* Updated Verra ARR Timestamp

* Added Schema

* Updated Gold Standard AR Timestamp

---------

Signed-off-by: simvalery <[email protected]>
Signed-off-by: Stepan Kiryakov <[email protected]>
Signed-off-by: artembuslaev <[email protected]>
Signed-off-by: Giuseppe Bertone <[email protected]>
Signed-off-by: otherNet <[email protected]>
Signed-off-by: Felipe Neuhauss <[email protected]>
Signed-off-by: artembuslaev <[email protected]>
Co-authored-by: Stepan Kiryakov <[email protected]>
Co-authored-by: prernaadev01 <[email protected]>
Co-authored-by: Gautam Prajapati <[email protected]>
Co-authored-by: Gautam Prajapati <[email protected]>
Co-authored-by: artembuslaev <[email protected]>
Co-authored-by: prernaa.agarwal <[email protected]>
Co-authored-by: artembuslaev <[email protected]>
Co-authored-by: Giuseppe Bertone <[email protected]>
Co-authored-by: Stepan Kirjakov <[email protected]>
Co-authored-by: otherNet <[email protected]>
Co-authored-by: Serg Metelin <[email protected]>
Co-authored-by: Felipe Neuhauss <[email protected]>
Co-authored-by: artembuslaev <[email protected]>
Co-authored-by: E. Santiago <[email protected]>
Co-authored-by: E. Santiago <[email protected]>
Co-authored-by: Vanessa Lopes <[email protected]>
Co-authored-by: Eduardo Santiago <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IEU Intellect EU Team
Projects
None yet
Development

No branches or pull requests

3 participants