Skip to content

9117: Prevent api_key sharing #9130

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

Merged
merged 6 commits into from
Feb 10, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,22 @@ import six
from six.moves import http_client as httplib


class TypeWithDefault(type):
def __init__(cls, name, bases, dct):
super(TypeWithDefault, cls).__init__(name, bases, dct)
cls._default = None

def __call__(cls):
if cls._default is None:
cls._default = type.__call__(cls)
return copy.copy(cls._default)

def set_default(cls, default):
cls._default = copy.copy(default)


class Configuration(six.with_metaclass(TypeWithDefault, object)):
class Configuration(object):
"""NOTE: This class is auto generated by the swagger code generator program.

Ref: https://github.com/swagger-api/swagger-codegen
Do not edit the class manually.
"""

_default = None

def __init__(self):
"""Constructor"""
if self._default:
for key in self._default.__dict__.keys():
self.__dict__[key] = copy.copy(self._default.__dict__[key])
return

# Default Base url
self.host = "{{{basePath}}}"
# Temp file folder for downloading files
Expand Down Expand Up @@ -95,6 +88,10 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
# Safe chars for path_param
self.safe_chars_for_path_param = ''

@classmethod
def set_default(cls, default):
cls._default = default

@property
def logger_file(self):
"""The logger file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,22 @@
from six.moves import http_client as httplib


class TypeWithDefault(type):
def __init__(cls, name, bases, dct):
super(TypeWithDefault, cls).__init__(name, bases, dct)
cls._default = None

def __call__(cls):
if cls._default is None:
cls._default = type.__call__(cls)
return copy.copy(cls._default)

def set_default(cls, default):
cls._default = copy.copy(default)


class Configuration(six.with_metaclass(TypeWithDefault, object)):
class Configuration(object):
"""NOTE: This class is auto generated by the swagger code generator program.

Ref: https://github.com/swagger-api/swagger-codegen
Do not edit the class manually.
"""

_default = None

def __init__(self):
"""Constructor"""
if self._default:
for key in self._default.__dict__.keys():
self.__dict__[key] = copy.copy(self._default.__dict__[key])
return

# Default Base url
self.host = "https://petstore.swagger.io */ ' \" =end -- \\r\\n \\n \\r/v2 */ ' \" =end -- \\r\\n \\n \\r"
# Temp file folder for downloading files
Expand Down Expand Up @@ -104,6 +97,10 @@ def __init__(self):
# Safe chars for path_param
self.safe_chars_for_path_param = ''

@classmethod
def set_default(cls, default):
cls._default = default

@property
def logger_file(self):
"""The logger file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,22 @@
from six.moves import http_client as httplib


class TypeWithDefault(type):
def __init__(cls, name, bases, dct):
super(TypeWithDefault, cls).__init__(name, bases, dct)
cls._default = None

def __call__(cls):
if cls._default is None:
cls._default = type.__call__(cls)
return copy.copy(cls._default)

def set_default(cls, default):
cls._default = copy.copy(default)


class Configuration(six.with_metaclass(TypeWithDefault, object)):
class Configuration(object):
"""NOTE: This class is auto generated by the swagger code generator program.

Ref: https://github.com/swagger-api/swagger-codegen
Do not edit the class manually.
"""

_default = None

def __init__(self):
"""Constructor"""
if self._default:
for key in self._default.__dict__.keys():
self.__dict__[key] = copy.copy(self._default.__dict__[key])
return

# Default Base url
self.host = "http://petstore.swagger.io:80/v2"
# Temp file folder for downloading files
Expand Down Expand Up @@ -104,6 +97,10 @@ def __init__(self):
# Safe chars for path_param
self.safe_chars_for_path_param = ''

@classmethod
def set_default(cls, default):
cls._default = default

@property
def logger_file(self):
"""The logger file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,22 @@
from six.moves import http_client as httplib


class TypeWithDefault(type):
def __init__(cls, name, bases, dct):
super(TypeWithDefault, cls).__init__(name, bases, dct)
cls._default = None

def __call__(cls):
if cls._default is None:
cls._default = type.__call__(cls)
return copy.copy(cls._default)

def set_default(cls, default):
cls._default = copy.copy(default)


class Configuration(six.with_metaclass(TypeWithDefault, object)):
class Configuration(object):
"""NOTE: This class is auto generated by the swagger code generator program.

Ref: https://github.com/swagger-api/swagger-codegen
Do not edit the class manually.
"""

_default = None

def __init__(self):
"""Constructor"""
if self._default:
for key in self._default.__dict__.keys():
self.__dict__[key] = copy.copy(self._default.__dict__[key])
return

# Default Base url
self.host = "http://petstore.swagger.io:80/v2"
# Temp file folder for downloading files
Expand Down Expand Up @@ -104,6 +97,10 @@ def __init__(self):
# Safe chars for path_param
self.safe_chars_for_path_param = ''

@classmethod
def set_default(cls, default):
cls._default = default

@property
def logger_file(self):
"""The logger file.
Expand Down
27 changes: 12 additions & 15 deletions samples/client/petstore/python/petstore_api/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,22 @@
from six.moves import http_client as httplib


class TypeWithDefault(type):
def __init__(cls, name, bases, dct):
super(TypeWithDefault, cls).__init__(name, bases, dct)
cls._default = None

def __call__(cls):
if cls._default is None:
cls._default = type.__call__(cls)
return copy.copy(cls._default)

def set_default(cls, default):
cls._default = copy.copy(default)


class Configuration(six.with_metaclass(TypeWithDefault, object)):
class Configuration(object):
"""NOTE: This class is auto generated by the swagger code generator program.

Ref: https://github.com/swagger-api/swagger-codegen
Do not edit the class manually.
"""

_default = None

def __init__(self):
"""Constructor"""
if self._default:
for key in self._default.__dict__.keys():
self.__dict__[key] = copy.copy(self._default.__dict__[key])
return

# Default Base url
self.host = "http://petstore.swagger.io:80/v2"
# Temp file folder for downloading files
Expand Down Expand Up @@ -104,6 +97,10 @@ def __init__(self):
# Safe chars for path_param
self.safe_chars_for_path_param = ''

@classmethod
def set_default(cls, default):
cls._default = default

@property
def logger_file(self):
"""The logger file.
Expand Down
37 changes: 34 additions & 3 deletions samples/client/petstore/python/tests/test_pet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def setUpFiles(self):
self.test_file_dir = os.path.realpath(self.test_file_dir)
self.foo = os.path.join(self.test_file_dir, "foo.png")

def tearDown(self):
Configuration.set_default(None)

def test_preload_content_flag(self):
self.pet_api.add_pet(body=self.pet)

Expand Down Expand Up @@ -132,15 +135,43 @@ def test_separate_default_client_instances(self):

self.assertNotEqual(pet_api.api_client.user_agent, pet_api2.api_client.user_agent)

def test_separate_default_config_instances(self):
def test_default_config(self):
default = Configuration()
default.host = 'default_host'
default.api_key['api_key'] = 'default_key'
default.api_key_prefix['prefix'] = 'default_prefix'
Configuration.set_default(default)

configuration = Configuration()
self.assertIsNot(configuration, default)
self.assertEqual(configuration.host, default.host)
self.assertEqual(configuration.api_key['api_key'], default.api_key['api_key'])
self.assertEqual(configuration.api_key_prefix['prefix'], default.api_key_prefix['prefix'])

configuration.host = 'some_host'
configuration.api_key['api_key'] = 'some_key'
configuration.api_key_prefix['prefix'] = 'some_prefix'
self.assertEqual(default.host, 'default_host')
self.assertEqual(default.api_key['api_key'], 'default_key')
self.assertEqual(default.api_key_prefix['prefix'], 'default_prefix')

def test_separate_config_instances(self):
pet_api = petstore_api.PetApi()
pet_api2 = petstore_api.PetApi()
self.assertNotEqual(pet_api.api_client.configuration, pet_api2.api_client.configuration)

pet_api.api_client.configuration.host = 'somehost'
pet_api2.api_client.configuration.host = 'someotherhost'
pet_api.api_client.configuration.host = 'some_host'
pet_api2.api_client.configuration.host = 'some_other_host'
self.assertNotEqual(pet_api.api_client.configuration.host, pet_api2.api_client.configuration.host)

pet_api.api_client.configuration.api_key['api_key'] = 'some_key'
pet_api2.api_client.configuration.api_key['api_key'] = 'some_other_key'
self.assertNotEqual(pet_api.api_client.configuration.api_key['api_key'], pet_api2.api_client.configuration.api_key['api_key'])

pet_api.api_client.configuration.api_key_prefix['prefix'] = 'some_prefix'
pet_api2.api_client.configuration.api_key_prefix['prefix'] = 'some_other_prefix'
self.assertNotEqual(pet_api.api_client.configuration.api_key_prefix['prefix'], pet_api2.api_client.configuration.api_key_prefix['prefix'])

def test_async_request(self):
thread = self.pet_api.add_pet(body=self.pet, async_req=True)
response = thread.get()
Expand Down