Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

api-docs: Update placeholder for curl user basic auth credentials.

Lauryn Menard47a4d8900d5c
diff --git a/api_docs/create-scheduled-message.md b/api_docs/create-scheduled-message.md
index 8720eae6339..8b69f39cf28 100644
--- a/api_docs/create-scheduled-message.md
+++ b/api_docs/create-scheduled-message.md
@@ -10,10 +10,12 @@
{tab|curl}
+{!curl-auth-credentials.md!}
+
``` curl
# Create a scheduled channel message
curl -X POST {{ api_url }}/v1/scheduled_messages \
- -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
+ -u EMAIL_ADDRESS:API_KEY \
--data-urlencode type=stream \
--data-urlencode to=9 \
--data-urlencode topic=Hello \
@@ -22,7 +24,7 @@ curl -X POST {{ api_url }}/v1/scheduled_messages \
# Create a scheduled direct message
curl -X POST {{ api_url }}/v1/messages \
- -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
+ -u EMAIL_ADDRESS:API_KEY \
--data-urlencode type=direct \
--data-urlencode 'to=[9, 10]' \
--data-urlencode 'content=Can we meet on Monday?' \
diff --git a/api_docs/http-headers.md b/api_docs/http-headers.md
index d0ca728504f..fcf94f45f37 100644
--- a/api_docs/http-headers.md
+++ b/api_docs/http-headers.md
@@ -24,7 +24,7 @@ Otherwise, to authenticate an API request:
- For `Basic` authentication credentials in the Zulip API, a "username"
takes the form of an email address, and a "password" takes the form of
an API key. In the `curl` example for each endpoint, this is shown as:
- `-u BOT_EMAIL_ADDRESS:BOT_API_KEY`.
+ `-u EMAIL_ADDRESS:API_KEY`.
- A bot's credentials can be obtained through the web and desktop apps'
[bot management UI](/help/manage-a-bot) or by [downloading the bot's
diff --git a/api_docs/include/curl-auth-credentials.md b/api_docs/include/curl-auth-credentials.md
new file mode 100644
index 00000000000..125d9e8c034
--- /dev/null
+++ b/api_docs/include/curl-auth-credentials.md
@@ -0,0 +1,6 @@
+The [`-u` line][curl-man-user] implements HTTP `Basic` authentication.
+See the [`Authorization` header][auth-header] documentation for how
+to get those credentials for Zulip users and bots.
+
+[curl-man-user]: https://curl.se/docs/manpage.html#--user
+[auth-header]: /api/http-headers#the-authorization-header
diff --git a/api_docs/send-message.md b/api_docs/send-message.md
index 6ae858770b5..f367352e64d 100644
--- a/api_docs/send-message.md
+++ b/api_docs/send-message.md
@@ -10,10 +10,12 @@
{tab|curl}
+{!curl-auth-credentials.md!}
+
``` curl
# For channel messages
curl -X POST {{ api_url }}/v1/messages \
- -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
+ -u EMAIL_ADDRESS:API_KEY \
--data-urlencode type=stream \
--data-urlencode 'to="Denmark"' \
--data-urlencode topic=Castle \
@@ -21,7 +23,7 @@ curl -X POST {{ api_url }}/v1/messages \
# For direct messages
curl -X POST {{ api_url }}/v1/messages \
- -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
+ -u EMAIL_ADDRESS:API_KEY \
--data-urlencode type=direct \
--data-urlencode 'to=[9]' \
--data-urlencode 'content=With mirth and laughter let old wrinkles come.'
diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py
index e8ba7000db7..5668bd5f53c 100644
--- a/zerver/openapi/markdown_extension.py
+++ b/zerver/openapi/markdown_extension.py
@@ -99,8 +99,8 @@ const config = { zuliprc: "zuliprc-admin" };
"""
-DEFAULT_AUTH_EMAIL = "BOT_EMAIL_ADDRESS"
-DEFAULT_AUTH_API_KEY = "BOT_API_KEY"
+DEFAULT_AUTH_EMAIL = "EMAIL_ADDRESS"
+DEFAULT_AUTH_API_KEY = "API_KEY"
DEFAULT_EXAMPLE = {
"integer": 1,
"string": "demo",
@@ -271,11 +271,17 @@ def generate_curl_example(
exclude: list[str] | None = None,
include: list[str] | None = None,
) -> list[str]:
- lines = ["```curl"]
operation = endpoint + ":" + method.lower()
operation_entry = openapi_spec.openapi()["paths"][endpoint][method.lower()]
global_security = openapi_spec.openapi()["security"]
+ insecure_operations = ["/dev_fetch_api_key:post", "/fetch_api_key:post"]
+ lines = []
+ if operation in insecure_operations:
+ lines.append("```curl")
+ else:
+ lines.append("{!curl-auth-credentials.md!}\n\n```curl")
+
parameters = get_openapi_parameters(endpoint, method)
operation_request_body = operation_entry.get("requestBody", None)
operation_security = operation_entry.get("security", None)
@@ -298,7 +304,6 @@ def generate_curl_example(
curl_first_line_parts = ["curl", *curl_method_arguments(example_endpoint, method, api_url)]
lines.append(shlex.join(curl_first_line_parts))
- insecure_operations = ["/dev_fetch_api_key:post", "/fetch_api_key:post"]
if operation_security is None:
if global_security == [{"basicAuth": []}]:
authentication_required = True
diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.py
index ad465f1ad05..14d3cd08f39 100644
--- a/zerver/openapi/test_curl_examples.py
+++ b/zerver/openapi/test_curl_examples.py
@@ -98,7 +98,7 @@ def test_generated_curl_examples_for_success(client: Client) -> None:
for curl_command_text in commands:
curl_command_text = curl_command_text.replace(
- "BOT_EMAIL_ADDRESS:BOT_API_KEY", AUTHENTICATION_LINE[0]
+ "EMAIL_ADDRESS:API_KEY", AUTHENTICATION_LINE[0]
)
print("Testing {} ...".format(curl_command_text.split("\n")[0]))
diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py
index 43f93762a54..6b32338f06a 100644
--- a/zerver/tests/test_markdown.py
+++ b/zerver/tests/test_markdown.py
@@ -3735,7 +3735,7 @@ class MarkdownErrorTests(ZulipTestCase):
markdown_input = [
"``` curl",
"curl {{ api_url }}/v1/register",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY",
+ " -u EMAIL_ADDRESS:API_KEY",
' -d "queue_id=fb67bf8a-c031-47cc-84cf-ed80accacda8"',
"```",
]
@@ -3749,14 +3749,14 @@ class MarkdownErrorTests(ZulipTestCase):
markdown_input = [
"``` curl",
"curl {{ api_url }}/v1/register",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY",
+ " -u EMAIL_ADDRESS:API_KEY",
' -d "queue_id=fb67bf8a-c031-47cc-84cf-ed80accacda8"',
"```",
]
expected = [
"",
"**curl:curl {{ api_url }}/v1/register",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY",
+ " -u EMAIL_ADDRESS:API_KEY",
' -d "queue_id=fb67bf8a-c031-47cc-84cf-ed80accacda8"**',
"",
"",
diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py
index 9d74e9f9481..ffd46d52f4e 100644
--- a/zerver/tests/test_openapi.py
+++ b/zerver/tests/test_openapi.py
@@ -760,9 +760,9 @@ class TestCurlExampleGeneration(ZulipTestCase):
def test_generate_and_render_curl_example(self) -> None:
generated_curl_example = self.curl_example("/get_stream_id", "GET")
expected_curl_example = [
- "```curl",
+ "{!curl-auth-credentials.md!}\n\n```curl",
"curl -sSX GET -G http://localhost:9991/api/v1/get_stream_id \\",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\",
+ " -u EMAIL_ADDRESS:API_KEY \\",
" --data-urlencode stream=Denmark",
"```",
]
@@ -789,9 +789,9 @@ class TestCurlExampleGeneration(ZulipTestCase):
spec_mock.return_value = self.spec_mock_without_examples
generated_curl_example = self.curl_example("/mark_stream_as_read", "POST")
expected_curl_example = [
- "```curl",
+ "{!curl-auth-credentials.md!}\n\n```curl",
"curl -sSX POST http://localhost:9991/api/v1/mark_stream_as_read \\",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\",
+ " -u EMAIL_ADDRESS:API_KEY \\",
" --data-urlencode stream_id=1 \\",
" --data-urlencode bool_param=false",
"```",
@@ -816,9 +816,9 @@ class TestCurlExampleGeneration(ZulipTestCase):
],
)
expected_curl_example = [
- "```curl",
+ "{!curl-auth-credentials.md!}\n\n```curl",
"curl -sSX GET -G http://localhost:9991/api/v1/messages \\",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\",
+ " -u EMAIL_ADDRESS:API_KEY \\",
" --data-urlencode anchor=43 \\",
" --data-urlencode include_anchor=false \\",
" --data-urlencode num_before=4 \\",
@@ -835,9 +835,9 @@ class TestCurlExampleGeneration(ZulipTestCase):
spec_mock.return_value = self.spec_mock_using_object
generated_curl_example = self.curl_example("/endpoint", "GET")
expected_curl_example = [
- "```curl",
+ "{!curl-auth-credentials.md!}\n\n```curl",
"curl -sSX GET -G http://localhost:9991/api/v1/endpoint \\",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\",
+ " -u EMAIL_ADDRESS:API_KEY \\",
' --data-urlencode \'param1={"key": "value"}\'',
"```",
]
@@ -864,9 +864,9 @@ class TestCurlExampleGeneration(ZulipTestCase):
spec_mock.return_value = self.spec_mock_using_param_in_path
generated_curl_example = self.curl_example("/endpoint/{param1}", "GET")
expected_curl_example = [
- "```curl",
+ "{!curl-auth-credentials.md!}\n\n```curl",
"curl -sSX GET -G http://localhost:9991/api/v1/endpoint/35 \\",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\",
+ " -u EMAIL_ADDRESS:API_KEY \\",
' --data-urlencode \'param2={"key": "value"}\'',
"```",
]
@@ -877,9 +877,9 @@ class TestCurlExampleGeneration(ZulipTestCase):
"/get_stream_id:GET", api_url="https://zulip.example.com/api"
)
expected_curl_example = [
- "```curl",
+ "{!curl-auth-credentials.md!}\n\n```curl",
"curl -sSX GET -G https://zulip.example.com/api/v1/get_stream_id \\",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\",
+ " -u EMAIL_ADDRESS:API_KEY \\",
" --data-urlencode stream=Denmark",
"```",
]
@@ -899,9 +899,9 @@ class TestCurlExampleGeneration(ZulipTestCase):
],
)
expected_curl_example = [
- "```curl",
+ "{!curl-auth-credentials.md!}\n\n```curl",
"curl -sSX GET -G http://localhost:9991/api/v1/messages \\",
- " -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\",
+ " -u EMAIL_ADDRESS:API_KEY \\",
" --data-urlencode anchor=43 \\",
" --data-urlencode include_anchor=false \\",
" --data-urlencode num_before=4 \\",