Skip to content

Commit 86425b6

Browse files
yasithdevlahirujayathilake
authored andcommitted
cleanup imports, fix bugs found by type checker
1 parent c327341 commit 86425b6

25 files changed

+320
-312
lines changed

airavata-api/airavata-client-sdks/airavata-python-sdk/airavata_experiments/airavata.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import logging
1818
from pathlib import Path
1919
from typing import Literal, NamedTuple
20+
21+
from airavata_sdk.transport.settings import APIServerSettings
2022
from .sftp import SFTPConnector
2123
import time
2224
import warnings
@@ -161,7 +163,8 @@ def __init__(self, access_token: str, config_file: str = "settings.ini"):
161163
self.access_token = access_token
162164
self.settings = Settings(config_file)
163165
# load api server settings and create client
164-
self.api_server_client = APIServerClient(api_server_settings=self.settings)
166+
api_server_settings = APIServerSettings(config_file)
167+
self.api_server_client = APIServerClient(api_server_settings=api_server_settings)
165168
# load gateway settings
166169
gateway_id = self.default_gateway_id()
167170
self.airavata_token = self.__airavata_token__(self.access_token, gateway_id)

airavata-api/airavata-client-sdks/airavata-python-sdk/airavata_sdk/clients/api_server_client.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import configparser
1818
import logging
19+
from typing import Optional
1920

20-
from airavata.api.Airavata import Client
2121
from airavata_sdk.transport import utils
2222
from airavata_sdk.transport.settings import APIServerSettings
2323

@@ -27,16 +27,16 @@
2727

2828
class APIServerClient(object):
2929

30-
def __init__(self, configuration_file_location=None, api_server_settings=None):
31-
if configuration_file_location is not None:
32-
self.api_server_settings = APIServerSettings(configuration_file_location)
30+
def __init__(self, configuration_file_location: Optional[str] = None, api_server_settings: Optional[APIServerSettings] = None):
31+
if api_server_settings is not None:
32+
self.settings = api_server_settings
33+
elif configuration_file_location is not None:
34+
self.settings = APIServerSettings(configuration_file_location)
3335
self._load_settings(configuration_file_location)
34-
elif api_server_settings is not None:
35-
self.api_server_settings = api_server_settings
36-
self.client: Client = utils.initialize_api_client_pool(
37-
self.api_server_settings.API_SERVER_HOST,
38-
self.api_server_settings.API_SERVER_PORT,
39-
self.api_server_settings.API_SERVER_SECURE,
36+
self.client = utils.initialize_api_client_pool(
37+
self.settings.API_SERVER_HOST,
38+
self.settings.API_SERVER_PORT,
39+
self.settings.API_SERVER_SECURE,
4040
)
4141
# expose the needed functions
4242
self.is_user_exists = self.client.isUserExists
@@ -231,10 +231,10 @@ def __init__(self, configuration_file_location=None, api_server_settings=None):
231231
self.remove_parsing_template = self.client.removeParsingTemplate
232232
self.list_all_parsing_templates = self.client.listAllParsingTemplates
233233

234-
def _load_settings(self, configuration_file_location):
234+
def _load_settings(self, configuration_file_location: Optional[str]):
235235
if configuration_file_location is not None:
236236
config = configparser.ConfigParser()
237237
config.read(configuration_file_location)
238-
self.api_server_settings.API_SERVER_HOST = config.get('APIServer', 'API_HOST')
239-
self.api_server_settings.API_SERVER_PORT = config.getint('APIServer', 'API_PORT')
240-
self.api_server_settings.API_SERVER_SECURE = config.getboolean('APIServer', 'API_SECURE')
238+
self.settings.API_SERVER_HOST = config.get('APIServer', 'API_HOST')
239+
self.settings.API_SERVER_PORT = config.getint('APIServer', 'API_PORT')
240+
self.settings.API_SERVER_SECURE = config.getboolean('APIServer', 'API_SECURE')

airavata-api/airavata-client-sdks/airavata-python-sdk/airavata_sdk/clients/credential_store_client.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import configparser
1818
import logging
19+
from typing import Optional
1920

20-
from airavata.api.credential.store.CredentialStoreService import Client
2121
from airavata_sdk.transport import utils
2222
from airavata_sdk.transport.settings import CredentialStoreServerSettings
2323

@@ -27,25 +27,21 @@
2727

2828
class CredentialStoreClient(object):
2929

30-
def __init__(self, configuration_file_location=None):
31-
self.credential_store_server_settings = CredentialStoreServerSettings(configuration_file_location)
30+
def __init__(self, configuration_file_location: Optional[str] = None):
31+
self.settings = CredentialStoreServerSettings(configuration_file_location)
3232
self._load_settings(configuration_file_location)
33-
self.client: Client = utils.initialize_credential_store_client(
34-
self.credential_store_server_settings.CREDENTIAL_STORE_API_HOST,
35-
self.credential_store_server_settings.CREDENTIAL_STORE_API_PORT,
36-
self.credential_store_server_settings.CREDENTIAL_STORE_API_SECURE
33+
self.client = utils.initialize_credential_store_client(
34+
self.settings.CREDENTIAL_STORE_API_HOST,
35+
self.settings.CREDENTIAL_STORE_API_PORT,
36+
self.settings.CREDENTIAL_STORE_API_SECURE,
3737
)
3838
# expose the needed functions
3939
self.get_SSH_credential = self.client.getSSHCredential
4040

41-
def _load_settings(self, configuration_file_location):
41+
def _load_settings(self, configuration_file_location: Optional[str]):
4242
if configuration_file_location is not None:
4343
config = configparser.ConfigParser()
4444
config.read(configuration_file_location)
45-
self.credential_store_server_settings.CREDENTIAL_STORE_API_HOST = config.get('CredentialStoreServer',
46-
'CREDENTIAL_STORE_API_HOST')
47-
self.credential_store_server_settings.CREDENTIAL_STORE_API_PORT = config.getint('CredentialStoreServer',
48-
'CREDENTIAL_STORE_API_PORT')
49-
self.credential_store_server_settings.CREDENTIAL_STORE_API_SECURE = config.getboolean(
50-
'CredentialStoreServer',
51-
'CREDENTIAL_STORE_API_SECURE')
45+
self.settings.CREDENTIAL_STORE_API_HOST = config.get('CredentialStoreServer', 'CREDENTIAL_STORE_API_HOST')
46+
self.settings.CREDENTIAL_STORE_API_PORT = config.getint('CredentialStoreServer', 'CREDENTIAL_STORE_API_PORT')
47+
self.settings.CREDENTIAL_STORE_API_SECURE = config.getboolean('CredentialStoreServer', 'CREDENTIAL_STORE_API_SECURE')

airavata-api/airavata-client-sdks/airavata-python-sdk/airavata_sdk/clients/file_handling_client.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616

1717
import logging
18+
from typing import Optional
1819

1920
import paramiko
2021
from paramiko import SSHClient
@@ -38,16 +39,16 @@
3839

3940
class FileHandler(object):
4041

41-
def __init__(self, host, port, username, passphrase, privateKeyFilePath):
42+
def __init__(self, host: str, port: int, username: str, passphrase: Optional[str], pkey: Optional[paramiko.RSAKey]):
4243
self.host = host
4344
self.port = port
4445
self.username = username
4546
self.password = passphrase
46-
self.filePath = privateKeyFilePath
47+
self.pkey = None
4748

4849
def upload_file(self, files, remote_path, recursive, preserve_item):
4950
try:
50-
ssh.connect(self.host, self.port, self.username, passphrase=self.password, pkey=self.filePath)
51+
ssh.connect(self.host, self.port, self.username, passphrase=self.password, pkey=self.pkey)
5152
transport = ssh.get_transport()
5253
assert transport is not None
5354
with SCPClient(transport) as scp:
@@ -57,7 +58,7 @@ def upload_file(self, files, remote_path, recursive, preserve_item):
5758

5859
def download_file(self, remote_path, local_path, recursive, preserve_item):
5960
try:
60-
ssh.connect(self.host, self.port, self.username, passphrase=self.password, pkey=self.filePath)
61+
ssh.connect(self.host, self.port, self.username, passphrase=self.password, pkey=self.pkey)
6162
transport = ssh.get_transport()
6263
assert transport is not None
6364
with SCPClient(transport) as scp:

airavata-api/airavata-client-sdks/airavata-python-sdk/airavata_sdk/clients/group_manager_client.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import configparser
1818
import logging
19+
from typing import Optional
1920

20-
from airavata.service.profile.groupmanager.cpi.GroupManagerService import Client
2121
from airavata_sdk.transport import utils
2222
from airavata_sdk.transport.settings import ProfileServerSettings
2323

@@ -35,13 +35,13 @@
3535

3636
class GroupManagerClient(object):
3737

38-
def __init__(self, configuration_file_location=None):
39-
self.group_manager_settings = ProfileServerSettings(configuration_file_location)
38+
def __init__(self, configuration_file_location: Optional[str] = None):
39+
self.settings = ProfileServerSettings(configuration_file_location)
4040
self._load_settings(configuration_file_location)
41-
self.client: Client = utils.initialize_group_manager_client(
42-
self.group_manager_settings.PROFILE_SERVICE_HOST,
43-
self.group_manager_settings.PROFILE_SERVICE_PORT,
44-
self.group_manager_settings.PROFILE_SERVICE_SECURE
41+
self.client = utils.initialize_group_manager_client(
42+
self.settings.PROFILE_SERVICE_HOST,
43+
self.settings.PROFILE_SERVICE_PORT,
44+
self.settings.PROFILE_SERVICE_SECURE,
4545
)
4646
# expose the needed functions
4747
self.get_api_version = self.client.getAPIVersion
@@ -59,11 +59,10 @@ def __init__(self, configuration_file_location=None):
5959
self.has_admin_access = self.client.hasAdminAccess
6060
self.has_owner_access = self.client.hasOwnerAccess
6161

62-
def _load_settings(self, configuration_file_location):
62+
def _load_settings(self, configuration_file_location: Optional[str]):
6363
if configuration_file_location is not None:
6464
config = configparser.ConfigParser()
6565
config.read(configuration_file_location)
66-
self.group_manager_settings.PROFILE_SERVICE_HOST = config.get('ProfileServer', 'PROFILE_SERVICE_HOST')
67-
self.group_manager_settings.PROFILE_SERVICE_PORT = config.getint('ProfileServer', 'PROFILE_SERVICE_PORT')
68-
self.group_manager_settings.PROFILE_SERVICE_SECURE = config.getboolean('ProfileServer',
69-
'PROFILE_SERVICE_SECURE')
66+
self.settings.PROFILE_SERVICE_HOST = config.get('ProfileServer', 'PROFILE_SERVICE_HOST')
67+
self.settings.PROFILE_SERVICE_PORT = config.getint('ProfileServer', 'PROFILE_SERVICE_PORT')
68+
self.settings.PROFILE_SERVICE_SECURE = config.getboolean('ProfileServer', 'PROFILE_SERVICE_SECURE')

airavata-api/airavata-client-sdks/airavata-python-sdk/airavata_sdk/clients/iam_admin_client.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import configparser
1818
import logging
19+
from typing import Optional
1920

20-
from airavata.service.profile.iam.admin.services.cpi.IamAdminServices import Client
2121
from airavata_sdk.transport import utils
2222
from airavata_sdk.transport.settings import ProfileServerSettings
2323

@@ -35,13 +35,14 @@
3535

3636
class IAMAdminClient(object):
3737

38-
def __init__(self, configuration_file_location=None):
39-
self.iam_admin_settings = ProfileServerSettings(configuration_file_location)
38+
def __init__(self, configuration_file_location: Optional[str] = None):
39+
self.settings = ProfileServerSettings(configuration_file_location)
4040
self._load_settings(configuration_file_location)
41-
self.client: Client = utils.initialize_iam_admin_client(
42-
self.iam_admin_settings.PROFILE_SERVICE_HOST,
43-
self.iam_admin_settings.PROFILE_SERVICE_PORT,
44-
self.iam_admin_settings.PROFILE_SERVICE_SECURE)
41+
self.client = utils.initialize_iam_admin_client(
42+
self.settings.PROFILE_SERVICE_HOST,
43+
self.settings.PROFILE_SERVICE_PORT,
44+
self.settings.PROFILE_SERVICE_SECURE,
45+
)
4546
# expose the needed functions
4647
self.set_up_gateway = self.client.setUpGateway
4748
self.is_username_available = self.client.isUsernameAvailable
@@ -59,12 +60,10 @@ def __init__(self, configuration_file_location=None):
5960
self.remove_role_from_user = self.client.removeRoleFromUser
6061
self.get_users_with_role = self.client.getUsersWithRole
6162

62-
def _load_settings(self, configuration_file_location):
63+
def _load_settings(self, configuration_file_location: Optional[str]):
6364
if configuration_file_location is not None:
6465
config = configparser.ConfigParser()
6566
config.read(configuration_file_location)
66-
self.iam_admin_settings.PROFILE_SERVICE_HOST = config.get('ProfileServer', 'PROFILE_SERVICE_HOST')
67-
self.iam_admin_settings.PROFILE_SERVICE_PORT = config.getint('ProfileServer', 'PROFILE_SERVICE_PORT')
68-
self.iam_admin_settings.PROFILE_SERVICE_SECURE = config.getboolean('ProfileServer',
69-
'PROFILE_SERVICE_SECURE')
70-
67+
self.settings.PROFILE_SERVICE_HOST = config.get('ProfileServer', 'PROFILE_SERVICE_HOST')
68+
self.settings.PROFILE_SERVICE_PORT = config.getint('ProfileServer', 'PROFILE_SERVICE_PORT')
69+
self.settings.PROFILE_SERVICE_SECURE = config.getboolean('ProfileServer', 'PROFILE_SERVICE_SECURE')

airavata-api/airavata-client-sdks/airavata-python-sdk/airavata_sdk/clients/keycloak_token_fetcher.py

+42-41
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import configparser
1818
import os
19+
from typing import Optional
1920

2021
from oauthlib.oauth2 import LegacyApplicationClient
2122
from requests_oauthlib import OAuth2Session
@@ -27,70 +28,70 @@
2728

2829
class Authenticator(object):
2930

30-
def __init__(self, configuration_file_location=None):
31-
self.keycloak_settings = KeycloakServerSettings(configuration_file_location)
31+
def __init__(self, configuration_file_location: Optional[str] = None):
32+
self.settings = KeycloakServerSettings(configuration_file_location)
3233
self._load_settings(configuration_file_location)
3334

34-
def get_token_and_user_info_password_flow(self, username, password, gateway_id):
35-
client_id = self.keycloak_settings.CLIENT_ID
36-
client_secret = self.keycloak_settings.CLIENT_SECRET
37-
token_url = self.keycloak_settings.TOKEN_URL
38-
userinfo_url = self.keycloak_settings.USER_INFO_URL
39-
verify_ssl = self.keycloak_settings.VERIFY_SSL
40-
oauth2_session = OAuth2Session(client=LegacyApplicationClient(
41-
client_id=client_id))
42-
token = oauth2_session.fetch_token(token_url=token_url,
43-
username=username,
44-
password=password,
45-
client_id=client_id,
46-
client_secret=client_secret,
47-
verify=verify_ssl)
48-
35+
def get_token_and_user_info_password_flow(self, username: str, password: str, gateway_id: str):
36+
client_id = self.settings.CLIENT_ID
37+
client_secret = self.settings.CLIENT_SECRET
38+
token_url = self.settings.TOKEN_URL
39+
# userinfo_url = self.keycloak_settings.USER_INFO_URL
40+
verify_ssl = self.settings.VERIFY_SSL
41+
oauth2_session = OAuth2Session(client=LegacyApplicationClient(client_id=client_id))
42+
token = oauth2_session.fetch_token(
43+
token_url=token_url,
44+
username=username,
45+
password=password,
46+
client_id=client_id,
47+
client_secret=client_secret,
48+
verify=verify_ssl,
49+
)
4950
claimsMap = {
5051
"userName": username,
5152
"gatewayID": gateway_id
5253
}
5354
return AuthzToken(accessToken=token['access_token'], claimsMap=claimsMap)
5455

55-
def get_airavata_authz_token(self, username, token, gateway_id):
56+
def get_airavata_authz_token(self, username: str, token: str, gateway_id: str):
5657
claimsMap = {
5758
"userName": username,
5859
"gatewayID": gateway_id
5960
}
6061
return AuthzToken(accessToken=token, claimsMap=claimsMap)
6162

62-
def get_authorize_url(self, username, password, gateway_id):
63-
client_id = self.keycloak_settings.CLIENT_ID
64-
client_secret = self.keycloak_settings.CLIENT_SECRET
65-
token_url = self.keycloak_settings.TOKEN_URL
66-
userinfo_url = self.keycloak_settings.USER_INFO_URL
67-
verify_ssl = self.keycloak_settings.VERIFY_SSL
68-
oauth2_session = OAuth2Session(client=LegacyApplicationClient(
69-
client_id=client_id))
70-
token = oauth2_session.fetch_token(token_url=token_url,
71-
username=username,
72-
password=password,
73-
client_id=client_id,
74-
client_secret=client_secret,
75-
verify=verify_ssl)
76-
63+
def get_authorize_url(self, username: str, password: str, gateway_id: str):
64+
client_id = self.settings.CLIENT_ID
65+
client_secret = self.settings.CLIENT_SECRET
66+
token_url = self.settings.TOKEN_URL
67+
# userinfo_url = self.keycloak_settings.USER_INFO_URL
68+
verify_ssl = self.settings.VERIFY_SSL
69+
oauth2_session = OAuth2Session(client=LegacyApplicationClient(client_id=client_id))
70+
token = oauth2_session.fetch_token(
71+
token_url=token_url,
72+
username=username,
73+
password=password,
74+
client_id=client_id,
75+
client_secret=client_secret,
76+
verify=verify_ssl,
77+
)
7778
claimsMap = {
7879
"userName": username,
7980
"gatewayID": gateway_id
8081
}
8182
return AuthzToken(accessToken=token['access_token'], claimsMap=claimsMap)
8283

8384
def authenticate_with_auth_code(self):
84-
print("Click on Login URI ", self.keycloak_settings.LOGIN_DESKTOP_URI)
85-
return self.keycloak_settings.LOGIN_DESKTOP_URI
85+
print("Click on Login URI ", self.settings.LOGIN_DESKTOP_URI)
86+
return self.settings.LOGIN_DESKTOP_URI
8687

87-
def _load_settings(self, configuration_file_location):
88+
def _load_settings(self, configuration_file_location: Optional[str]):
8889
if configuration_file_location is not None:
8990
config = configparser.ConfigParser()
9091
config.read(configuration_file_location)
9192
# self.keycloak_settings.KEYCLOAK_CA_CERTIFICATE = config.get("KeycloakServer", 'CERTIFICATE_FILE_PATH')
92-
self.keycloak_settings.CLIENT_ID = config.get('KeycloakServer', 'CLIENT_ID')
93-
self.keycloak_settings.CLIENT_SECRET = config.get('KeycloakServer', 'CLIENT_SECRET')
94-
self.keycloak_settings.TOKEN_URL = config.get('KeycloakServer', 'TOKEN_URL')
95-
self.keycloak_settings.USER_INFO_URL = config.get('KeycloakServer', 'USER_INFO_URL')
96-
self.keycloak_settings.VERIFY_SSL = config.getboolean('KeycloakServer', 'VERIFY_SSL')
93+
self.settings.CLIENT_ID = config.get('KeycloakServer', 'CLIENT_ID')
94+
self.settings.CLIENT_SECRET = config.get('KeycloakServer', 'CLIENT_SECRET')
95+
self.settings.TOKEN_URL = config.get('KeycloakServer', 'TOKEN_URL')
96+
self.settings.USER_INFO_URL = config.get('KeycloakServer', 'USER_INFO_URL')
97+
self.settings.VERIFY_SSL = config.getboolean('KeycloakServer', 'VERIFY_SSL')

airavata-api/airavata-client-sdks/airavata-python-sdk/airavata_sdk/clients/sftp_file_handling_client.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, host, port, username, password):
4343
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
4444

4545

46-
def upload_files(self, local_path, project_name, exprement_id):
46+
def upload_files(self, local_path: str, project_name: str, exprement_id: str):
4747
project_name = project_name.replace(" ", "_")
4848
time = datetime.now().strftime('%Y-%m-%d %H:%M:%S').replace(" ", "_")
4949
time = time.replace(":", "_")
@@ -72,8 +72,7 @@ def upload_files(self, local_path, project_name, exprement_id):
7272
transport.close()
7373
return pathsuffix
7474

75-
def download_files(self, local_path, remote_path):
76-
75+
def download_files(self, local_path: str, remote_path: str):
7776
self.ssh.connect(self.host, self.port, self.username, password = self.password)
7877
transport = self.ssh.get_transport()
7978
assert transport is not None
@@ -82,6 +81,5 @@ def download_files(self, local_path, remote_path):
8281
self.ssh.close()
8382

8483
@staticmethod
85-
def uploading_info(uploaded_file_size, total_file_size):
86-
logging.info('uploaded_file_size : {} total_file_size : {}'.
87-
format(uploaded_file_size, total_file_size))
84+
def uploading_info(uploaded_file_size: str, total_file_size: str):
85+
logging.info('uploaded_file_size : {} total_file_size : {}'.format(uploaded_file_size, total_file_size))

0 commit comments

Comments
 (0)