Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
enolfc committed Oct 16, 2023
1 parent 2c3df85 commit 5087d48
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 29 deletions.
9 changes: 3 additions & 6 deletions cloud-info/cloud_info_catchall/config_generator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Discover projects for cloud-info-povider and generate configuration
Takes its own configuration from env variables:
SECRETS_FILE: yaml file with the secrets to access shares
The yaml includes as many credentials as wanted in 2 formats
SECRETS_FILE: yaml file with the secrets to access shares
The yaml includes as many credentials as wanted in 2 formats
```
---
secret_name:
Expand All @@ -20,16 +20,13 @@
TOKEN_URL: URL to refresh tokens
OS_AUTH_URL, OS_IDENTITY_PROVIDER, OS_PROTOCOL: OpenStack endpoint config
SITE_NAME: site name
"""

import logging
import os

import fedcloudclient.endpoint as fedcli
import yaml
from cloud_info_provider.auth_refreshers.oidc_refresh import OidcRefreshToken

from cloud_info_catchall.share_discovery import (
AccessTokenShareDiscovery,
Expand Down Expand Up @@ -79,7 +76,7 @@ def main():
"token_url": os.environ["TOKEN_URL"],
"vo_dir": os.environ.get("VO_SECRETS_PATH", ""),
}
secrets = read_secrets(checkin_secrets_file)
secrets = read_secrets(secrets_file)
shares_config = generate_shares_config(config, secrets)
print(yaml.dump(shares_config))

Expand Down
2 changes: 1 addition & 1 deletion cloud-info/cloud_info_catchall/share_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def config_shares(self, shares, access_token):
pass

def get_token(self):
raise NotImplemented
raise NotImplementedError


class RefresherShareDiscovery(ShareDiscovery):
Expand Down
4 changes: 2 additions & 2 deletions cloud-info/cloud_info_catchall/test_config_generator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
""" Tests for the config generator """

from collections import defaultdict
import unittest
from unittest.mock import call, mock_open, patch, MagicMock
from collections import defaultdict
from unittest.mock import patch

import cloud_info_catchall.config_generator as cg

Expand Down
23 changes: 6 additions & 17 deletions cloud-info/cloud_info_catchall/test_share_discovery.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Tests for the Share discovery """

import unittest
from unittest.mock import call, mock_open, patch, MagicMock
from unittest.mock import MagicMock, call, mock_open, patch

from cloud_info_catchall.share_discovery import (
AccessTokenShareDiscovery,
Expand All @@ -20,7 +20,7 @@ class ShareDiscoveryTest(unittest.TestCase):
"token_url": "https://aai.egi.eu",
"vo_dir": "vo",
}
SECRET = {}
SECRET = {"foo": "bar"}

def setUp(self):
self.discoverer = self.DISCOVERER_CLASS(self.CONFIG, self.SECRET)
Expand Down Expand Up @@ -99,28 +99,17 @@ def test_token_refresh(self, m):

@patch("os.makedirs")
def config_shares(self, m_makedirs):
vos = {
"foobar.eu": {
"client_id": "bar",
"client_secret": "foo",
"refresh_token": "foobar",
},
"baz.eu": {
"client_id": "barz",
"refresh_token": "foobarz",
},
}
shares = [
{"foobar.eu": {"auth": {"project_id": "id1"}}},
{"baz.eu": {"auth": {"project_id": "id2"}}},
]
with patch("builtins.open", mock_open()) as m_file:
s = d.config_shares({"s1": vos["foobar.eu"], "s2": vos["baz.eu"]}, "token")
self.discoverer.config_shares(shares, "token")
handle = m_file()
for vo in vos:
for field in vos[vo]:
for vo in shares:
for field in self.SECRET:
m_file.assert_any_call(f"vo/{vo}/{field}", "w+"),
handle.write.assert_any_call(vos[vo][field])
handle.write.assert_any_call(self.SECRET[field])
m_makedirs.assert_has_calls(
[call("vo/foobar.eu", exist_ok=True), call("vo/baz.eu", exist_ok=True)]
)
Expand Down
6 changes: 3 additions & 3 deletions cloud-info/cloud_info_catchall/token_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"""

import calendar
from datetime import datetime, timezone
import json
import logging
import os
from datetime import datetime, timezone

import jwt
import requests
import yaml
import jwt

# Default OIDC URL for Check-in
CHECKIN_OIDC_URL = "https://aai.egi.eu/auth/realms/egi/.well-known/openid-configuration"
Expand Down Expand Up @@ -55,7 +55,7 @@ def valid_token(token, oidc_config, min_time):
headers = jwt.get_unverified_header(token)
kid = headers["kid"]
key = public_keys[kid]
payload = jwt.decode(token, key=public_keys[kid], algorithms=[headers["alg"]])
payload = jwt.decode(token, key=key, algorithms=[headers["alg"]])
# this comes from JWT documentation
# https://pyjwt.readthedocs.io/en/stable/usage.html#expiration-time-claim-exp
now = calendar.timegm(datetime.now(tz=timezone.utc).utctimetuple())
Expand Down

0 comments on commit 5087d48

Please sign in to comment.