|
1
|
{% extends "base.html" %} |
|
2
|
{% block title %}API Tokens — {{ project.name }} — Fossilrepo{% endblock %} |
|
3
|
|
|
4
|
{% block content %} |
|
5
|
<h1 class="text-2xl font-bold text-gray-100 mb-2">{{ project.name }}</h1> |
|
6
|
{% include "fossil/_project_nav.html" %} |
|
7
|
|
|
8
|
<div class="flex items-center justify-between mb-6"> |
|
9
|
<div> |
|
10
|
<h2 class="text-lg font-semibold text-gray-200">API Tokens</h2> |
|
11
|
<p class="text-sm text-gray-500 mt-1">Tokens for CI/CD systems and automation. Used with Bearer authentication.</p> |
|
12
|
</div> |
|
13
|
<div class="flex items-center gap-3"> |
|
14
|
<span class="search-wrap"> |
|
15
|
<input type="search" |
|
16
|
name="search" |
|
17
|
value="{{ search }}" |
|
18
|
placeholder="Search tokens..." |
|
19
|
aria-label="Search API tokens" |
|
20
|
class="rounded-md border-gray-700 bg-gray-800 text-gray-100 shadow-sm focus:border-brand focus:ring-brand text-sm px-3 py-1.5" |
|
21
|
hx-get="{% url 'fossil:api_tokens' slug=project.slug %}" |
|
22
|
hx-trigger="input changed delay:300ms, search" |
|
23
|
hx-target="#token-content" |
|
24
|
hx-swap="innerHTML" |
|
25
|
hx-push-url="true" |
|
26
|
hx-indicator="closest .search-wrap" /> |
|
27
|
<svg class="search-spinner animate-spin h-4 w-4" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path></svg> |
|
28
|
</span> |
|
29
|
<a href="{% url 'fossil:api_token_create' slug=project.slug %}" |
|
30
|
class="inline-flex items-center rounded-md bg-brand px-3 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-brand-hover"> |
|
31
|
Generate Token |
|
32
|
</a> |
|
33
|
</div> |
|
34
|
</div> |
|
35
|
|
|
36
|
<div id="token-content"> |
|
37
|
{% if tokens %} |
|
38
|
<div class="space-y-3"> |
|
39
|
{% for token in tokens %} |
|
40
|
<div class="rounded-lg bg-gray-800 border border-gray-700"> |
|
41
|
<div class="px-5 py-4"> |
|
42
|
<div class="flex items-start justify-between gap-4"> |
|
43
|
<div class="flex-1 min-w-0"> |
|
44
|
<div class="flex items-center gap-3 mb-1"> |
|
45
|
<span class="text-sm font-medium text-gray-100">{{ token.name }}</span> |
|
46
|
<code class="text-xs font-mono text-gray-500">{{ token.token_prefix }}...</code> |
|
47
|
</div> |
|
48
|
<div class="flex items-center gap-3 text-xs text-gray-500 mt-1 flex-wrap"> |
|
49
|
<span>Permissions: {{ token.permissions }}</span> |
|
50
|
<span>Created {{ token.created_at|timesince }} ago</span> |
|
51
|
{% if token.last_used_at %} |
|
52
|
<span>Last used {{ token.last_used_at|timesince }} ago</span> |
|
53
|
{% else %} |
|
54
|
<span>Never used</span> |
|
55
|
{% endif %} |
|
56
|
{% if token.expires_at %} |
|
57
|
<span>Expires {{ token.expires_at|date:"Y-m-d" }}</span> |
|
58
|
{% else %} |
|
59
|
<span>No expiration</span> |
|
60
|
{% endif %} |
|
61
|
</div> |
|
62
|
</div> |
|
63
|
<div class="flex items-center gap-2 flex-shrink-0"> |
|
64
|
<form method="post" action="{% url 'fossil:api_token_delete' slug=project.slug token_id=token.pk %}" |
|
65
|
class="inline" onsubmit="return confirm('Revoke this token? Any systems using it will lose access.')"> |
|
66
|
{% csrf_token %} |
|
67
|
<button type="submit" class="text-xs text-red-400 hover:text-red-300">Revoke</button> |
|
68
|
</form> |
|
69
|
</div> |
|
70
|
</div> |
|
71
|
</div> |
|
72
|
</div> |
|
73
|
{% endfor %} |
|
74
|
</div> |
|
75
|
{% else %} |
|
76
|
<div class="rounded-lg bg-gray-800 border border-gray-700 p-8 text-center"> |
|
77
|
<p class="text-sm text-gray-500">{% if search %}No tokens matching "{{ search }}".{% else %}No API tokens generated yet.{% endif %}</p> |
|
78
|
{% if not search %} |
|
79
|
<a href="{% url 'fossil:api_token_create' slug=project.slug %}" |
|
80
|
class="mt-3 inline-flex items-center rounded-md bg-brand px-3 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-brand-hover"> |
|
81
|
Generate the first token |
|
82
|
</a> |
|
83
|
{% endif %} |
|
84
|
</div> |
|
85
|
{% endif %} |
|
86
|
{% include "includes/_pagination.html" %} |
|
87
|
</div> |
|
88
|
|
|
89
|
<div class="mt-6 rounded-lg bg-gray-800/50 border border-gray-700 p-4"> |
|
90
|
<h3 class="text-sm font-semibold text-gray-300 mb-2">Usage</h3> |
|
91
|
<p class="text-xs text-gray-500 mb-2">Use the token with the CI Status API:</p> |
|
92
|
<pre class="text-xs font-mono text-gray-400 bg-gray-900 rounded p-3 overflow-x-auto">curl -X POST {{ request.scheme }}://{{ request.get_host }}/projects/{{ project.slug }}/fossil/api/status \ |
|
93
|
-H "Authorization: Bearer YOUR_TOKEN" \ |
|
94
|
-H "Content-Type: application/json" \ |
|
95
|
-d '{"checkin": "abc123", "context": "ci/tests", "state": "success"}'</pre> |
|
96
|
</div> |
|
97
|
{% endblock %} |
|
98
|
|