Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 14, 2023
1 parent 0ef555e commit 37a9248
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 35 deletions.
7 changes: 3 additions & 4 deletions frontend/glideinFrontendElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __init__(self, parent_pid, work_dir, group_name, action):
self.removal_margin = int(self.elementDescript.element_data["RemovalMargin"])

# Default bahavior: Use factory proxies unless configure overrides it
self.x509_proxy_plugin: glideinFrontendPlugins.CredentialsPlugin = None # type: ignore
self.x509_proxy_plugin: glideinFrontendPlugins.CredentialsPlugin = None # type: ignore

# If not None, this is a request for removal of glideins only (i.e. do not ask for more)
self.request_removal_wtype = None
Expand Down Expand Up @@ -222,8 +222,7 @@ def configure(self):
if not proxy_plugins.get(self.elementDescript.merged_data["ProxySelectionPlugin"]):
logSupport.log.warning(
"Invalid ProxySelectionPlugin '%s', supported plugins are %s"
% (self.elementDescript.merged_data["ProxySelectionPlugin"],
list(proxy_plugins.keys()))
% (self.elementDescript.merged_data["ProxySelectionPlugin"], list(proxy_plugins.keys()))
)
return 1
self.x509_proxy_plugin = proxy_plugins[self.elementDescript.merged_data["ProxySelectionPlugin"]](
Expand Down Expand Up @@ -874,7 +873,7 @@ def iterate_one(self):

if stkn:
if generator_name:
for cred_el in advertizer.descript_obj.x509_proxies_plugin.cred_list: # type: ignore
for cred_el in advertizer.descript_obj.x509_proxies_plugin.cred_list: # type: ignore
if cred_el.filename == generator_name:
cred_el.generated_data = stkn
break
Expand Down
16 changes: 7 additions & 9 deletions frontend/glideinFrontendInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,7 @@ def createGlobalAdvertizeWorkFile(self, factory_pool):
glidein_params_to_encrypt[cred_el.id] = cred_el.credential.string
if hasattr(cred_el, "security_class"):
# Convert the sec class to a string so the Factory can interpret the value correctly
glidein_params_to_encrypt["SecurityClass" + cred_el.id] = str(
cred_el.security_class
)
glidein_params_to_encrypt["SecurityClass" + cred_el.id] = str(cred_el.security_class)

key_obj = None
if factory_pool in self.global_key:
Expand Down Expand Up @@ -1163,7 +1161,7 @@ def createAdvertizeWorkFile(self, factory_pool, params_obj, key_obj=None, file_i
nr_credentials = len(credentials_with_requests)
if nr_credentials == 0:
raise NoCredentialException

auth_set = factory_auth.match([t.credential for t in credentials_with_requests])
if not auth_set:
logSupport.log.warning("No credentials match for factory pool %s, not advertising request" % factory_pool)
Expand All @@ -1172,7 +1170,7 @@ def createAdvertizeWorkFile(self, factory_pool, params_obj, key_obj=None, file_i
if file_id_cache is None:
# create a local cache, if no global provided
file_id_cache = CredentialCache()

for name, value in descript_obj.x509_proxies_plugin.params_dict.items():
params_obj.glidein_params_to_encrypt[name.value] = value

Expand Down Expand Up @@ -1201,9 +1199,7 @@ def createAdvertizeWorkFile(self, factory_pool, params_obj, key_obj=None, file_i

# TODO: REFACTOR THIS BLOCK!!!
if not credential_el.credential.valid():
logSupport.log.warning(
f"Credential file {credential_el.credential.path} has expired, skipping..."
)
logSupport.log.warning(f"Credential file {credential_el.credential.path} has expired, skipping...")
continue

if params_obj.request_name in self.factory_constraint:
Expand All @@ -1226,7 +1222,9 @@ def createAdvertizeWorkFile(self, factory_pool, params_obj, key_obj=None, file_i

glidein_params_to_encrypt[credential_el.credential.classad_attribute] = credential_el.id
if isinstance(credential_el.credential, CredentialPair):
glidein_params_to_encrypt[credential_el.credential.private_credential.classad_attribute] = credential_el.private_id
glidein_params_to_encrypt[
credential_el.credential.private_credential.classad_attribute
] = credential_el.private_id

# TODO: Is this still needed?
# # Process additional information of the credential
Expand Down
9 changes: 5 additions & 4 deletions frontend/glideinFrontendPlugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class CredentialsPlugin(ABC):

def __init__(self, config_dir: str, request_bundle: RequestBundle):
self.request_bundle = request_bundle

@property
def cred_list(self) -> List[RequestCredential]:
return list(self.request_bundle.credentials.values())

@property
def params_dict(self) -> Mapping[ParameterName, Parameter]:
return self.request_bundle.parameters
Expand All @@ -78,7 +78,7 @@ def get_required_classad_attributes(self):

def update_usermap(self, condorq_dict, condorq_dict_types, status_dict, status_dict_types):
return

@abstractmethod
def get_credentials(self, params_obj=None, credential_type=None, trust_domain=None):
pass
Expand Down Expand Up @@ -121,6 +121,7 @@ def get_credentials(self, params_obj=None, credential_type=None, trust_domain=No
### Proxy plugins are deprecated and should not be used ###
###########################################################


class ProxyFirst:
"""This plugin always returns the first proxy
Useful when there is only one proxy or for testing
Expand Down Expand Up @@ -652,7 +653,7 @@ def list2ilist(lst):
return out


# TODO: Deprecate in favor of createRequestBundle
# TODO: Deprecate in favor of createRequestBundle
def createCredentialList(elementDescript):
"""Creates a list of Credentials for a proxy plugin"""
request_bundle = credentials.RequestBundle()
Expand Down
34 changes: 19 additions & 15 deletions lib/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def save_to_file(
compress: bool = False,
data_pattern: Optional[bytes] = None,
overwrite: bool = True,
continue_if_no_path = False,
continue_if_no_path=False,
) -> None:
if not self.string:
raise CredentialError("Credential not initialized")
Expand Down Expand Up @@ -240,7 +240,9 @@ def save_to_file(
try:
shutil.copy2(path, f"{path}.old")
except FileNotFoundError as err:
logSupport.log.debug(f"Tried to backup credential at {path} but file does not exist: {err}. Probably first time saving credential.")
logSupport.log.debug(
f"Tried to backup credential at {path} but file does not exist: {err}. Probably first time saving credential."
)
os.replace(fd.name, path)
except OSError as err:
raise CredentialError(f"Could not save credential to {path}: {err}") from err
Expand Down Expand Up @@ -268,10 +270,10 @@ def __init__(
credential_class = self.__class__.__bases__[1]
super(credential_class, self).__init__(string, path) # type: ignore
self.private_credential = credential_class(private_string, private_path)

def renew(self) -> None:
try:
self.__renew__() # type: ignore
self.__renew__() # type: ignore
self.private_credential.__renew__()
except NotImplementedError:
pass
Expand Down Expand Up @@ -322,28 +324,28 @@ def __init__(self, string: Optional[bytes] = None, path: Optional[str] = None) -
self._string = string
self.path = None
self.load(string)

def __renew__(self) -> None:
self.load(self._string)

@property
def _payload(self) -> Optional[Credential]:
return self.decode(self._string) if self._string else None

@property
def string(self) -> Optional[bytes]:
return self._payload.string if self._payload else None

@staticmethod
def decode(string: bytes) -> Credential:
generator = load_generator(string.decode())
return create_credential(generator.generate())

def valid(self) -> bool:
if self._payload:
return self._payload.valid()
return False

def load_from_file(self, path: str) -> None:
raise CredentialError("Cannot load CredentialGenerator from file")

Expand All @@ -359,7 +361,7 @@ def load(self, string: Optional[bytes] = None, path: Optional[str] = None) -> No

class Token(Credential[Mapping]):
cred_type = CredentialType.TOKEN
classad_attribute = "ScitokenId" # TODO: We might want to change this name to "TokenId" in the future
classad_attribute = "ScitokenId" # TODO: We might want to change this name to "TokenId" in the future

@property
def scope(self) -> Optional[str]:
Expand Down Expand Up @@ -468,7 +470,7 @@ def extract_sym_key(self, enc_sym_key) -> symCrypto.AutoSymKey:
# @staticmethod
# def decode(string: bytes) -> bytes:
# return string

# def valid(self) -> bool:
# return True

Expand Down Expand Up @@ -529,7 +531,7 @@ def __str__(self) -> str:
def id(self) -> str:
if not str(self.credential):
raise CredentialError("Credential not initialized")

return hash_nc(f"{str(self.credential)}{self.purpose}{self.trust_domain}{self.security_class}", 8)

@property
Expand All @@ -538,7 +540,9 @@ def private_id(self) -> str:
raise CredentialError("Credential must be a CredentialPair")
if not self.credential.private_credential.string:
raise CredentialError("Private credential not initialized")
return hash_nc(f"{self.credential.private_credential.string.decode()}{self.purpose}{self.trust_domain}{self.security_class}")
return hash_nc(
f"{self.credential.private_credential.string.decode()}{self.purpose}{self.trust_domain}{self.security_class}"
)

def add_usage_details(self, req_idle=0, req_max_run=0):
self.req_idle = req_idle
Expand All @@ -560,7 +564,7 @@ def __init__(self):
def add_credential(self, credential, id=None, purpose=None, trust_domain=None, security_class=None):
rbCredential = RequestCredential(credential, purpose, trust_domain, security_class)
self.credentials[id or rbCredential.id] = rbCredential

def add_parameter(self, name: str, value: str):
self.parameters.add(Parameter(ParameterName.from_string(name), value))

Expand Down Expand Up @@ -663,7 +667,7 @@ def __str__(self) -> str:
def load(self, auth_method: str):
for group in auth_method.split(";"):
if group.lower() == "any":
self._requirements.append([]) # type: ignore
self._requirements.append([]) # type: ignore
else:
options = []
for option in group.split(","):
Expand Down
5 changes: 2 additions & 3 deletions lib/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class Generator(ABC, Generic[T]):
def __str__(self):
return f"{self.__class__.__name__}()"

def __repr__(self):
return str(self)

Expand Down Expand Up @@ -74,10 +74,9 @@ def export_generator(generator: Generator):


class RoundRobinGenerator(Generator[T]):

def __init__(self, items: List[T]) -> None:
self._items = items

def generate(self) -> T:
item = self._items.pop()
self._items.insert(0, item)
Expand Down

0 comments on commit 37a9248

Please sign in to comment.