Skip to content

Commit

Permalink
Move auth
Browse files Browse the repository at this point in the history
  • Loading branch information
therve committed Mar 9, 2022
1 parent 18642e7 commit 6449fca
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 83 deletions.
50 changes: 0 additions & 50 deletions .generator/src/generator/templates/base_configuration.j2
Original file line number Diff line number Diff line change
Expand Up @@ -295,55 +295,6 @@ class BaseConfiguration:
password = self.password
return urllib3.util.make_headers(basic_auth=username + ":" + password).get("authorization")

def auth_settings(self):
"""Gets Auth Settings dict for api client.

:return: The Auth Settings information dict.
"""
auth = {}
{%- for name, schema in openapi.components.securitySchemes.items() %}
{%- if schema.type == "apiKey" %}
if "{{name}}" in self.api_key{% if "x-auth-id-alias" in schema %} or "{{ schema["x-auth-id-alias"] }}" in self.api_key{% endif %}:
auth["{{name}}"] = {
"type": "api_key",
"in": "{{ schema.in }}",
"key": "{{ schema.name }}",
"value": self.get_api_key_with_prefix(
"{{name}}",{% if "x-auth-id-alias" in schema %}
alias="{{ schema["x-auth-id-alias"] }}",{%- endif %}
),
}
{%- elif schema.type == "http" and schema.scheme == "basic" %}
if self.username is not None and self.password is not None:
auth["{{name}}"] = {
"type": "basic",
"in": "header",
"key": "Authorization",
"value": self.get_basic_auth_token()
}
{%- elif schema.type == "http" and schema.scheme == "bearer" %}
if self.access_token is not None:
auth["{{name}}"] = {
"type": "bearer",
"in": "header",
{% if schema.bearerFormat %}
"format": "{{ schema.bearerFormat }}",
{% endif %}
"key": "Authorization",
"value": "Bearer " + self.access_token
}
{%- elif schema.type == "oauth2" %}
if self.access_token is not None:
auth["AuthZ"] = {
"type": "oauth2",
"in": "header",
"key": "Authorization",
"value": "Bearer " + self.access_token,
}
{%- endif %}
{%- endfor %}
return auth

def get_host_settings(self):
"""Gets an array of host settings

Expand Down Expand Up @@ -425,4 +376,3 @@ class BaseConfiguration:
self._base_path = value
self.server_index = None
{# keep new line #}

49 changes: 49 additions & 0 deletions .generator/src/generator/templates/configuration.j2
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,53 @@ class Configuration(BaseConfiguration):
{%- endfor %}
{%- endfor %}
}

def auth_settings(self):
"""Gets Auth Settings dict for api client.

:return: The Auth Settings information dict.
"""
auth = {}
{%- for name, schema in openapi.components.securitySchemes.items() %}
{%- if schema.type == "apiKey" %}
if "{{name}}" in self.api_key{% if "x-auth-id-alias" in schema %} or "{{ schema["x-auth-id-alias"] }}" in self.api_key{% endif %}:
auth["{{name}}"] = {
"type": "api_key",
"in": "{{ schema.in }}",
"key": "{{ schema.name }}",
"value": self.get_api_key_with_prefix(
"{{name}}",{% if "x-auth-id-alias" in schema %}
alias="{{ schema["x-auth-id-alias"] }}",{%- endif %}
),
}
{%- elif schema.type == "http" and schema.scheme == "basic" %}
if self.username is not None and self.password is not None:
auth["{{name}}"] = {
"type": "basic",
"in": "header",
"key": "Authorization",
"value": self.get_basic_auth_token()
}
{%- elif schema.type == "http" and schema.scheme == "bearer" %}
if self.access_token is not None:
auth["{{name}}"] = {
"type": "bearer",
"in": "header",
{% if schema.bearerFormat %}
"format": "{{ schema.bearerFormat }}",
{% endif %}
"key": "Authorization",
"value": "Bearer " + self.access_token
}
{%- elif schema.type == "oauth2" %}
if self.access_token is not None:
auth["AuthZ"] = {
"type": "oauth2",
"in": "header",
"key": "Authorization",
"value": "Bearer " + self.access_token,
}
{%- endif %}
{%- endfor %}
return auth
{# keep new line #}
33 changes: 0 additions & 33 deletions src/datadog_api_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,39 +297,6 @@ def get_basic_auth_token(self):
password = self.password
return urllib3.util.make_headers(basic_auth=username + ":" + password).get("authorization")

def auth_settings(self):
"""Gets Auth Settings dict for api client.
:return: The Auth Settings information dict.
"""
auth = {}
if self.access_token is not None:
auth["AuthZ"] = {
"type": "oauth2",
"in": "header",
"key": "Authorization",
"value": "Bearer " + self.access_token,
}
if "apiKeyAuth" in self.api_key:
auth["apiKeyAuth"] = {
"type": "api_key",
"in": "header",
"key": "DD-API-KEY",
"value": self.get_api_key_with_prefix(
"apiKeyAuth",
),
}
if "appKeyAuth" in self.api_key:
auth["appKeyAuth"] = {
"type": "api_key",
"in": "header",
"key": "DD-APPLICATION-KEY",
"value": self.get_api_key_with_prefix(
"appKeyAuth",
),
}
return auth

def get_host_settings(self):
"""Gets an array of host settings
Expand Down
53 changes: 53 additions & 0 deletions src/datadog_api_client/v1/configuration.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions src/datadog_api_client/v2/configuration.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6449fca

Please sign in to comment.