|
| 1 | +import json |
1 | 2 | from typing import Dict, Any, List, Optional |
| 3 | +import osbot_fast_api |
2 | 4 | from fastapi import Request, Response |
| 5 | +from osbot_utils.utils.Files import path_combine, file_exists |
3 | 6 | from osbot_fast_api.api.routes.Fast_API__Routes import Fast_API__Routes |
4 | 7 | from osbot_utils.type_safe.Type_Safe import Type_Safe |
5 | 8 | from osbot_utils.utils.Misc import random_guid |
@@ -32,77 +35,90 @@ class Cookies__Templates(Type_Safe): |
32 | 35 |
|
33 | 36 | class Routes__Admin__Cookies(Fast_API__Routes): # API routes for cookie management |
34 | 37 | tag = 'admin-cookies' |
35 | | - parent_app = None # Will be set by Admin_UI__Fast_API |
36 | | - |
37 | | - # Predefined cookie templates |
38 | | - COOKIE_TEMPLATES = [ # todo: move to .json file which can then be changed by the multiple implementations (especialy since by default we should not have have all this cookies set in the main Fast_API package) |
39 | | - { |
40 | | - "id": "openai", |
41 | | - "name": "OpenAI Configuration", |
42 | | - "description": "Cookies for OpenAI API integration", |
43 | | - "cookies": [ |
44 | | - { |
45 | | - "name": "openai-api-key", |
46 | | - "description": "OpenAI API Key", |
47 | | - "required": True, |
48 | | - "category": "llm", |
49 | | - "validator": "^sk-[a-zA-Z0-9]{48}$" |
50 | | - }, |
51 | | - { |
52 | | - "name": "openai-org-id", |
53 | | - "description": "OpenAI Organization ID", |
54 | | - "required": False, |
55 | | - "category": "llm" |
56 | | - } |
57 | | - ] |
58 | | - }, |
59 | | - { |
60 | | - "id": "anthropic", |
61 | | - "name": "Anthropic Configuration", |
62 | | - "description": "Cookies for Anthropic Claude API", |
63 | | - "cookies": [ |
64 | | - { |
65 | | - "name": "anthropic-api-key", |
66 | | - "description": "Anthropic API Key", |
67 | | - "required": True, |
68 | | - "category": "llm", |
69 | | - "validator": "^sk-ant-[a-zA-Z0-9-]{95}$" |
70 | | - } |
71 | | - ] |
72 | | - }, |
73 | | - { |
74 | | - "id": "groq", |
75 | | - "name": "Groq Configuration", |
76 | | - "description": "Cookies for Groq API", |
77 | | - "cookies": [ |
78 | | - { |
79 | | - "name": "groq-api-key", |
80 | | - "description": "Groq API Key", |
81 | | - "required": True, |
82 | | - "category": "llm" |
83 | | - } |
84 | | - ] |
85 | | - }, |
86 | | - { |
87 | | - "id": "auth", |
88 | | - "name": "Authentication", |
89 | | - "description": "Authentication cookies", |
90 | | - "cookies": [ |
91 | | - { |
92 | | - "name": "auth-token", |
93 | | - "description": "Authentication token", |
94 | | - "required": False, |
95 | | - "category": "auth" |
96 | | - }, |
97 | | - { |
98 | | - "name": "api-key", |
99 | | - "description": "API Key for protected endpoints", |
100 | | - "required": False, |
101 | | - "category": "auth" |
102 | | - } |
103 | | - ] |
104 | | - } |
105 | | - ] |
| 38 | + parent_app = None # Will be set by Admin_UI__Fast_API |
| 39 | + _templates : list = None |
| 40 | + |
| 41 | + @property |
| 42 | + def COOKIE_TEMPLATES(self): |
| 43 | + if self._templates is None: |
| 44 | + template_path = path_combine(osbot_fast_api.path, 'admin_ui/content/templates/cookies.json') |
| 45 | + if file_exists(template_path): |
| 46 | + with open(template_path, 'r') as f: |
| 47 | + data = json.load(f) |
| 48 | + self._templates = data.get('templates', []) |
| 49 | + else: |
| 50 | + self._templates = [] # Fallback to empty |
| 51 | + return self._templates |
| 52 | + |
| 53 | + # # Predefined cookie templates |
| 54 | + # COOKIE_TEMPLATES = [ # todo: move to .json file which can then be changed by the multiple implementations (especialy since by default we should not have have all this cookies set in the main Fast_API package) |
| 55 | + # { |
| 56 | + # "id": "openai", |
| 57 | + # "name": "OpenAI Configuration", |
| 58 | + # "description": "Cookies for OpenAI API integration", |
| 59 | + # "cookies": [ |
| 60 | + # { |
| 61 | + # "name": "openai-api-key", |
| 62 | + # "description": "OpenAI API Key", |
| 63 | + # "required": True, |
| 64 | + # "category": "llm", |
| 65 | + # "validator": "^sk-[a-zA-Z0-9]{48}$" |
| 66 | + # }, |
| 67 | + # { |
| 68 | + # "name": "openai-org-id", |
| 69 | + # "description": "OpenAI Organization ID", |
| 70 | + # "required": False, |
| 71 | + # "category": "llm" |
| 72 | + # } |
| 73 | + # ] |
| 74 | + # }, |
| 75 | + # { |
| 76 | + # "id": "anthropic", |
| 77 | + # "name": "Anthropic Configuration", |
| 78 | + # "description": "Cookies for Anthropic Claude API", |
| 79 | + # "cookies": [ |
| 80 | + # { |
| 81 | + # "name": "anthropic-api-key", |
| 82 | + # "description": "Anthropic API Key", |
| 83 | + # "required": True, |
| 84 | + # "category": "llm", |
| 85 | + # "validator": "^sk-ant-[a-zA-Z0-9-]{95}$" |
| 86 | + # } |
| 87 | + # ] |
| 88 | + # }, |
| 89 | + # { |
| 90 | + # "id": "groq", |
| 91 | + # "name": "Groq Configuration", |
| 92 | + # "description": "Cookies for Groq API", |
| 93 | + # "cookies": [ |
| 94 | + # { |
| 95 | + # "name": "groq-api-key", |
| 96 | + # "description": "Groq API Key", |
| 97 | + # "required": True, |
| 98 | + # "category": "llm" |
| 99 | + # } |
| 100 | + # ] |
| 101 | + # }, |
| 102 | + # { |
| 103 | + # "id": "auth", |
| 104 | + # "name": "Authentication", |
| 105 | + # "description": "Authentication cookies", |
| 106 | + # "cookies": [ |
| 107 | + # { |
| 108 | + # "name": "auth-token", |
| 109 | + # "description": "Authentication token", |
| 110 | + # "required": False, |
| 111 | + # "category": "auth" |
| 112 | + # }, |
| 113 | + # { |
| 114 | + # "name": "api-key", |
| 115 | + # "description": "API Key for protected endpoints", |
| 116 | + # "required": False, |
| 117 | + # "category": "auth" |
| 118 | + # } |
| 119 | + # ] |
| 120 | + # } |
| 121 | + # ] |
106 | 122 |
|
107 | 123 | def api__cookies_list(self, request: Request) -> List[Dict[str, Any]]: # Get list of all cookies with their current values |
108 | 124 | cookies = [] |
|
0 commit comments