Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"postCreateCommand": "pip install -e .",
"customizations": {
"vscode": {
// "settings": {
// },
"settings": {
"python.analysis.typeCheckingMode": "strict"
},
"extensions": [
"davidanson.vscode-markdownlint",
"redhat.vscode-yaml",
Expand Down
3 changes: 3 additions & 0 deletions codresh-support-package.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CF_API_KEY=
CF_URL=
USERPROFILE=
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ dependencies = [
"click>=8.1",
"kubernetes>=31.1",
"PyYAML>=6.0",
"requests>=2.32"
"requests>=2.32",
"python-dotenv>=1.1.1"
]

[project.scripts]
Expand Down
75 changes: 0 additions & 75 deletions src/cf_support/logic/codefresh.py

This file was deleted.

14 changes: 14 additions & 0 deletions src/cf_support/logic/controllers/account_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests


class AccountController:
def __init__(self, cf_creds: dict[str, dict[str, str]]) -> None:
self.base_url = cf_creds["base_url"]
self.auth_headers = cf_creds["headers"]

def get_runtimes(self):
response = requests.get(
f"{self.base_url}/runtime-environments",
headers=self.auth_headers["headers"], # type: ignore
)
return response.json()
48 changes: 48 additions & 0 deletions src/cf_support/logic/controllers/auth_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import yaml
import os


class AuthController:
def __init__(self, env_token: str | None, env_url: str | None) -> None:
self.env_token = env_token
self.env_url = env_url

def get_cf_credentials(
self,
) -> dict[str, dict[str, str] | str] | None:
env_token = self.env_token
env_url = self.env_url
cf_credentials: dict[str, dict[str, str] | str] | None = None

if env_token and env_url:
auth_header: dict[str, str] = {"Authorization": env_token}

cf_credentials = {
"headers": auth_header,
"base_url": f"{env_url}/api",
}

else:
config_path = (
f"{os.getenv('USERPROFILE')}/.cfconfig"
if os.name == "nt"
else f"{os.getenv('HOME')}/.cfconfig"
)

with open(config_path, "r") as config_file:
config = yaml.safe_load(config_file)

current_context = config["contexts"].get(config["current-context"])

if current_context:
context_token = current_context["token"]
context_url = current_context["url"]

if context_token and context_url:
auth_header = {"Authorization": context_token}
cf_credentials = {
"headers": auth_header,
"base_url": f"{context_url}/api",
}

return cf_credentials
14 changes: 14 additions & 0 deletions src/cf_support/logic/controllers/runtime_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests


class RuntimeController:
def __init__(self, cf_creds: dict[str, dict[str, str]]) -> None:
self.base_url = cf_creds["base_url"]
self.auth_headers = cf_creds["headers"]

def get_spec(self, runtime_name: str):
response = requests.get(
f"{self.base_url}/runtime-environments/{runtime_name}",
headers=self.auth_headers,
)
return response.json()
37 changes: 37 additions & 0 deletions src/cf_support/logic/controllers/system_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import requests


class SystemController:
def __init__(self, cf_creds: dict[str, dict[str, str]]) -> None:
self.base_url = cf_creds["base_url"]
self.auth_headers = cf_creds["headers"]

def get_all_accounts(self):
response = requests.get(
f"{self.base_url}/admin/accounts",
headers=self.auth_headers,
)
return response.json()

def get_all_runtimes(self):
response = requests.get(
f"{self.base_url}/admin/runtime-environments",
headers=self.auth_headers,
)
return response.json()

def get_feature_flags(self):
response = requests.get(
f"{self.base_url}/admin/features",
headers=self.auth_headers,
)
return response.json()

def get_total_users(self):
response = requests.get(
f"{self.base_url}/admin/user?limit=1&page=1",
headers=self.auth_headers,
)
users = response.json()

return {"totalUsers": users["total"]}
Empty file.
14 changes: 14 additions & 0 deletions src/cf_support/logic/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from dotenv import load_dotenv
import os

from .controllers.auth_controller import AuthController

load_dotenv()

def main():
env_token = os.getenv("CF_API_KEY")
env_url = os.getenv("CF_URL")
auth_controller = AuthController(env_token, env_url)

if __name__ == "__main__":
main()
Empty file.