From fcd30565ca12a0d3993e99d7b2b15523c7905ccc Mon Sep 17 00:00:00 2001 From: "Loic L." Date: Tue, 6 Feb 2024 14:25:47 +0100 Subject: [PATCH 01/12] first commit --- naas/secret.py | 134 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 4 deletions(-) diff --git a/naas/secret.py b/naas/secret.py index c2e86864..7f81cb9a 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -2,10 +2,81 @@ from .runner.env_var import n_env import pandas as pd import requests +import naas_python class Secret: - def list(self, raw=False): + + def __get_remote_secret(self, name: str): + try: + return naas_python.secret.get(name) + except: + print("Secret get failed") + return False + + def __create_remote_secret(self, name: str, value: str): + try: + naas_python.secret.create(name, value) + return True + # print("\nYour Secret has been moved to naas.ai 👌\n") + except: + print("Secret creation failed") + return False + + def __delete_remote_secret(self, name:str): + try: + naas_python.secret.delete(name=name) + return True + except: + print("Secret not found") + return False + + def __list_remote_secret(self): + try: + return naas_python.secret.list() + except: + print("Secret list failed") + return False + + def list(self): + local_secret = None + remote_secret_list = self.__list_remote_secret() + + # convert remote secret to a dataframe + remote_secret = pd.DataFrame(columns=['name', 'secret']) + for secret in remote_secret_list: + new_row = pd.DataFrame({'name': [secret.name], 'secret': [secret.value]}) + remote_secret = remote_secret.append(new_row, ignore_index=True) + + # local secret dataframe + local_secret = self.__old_list() + + if local_secret.empty: + return remote_secret + + local_secret = local_secret.drop("id", axis=1) + local_secret = local_secret.drop("lastUpdate", axis=1) + + merged_secrets_df = pd.merge(remote_secret, local_secret, how='outer', indicator=True) + + # If the secret exists locally AND in api.naas.ai, I remove the local version of the secret. + selected_secrets = merged_secrets_df[merged_secrets_df['_merge'] == "both"] + for index, row in selected_secrets.iterrows(): + self.__old_delete(row['name']) + + # If the secret exists locally and does not exists in api.naas.ai, I create it in api.naas.ai and I delete the local version. + selected_secrets = merged_secrets_df[merged_secrets_df['_merge'] == "right_only"] + for index, row in selected_secrets.iterrows(): + self.__create_remote_secret(name=row['name'], value=row['secret']) + + new_row = pd.DataFrame({'name': [row['name']], 'secret': [row['secret']]}) + remote_secret = remote_secret.append(new_row, ignore_index=True) + + self.__old_delete(row['name']) + + return remote_secret + + def __old_list(self, raw=False): try: r = requests.get(f"{n_env.api}/{t_secret}") r.raise_for_status() @@ -22,6 +93,12 @@ def list(self, raw=False): raise def add(self, name=None, secret=None): + if name is None or secret is None: + return ("Incomplete secret") + self.__create_remote_secret(name=name, value=secret) + self.__old_delete(name) + + def __old_add(self, name=None, secret=None): obj = {"name": name, "secret": secret, "status": t_add} try: r = requests.post(f"{n_env.api}/{t_secret}", json=obj) @@ -36,7 +113,50 @@ def add(self, name=None, secret=None): raise def get(self, name=None, default_value=None): - all_secret = self.list(True) + all_secret = self.__old_list(True) + local_secret = None + remote_secret = None + + # Find local_secret + for item in all_secret: + if name == item["name"]: + local_secret = item + break + + try: + remote_secret = self.__get_remote_secret(name=name) + except: + print("Try Again") + return None + + #if the secret exists on api.naas.ai + # AND exists locally, then I remove the local version. + if remote_secret is not None and local_secret is not None: + if remote_secret.name == local_secret["name"]: + self.__old_delete(name=local_secret["name"]) + return remote_secret.value + + #If the secret does not exists on api.naas.ai + #If the secret exists locally + #I take the local secret and create it on api.naas.ai. + #I delete the local version of the secret. + elif remote_secret is None and local_secret is not None: + self.__create_remote_secret(local_secret["name"], local_secret["secret"]) + secret = self.__get_remote_secret(local_secret["name"]) + self.__old_delete(name=local_secret["name"]) + return secret.value + + else: # local_secret is None + # If the secret exists on api.naas.ai + # I use that value + if remote_secret is not None : + return remote_secret.value + else: + print("Secret not found \n") + return default_value + + def __old_get(self, name=None, default_value=None): + all_secret = self.__old_list(True) secret_item = None for item in all_secret: if name == item["name"]: @@ -47,14 +167,20 @@ def get(self, name=None, default_value=None): return default_value def delete(self, name=None): + if name is None: + return ("Incomplete name") + self.__delete_remote_secret(name=name) + self.__old_delete(name + ) + def __old_delete(self, name=None): obj = {"name": name, "secret": "", "status": t_delete} try: r = requests.post(f"{n_env.api}/{t_secret}", json=obj) r.raise_for_status() - print("👌 Well done! Your Secret has been remove in production. \n") + # print("👌 Well done! Your Secret has been remove in production. \n") except requests.exceptions.ConnectionError as err: print(error_busy, err) raise except requests.exceptions.HTTPError as err: print(error_reject, err) - raise + raise \ No newline at end of file From 33088241b2132adb77792024e217039dbaab21a0 Mon Sep 17 00:00:00 2001 From: Maxime Jublou Date: Fri, 23 Feb 2024 18:03:58 +0100 Subject: [PATCH 02/12] fix: Few updates to make it more like the legacy --- docker-compose.yaml | 1 + naas/secret.py | 24 ++++++++++++------------ setup.py | 5 +++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 4f060631..532bdd9b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,6 +13,7 @@ services: ports: - 8888:8888 - 5000:5000 + - 38745:38745 volumes: - ~/.ssh:/home/ftp/.ssh - .:/home/ftp/naas diff --git a/naas/secret.py b/naas/secret.py index 7f81cb9a..0d4922fd 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -10,6 +10,8 @@ class Secret: def __get_remote_secret(self, name: str): try: return naas_python.secret.get(name) + except naas_python.domains.secret.SecretSchema.SecretNotFound: + return None except: print("Secret get failed") return False @@ -28,15 +30,15 @@ def __delete_remote_secret(self, name:str): naas_python.secret.delete(name=name) return True except: - print("Secret not found") + #print("Secret not found") return False def __list_remote_secret(self): - try: + # try: return naas_python.secret.list() - except: - print("Secret list failed") - return False + # except: + # print("Secret list failed") + # return False def list(self): local_secret = None @@ -123,11 +125,11 @@ def get(self, name=None, default_value=None): local_secret = item break - try: - remote_secret = self.__get_remote_secret(name=name) - except: - print("Try Again") - return None + # try: + remote_secret = self.__get_remote_secret(name=name) + # except: + # print("Try Again") + # return None #if the secret exists on api.naas.ai # AND exists locally, then I remove the local version. @@ -151,8 +153,6 @@ def get(self, name=None, default_value=None): # I use that value if remote_secret is not None : return remote_secret.value - else: - print("Secret not found \n") return default_value def __old_get(self, name=None, default_value=None): diff --git a/setup.py b/setup.py index ad05af35..524d63d7 100644 --- a/setup.py +++ b/setup.py @@ -74,10 +74,11 @@ "pymongo[srv]==3.11.3", "psycopg2-binary==2.9.1", "mprop==0.16.0", - "pydash==5.1.0", + "pydash==7.0.7", "pyvis==0.3.0", "rich", - "tzlocal==2.1" + "tzlocal==2.1", + "naas-python==1.2.*" ], classifiers=[ "Programming Language :: Python :: 3.9", From 884e02ffd7bafde8997d6414be0e07352a2b2593 Mon Sep 17 00:00:00 2001 From: "Loic L." Date: Mon, 26 Feb 2024 11:38:13 +0100 Subject: [PATCH 03/12] feat: create remote bulk secrets list --- naas/secret.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/naas/secret.py b/naas/secret.py index 0d4922fd..0a8cf499 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -24,6 +24,15 @@ def __create_remote_secret(self, name: str, value: str): except: print("Secret creation failed") return False + + def __create_remote_bulk_secret(self, secrets:str): + try: + naas_python.secret.bulk_create(secrets) + return True + # print("\nYour Secret has been moved to naas.ai 👌\n") + except: + print("Secret creation failed") + return False def __delete_remote_secret(self, name:str): try: @@ -53,6 +62,7 @@ def list(self): # local secret dataframe local_secret = self.__old_list() + if local_secret.empty: return remote_secret @@ -67,14 +77,21 @@ def list(self): self.__old_delete(row['name']) # If the secret exists locally and does not exists in api.naas.ai, I create it in api.naas.ai and I delete the local version. + secrets_list=[] selected_secrets = merged_secrets_df[merged_secrets_df['_merge'] == "right_only"] for index, row in selected_secrets.iterrows(): - self.__create_remote_secret(name=row['name'], value=row['secret']) + # self.__create_remote_secret(name=row['name'], value=row['secret']) + name = row['name'] + value = row['secret'] + new_secret = { "name": name, "value": value } + secrets_list.append(new_secret) + new_row = pd.DataFrame({'name': [row['name']], 'secret': [row['secret']]}) remote_secret = remote_secret.append(new_row, ignore_index=True) self.__old_delete(row['name']) + self.__create_remote_bulk_secret({"secrets":secrets_list}) return remote_secret From 695f01d52c657231e08186203a02b11281df1dd0 Mon Sep 17 00:00:00 2001 From: "Loic L." Date: Tue, 27 Feb 2024 09:11:12 +0100 Subject: [PATCH 04/12] move old func at the end --- naas/secret.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/naas/secret.py b/naas/secret.py index 0a8cf499..7336bb34 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -11,7 +11,8 @@ def __get_remote_secret(self, name: str): try: return naas_python.secret.get(name) except naas_python.domains.secret.SecretSchema.SecretNotFound: - return None + print("Secret not found") + return False except: print("Secret get failed") return False @@ -117,20 +118,6 @@ def add(self, name=None, secret=None): self.__create_remote_secret(name=name, value=secret) self.__old_delete(name) - def __old_add(self, name=None, secret=None): - obj = {"name": name, "secret": secret, "status": t_add} - try: - r = requests.post(f"{n_env.api}/{t_secret}", json=obj) - r.raise_for_status() - print("👌 Well done! Your Secret has been sent to production. \n") - print('PS: to remove the "Secret" feature, just replace .add by .delete') - except requests.exceptions.ConnectionError as err: - print(error_busy, err) - raise - except requests.exceptions.HTTPError as err: - print(error_reject, err) - raise - def get(self, name=None, default_value=None): all_secret = self.__old_list(True) local_secret = None @@ -198,6 +185,20 @@ def __old_delete(self, name=None): except requests.exceptions.ConnectionError as err: print(error_busy, err) raise + except requests.exceptions.HTTPError as err: + print(error_reject, err) + raise + + def __old_add(self, name=None, secret=None): + obj = {"name": name, "secret": secret, "status": t_add} + try: + r = requests.post(f"{n_env.api}/{t_secret}", json=obj) + r.raise_for_status() + print("👌 Well done! Your Secret has been sent to production. \n") + print('PS: to remove the "Secret" feature, just replace .add by .delete') + except requests.exceptions.ConnectionError as err: + print(error_busy, err) + raise except requests.exceptions.HTTPError as err: print(error_reject, err) raise \ No newline at end of file From 53ad603361625bd20306664bb0b54a7fbf994ee1 Mon Sep 17 00:00:00 2001 From: "Loic L." Date: Tue, 27 Feb 2024 09:32:12 +0100 Subject: [PATCH 05/12] check for naas api --- naas/secret.py | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/naas/secret.py b/naas/secret.py index 7336bb34..45b58f42 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -9,7 +9,11 @@ class Secret: def __get_remote_secret(self, name: str): try: - return naas_python.secret.get(name) + if self.__check_api() : + return naas_python.secret.get(name) + else : + print("API is not available") + return False except naas_python.domains.secret.SecretSchema.SecretNotFound: print("Secret not found") return False @@ -19,37 +23,62 @@ def __get_remote_secret(self, name: str): def __create_remote_secret(self, name: str, value: str): try: - naas_python.secret.create(name, value) - return True - # print("\nYour Secret has been moved to naas.ai 👌\n") + if self.__check_api() : + naas_python.secret.create(name, value) + return True + # print("\nYour Secret has been moved to naas.ai 👌\n") + else : + print("API is not available") + return False except: print("Secret creation failed") return False def __create_remote_bulk_secret(self, secrets:str): try: - naas_python.secret.bulk_create(secrets) - return True - # print("\nYour Secret has been moved to naas.ai 👌\n") + if self.__check_api() : + naas_python.secret.bulk_create(secrets) + return True + # print("\nYour Secret has been moved to naas.ai 👌\n") + else : + print("API is not available") + return False except: print("Secret creation failed") return False def __delete_remote_secret(self, name:str): try: - naas_python.secret.delete(name=name) - return True + if self.__check_api() : + naas_python.secret.delete(name=name) + return True + else : + print("API is not available") + return False except: #print("Secret not found") return False def __list_remote_secret(self): # try: + if self.__check_api() : return naas_python.secret.list() + else : + print("API is not available") + return False # except: # print("Secret list failed") # return False + def __check_api(self, url="https://api.naas.ai/"): + response = requests.get(url) + if response.status_code == 200: + data = response.json() + if 'status' in data and data['status'] == 'ok': + return True + else: + return False + def list(self): local_secret = None remote_secret_list = self.__list_remote_secret() From 603ef35b4928621fc7e40e9609cd60a472ca4369 Mon Sep 17 00:00:00 2001 From: "Loic L." Date: Tue, 27 Feb 2024 15:33:43 +0100 Subject: [PATCH 06/12] fix: better error message --- naas/secret.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/naas/secret.py b/naas/secret.py index 45b58f42..3f3bc26e 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -12,13 +12,12 @@ def __get_remote_secret(self, name: str): if self.__check_api() : return naas_python.secret.get(name) else : - print("API is not available") + print("Naas.api service request failed. Please retry again in few seconds.") return False except naas_python.domains.secret.SecretSchema.SecretNotFound: - print("Secret not found") return False except: - print("Secret get failed") + print("Secret get failed. Please retry again in few seconds.") return False def __create_remote_secret(self, name: str, value: str): @@ -28,10 +27,10 @@ def __create_remote_secret(self, name: str, value: str): return True # print("\nYour Secret has been moved to naas.ai 👌\n") else : - print("API is not available") + print("Naas.api service request failed. Please retry again in few seconds.") return False except: - print("Secret creation failed") + print("Secret creation failed. Please retry again in few seconds.") return False def __create_remote_bulk_secret(self, secrets:str): @@ -41,10 +40,10 @@ def __create_remote_bulk_secret(self, secrets:str): return True # print("\nYour Secret has been moved to naas.ai 👌\n") else : - print("API is not available") + print("Naas.api service request failed. Please retry again in few seconds.") return False except: - print("Secret creation failed") + print("Secret creation failed. Please retry again in few seconds.") return False def __delete_remote_secret(self, name:str): @@ -53,7 +52,7 @@ def __delete_remote_secret(self, name:str): naas_python.secret.delete(name=name) return True else : - print("API is not available") + print("Naas.api service request failed. Please retry again in few seconds.") return False except: #print("Secret not found") @@ -64,7 +63,7 @@ def __list_remote_secret(self): if self.__check_api() : return naas_python.secret.list() else : - print("API is not available") + print("Naas.api service request failed. Please retry again in few seconds.") return False # except: # print("Secret list failed") From eec29e6dab685289b028415d21f83a9d2c3c0268 Mon Sep 17 00:00:00 2001 From: Florent <48032461+FlorentLvr@users.noreply.github.com> Date: Mon, 18 Mar 2024 08:52:25 +0100 Subject: [PATCH 07/12] fix: lint secret.py --- naas/secret.py | 162 ++++++++++++++++++++++++++----------------------- 1 file changed, 86 insertions(+), 76 deletions(-) diff --git a/naas/secret.py b/naas/secret.py index 3f3bc26e..76b7381e 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -6,124 +6,134 @@ class Secret: - + def __get_remote_secret(self, name: str): try: - if self.__check_api() : + if self.__check_api(): return naas_python.secret.get(name) - else : - print("Naas.api service request failed. Please retry again in few seconds.") + else: + print( + "Naas.api service request failed. Please retry again in few seconds." + ) return False except naas_python.domains.secret.SecretSchema.SecretNotFound: return False except: print("Secret get failed. Please retry again in few seconds.") return False - + def __create_remote_secret(self, name: str, value: str): try: - if self.__check_api() : + if self.__check_api(): naas_python.secret.create(name, value) return True # print("\nYour Secret has been moved to naas.ai 👌\n") - else : - print("Naas.api service request failed. Please retry again in few seconds.") - return False + else: + print( + "Naas.api service request failed. Please retry again in few seconds." + ) + return False except: print("Secret creation failed. Please retry again in few seconds.") return False - - def __create_remote_bulk_secret(self, secrets:str): + + def __create_remote_bulk_secret(self, secrets: str): try: - if self.__check_api() : + if self.__check_api(): naas_python.secret.bulk_create(secrets) return True # print("\nYour Secret has been moved to naas.ai 👌\n") - else : - print("Naas.api service request failed. Please retry again in few seconds.") - return False + else: + print( + "Naas.api service request failed. Please retry again in few seconds." + ) + return False except: print("Secret creation failed. Please retry again in few seconds.") return False - - def __delete_remote_secret(self, name:str): + + def __delete_remote_secret(self, name: str): try: - if self.__check_api() : + if self.__check_api(): naas_python.secret.delete(name=name) return True - else : - print("Naas.api service request failed. Please retry again in few seconds.") - return False + else: + print( + "Naas.api service request failed. Please retry again in few seconds." + ) + return False except: - #print("Secret not found") + # print("Secret not found") return False - + def __list_remote_secret(self): # try: - if self.__check_api() : + if self.__check_api(): return naas_python.secret.list() - else : + else: print("Naas.api service request failed. Please retry again in few seconds.") - return False + return False # except: # print("Secret list failed") # return False - + def __check_api(self, url="https://api.naas.ai/"): response = requests.get(url) if response.status_code == 200: data = response.json() - if 'status' in data and data['status'] == 'ok': + if "status" in data and data["status"] == "ok": return True else: return False - + def list(self): local_secret = None remote_secret_list = self.__list_remote_secret() - + # convert remote secret to a dataframe - remote_secret = pd.DataFrame(columns=['name', 'secret']) + remote_secret = pd.DataFrame(columns=["name", "secret"]) for secret in remote_secret_list: - new_row = pd.DataFrame({'name': [secret.name], 'secret': [secret.value]}) + new_row = pd.DataFrame({"name": [secret.name], "secret": [secret.value]}) remote_secret = remote_secret.append(new_row, ignore_index=True) - + # local secret dataframe local_secret = self.__old_list() - - + if local_secret.empty: return remote_secret local_secret = local_secret.drop("id", axis=1) local_secret = local_secret.drop("lastUpdate", axis=1) - - merged_secrets_df = pd.merge(remote_secret, local_secret, how='outer', indicator=True) - + + merged_secrets_df = pd.merge( + remote_secret, local_secret, how="outer", indicator=True + ) + # If the secret exists locally AND in api.naas.ai, I remove the local version of the secret. - selected_secrets = merged_secrets_df[merged_secrets_df['_merge'] == "both"] + selected_secrets = merged_secrets_df[merged_secrets_df["_merge"] == "both"] for index, row in selected_secrets.iterrows(): - self.__old_delete(row['name']) - + self.__old_delete(row["name"]) + # If the secret exists locally and does not exists in api.naas.ai, I create it in api.naas.ai and I delete the local version. - secrets_list=[] - selected_secrets = merged_secrets_df[merged_secrets_df['_merge'] == "right_only"] + secrets_list = [] + selected_secrets = merged_secrets_df[ + merged_secrets_df["_merge"] == "right_only" + ] for index, row in selected_secrets.iterrows(): # self.__create_remote_secret(name=row['name'], value=row['secret']) - name = row['name'] - value = row['secret'] - new_secret = { "name": name, "value": value } + name = row["name"] + value = row["secret"] + new_secret = {"name": name, "value": value} secrets_list.append(new_secret) - - - new_row = pd.DataFrame({'name': [row['name']], 'secret': [row['secret']]}) + + new_row = pd.DataFrame({"name": [row["name"]], "secret": [row["secret"]]}) remote_secret = remote_secret.append(new_row, ignore_index=True) - - self.__old_delete(row['name']) - self.__create_remote_bulk_secret({"secrets":secrets_list}) - + + self.__old_delete(row["name"]) + self.__create_remote_bulk_secret({"secrets": secrets_list}) + return remote_secret - + def __old_list(self, raw=False): try: r = requests.get(f"{n_env.api}/{t_secret}") @@ -142,7 +152,7 @@ def __old_list(self, raw=False): def add(self, name=None, secret=None): if name is None or secret is None: - return ("Incomplete secret") + return "Incomplete secret" self.__create_remote_secret(name=name, value=secret) self.__old_delete(name) @@ -150,43 +160,43 @@ def get(self, name=None, default_value=None): all_secret = self.__old_list(True) local_secret = None remote_secret = None - + # Find local_secret for item in all_secret: if name == item["name"]: local_secret = item - break - + break + # try: remote_secret = self.__get_remote_secret(name=name) # except: # print("Try Again") # return None - - #if the secret exists on api.naas.ai - # AND exists locally, then I remove the local version. + + # if the secret exists on api.naas.ai + # AND exists locally, then I remove the local version. if remote_secret is not None and local_secret is not None: - if remote_secret.name == local_secret["name"]: + if remote_secret.name == local_secret["name"]: self.__old_delete(name=local_secret["name"]) return remote_secret.value - - #If the secret does not exists on api.naas.ai - #If the secret exists locally - #I take the local secret and create it on api.naas.ai. - #I delete the local version of the secret. + + # If the secret does not exists on api.naas.ai + # If the secret exists locally + # I take the local secret and create it on api.naas.ai. + # I delete the local version of the secret. elif remote_secret is None and local_secret is not None: self.__create_remote_secret(local_secret["name"], local_secret["secret"]) secret = self.__get_remote_secret(local_secret["name"]) self.__old_delete(name=local_secret["name"]) return secret.value - - else: # local_secret is None - # If the secret exists on api.naas.ai + + else: # local_secret is None + # If the secret exists on api.naas.ai # I use that value - if remote_secret is not None : + if remote_secret is not None: return remote_secret.value return default_value - + def __old_get(self, name=None, default_value=None): all_secret = self.__old_list(True) secret_item = None @@ -200,10 +210,10 @@ def __old_get(self, name=None, default_value=None): def delete(self, name=None): if name is None: - return ("Incomplete name") + return "Incomplete name" self.__delete_remote_secret(name=name) - self.__old_delete(name - ) + self.__old_delete(name) + def __old_delete(self, name=None): obj = {"name": name, "secret": "", "status": t_delete} try: @@ -229,4 +239,4 @@ def __old_add(self, name=None, secret=None): raise except requests.exceptions.HTTPError as err: print(error_reject, err) - raise \ No newline at end of file + raise From 301bad2fbb2c46788ddc28636fcc85d981e1eda0 Mon Sep 17 00:00:00 2001 From: Maxime Jublou Date: Mon, 18 Mar 2024 09:47:30 +0100 Subject: [PATCH 08/12] fix: Bump naas-python --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 524d63d7..c6dc0641 100644 --- a/setup.py +++ b/setup.py @@ -78,7 +78,7 @@ "pyvis==0.3.0", "rich", "tzlocal==2.1", - "naas-python==1.2.*" + "naas-python==1.3.0" ], classifiers=[ "Programming Language :: Python :: 3.9", From adb6bc03d5f66b610347b6baa9386cd126333aaf Mon Sep 17 00:00:00 2001 From: "Loic L." Date: Mon, 18 Mar 2024 11:03:45 +0100 Subject: [PATCH 09/12] fix: get secret return None --- naas/secret.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/naas/secret.py b/naas/secret.py index 76b7381e..f12ee882 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -15,12 +15,13 @@ def __get_remote_secret(self, name: str): print( "Naas.api service request failed. Please retry again in few seconds." ) - return False + return None except naas_python.domains.secret.SecretSchema.SecretNotFound: - return False + print("Secret not found.") + return None except: print("Secret get failed. Please retry again in few seconds.") - return False + return None def __create_remote_secret(self, name: str, value: str): try: @@ -169,6 +170,7 @@ def get(self, name=None, default_value=None): # try: remote_secret = self.__get_remote_secret(name=name) + # except: # print("Try Again") # return None From ffc9dc07e351b1c80430c6264e0ff345f262ba62 Mon Sep 17 00:00:00 2001 From: Maxime Jublou Date: Mon, 18 Mar 2024 14:49:35 +0100 Subject: [PATCH 10/12] fix: Bump ci python version to 3.9 --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 066ebaa5..587f9281 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: '3.8' + python-version: '3.9' - uses: actions/cache@v2 with: path: ~/.cache/pip From 0057547cd183ab5fca0d9a4d591217c7337795fe Mon Sep 17 00:00:00 2001 From: Maxime Jublou Date: Mon, 18 Mar 2024 15:51:53 +0100 Subject: [PATCH 11/12] fix: Add make prod-build --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 6367f187..ba230a9c 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ run: sh: docker-compose exec naas /bin/bash +prod-build: + docker build . -t naas:latest + build: docker-compose down docker-compose build From 0072bee8457da68227557d2e5542ffc76a0b3642 Mon Sep 17 00:00:00 2001 From: Maxime Jublou Date: Mon, 18 Mar 2024 18:33:01 +0100 Subject: [PATCH 12/12] fix: linter --- naas/secret.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/naas/secret.py b/naas/secret.py index f12ee882..3b6ecd13 100644 --- a/naas/secret.py +++ b/naas/secret.py @@ -19,6 +19,7 @@ def __get_remote_secret(self, name: str): except naas_python.domains.secret.SecretSchema.SecretNotFound: print("Secret not found.") return None + #noqa: E722 except: print("Secret get failed. Please retry again in few seconds.") return None @@ -34,6 +35,7 @@ def __create_remote_secret(self, name: str, value: str): "Naas.api service request failed. Please retry again in few seconds." ) return False + #noqa: E722 except: print("Secret creation failed. Please retry again in few seconds.") return False @@ -49,6 +51,7 @@ def __create_remote_bulk_secret(self, secrets: str): "Naas.api service request failed. Please retry again in few seconds." ) return False + #noqa: E722 except: print("Secret creation failed. Please retry again in few seconds.") return False @@ -63,6 +66,7 @@ def __delete_remote_secret(self, name: str): "Naas.api service request failed. Please retry again in few seconds." ) return False + #noqa: E722 except: # print("Secret not found") return False