Skip to content

Use ftp w/ TLS for default IERS download (CDDIS) - #9964

Merged
bsipocz merged 8 commits into
astropy:masterfrom
eteq:use-ftps-for-iers-cddis
Apr 24, 2020
Merged

bsipocz merged 8 commits into
astropy:masterfrom
eteq:use-ftps-for-iers-cddis

Conversation

@eteq

@eteq eteq commented Feb 20, 2020 •

Copy link
Copy Markdown
Member

This is an attempt to address #9963. It is quite a bit hackier that I would like, but I don't really see an obvious way to do any better without circumventing the caching machinery. I'm also very curious to see if the tests pass - it worked for me locally, but some of these remote tests behave quite differently on the CI...

One subtle side-effect of this implementation is that any ftp IERS URLs now use TLS with no way to turn it off. There are some ways I can imagine to avoid that if we think it is important (e.g. use "ftps" instead of "ftp" to indicate the tls version), but I'm not really sure how/if it's important at all.

@pep8speaks

pep8speaks commented Feb 20, 2020 •

Copy link
Copy Markdown

Hello @eteq 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style.

There are no PEP8 style issues with this pull request - thanks! 🎉

Comment last updated at 2020-04-24 19:43:21 UTC

@astropy-bot astropy-bot Bot added the utils label Feb 20, 2020
@eteq eteq changed the title Use ftps for iers cddis Use ftp w/ TLS for default IERS download (CDDIS) Feb 20, 2020
@eteq eteq added this to the v4.0.1 milestone Feb 20, 2020
@bsipocz

bsipocz commented Feb 20, 2020

Copy link
Copy Markdown
Member

interesting, test are complaining that they should be remote_data

Comment thread astropy/utils/iers/iers.py Outdated
"""
kwargs.setdefault('http_headers', {'User-Agent': 'astropy/iers',
'Accept': '*/*'})
kwarg.setdefault('ftp_tls', True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo: should be kwargs

@pllim pllim Feb 20, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it worked for me locally

Wait a minute, how did the test even pass with this typo?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The tests did fail! (At least remote_data) That's how I found out.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mhvk , sorry for the confusion, but I meant how @eteq got it to work locally.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah, yes, now you mention it, I wondered about that too!

@eteq eteq Feb 25, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good question. I think it's because I tested an earlier version to prove it works and was in a hurry at the end so didn't run the later versions with --remote-data... 🐑 - I cooked up a hacky version first, tested that, but then didn't with the cleaned-up version.

@mhvk

mhvk commented Feb 20, 2020

Copy link
Copy Markdown
Contributor

Certainly for a temporary work-around this looks fine. It is strange that CDDIS doesn't provide anonymous download via https.

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, does seem hacky and I don't know how I feel about download_data having more and more options. But like you pointed out, we do not have a lot of choices here other than creating our own mirror.

Comment thread astropy/utils/data.py
http_headers = {}

if ftp_tls:
urlopener = urllib.request.build_opener(_FTPTLSHandler())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should there be a check to raise exception if this option is given but URL is not FTP?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think so. This is pretty deep into some hacky layers of urllib, but based on https://docs.python.org/3/library/urllib.request.html#urllib.request.build_opener it looks to me like this just replaces the default FTP handler with the new one. So if the user passes in a non-ftp url a different handler takes care of it and this one is just skipped.

@pllim

pllim commented Feb 20, 2020

Copy link
Copy Markdown
Member

I think this needs a change log too.

@eteq

eteq commented Feb 25, 2020

Copy link
Copy Markdown
Member Author

Added changelog and typo fix. There's still one remaining error (see, I did run the tests this time!) which I'll have to debug later.

Re: @mhvk's:

It is strange that CDDIS doesn't provide anonymous download via https.

Yeah I thought so too. It's possible there's some undocumented way but I figured it was safer to use what they support on their web site instead...

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you code broke the monkeypatching in test_data.py.

Comment thread CHANGES.rst Outdated
astropy.utils
^^^^^^^^^^^^^

- ``astropy.utils.data.download_file` now supports FTPS/FTP over TLS. (#9964)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is there a new feature entry? Also parenthesis should be square brackets.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

New feature entry because this really is a new feature of allowing FTPS for any use of download_file. And that's actually kinda a big deal. It's just we're forced to do that to enable the bug fix, otherwise I would have had this be 4.1.

(parenths was a typo - fixed in the rebased version)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have a precedence to add "new feature" in a bug fix change log? I'll let @bsipocz decide.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's fine. It's not an API change, but non user oriented utils feature that helps to resolve a bug.

We occasionally had utils new features in bugfix releases in the past, e.g. for the decorators. E.g. 2.0.12 or 1.3.1.

@eteq
eteq force-pushed the use-ftps-for-iers-cddis branch from f15fa79 to 1a8036b Compare February 26, 2020 16:56
Comment thread CHANGES.rst Outdated
astropy.utils
^^^^^^^^^^^^^

- The default IERS server has been updated to use the FTPS server hosted by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this has to come down to the 4.0.1 section, too

@bsipocz

bsipocz commented Feb 28, 2020

Copy link
Copy Markdown
Member

test failures are related

@bsipocz bsipocz modified the milestones: v4.0.1, v4.0.2 Mar 21, 2020
@pllim

pllim commented Apr 3, 2020

Copy link
Copy Markdown
Member

@eteq , do you have plans to wrap this up and address the monkeypatching failure?

@eteq
eteq force-pushed the use-ftps-for-iers-cddis branch from 1a8036b to 6bb2086 Compare April 24, 2020 19:16
@eteq
eteq force-pushed the use-ftps-for-iers-cddis branch from 0de9fce to 989d3ef Compare April 24, 2020 19:19
@eteq

eteq commented Apr 24, 2020 •

Copy link
Copy Markdown
Member Author

I think this is all set now, although @pllim and/or @bsipocz might want to give it a finally look. The monkeypatch is now working locally (we shall see if travis agrees...). I'm not especially proud of the monkeypatching solution, but hey a hack on a hack is elegant code right? 😉

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a minor typo left on change log, otherwise LGTM. Thanks!

Comment thread CHANGES.rst Outdated
Comment thread CHANGES.rst Outdated

@bsipocz bsipocz left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think doubling hacks are negating each other to become elegant, but agree that a hack that works here is more than good enough.

Co-Authored-By: P. L. Lim <[email protected]>
@bsipocz

bsipocz commented Apr 24, 2020

Copy link
Copy Markdown
Member

Added the changelog changes so this doesn't queue twice in CI

@bsipocz bsipocz added the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label Apr 24, 2020
@bsipocz
bsipocz merged commit 87e15ce into astropy:master Apr 24, 2020
@bsipocz

bsipocz commented Apr 24, 2020

Copy link
Copy Markdown
Member

Thanks @eteq!

bsipocz added a commit that referenced this pull request Apr 28, 2020
Use ftp w/ TLS for default IERS download (CDDIS)
bsipocz added a commit that referenced this pull request Apr 28, 2020
Use ftp w/ TLS for default IERS download (CDDIS)
Comment thread astropy/utils/data.py

req = urllib.request.Request(source_url, headers=http_headers)
with urllib.request.urlopen(req, timeout=timeout) as remote:
with urlopener.open(req, timeout=timeout) as remote:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@eteq - this breaks astroquery

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's discuss at #10227.

@aarchiba

Copy link
Copy Markdown
Contributor

#10437 now defaults to "if no-TLS fails retry with TLS"; I think special handling of IERS URLs could go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

utils.iers utils zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants