-
Notifications
You must be signed in to change notification settings - Fork 3
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
Ingest settings #309
Merged
Merged
Ingest settings #309
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e85433c
created ingest settings class and new local api persistance mode
sherwoodf 7b4d1c1
fix local api user creation
sherwoodf 42f7175
update tests and fix using wrong settings field
sherwoodf 37dec65
updated readme
sherwoodf 03470d4
added api based test and updated find_bia_studies to use bia api to w…
sherwoodf f46599f
bia-ingest tests to use api in github ci
sherwoodf 4baa66b
update to comments and imports
sherwoodf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
bia_data_dir=Root of directory to save/read models from disk if using persistence_mode=disk | ||
bia_api_basepath=CREDENTIALS_FOR_LOCALHOST | ||
bia_api_username=CREDENTIALS_FOR_LOCALHOST | ||
bia_api_password=CREDENTIALS_FOR_LOCALHOST | ||
# bia_data_dir=Root of directory to save/read models from disk if using persistence_mode=disk | ||
local_bia_api_basepath="http://localhost:8080" | ||
local_bia_api_username="[email protected]" | ||
local_bia_api_password="test" | ||
# Do NOT edit this file directly to put in your credentials, as we do not want to the information to be committed to git | ||
# Insteaded create a copy called .env and update with your information if you want to use the actual api | ||
bia_api_basepath="https://wwwdev.ebi.ac.uk/bioimage-archive/api" | ||
bia_api_username=YOUR_CREDENTIALS_FOR_WWWDEV_API | ||
bia_api_password=YOUR_CREDENTIALS_FOR_WWWDEV_API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from bia_ingest.settings import Settings | ||
from bia_integrator_api.util import get_client_private | ||
from bia_integrator_api import Configuration, ApiClient, exceptions | ||
from bia_integrator_api.api import PrivateApi | ||
import bia_integrator_api.models as api_models | ||
import logging | ||
|
||
settings = Settings() | ||
|
||
logger = logging.getLogger("__main__." + __name__) | ||
|
||
|
||
def get_bia_api_client(): | ||
private_api_client = get_client_private( | ||
username=settings.bia_api_username, | ||
password=settings.bia_api_password, | ||
api_base_url=settings.bia_api_basepath, | ||
) | ||
return private_api_client | ||
|
||
|
||
def get_local_bia_api_client(): | ||
api_config = Configuration(host=settings.local_bia_api_basepath) | ||
private_api = PrivateApi(ApiClient(configuration=api_config)) | ||
try: | ||
access_token = private_api.login_for_access_token( | ||
username=settings.local_bia_api_username, | ||
password=settings.local_bia_api_password, | ||
) | ||
except exceptions.UnauthorizedException: | ||
private_api.register_user( | ||
api_models.BodyRegisterUser( | ||
email=settings.local_bia_api_username, | ||
password_plain=settings.local_bia_api_password, | ||
secret_token=settings.local_user_create_secret_token, | ||
) | ||
) | ||
access_token = private_api.login_for_access_token( | ||
username=settings.local_bia_api_username, | ||
password=settings.local_bia_api_password, | ||
) | ||
assert access_token | ||
api_config.access_token = access_token.access_token | ||
return private_api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from pathlib import Path | ||
import os | ||
import logging | ||
|
||
from pydantic import Field, AliasChoices | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
logger = logging.getLogger("__main__." + __name__) | ||
|
||
|
||
class Settings(BaseSettings): | ||
# Note env files overwrite one another in order of the list (last element overwrites previous ones) | ||
# Uses api settings to get user create token when testing locally. | ||
model_config = SettingsConfigDict( | ||
env_file=[ | ||
str(Path(__file__).parents[2] / "api" / ".env_compose"), | ||
str(Path(__file__).parents[1] / ".env_template"), | ||
str(Path(__file__).parents[1] / ".env"), | ||
], | ||
env_file_encoding="utf-8", | ||
case_sensitive=False, | ||
extra='ignore' | ||
) | ||
|
||
bia_data_dir: str = Field( | ||
str(Path(os.environ.get("HOME", "")) / ".cache" / "bia-integrator-data-sm") | ||
) | ||
local_bia_api_basepath: str = Field("http://localhost:8080") | ||
local_bia_api_username: str = Field("[email protected]") | ||
local_bia_api_password: str = Field("test") | ||
local_user_create_secret_token: str = Field( | ||
validation_alias=AliasChoices( | ||
"local_user_create_secret_token", "USER_CREATE_SECRET_TOKEN" | ||
) | ||
) | ||
bia_api_basepath: str = Field("") | ||
bia_api_username: str = Field("") | ||
bia_api_password: str = Field("") | ||
|
||
|
||
settings = Settings() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
typo?