Skip to content

Commit

Permalink
added ability to specify workspace_id
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkumpe committed Jun 1, 2024
1 parent 96eefa9 commit 4c2f729
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions infisical_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,29 @@ class infisical_api: # pylint: disable=invalid-name
def __init__(
self,
service_token: str,
infisical_url: str = "https://infisical.com",
infisical_url: str = "https://app.infisical.com",
workspace_id: str = "dynamic",
):
self.service_token = service_token
self.infisical_url = infisical_url
self.workspace_id = workspace_id

def get_secret(
self, secret_name: str, environment: str = "prod", path: str = "/"
) -> dict: # pylint: disable=no-self-argument
"""Retrieve Secret"""
if self.service_token == "":
raise PermissionError("Please provide a valid service_token")

try:
if self.workspace_id == "dynamic":
workspace_id = self.get_workspace_id()
else:
workspace_id = self.workspace_id
response = requests.get(
url=f"{self.infisical_url}/api/v3/secrets/raw/{secret_name}",
params={
"workspaceId": self.get_workspace_id(),
"workspaceId": workspace_id,
"environment": environment,
"secretPath": path,
},
Expand All @@ -49,16 +58,18 @@ def get_workspace_id(self) -> str:
},
timeout=15,
)
print(response)
data = json.loads(response.text)
return data["workspace"]
except requests.exceptions.RequestException:
print("Failed to get Workspace ID")


class convert_to_dot_notation(dict):
"""
Access dictionary attributes via dot notation
"""

__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
__delattr__ = dict.__delitem__
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "infisical_api"
version = "1.0.0"
version = "1.0.1a"
license = "GPL-3.0"
authors = [
{ name="Justin Kumpe", email="[email protected]" },
Expand Down

0 comments on commit 4c2f729

Please sign in to comment.