Skip to content

Commit 158bb3a

Browse files
fix: credential form shows expected keys per auth type, fix db stats
Credential ekleme formunda auth tipine gore beklenen key isimleri dropdown olarak sunuluyor (bearer: token, basic: username/password, api_key: api_key, oauth2: client_id/client_secret). Settings sayfasindaki Database Statistics artik gercek tablo sayilarini gosteriyor. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b94cb51 commit 158bb3a

3 files changed

Lines changed: 103 additions & 9 deletions

File tree

schema-monitor/api/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ async def settings_page(request: Request) -> HTMLResponse:
294294

295295
if storage is not None:
296296
settings_data = await storage.get_all_settings()
297+
# Tablo sayılarını da ekle
298+
table_counts = await storage.get_table_counts()
299+
for key, value in table_counts.items():
300+
settings_data[key] = str(value)
297301

298302
return templates.TemplateResponse(
299303
"settings.html",

schema-monitor/core/store/sqlite_store.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,31 @@ async def get_all_settings(self) -> dict[str, str]:
793793
cursor = conn.execute("SELECT key, value FROM settings ORDER BY key")
794794
return {row["key"]: row["value"] for row in cursor.fetchall()}
795795

796+
async def get_table_counts(self) -> dict[str, int]:
797+
"""Tablo bazlı kayıt sayılarını getir (Settings sayfası için).
798+
799+
Returns:
800+
Tablo adı -> kayıt sayısı dict'i
801+
"""
802+
conn = self._get_connection()
803+
804+
counts: dict[str, int] = {}
805+
tables = {
806+
"provider_count": "providers",
807+
"endpoint_count": "endpoints",
808+
"snapshot_count": "snapshots",
809+
"change_count": "changes",
810+
"alert_config_count": "alert_channels",
811+
}
812+
for key, table in tables.items():
813+
try:
814+
cursor = conn.execute(f"SELECT COUNT(*) as cnt FROM {table}") # noqa: S608
815+
counts[key] = cursor.fetchone()["cnt"]
816+
except Exception:
817+
counts[key] = 0
818+
819+
return counts
820+
796821
# === İstatistikler ===
797822

798823
async def get_stats(self) -> dict[str, Any]:

schema-monitor/templates/provider_detail.html

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -821,19 +821,60 @@ <h2 class="text-lg font-semibold text-gray-900 dark:text-white">Add Credential</
821821
</div>
822822
</div>
823823

824+
<!-- Auth tipine gore bilgilendirme -->
825+
<div class="rounded-md bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 p-3">
826+
<div class="flex items-start gap-2">
827+
<svg class="h-5 w-5 text-blue-400 dark:text-blue-500 flex-shrink-0 mt-0.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
828+
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd" />
829+
</svg>
830+
<div class="text-sm text-blue-700 dark:text-blue-300">
831+
<template x-if="PROVIDER_AUTH_TYPE === 'bearer'">
832+
<span>Bearer auth icin <strong class="font-mono">token</strong> key'i ile Bearer token degerinizi ekleyin.</span>
833+
</template>
834+
<template x-if="PROVIDER_AUTH_TYPE === 'basic'">
835+
<span>Basic auth icin <strong class="font-mono">username</strong> ve <strong class="font-mono">password</strong> key'leriyle iki ayri credential ekleyin.</span>
836+
</template>
837+
<template x-if="PROVIDER_AUTH_TYPE === 'api_key'">
838+
<span>API Key auth icin <strong class="font-mono">api_key</strong> key'i ile API anahtarinizi ekleyin.</span>
839+
</template>
840+
<template x-if="PROVIDER_AUTH_TYPE === 'oauth2'">
841+
<span>OAuth2 auth icin <strong class="font-mono">client_id</strong> ve <strong class="font-mono">client_secret</strong> key'leriyle iki ayri credential ekleyin.</span>
842+
</template>
843+
<template x-if="!PROVIDER_AUTH_TYPE || PROVIDER_AUTH_TYPE === 'none'">
844+
<span>Bu provider icin auth tipi secilmemis. Gerekirse provider'i duzenleyerek auth tipi secin.</span>
845+
</template>
846+
</div>
847+
</div>
848+
</div>
849+
824850
<!-- Anahtar adi -->
825851
<div>
826852
<label for="cred-key" class="block text-sm font-medium text-gray-700 dark:text-gray-300">
827853
Key Name <span class="text-red-500">*</span>
828854
</label>
829-
<input
830-
type="text"
831-
id="cred-key"
832-
x-model="credentialForm.key_name"
833-
required
834-
placeholder="ornek: api_token"
835-
class="mt-1 block w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm text-gray-900 dark:text-white shadow-sm placeholder:text-gray-400 dark:placeholder:text-gray-500 focus:border-indigo-500 dark:focus:border-indigo-400 focus:ring-1 focus:ring-indigo-500 dark:focus:ring-indigo-400 focus:outline-none font-mono"
836-
>
855+
<template x-if="credentialKeyOptions.length > 0">
856+
<select
857+
id="cred-key"
858+
x-model="credentialForm.key_name"
859+
required
860+
class="mt-1 block w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm text-gray-900 dark:text-white shadow-sm focus:border-indigo-500 dark:focus:border-indigo-400 focus:ring-1 focus:ring-indigo-500 dark:focus:ring-indigo-400 focus:outline-none font-mono"
861+
>
862+
<option value="" disabled>Key secin...</option>
863+
<template x-for="opt in credentialKeyOptions" :key="opt">
864+
<option :value="opt" x-text="opt"></option>
865+
</template>
866+
</select>
867+
</template>
868+
<template x-if="credentialKeyOptions.length === 0">
869+
<input
870+
type="text"
871+
id="cred-key"
872+
x-model="credentialForm.key_name"
873+
required
874+
placeholder="ornek: api_token"
875+
class="mt-1 block w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm text-gray-900 dark:text-white shadow-sm placeholder:text-gray-400 dark:placeholder:text-gray-500 focus:border-indigo-500 dark:focus:border-indigo-400 focus:ring-1 focus:ring-indigo-500 dark:focus:ring-indigo-400 focus:outline-none font-mono"
876+
>
877+
</template>
837878
</div>
838879

839880
<!-- Deger (sifre alani) -->
@@ -846,7 +887,7 @@ <h2 class="text-lg font-semibold text-gray-900 dark:text-white">Add Credential</
846887
id="cred-value"
847888
x-model="credentialForm.value"
848889
required
849-
placeholder="Credential degerini girin"
890+
:placeholder="credentialValuePlaceholder"
850891
class="mt-1 block w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm text-gray-900 dark:text-white shadow-sm placeholder:text-gray-400 dark:placeholder:text-gray-500 focus:border-indigo-500 dark:focus:border-indigo-400 focus:ring-1 focus:ring-indigo-500 dark:focus:ring-indigo-400 focus:outline-none font-mono"
851892
>
852893
<p class="mt-1 text-xs text-gray-400 dark:text-gray-500">Deger sifrelenerek kaydedilir. Kaydedildikten sonra goruntulenebilir olmayacaktir.</p>
@@ -924,6 +965,30 @@ <h2 class="text-lg font-semibold text-gray-900 dark:text-white">Add Credential</
924965
value: ''
925966
},
926967

968+
/* Auth tipine gore beklenen credential key'leri */
969+
get credentialKeyOptions() {
970+
const keyMap = {
971+
'bearer': ['token'],
972+
'basic': ['username', 'password'],
973+
'api_key': ['api_key'],
974+
'oauth2': ['client_id', 'client_secret']
975+
};
976+
return keyMap[PROVIDER_AUTH_TYPE] || [];
977+
},
978+
979+
/* Auth tipine gore placeholder metni */
980+
get credentialValuePlaceholder() {
981+
const placeholderMap = {
982+
'token': 'Bearer token degerini girin',
983+
'username': 'Kullanici adini girin',
984+
'password': 'Sifre degerini girin',
985+
'api_key': 'API anahtarini girin',
986+
'client_id': 'OAuth2 client ID girin',
987+
'client_secret': 'OAuth2 client secret girin'
988+
};
989+
return placeholderMap[this.credentialForm.key_name] || 'Credential degerini girin';
990+
},
991+
927992
/* Yukleme ve hata durumlari */
928993
editLoading: false,
929994
editError: '',

0 commit comments

Comments
 (0)