Skip to content

Commit 8698a04

Browse files
authored
Add API token instructions to confirmation section (#6615)
1 parent 9000661 commit 8698a04

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

warehouse/static/sass/blocks/_api-token.scss renamed to warehouse/static/sass/blocks/_code-block.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
*/
1414

1515
/*
16-
A custom styled code block for API tokens.
16+
A custom styled code block.
1717
18-
<code class="api-token">
19-
Token here
18+
<code class="code-block">
19+
Code here
2020
</code>
21+
22+
<pre class="code-block">
23+
Code here
24+
</pre>
2125
*/
2226

23-
.api-token {
27+
.code-block {
2428
display: block;
2529
padding: $spacing-unit / 2;
2630
margin-bottom: $spacing-unit / 2;

warehouse/static/sass/warehouse.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
// blocks LAYER: some warehouse specific, some generic/reusable
6666
@import "blocks/about-pypi";
6767
@import "blocks/accordion";
68-
@import "blocks/api-token";
6968
@import "blocks/applied-filters";
7069
@import "blocks/author-profile";
7170
@import "blocks/badge";
@@ -75,6 +74,7 @@
7574
@import "blocks/callout-block";
7675
@import "blocks/centered-heading";
7776
@import "blocks/checkbox-tree";
77+
@import "blocks/code-block";
7878
@import "blocks/copy-tooltip";
7979
@import "blocks/dark-overlay";
8080
@import "blocks/dropdown";

warehouse/templates/manage/token.html

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ <h2>{% trans macaroon_description=macaroon.description %}Token for "{{ macaroon_
3737
<strong>{% trans %}Scope:{% endtrans %}</strong> {% trans project=macaroon.caveats.permissions.projects[0] %}Project "{{ project }}"{% endtrans %}
3838
{% endif %}
3939
</p>
40-
<p>{% trans href='/help#apitoken' %}For instructions on how to use this token, <a href="{{ href }}">visit the PyPI help page</a>.{% endtrans %}</p>
41-
<code class="api-token">{{ serialized_macaroon }}</code>
40+
41+
<code class="code-block">{{ serialized_macaroon }}</code>
4242
<div class="margin-bottom--large">
4343
<div class="callout-block callout-block--danger no-top-margin">
4444
<p>{% trans %}For security reasons this token will only appear once. <strong>Copy it now.</strong>{% endtrans %}</p>
@@ -61,8 +61,51 @@ <h2>{% trans macaroon_description=macaroon.description %}Token for "{{ macaroon_
6161

6262
{{ confirm_modal(title=title, confirm_name=gettext("Username"), confirm_string=user.username, confirm_button_label=confirm_button_label, slug=slug, extra_fields=extra_fields, custom_warning_text=token_warning_text, confirm_string_in_title=False) }}
6363
</div>
64-
<hr>
64+
65+
<h2>{% trans %}Using this token{% endtrans %}</h2>
66+
67+
<p>{% trans %}To use this API token:{% endtrans %}</p>
68+
69+
<ul>
70+
<li>{% trans token='__token__' %}Set your username to <code>{{ token }}</code>{% endtrans %}</li>
71+
<li>{% trans prefix='pypi-' %}Set your password to the token value, including the <code>{{ prefix }}</code> prefix{% endtrans %}</li>
72+
</ul>
73+
74+
{% if macaroon.caveats.permissions == "user" %}
75+
76+
<p>
77+
{% trans trimmed href='https://pypi.org/project/virtualenv/', filename='$HOME/.pypirc' %}
78+
For example, if you are using <a href="{{ href }}">Twine</a> to upload your projects to PyPI, set up your <code>{{ filename }}</code> file like this:
79+
{% endtrans %}
80+
</p>
81+
<pre class="code-block">
82+
[pypi]
83+
username = __token__
84+
password = {{ serialized_macaroon }}</pre>
85+
{% else %}
86+
<p>
87+
{% trans trimmed href='https://pypi.org/project/virtualenv/', filename='$HOME/.pypirc' %}
88+
For example, if you are using <a href="{{ href }}">Twine</a> to upload multiple projects to PyPI, you can set up your <code>{{ filename }}</code> file like this:
89+
{% endtrans %}
90+
</p>
91+
<pre class="code-block">
92+
[pypi]
93+
username = __token__
94+
password = # {% trans %}either a user-scoped token or a project-scoped token you want to set as the default{% endtrans %}
95+
96+
[PROJECT_NAME]
97+
username = __token__
98+
password = # {% trans %}a project token{% endtrans %} </pre>
99+
<p>
100+
{% trans trimmed command='twine --repository PROJECT_NAME' %}
101+
You can then use <code>{{ command }}</code> to switch to the correct token when uploading to PyPI.
102+
{% endtrans %}
103+
</p>
104+
{% endif %}
105+
106+
<p>{% trans href='/help#apitoken' %}For further instructions on how to use this token, <a href="{{ href }}">visit the PyPI help page</a>.{% endtrans %}</p>
65107
</section>
108+
<hr>
66109
{% endif %}
67110

68111
{{ form_error_anchor(create_macaroon_form) }}
@@ -111,7 +154,7 @@ <h2>{% trans %}Add another token{% endtrans %}</h2>
111154
</div>
112155
<div id="api-token-scope-warning" class="callout-block callout-block--warning" hidden>
113156
<h3 class="callout-block__heading">{% trans %}Proceed with caution!{% endtrans %}</h3>
114-
<p>{% trans %}An API token scoped to your entire account will have upload permissions for all of your projects.{% endtrans %}</p>
157+
<p>{% trans %}An API token scoped to your entire account will have upload permissions for all of your current and future projects.{% endtrans %}</p>
115158
</div>
116159
<div>
117160
<input value="{% trans %}Add token{% endtrans %}" class="button button--primary" type="submit">

0 commit comments

Comments
 (0)