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

Helper to convert api_endpoint into DecodedURL #223

Merged
merged 3 commits into from
Aug 3, 2020

Conversation

exarkun
Copy link
Member

@exarkun exarkun commented Jul 31, 2020

Fixes #222

There didn't seem to be any particular reason to tie this tightly to GlobalConfigDatabase.api_endpoint so I didn't. It's just a helper you can use with that value.

@codecov
Copy link

codecov bot commented Jul 31, 2020

Codecov Report

Merging #223 into master will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #223      +/-   ##
==========================================
+ Coverage   87.15%   87.25%   +0.09%     
==========================================
  Files          24       25       +1     
  Lines        2685     2706      +21     
  Branches      348      350       +2     
==========================================
+ Hits         2340     2361      +21     
  Misses        256      256              
  Partials       89       89              
Flag Coverage Δ
#integration 55.76% <42.85%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/magic_folder/_endpoint_parser.py 100.00% <100.00%> (ø)
src/magic_folder/config.py 98.73% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3bf6cbc...fcb04dd. Read the comment docs.

Copy link
Member

@sajith sajith left a comment

Choose a reason for hiding this comment

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

Looks nifty to me. We could learn more about the "ergonomics" of this helper in actual use, and refine from there on.

_ENDPOINT_CONVERTERS = {
u"tcp": _tcp_to_http_api_root,
u"ssl": _ssl_to_https_api_root,
}
Copy link
Member

@sajith sajith Aug 3, 2020

Choose a reason for hiding this comment

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

Perhaps error handling could be improved here? As in, what happens when endpoint_description is not really an endpoint?

I just learned that magic-folder migrate --listen-endpoint 6001 --node-directory ../path/to/node accepts that non-endpoint argument without complaining. Thus magic folder configuration will have just 6001 for api_endpoint, and passing that on will result in an error here.

Of course migrate too probably could some error checking...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, it would be good to reject that early. create_global_configuration should probably reject it and then the migrate command could handle that exception and report something meaningful to the cli user.

By the time it makes it into the database, it should really be valid and no one else in the system should have to worry about validation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed #226

from ._endpoint_parser import (
endpoint_description_to_http_api_root,
)


Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add an additional helper in GlobalConfigDatabase, like this:

    def http_api_root(self):
        """
        Base URL for HTTP API, derived from endpoint describtion.
        """
        return endpoint_description_to_http_api_root(self.api_endpoint)

Perhaps consumers of the code in config.py can avoid some duplication that way?

Copy link
Member Author

Choose a reason for hiding this comment

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

It might make sense, I'm not sure. It might also come down to taste. I almost made it a method but decided against it based on the idea that GlobalConfigDatabase's job is to allow state to be stored and retrieved, not to provide all of the different convenient interfaces to that state. Adding one accessor is hardly a terrible burden but maybe it's a step in the direction we don't want to go, so I'm inclined to leave it off for now and then add it later if it turns out it would be a significant benefit (we could also consider adding the above except as a free function instead of a method which might be 99% of the convenience without expanding GlobalConfigDatabase's interface.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense. Thank you.

@exarkun exarkun merged commit ee07ef4 into master Aug 3, 2020
@exarkun exarkun deleted the 222.magic-folder-api-endpoint-config branch August 3, 2020 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the Magic-Folder daemon HTTP API root on GlobalConfigDatabase
2 participants