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

Astarte: update /version endpoint #893

Merged
merged 8 commits into from
Mar 12, 2024

Conversation

osmanhadzic
Copy link
Contributor

@osmanhadzic osmanhadzic commented Jan 22, 2024

Provide third-party applications with information about the version of Astarte microservices they are interacting with, enabling them to adapt their behavior based on the underlying service version.

Standardization of routers for the Astarte API endpoints to have a uniform Phoenix pipeline structure.

Add a /version endpoint to each microservice API, allowing third-party applications to query and retrieve the microservice version using the GET verb. Authentication is not required for accessing this endpoint.

Standardize code for Astarte APIs by refactoring the router for endpoints. Remove plugs from controllers and incorporate them into the router pipeline.

By improving code readability in the app, astarte will expose information about the microservice version to third-party applications without authorization.

(#890)

Copy link

codecov bot commented Jan 22, 2024

Codecov Report

Attention: Patch coverage is 78.94737% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 68.56%. Comparing base (965ed38) to head (ee23ce3).

Files Patch % Lines
...engine_api/lib/astarte_appengine_api_web/router.ex 78.57% 6 Missing ⚠️
...ing_api/lib/astarte_housekeeping_api_web/router.ex 0.00% 1 Missing ⚠️
..._pairing_api/lib/astarte_pairing_api_web/router.ex 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #893      +/-   ##
==========================================
+ Coverage   68.08%   68.56%   +0.48%     
==========================================
  Files         274      226      -48     
  Lines        7093     6553     -540     
==========================================
- Hits         4829     4493     -336     
+ Misses       2264     2060     -204     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@Annopaolo Annopaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also update commit and PR description to reflect latest changes?

@osmanhadzic osmanhadzic force-pushed the astarte_api_version branch 3 times, most recently from 444583d to 0dcb387 Compare January 25, 2024 14:24
@osmanhadzic osmanhadzic requested a review from Annopaolo January 25, 2024 15:41
Copy link
Collaborator

@Annopaolo Annopaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicking on commits:

  • Pay attention to typos in the title: /verison --> /version
  • It would be better to keep consistency in commit titles.
    If you prefer, you can have a different pipeline standardization commit for each app, but then it would be better to mention the app in the title rather than keeping it generic (as you already did for AppEngine and RealmManagement API). Otherwise, if you want, you can put all pipeline standardization commits together: in this case, it is ok to say that the commit scope includes all apps.

Copy link
Collaborator

@Annopaolo Annopaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More nitpicking:

  • Commits 706f43a and 28ad443 should refer to pairing API rather than be generic, as all others
  • Commit ff0e150 has a typo in the title
  • The PR title is now outdated, as it is not just AppEngine that is changed

Finally, a new line should be added to CHANGELOG.md stating that the new /version endpoint was added. Refer to Keep a Changelog for the format

@Annopaolo Annopaolo added the API This issue or pull request is about API (e.g. unclear API, new API, API change, deprecation) label Jan 29, 2024
@osmanhadzic osmanhadzic changed the title AppEngine: update /version endpoint Astarte: update /version endpoint Jan 30, 2024
Copy link
Collaborator

@Annopaolo Annopaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidebriani's point was to use nested scopes, instead of nested pipelines. At each nesting level in scopes, it would be possible to add different plugs.
This could be clearer as it would allow to segregate the different sections of the API without adding new names to keep in mind (i.e. pipeline names).

I left a comment to show an example of a scope that could be nested

@osmanhadzic osmanhadzic marked this pull request as ready for review February 19, 2024 08:02
Comment on lines 38 to 40
post "/agent/devices", AgentController, :create
delete "/agent/devices/:device_id", AgentController, :delete
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Astarte.Pairing.APIWeb.Plug.AuthorizePath plug is missing (see https://github.com/astarte-platform/astarte/pull/893/files#diff-7bdaad5dbdd7c2ef3cc43ee2eaa46cc23afd1f6e6ae3ef955e274188665cc0c2L27), it should be included

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created :api_device and :api pipeline to separate. DeviceController does not require using Astarte.Pairing.APIWeb.Plug.AuthorizePath . I create a new pipeline only for DeviceController to separate from other controllers. @Annopaolo
:api_device does not have anything with pipeline :api

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both "/agent/devices" and "/agent/devices/:device_id" should have the Astarte.Pairing.APIWeb.Plug.AuthorizePath plug, that is currently missing (it has been removed by this PR, see https://github.com/astarte-platform/astarte/pull/893/files/cc196eee9bb629d3ef0863faba74d6718c8d1f41#diff-7bdaad5dbdd7c2ef3cc43ee2eaa46cc23afd1f6e6ae3ef955e274188665cc0c2L27-L28). Unless it is added back, those two endpoints are broken

Copy link
Collaborator

@Annopaolo Annopaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, an AppEngine API route seems to be missing (see CI run):

(Phoenix.Router.NoRouteError) no route found for GET /v1/autotestrealm/devices-by-alias/device_a/interfaces/com.test.LCDMonitor/time/to (Astarte.AppEngine.APIWeb.Router)

@osmanhadzic osmanhadzic force-pushed the astarte_api_version branch 2 times, most recently from 35dbde4 to 2474849 Compare March 6, 2024 11:54
Add a new scope, '/version', in the router with the HTTP GET method
endpoint for the version controller. The scope does not require any type
of authorization and does not have any effect on other endpoints in the
API.

(astarte-platform#890)

Signed-off-by: Osman Hadzic <[email protected]>
@osmanhadzic osmanhadzic force-pushed the astarte_api_version branch from 2474849 to 736eb8b Compare March 6, 2024 13:36
@osmanhadzic osmanhadzic requested a review from Annopaolo March 6, 2024 13:47
Copy link
Collaborator

@Annopaolo Annopaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there!

@osmanhadzic osmanhadzic requested a review from Annopaolo March 11, 2024 08:03
Copy link
Collaborator

@Annopaolo Annopaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from two minor details, LGTM

Comment on lines 43 to 47
scope "/version" do
pipe_through :api

get "/", VersionController, :show
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this scope is inside another scope that is piped through :device_api, the "/version" call will pass through the LogHwId plug, but there is no id to log when calling /version

Comment on lines 49 to 45
scope "/agent" do
pipe_through :api

post "/devices", AgentController, :create
delete "/devices/:device_id", AgentController, :delete
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this scope is inside another scope that is piped through :device_api, the "/agent" call will pass through the LogHwId plug, but there is no id to log when calling /agent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made changes.

@osmanhadzic osmanhadzic force-pushed the astarte_api_version branch from 736eb8b to 5501d85 Compare March 11, 2024 15:16
@osmanhadzic osmanhadzic requested a review from Annopaolo March 11, 2024 15:18
`astarte_appengine_api` components did not have a uniform
Phoenix pipeline structure: some plugs were specified inside the
pipeline, and some inside controllers. Most of the plugs specified
inside controllers were replicated
(e.g. `Astarte.AppEngine.APIWeb.Plug.AuthorizePath`
in `astarte_appengine_api`).

Refactor exiting code: rationalize the structure of the pipeline by
factoring out
replicated plugs from controllers and including them in the pipelines.
This leads to some replication for scope
(seee.g apps/astarte_pairing_api/lib/astarte_pairing_api_web/router.ex),
but Phoenix allows for duplicated scopes as long as endpoints
are different.

The API of the components is not changed.

Signed-off-by: Osman Hadzic <[email protected]>
Add a new scope, '/version', in the router with the HTTP GET method
endpoint for the version controller. The scope does not require any type
of authorization and does not have any effect on other endpoints in the
API.

Signed-off-by: Osman Hadzic <[email protected]>
`astarte_pairing_api` components did not have a uniform Phoenix pipeline
structure: some plugs were specified inside the pipeline, and some
inside controllers. Most of the plugs specified inside controllers were
replicated (e.g. `Astarte.Pairing.APIWeb.Plug.AuthorizePath`
in `astarte_pairing_api`).

Refactor exiting code: rationalize the structure of the pipeline by
factoring out
replicated plugs from controllers and including them in the pipelines.
This leads to some replication for scope
(seee.g apps/astarte_pairing_api/lib/astarte_pairing_api_web/router.ex),
but Phoenix allows for duplicated scopes as long as endpoints
are different.

The API of the components is not changed.

Signed-off-by: Osman Hadzic <[email protected]>
Add a new scope, '/version', in the router with the HTTP GET method
endpoint for the version controller. The scope does not require any type
of authorization and does not have any effect on other endpoints in the
API.

(astarte-platform#890)

Signed-off-by: Osman Hadzic <[email protected]>
`astarte_realm_management_api` components did not have a uniform Phoenix
pipeline structure: some plugs were specified inside the pipeline and
some inside controllers. Most of the plugs specified inside controllers
were replicated (e.g.`Astarte.RealmManagement.APIWeb.Plug.AuthorizePath`
in `astarte_realm_management_api`).

Refactor existing code: rationalize the structure of the pipeline by
factoring out
replicated plugs from controllers and included them in the pipelines.
This leads to some replication of the scope
(see e.g.apps/astarte_realm_management_api/lib/astarte_pairing_api_web
/router.ex),
but Phoenix allows for duplicated scopes as long as
endpoints are different.

The API of the components is not changed.

Signed-off-by: Osman Hadzic <[email protected]>
Add a new scope, '/version', in the router with the HTTP GET method
endpoint for the version controller. The scope does not require any type
of authorization and does not have any effect on other endpoints in the
API.

(astarte-platform#890)

Signed-off-by: Osman Hadzic <[email protected]>
Signed-off-by: Osman Hadzic <[email protected]>
@Annopaolo Annopaolo merged commit c17ee3a into astarte-platform:master Mar 12, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API This issue or pull request is about API (e.g. unclear API, new API, API change, deprecation)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants