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

Adding credentials file support #157

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,7 @@ _html/
data/
results/
example_model.pth

# Common location to stash personal or notebook example config
fibad_config.toml
credentials.ini
30 changes: 26 additions & 4 deletions src/fibad/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from threading import Thread
from typing import Optional, Union

import toml
from astropy.io import fits
from astropy.table import Table, hstack

Expand Down Expand Up @@ -49,12 +50,33 @@

logger.info("Download command Start")

username = self.config["download"]["username"]
password = self.config["download"]["password"]
credentials_file = self.config["download"]["credentials_file"]
credentials_file_path = Path(credentials_file) if credentials_file else None

Check warning on line 54 in src/fibad/download.py

View check run for this annotation

Codecov / codecov/patch

src/fibad/download.py#L53-L54

Added lines #L53 - L54 were not covered by tests

credentials_configured = bool(

Check warning on line 56 in src/fibad/download.py

View check run for this annotation

Codecov / codecov/patch

src/fibad/download.py#L56

Added line #L56 was not covered by tests
self.config["download"]["username"] or self.config["download"]["password"]
)

if credentials_file_path.exists() and credentials_configured:
msg = f"Credentials file {credentials_file} found in addition to username/password in your "
msg += "fibad config. Credentials must be provided in only one place."
raise RuntimeError(msg)

Check warning on line 63 in src/fibad/download.py

View check run for this annotation

Codecov / codecov/patch

src/fibad/download.py#L60-L63

Added lines #L60 - L63 were not covered by tests

if credentials_file_path.exists():
credentials = toml.load(credentials_file_path)
username = credentials.get("username", False)
password = credentials.get("password", False)

Check warning on line 68 in src/fibad/download.py

View check run for this annotation

Codecov / codecov/patch

src/fibad/download.py#L65-L68

Added lines #L65 - L68 were not covered by tests
else:
username = self.config["download"]["username"]
password = self.config["download"]["password"]

Check warning on line 71 in src/fibad/download.py

View check run for this annotation

Codecov / codecov/patch

src/fibad/download.py#L70-L71

Added lines #L70 - L71 were not covered by tests

if not username or not password:
msg = "Please define a username and password to the HSC cutout service in your fibad config "
msg += "file to use the downloader. Accounts can be created at the following url: \n"
msg = "Please define a username and password to the HSC cutout service in credentials "
msg += f"file: {credentials_file} to use the downloader. The format of the credentials file is:\n"
msg += '\nusername = "<your username>"\n'
msg += 'password = "<your password>"\n\n'
msg += "Please do not check your credentials into git or other version control systems.\n"
msg += "Accounts can be created at the following url: \n"

Check warning on line 79 in src/fibad/download.py

View check run for this annotation

Codecov / codecov/patch

src/fibad/download.py#L74-L79

Added lines #L74 - L79 were not covered by tests
msg += " https://hsc-release.mtk.nao.ac.jp/datasearch/new_user/new "
raise RuntimeError(msg)

Expand Down
13 changes: 13 additions & 0 deletions src/fibad/fibad_default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@ sh = "22asec"
filter = ["HSC-G", "HSC-R", "HSC-I", "HSC-Z", "HSC-Y"]
type = "coadd"
rerun = "pdr3_wide"

# Credentials for the downloader. Either provide username/password in a fibad config file
# or with a credentials.ini file. The format for credentials.ini is as follows:
#
# username = "<your username>"
# password = "<your password>"
#
# It is preferred to use a credentials.ini file to avoid sensitive user credentials being
# committed to source control systems like git.
username = false
password = false
# Location of the credentials.ini file. Defaults to credentials.ini in the current directory
# but can be configured to a common location for batch processing.
credentials_file = "./credentials.ini"

num_sources = -1 # Values below 1 here indicate all sources in the catalog will be downloaded
offset = 0
concurrent_connections = 4
Expand Down
Loading