Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fix to allow API tokens to be used #29

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dohq_teamcity/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def __init__(self, configuration=None, header_name=None, header_value=None,

def __del__(self):
self.pool.close()
self.pool.join()

@property
def user_agent(self):
Expand Down
13 changes: 11 additions & 2 deletions dohq_teamcity/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def __init__(self):
# Password for HTTP basic authentication
self.password = ""

# key in dict of api key to use
self.active_api_key = ""

# Logging Settings
self.logger = {}
self.logger["package_logger"] = logging.getLogger("dohq_teamcity")
Expand Down Expand Up @@ -231,8 +234,14 @@ def auth_settings(self):
'key': 'Authorization',
'value': self.get_basic_auth_token()
},

}
'Token':
{
'type': 'token',
'in': 'header',
'key': 'Authorization',
'value': self.get_api_key_with_prefix(self.active_api_key)
}
}

def to_debug_report(self):
"""Gets the essential information for debugging.
Expand Down
5 changes: 3 additions & 2 deletions dohq_teamcity/custom/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@


class TeamCity(ApiClient):
def __init__(self, url, auth, proxy=None, configuration=None):
def __init__(self, url, auth=["Basic"], proxy=None, configuration=None):
configuration = configuration or Configuration()
configuration.host = url
if isinstance(auth, tuple):
configuration.username, configuration.password = auth
self.auth_settings = auth
if proxy is not None:
configuration.proxy = proxy
super(TeamCity, self).__init__(configuration=configuration)
Expand Down Expand Up @@ -65,7 +66,7 @@ def call_api(self, *args, **kwargs):
"""
Quick hack for add Basic auth to swagger-codegen python
"""
kwargs['auth_settings'] = ['Basic']
kwargs['auth_settings'] = self.auth_settings
return super(TeamCity, self).call_api(*args, **kwargs)

def to_str(self):
Expand Down