Skip to content

Commit d9af202

Browse files
committed
Deploy
1 parent b1e10b7 commit d9af202

21 files changed

+712
-5
lines changed

bandwidth/bandwidth_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from bandwidth.configuration import Configuration
1111
from bandwidth.configuration import Environment
1212
from bandwidth.messaging.messaging_client import MessagingClient
13+
from bandwidth.twofactorauth.two_factor_auth_client import TwoFactorAuthClient
1314
from bandwidth.voice.voice_client import VoiceClient
1415

1516

@@ -19,6 +20,10 @@ class BandwidthClient(object):
1920
def messaging_client(self):
2021
return MessagingClient(config=self.config)
2122

23+
@lazy_property
24+
def two_factor_auth_client(self):
25+
return TwoFactorAuthClient(config=self.config)
26+
2227
@lazy_property
2328
def voice_client(self):
2429
return VoiceClient(config=self.config)
@@ -27,6 +32,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
2732
environment=Environment.PRODUCTION,
2833
messaging_basic_auth_user_name='TODO: Replace',
2934
messaging_basic_auth_password='TODO: Replace',
35+
two_factor_auth_basic_auth_user_name='TODO: Replace',
36+
two_factor_auth_basic_auth_password='TODO: Replace',
3037
voice_basic_auth_user_name='TODO: Replace',
3138
voice_basic_auth_password='TODO: Replace', config=None):
3239
if config is None:
@@ -36,6 +43,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
3643
environment=environment,
3744
messaging_basic_auth_user_name=messaging_basic_auth_user_name,
3845
messaging_basic_auth_password=messaging_basic_auth_password,
46+
two_factor_auth_basic_auth_user_name=two_factor_auth_basic_auth_user_name,
47+
two_factor_auth_basic_auth_password=two_factor_auth_basic_auth_password,
3948
voice_basic_auth_user_name=voice_basic_auth_user_name,
4049
voice_basic_auth_password=voice_basic_auth_password)
4150
else:

bandwidth/configuration.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Server(Enum):
1919
"""An enum for API servers"""
2020
DEFAULT = 0
2121
MESSAGINGDEFAULT = 1
22-
VOICEDEFAULT = 2
22+
TWOFACTORAUTHDEFAULT = 2
23+
VOICEDEFAULT = 3
2324

2425

2526
class Configuration(object):
@@ -54,6 +55,14 @@ def messaging_basic_auth_user_name(self):
5455
def messaging_basic_auth_password(self):
5556
return self._messaging_basic_auth_password
5657

58+
@property
59+
def two_factor_auth_basic_auth_user_name(self):
60+
return self._two_factor_auth_basic_auth_user_name
61+
62+
@property
63+
def two_factor_auth_basic_auth_password(self):
64+
return self._two_factor_auth_basic_auth_password
65+
5766
@property
5867
def voice_basic_auth_user_name(self):
5968
return self._voice_basic_auth_user_name
@@ -66,6 +75,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
6675
environment=Environment.PRODUCTION,
6776
messaging_basic_auth_user_name='TODO: Replace',
6877
messaging_basic_auth_password='TODO: Replace',
78+
two_factor_auth_basic_auth_user_name='TODO: Replace',
79+
two_factor_auth_basic_auth_password='TODO: Replace',
6980
voice_basic_auth_user_name='TODO: Replace',
7081
voice_basic_auth_password='TODO: Replace'):
7182
# The value to use for connection timeout
@@ -88,6 +99,12 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
8899
# The password to use with basic authentication
89100
self._messaging_basic_auth_password = messaging_basic_auth_password
90101

102+
# The username to use with basic authentication
103+
self._two_factor_auth_basic_auth_user_name = two_factor_auth_basic_auth_user_name
104+
105+
# The password to use with basic authentication
106+
self._two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password
107+
91108
# The username to use with basic authentication
92109
self._voice_basic_auth_user_name = voice_basic_auth_user_name
93110

@@ -100,6 +117,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
100117
def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
101118
environment=None, messaging_basic_auth_user_name=None,
102119
messaging_basic_auth_password=None,
120+
two_factor_auth_basic_auth_user_name=None,
121+
two_factor_auth_basic_auth_password=None,
103122
voice_basic_auth_user_name=None,
104123
voice_basic_auth_password=None):
105124
timeout = timeout or self.timeout
@@ -108,6 +127,8 @@ def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
108127
environment = environment or self.environment
109128
messaging_basic_auth_user_name = messaging_basic_auth_user_name or self.messaging_basic_auth_user_name
110129
messaging_basic_auth_password = messaging_basic_auth_password or self.messaging_basic_auth_password
130+
two_factor_auth_basic_auth_user_name = two_factor_auth_basic_auth_user_name or self.two_factor_auth_basic_auth_user_name
131+
two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password or self.two_factor_auth_basic_auth_password
111132
voice_basic_auth_user_name = voice_basic_auth_user_name or self.voice_basic_auth_user_name
112133
voice_basic_auth_password = voice_basic_auth_password or self.voice_basic_auth_password
113134

@@ -116,6 +137,8 @@ def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
116137
backoff_factor=backoff_factor, environment=environment,
117138
messaging_basic_auth_user_name=messaging_basic_auth_user_name,
118139
messaging_basic_auth_password=messaging_basic_auth_password,
140+
two_factor_auth_basic_auth_user_name=two_factor_auth_basic_auth_user_name,
141+
two_factor_auth_basic_auth_password=two_factor_auth_basic_auth_password,
119142
voice_basic_auth_user_name=voice_basic_auth_user_name,
120143
voice_basic_auth_password=voice_basic_auth_password
121144
)
@@ -130,6 +153,7 @@ def create_http_client(self):
130153
Environment.PRODUCTION: {
131154
Server.DEFAULT: 'api.bandwidth.com',
132155
Server.MESSAGINGDEFAULT: 'https://messaging.bandwidth.com/api/v2',
156+
Server.TWOFACTORAUTHDEFAULT: 'https://mfa.bandwidth.com/api/v1/',
133157
Server.VOICEDEFAULT: 'https://voice.bandwidth.com'
134158
}
135159
}

bandwidth/controllers/base_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BaseController(object):
2727
"""
2828

2929
global_headers = {
30-
'user-agent': 'python-sdk-refs/tags/python6.1.0'
30+
'user-agent': 'python-sdk-refs/tags/python6.2.0'
3131
}
3232

3333
def __init__(self, config, call_back=None):

bandwidth/http/auth/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__all__ = [
22
'messaging_basic_auth',
3+
'two_factor_auth_basic_auth',
34
'voice_basic_auth',
45
]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
bandwidth
5+
6+
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
7+
"""
8+
9+
import base64
10+
11+
12+
class TwoFactorAuthBasicAuth:
13+
14+
@staticmethod
15+
def apply(config, http_request):
16+
""" Add basic authentication to the request.
17+
18+
Args:
19+
config (Configuration): The Configuration object which holds the
20+
authentication information.
21+
http_request (HttpRequest): The HttpRequest object to which
22+
authentication will be added.
23+
24+
"""
25+
username = config.two_factor_auth_basic_auth_user_name
26+
password = config.two_factor_auth_basic_auth_password
27+
joined = "{}:{}".format(username, password)
28+
encoded = base64.b64encode(str.encode(joined)).decode('iso-8859-1')
29+
header_value = "Basic {}".format(encoded)
30+
http_request.headers["Authorization"] = header_value

bandwidth/messaging/controllers/base_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BaseController(object):
2727
"""
2828

2929
global_headers = {
30-
'user-agent': 'python-sdk-refs/tags/python6.1.0'
30+
'user-agent': 'python-sdk-refs/tags/python6.2.0'
3131
}
3232

3333
def __init__(self, config, call_back=None):

bandwidth/messaging/messaging_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
2222
environment=Environment.PRODUCTION,
2323
messaging_basic_auth_user_name='TODO: Replace',
2424
messaging_basic_auth_password='TODO: Replace',
25+
two_factor_auth_basic_auth_user_name='TODO: Replace',
26+
two_factor_auth_basic_auth_password='TODO: Replace',
2527
voice_basic_auth_user_name='TODO: Replace',
2628
voice_basic_auth_password='TODO: Replace', config=None):
2729
if config is None:
@@ -31,6 +33,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
3133
environment=environment,
3234
messaging_basic_auth_user_name=messaging_basic_auth_user_name,
3335
messaging_basic_auth_password=messaging_basic_auth_password,
36+
two_factor_auth_basic_auth_user_name=two_factor_auth_basic_auth_user_name,
37+
two_factor_auth_basic_auth_password=two_factor_auth_basic_auth_password,
3438
voice_basic_auth_user_name=voice_basic_auth_user_name,
3539
voice_basic_auth_password=voice_basic_auth_password)
3640
else:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__all__ = [
2+
'controllers',
3+
'models',
4+
'two_factor_auth_client',
5+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__all__ = [
2+
'base_controller',
3+
'api_controller',
4+
]
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
bandwidth
5+
6+
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
7+
"""
8+
9+
from bandwidth.api_helper import APIHelper
10+
from bandwidth.configuration import Server
11+
from bandwidth.http.api_response import ApiResponse
12+
from bandwidth.twofactorauth.controllers.base_controller import BaseController
13+
from bandwidth.http.auth.two_factor_auth_basic_auth import TwoFactorAuthBasicAuth
14+
from bandwidth.twofactorauth.models.two_factor_voice_response import TwoFactorVoiceResponse
15+
from bandwidth.twofactorauth.models.two_factor_messaging_response import TwoFactorMessagingResponse
16+
from bandwidth.twofactorauth.models.two_factor_verify_code_response import TwoFactorVerifyCodeResponse
17+
18+
19+
class APIController(BaseController):
20+
21+
"""A Controller to access Endpoints in the bandwidth API."""
22+
23+
def __init__(self, config, call_back=None):
24+
super(APIController, self).__init__(config, call_back)
25+
26+
def create_voice_two_factor(self,
27+
account_id,
28+
body):
29+
"""Does a POST request to /accounts/{accountId}/code/voice.
30+
31+
Two-Factor authentication with Bandwidth Voice services
32+
33+
Args:
34+
account_id (string): Bandwidth Account ID with Voice service
35+
enabled
36+
body (TwoFactorCodeRequestSchema): TODO: type description here.
37+
38+
Returns:
39+
ApiResponse: An object with the response value as well as other
40+
useful information such as status codes and headers.
41+
successful operation
42+
43+
Raises:
44+
APIException: When an error occurs while fetching the data from
45+
the remote API. This exception includes the HTTP Response
46+
code, an error message, and the HTTP body that was received in
47+
the request.
48+
49+
"""
50+
51+
# Prepare query URL
52+
_url_path = '/accounts/{accountId}/code/voice'
53+
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
54+
'accountId': account_id
55+
})
56+
_query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT)
57+
_query_builder += _url_path
58+
_query_url = APIHelper.clean_url(_query_builder)
59+
60+
# Prepare headers
61+
_headers = {
62+
'accept': 'application/json',
63+
'content-type': 'application/json; charset=utf-8'
64+
}
65+
66+
# Prepare and execute request
67+
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
68+
TwoFactorAuthBasicAuth.apply(self.config, _request)
69+
_response = self.execute_request(_request)
70+
self.validate_response(_response)
71+
72+
decoded = APIHelper.json_deserialize(_response.text, TwoFactorVoiceResponse.from_dictionary)
73+
_result = ApiResponse(_response, body=decoded)
74+
return _result
75+
76+
def create_messaging_two_factor(self,
77+
account_id,
78+
body):
79+
"""Does a POST request to /accounts/{accountId}/code/messaging.
80+
81+
Two-Factor authentication with Bandwidth messaging services
82+
83+
Args:
84+
account_id (string): Bandwidth Account ID with Messaging service
85+
enabled
86+
body (TwoFactorCodeRequestSchema): TODO: type description here.
87+
88+
Returns:
89+
ApiResponse: An object with the response value as well as other
90+
useful information such as status codes and headers.
91+
successful operation
92+
93+
Raises:
94+
APIException: When an error occurs while fetching the data from
95+
the remote API. This exception includes the HTTP Response
96+
code, an error message, and the HTTP body that was received in
97+
the request.
98+
99+
"""
100+
101+
# Prepare query URL
102+
_url_path = '/accounts/{accountId}/code/messaging'
103+
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
104+
'accountId': account_id
105+
})
106+
_query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT)
107+
_query_builder += _url_path
108+
_query_url = APIHelper.clean_url(_query_builder)
109+
110+
# Prepare headers
111+
_headers = {
112+
'accept': 'application/json',
113+
'content-type': 'application/json; charset=utf-8'
114+
}
115+
116+
# Prepare and execute request
117+
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
118+
TwoFactorAuthBasicAuth.apply(self.config, _request)
119+
_response = self.execute_request(_request)
120+
self.validate_response(_response)
121+
122+
decoded = APIHelper.json_deserialize(_response.text, TwoFactorMessagingResponse.from_dictionary)
123+
_result = ApiResponse(_response, body=decoded)
124+
return _result
125+
126+
def create_verify_two_factor(self,
127+
account_id,
128+
body):
129+
"""Does a POST request to /accounts/{accountId}/code/verify.
130+
131+
Verify a previously sent two-factor authentication code
132+
133+
Args:
134+
account_id (string): Bandwidth Account ID with Two-Factor enabled
135+
body (TwoFactorVerifyRequestSchema): TODO: type description here.
136+
137+
Returns:
138+
ApiResponse: An object with the response value as well as other
139+
useful information such as status codes and headers.
140+
successful operation
141+
142+
Raises:
143+
APIException: When an error occurs while fetching the data from
144+
the remote API. This exception includes the HTTP Response
145+
code, an error message, and the HTTP body that was received in
146+
the request.
147+
148+
"""
149+
150+
# Prepare query URL
151+
_url_path = '/accounts/{accountId}/code/verify'
152+
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
153+
'accountId': account_id
154+
})
155+
_query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT)
156+
_query_builder += _url_path
157+
_query_url = APIHelper.clean_url(_query_builder)
158+
159+
# Prepare headers
160+
_headers = {
161+
'accept': 'application/json',
162+
'content-type': 'application/json; charset=utf-8'
163+
}
164+
165+
# Prepare and execute request
166+
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
167+
TwoFactorAuthBasicAuth.apply(self.config, _request)
168+
_response = self.execute_request(_request)
169+
self.validate_response(_response)
170+
171+
decoded = APIHelper.json_deserialize(_response.text, TwoFactorVerifyCodeResponse.from_dictionary)
172+
_result = ApiResponse(_response, body=decoded)
173+
return _result

0 commit comments

Comments
 (0)