162 lines
8.2 KiB
Plaintext
162 lines
8.2 KiB
Plaintext
<% content_for :title, "DSNs" %>
|
|
|
|
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
|
|
<!-- Header -->
|
|
<div class="mb-8">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<h1 class="text-3xl font-bold text-gray-900">DSN Management</h1>
|
|
<p class="mt-2 text-gray-600">Manage DSN keys for agent authentication</p>
|
|
</div>
|
|
<% if policy(Dsn).create? %>
|
|
<div class="flex space-x-3">
|
|
<%= link_to "New DSN", new_dsn_path, class: "inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700" %>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Environment DSNs -->
|
|
<div class="bg-white shadow overflow-hidden sm:rounded-md mb-8">
|
|
<div class="px-4 py-5 sm:px-6">
|
|
<h3 class="text-lg leading-6 font-medium text-gray-900">Environment DSNs</h3>
|
|
<p class="mt-1 max-w-2xl text-sm text-gray-500">
|
|
Default DSNs configured via environment variables for agent connectivity.
|
|
</p>
|
|
</div>
|
|
<div class="border-t border-gray-200">
|
|
<dl>
|
|
<!-- BAFFLE_HOST DSN -->
|
|
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
|
<dt class="text-sm font-medium text-gray-500">External DSN (BAFFLE_HOST)</dt>
|
|
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
|
<div class="flex items-center space-x-2">
|
|
<code class="bg-gray-100 px-2 py-1 rounded text-sm font-mono">
|
|
<%= @external_dsn %>
|
|
</code>
|
|
<button onclick="copyToClipboard('<%= @external_dsn %>')" class="text-blue-600 hover:text-blue-800 text-sm">
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
|
|
</svg>
|
|
Copy
|
|
</button>
|
|
</div>
|
|
<p class="text-xs text-gray-400 mt-1">Host: <%= ENV['BAFFLE_HOST'] || 'localhost:3000' %></p>
|
|
</dd>
|
|
</div>
|
|
|
|
<% if @internal_dsn.present? %>
|
|
<!-- BAFFLE_INTERNAL_HOST DSN -->
|
|
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
|
<dt class="text-sm font-medium text-gray-500">Internal DSN (BAFFLE_INTERNAL_HOST)</dt>
|
|
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
|
<div class="flex items-center space-x-2">
|
|
<code class="bg-gray-100 px-2 py-1 rounded text-sm font-mono">
|
|
<%= @internal_dsn %>
|
|
</code>
|
|
<button onclick="copyToClipboard('<%= @internal_dsn %>')" class="text-blue-600 hover:text-blue-800 text-sm">
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
|
|
</svg>
|
|
Copy
|
|
</button>
|
|
</div>
|
|
<p class="text-xs text-gray-400 mt-1">Host: <%= ENV['BAFFLE_INTERNAL_HOST'] %></p>
|
|
</dd>
|
|
</div>
|
|
<% end %>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Database DSNs -->
|
|
<div class="bg-white shadow overflow-hidden sm:rounded-md">
|
|
<% if @dsns.any? %>
|
|
<ul role="list" class="divide-y divide-gray-200">
|
|
<% @dsns.each do |dsn| %>
|
|
<li>
|
|
<div class="px-4 py-4 flex items-center justify-between">
|
|
<div class="flex items-center">
|
|
<div class="flex-shrink-0">
|
|
<% if dsn.enabled? %>
|
|
<div class="w-8 h-8 bg-green-100 rounded-full flex items-center justify-center">
|
|
<svg class="w-5 h-5 text-green-600" fill="currentColor" viewBox="0 0 20 20">
|
|
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
|
|
</svg>
|
|
</div>
|
|
<% else %>
|
|
<div class="w-8 h-8 bg-red-100 rounded-full flex items-center justify-center">
|
|
<svg class="w-5 h-5 text-red-600" fill="currentColor" viewBox="0 0 20 20">
|
|
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
|
|
</svg>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
<div class="ml-4">
|
|
<div class="flex items-center">
|
|
<p class="text-sm font-medium text-gray-900"><%= dsn.name %></p>
|
|
<span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium <%= dsn.enabled? ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' %>">
|
|
<%= dsn.enabled? ? 'Enabled' : 'Disabled' %>
|
|
</span>
|
|
</div>
|
|
<p class="text-sm text-gray-500 font-mono">
|
|
Key: <%= dsn.key[0..15] + "..." %>
|
|
</p>
|
|
<p class="text-xs text-gray-400">
|
|
Created: <%= dsn.created_at.strftime('%Y-%m-%d %H:%M') %>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="flex items-center space-x-2">
|
|
<%= link_to "View", dsn, class: "text-blue-600 hover:text-blue-900 text-sm font-medium" %>
|
|
<% if policy(dsn).edit? %>
|
|
<%= link_to "Edit", edit_dsn_path(dsn), class: "text-indigo-600 hover:text-indigo-900 text-sm font-medium" %>
|
|
<% end %>
|
|
<% if policy(dsn).disable? && dsn.enabled? %>
|
|
<%= link_to "Disable", disable_dsn_path(dsn), method: :post,
|
|
data: { confirm: "Are you sure you want to disable this DSN?" },
|
|
class: "text-red-600 hover:text-red-900 text-sm font-medium" %>
|
|
<% elsif policy(dsn).enable? && !dsn.enabled? %>
|
|
<%= link_to "Enable", enable_dsn_path(dsn), method: :post,
|
|
class: "text-green-600 hover:text-green-900 text-sm font-medium" %>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
<% end %>
|
|
</ul>
|
|
<% else %>
|
|
<div class="text-center py-12">
|
|
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" />
|
|
</svg>
|
|
<h3 class="mt-2 text-sm font-medium text-gray-900">No DSNs</h3>
|
|
<p class="mt-1 text-sm text-gray-500">Get started by creating a new DSN.</p>
|
|
<% if policy(Dsn).create? %>
|
|
<div class="mt-6">
|
|
<%= link_to "New DSN", new_dsn_path, class: "inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700" %>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function copyToClipboard(text) {
|
|
navigator.clipboard.writeText(text).then(function() {
|
|
// Show a brief confirmation
|
|
const button = event.target.closest('button');
|
|
const originalText = button.innerHTML;
|
|
button.innerHTML = '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> Copied!';
|
|
button.classList.add('text-green-600');
|
|
button.classList.remove('text-blue-600');
|
|
|
|
setTimeout(function() {
|
|
button.innerHTML = originalText;
|
|
button.classList.remove('text-green-600');
|
|
button.classList.add('text-blue-600');
|
|
}, 2000);
|
|
});
|
|
}
|
|
</script> |