more work on bitwarden
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
pierre geeraert
2026-06-24 11:42:53 +01:00
parent 024736c887
commit 57d2559ad3
2 changed files with 51 additions and 67 deletions
+30 -46
View File
@@ -6,6 +6,8 @@ from bitwarden_sdk import BitwardenClient, DeviceType, client_settings_from_dict
class bitwardenUtils(): class bitwardenUtils():
#documentation
#https://github.com/external-secrets/bitwarden-sdk-server
state_path = "/tmp/state_file.txt" state_path = "/tmp/state_file.txt"
client = BitwardenClient( client = BitwardenClient(
client_settings_from_dict( client_settings_from_dict(
@@ -18,6 +20,10 @@ class bitwardenUtils():
) )
) )
def verbose(self):
logging.basicConfig(level=logging.DEBUG)
def __init__(self, access_token, organization_id): def __init__(self, access_token, organization_id):
self.access_token = access_token self.access_token = access_token
self.organization_id = organization_id self.organization_id = organization_id
@@ -39,45 +45,11 @@ class bitwardenUtils():
def generate_strong_password(self): def generate_strong_password(self):
# Note: using the generator does not require authentication with a server # Note: using the generator does not require authentication with a server
return client.generators().generate() # using default params return self.client.generators().generate() # using default params
def create_secret(self,project_id,secret_name,secret_value,description="description"):
#documentation secret = self.client.secrets().create(
#https://github.com/external-secrets/bitwarden-sdk-server self.organization_id,
#credentials
#organization_id = ""
#access_token = ""
state_path = "/tmp/state_file.txt"
# Create the BitwardenClient, which is used to interact with the SDK
client = BitwardenClient(
client_settings_from_dict(
{
"apiUrl": os.getenv("API_URL", "https://bitwarden.tryton.geeraert.eu/api"),
"deviceType": DeviceType.SDK,
"identityUrl": os.getenv("IDENTITY_URL", "https://bitwarden.tryton.geeraert.eu/identity"),
"userAgent": "Python",
}
)
)
# Add some logging & set the org id
logging.basicConfig(level=logging.DEBUG)
client.auth().login_access_token(access_token, state_path)
# -- Example Project Commands --
def create_project(project_name):
project = client.projects().create(organization_id, project_name)
return project.data.id
def create_secret(project_id,secret_name,secret_value,description="description"):
secret = client.secrets().create(
organization_id,
secret_name, secret_name,
secret_value, secret_value,
description, description,
@@ -85,29 +57,41 @@ def create_secret(project_id,secret_name,secret_value,description="description")
) )
return secret.data.id return secret.data.id
def read_value_secret(secret_id):
return client.secrets().get_by_ids([secret_id]).data.data[0].value
def read_value_secrets(list_secret_id): def read_value_secret(self,secret_id):
return self.client.secrets().get_by_ids([secret_id]).data.data[0].value
def read_value_secrets(self,list_secret_id):
if not(isinstance(list_secret_id, list)):
print("this is not a list")
return 1
list_secret_value = [] list_secret_value = []
for secret_value in client.secrets().get_by_ids(list_secret_id).data.data: for secret_value in self.client.secrets().get_by_ids(list_secret_id).data.data:
list_secret_value.append(secret_value.value) list_secret_value.append(secret_value.value)
return list_secret_value return list_secret_value
def delete_secrets(list_secret_id): def delete_secrets(self,list_secret_id):
if not(isinstance(list_secret_id, list)):
print("this is not a list")
return 1
try: try:
client.secrets().delete(list_secret_id) self.client.secrets().delete(list_secret_id)
status=0 status=0
except: except:
print("Cannot delete the secrets") print("Cannot delete the secrets")
status=1 status=1
return status return status
def delete_projects(list_project_id): def delete_projects(self,list_project_id):
if not(isinstance(list_project_id, list)):
print("this is not a list")
return 1
try: try:
client.projects().delete(list_project_id) self.client.projects().delete(list_project_id)
status=0 status=0
except: except:
print("Cannot delete the project") print("Cannot delete the project")
status=1 status=1
return status return status