-
Notifications
You must be signed in to change notification settings - Fork 52
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
Astarte: update /version endpoint #893
Conversation
Codecov ReportAttention: Patch coverage is
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. |
847f994
to
02dd022
Compare
apps/astarte_appengine_api/lib/astarte_appengine_api_web/endpoint.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/plug/microservice_version_plug.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/plug/microservice_version_plug.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/plug/microservice_version_plug.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/plug/microservice_version_plug.ex
Outdated
Show resolved
Hide resolved
02dd022
to
1f9a76c
Compare
apps/astarte_appengine_api/lib/astarte_appengine_api_web/plug/microservice_version_plug.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/endpoint.ex
Outdated
Show resolved
Hide resolved
1f9a76c
to
4dcb336
Compare
4dcb336
to
d12bab6
Compare
There was a problem hiding this 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?
93f5d87
to
4ba0016
Compare
444583d
to
0dcb387
Compare
0dcb387
to
9ee380e
Compare
There was a problem hiding this 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.
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
9ee380e
to
1cb07f0
Compare
There was a problem hiding this 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
and28ad443
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
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
1cb07f0
to
aa84119
Compare
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
aa84119
to
138acf8
Compare
There was a problem hiding this 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
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
138acf8
to
d266243
Compare
96eb6a7
to
cc196ee
Compare
post "/agent/devices", AgentController, :create | ||
delete "/agent/devices/:device_id", AgentController, :delete |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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)
35dbde4
to
2474849
Compare
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]>
2474849
to
736eb8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
There was a problem hiding this 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
scope "/version" do | ||
pipe_through :api | ||
|
||
get "/", VersionController, :show | ||
end |
There was a problem hiding this comment.
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
scope "/agent" do | ||
pipe_through :api | ||
|
||
post "/devices", AgentController, :create | ||
delete "/devices/:device_id", AgentController, :delete | ||
end |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made changes.
736eb8b
to
5501d85
Compare
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
apps/astarte_appengine_api/lib/astarte_appengine_api_web/router.ex
Outdated
Show resolved
Hide resolved
`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]>
5501d85
to
ee23ce3
Compare
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)