pdnd-python-client 0.1.3__tar.gz → 0.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pdnd-python-client
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: Client Python per autenticazione e interazione con le API della Piattaforma Digitale Nazionale Dati (PDND).
5
5
  Author-email: Francesco Loreti <francesco.loreti@isprambiente.it>
6
6
  License-Expression: MIT
@@ -10,7 +10,7 @@ class Config:
10
10
  # Questo metodo inizializza l'oggetto Config caricando la configurazione da un file JSON.
11
11
  def __init__(self, config_path: str = None, env: str ="produzione"):
12
12
  if config_path is None:
13
- config_path = os.path.join(os.path.dirname(__file__), "..", "configs", "sample.json")
13
+ config_path = os.path.join(os.path.dirname(__file__), "configs", "sample.json")
14
14
 
15
15
  self.env = env
16
16
  with open(config_path, "r") as f:
@@ -44,7 +44,7 @@ class JWTGenerator:
44
44
  self.aud = "auth.uat.interop.pagopa.it/client-assertion"
45
45
  return True
46
46
 
47
- def request_token(self) -> str:
47
+ def request_token(self) -> [str, int]:
48
48
  if not self.client_id:
49
49
  raise ValueError("Client ID non specificato nella configurazione.")
50
50
  if not self.privKeyPath:
@@ -68,6 +68,7 @@ class JWTGenerator:
68
68
  issued_at = int(time.time())
69
69
  expiration_time = issued_at + (43200 * 60) # 30 giorni
70
70
  jti = secrets.token_hex(16)
71
+ access_token = None
71
72
 
72
73
  payload = {
73
74
  "iss": self.issuer,
@@ -116,7 +117,7 @@ class JWTGenerator:
116
117
  response.raise_for_status() # Solleva eccezione per codici HTTP 4xx/5xx
117
118
  except requests.exceptions.RequestException as e:
118
119
  print(f"❌ Errore nella richiesta POST: {e}")
119
- return False
120
+ return None
120
121
 
121
122
  if response.status_code == 200:
122
123
  json_response = response.json()
@@ -141,8 +142,9 @@ class JWTGenerator:
141
142
  print(f"\n🔐 Access Token:\n{access_token}")
142
143
  print(f"\n⏰ Scadenza token (exp): {token_exp_str}")
143
144
 
144
- return access_token, token_exp_str
145
+ self.token = access_token
146
+ self.token_exp = self.token_exp or expiration_time
145
147
  else:
146
148
  raise Exception(f"⚠️ Nessun access token trovato:\n{json.dumps(json_response, indent=2)}")
147
149
 
148
- return access_token
150
+ return self.token, self.token_exp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pdnd-python-client
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: Client Python per autenticazione e interazione con le API della Piattaforma Digitale Nazionale Dati (PDND).
5
5
  Author-email: Francesco Loreti <francesco.loreti@isprambiente.it>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pdnd-python-client"
3
- version = "0.1.3"
3
+ version = "0.1.5"
4
4
  description = "Client Python per autenticazione e interazione con le API della Piattaforma Digitale Nazionale Dati (PDND)."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"