From f6b4a9b234c32f607b5e209b18bc45b259849c45 Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Wed, 28 Feb 2024 10:15:04 +0100 Subject: [PATCH 1/4] Init endpoint_macros template --- .../templates/endpoint_macros.py.jinja | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 osidb_bindings/templates/endpoint_macros.py.jinja diff --git a/osidb_bindings/templates/endpoint_macros.py.jinja b/osidb_bindings/templates/endpoint_macros.py.jinja new file mode 100644 index 0000000..0445236 --- /dev/null +++ b/osidb_bindings/templates/endpoint_macros.py.jinja @@ -0,0 +1,151 @@ +{# + This is a custom template derived from: + https://github.com/openapi-generators/openapi-python-client/blob/v.0.10.7/openapi_python_client/templates/endpoint_macros.py.jinja +#} +{% macro header_params(endpoint) %} +{% if endpoint.header_parameters %} + {% for parameter in endpoint.header_parameters.values() %} + {% if parameter.required %} +headers["{{ parameter.name | kebabcase}}"] = {{ parameter.python_name }} + {% else %} +if {{ parameter.python_name }} is not UNSET: + headers["{{ parameter.name | kebabcase}}"] = {{ parameter.python_name }} + {% endif %} + {% endfor %} +{% endif %} +{% endmacro %} + +{% macro cookie_params(endpoint) %} +{% if endpoint.cookie_parameters %} + {% for parameter in endpoint.cookie_parameters.values() %} + {% if parameter.required %} +cookies["{{ parameter.name}}"] = {{ parameter.python_name }} + {% else %} +if {{ parameter.python_name }} is not UNSET: + cookies["{{ parameter.name}}"] = {{ parameter.python_name }} + {% endif %} + {% endfor %} +{% endif %} +{% endmacro %} + + +{% macro query_params(endpoint) %} +{% if endpoint.query_parameters %} + {% for property in endpoint.query_parameters.values() %} + {% set destination = "json_" + property.python_name %} + {% if property.template %} + {% from "property_templates/" + property.template import transform %} +{{ transform(property, property.python_name, destination) }} + {% endif %} + {% endfor %} +params: Dict[str, Any] = { + {% for property in endpoint.query_parameters.values() %} + {% if not property.json_is_dict %} + {% if property.template %} + "{{ property.name }}": {{ "json_" + property.python_name }}, + {% else %} + "{{ property.name }}": {{ property.python_name }}, + {% endif %} + {% endif %} + {% endfor %} +} + {% for property in endpoint.query_parameters.values() %} + {% if property.json_is_dict %} + {% set property_name = "json_" + property.python_name %} + {% if property.required and not property.nullable %} +params.update({{ property_name }}) + {% else %} +if {% if not property.required %}not isinstance({{ property_name }}, Unset){% endif %}{% if not property.required and property.nullable %} and {% endif %}{% if property.nullable %}{{ property_name }} is not None{% endif %}: + params.update({{ property_name }}) + {% endif %} + {% endif %} + {% endfor %} +params = {k: v for k, v in params.items() if v is not UNSET and v is not None} +{% endif %} +{% endmacro %} + +{% macro json_body(endpoint) %} +{% if endpoint.json_body %} + {% set property = endpoint.json_body %} + {% set destination = "json_" + property.python_name %} + {% if property.template %} + {% from "property_templates/" + property.template import transform %} +{{ transform(property, property.python_name, destination) }} + {% endif %} +{% endif %} +{% endmacro %} + +{% macro multipart_body(endpoint) %} +{% if endpoint.multipart_body %} + {% set property = endpoint.multipart_body %} + {% set destination = "multipart_" + property.python_name %} + {% if property.template %} + {% from "property_templates/" + property.template import transform_multipart %} +{{ transform_multipart(property, property.python_name, destination) }} + {% endif %} +{% endif %} +{% endmacro %} + +{# The all the kwargs passed into an endpoint (and variants thereof)) #} +{% macro arguments(endpoint) %} +{# path parameters #} +{% for parameter in endpoint.path_parameters.values() %} +{{ parameter.to_string() }}, +{% endfor %} +*, +{# Proper client based on whether or not the endpoint requires authentication #} +{% if endpoint.requires_security %} +client: AuthenticatedClient, +{% else %} +client: Client, +{% endif %} +{# Form data if any #} +{% if endpoint.form_body_class %} +form_data: {{ endpoint.form_body_class.name }}, +{% endif %} +{# Multipart data if any #} +{% if endpoint.multipart_body %} +multipart_data: {{ endpoint.multipart_body.get_type_string() }}, +{% endif %} +{# JSON body if any #} +{% if endpoint.json_body %} +json_body: {{ endpoint.json_body.get_type_string() }}, +{% endif %} +{# query parameters #} +{% for parameter in endpoint.query_parameters.values() %} +{{ parameter.to_string() }}, +{% endfor %} +{% for parameter in endpoint.header_parameters.values() %} +{{ parameter.to_string() }}, +{% endfor %} +{# cookie parameters #} +{% for parameter in endpoint.cookie_parameters.values() %} +{{ parameter.to_string() }}, +{% endfor %} +{% endmacro %} + +{# Just lists all kwargs to endpoints as name=name for passing to other functions #} +{% macro kwargs(endpoint) %} +{% for parameter in endpoint.path_parameters.values() %} +{{ parameter.python_name }}={{ parameter.python_name }}, +{% endfor %} +client=client, +{% if endpoint.form_body_class %} +form_data=form_data, +{% endif %} +{% if endpoint.multipart_body %} +multipart_data=multipart_data, +{% endif %} +{% if endpoint.json_body %} +json_body=json_body, +{% endif %} +{% for parameter in endpoint.query_parameters.values() %} +{{ parameter.python_name }}={{ parameter.python_name }}, +{% endfor %} +{% for parameter in endpoint.header_parameters.values() %} +{{ parameter.python_name }}={{ parameter.python_name }}, +{% endfor %} +{% for parameter in endpoint.cookie_parameters.values() %} +{{ parameter.python_name }}={{ parameter.python_name }}, +{% endfor %} +{% endmacro %} From c3ef71f732b8a7c1086202bb214eb2d4dea20939 Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Thu, 23 May 2024 13:06:15 +0200 Subject: [PATCH 2/4] Remove header parameters These parameters are currently being sent automatically and there is no need to supply them. --- .../api/osidb/osidb_api_v1_affects_create.py | 11 ---------- .../api/osidb/osidb_api_v1_affects_update.py | 11 ---------- .../api/osidb/osidb_api_v1_flaws_create.py | 21 ------------------- .../osidb_api_v1_flaws_promote_create.py | 11 ---------- .../osidb/osidb_api_v1_flaws_reject_create.py | 11 ---------- .../api/osidb/osidb_api_v1_flaws_update.py | 21 ------------------- .../api/osidb/osidb_api_v1_trackers_create.py | 21 ------------------- .../api/osidb/osidb_api_v1_trackers_update.py | 21 ------------------- .../templates/endpoint_macros.py.jinja | 6 ------ .../templates/endpoint_module.py.jinja | 2 -- 10 files changed, 136 deletions(-) diff --git a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_affects_create.py b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_affects_create.py index 3ad77a8..ac7749b 100644 --- a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_affects_create.py +++ b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_affects_create.py @@ -19,7 +19,6 @@ def _get_kwargs( form_data: AffectPost, multipart_data: AffectPost, json_body: AffectPost, - bugzilla_api_key: str, ) -> Dict[str, Any]: url = "{}/osidb/api/v1/affects".format( client.base_url, @@ -27,8 +26,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - headers["bugzilla-api-key"] = bugzilla_api_key - json_json_body: Dict[str, Any] = UNSET if not isinstance(json_body, Unset): json_body.to_dict() @@ -76,14 +73,12 @@ def sync_detailed( form_data: AffectPost, multipart_data: AffectPost, json_body: AffectPost, - bugzilla_api_key: str, ) -> Response[OsidbApiV1AffectsCreateResponse201]: kwargs = _get_kwargs( client=client, form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, ) response = requests.post( @@ -103,7 +98,6 @@ def sync( form_data: AffectPost, multipart_data: AffectPost, json_body: AffectPost, - bugzilla_api_key: str, ) -> Optional[OsidbApiV1AffectsCreateResponse201]: """ """ @@ -112,7 +106,6 @@ def sync( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, ).parsed @@ -122,14 +115,12 @@ async def async_detailed( form_data: AffectPost, multipart_data: AffectPost, json_body: AffectPost, - bugzilla_api_key: str, ) -> Response[OsidbApiV1AffectsCreateResponse201]: kwargs = _get_kwargs( client=client, form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, ) async with client.get_async_session().post( @@ -149,7 +140,6 @@ async def async_( form_data: AffectPost, multipart_data: AffectPost, json_body: AffectPost, - bugzilla_api_key: str, ) -> Optional[OsidbApiV1AffectsCreateResponse201]: """ """ @@ -159,6 +149,5 @@ async def async_( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, ) ).parsed diff --git a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_affects_update.py b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_affects_update.py index 6af5625..73929b0 100644 --- a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_affects_update.py +++ b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_affects_update.py @@ -20,7 +20,6 @@ def _get_kwargs( form_data: Affect, multipart_data: Affect, json_body: Affect, - bugzilla_api_key: str, ) -> Dict[str, Any]: url = "{}/osidb/api/v1/affects/{uuid}".format( client.base_url, @@ -29,8 +28,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - headers["bugzilla-api-key"] = bugzilla_api_key - json_json_body: Dict[str, Any] = UNSET if not isinstance(json_body, Unset): json_body.to_dict() @@ -79,7 +76,6 @@ def sync_detailed( form_data: Affect, multipart_data: Affect, json_body: Affect, - bugzilla_api_key: str, ) -> Response[OsidbApiV1AffectsUpdateResponse200]: kwargs = _get_kwargs( uuid=uuid, @@ -87,7 +83,6 @@ def sync_detailed( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, ) response = requests.put( @@ -108,7 +103,6 @@ def sync( form_data: Affect, multipart_data: Affect, json_body: Affect, - bugzilla_api_key: str, ) -> Optional[OsidbApiV1AffectsUpdateResponse200]: """ """ @@ -118,7 +112,6 @@ def sync( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, ).parsed @@ -129,7 +122,6 @@ async def async_detailed( form_data: Affect, multipart_data: Affect, json_body: Affect, - bugzilla_api_key: str, ) -> Response[OsidbApiV1AffectsUpdateResponse200]: kwargs = _get_kwargs( uuid=uuid, @@ -137,7 +129,6 @@ async def async_detailed( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, ) async with client.get_async_session().put( @@ -158,7 +149,6 @@ async def async_( form_data: Affect, multipart_data: Affect, json_body: Affect, - bugzilla_api_key: str, ) -> Optional[OsidbApiV1AffectsUpdateResponse200]: """ """ @@ -169,6 +159,5 @@ async def async_( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, ) ).parsed diff --git a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_create.py b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_create.py index 70e4680..7b963d8 100644 --- a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_create.py +++ b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_create.py @@ -19,8 +19,6 @@ def _get_kwargs( form_data: FlawPost, multipart_data: FlawPost, json_body: FlawPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Dict[str, Any]: url = "{}/osidb/api/v1/flaws".format( client.base_url, @@ -28,9 +26,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - headers["bugzilla-api-key"] = bugzilla_api_key - headers["jira-api-key"] = jira_api_key - json_json_body: Dict[str, Any] = UNSET if not isinstance(json_body, Unset): json_body.to_dict() @@ -78,16 +73,12 @@ def sync_detailed( form_data: FlawPost, multipart_data: FlawPost, json_body: FlawPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Response[OsidbApiV1FlawsCreateResponse201]: kwargs = _get_kwargs( client=client, form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) response = requests.post( @@ -107,8 +98,6 @@ def sync( form_data: FlawPost, multipart_data: FlawPost, json_body: FlawPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Optional[OsidbApiV1FlawsCreateResponse201]: """ """ @@ -117,8 +106,6 @@ def sync( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ).parsed @@ -128,16 +115,12 @@ async def async_detailed( form_data: FlawPost, multipart_data: FlawPost, json_body: FlawPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Response[OsidbApiV1FlawsCreateResponse201]: kwargs = _get_kwargs( client=client, form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) async with client.get_async_session().post( @@ -157,8 +140,6 @@ async def async_( form_data: FlawPost, multipart_data: FlawPost, json_body: FlawPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Optional[OsidbApiV1FlawsCreateResponse201]: """ """ @@ -168,7 +149,5 @@ async def async_( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) ).parsed diff --git a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_promote_create.py b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_promote_create.py index f19b31d..f3faf82 100644 --- a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_promote_create.py +++ b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_promote_create.py @@ -15,7 +15,6 @@ def _get_kwargs( flaw_id: str, *, client: AuthenticatedClient, - jira_api_key: str, ) -> Dict[str, Any]: url = "{}/osidb/api/v1/flaws/{flaw_id}/promote".format( client.base_url, @@ -24,8 +23,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - headers["jira-api-key"] = jira_api_key - return { "url": url, "headers": headers, @@ -64,12 +61,10 @@ def sync_detailed( flaw_id: str, *, client: AuthenticatedClient, - jira_api_key: str, ) -> Response[OsidbApiV1FlawsPromoteCreateResponse200]: kwargs = _get_kwargs( flaw_id=flaw_id, client=client, - jira_api_key=jira_api_key, ) response = requests.post( @@ -87,7 +82,6 @@ def sync( flaw_id: str, *, client: AuthenticatedClient, - jira_api_key: str, ) -> Optional[OsidbApiV1FlawsPromoteCreateResponse200]: """workflow promotion API endpoint @@ -97,7 +91,6 @@ def sync( return sync_detailed( flaw_id=flaw_id, client=client, - jira_api_key=jira_api_key, ).parsed @@ -105,12 +98,10 @@ async def async_detailed( flaw_id: str, *, client: AuthenticatedClient, - jira_api_key: str, ) -> Response[OsidbApiV1FlawsPromoteCreateResponse200]: kwargs = _get_kwargs( flaw_id=flaw_id, client=client, - jira_api_key=jira_api_key, ) async with client.get_async_session().post( @@ -128,7 +119,6 @@ async def async_( flaw_id: str, *, client: AuthenticatedClient, - jira_api_key: str, ) -> Optional[OsidbApiV1FlawsPromoteCreateResponse200]: """workflow promotion API endpoint @@ -139,6 +129,5 @@ async def async_( await async_detailed( flaw_id=flaw_id, client=client, - jira_api_key=jira_api_key, ) ).parsed diff --git a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_reject_create.py b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_reject_create.py index 09c2ff8..000311f 100644 --- a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_reject_create.py +++ b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_reject_create.py @@ -20,7 +20,6 @@ def _get_kwargs( form_data: Reject, multipart_data: Reject, json_body: Reject, - jira_api_key: str, ) -> Dict[str, Any]: url = "{}/osidb/api/v1/flaws/{flaw_id}/reject".format( client.base_url, @@ -29,8 +28,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - headers["jira-api-key"] = jira_api_key - json_json_body: Dict[str, Any] = UNSET if not isinstance(json_body, Unset): json_body.to_dict() @@ -81,7 +78,6 @@ def sync_detailed( form_data: Reject, multipart_data: Reject, json_body: Reject, - jira_api_key: str, ) -> Response[OsidbApiV1FlawsRejectCreateResponse200]: kwargs = _get_kwargs( flaw_id=flaw_id, @@ -89,7 +85,6 @@ def sync_detailed( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - jira_api_key=jira_api_key, ) response = requests.post( @@ -110,7 +105,6 @@ def sync( form_data: Reject, multipart_data: Reject, json_body: Reject, - jira_api_key: str, ) -> Optional[OsidbApiV1FlawsRejectCreateResponse200]: """workflow promotion API endpoint @@ -122,7 +116,6 @@ def sync( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - jira_api_key=jira_api_key, ).parsed @@ -133,7 +126,6 @@ async def async_detailed( form_data: Reject, multipart_data: Reject, json_body: Reject, - jira_api_key: str, ) -> Response[OsidbApiV1FlawsRejectCreateResponse200]: kwargs = _get_kwargs( flaw_id=flaw_id, @@ -141,7 +133,6 @@ async def async_detailed( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - jira_api_key=jira_api_key, ) async with client.get_async_session().post( @@ -162,7 +153,6 @@ async def async_( form_data: Reject, multipart_data: Reject, json_body: Reject, - jira_api_key: str, ) -> Optional[OsidbApiV1FlawsRejectCreateResponse200]: """workflow promotion API endpoint @@ -175,6 +165,5 @@ async def async_( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - jira_api_key=jira_api_key, ) ).parsed diff --git a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_update.py b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_update.py index 18d26af..c0d296a 100644 --- a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_update.py +++ b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_flaws_update.py @@ -20,8 +20,6 @@ def _get_kwargs( form_data: Flaw, multipart_data: Flaw, json_body: Flaw, - bugzilla_api_key: str, - jira_api_key: str, ) -> Dict[str, Any]: url = "{}/osidb/api/v1/flaws/{id}".format( client.base_url, @@ -30,9 +28,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - headers["bugzilla-api-key"] = bugzilla_api_key - headers["jira-api-key"] = jira_api_key - json_json_body: Dict[str, Any] = UNSET if not isinstance(json_body, Unset): json_body.to_dict() @@ -81,8 +76,6 @@ def sync_detailed( form_data: Flaw, multipart_data: Flaw, json_body: Flaw, - bugzilla_api_key: str, - jira_api_key: str, ) -> Response[OsidbApiV1FlawsUpdateResponse200]: kwargs = _get_kwargs( id=id, @@ -90,8 +83,6 @@ def sync_detailed( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) response = requests.put( @@ -112,8 +103,6 @@ def sync( form_data: Flaw, multipart_data: Flaw, json_body: Flaw, - bugzilla_api_key: str, - jira_api_key: str, ) -> Optional[OsidbApiV1FlawsUpdateResponse200]: """ """ @@ -123,8 +112,6 @@ def sync( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ).parsed @@ -135,8 +122,6 @@ async def async_detailed( form_data: Flaw, multipart_data: Flaw, json_body: Flaw, - bugzilla_api_key: str, - jira_api_key: str, ) -> Response[OsidbApiV1FlawsUpdateResponse200]: kwargs = _get_kwargs( id=id, @@ -144,8 +129,6 @@ async def async_detailed( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) async with client.get_async_session().put( @@ -166,8 +149,6 @@ async def async_( form_data: Flaw, multipart_data: Flaw, json_body: Flaw, - bugzilla_api_key: str, - jira_api_key: str, ) -> Optional[OsidbApiV1FlawsUpdateResponse200]: """ """ @@ -178,7 +159,5 @@ async def async_( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) ).parsed diff --git a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_trackers_create.py b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_trackers_create.py index 5e74b02..81872cc 100644 --- a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_trackers_create.py +++ b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_trackers_create.py @@ -19,8 +19,6 @@ def _get_kwargs( form_data: TrackerPost, multipart_data: TrackerPost, json_body: TrackerPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Dict[str, Any]: url = "{}/osidb/api/v1/trackers".format( client.base_url, @@ -28,9 +26,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - headers["bugzilla-api-key"] = bugzilla_api_key - headers["jira-api-key"] = jira_api_key - json_json_body: Dict[str, Any] = UNSET if not isinstance(json_body, Unset): json_body.to_dict() @@ -78,16 +73,12 @@ def sync_detailed( form_data: TrackerPost, multipart_data: TrackerPost, json_body: TrackerPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Response[OsidbApiV1TrackersCreateResponse201]: kwargs = _get_kwargs( client=client, form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) response = requests.post( @@ -107,8 +98,6 @@ def sync( form_data: TrackerPost, multipart_data: TrackerPost, json_body: TrackerPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Optional[OsidbApiV1TrackersCreateResponse201]: """ """ @@ -117,8 +106,6 @@ def sync( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ).parsed @@ -128,16 +115,12 @@ async def async_detailed( form_data: TrackerPost, multipart_data: TrackerPost, json_body: TrackerPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Response[OsidbApiV1TrackersCreateResponse201]: kwargs = _get_kwargs( client=client, form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) async with client.get_async_session().post( @@ -157,8 +140,6 @@ async def async_( form_data: TrackerPost, multipart_data: TrackerPost, json_body: TrackerPost, - bugzilla_api_key: str, - jira_api_key: str, ) -> Optional[OsidbApiV1TrackersCreateResponse201]: """ """ @@ -168,7 +149,5 @@ async def async_( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) ).parsed diff --git a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_trackers_update.py b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_trackers_update.py index 4cca8d0..055f614 100644 --- a/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_trackers_update.py +++ b/osidb_bindings/bindings/python_client/api/osidb/osidb_api_v1_trackers_update.py @@ -20,8 +20,6 @@ def _get_kwargs( form_data: Tracker, multipart_data: Tracker, json_body: Tracker, - bugzilla_api_key: str, - jira_api_key: str, ) -> Dict[str, Any]: url = "{}/osidb/api/v1/trackers/{uuid}".format( client.base_url, @@ -30,9 +28,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - headers["bugzilla-api-key"] = bugzilla_api_key - headers["jira-api-key"] = jira_api_key - json_json_body: Dict[str, Any] = UNSET if not isinstance(json_body, Unset): json_body.to_dict() @@ -81,8 +76,6 @@ def sync_detailed( form_data: Tracker, multipart_data: Tracker, json_body: Tracker, - bugzilla_api_key: str, - jira_api_key: str, ) -> Response[OsidbApiV1TrackersUpdateResponse200]: kwargs = _get_kwargs( uuid=uuid, @@ -90,8 +83,6 @@ def sync_detailed( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) response = requests.put( @@ -112,8 +103,6 @@ def sync( form_data: Tracker, multipart_data: Tracker, json_body: Tracker, - bugzilla_api_key: str, - jira_api_key: str, ) -> Optional[OsidbApiV1TrackersUpdateResponse200]: """ """ @@ -123,8 +112,6 @@ def sync( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ).parsed @@ -135,8 +122,6 @@ async def async_detailed( form_data: Tracker, multipart_data: Tracker, json_body: Tracker, - bugzilla_api_key: str, - jira_api_key: str, ) -> Response[OsidbApiV1TrackersUpdateResponse200]: kwargs = _get_kwargs( uuid=uuid, @@ -144,8 +129,6 @@ async def async_detailed( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) async with client.get_async_session().put( @@ -166,8 +149,6 @@ async def async_( form_data: Tracker, multipart_data: Tracker, json_body: Tracker, - bugzilla_api_key: str, - jira_api_key: str, ) -> Optional[OsidbApiV1TrackersUpdateResponse200]: """ """ @@ -178,7 +159,5 @@ async def async_( form_data=form_data, multipart_data=multipart_data, json_body=json_body, - bugzilla_api_key=bugzilla_api_key, - jira_api_key=jira_api_key, ) ).parsed diff --git a/osidb_bindings/templates/endpoint_macros.py.jinja b/osidb_bindings/templates/endpoint_macros.py.jinja index 0445236..756a727 100644 --- a/osidb_bindings/templates/endpoint_macros.py.jinja +++ b/osidb_bindings/templates/endpoint_macros.py.jinja @@ -115,9 +115,6 @@ json_body: {{ endpoint.json_body.get_type_string() }}, {% for parameter in endpoint.query_parameters.values() %} {{ parameter.to_string() }}, {% endfor %} -{% for parameter in endpoint.header_parameters.values() %} -{{ parameter.to_string() }}, -{% endfor %} {# cookie parameters #} {% for parameter in endpoint.cookie_parameters.values() %} {{ parameter.to_string() }}, @@ -142,9 +139,6 @@ json_body=json_body, {% for parameter in endpoint.query_parameters.values() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} -{% for parameter in endpoint.header_parameters.values() %} -{{ parameter.python_name }}={{ parameter.python_name }}, -{% endfor %} {% for parameter in endpoint.cookie_parameters.values() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} diff --git a/osidb_bindings/templates/endpoint_module.py.jinja b/osidb_bindings/templates/endpoint_module.py.jinja index 8c28390..c346a00 100644 --- a/osidb_bindings/templates/endpoint_module.py.jinja +++ b/osidb_bindings/templates/endpoint_module.py.jinja @@ -40,8 +40,6 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() - {{ header_params(endpoint) | indent(4) }} - {{ cookie_params(endpoint) | indent(4) }} {{ query_params(endpoint) | indent(4) }} From 6a25f5578b718bea019b3af3425b1bfc55b092c1 Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Thu, 23 May 2024 12:59:23 +0200 Subject: [PATCH 3/4] Add Trackers create,update --- osidb_bindings/session.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osidb_bindings/session.py b/osidb_bindings/session.py index 51d81bb..381cb95 100644 --- a/osidb_bindings/session.py +++ b/osidb_bindings/session.py @@ -198,6 +198,8 @@ def __init__(self, base_url, auth=None, verify_ssl=True): allowed_operations=( "retrieve", "list", + "update", + "create", ), ) From bc272be166cbad3d6d932d12f33965f18549422e Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Thu, 23 May 2024 13:00:11 +0200 Subject: [PATCH 4/4] Send Jira Access Token with every request --- TUTORIAL.md | 15 +++++++++++---- osidb_bindings/session.py | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/TUTORIAL.md b/TUTORIAL.md index 51f8082..3f3138a 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -62,11 +62,18 @@ OSIDB uses token (JWT) authentication on most of the endpoints. Bindings handles session = osidb_bindings.new_session(osidb_server_uri="http://localhost:8000/") ``` -Some operations mentioned in [operations section](#session-operations) (mainly unsafe operations which creates or modify content) will require Bugzilla API key to work properly. Valid Bugzilla API key is provided via `BUGZILLA_API_KEY` environment variable. +Some operations mentioned in [operations section](#session-operations) (mainly unsafe operations which creates or modify content) will require Bugzilla API key or Jira Access Token to work properly. -```bash -export BUGZILLA_API_KEY="bugzilla api key" -``` +* Valid Bugzilla API key is provided via `BUGZILLA_API_KEY` environment variable. + + ```bash + export BUGZILLA_API_KEY="bugzilla api key" + ``` +* Valid Jira Access Token is provided via `JIRA_ACCESS_TOKEN` environment variable. + + ```bash + export JIRA_ACCESS_TOKEN="jira access token" + ``` The SSL verification is enabled by the default and in order to work properly you should export the `REQUESTS_CA_BUNDLE` environment variable to point to the location with the proper CA bundle. For example: diff --git a/osidb_bindings/session.py b/osidb_bindings/session.py index 381cb95..ed54367 100644 --- a/osidb_bindings/session.py +++ b/osidb_bindings/session.py @@ -116,6 +116,7 @@ def __init__(self, base_url, auth=None, verify_ssl=True): headers={ "User-Agent": OSIDB_BINDINGS_USERAGENT, "Bugzilla-Api-Key": get_env("BUGZILLA_API_KEY", ""), + "Jira-Api-Key": get_env("JIRA_ACCESS_TOKEN", ""), }, verify_ssl=verify_ssl, )